CryptoBox rewrite in 100 Zeilen ;)

This commit is contained in:
age 2012-07-19 22:22:12 +00:00
parent 5e7433ab56
commit 7f37670386

102
CryptoBottle/CryptoBottle.py Executable file
View file

@ -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 '''
<html><body>
<h1>crypto in a bottle</h1>
<ul><li>
<form action="/cryptopen" method="POST">Passwort eingeben:
<input name="passwd" type="password" /> <input type="submit" value=" Datenhafen &ouml;ffnen ">
</form></li><li>
<form action="/cryptclose" ><input type="submit" value=" Datenhafen abschliessen ">
</form></li></ul><hr />
%s
</body></html>
''' % (cryptstatus())
@route('/status')
def cryptstatus():
shell = Popen([cryptcmd, "status", mappername], stdout=PIPE, stderr=PIPE)
(cryptsetup_out, err) = shell.communicate()
if len(err) != 0:
return '''<h1>cryptsetup error</h1> <pre>%s</pre> ''' % err
if len(cryptsetup_out) == 0:
cryptsetup_out = '<p>"%s%s" is not mapped</p>' % (mapperpath, mappername)
shell = Popen(["df", "-h"], stdout=PIPE)
df_out = shell.communicate()[0]
return '''<h1>cryptsetup status</h1>
<pre>%s</pre>
<h1>df -h</h1>
<pre>%s</pre> ''' % (cryptsetup_out, df_out)
@route('/cryptopen', method='POST')
def cryptopen():
cryptpw = request.forms.get('passwd')
if len(cryptpw) == 0:
return '''<h1>cryptsetup error</h1>
password is empty<br />
<a href=\"/\">zur&uuml;ck</a> '''
shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE)
(cryptsetup_out, err) = shell.communicate(cryptpw)
if len(err) != 0:
return '''<h1>cryptsetup error</h1><pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % err
if len(cryptsetup_out) == 0:
cryptsetup_out = '<p>Einh&auml;ngen war erfolgreich!</p>'
shell = Popen([mntcmd, mapperpath + mappername, mntpoint], stdout=PIPE,stderr=PIPE)
(mount_out, err) = shell.communicate()
return '''<meta http-equiv="refresh" content="2; URL=/">
<pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % (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 '''<h1>cryptsetup error</h1> <pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % err
if len(cryptsetup_out) == 0:
cryptsetup_out = '<p>Aush&auml;ngen war erfolgreich!</p>'
return '''<meta http-equiv="refresh" content="2; URL=/">
<pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % (cryptsetup_out)
debug(True)
run(host='', port=serverport, reloader=True)