Skip to content

Instantly share code, notes, and snippets.

@santrancisco
Last active August 2, 2018 06:27
Show Gist options
  • Save santrancisco/71e3f7efec2ac2e9b6583af49bf3a642 to your computer and use it in GitHub Desktop.
Save santrancisco/71e3f7efec2ac2e9b6583af49bf3a642 to your computer and use it in GitHub Desktop.
Querying cert signed by Symantec before 1st June 2016 using data.gov.au
<html>
<body>please wait, loading...</body>
<script>
// Original code from Maxiosu ;) https://codepen.io/maxiosu/pen/gvJmgd?editors=0010
var query = "Symantec";
var sql = "SELECT s.domain, s.issuer_cn, s.not_valid_after, s.not_valid_before "+
"FROM ( "+
"SELECT key, UNNEST(domains) AS domain, issuer_cn, not_valid_after, not_valid_before "+
'FROM "b718232a-bc8d-49c0-9c1f-33c31b57cd88" '+
"WHERE not_valid_before < NOW() AND not_valid_after > NOW() "+
") s WHERE s.issuer_cn LIKE '%"+query+"%' and s.not_valid_before < '2016-06-01'::date"
var request = new XMLHttpRequest();
console.log('https://data.gov.au/api/3/action/datastore_search_sql?sql='+ encodeURI(sql))
request.open('GET', 'https://cors-anywhere.herokuapp.com/https://data.gov.au/api/3/action/datastore_search_sql?sql='+encodeURI(sql), true);
request.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status >= 200 && this.status < 400) {
// Success!
var data = JSON.parse(this.responseText);
var body = document.querySelector('body');
body.innerHTML = "<h1>"+query+"</h1><table><thead><tr><th>Domain</th><th>Issuer CA</th><th>from</th><th>to</th><tbody><tbody></table>";
var tbody = document.querySelector('table');
data.result.records.forEach(function(record) {
var row = document.createElement("tr");
var cell1 = document.createElement("td");
var cell2 = document.createElement("td");
var cell3 = document.createElement("td");
var cell4 = document.createElement("td");
cell2.innerHTML = record.issuer_cn;
cell1.innerHTML = record.domain;
cell3.innerHTML = record.not_valid_before;
cell4.innerHTML = record.not_valid_after;
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell4);
tbody.appendChild(row);
});
} else {
// Error :(
}
}
};
request.send();
request = null;
</script>
</html>
@santrancisco
Copy link
Author

link to codepen here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment