diff options
author | Remy <relst@relst.nl> | 2015-04-04 21:46:18 +0200 |
---|---|---|
committer | Remy <relst@relst.nl> | 2015-04-04 21:46:18 +0200 |
commit | 735c2a72b293655b74293ef999374582f948bd8b (patch) | |
tree | d64a223f85fcbc2655d1f47917f4ca0123329145 /json.php | |
parent | cd031f18cb342fabf2d231d6a6b4a405b5ea3122 (diff) | |
download | ssl-decoder-735c2a72b293655b74293ef999374582f948bd8b.zip ssl-decoder-735c2a72b293655b74293ef999374582f948bd8b.tar.gz ssl-decoder-735c2a72b293655b74293ef999374582f948bd8b.tar.bz2 |
Add json output saving
Diffstat (limited to 'json.php')
-rw-r--r-- | json.php | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -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)); + } +} + ?> |