CryptoBox rewrite in 100 Zeilen ;)
This commit is contained in:
parent
5e7433ab56
commit
7f37670386
1 changed files with 102 additions and 0 deletions
102
CryptoBottle/CryptoBottle.py
Executable file
102
CryptoBottle/CryptoBottle.py
Executable 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 ö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ü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ück</a> ''' % err
|
||||
|
||||
if len(cryptsetup_out) == 0:
|
||||
cryptsetup_out = '<p>Einhä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ü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ück</a> ''' % err
|
||||
|
||||
if len(cryptsetup_out) == 0:
|
||||
cryptsetup_out = '<p>Aushängen war erfolgreich!</p>'
|
||||
|
||||
return '''<meta http-equiv="refresh" content="2; URL=/">
|
||||
<pre>%s</pre>
|
||||
<a href=\"/\">zurück</a> ''' % (cryptsetup_out)
|
||||
|
||||
|
||||
debug(True)
|
||||
run(host='', port=serverport, reloader=True)
|
||||
|
Loading…
Reference in a new issue