From 098609d70ddce81d176c5f4d87a3055b25754803 Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Thu, 28 Feb 2013 17:38:06 +0100 Subject: [PATCH] checkpoint --- checkcert/checkcert | 103 ++++++++++++++++++++++++++++++++++++++ homedir.makefile/Makefile | 32 ++++++++---- osxbackup/backup.command | 8 ++- 3 files changed, 132 insertions(+), 11 deletions(-) create mode 100755 checkcert/checkcert diff --git a/checkcert/checkcert b/checkcert/checkcert new file mode 100755 index 0000000..d6e94ae --- /dev/null +++ b/checkcert/checkcert @@ -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 " % 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() diff --git a/homedir.makefile/Makefile b/homedir.makefile/Makefile index 7809012..223362c 100644 --- a/homedir.makefile/Makefile +++ b/homedir.makefile/Makefile @@ -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) diff --git a/osxbackup/backup.command b/osxbackup/backup.command index ab29e61..69d64dc 100755 --- a/osxbackup/backup.command +++ b/osxbackup/backup.command @@ -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/