103 lines
3.4 KiB
Python
Executable file
103 lines
3.4 KiB
Python
Executable file
#!/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, template, debug, TEMPLATES, static_file
|
|
from subprocess import Popen, PIPE
|
|
from os.path import join
|
|
|
|
serverport = 83
|
|
cryptcmd = "/sbin/cryptsetup"
|
|
mntcmd = "/bin/mount"
|
|
umntcmd = "/bin/umount"
|
|
cryptdevice = "/dev/vdc1"
|
|
mapperpath = "/dev/mapper/"
|
|
mappername = "vdc1"
|
|
mntpoint = "/mnt"
|
|
|
|
@route('/style/default.css')
|
|
def server_static():
|
|
return static_file('default.css', root='/data/cryptobottle-dev/style')
|
|
|
|
@route('/')
|
|
def index():
|
|
output = {'passwd':'Datenhafen oeffnen'}
|
|
return template('generic', output=output)
|
|
|
|
@route('/status')
|
|
def cryptstatus():
|
|
shell = Popen([cryptcmd, "status", mappername], stdout=PIPE, stderr=PIPE)
|
|
(cryptsetup, err) = shell.communicate()
|
|
if err:
|
|
return template('generic', output= {'cryptsetup':err})
|
|
if len(cryptsetup) == 0:
|
|
cryptsetup = '"%s%s" is not mapped' % (mapperpath, mappername)
|
|
|
|
shell = Popen(["df", "-h"], stdout=PIPE)
|
|
(df, err) = shell.communicate()
|
|
if err:
|
|
return template('generic', output= {'df':err})
|
|
status = ''
|
|
shell = Popen(["lsof", mntpoint], stdout=PIPE)
|
|
lsof = shell.communicate()[0]
|
|
output = {'cryptsetup': cryptsetup, 'df': df, 'lsof': lsof}
|
|
return template('generic', output=output )
|
|
|
|
@route('/cryptopen', method='POST')
|
|
def cryptopen():
|
|
cryptpw = request.forms.get('passwd')
|
|
mount = ''
|
|
if len(cryptpw) == 0:
|
|
cryptsetup = 'kein Passwort angegeben'
|
|
else:
|
|
shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE)
|
|
(cryptsetup, err) = shell.communicate(cryptpw)
|
|
if err:
|
|
cryptsetup = err
|
|
elif len(cryptsetup) == 0:
|
|
cryptsetup = 'erfolgreich entschluesselt'
|
|
shell = Popen([mntcmd, join(mapperpath, mappername), mntpoint], stdout=PIPE,stderr=PIPE)
|
|
(mount, mount_err) = shell.communicate()
|
|
if mount_err:
|
|
mount = mount_err
|
|
elif len(mount) == 0:
|
|
mount = 'erfolgreich eingehangen'
|
|
|
|
output = {'cryptsetup': cryptsetup, 'mount': mount}
|
|
return template('generic', output=output )
|
|
|
|
@route('/cryptclose')
|
|
def cryptclose():
|
|
output = {}
|
|
umount = ''
|
|
shell = Popen(["lsof", mntpoint], stdout=PIPE)
|
|
lsof = shell.communicate()[0]
|
|
if lsof:
|
|
lsof += 'Aushaengen nicht moeglich. Verzeichnis wird noch benutzt.'
|
|
output = {'lsof':lsof}
|
|
else:
|
|
shell = Popen([umntcmd, mntpoint], stdout=PIPE,stderr=PIPE)
|
|
(umount, umount_err) = shell.communicate()
|
|
if umount_err:
|
|
output = {'mount':umount_err}
|
|
|
|
elif len(umount) == 0:
|
|
umount = 'erfolgreich ausgehangen'
|
|
#try luksclose in any case
|
|
shell = Popen([cryptcmd, "luksClose", mappername], stdout=PIPE,stderr=PIPE)
|
|
(cryptsetup, err) = shell.communicate()
|
|
if len(err) != 0:
|
|
cryptsetup += err
|
|
if len(cryptsetup) == 0:
|
|
cryptsetup = 'erfolgreich verschluesselt'
|
|
output = {'mount':umount, 'cryptsetup': cryptsetup}
|
|
return template('generic', output=output)
|
|
|
|
debug(True)
|
|
run(host='', port=serverport, reloader=True)
|
|
|