slitaz-dev-tools view tazwikiss/rootfs/var/www/wiki/plugins/wkp_Admin.sh @ rev 120

tazwikiss/wkp_Admin: shrink to 4K, add section separators
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jun 19 14:03:36 2011 +0200 (2011-06-19)
parents d2a15f85b581
children 229bf48d394c
line source
1 plugin="<a href=\"?action=admin\">Administration</a>"
2 description_fr="Administration du Wiki"
3 description="Wiki administration"
5 admin_enable()
6 {
7 [ -n "$(POST $1)" ] || return
8 chmod 0 $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 curpassword="$(POST curpassword)"
47 secret="admin.secret"
48 if [ -n "$(POST setpassword)" ]; then
49 if [ -z "$curpassword" ]; then # unauthorized
50 if [ ! -s $secret -o "$(cat $secret)" == \
51 "$(echo $(POST password) | md5sum)" ]; then
52 curpassword="$(POST password)"
53 fi
54 fi
55 [ -n "$curpassword" ] && echo $curpassword | md5sum > $secret
56 fi
57 if [ -n "$(POST save)" ]; then
58 admin_download $(POST file)
59 exit 0
60 fi
61 [ -n "$(POST restore)" ] && mv -f $(FILE data tmpname) $(POST file)
62 admin_enable locales config- config_ ./
63 admin_enable plugins wkp_ wkp_ plugins/
64 disabled="disabled=disabled"
65 [ -n "$curpassword" ] && disabled="" &&
66 curpassword="<input type=\"hidden\" name=\"curpassword\" value=\"$curpassword\" />
67 "
68 hr="$curpassword<tr><td colspan=2><hr /></td><tr />"
69 CONTENT="
70 <table width=\"100%\">
71 <form method=\"post\" action=\"?action=admin\">
72 <tr><td><h2>$MDP</h2></td>
73 <td><input type=\"text\" name=\"password\" />$curpassword
74 <input type=\"submit\" value=\"$DONE_BUTTON\" name=\"setpassword\" /></td></tr>
75 </form>
76 <form method=\"post\" enctype=\"multipart/form-data\" action=\"?action=admin\">
77 $hr
78 <tr><td><h2>Plugins</h2></td>
79 <td><input type=\"submit\" $disabled value=\"$DONE_BUTTON\" name=\"plugins\" /></td></tr>
80 "
81 for i in $plugins_dir/*.sh ; do
82 plugin=
83 eval $(grep ^plugin= $i)
84 [ -n "$plugin" ] || continue
85 eval $(grep ^description= $i)
86 alt="$(grep ^description_$lang= $i)"
87 [ -n "$alt" ] && eval $(echo "$alt" | sed 's/_..=/=/')
88 CONTENT="$CONTENT
89 <tr><td><b>
90 <input type=checkbox $disabled $([ -x $i ] && echo 'checked=checked ') name=\"$(basename $i .sh)\" />
91 $plugin</b></td><td><i>$description</i></td></tr>"
92 done
93 CONTENT="$CONTENT
94 </form>
95 <form method=\"post\" enctype=\"multipart/form-data\" action=\"?action=admin\">
96 $hr
97 <tr><td><h2>Locales</h2></td>
98 <td><input type=\"submit\" $disabled value=\"$DONE_BUTTON\" name=\"locales\" /></td></tr>
99 "
100 for i in config-*.sh ; do
101 j=${i#config-}
102 j=${j%.sh}
103 [ -n "$j" ] && CONTENT="$CONTENT
104 <tr><td><b>
105 <input type=checkbox $disabled $([ -x $i ] && echo 'checked=checked ') name=\"config_$j\" />
106 $j</b></td><td><i>$(. ./$i ; echo $WIKI_TITLE)</i></td></tr>
107 "
108 done
109 CONTENT="$CONTENT
110 </form>
111 <form method=\"post\" enctype=\"multipart/form-data\" action=\"?action=admin\">
112 $hr
113 <tr><td><h2>Configuration</h2></td>
114 <td><select name="file" $disabled>
115 $(for i in template.html style.css config*.sh; do
116 [ -x $i ] && echo "<option>$i</option>"; done)
117 </select>
118 <input type=\"submit\" $disabled value=\"$DONE_BUTTON\" name=\"save\" />
119 <input type=\"file\" $disabled name=\"data\" />
120 <input type=\"submit\" $disabled value=\"$RESTORE\" name=\"restore\" /></td></tr>
121 </form>
122 <form method=\"post\" enctype=\"multipart/form-data\" action=\"?action=backup\">
123 $hr
124 <tr><td><h2>Data</h2></td>
125 <td><input type=\"submit\" $disabled name=\"save\" value=\"$DONE_BUTTON\" />
126 <input type=\"file\" $disabled name=\"file\" value=\"file\" />
127 <input type=\"submit\" $disabled name=\"restore\" value=\"$RESTORE\" />
128 </td></tr>
129 $(du -hs */ | sed 's|\(.*\)\t\(.*\)|<tr><td><b>\1</b></td><td><i>\2</i></td></tr>|')
130 </form>
131 </table>
132 "
133 }