coffin

secure lan file storage on a device
git clone git://parazyd.org/coffin.git
Log | Files | Refs | Submodules | README | LICENSE

commit f7a9f52b2508eff9381a644bb13e87f9ed7b6f9c
parent cc17987e9314c3d746a5ea585f46c766e3a2a8d6
Author: parazyd <parazyd@dyne.org>
Date:   Mon, 28 Mar 2016 15:33:39 +0200

tomb deletion function

Diffstat:
M.gitignore | 1+
Msrc/sacrist | 10++++++----
Msrc/zlibs/features | 27++++++++++++++++++++-------
Msrc/zlibs/hooks | 46+++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 70 insertions(+), 14 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1 +1,2 @@ NOTES.md +.*.swp diff --git a/src/sacrist b/src/sacrist @@ -7,7 +7,7 @@ coffin_version=0.2 coffin_release_date="Mar/2016" -DEBUG=${DEBUG:-1} +DEBUG=${DEBUG:-1} # NOTE: Change default value to 0 later QUIET=${QUIET:-0} LOG=${LOG:-""} @@ -32,9 +32,9 @@ source $R/zlibs/keyfiles source $R/zlibs/mounts source $R/zlibs/ttab -LOCK=$R/lock # TODO: implement lock +LOCK=$R/.lock [[ -f $LOCK ]] && { warn "Lock found. Wait until finished." && exit } -#touch $LOCK +touch $LOCK device=$1 && xxx "Device: $device" happenz=$2 && xxx "Happenz: $happenz" @@ -54,7 +54,7 @@ TOMBPASSWD="${TOMBPASSWD:-$GRAVEYARD/passwd}" req=(happenz device) #ckreq || { # die "Not called through mourner. Exiting..." -# # clean +# clean # exit #} @@ -76,10 +76,12 @@ act "Version: $coffin_version, $coffin_release_date" fi umount-key $device + rm $LOCK # cleanup & exit } [[ $happenz == "DELETE" ]] && { # TODO: Some kind of endgame + rm $LOCK } diff --git a/src/zlibs/features b/src/zlibs/features @@ -1,7 +1,7 @@ #!/usr/bin/env zsh -check-webdav-hook() { - fn check-webdav-hook +create-webdav-hook() { + fn create-webdav-hook davconf="/etc/apache2/sites-available/coffindav.conf" @@ -19,7 +19,7 @@ check-webdav-hook() { sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' $davconf cat $COFFINDOT/webdav.conf >> $davconf act "Wrote to $davconf" - /etc/init.d/apache2 restart + /etc/init.d/apache2 reload [[ $? = 0 ]] || warn "Apache is funky" rm $COFFINDOT/webdav.conf act "Done setting up WebDAV" @@ -29,11 +29,22 @@ check-webdav-hook() { fi } -delete-webdav-hook() { } +delete-webdav-hook() { + fn delete-webdav-hook $* + req=(tombid) + tombid="$1" + ckreq || return 1 + davconf="/etc/apache2/sites-available/coffindav.conf" -check-sshfs-hook() { - fn check-sshfs-hook + sed -i '/alias\ \/${tombid}/,+10 d' $davconf + /etc/init.d/apache2 reload + [[ $? = 0 ]] || warn "Apache is funky" + act "Deleted WebDAV data" +} + +create-sshfs-hook() { + fn create-sshfs-hook if [[ $entry =~ sshfs && -f $COFFINDOT/sshpubkey ]]; then act "Found SSH data. Setting up..." @@ -46,7 +57,7 @@ check-sshfs-hook() { [[ $? = 0 ]] && act "Wrote to authorized_keys" \ && act "Done setting up SSH" - # TODO: remove SSH key from usb + # NOTE: maybe remove SSH key from usb, consider deletion else act "No SSH data found" fi @@ -64,4 +75,6 @@ delete-sshfs-hook() { grep -v $tombid $authkeys > $tempkeys mv $tempkeys $authkeys + + act "Deleted SSH data" } diff --git a/src/zlibs/hooks b/src/zlibs/hooks @@ -23,7 +23,6 @@ check-hooks() { return 1 fi done - rm $HOOKS } @@ -78,6 +77,47 @@ create-new-tomb() { act "Wrote to ttab and tombpasswd" # Check for features - check-webdav-hook - check-sshfs-hook + create-webdav-hook + create-sshfs-hook +} + +delete-tomb() { + fn delete-tomb + + act "Deleting tomb" + + undertaker=${entry[(ws@:@)2]} && xxx "Undertaker: $undertaker" + tombid=${entry[(ws@:@)2]} && xxx "Tombid: $tombid" + + [[ $(id $undertaker &>/dev/null) ]] || { + die "User $undertaker not found. Exiting..." + return 1 + } + + [[ -f $GRAVEYARD/$tombid.tomb ]] || { + die "Tomb $tombid.tomb not found. Exiting..." + return 1 + } + + [[ -f $COFFINDOT/$tombid.key ]] || { + die "Key of $tombid not found. Exiting..." + return 1 + } + + compare-key + [[ $? = 0 ]] && { + sudo -u $undertaker $TOMB slam $tombid + + grep -v ${undertaker}:${tombid} $TTAB > $TTAB.tmp + [[ $? = 0 ]] && mv $TTAB.tmp $TTAB && \ + act "Removed from ttab" + + grep -v ${keyhash} $TOMBPASSWD > $TOMBPASSWD.tmp + [[ $? = 0 ]] && mv $TOMBPASSWD.tmp $TOMBPASSWD && \ + act "Removed from tombpasswd" + + # Check for features + delete-webdav-hook $tombid + delete-sshfs-hook $undertaker $tombid + } }