-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
73 lines (54 loc) · 2.11 KB
/
Copy pathindex.php
File metadata and controls
73 lines (54 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
$data = [];
if(!empty($_POST)) {
if(filter_var($_POST['host'], FILTER_VALIDATE_URL)) {
$_POST['host'] = parse_url($_POST['host'], PHP_URL_HOST);
}
/* Check for any errors */
$required_fields = ['host'];
foreach($required_fields as $field) {
if(!isset($_POST[$field]) || (isset($_POST[$field]) && empty($_POST[$field]) && $_POST[$field] != '0')) {
Alerts::add_field_error($field, l('global.error_message.empty_field'));
}
}
/* Check for an SSL certificate */
$certificate = get_website_certificate('https://' . $_POST['host']);
if(!$certificate) {
Alerts::add_field_error('host', l('tools.ssl_lookup.error_message'));
}
if(!Alerts::has_field_errors() && !Alerts::has_errors()) {
/* Create the new SSL object */
$ssl = [
'organization' => $certificate['issuer']['O'],
'country' => $certificate['issuer']['C'],
'common_name' => $certificate['issuer']['CN'],
'start_datetime' => (new \DateTime())->setTimestamp($certificate['validFrom_time_t'])->format('Y-m-d H:i:s'),
'end_datetime' => (new \DateTime())->setTimestamp($certificate['validTo_time_t'])->format('Y-m-d H:i:s'),
];
$data['result'] = $ssl;
}
}
$values = [
'host' => $_POST['host'] ?? '',
'result' => $data,
];
function get_website_certificate($url) {
try {
$domain = parse_url($url, PHP_URL_HOST);
$get = stream_context_create([
'ssl' => [
'capture_peer_cert' => TRUE,
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
$read = @stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
if(!$read || $errstr) return false;
$cert = stream_context_get_params($read);
$certInfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
return empty($certInfo) ? false : $certInfo;
} catch (\Exception $exception) {
return false;
}
}