wok-tiny view wiki/stuff/var/www/wiki/plugins/wkp_Admin.sh @ rev 100

Update wiki, add module-serial
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 31 16:32:19 2015 +0100 (2015-10-31)
parents
children 3de5e6325aab
line source
1 plugin="<a href=\"?action=admin\" title=\"Wiki administration\">Administration</a>"
2 description_fr="Administration du Wiki"
3 description="Wiki administration"
5 admin_enable()
6 {
7 [ -n "$(POST $1)" ] || return
8 chmod 444 $4/$2*
9 for i in $(POST); do
10 case "$i" in $3*) chmod 755 $4/${i/$3/$2}.* ;; esac
11 done
12 }
14 admin_download()
15 {
16 cat - $1 <<EOT
17 Content-Type: application/octet-stream
18 Content-Length: $(stat -c %s $1)
19 Content-Disposition: attachment; filename=${2:-$1}
21 EOT
22 }
24 action()
25 {
26 case "$1" in
27 list|config|admin);;
28 backup) file=$(FILE file tmpname)
29 if [ -z "$file" ]; then
30 file=$(mktemp -p /tmp)
31 find */ | cpio -o -H newc | gzip -9 > $file
32 admin_download $file wiki-$(date '+%Y%m%d%H%M').cpio.gz
33 rm -f $file
34 exit 0
35 else
36 zcat $file | cpio -idmu $(echo */ | sed 's|/||g')
37 rm -rf $(dirname $file)
38 return 1
39 fi ;;
40 *) return 1 ;;
41 esac
42 PAGE_TITLE_link=false
43 editable=false
44 lang="${HTTP_ACCEPT_LANGUAGE%%[,;_-]*}"
45 PAGE_TITLE="Administration"
46 curpass="$(POST curpass)"
47 secret="admin.secret"
48 if [ -n "$(POST setpass)" ]; then
49 if [ -z "$curpass" ]; then # unauthorized
50 if [ ! -s $secret -o "$(cat $secret 2> /dev/null)" == \
51 "$(echo $(POST password) | md5sum)" ]; then
52 curpass="$(POST password)"
53 fi
54 fi
55 [ -n "$curpass" ] && echo $curpass | md5sum > $secret &&
56 chmod 400 $secret
57 fi
58 if [ -n "$(POST save)" ]; then
59 admin_download $(POST file)
60 exit 0
61 fi
62 [ -n "$(POST restore)" ] && mv -f $(FILE data tmpname) $(POST file)
63 admin_enable Locales config- config_ .
64 admin_enable Plugins wkp_ wkp_ plugins
65 admin_enable Pages '' page pages
66 disabled="disabled=disabled"
67 [ -n "$curpass" ] && disabled="" &&
68 curpass="<input type=\"hidden\" name=\"curpass\" value=\"$curpass\" />
69 "
70 hr="$curpass<tr><td colspan=2><hr /></td><tr />"
71 CONTENT="
72 <table width=\"100%\">
73 <form method=\"post\" action=\"?action=admin\">
74 <tr><td><h2>$MDP</h2></td>
75 <td><input type=\"text\" name=\"password\" />$curpass
76 <input type=\"submit\" value=\"$DONE_BUTTON\" name=\"setpass\" /></td></tr>
77 </form>
78 "
79 mform="form method=\"post\" enctype=\"multipart/form-data\" action=\"?action"
80 while read section files test; do
81 CONTENT="$CONTENT
82 <$mform=admin\">
83 $hr
84 <tr><td><h2>$section</h2></td>
85 <td><input type=\"submit\" $disabled value=\"$DONE_BUTTON\" name=\"$section\" /></td></tr>
86 "
87 for i in $files ; do
88 case "$section" in
89 Plugins)
90 plugin=
91 eval $(grep ^plugin= $i)
92 [ -n "$plugin" ] || continue
93 eval $(grep ^description= $i)
94 alt="$(grep ^description_$lang= $i)"
95 [ -n "$alt" ] && eval $(echo "$alt" | sed 's/_..=/=/')
96 help=
97 eval $(grep ^help= $i)
98 alt="$(grep ^help_$lang= $i)"
99 [ -n "$alt" ] && eval $(echo "$alt" | sed 's/_..=/=/')
100 name="$(basename $i .sh)"
101 [ -n "$help" ] && description=" <a href='?page=$help' title='$plugin help page'>$description</a>"
102 ;;
103 Locales)
104 j=${i#config-}
105 j=${j%.sh}
106 [ -n "$j" ] || continue
107 name="config_$j"
108 plugin="$j"
109 description="$(. ./$i ; echo $WIKI_TITLE)"
110 ;;
111 Pages)
112 j="$(basename $i .txt)"
113 plugin="<a href=\"?page=$j\">$j</a>"
114 name="page$j"
115 description="$([ -w $i ] || echo -n $PROTECTED_BUTTON)"
116 ;;
117 esac
118 CONTENT="$CONTENT
119 <tr><td><b>
120 <input type=checkbox $disabled $([ $test $i ] && echo 'checked=checked ') name=\"$name\" />
121 $plugin</b></td><td><i>$description</i></td></tr>"
122 done
123 CONTENT="$CONTENT</form>"
124 done <<EOT
125 Plugins $plugins_dir/*.sh -x
126 Locales config-*.sh -x
127 Pages pages/*.txt -w
128 EOT
129 CONTENT="$CONTENT
130 <$mform=admin\">
131 $hr
132 <tr><td><h2>Configuration</h2></td>
133 <td><select name="file" $disabled>
134 $(for i in template.html style.css config*.sh; do
135 [ -x $i ] && echo "<option>$i</option>"; done)
136 </select>
137 <input type=\"submit\" $disabled value=\"$DONE_BUTTON\" name=\"save\" />
138 <input type=\"file\" $disabled name=\"data\" />
139 <input type=\"submit\" $disabled value=\"$RESTORE\" name=\"restore\" /></td></tr>
140 </form>
141 <$mform=backup\">
142 $hr
143 <tr><td><h2>Data</h2></td>
144 <td><input type=\"submit\" $disabled name=\"save\" value=\"$DONE_BUTTON\" />
145 <input type=\"file\" $disabled name=\"file\" value=\"file\" />
146 <input type=\"submit\" $disabled name=\"restore\" value=\"$RESTORE\" />
147 </td></tr>
148 $(du -hs */ | sed 's|\(.*\)\t\(.*\)|<tr><td><b>\1</b></td><td><i>\2</i></td></tr>|')
149 </form>
150 </table>
151 "
152 }