From 143891365650bc0512a9623c61f3f95b4575e1f1 Mon Sep 17 00:00:00 2001 From: lars Date: Mon, 27 Nov 2006 19:25:26 +0000 Subject: [PATCH] renamed python package to cryptobox-server unittests are working again http-error handling implemented --- bin/CryptoBoxWebserver | 8 ++--- bin/cryptobox.conf | 8 +++-- bin/do_unittests.sh | 9 ++++- conf-examples/cryptobox.conf | 16 ++++----- debian/README.Debian | 2 +- debian/control | 13 +++---- ...tobox.default => cryptobox-server.default} | 5 +-- debian/cryptobox-server.dirs | 4 +++ .../{cryptobox.docs => cryptobox-server.docs} | 0 ...box.examples => cryptobox-server.examples} | 0 .../{cryptobox.init => cryptobox-server.init} | 16 ++++----- debian/cryptobox-server.lintian | 1 + debian/cryptobox-server.logrotate | 6 ++++ ...box.manpages => cryptobox-server.manpages} | 0 .../{postinst => cryptobox-server.postinst} | 24 ++++++------- debian/{postrm => cryptobox-server.postrm} | 19 +++++----- debian/{preinst => cryptobox-server.preinst} | 0 debian/{prerm => cryptobox-server.prerm} | 0 debian/cryptobox.lintian | 1 - debian/dirs | 6 ---- debian/rules | 19 +++++----- lang/en.hdf | 14 ++++++++ plugins/date/unittests.py | 4 +-- plugins/disks/unittests.py | 4 +-- plugins/help/unittests.py | 4 +-- plugins/language_selection/unittests.py | 4 +-- plugins/logs/unittests.py | 4 +-- plugins/network/unittests.py | 4 +-- plugins/partition/unittests.py | 4 +-- plugins/plugin_manager/unittests.py | 4 +-- plugins/shutdown/unittests.py | 4 +-- plugins/system_preferences/unittests.py | 4 +-- plugins/user_manager/unittests.py | 4 +-- plugins/volume_automount/unittests.py | 6 ++-- plugins/volume_chpasswd/unittests.py | 4 +-- plugins/volume_details/unittests.py | 4 +-- plugins/volume_format_fs/unittests.py | 4 +-- plugins/volume_mount/unittests.py | 4 +-- plugins/volume_props/unittests.py | 4 +-- plugins/volume_rename/unittests.py | 4 +-- setup.py | 4 +-- src/cryptobox/core/settings.py | 16 ++++----- .../tests/{cryptobox.py => test.cryptobox.py} | 35 +++++++++---------- ...yptoboxtools.py => test.cryptoboxtools.py} | 10 +++--- .../tests/{plugins.py => test.plugins.py} | 0 .../tests/{websites.py => test.websites.py} | 0 src/cryptobox/web/sites.py | 32 ++++++++++++++++- src/cryptobox/web/testclass.py | 4 +-- 48 files changed, 199 insertions(+), 147 deletions(-) rename debian/{cryptobox.default => cryptobox-server.default} (69%) create mode 100644 debian/cryptobox-server.dirs rename debian/{cryptobox.docs => cryptobox-server.docs} (100%) rename debian/{cryptobox.examples => cryptobox-server.examples} (100%) rename debian/{cryptobox.init => cryptobox-server.init} (81%) create mode 100644 debian/cryptobox-server.lintian create mode 100644 debian/cryptobox-server.logrotate rename debian/{cryptobox.manpages => cryptobox-server.manpages} (100%) rename debian/{postinst => cryptobox-server.postinst} (78%) rename debian/{postrm => cryptobox-server.postrm} (70%) rename debian/{preinst => cryptobox-server.preinst} (100%) rename debian/{prerm => cryptobox-server.prerm} (100%) delete mode 100644 debian/cryptobox.lintian delete mode 100644 debian/dirs rename src/cryptobox/tests/{cryptobox.py => test.cryptobox.py} (77%) rename src/cryptobox/tests/{cryptoboxtools.py => test.cryptoboxtools.py} (85%) rename src/cryptobox/tests/{plugins.py => test.plugins.py} (100%) rename src/cryptobox/tests/{websites.py => test.websites.py} (100%) diff --git a/bin/CryptoBoxWebserver b/bin/CryptoBoxWebserver index 2d699bb..73c094a 100755 --- a/bin/CryptoBoxWebserver +++ b/bin/CryptoBoxWebserver @@ -117,11 +117,11 @@ def write_pid_file(pid_file): def parseOptions(): version = "%prog" + cryptobox.core.main.VERSION parser = OptionParser(version=version) - parser.set_defaults(conffile="/etc/cryptobox/webserver.conf", - pidfile="/var/run/cryptobox/webserver.pid", + parser.set_defaults(conffile="/etc/cryptobox-server/cryptobox.conf", + pidfile="/var/run/cryptobox-server/webserver.pid", background=False, - datadir="/usr/share/cryptobox/www-data", - logfile="/var/log/cryptobox/webserver.log", + datadir="/usr/share/cryptobox-server/www-data", + logfile="/var/log/cryptobox-server/webserver.log", port="8080", host="", verbose=True) diff --git a/bin/cryptobox.conf b/bin/cryptobox.conf index a499cbe..e69b6a4 100644 --- a/bin/cryptobox.conf +++ b/bin/cryptobox.conf @@ -24,10 +24,12 @@ ConfigVolumeLabel = cbox_config [Locations] # where should we mount volumes? # this directory must be writeable by the cryptobox user (see above) -MountParentDir = /var/cache/cryptobox/mnt +#MountParentDir = /var/cache/cryptobox/mnt +MountParentDir = ../ttt/mnt # settings directory: contains name database and plugin configuration -SettingsDir = /var/cache/cryptobox/settings +#SettingsDir = /var/cache/cryptobox/settings +SettingsDir = ../ttt/settings # where are the clearsilver templates? #TemplateDir = /usr/share/cryptobox/templates @@ -47,7 +49,7 @@ PluginDir = ../plugins # path to the hook directory (e.g. containing some scripts) #HookDir = /etc/cryptobox/hooks.d -HookDir = ../hook-scripts +EventDir = ../event-scripts [Log] diff --git a/bin/do_unittests.sh b/bin/do_unittests.sh index 6af0d02..ae4a64b 100755 --- a/bin/do_unittests.sh +++ b/bin/do_unittests.sh @@ -3,6 +3,10 @@ # run this script _before_ you do a commit and fix errors before uploading # +BASE_DIR=$(cd "$(dirname $0)/.."; pwd) + +export PYTHONPATH=$BASE_DIR/src + # check if /dev/loop1 is available - otherwise some tests will fail! if /sbin/losetup /dev/loop1 &>/dev/null then true @@ -15,8 +19,11 @@ if /sbin/losetup /dev/loop1 &>/dev/null exit 1 fi +# chdir to 'bin' - all config settings depend on this +cd "${BASE_DIR}/bin" + # do the tests -for a in unittests.*.py +for a in ${BASE_DIR}/src/cryptobox/tests/test.*.py do testoob -v "$a" done diff --git a/conf-examples/cryptobox.conf b/conf-examples/cryptobox.conf index 83c87a4..1ac17a1 100644 --- a/conf-examples/cryptobox.conf +++ b/conf-examples/cryptobox.conf @@ -24,25 +24,25 @@ ConfigVolumeLabel = cbox_config [Locations] # where should we mount volumes? # this directory must be writeable by the cryptobox user (see above) -MountParentDir = /var/cache/cryptobox/mnt +MountParentDir = /var/cache/cryptobox-server/mnt # settings directory: contains name database and plugin configuration -SettingsDir = /var/cache/cryptobox/settings +SettingsDir = /var/cache/cryptobox-server/settings # where are the clearsilver templates? -TemplateDir = /usr/share/cryptobox/templates +TemplateDir = /usr/share/cryptobox-server/templates # path to language files -LangDir = /usr/share/cryptobox/lang +LangDir = /usr/share/cryptobox-server/lang # path to documentation files -DocDir = /usr/share/doc/cryptobox/html +DocDir = /usr/share/doc/cryptobox-server/html # path to the plugin directory -PluginDir = /usr/share/cryptobox/plugins +PluginDir = /usr/share/cryptobox-server/plugins # path to the hook directory (e.g. containing some scripts) -HookDir = /etc/cryptobox/events.d +HookDir = /etc/cryptobox-server/events.d [Log] @@ -59,7 +59,7 @@ Destination = file # details. Possible values for the different destinations are: # file: $FILENAME # syslog: $LOG_FACILITY -Details = /var/log/cryptobox/cryptobox.log +Details = /var/log/cryptobox-server/cryptobox.log [WebSettings] diff --git a/debian/README.Debian b/debian/README.Debian index f06e815..6dc8846 100644 --- a/debian/README.Debian +++ b/debian/README.Debian @@ -1,5 +1,5 @@ CryptoBox for Debian - installation notes be aware of one thing: -1) you need cryptsetup with luks support (for now only in unstable) +1) you need cryptsetup with luks support (for now only in testing) diff --git a/debian/control b/debian/control index 36aa61a..a806b2b 100644 --- a/debian/control +++ b/debian/control @@ -6,15 +6,16 @@ Build-Depends: debhelper (>= 5.0.38), dpatch, python-all-dev (>= 2.4), python-ce XS-Python-Version: >= 2.4 Standards-Version: 3.7.2 -Package: cryptobox +Package: cryptobox-server Architecture: any -Depends: ${python:Depends}, bash (>=2.0), sed (>=4.0), coreutils, grep (>=2.0), cryptsetup (>=20050111), dmsetup, initscripts, e2fsprogs (>= 1.27), adduser, python (>=2.4), python-clearsilver, super, dosfstools, python-cherrypy, python-configobj -Suggests: samba, stunnel, openssl +Depends: ${python:Depends}, cryptsetup (>=20050111), e2fsprogs (>= 1.27), adduser, python (>=2.4), python-clearsilver, super, dosfstools, python-cherrypy, python-configobj +Suggests: samba, apache, stunnel +Replaces: cryptobox XB-Python-Version: ${python:Versions} Description: Web interface for an encrypting fileserver - This web interface allows you to manage the encrypted and plaintext - disks of your system. The data is platform independently available - via samba file shares. + This web interface allows you to manage encrypted and plaintext + disks. + This package is especially useful for non-desktop systems. Even non-technical users are able to encrypt their private data with the CryptoBox. diff --git a/debian/cryptobox.default b/debian/cryptobox-server.default similarity index 69% rename from debian/cryptobox.default rename to debian/cryptobox-server.default index 556f981..d4bea5a 100644 --- a/debian/cryptobox.default +++ b/debian/cryptobox-server.default @@ -11,9 +11,6 @@ RUNAS=cryptobox # listening port PORT=8080 -# log file of the webserver -LOGFILE=/var/log/cryptobox/webserver.log - # some more server options (rarely necessary) -#SERVER_OPTS="--host localhost --datadir=/usr/share/cryptobox/html" +#SERVER_OPTS="--host localhost --datadir=/usr/share/cryptobox-server/html" diff --git a/debian/cryptobox-server.dirs b/debian/cryptobox-server.dirs new file mode 100644 index 0000000..b12a5dc --- /dev/null +++ b/debian/cryptobox-server.dirs @@ -0,0 +1,4 @@ +usr/sbin +usr/share/cryptobox-server +var/log/cryptobox-server +var/run/cryptobox-server diff --git a/debian/cryptobox.docs b/debian/cryptobox-server.docs similarity index 100% rename from debian/cryptobox.docs rename to debian/cryptobox-server.docs diff --git a/debian/cryptobox.examples b/debian/cryptobox-server.examples similarity index 100% rename from debian/cryptobox.examples rename to debian/cryptobox-server.examples diff --git a/debian/cryptobox.init b/debian/cryptobox-server.init similarity index 81% rename from debian/cryptobox.init rename to debian/cryptobox-server.init index 0cf8ff5..2b2aead 100644 --- a/debian/cryptobox.init +++ b/debian/cryptobox-server.init @@ -8,7 +8,7 @@ # ### BEGIN INIT INFO -# Provides: cryptobox +# Provides: cryptobox-server # Required-Start: $network $local_fs $remote_fs # Required-Stop: $network $local_fs $remote_fs # Default-Start: 2 3 4 5 @@ -18,24 +18,24 @@ # read the default setting file, if it exists -[ -r /etc/default/cryptobox ] && source /etc/default/cryptobox +[ -r /etc/default/cryptobox-server ] && source /etc/default/cryptobox-server -# set default values (if not defined in /etc/default/cryptobox) +# set default values (if not defined in /etc/default/cryptobox-server) NO_START=${NO_START:-0} RUNAS=${RUNAS:-cryptobox} PORT=${PORT:-8080} HOST=${HOST:-} -LOGFILE=${LOGFILE:-/var/log/cryptobox/webserver.log} +LOGFILE=/var/log/cryptobox-server/webserver.log SERVER_OPTS=${SERVER_OPTS:-} -CONF_FILE=/etc/cryptobox/cryptobox.conf +CONF_FILE=/etc/cryptobox-server/cryptobox.conf -# quit if NO_START is 1 (see /etc/default/cryptobox) +# quit if NO_START is 1 (see /etc/default/cryptobox-server) [ "$NO_START" = "1" ] && exit 0 DAEMON=/usr/sbin/CryptoBoxWebserver -PIDFILE=/var/run/cryptobox/webserver.pid +PIDFILE=/var/run/cryptobox-server/webserver.pid DESC="CryptoBox Daemon (webinterface)" -OPTIONS="-B --pidfile=$PIDFILE --config=$CONF_FILE $SERVER_OPTS" +OPTIONS="-B --pidfile=$PIDFILE --config=$CONF_FILE --logfile=$LOGFILE --host=$HOST --port=$PORT $SERVER_OPTS" # check if the package is installed test -e "$DAEMON" || exit 0 diff --git a/debian/cryptobox-server.lintian b/debian/cryptobox-server.lintian new file mode 100644 index 0000000..2b4a0e9 --- /dev/null +++ b/debian/cryptobox-server.lintian @@ -0,0 +1 @@ +cryptobox-server: package-has-a-duplicate-relation diff --git a/debian/cryptobox-server.logrotate b/debian/cryptobox-server.logrotate new file mode 100644 index 0000000..35ae3e7 --- /dev/null +++ b/debian/cryptobox-server.logrotate @@ -0,0 +1,6 @@ +/var/log/cryptobox-server/cryptobox.log /var/log/cryptobox-server/webserver.log { + rotate 2 + size 100k + copytruncate + nocompress +} diff --git a/debian/cryptobox.manpages b/debian/cryptobox-server.manpages similarity index 100% rename from debian/cryptobox.manpages rename to debian/cryptobox-server.manpages diff --git a/debian/postinst b/debian/cryptobox-server.postinst similarity index 78% rename from debian/postinst rename to debian/cryptobox-server.postinst index 42ae618..d5468b1 100644 --- a/debian/postinst +++ b/debian/cryptobox-server.postinst @@ -1,19 +1,19 @@ #!/bin/sh -LOG_FILE=/var/log/cryptobox/cryptobox.log -WEBLOG_FILE=/var/log/cryptobox/webserver.log -PID_DIR=/var/run/cryptobox -CRYPTOBOX_USER=cryptobox -USER_HOME=/var/cache/cryptobox +set -u + +# check the current cryptobox user - maybe it was changed manually +test -r /etc/default/cryptobox-server && . /etc/default/cryptobox-server + +# RUNAS was probably imported from /etc/default/cryptobox-server - otherwise use the default +CRYPTOBOX_USER=${RUNAS:-cryptobox} +LOG_FILE=/var/log/cryptobox-server/cryptobox.log +WEBLOG_FILE=/var/log/cryptobox-server/webserver.log +PID_DIR=/var/run/cryptobox-server +USER_HOME=/var/cache/cryptobox-server SUPER_FILE=/etc/super.tab ADDITIONAL_GROUP=disk -# check the current cryptobox user - maybe it was changed -if test -r /etc/default/cryptobox - then runas_user=$(grep "^RUNAS=" /etc/default/cryptobox | cut -d "=" -f 2) - test -n "$runas_user" && CRYPTOBOX_USER=$runas_user - fi - create_user_home() { @@ -55,7 +55,7 @@ create_dirs_and_files() #################### main ###################### case "$1" in - configure) + reconfigure|configure) create_user_home create_dirs_and_files create_add_super_permission diff --git a/debian/postrm b/debian/cryptobox-server.postrm similarity index 70% rename from debian/postrm rename to debian/cryptobox-server.postrm index fcdb53f..fc2d7aa 100644 --- a/debian/postrm +++ b/debian/cryptobox-server.postrm @@ -1,11 +1,14 @@ #!/bin/sh -LOG_FILE=/var/log/cryptobox/cryptobox.log -WEBLOG_FILE=/var/log/cryptobox/webserver.log -PID_DIR=/var/run/cryptobox +set -u + +CRYPTOBOX_USER=cryptobox +LOG_FILE=/var/log/cryptobox-server/cryptobox.log +WEBLOG_FILE=/var/log/cryptobox-server/webserver.log +PID_DIR=/var/run/cryptobox-server SUPER_FILE=/etc/super.tab -MNT_DIR=/var/cache/cryptobox/mnt -SETTINGS_DIR=/var/cache/cryptobox/settings +MNT_DIR=/var/cache/cryptobox-server/mnt +SETTINGS_DIR=/var/cache/cryptobox-server/settings remove_super_lines() { @@ -43,10 +46,10 @@ remove_stuff() umount_all # remove the user -if test "$1" = "purge" && getent passwd cryptobox 2>/dev/null >/dev/null \ - && test "$(cd ~cryptobox;pwd)" = /var/cache/cryptobox +if test "$1" = "purge" && getent passwd "$CRYPTOBOX_USER" 2>/dev/null >/dev/null \ + && test "$(getent passwd $CRYPTOBOX_USER | cut -d : -f 6)" = /var/cache/cryptobox-server then echo "Removing user 'cryptobox' ..." - userdel -r cryptobox + userdel -r "$CRYPTOBOX_USER" fi # always remove the lines from the 'super' configuration file diff --git a/debian/preinst b/debian/cryptobox-server.preinst similarity index 100% rename from debian/preinst rename to debian/cryptobox-server.preinst diff --git a/debian/prerm b/debian/cryptobox-server.prerm similarity index 100% rename from debian/prerm rename to debian/cryptobox-server.prerm diff --git a/debian/cryptobox.lintian b/debian/cryptobox.lintian deleted file mode 100644 index 4942d86..0000000 --- a/debian/cryptobox.lintian +++ /dev/null @@ -1 +0,0 @@ -cryptobox: package-has-a-duplicate-relation diff --git a/debian/dirs b/debian/dirs deleted file mode 100644 index 815d726..0000000 --- a/debian/dirs +++ /dev/null @@ -1,6 +0,0 @@ -etc/cryptobox -etc/cryptobox/events.d -etc/default -etc/init.d -usr/share/cryptobox -usr/sbin diff --git a/debian/rules b/debian/rules index 44f7fca..19ca397 100755 --- a/debian/rules +++ b/debian/rules @@ -12,7 +12,7 @@ # necessary for dpatch .NOTPARALLEL: -DEB_BUILD_DIR=$(CURDIR)/debian/cryptobox +DEB_BUILD_DIR=$(CURDIR)/debian/cryptobox-server CB_PYDIR=$(DEB_BUILD_DIR)/usr/lib/python$(shell pyversions -vr)/site-packages/cryptobox @@ -31,7 +31,7 @@ clean-patched: python setup.py clean rm -f build-stamp rm -rf build - find -type f -name '*.py[co]' | xargs rm -f + find -type f -name '*.py[co]' -print0 | xargs -0 rm -f rm -f MANIFEST dh_clean @@ -58,16 +58,11 @@ install: build # remove duplicate documentation files rm -r $(CB_PYDIR)/doc # move shared files - install -d -m 755 $(DEB_BUILD_DIR)/usr/share/cryptobox - mv $(CB_PYDIR)/share/* $(DEB_BUILD_DIR)/usr/share/cryptobox/ + mv $(CB_PYDIR)/share/* $(DEB_BUILD_DIR)/usr/share/cryptobox-server/ rmdir $(CB_PYDIR)/share - # create log directory - install -d -m 755 $(DEB_BUILD_DIR)/var/log/cryptobox - # create pid directory - install -d -m 755 $(DEB_BUILD_DIR)/var/run/cryptobox # install lintian override file: for multiple dependency caused by {python:Depends} - install -D -m 644 debian/cryptobox.lintian \ - $(DEB_BUILD_DIR)/usr/share/lintian/overrides/cryptobox + install -D -m 644 debian/cryptobox-server.lintian \ + $(DEB_BUILD_DIR)/usr/share/lintian/overrides/cryptobox-server # Build architecture-independent files here. @@ -81,11 +76,13 @@ binary-arch: build install dh_installdocs dh_installexamples dh_installlogrotate + dh_installdirs dh_installman dh_install dh_pycentral @# pycentral must be called before installinit - otherwise the DEBHELPER part - @# in the postinst script is filled in the wrong order + @# in the postinst script is filled in the wrong order - this causes a failing + @# shutdown after removal, as the "pycentral pkgremove" call stops the daemon before dh_installinit dh_compress dh_fixperms diff --git a/lang/en.hdf b/lang/en.hdf index 684030d..ac36aab 100644 --- a/lang/en.hdf +++ b/lang/en.hdf @@ -59,6 +59,20 @@ WarningMessage { Link.Text = Deactivate volume Link.Rel = volume_mount } + + InvalidAction { + Title = Invalid request + Text = Sorry - I do not know how to handle this request. If you think, that this is a bug, then you should send the most recent part of the CryptoBox log to info@cryptobox.org. + Link.Text = View log + Link.Rel = logs + } + + RuntimeError { + Title = Something weird happened + Text = We (the developer of the CryptoBox) would like to fix this problem for you and others. Please send the most recent part of the CryptoBox log to info@cryptobox.org. Thanks for your contribution! + Link.Text = View log + Link.Rel = logs + } } diff --git a/plugins/date/unittests.py b/plugins/date/unittests.py index 82f1faa..cd94f31 100644 --- a/plugins/date/unittests.py +++ b/plugins/date/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_get_date(self): date = self._getCurrentDate() diff --git a/plugins/disks/unittests.py b/plugins/disks/unittests.py index e7cdf34..d632e0d 100644 --- a/plugins/disks/unittests.py +++ b/plugins/disks/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): '''display all devices''' diff --git a/plugins/help/unittests.py b/plugins/help/unittests.py index f1e1f97..94cb4b8 100644 --- a/plugins/help/unittests.py +++ b/plugins/help/unittests.py @@ -1,7 +1,7 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass from twill.errors import * -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_help_pages(self): '''help pages should be available in different languages''' diff --git a/plugins/language_selection/unittests.py b/plugins/language_selection/unittests.py index 6e9b349..a70f47d 100644 --- a/plugins/language_selection/unittests.py +++ b/plugins/language_selection/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "language_selection?weblang=en" diff --git a/plugins/logs/unittests.py b/plugins/logs/unittests.py index 25b7727..68cb8ef 100644 --- a/plugins/logs/unittests.py +++ b/plugins/logs/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_logs(self): log_url = self.URL + "logs" diff --git a/plugins/network/unittests.py b/plugins/network/unittests.py index 0a04f59..5380fe9 100644 --- a/plugins/network/unittests.py +++ b/plugins/network/unittests.py @@ -1,8 +1,8 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass from network import CHANGE_IP_DELAY -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_ip_change(self): '''change of network address''' diff --git a/plugins/partition/unittests.py b/plugins/partition/unittests.py index c2f5512..2c2fbd2 100644 --- a/plugins/partition/unittests.py +++ b/plugins/partition/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "partition?weblang=en" diff --git a/plugins/plugin_manager/unittests.py b/plugins/plugin_manager/unittests.py index e5a9165..c545e86 100644 --- a/plugins/plugin_manager/unittests.py +++ b/plugins/plugin_manager/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "plugin_manager?weblang=en" diff --git a/plugins/shutdown/unittests.py b/plugins/shutdown/unittests.py index baa0308..5edf587 100644 --- a/plugins/shutdown/unittests.py +++ b/plugins/shutdown/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "shutdown" diff --git a/plugins/system_preferences/unittests.py b/plugins/system_preferences/unittests.py index 5e0e862..5e410d7 100644 --- a/plugins/system_preferences/unittests.py +++ b/plugins/system_preferences/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_preferences_overview(self): self.cmd.go(self.URL + "system_preferences?weblang=en") diff --git a/plugins/user_manager/unittests.py b/plugins/user_manager/unittests.py index d2622f2..4560715 100644 --- a/plugins/user_manager/unittests.py +++ b/plugins/user_manager/unittests.py @@ -1,9 +1,9 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass ## this user may not be removed from user_manager import RESERVED_USERS -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_users(self): cur_users = self._getUsers() diff --git a/plugins/volume_automount/unittests.py b/plugins/volume_automount/unittests.py index 5483807..0aeedba 100644 --- a/plugins/volume_automount/unittests.py +++ b/plugins/volume_automount/unittests.py @@ -1,11 +1,11 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "volume_automount?weblang=en&device=%2Fdev%2Floop1" self.register_auth(url) self.cmd.go(url) - self.cmd.find('automatic') + self.cmd.find('Activate') self.cmd.find('startup') diff --git a/plugins/volume_chpasswd/unittests.py b/plugins/volume_chpasswd/unittests.py index b8567ed..d566e0d 100644 --- a/plugins/volume_chpasswd/unittests.py +++ b/plugins/volume_chpasswd/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "volume_chpasswd?weblang=en&device=%2Fdev%2Floop1" diff --git a/plugins/volume_details/unittests.py b/plugins/volume_details/unittests.py index 0b5a451..ba49db9 100644 --- a/plugins/volume_details/unittests.py +++ b/plugins/volume_details/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "volume_details?weblang=en&device=%2Fdev%2Floop1" diff --git a/plugins/volume_format_fs/unittests.py b/plugins/volume_format_fs/unittests.py index c55a8a9..88f5516 100644 --- a/plugins/volume_format_fs/unittests.py +++ b/plugins/volume_format_fs/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "volume_format_fs?weblang=en&device=%2Fdev%2Floop1" diff --git a/plugins/volume_mount/unittests.py b/plugins/volume_mount/unittests.py index 9a3e1ee..4840fa7 100644 --- a/plugins/volume_mount/unittests.py +++ b/plugins/volume_mount/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "volume_mount?weblang=en&device=%2Fdev%2Floop1" diff --git a/plugins/volume_props/unittests.py b/plugins/volume_props/unittests.py index e91a78d..fe235c6 100644 --- a/plugins/volume_props/unittests.py +++ b/plugins/volume_props/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "volume_props?weblang=en&device=%2Fdev%2Floop1" diff --git a/plugins/volume_rename/unittests.py b/plugins/volume_rename/unittests.py index 59fece9..3325dd5 100644 --- a/plugins/volume_rename/unittests.py +++ b/plugins/volume_rename/unittests.py @@ -1,6 +1,6 @@ -import WebInterfaceTestClass +import cryptobox.web.testclass -class unittests(WebInterfaceTestClass.WebInterfaceTestClass): +class unittests(cryptobox.web.testclass.WebInterfaceTestClass): def test_read_form(self): url = self.URL + "volume_rename?weblang=en&device=%2Fdev%2Floop1" diff --git a/setup.py b/setup.py index 3a3156a..b7b85ba 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ datadir = os.path.join(pydir, 'share') ## doc dir docdir = os.path.join(pydir, 'doc') ## configuration directory -confdir = os.path.join(os.path.sep, 'etc', 'cryptobox') +confdir = os.path.join(os.path.sep, 'etc', 'cryptobox-server') def listfiles(prefix,src): @@ -51,7 +51,7 @@ def getdatafiles(prefix,dirs): setup( - name = 'cryptobox', + name = 'cryptobox-server', version = '0.3.0', description = 'webinterface for handling encrypted disks', author = 'Lars Kruse', diff --git a/src/cryptobox/core/settings.py b/src/cryptobox/core/settings.py index 23f9ff1..0bf8b97 100644 --- a/src/cryptobox/core/settings.py +++ b/src/cryptobox/core/settings.py @@ -18,7 +18,7 @@ class CryptoBoxSettings: CONF_LOCATIONS = [ "./cryptobox.conf", "~/.cryptobox.conf", - "/etc/cryptobox/cryptobox.conf"] + "/etc/cryptobox-server/cryptobox.conf"] VOLUMESDB_FILE = "cryptobox_volumes.db" PLUGINCONF_FILE = "cryptobox_plugins.conf" @@ -358,13 +358,13 @@ UseConfigPartition = integer(min=0, max=1, default=0) DisabledPlugins = list(default=[]) [Locations] -MountParentDir = directoryExists(default="/var/cache/cryptobox/mnt") -SettingsDir = directoryExists(default="/var/cache/cryptobox/settings") -TemplateDir = directoryExists(default="/usr/share/cryptobox/template") -LangDir = directoryExists(default="/usr/share/cryptobox/lang") -DocDir = directoryExists(default="/usr/share/doc/cryptobox/www-data") -PluginDir = directoryExists(default="/usr/share/cryptobox/plugins") -EventDir = directoryExists(default="/etc/cryptobox/events.d") +MountParentDir = directoryExists(default="/var/cache/cryptobox-server/mnt") +SettingsDir = directoryExists(default="/var/cache/cryptobox-server/settings") +TemplateDir = directoryExists(default="/usr/share/cryptobox-server/template") +LangDir = directoryExists(default="/usr/share/cryptobox-server/lang") +DocDir = directoryExists(default="/usr/share/doc/cryptobox-server/www-data") +PluginDir = directoryExists(default="/usr/share/cryptobox-server/plugins") +EventDir = string(default="/etc/cryptobox-server/events.d") [Log] Level = option("debug", "info", "warn", "error", default="warn") diff --git a/src/cryptobox/tests/cryptobox.py b/src/cryptobox/tests/test.cryptobox.py similarity index 77% rename from src/cryptobox/tests/cryptobox.py rename to src/cryptobox/tests/test.cryptobox.py index 9ee1fd4..171c953 100755 --- a/src/cryptobox/tests/cryptobox.py +++ b/src/cryptobox/tests/test.cryptobox.py @@ -2,13 +2,12 @@ import unittest import sys -from CryptoBox import * -from CryptoBoxExceptions import * -import CryptoBoxSettings +import cryptobox.core.main +from cryptobox.core.exceptions import * +import cryptobox.core.settings class CryptoBoxPropsDeviceTests(unittest.TestCase): - import CryptoBox - cb = CryptoBox.CryptoBoxProps() + cb = cryptobox.core.main.CryptoBoxProps() def testAllowedDevices(self): '''isDeviceAllowed should accept permitted devices''' @@ -27,8 +26,6 @@ class CryptoBoxPropsDeviceTests(unittest.TestCase): class CryptoBoxPropsConfigTests(unittest.TestCase): '''test here if everything with the config turns right''' import os - import CryptoBox - files = { "configFileOK" : "cbox-test_ok.conf", "configFileBroken" : "cbox-test_broken.conf", @@ -91,35 +88,35 @@ CryptoBoxRootActions = CryptoBoxRootActions def testConfigInit(self): '''Check various branches of config file loading''' import os - self.assertRaises(CBConfigUnavailableError, self.CryptoBox.CryptoBoxProps,"/invalid/path/to/config/file") - self.assertRaises(CBConfigUnavailableError, self.CryptoBox.CryptoBoxProps,"/etc/shadow") + self.assertRaises(CBConfigUnavailableError, cryptobox.core.main.CryptoBoxProps,"/invalid/path/to/config/file") + self.assertRaises(CBConfigUnavailableError, cryptobox.core.main.CryptoBoxProps,"/etc/shadow") """ check one of the following things: 1) are we successfully using an existing config file? 2) do we break, if no config file is there? depending on the existence of a config file, only one of these conditions can be checked - hints for more comprehensive tests are appreciated :) """ - for a in CryptoBoxSettings.CryptoBoxSettings.CONF_LOCATIONS: + for a in ['cryptobox.conf']: if os.path.exists(a): - self.CryptoBox.CryptoBoxProps() + cryptobox.core.main.CryptoBoxProps() break # this skips the 'else' clause - else: self.assertRaises(CBConfigUnavailableError, self.CryptoBox.CryptoBoxProps) - self.assertRaises(CBConfigUnavailableError, self.CryptoBox.CryptoBoxProps,[]) + else: self.assertRaises(CBConfigUnavailableError, cryptobox.core.main.CryptoBoxProps) + self.assertRaises(CBConfigUnavailableError, cryptobox.core.main.CryptoBoxProps,[]) def testBrokenConfigs(self): """Check various broken configurations""" self.writeConfig("SettingsDir", "SettingsDir=/foo/bar", filename=self.filenames["configFileBroken"]) - self.assertRaises(CBConfigError, self.CryptoBox.CryptoBoxProps,self.filenames["configFileBroken"]) + self.assertRaises(CBConfigError, cryptobox.core.main.CryptoBoxProps,self.filenames["configFileBroken"]) self.writeConfig("Level", "Level = ho", filename=self.filenames["configFileBroken"]) - self.assertRaises(CBConfigError, self.CryptoBox.CryptoBoxProps,self.filenames["configFileBroken"]) + self.assertRaises(CBConfigError, cryptobox.core.main.CryptoBoxProps,self.filenames["configFileBroken"]) self.writeConfig("Details", "#out", filename=self.filenames["configFileBroken"]) - self.assertRaises(CBConfigError, self.CryptoBox.CryptoBoxProps,self.filenames["configFileBroken"]) + self.assertRaises(CBConfigError, cryptobox.core.main.CryptoBoxProps,self.filenames["configFileBroken"]) self.writeConfig("super", "super=/bin/invalid/no", filename=self.filenames["configFileBroken"]) - self.assertRaises(CBConfigError, self.CryptoBox.CryptoBoxProps,self.filenames["configFileBroken"]) + self.assertRaises(CBConfigError, cryptobox.core.main.CryptoBoxProps,self.filenames["configFileBroken"]) self.writeConfig("CryptoBoxRootActions", "#not here", filename=self.filenames["configFileBroken"]) - self.assertRaises(CBConfigError, self.CryptoBox.CryptoBoxProps,self.filenames["configFileBroken"]) + self.assertRaises(CBConfigError, cryptobox.core.main.CryptoBoxProps,self.filenames["configFileBroken"]) self.writeConfig("CryptoBoxRootActions", "CryptoBoxRootActions = /bin/false", filename=self.filenames["configFileBroken"]) - self.assertRaises(CBEnvironmentError, self.CryptoBox.CryptoBoxProps,self.filenames["configFileBroken"]) + self.assertRaises(CBEnvironmentError, cryptobox.core.main.CryptoBoxProps,self.filenames["configFileBroken"]) def writeConfig(self, replace=None, newline=None, filename=None): diff --git a/src/cryptobox/tests/cryptoboxtools.py b/src/cryptobox/tests/test.cryptoboxtools.py similarity index 85% rename from src/cryptobox/tests/cryptoboxtools.py rename to src/cryptobox/tests/test.cryptoboxtools.py index 10daf4e..2823a4d 100755 --- a/src/cryptobox/tests/cryptoboxtools.py +++ b/src/cryptobox/tests/test.cryptoboxtools.py @@ -1,21 +1,21 @@ #!/usr/bin/env python2.4 import unittest -import CryptoBoxTools +import cryptobox.core.tools as cbxTools import os class CryptoBoxToolsTests(unittest.TestCase): def testGetAbsoluteDeviceName(self): - func = CryptoBoxTools.getAbsoluteDeviceName + func = cbxTools.getAbsoluteDeviceName self.assertTrue(func("hda") == "/dev/hda") self.assertTrue(func("loop0") == "/dev/loop0") self.assertTrue(func(os.path.devnull) == os.path.devnull) def testFindMajorMinorOfDevice(self): - func = CryptoBoxTools.findMajorMinorOfDevice + func = cbxTools.findMajorMinorOfDevice self.assertTrue(func("/dev/hda") == (3,0)) self.assertTrue(func("/dev/hda1") == (3,1)) self.assertTrue(func(os.path.devnull) == (1,3)) @@ -23,7 +23,7 @@ class CryptoBoxToolsTests(unittest.TestCase): def testFindMajorMinorDeviceName(self): - func = CryptoBoxTools.findMajorMinorDeviceName + func = cbxTools.findMajorMinorDeviceName dir = os.path.join(os.path.sep, "dev") self.assertTrue(os.path.join(dir,"hda") in func(dir,3,0)) self.assertTrue(os.path.devnull in func(dir,1,3)) @@ -31,7 +31,7 @@ class CryptoBoxToolsTests(unittest.TestCase): def testIsPartOfBlockDevice(self): - func = CryptoBoxTools.isPartOfBlockDevice + func = cbxTools.isPartOfBlockDevice self.assertTrue(func("/dev/hda", "/dev/hda1")) self.assertFalse(func("/dev/hda", "/dev/hda")) self.assertFalse(func("/dev/hda1", "/dev/hda")) diff --git a/src/cryptobox/tests/plugins.py b/src/cryptobox/tests/test.plugins.py similarity index 100% rename from src/cryptobox/tests/plugins.py rename to src/cryptobox/tests/test.plugins.py diff --git a/src/cryptobox/tests/websites.py b/src/cryptobox/tests/test.websites.py similarity index 100% rename from src/cryptobox/tests/websites.py rename to src/cryptobox/tests/test.websites.py diff --git a/src/cryptobox/web/sites.py b/src/cryptobox/web/sites.py index 4650e28..9049e04 100644 --- a/src/cryptobox/web/sites.py +++ b/src/cryptobox/web/sites.py @@ -42,6 +42,8 @@ class WebInterfaceSites: self.log = logging.getLogger("CryptoBox") self.prefs = self.cbox.prefs self.__resetDataset() + ## store the original http error handler + self._cp_on_http_error = self.newHTTPErrorHandler def __resetDataset(self): @@ -128,7 +130,35 @@ class WebInterfaceSites: param_dict = {"weblang":weblang} ## render "disks" plugin by default return self.return_plugin_action(self.pluginList.getPlugin("disks"))(**param_dict) - + + def newHTTPErrorHandler(self, errorCode, message): + ## we ignore uninteresting not-found errors + if (errorCode == 404) and \ + (cherrypy.request.path.startswith("/cryptobox-misc/") or \ + cherrypy.request.path in ['/robots.txt','/favicon.ico']): + cherrypy.response.status = errorCode + return + ## an invalid action was requested + if errorCode == 404: + ## we send a not-found error (with the usual interface) + cherrypy.response.status = errorCode + self.dataset["Data.Warning"] = "InvalidAction" + cherrypy.response.body = self.__render("empty") + return + ## are there still bugs in the code? + if errorCode == 500: + ## we fix the error code (200 is "OK") + cherrypy.response.status = 200 + ## TODO: 'message' is None - we should check a stack trace or something? + self.cbox.log.warn("HTTP-ERROR[500] - a runtime error occoured: %s" % str(message)) + self.dataset["Data.Warning"] = "RuntimeError" + cherrypy.response.body = self.__render("empty") + return + ## unknown error type + cherrypy.response.status = errorCode + self.cbox.log.warn("HTTP-ERROR[%d] - an unknown error occoured: %s" % (errorCode, message)) + cherrypy.response.body = self.__render("empty") + def return_plugin_action(self, plugin): def handler(self, **args): diff --git a/src/cryptobox/web/testclass.py b/src/cryptobox/web/testclass.py index fa1d6ae..1eff640 100644 --- a/src/cryptobox/web/testclass.py +++ b/src/cryptobox/web/testclass.py @@ -7,7 +7,7 @@ just inherit this class and add some test functions import unittest import twill import cherrypy -import cryptobox.web.dataset +import cryptobox.web.sites ## we do the following, for easy surfing ## e.g. use: cbx.go(your_url) @@ -42,7 +42,7 @@ class WebInterfaceTestClass(unittest.TestCase): 'server.threadPool': 1, 'server.environment': 'production', }) - cherrypy.root = cryptobox.web.dataset.WebInterfaceSites() + cherrypy.root = cryptobox.web.sites.WebInterfaceSites() cherrypy.server.start(initOnly=True, serverClass=None) from cherrypy._cpwsgi import wsgiApp