From 66cf3a013e6687632df455b3f879cae990d0d458 Mon Sep 17 00:00:00 2001 From: age Date: Wed, 9 Jan 2008 00:29:41 +0000 Subject: [PATCH] * sed in the webdav event script now works * share names must not have any whitespaces --- event-scripts/apache2_dav | 42 ++++++++++++++++++++------------- src/cryptobox/core/container.py | 2 +- src/cryptobox/web/sites.py | 2 +- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/event-scripts/apache2_dav b/event-scripts/apache2_dav index 2e8dd19..da4e121 100755 --- a/event-scripts/apache2_dav +++ b/event-scripts/apache2_dav @@ -1,12 +1,12 @@ #!/bin/sh +# To make this event script work add the apache2_dav.conf file +# from /usr/share/doc/cryptobox/conf-examples/ to your apache +# configuration directory (e.g. /etc/apache2/conf.d) # -# Manage apache webdav +# This event script manages apache webdav # - after mounting: add the new webdav share # - before umounting: disable and remove the webdav share # -# This script assumes, that you added the apache2_dav.conf file -# (/usr/share/doc/cryptobox/conf-examples/) to your apache configuration directory -# (e.g. /etc/apache2/conf.d) # # # Params: $event $device $volume_name $volume_type $mount_dir @@ -24,19 +24,21 @@ set -eu # adapt this part of the file to your setup APACHE_SCRIPT=/etc/init.d/apache2 -APACHE_CONF_DIR=/var/cache/cryptobox/settings/misc/apache2_dav.conf.d +APACHE_CONF_DIR=/var/cache/cryptobox-server/settings/misc/apache2_dav.conf.d # this apache config snippet is used for every published volume # _VOLUME_NAME_ and _SHARE_DIR_ are replaced by their actual values APACHE_SHARE_TEMPLATE=$(cat - <<-"EOF" - # this file is part of the CryptoBox - Alias "/cryptobox/_VOLUME_NAME_" "_SHARE_DIR_" - - Dav filesystem + Alias "/cryptonas/_VOLUME_NAME_" "_SHARE_DIR_" + # this is an automatically generarted file for the CryptoNAS + # please do not change + + \tDav filesystem EOF ) +# no need for changes from here on.. # -----=-=-=- check arguments and the environment -=-=-=---- # exit if apache2 is not installed @@ -47,7 +49,11 @@ if test -x "$APACHE_SCRIPT" fi # create include-file directory -mkdir -p "$APACHE_CONF_DIR" +if test ! -d ${APACHE_CONF_DIR} + echo "apache2_dav include-file directory does not exist, creating it" >&2 + then mkdir -p ${APACHE_CONF_DIR} + chmod 775 ${APACHE_CONF_DIR} +fi # check event argument if test "$#" -eq 0 @@ -59,9 +65,11 @@ event=$1 # ------------=-=-=- some functions -=-=-=----------------- -# remove invalid config files +# keep the include file directory clean update_include_conf_dir() { + # if a webdav alias is given but no corresponding mount dir exists + # then remove the includefile find "$APACHE_CONF_DIR" -type f -name "*.conf" | while read fname do mdir=$(head -1 "$fname" | cut -f 4 -d '"') test ! -d "$mdir" && rm "$fname" @@ -85,16 +93,16 @@ case "$event" in premount|postumount ) ;; postmount ) - vol_name=$3 - mount_dir=$5 - echo "$APACHE_SHARE_TEMPLATE" | sed "s#_SHARE_DIR_#$mount_dir#g; s#_VOLUME_NAME_#$vol_name#g" >"$APACHE_CONF_DIR/${vol_name}.conf" - update_include_conf_dir + vol_name="$3" + mountdir="$5" + echo "$APACHE_SHARE_TEMPLATE" | sed s\#_SHARE_DIR_\#"$mountdir"\#g | sed s\#_VOLUME_NAME_\#"$vol_name"\#g > ${APACHE_CONF_DIR}/${vol_name}.conf + #update_include_conf_dir send_reload_command ;; preumount ) - vol_name=$3 + vol_name="$3" rm "$APACHE_CONF_DIR/${vol_name}.conf" || true - update_include_conf_dir + #update_include_conf_dir send_reload_command ;; shutdown | bootup ) diff --git a/src/cryptobox/core/container.py b/src/cryptobox/core/container.py index 9e1075e..b14d479 100644 --- a/src/cryptobox/core/container.py +++ b/src/cryptobox/core/container.py @@ -108,7 +108,7 @@ class CryptoBoxContainer: ## is the same as the volume name if self.is_mounted(): raise CBVolumeIsActive("the container must not be active during renaming") - if not re.search(r'^[a-zA-Z0-9_\.\- ]+$', new_name): + if not re.search(r'^[a-zA-Z0-9_\.\-]+$', new_name): raise CBInvalidName("the supplied new name contains illegal characters") ## check for another partition with the same name if self.cbox.get_container_list(filter_name=new_name): diff --git a/src/cryptobox/web/sites.py b/src/cryptobox/web/sites.py index 7d3c6c1..a637893 100644 --- a/src/cryptobox/web/sites.py +++ b/src/cryptobox/web/sites.py @@ -347,7 +347,7 @@ class WebInterfaceSites: self.__dataset[key] = value ## check if the device is busy if plugin.device and self.cbox.get_container(plugin.device).is_busy(): - return self.__render("volume_busy") + return self.__render("volume_busy") ## call the plugin handler next_template = plugin.do_action(**args) ## for 'volume' plugins: reread the dataset of the current disk