forked from tomwijnroks/ssl-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.php
64 lines (56 loc) · 1.83 KB
/
json.php
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
<?php
error_reporting(E_ALL & ~E_NOTICE);
$write_cache = 0;
$epoch = date('U');
$random_bla = md5(uniqid(rand(), true));
foreach (glob("functions/*.php") as $filename) {
include $filename;
}
if ( isset($_GET['host']) && !empty($_GET['host'])) {
$data = [];
$hostname = mb_strtolower(get($_GET['host']));
$hostname = parse_hostname($hostname);
if ($hostname['multiple_ip']) {
$data["error"] = ["Host format is incorrect. (use \$host:\$ip.)"];
}
$host = $hostname['hostname'];
$ip = $hostname['ip'];
$port = get($_GET['port'], '443');
if ( !is_numeric($port) ) {
$port = 443;
}
$fastcheck = $_GET['fastcheck'];
$write_cache = 1;
$hostfilename = preg_replace("([^\w\s\d\-_~,;:\[\]\(\).])", '', $host);
$hostfilename = preg_replace("([\.]{2,})", '', $host);
$hostfilename = preg_replace("([^a-z0-9])", '', $host);
$cache_filename = (string) "results/saved." . $hostfilename . "." . $epoch . "." . $random_bla . ".api.json";
$data["data"] = check_json($host, $ip, $port, $fastcheck);
} elseif(isset($_GET['csr']) && !empty($_GET['csr'])) {
$write_cache = 1;
$cache_filename = (string) "results/saved.csr." . $epoch . "." . $random_bla . ".api.json";
$data["data"]["chain"]["1"] = csr_parse_json($_GET['csr']);
} else {
$data["error"] = ["Host is required"];
}
$data['version'] = $version;
$data = utf8encodeNestedArray($data);
if(isset($data["data"]["error"])) {
$data["error"] = $data["data"]["error"];
unset($data["data"]);
}
if ($_GET["type"] == "pretty") {
header('Content-Type: text/html');
echo "<pre>";
echo htmlspecialchars(json_encode($data,JSON_PRETTY_PRINT));
echo "</pre>";
} else {
header('Content-Type: application/json');
echo json_encode($data);
}
if ($write_cache == 1) {
if (!file_exists($cache_filename)) {
file_put_contents($cache_filename, json_encode($data));
}
}
?>