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" set all variables before the first run & create "mntpoint"
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, template, debug, TEMPLATES, static_file
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from os.path import join from os.path import join
@ -17,91 +17,86 @@ mntcmd = "/bin/mount"
umntcmd = "/bin/umount" umntcmd = "/bin/umount"
cryptdevice = "/dev/vdc1" cryptdevice = "/dev/vdc1"
mapperpath = "/dev/mapper/" mapperpath = "/dev/mapper/"
mappername = "vdc1_crypt" mappername = "vdc1"
mntpoint = "/mnt" mntpoint = "/mnt"
@route('/style/default.css')
def server_static():
return static_file('default.css', root='/data/cryptobottle-dev/style')
@route('/') @route('/')
def index(): def index():
return '''<html><body> output = {'passwd':'Datenhafen oeffnen'}
<h1>crypto in a bottle</h1> return template('generic', output=output)
<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') @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, err) = shell.communicate()
if err: if err:
return '''<h1>cryptsetup error</h1> <pre>%s</pre> ''' % err return template('generic', output= {'cryptsetup':err})
if len(cryptsetup_out) == 0: if len(cryptsetup) == 0:
cryptsetup_out = '<p>"%s%s" is not mapped</p>' % (mapperpath, mappername) cryptsetup = '"%s%s" is not mapped' % (mapperpath, mappername)
shell = Popen(["df", "-h"], stdout=PIPE) shell = Popen(["df", "-h"], stdout=PIPE)
df_out = shell.communicate()[0] (df, err) = shell.communicate()
if err:
return '''<h1>cryptsetup status</h1> return template('generic', output= {'df':err})
<pre>%s</pre> status = ''
<h1>df -h</h1> shell = Popen(["lsof", mntpoint], stdout=PIPE)
<pre>%s</pre> ''' % (cryptsetup_out, df_out) lsof = shell.communicate()[0]
output = {'cryptsetup': cryptsetup, 'df': df, 'lsof': lsof}
return template('generic', output=output )
@route('/cryptopen', method='POST') @route('/cryptopen', method='POST')
def cryptopen(): def cryptopen():
cryptpw = request.forms.get('passwd') cryptpw = request.forms.get('passwd')
mount = ''
if len(cryptpw) == 0: if len(cryptpw) == 0:
return '''<h1>cryptsetup error</h1> cryptsetup = 'kein Passwort angegeben'
password is empty<br /> else:
<a href=\"/\">zur&uuml;ck</a> ''' shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE)
(cryptsetup, err) = shell.communicate(cryptpw)
shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE) if err:
(cryptsetup_out, err) = shell.communicate(cryptpw) cryptsetup = err
if err: elif len(cryptsetup) == 0:
return '''<h1>cryptsetup error</h1><pre>%s</pre> cryptsetup = 'erfolgreich entschluesselt'
<a href=\"/\">zur&uuml;ck</a> ''' % err shell = Popen([mntcmd, join(mapperpath, mappername), mntpoint], stdout=PIPE,stderr=PIPE)
(mount, mount_err) = shell.communicate()
if len(cryptsetup_out) == 0: if mount_err:
cryptsetup_out = '<p>Einh&auml;ngen war erfolgreich!</p>' mount = mount_err
elif len(mount) == 0:
shell = Popen([mntcmd, join(mapperpath, mappername), mntpoint], stdout=PIPE,stderr=PIPE) mount = 'erfolgreich eingehangen'
(mount_out, err) = shell.communicate()
return '''<meta http-equiv="refresh" content="2; URL=/">
<pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % cryptsetup_out
output = {'cryptsetup': cryptsetup, 'mount': mount}
return template('generic', output=output )
@route('/cryptclose') @route('/cryptclose')
def cryptclose(): def cryptclose():
output = {}
umount = ''
shell = Popen(["lsof", mntpoint], stdout=PIPE) shell = Popen(["lsof", mntpoint], stdout=PIPE)
lsof_out = shell.communicate()[0] lsof = shell.communicate()[0]
if lsof_out: if lsof:
return '''Aush&auml;ngen nicht m&ouml;glich. Verzeichnis wird noch benutzt. lsof += 'Aushaengen nicht moeglich. Verzeichnis wird noch benutzt.'
<h1>lsof %s</h1> output = {'lsof':lsof}
<pre>%s</&pre> ''' % (mntpoint, lsof_out) else:
shell = Popen([umntcmd, mntpoint], stdout=PIPE,stderr=PIPE)
shell = Popen([umntcmd, mntpoint], stdout=PIPE,stderr=PIPE) (umount, umount_err) = shell.communicate()
(umount_out, 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) shell = Popen([cryptcmd, "luksClose", mappername], stdout=PIPE,stderr=PIPE)
(cryptsetup_out, err) = shell.communicate() (cryptsetup, err) = shell.communicate()
if len(err) != 0: if len(err) != 0:
return '''<h1>cryptsetup error</h1> <pre>%s</pre> cryptsetup += err
<a href=\"/\">zur&uuml;ck</a> ''' % err if len(cryptsetup) == 0:
cryptsetup = 'erfolgreich verschluesselt'
if len(cryptsetup_out) == 0: output = {'mount':umount, 'cryptsetup': cryptsetup}
cryptsetup_out = '<p>Aush&auml;ngen war erfolgreich!</p>' return template('generic', output=output)
return '''<meta http-equiv="refresh" content="2; URL=/">
<pre>%s</pre>
<a href=\"/\">zur&uuml;ck</a> ''' % (cryptsetup_out)
debug(True) debug(True)
run(host='', port=serverport, reloader=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>