summaryrefslogtreecommitdiffstats
path: root/json.php
diff options
context:
space:
mode:
Diffstat (limited to 'json.php')
-rw-r--r--json.php20
1 files changed, 17 insertions, 3 deletions
diff --git a/json.php b/json.php
index f83d7f9..0b9fbca 100644
--- a/json.php
+++ b/json.php
@@ -1,5 +1,8 @@
<?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;
}
@@ -17,14 +20,18 @@ if ( isset($_GET['host']) && !empty($_GET['host'])) {
if ( !is_numeric($port) ) {
$port = 443;
}
+ $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,$port);
-
} 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 = utf8encodeNestedArray($data);
@@ -61,5 +68,12 @@ if ($_GET["type"] == "pretty") {
echo json_encode($data);
}
+
+if ($write_cache == 1) {
+ if (!file_exists($cache_filename)) {
+ file_put_contents($cache_filename, json_encode($data));
+ }
+}
+
?>