nu doch mit template verstyled

This commit is contained in:
age 2012-07-21 20:49:48 +00:00
parent 114208504e
commit fd3eb0a702
3 changed files with 248 additions and 62 deletions

View file

@ -7,7 +7,7 @@
set all variables before the first run & create "mntpoint"
run this script as root
"""
from bottle import route, run, post, request, debug
from bottle import route, run, post, request, template, debug, TEMPLATES, static_file
from subprocess import Popen, PIPE
from os.path import join
@ -17,91 +17,86 @@ mntcmd = "/bin/mount"
umntcmd = "/bin/umount"
cryptdevice = "/dev/vdc1"
mapperpath = "/dev/mapper/"
mappername = "vdc1_crypt"
mappername = "vdc1"
mntpoint = "/mnt"
@route('/style/default.css')
def server_static():
return static_file('default.css', root='/data/cryptobottle-dev/style')
@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())
output = {'passwd':'Datenhafen oeffnen'}
return template('generic', output=output)
@route('/status')
def cryptstatus():
shell = Popen([cryptcmd, "status", mappername], stdout=PIPE, stderr=PIPE)
(cryptsetup_out, err) = shell.communicate()
(cryptsetup, err) = shell.communicate()
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)
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_out = shell.communicate()[0]
return '''<h1>cryptsetup status</h1>
<pre>%s</pre>
<h1>df -h</h1>
<pre>%s</pre> ''' % (cryptsetup_out, df_out)
(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:
return '''<h1>cryptsetup error</h1>
password is empty<br />
<a href=\"/\">zur&uuml;ck</a> '''
cryptsetup = 'kein Passwort angegeben'
else:
shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE)
(cryptsetup_out, err) = shell.communicate(cryptpw)
(cryptsetup, err) = shell.communicate(cryptpw)
if err:
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>'
cryptsetup = err
elif len(cryptsetup) == 0:
cryptsetup = 'erfolgreich entschluesselt'
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
(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_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)
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_out, err) = shell.communicate()
(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_out, err) = shell.communicate()
(cryptsetup, 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)
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)

View file

@ -0,0 +1,139 @@
* {
margin: 0px;
padding: 0px;
}
body {
background-color: #eed;
color: #9f9f9f;
font-size: 11px;
font-family: helvetica, sans-serif;
}
a {
text-decoration: underline;
color: #93B300;
}
a:hover {
text-decoration: none;
color: #50514D;
}
#main {
padding-top: 20px;
position: relative;
width: 680px;
margin: 0px auto;
padding-bottom: 10px;
}
#menu ul {
list-style: none;
margin: 0px;
padding-top: 10px;
}
#menu li {
background: none;
padding: 0px;
font-weight: bold;
}
#menu a {
display: block;
position: relative;
height: 27px;
margin-bottom: 1px;
text-decoration: none;
background: inherit;
padding-left: 20px;
padding-top: 10px;
color: #636363;
font-size: 16px;
}
#menu a:hover {
background: inherit;
color: #222;
border: dotted 1px #50514D;
}
h1 {
background: inherit;
color: #50514D;
height: 50px;
}
h1 span {
background: inherit;
color: #85AC1E;
}
h3 {
margin-top: 10px;
background: inherit;
color: #50514D;
font-size: 19px;
height: 34px;
}
h3 span {
background: inherit;
color: #85AC1E;
}
#lcol {
position: relative;
width: 125px;
float: left;
margin-top: 10px;
padding-top: 50px;
}
#llogo {
position: relative;
padding: 0px 15px 0px 15px;
border-bottom: dotted 1px;
}
#content {
position: relative;
padding: 5px 20px 20px 20px;
font-size: 12px;
}
#rcol {
position: relative;
margin-left: 130px;
width: 560px;
border-left: dotted 1px;
}
#rlogo {
font-size: 18px;
position: relative;
padding: 0px 5px 35px 21px;
}
.output, .form {
background-color: #fff;
padding: 7px 7px 25px 17px;
margin: 5px 0px 5px 0px;
border: dotted 1px #333;
}
#lcol p {
font-size: 10px;
line-height: 16px;
margin: 0px;
}
.pre_inner {
border: dashed 1px #dadada;
font-size: 12px;
padding: 10px;
background: #FFFFE9;
color: inherit;
width: 80;
}

View file

@ -0,0 +1,52 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>CryptoBottle</title>
<link rel="stylesheet" type="text/css" href="/style/default.css" />
</head>
<body>
<div id="main">
<div id="lcol">
<div id="llogo">
<!-- <a href="http://senselab.org" title="Sense.Lab e.V."><img src="foo" title="Logo" /></a> -->
<h3 class="first">sense.<span>lab</span></h3>
</div>
<div id="menu">
<ul>
<li><a href="/">&ouml;ffnen<span></span></a></li>
<li><a href="/cryptclose">schlie&szlig;en<span></span></a></li>
<li><a href="/status">status<span></span></a></li>
</ul>
</div>
</div>
<div id="rcol">
<div id="rlogo">
<h1>Crypto<span>.Bottle<sup>0.2</sup></span></h1>
<span class="slogan2">a minimalist webfrontend for cryptsetup</span>
</div>
<div id="content">
%for foo in output:
%if foo == 'passwd':
<div class="form">
<h3>Passwort <span>eingeben</span></h3>
<form action="/cryptopen" method="POST">
<input name="passwd" type="password" tabindex="1" />
<input type="submit" tabindex="2" value="{{output['passwd']}}">
</form>
</div>
%elif output[foo]:
<div class="output">
<h3>output <span>{{foo}}</span></h3>
<pre class="pre_inner">{{output[foo]}}</pre>
</div>
%end
%end
</div>
</div>
</div>
</body>
</html>