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

tazwikiss: add admin plugin
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Apr 03 16:54:16 2011 +0200 (2011-04-03)
parents
children 79eb86e1e0ed
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 $3$2*
9 for i in $(POST); do
10 case "$i" in $2*) chmod 755 $3$i;; esac
11 done
12 }
14 action()
15 {
16 [ "$1" == "admin" ] || return 1
17 curpassword="$(POST curpassword)"
18 secret="admin.secret"
19 if [ -n "$(POST setpassword)" ]; then
20 if [ -z "$curpassword" ]; then # unauthorized
21 if [ ! -s $secret -o "$(cat $secret)" == \
22 "$(echo $(POST password) | md5sum)" ]; then
23 curpassword="$(POST password)"
24 fi
25 fi
26 [ -n "$curpassword" ] && echo $curpassword | md5sum > $secret
27 fi
28 if [ -n "$(POST save)" ]; then
29 cat <<EOT
30 Content-Type: application/octet-stream
31 Content-Length: $(stat -c %s $(POST file))
32 Content-Disposition: attachment; filename=$(POST file)
34 EOT
35 cat $(POST file)
36 exit 0
37 fi
38 [ -n "$(POST restore)" ] && mv -f $(FILE file tmpname) $(POST file)
39 admin_enable locales config- ./
40 admin_enable plugins wkp_ plugins/
41 CONTENT="
42 <table width=\"100%\">
43 <form method=\"post\" action=\"?action=admin\">
44 <tr><td><h2>$MDP</h2></td>
45 <td><input type=\"text\" name=\"password\" />
46 <input type=\"hidden\" name=\"curpassword\" value=\"$curpassword\" />
47 <input type=\"submit\" value=\"$DONE_BUTTON\" name=\"setpassword\" /></td></tr>
48 </form>"
49 [ -z "$curpassword" ] && return 0
50 CONTENT="$CONTENT
51 <form method=\"post\" enctype=\"multipart/form-data\" action=\"?action=admin\">
52 <input type=\"hidden\" name=\"curpassword\" value=\"$curpassword\" />
53 <tr><td><h2>Plugins</h2></td>
54 <td><input type=\"submit\" value=\"$DONE_BUTTON\" name=\"plugins\" /></td></tr>
55 "
56 PAGE_TITLE_link=false
57 editable=false
58 lang="${HTTP_ACCEPT_LANGUAGE%%,*}"
59 PAGE_TITLE="Administration"
60 for i in $plugins_dir/*.sh ; do
61 plugin=
62 eval $(grep ^plugin= $i)
63 [ -n "$plugin" ] || continue
64 eval $(grep ^description= $i)
65 alt="$(grep ^description_$lang= $i)"
66 [ -n "$alt" ] && eval $(echo "$alt" | sed 's/_..=/=/')
67 CONTENT="$CONTENT
68 <tr><td><b>
69 <input type=checkbox $([ -x $i ] && echo 'checked=checked ') name=\"$(basename $i)\" />
70 $plugin</b></td><td><i>$description</i></td></tr>"
71 done
72 CONTENT="$CONTENT
73 </form>
74 <form method=\"post\" enctype=\"multipart/form-data\" action=\"?action=admin\">
75 <input type=\"hidden\" name=\"curpassword\" value=\"$curpassword\" />
76 <tr><td><h2>Locales</h2></td>
77 <td><input type=\"submit\" value=\"$DONE_BUTTON\" name=\"locales\" /></td></tr>
78 "
79 for i in config-*.sh ; do
80 j=${i#config-}
81 j=${j%.sh}
82 [ -n "$j" ] || continue
83 CONTENT="$CONTENT
84 <tr><td><b>
85 <input type=checkbox $([ -x $i ] && echo 'checked=checked ') name=\"$i\" />
86 $j</b></td><td><i>$(. ./$i ; echo $WIKI_TITLE)</i></td></tr>
87 "
88 done
89 CONTENT="$CONTENT
90 </form>
91 <form method=\"post\" action=\"?action=admin\">
92 <input type=\"hidden\" name=\"curpassword\" value=\"$curpassword\" />
93 <tr><td><h2>Configuration</h2></td><td>
94 <select name="file">
95 $(for i in template.html style.css config*.sh; do
96 [ -x $i ] && echo "<option>$i</option>"; done)
97 </select>
98 <input type=\"submit\" value=\"$DONE_BUTTON\" name=\"save\" />
99 <input type=\"submit\" value=\"$RESTORE\" name=\"restore\" /></td></tr>
100 </form>
101 </table>
102 "
103 }