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 | |
parent | cd031f18cb342fabf2d231d6a6b4a405b5ea3122 (diff) | |
download | ssl-decoder-735c2a72b293655b74293ef999374582f948bd8b.zip ssl-decoder-735c2a72b293655b74293ef999374582f948bd8b.tar.gz ssl-decoder-735c2a72b293655b74293ef999374582f948bd8b.tar.bz2 |
Add json output saving
-rw-r--r-- | index.php | 9 | ||||
-rw-r--r-- | json.php | 20 |
2 files changed, 25 insertions, 4 deletions
@@ -137,6 +137,7 @@ foreach (glob("functions/*.php") as $filename) { $hostfilename = preg_replace("([\.]{2,})", '', $host); $hostfilename = preg_replace("([^a-z0-9])", '', $host); $cache_filename = (string) "results/saved." . $hostfilename . "." . $epoch . "." . $random_bla . ".html"; + $cache_filename_json = (string) "results/saved." . $hostfilename . "." . $epoch . "." . $random_bla . ".json"; if ($write_cache == 1) { echo "This result is saved at most 60 days on <a href=\""; @@ -154,7 +155,6 @@ foreach (glob("functions/*.php") as $filename) { foreach ($data["data"]["chain"] as $key => $value) { echo "<div class='content'><section id='cert" . $key . "'>"; echo "<header><h2>Certificate for '". htmlspecialchars($value["cert_data"]["subject"]["CN"]) ."'</h2></header>"; - //pre_dump($value); cert_parse($value); echo "</section></div>"; } @@ -163,6 +163,7 @@ foreach (glob("functions/*.php") as $filename) { $data = csr_parse_json($_GET['csr']); echo "<p><strong>This tool does not make conclusions. Please check the data and define the validity yourself!</strong><br>\n </p>"; $cache_filename = (string) "results/saved.csr." . $epoch . "." . $random_bla . ".html"; + $cache_filename_json = (string) "results/saved.csr." . $epoch . "." . $random_bla . ".json"; if ($write_cache == 1) { echo "This result is saved at most 60 days on <a href=\""; echo(htmlspecialchars($current_folder) . $cache_filename); @@ -197,6 +198,12 @@ if ($write_cache == 1) { if (!file_exists($cache_filename)) { file_put_contents($cache_filename, ob_get_contents()); } + if (is_array($data)) { + $json_data = json_encode(utf8encodeNestedArray($data)); + } + if (!file_exists($cache_filename_json)) { + file_put_contents($cache_filename_json, $json_data); + } } ?> @@ -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)); + } +} + ?> |