From 114208504e1d7c840722338307e7c2b5f054c8f5 Mon Sep 17 00:00:00 2001 From: age Date: Fri, 20 Jul 2012 08:22:08 +0000 Subject: [PATCH] Lars' Anmerkungen eingepflegt --- CryptoBottle/CryptoBottle.py | 56 ++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/CryptoBottle/CryptoBottle.py b/CryptoBottle/CryptoBottle.py index 11890cc..2036303 100755 --- a/CryptoBottle/CryptoBottle.py +++ b/CryptoBottle/CryptoBottle.py @@ -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 ''' - -

crypto in a bottle

-
-%s - -''' % (cryptstatus()) + return ''' +

crypto in a bottle

+
+ %s + ''' % (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 '''

cryptsetup error

%s
''' % err if len(cryptsetup_out) == 0: cryptsetup_out = '

"%s%s" is not mapped

' % (mapperpath, mappername) @@ -48,9 +47,9 @@ def cryptstatus(): df_out = shell.communicate()[0] return '''

cryptsetup status

-
%s
-

df -h

-
%s
''' % (cryptsetup_out, df_out) +
%s
+

df -h

+
%s
''' % (cryptsetup_out, df_out) @route('/cryptopen', method='POST') @@ -63,23 +62,30 @@ password is empty
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 '''

cryptsetup error

%s
-zurück ''' % err + zurück ''' % err if len(cryptsetup_out) == 0: cryptsetup_out = '

Einhängen war erfolgreich!

' - 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 ''' -
%s
-zurück ''' % (cryptsetup_out) +
%s
+ zurück ''' % cryptsetup_out @route('/cryptclose') def cryptclose(): + shell = Popen(["lsof", mntpoint], stdout=PIPE) + lsof_out = shell.communicate()[0] + if lsof_out: + return '''Aushängen nicht möglich. Verzeichnis wird noch benutzt. +

lsof %s

+
%s ''' % (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 '''

cryptsetup error

%s
-zurück ''' % err + zurück ''' % err if len(cryptsetup_out) == 0: cryptsetup_out = '

Aushängen war erfolgreich!

' return ''' -
%s
-zurück ''' % (cryptsetup_out) +
%s
+ zurück ''' % (cryptsetup_out) debug(True)