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