diff --git a/CryptoBottle/CryptoBottle.py b/CryptoBottle/CryptoBottle.py new file mode 100755 index 0000000..11890cc --- /dev/null +++ b/CryptoBottle/CryptoBottle.py @@ -0,0 +1,102 @@ +#!/usr/bin/python +""" CryptoBottle - minimalistic webfrontend for cryptsetup + + prepare your Debian/squeeze: + aptitude install python-bottle cryptsetup + modprobe dm_crypt + set all variables before the first run & create "mntpoint" + run this script as root +""" +from bottle import route, run, post, request, debug +from subprocess import * + +serverport = 83 +cryptcmd = "/sbin/cryptsetup" +mntcmd = "/bin/mount" +umntcmd = "/bin/umount" +cryptdevice = "/dev/vdc1" +mapperpath = "/dev/mapper/" +mappername = "vdc1_crypt" +mntpoint = "/mnt" + +@route('/') +def index(): + return ''' + +

crypto in a bottle

+
+%s + +''' % (cryptstatus()) + + +@route('/status') +def cryptstatus(): + shell = Popen([cryptcmd, "status", mappername], stdout=PIPE, stderr=PIPE) + (cryptsetup_out, err) = shell.communicate() + if len(err) != 0: + return '''

cryptsetup error

%s
''' % err + if len(cryptsetup_out) == 0: + cryptsetup_out = '

"%s%s" is not mapped

' % (mapperpath, mappername) + + shell = Popen(["df", "-h"], stdout=PIPE) + df_out = shell.communicate()[0] + + return '''

cryptsetup status

+
%s
+

df -h

+
%s
''' % (cryptsetup_out, df_out) + + +@route('/cryptopen', method='POST') +def cryptopen(): + cryptpw = request.forms.get('passwd') + if len(cryptpw) == 0: + return '''

cryptsetup error

+password is empty
+zurück ''' + + shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE) + (cryptsetup_out, err) = shell.communicate(cryptpw) + if len(err) != 0: + return '''

cryptsetup error

%s
+zurück ''' % err + + if len(cryptsetup_out) == 0: + cryptsetup_out = '

Einhängen war erfolgreich!

' + + shell = Popen([mntcmd, mapperpath + mappername, mntpoint], stdout=PIPE,stderr=PIPE) + (mount_out, err) = shell.communicate() + + return ''' +
%s
+zurück ''' % (cryptsetup_out) + + +@route('/cryptclose') +def cryptclose(): + shell = Popen([umntcmd, mntpoint], stdout=PIPE,stderr=PIPE) + (umount_out, err) = shell.communicate() + + shell = Popen([cryptcmd, "luksClose", mappername], stdout=PIPE,stderr=PIPE) + (cryptsetup_out, err) = shell.communicate() + if len(err) != 0: + return '''

cryptsetup error

%s
+zurück ''' % err + + if len(cryptsetup_out) == 0: + cryptsetup_out = '

Aushängen war erfolgreich!

' + + return ''' +
%s
+zurück ''' % (cryptsetup_out) + + +debug(True) +run(host='', port=serverport, reloader=True) +