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 run this script as root
""" """
from bottle import route, run, post, request, debug from bottle import route, run, post, request, debug
from subprocess import * from subprocess import Popen, PIPE
from os.path import join
serverport = 83 serverport = 83
cryptcmd = "/sbin/cryptsetup" cryptcmd = "/sbin/cryptsetup"
@ -21,25 +22,23 @@ mntpoint = "/mnt"
@route('/') @route('/')
def index(): def index():
return ''' return '''<html><body>
<html><body> <h1>crypto in a bottle</h1>
<h1>crypto in a bottle</h1> <ul><li>
<ul><li> <form action="/cryptopen" method="POST">Passwort eingeben:
<form action="/cryptopen" method="POST">Passwort eingeben: <input name="passwd" type="password" /> <input type="submit" value=" Datenhafen &ouml;ffnen ">
<input name="passwd" type="password" /> <input type="submit" value=" Datenhafen &ouml;ffnen "> </form></li><li>
</form></li><li> <form action="/cryptclose" ><input type="submit" value=" Datenhafen abschliessen ">
<form action="/cryptclose" ><input type="submit" value=" Datenhafen abschliessen "> </form></li></ul><hr />
</form></li></ul><hr /> %s
%s </body></html> ''' % (cryptstatus())
</body></html>
''' % (cryptstatus())
@route('/status') @route('/status')
def cryptstatus(): def cryptstatus():
shell = Popen([cryptcmd, "status", mappername], stdout=PIPE, stderr=PIPE) shell = Popen([cryptcmd, "status", mappername], stdout=PIPE, stderr=PIPE)
(cryptsetup_out, err) = shell.communicate() (cryptsetup_out, err) = shell.communicate()
if len(err) != 0: if err:
return '''<h1>cryptsetup error</h1> <pre>%s</pre> ''' % err return '''<h1>cryptsetup error</h1> <pre>%s</pre> ''' % err
if len(cryptsetup_out) == 0: if len(cryptsetup_out) == 0:
cryptsetup_out = '<p>"%s%s" is not mapped</p>' % (mapperpath, mappername) cryptsetup_out = '<p>"%s%s" is not mapped</p>' % (mapperpath, mappername)
@ -48,9 +47,9 @@ def cryptstatus():
df_out = shell.communicate()[0] df_out = shell.communicate()[0]
return '''<h1>cryptsetup status</h1> return '''<h1>cryptsetup status</h1>
<pre>%s</pre> <pre>%s</pre>
<h1>df -h</h1> <h1>df -h</h1>
<pre>%s</pre> ''' % (cryptsetup_out, df_out) <pre>%s</pre> ''' % (cryptsetup_out, df_out)
@route('/cryptopen', method='POST') @route('/cryptopen', method='POST')
@ -63,23 +62,30 @@ password is empty<br />
shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE) shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE)
(cryptsetup_out, err) = shell.communicate(cryptpw) (cryptsetup_out, err) = shell.communicate(cryptpw)
if len(err) != 0: if err:
return '''<h1>cryptsetup error</h1><pre>%s</pre> 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: if len(cryptsetup_out) == 0:
cryptsetup_out = '<p>Einh&auml;ngen war erfolgreich!</p>' 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() (mount_out, err) = shell.communicate()
return '''<meta http-equiv="refresh" content="2; URL=/"> return '''<meta http-equiv="refresh" content="2; URL=/">
<pre>%s</pre> <pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % (cryptsetup_out) <a href=\"/\">zur&uuml;ck</a> ''' % cryptsetup_out
@route('/cryptclose') @route('/cryptclose')
def 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) shell = Popen([umntcmd, mntpoint], stdout=PIPE,stderr=PIPE)
(umount_out, err) = shell.communicate() (umount_out, err) = shell.communicate()
@ -87,14 +93,14 @@ def cryptclose():
(cryptsetup_out, err) = shell.communicate() (cryptsetup_out, err) = shell.communicate()
if len(err) != 0: if len(err) != 0:
return '''<h1>cryptsetup error</h1> <pre>%s</pre> 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: if len(cryptsetup_out) == 0:
cryptsetup_out = '<p>Aush&auml;ngen war erfolgreich!</p>' cryptsetup_out = '<p>Aush&auml;ngen war erfolgreich!</p>'
return '''<meta http-equiv="refresh" content="2; URL=/"> return '''<meta http-equiv="refresh" content="2; URL=/">
<pre>%s</pre> <pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % (cryptsetup_out) <a href=\"/\">zur&uuml;ck</a> ''' % (cryptsetup_out)
debug(True) debug(True)