checkpoint

This commit is contained in:
Jeffrey Paul 2013-02-28 17:38:06 +01:00
parent 43ab9629f2
commit 098609d70d
3 changed files with 132 additions and 11 deletions

103
checkcert/checkcert Executable file
View File

@ -0,0 +1,103 @@
#!/usr/bin/env python
import sys
from pprint import pformat
import requests
import pyquery
import ssl
import OpenSSL
from urlparse import urlparse, urljoin
from datetime import datetime, timedelta
from pytz import UTC
import logging
logging.getLogger().setLevel(logging.DEBUG)
class AttrDict(dict):
def __init__(self, *a, **kw):
dict.__init__(self, *a, **kw)
self.__dict__ = self
derp = AttrDict()
def die(reason):
raise SystemExit(reason)
def interact():
import code
code.InteractiveConsole(locals=globals()).interact()
class CertificateProblem(Exception):
pass
class ReachabilityProblem(Exception):
pass
def decode_ossl_time(t):
f = '%Y%m%d%H%M%SZ'
return datetime.strptime(t, f)
class SSLCert(object):
def __init__(self,x):
self.x = x
def notBefore(self):
return decode_ossl_time(self.x.get_notBefore())
def notAfter(self):
return decode_ossl_time(self.x.get_notAfter())
def commonName(self):
t = self.x.get_subject().get_components()
for x in t:
if x[0] == "CN":
return x[1]
def expired(self):
return datetime.utcnow() > self.notAfter()
def tooEarly(self):
return datetime.utcnow() < self.notBefore()
def validTime(self):
if not self.expired() and not self.tooEarly():
return True
return False
def expiresSoon(self):
week = timedelta(days=7)
then = datetime.utcnow() + week
return then > self.notAfter()
def check_url(url):
r = requests.get(url,verify=True)
if r.status_code is not 200:
raise ReachabilityProblem
cert = cert_for_url(url)
def cert_for_url(url):
o = urlparse(url)
if o.scheme != 'https':
return None
if not o.port:
p = 443
else:
p = o.port
c = ssl.get_server_certificate((o.hostname, p))
return SSLCert(
OpenSSL.crypto.load_certificate(
OpenSSL.crypto.FILETYPE_PEM,
c
)
)
def main():
if len(sys.argv) < 2:
print "usage: %s <url>" % sys.argv[0]
sys.exit(1)
do_checks(sys.argv[1])
def do_checks(starturl):
urlqueue = []
urlqueue.append(starturl)
while len(urlqueue):
urlqueue.extend(check_url(urlqueue.pop()))
if __name__ == '__main__':
main()

View File

@ -2,21 +2,33 @@ JUNKFILES = .bash_history .irb_history .pip .ScanSnap .nbems .fldigi .cpan
JUNKFILES += .gdb_history .mysql_history .sqlite_history
YYYYMM := $(shell date +%Y%m)
NO_COLOR = \033[0m
O1_COLOR = \033[0;01m
O2_COLOR = \033[32;01m
PREFIX = "$(O2_COLOR)==>$(O1_COLOR)"
SUFFIX = "$(NO_COLOR)"
default: backup
backup: clean
mbsync eeqjgmail
mbsync acidhousegmail
-rsync -avPhz --delete sneak@datavibe.net:.maildir/ \
$(HOME)/Documents/Secure/datavibe.maildir/
@internalbackup.command # to 1tb
@externalbackup.command # to fw800
@echo $(PREFIX) $@ $(SUFFIX)
cd ~/Documents/datavibe/backup && make
offlineimap
rsync -e "ssh -c arcfour -o Compression=no -x" \
-avPhzy --delete sneak@datavibe.net:.maildir/ \
$(HOME)/Documents/Archival/mail/sneak.datavibe.net.maildir/
rsync -e "ssh -c arcfour -o Compression=no -x" \
-avPhzy --delete $(HOME)/Documents/Archival/mail/ \
sneak@datavibe.net:.mailbackup/
backup.command
clean:
-rm -rfv ~/tmp/*
-rm -rfv ~/Library/Caches/*
-rm -rfv ~/.Trash/*
-rm -rfv $(JUNKFILES)
@echo $(PREFIX) $@ $(SUFFIX)
@-rm -rf ~/tmp/*
@-rm -rf ~/Library/Caches/*
@-rm -rf ~/.Trash/*
@-rm -rf $(JUNKFILES)
-mkdir -p $(HOME)/Documents/$(YYYYMM)
-mv $(HOME)/Desktop/* $(HOME)/Documents/$(YYYYMM)

View File

@ -7,12 +7,13 @@
NOW="`date +%Y%m%d.%H%M%S`"
BACKUPDEST=${BACKUPDEST:-"${USER}@jfk1.datavibe.net:backup/"}
BACKUPDEST=${BACKUPDEST:-"/Volumes/ExternalBackup/sneak.backup"}
RSYNC="rsync.3.0.9"
OPTS="-rlptDPSyzh --no-owner --no-group --delete-excluded --delete"
RE=""
RE+=" --exclude=.cache/"
RE+=" --exclude=/Desktop/" # desktop is like a visible tempdir.
RE+=" --exclude=/Library/Safari/"
RE+=" --exclude=/Downloads/"
@ -61,6 +62,11 @@ MINRE+=" --exclude=.DS_Store"
RE+=" ${MINRE}"
if [ ! -e "${BACKUPDEST}" ]; then
echo "backup destination $BACKUPDEST not available!" > /dev/stderr
exit 127
fi
RETVAL=255
while [ $RETVAL -ne 0 ]; do
$RSYNC $OPTS $RE ${HOME}/ ${BACKUPDEST}/Home/