Skip to content

Instantly share code, notes, and snippets.

@jrhz
Created May 7, 2019 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrhz/db66a117b9d6f8e94c34aa2a8dfaead5 to your computer and use it in GitHub Desktop.
Save jrhz/db66a117b9d6f8e94c34aa2a8dfaead5 to your computer and use it in GitHub Desktop.
Create an index.html with a bunch of SSL cert info
body {
background-color: rgb(42, 42, 46)
}
table {
border-collapse: collapse;
width: 100%;
color: white
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
#!/usr/bin/env python3
import yaml
import io
import subprocess
import datetime
import calendar
def gethosts():
with open("hosts.yaml", 'r') as stream:
try:
hostyaml = yaml.safe_load(stream)
print("<html><head><link rel=\"stylesheet\" href=\"cert.css\"><title>Cert Watcher</title></head><body>")
print("<table><tr><th>Hostname</th><th>Not Before</th><th>Not After (Expires)</th><th>Renewal Needed</th><th>Issuer</th></tr>")
for i in hostyaml['hosts']:
print("<tr>")
getcertinfo(i)
print("</tr>")
print("</table></body></html>")
except yaml.YAMLError as exc:
print(exc)
def getcertinfo(host):
today = datetime.date.today()
# Requires https://github.com/mozilla-it/cert-tools
p = subprocess.Popen(["../cert-tools/ssl-validity", host], stdout=subprocess.PIPE)
pout = p.stdout.readlines()
print("<td>" + host + "</td>")
for i in pout:
d = i.decode("UTF-8").rstrip("\n").replace("Not Before: ", "")
if 'Not After :' in d:
afterdate = d.split()
month = list(calendar.month_abbr).index(afterdate[3])
day = afterdate[4]
year = afterdate[6]
expireday = datetime.date(int(year), int(month), int(day))
daydiff = expireday - today
d = d.replace("Not After : ", "")
print("<td>",d,"</td>")
if daydiff.days < 60:
print("<td style=\"color:orange\">Due in", daydiff.days, "days</td>")
elif daydiff.days < 30:
print("<td style=\"color:tomato\">Due in", daydiff.days, "days</td>")
else:
print("<td style=\"color:mediumseagreen\">Due in", daydiff.days, "days</td>")
else:
print("<td>", d, "</td>")
c = subprocess.Popen(["../cert-tools/ssl-inspect", host], stdout=subprocess.PIPE)
cout = c.stdout.readlines()
for i in cout:
if 'Issuer:' in i.decode("UTF-8"):
i = i.decode("UTF-8").split(",")
print("<td>",i[1].replace("O = ",""),"</td>")
if __name__ == "__main__":
gethosts()
hosts:
- start.mozilla.org
- developer.mozilla.org
- support.mozilla.org
- voice.mozilla.org
- wiki.mozilla.org
- air.mozilla.org
- jira.mozilla.com
- mana.mozilla.org
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment