tfeature-webdav - coffin - secure lan file storage on a device
HTML git clone git://parazyd.org/coffin.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
tfeature-webdav (2160B)
---
1 #!/usr/bin/env zsh
2 #
3 # Copyright (c) 2016 Dyne.org Foundation
4 # coffin is written and maintained by Ivan J. <parazyd@dyne.org>
5 #
6 # This file is part of coffin
7 #
8 # This source code is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This software is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this source code. If not, see <http://www.gnu.org/licenses/>.
20
21 create-webdav-hook() {
22 fn create-webdav-hook
23 req=(entry COFFINDOT davconf davpass undertaker tombid)
24 local davconf="/etc/apache2/sites-available/coffindav.conf"
25 local davpass="/etc/apache2/DAV/davpasswd"
26 ckreq || return 1
27
28 if [[ $entry =~ webdav && -f $COFFINDOT/davpasswd ]]; then
29 act "Found WebDAV data. Setting up..."
30
31 cat $COFFINDOT/davpasswd >> $davpass
32 [[ $? = 0 ]] || {
33 die "Failed setting up WebDAV."
34 return 1 }
35
36 rm $COFFINDOT/davpasswd
37 gpasswd -a www-data $undertaker # NOTE: consider standalone group
38
39 sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' $davconf
40 cat <<EOF >> $davconf
41
42 alias /${tombid} /media/${tombid}
43 <Directory "/media/${tombid}">
44 Dav On
45 AllowOverride none
46 Options Indexes
47 AuthType Digest
48 AuthName WebDAV
49 AuthUserFile /etc/apache2/DAV/davpasswd
50 Require user ${undertaker}
51 </Directory>
52
53 </VirtualHost>
54 </IfModule>
55 EOF
56 act "Wrote to $davconf"
57 /etc/init.d/apache2 reload || warn "Apache is funky"
58 # rm $COFFINDOT/webdav.conf
59 act "Done setting up WebDAV"
60 else
61 act "No WebDAV data found"
62 return 0
63 fi
64 }
65
66 delete-webdav-hook() {
67 fn delete-webdav-hook $*
68 freq=(davconf)
69 local davconf="/etc/apache2/sites-available/coffindav.conf"
70 ckreq || return 1
71
72 sed -i '/alias\ \/${tombid}/,+10 d' $davconf
73 /etc/init.d/apache2 reload || warn "Apache is funky"
74 act "Deleted WebDAV data"
75 }