Lars' Anmerkungen eingepflegt

This commit is contained in:
age 2012-07-20 08:22:08 +00:00
parent 7f37670386
commit 114208504e

View file

@ -8,7 +8,8 @@
run this script as root
"""
from bottle import route, run, post, request, debug
from subprocess import *
from subprocess import Popen, PIPE
from os.path import join
serverport = 83
cryptcmd = "/sbin/cryptsetup"
@ -21,25 +22,23 @@ 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())
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:
if err:
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)
@ -48,9 +47,9 @@ def cryptstatus():
df_out = shell.communicate()[0]
return '''<h1>cryptsetup status</h1>
<pre>%s</pre>
<h1>df -h</h1>
<pre>%s</pre> ''' % (cryptsetup_out, df_out)
<pre>%s</pre>
<h1>df -h</h1>
<pre>%s</pre> ''' % (cryptsetup_out, df_out)
@route('/cryptopen', method='POST')
@ -63,23 +62,30 @@ password is empty<br />
shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE)
(cryptsetup_out, err) = shell.communicate(cryptpw)
if len(err) != 0:
if err:
return '''<h1>cryptsetup error</h1><pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % err
<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)
shell = Popen([mntcmd, join(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)
<pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % cryptsetup_out
@route('/cryptclose')
def cryptclose():
shell = Popen(["lsof", mntpoint], stdout=PIPE)
lsof_out = shell.communicate()[0]
if lsof_out:
return '''Aush&auml;ngen nicht m&ouml;glich. Verzeichnis wird noch benutzt.
<h1>lsof %s</h1>
<pre>%s</&pre> ''' % (mntpoint, lsof_out)
shell = Popen([umntcmd, mntpoint], stdout=PIPE,stderr=PIPE)
(umount_out, err) = shell.communicate()
@ -87,14 +93,14 @@ def cryptclose():
(cryptsetup_out, err) = shell.communicate()
if len(err) != 0:
return '''<h1>cryptsetup error</h1> <pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % err
<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)
<pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % (cryptsetup_out)
debug(True)