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

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 08:23:49 2019 +0100 (2019-02-26)
parents 39a1656c8f04
children
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 PAGE_TITLE="Administration"
45 curpass="$(POST curpass)"
46 secret="admin.secret"
47 if [ -n "$(POST setpass)" ]; then
48 if [ -z "$curpass" ]; then # unauthorized
49 if [ ! -s $secret -o "$(cat $secret 2> /dev/null)" = \
50 "$(echo $(POST password) | md5sum)" ]; then
51 curpass="$(POST password)"
52 fi
53 fi
54 [ -n "$curpass" ] && echo $curpass | md5sum > $secret &&
55 chmod 400 $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 admin_enable Pages '' page pages
65 disabled="disabled=disabled"
66 [ -n "$curpass" ] && disabled="" &&
67 curpass="<input type=\"hidden\" name=\"curpass\" value=\"$curpass\" />
68 "
69 hr="$curpass<tr><td colspan=2><hr /></td><tr />"
70 CONTENT="
71 <table width=\"100%\">
72 <form method=\"post\" action=\"?action=admin\">
73 <tr><td><h2>$MDP</h2></td>
74 <td><input type=\"text\" name=\"password\" />$curpass
75 <input type=\"submit\" value=\"$DONE_BUTTON\" name=\"setpass\" /></td></tr>
76 </form>
77 "
78 mform="form method=\"post\" enctype=\"multipart/form-data\" action=\"?action"
79 while read section files test; do
80 CONTENT="$CONTENT
81 <$mform=admin\">
82 $hr
83 <tr><td><h2>$section</h2></td>
84 <td><input type=\"submit\" $disabled value=\"$DONE_BUTTON\" name=\"$section\" /></td></tr>
85 "
86 for i in $files ; do
87 case "$section" in
88 Plugins)
89 plugin=
90 eval $(grep ^plugin= $i)
91 [ -n "$plugin" ] || continue
92 eval $(grep ^description= $i)
93 alt="$(grep ^description_$LANG= $i)"
94 [ -n "$alt" ] && eval $(echo "$alt" | sed 's/_..=/=/')
95 help=
96 eval $(grep ^help= $i)
97 alt="$(grep ^help_$LANG= $i)"
98 [ -n "$alt" ] && eval $(echo "$alt" | sed 's/_..=/=/')
99 name="$(basename $i .sh)"
100 [ -n "$help" ] && description=" <a href='?page=$help' title='$plugin help page'>$description</a>"
101 ;;
102 Locales)
103 j=${i#config-}
104 j=${j%.sh}
105 [ -n "$j" ] || continue
106 name="config_$j"
107 plugin="$j"
108 description="$(. ./$i ; echo $WIKI_TITLE)"
109 ;;
110 Pages)
111 j="$(basename $i .txt)"
112 plugin="<a href=\"?page=$j\">$j</a>"
113 name="page$j"
114 description="$([ -w $i ] || echo -n $PROTECTED_BUTTON)"
115 ;;
116 esac
117 CONTENT="$CONTENT
118 <tr><td><b>
119 <input type=checkbox $disabled $([ $test $i ] && echo 'checked=checked ') name=\"$name\" />
120 $plugin</b></td><td><i>$description</i></td></tr>"
121 done
122 CONTENT="$CONTENT</form>"
123 done <<EOT
124 Plugins $plugins_dir/*.sh -x
125 Locales config-*.sh -x
126 Pages pages/*.txt -w
127 EOT
128 CONTENT="$CONTENT
129 <$mform=admin\">
130 $hr
131 <tr><td><h2>Configuration</h2></td>
132 <td><select name="file" $disabled>
133 $(for i in template.html style.css config*.sh; do
134 [ -x $i ] && echo "<option>$i</option>"; done)
135 </select>
136 <input type=\"submit\" $disabled value=\"$DONE_BUTTON\" name=\"save\" />
137 <input type=\"file\" $disabled name=\"data\" />
138 <input type=\"submit\" $disabled value=\"$RESTORE\" name=\"restore\" /></td></tr>
139 </form>
140 <$mform=backup\">
141 $hr
142 <tr><td><h2>Data</h2></td>
143 <td><input type=\"submit\" $disabled name=\"save\" value=\"$DONE_BUTTON\" />
144 <input type=\"file\" $disabled name=\"file\" value=\"file\" />
145 <input type=\"submit\" $disabled name=\"restore\" value=\"$RESTORE\" />
146 </td></tr>
147 $(du -hs */ | sed 's|\(.*\)\t\(.*\)|<tr><td><b>\1</b></td><td><i>\2</i></td></tr>|')
148 </form>
149 </table>
150 "
151 }