Passwort eingeben
+ +output {{foo}}
+{{output[foo]}}+
diff --git a/CryptoBottle/CryptoBottle.py b/CryptoBottle/CryptoBottle.py index 2036303..82bc446 100755 --- a/CryptoBottle/CryptoBottle.py +++ b/CryptoBottle/CryptoBottle.py @@ -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 '''
-%s''' % err - if len(cryptsetup_out) == 0: - cryptsetup_out = '
"%s%s" is not mapped
' % (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 '''%s-
%s''' % (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 '''
%s- zurück ''' % err - - if len(cryptsetup_out) == 0: - cryptsetup_out = '
Einhängen war erfolgreich!
' - - shell = Popen([mntcmd, join(mapperpath, mappername), mntpoint], stdout=PIPE,stderr=PIPE) - (mount_out, err) = shell.communicate() - - return ''' -%s- zurück ''' % cryptsetup_out + cryptsetup = 'kein Passwort angegeben' + else: + shell = Popen([cryptcmd, "luksOpen", cryptdevice, mappername], stdin=PIPE, stdout=PIPE,stderr=PIPE) + (cryptsetup, err) = shell.communicate(cryptpw) + if err: + cryptsetup = err + elif len(cryptsetup) == 0: + cryptsetup = 'erfolgreich entschluesselt' + shell = Popen([mntcmd, join(mapperpath, mappername), mntpoint], stdout=PIPE,stderr=PIPE) + (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ängen nicht möglich. Verzeichnis wird noch benutzt. -
%s&pre> ''' % (mntpoint, lsof_out) - - shell = Popen([umntcmd, mntpoint], stdout=PIPE,stderr=PIPE) - (umount_out, err) = shell.communicate() + 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, 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 '''cryptsetup error
%s- zurück ''' % err - - if len(cryptsetup_out) == 0: - cryptsetup_out = 'Aushängen war erfolgreich!
' - - return ''' -%s- zurück ''' % (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) diff --git a/CryptoBottle/style/default.css b/CryptoBottle/style/default.css new file mode 100644 index 0000000..527a47f --- /dev/null +++ b/CryptoBottle/style/default.css @@ -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; +} diff --git a/CryptoBottle/views/generic.tpl b/CryptoBottle/views/generic.tpl new file mode 100644 index 0000000..c517561 --- /dev/null +++ b/CryptoBottle/views/generic.tpl @@ -0,0 +1,52 @@ + + + + +CryptoBottle + + + +++ +++ ++ ++ + +sense.lab
+++++ +Crypto.Bottle0.2
+ a minimalist webfrontend for cryptsetup ++ %for foo in output: + %if foo == 'passwd': ++++ %elif output[foo]: +Passwort eingeben
+ +++ %end + %end +output {{foo}}
+{{output[foo]}}+