wok-tiny diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/wiki/stuff/var/www/wiki/plugins/wkp_Admin.sh Sat Oct 31 16:32:19 2015 +0100 1.3 @@ -0,0 +1,152 @@ 1.4 +plugin="<a href=\"?action=admin\" title=\"Wiki administration\">Administration</a>" 1.5 +description_fr="Administration du Wiki" 1.6 +description="Wiki administration" 1.7 + 1.8 +admin_enable() 1.9 +{ 1.10 + [ -n "$(POST $1)" ] || return 1.11 + chmod 444 $4/$2* 1.12 + for i in $(POST); do 1.13 + case "$i" in $3*) chmod 755 $4/${i/$3/$2}.* ;; esac 1.14 + done 1.15 +} 1.16 + 1.17 +admin_download() 1.18 +{ 1.19 + cat - $1 <<EOT 1.20 +Content-Type: application/octet-stream 1.21 +Content-Length: $(stat -c %s $1) 1.22 +Content-Disposition: attachment; filename=${2:-$1} 1.23 + 1.24 +EOT 1.25 +} 1.26 + 1.27 +action() 1.28 +{ 1.29 + case "$1" in 1.30 + list|config|admin);; 1.31 + backup) file=$(FILE file tmpname) 1.32 + if [ -z "$file" ]; then 1.33 + file=$(mktemp -p /tmp) 1.34 + find */ | cpio -o -H newc | gzip -9 > $file 1.35 + admin_download $file wiki-$(date '+%Y%m%d%H%M').cpio.gz 1.36 + rm -f $file 1.37 + exit 0 1.38 + else 1.39 + zcat $file | cpio -idmu $(echo */ | sed 's|/||g') 1.40 + rm -rf $(dirname $file) 1.41 + return 1 1.42 + fi ;; 1.43 + *) return 1 ;; 1.44 + esac 1.45 + PAGE_TITLE_link=false 1.46 + editable=false 1.47 + lang="${HTTP_ACCEPT_LANGUAGE%%[,;_-]*}" 1.48 + PAGE_TITLE="Administration" 1.49 + curpass="$(POST curpass)" 1.50 + secret="admin.secret" 1.51 + if [ -n "$(POST setpass)" ]; then 1.52 + if [ -z "$curpass" ]; then # unauthorized 1.53 + if [ ! -s $secret -o "$(cat $secret 2> /dev/null)" == \ 1.54 + "$(echo $(POST password) | md5sum)" ]; then 1.55 + curpass="$(POST password)" 1.56 + fi 1.57 + fi 1.58 + [ -n "$curpass" ] && echo $curpass | md5sum > $secret && 1.59 + chmod 400 $secret 1.60 + fi 1.61 + if [ -n "$(POST save)" ]; then 1.62 + admin_download $(POST file) 1.63 + exit 0 1.64 + fi 1.65 + [ -n "$(POST restore)" ] && mv -f $(FILE data tmpname) $(POST file) 1.66 + admin_enable Locales config- config_ . 1.67 + admin_enable Plugins wkp_ wkp_ plugins 1.68 + admin_enable Pages '' page pages 1.69 + disabled="disabled=disabled" 1.70 + [ -n "$curpass" ] && disabled="" && 1.71 + curpass="<input type=\"hidden\" name=\"curpass\" value=\"$curpass\" /> 1.72 +" 1.73 + hr="$curpass<tr><td colspan=2><hr /></td><tr />" 1.74 + CONTENT=" 1.75 +<table width=\"100%\"> 1.76 +<form method=\"post\" action=\"?action=admin\"> 1.77 +<tr><td><h2>$MDP</h2></td> 1.78 +<td><input type=\"text\" name=\"password\" />$curpass 1.79 +<input type=\"submit\" value=\"$DONE_BUTTON\" name=\"setpass\" /></td></tr> 1.80 +</form> 1.81 +" 1.82 + mform="form method=\"post\" enctype=\"multipart/form-data\" action=\"?action" 1.83 + while read section files test; do 1.84 + CONTENT="$CONTENT 1.85 +<$mform=admin\"> 1.86 +$hr 1.87 +<tr><td><h2>$section</h2></td> 1.88 +<td><input type=\"submit\" $disabled value=\"$DONE_BUTTON\" name=\"$section\" /></td></tr> 1.89 +" 1.90 + for i in $files ; do 1.91 + case "$section" in 1.92 + Plugins) 1.93 + plugin= 1.94 + eval $(grep ^plugin= $i) 1.95 + [ -n "$plugin" ] || continue 1.96 + eval $(grep ^description= $i) 1.97 + alt="$(grep ^description_$lang= $i)" 1.98 + [ -n "$alt" ] && eval $(echo "$alt" | sed 's/_..=/=/') 1.99 + help= 1.100 + eval $(grep ^help= $i) 1.101 + alt="$(grep ^help_$lang= $i)" 1.102 + [ -n "$alt" ] && eval $(echo "$alt" | sed 's/_..=/=/') 1.103 + name="$(basename $i .sh)" 1.104 + [ -n "$help" ] && description=" <a href='?page=$help' title='$plugin help page'>$description</a>" 1.105 + ;; 1.106 + Locales) 1.107 + j=${i#config-} 1.108 + j=${j%.sh} 1.109 + [ -n "$j" ] || continue 1.110 + name="config_$j" 1.111 + plugin="$j" 1.112 + description="$(. ./$i ; echo $WIKI_TITLE)" 1.113 + ;; 1.114 + Pages) 1.115 + j="$(basename $i .txt)" 1.116 + plugin="<a href=\"?page=$j\">$j</a>" 1.117 + name="page$j" 1.118 + description="$([ -w $i ] || echo -n $PROTECTED_BUTTON)" 1.119 + ;; 1.120 + esac 1.121 + CONTENT="$CONTENT 1.122 +<tr><td><b> 1.123 +<input type=checkbox $disabled $([ $test $i ] && echo 'checked=checked ') name=\"$name\" /> 1.124 +$plugin</b></td><td><i>$description</i></td></tr>" 1.125 + done 1.126 + CONTENT="$CONTENT</form>" 1.127 + done <<EOT 1.128 +Plugins $plugins_dir/*.sh -x 1.129 +Locales config-*.sh -x 1.130 +Pages pages/*.txt -w 1.131 +EOT 1.132 + CONTENT="$CONTENT 1.133 +<$mform=admin\"> 1.134 +$hr 1.135 +<tr><td><h2>Configuration</h2></td> 1.136 +<td><select name="file" $disabled> 1.137 +$(for i in template.html style.css config*.sh; do 1.138 + [ -x $i ] && echo "<option>$i</option>"; done) 1.139 +</select> 1.140 +<input type=\"submit\" $disabled value=\"$DONE_BUTTON\" name=\"save\" /> 1.141 +<input type=\"file\" $disabled name=\"data\" /> 1.142 +<input type=\"submit\" $disabled value=\"$RESTORE\" name=\"restore\" /></td></tr> 1.143 +</form> 1.144 +<$mform=backup\"> 1.145 +$hr 1.146 +<tr><td><h2>Data</h2></td> 1.147 +<td><input type=\"submit\" $disabled name=\"save\" value=\"$DONE_BUTTON\" /> 1.148 +<input type=\"file\" $disabled name=\"file\" value=\"file\" /> 1.149 +<input type=\"submit\" $disabled name=\"restore\" value=\"$RESTORE\" /> 1.150 +</td></tr> 1.151 +$(du -hs */ | sed 's|\(.*\)\t\(.*\)|<tr><td><b>\1</b></td><td><i>\2</i></td></tr>|') 1.152 +</form> 1.153 +</table> 1.154 +" 1.155 +}