slitaz-dev-tools 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 8b4a54db076c
children 81bcfeba99a6
files tazwikiss/rootfs/var/www/wiki/plugins/wkp_Admin.sh tazwikiss/rootfs/var/www/wiki/plugins/wkp_ListPlugins.sh
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tazwikiss/rootfs/var/www/wiki/plugins/wkp_Admin.sh	Sun Apr 03 16:54:16 2011 +0200
     1.3 @@ -0,0 +1,103 @@
     1.4 +plugin="<a href=\"?action=admin\">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 0 $3$2*
    1.12 +	for i in $(POST); do
    1.13 +		case "$i" in $2*) chmod 755 $3$i;; esac
    1.14 +	done
    1.15 +}
    1.16 +
    1.17 +action()
    1.18 +{
    1.19 +	[ "$1" == "admin" ] || return 1
    1.20 +	curpassword="$(POST curpassword)"
    1.21 +	secret="admin.secret"
    1.22 +	if [ -n "$(POST setpassword)" ]; then
    1.23 +		if [ -z "$curpassword" ]; then	# unauthorized
    1.24 +			if [ ! -s $secret -o "$(cat $secret)" == \
    1.25 +				  "$(echo $(POST password) | md5sum)" ]; then
    1.26 +				curpassword="$(POST password)"
    1.27 +			fi
    1.28 +		fi
    1.29 +		[ -n "$curpassword" ] && echo $curpassword | md5sum > $secret
    1.30 +	fi
    1.31 +	if [ -n "$(POST save)" ]; then
    1.32 +		cat <<EOT
    1.33 +Content-Type: application/octet-stream
    1.34 +Content-Length: $(stat -c %s $(POST file))
    1.35 +Content-Disposition: attachment; filename=$(POST file)
    1.36 +
    1.37 +EOT
    1.38 +		cat $(POST file)
    1.39 +		exit 0
    1.40 +	fi
    1.41 +	[ -n "$(POST restore)" ] && mv -f $(FILE file tmpname) $(POST file)
    1.42 +	admin_enable locales config- ./
    1.43 +	admin_enable plugins wkp_ plugins/
    1.44 +	CONTENT="
    1.45 +<table width=\"100%\">
    1.46 +<form method=\"post\" action=\"?action=admin\">
    1.47 +<tr><td><h2>$MDP</h2></td>
    1.48 +<td><input type=\"text\" name=\"password\" />
    1.49 +<input type=\"hidden\" name=\"curpassword\" value=\"$curpassword\" />
    1.50 +<input type=\"submit\" value=\"$DONE_BUTTON\" name=\"setpassword\" /></td></tr>
    1.51 +</form>"
    1.52 +	[ -z "$curpassword" ] && return 0
    1.53 +	CONTENT="$CONTENT
    1.54 +<form method=\"post\" enctype=\"multipart/form-data\" action=\"?action=admin\">
    1.55 +<input type=\"hidden\" name=\"curpassword\" value=\"$curpassword\" />
    1.56 +<tr><td><h2>Plugins</h2></td>
    1.57 +<td><input type=\"submit\" value=\"$DONE_BUTTON\" name=\"plugins\" /></td></tr>
    1.58 +"
    1.59 +	PAGE_TITLE_link=false
    1.60 +	editable=false
    1.61 +	lang="${HTTP_ACCEPT_LANGUAGE%%,*}"
    1.62 +	PAGE_TITLE="Administration"
    1.63 +	for i in $plugins_dir/*.sh ; do
    1.64 +		plugin=
    1.65 +		eval $(grep ^plugin= $i)
    1.66 +		[ -n "$plugin" ] || continue
    1.67 +		eval $(grep ^description= $i)
    1.68 +		alt="$(grep ^description_$lang= $i)"
    1.69 +		[ -n "$alt" ] && eval $(echo "$alt" | sed 's/_..=/=/')
    1.70 +		CONTENT="$CONTENT
    1.71 +<tr><td><b>
    1.72 +<input type=checkbox $([ -x $i ] && echo 'checked=checked ') name=\"$(basename $i)\" />
    1.73 +$plugin</b></td><td><i>$description</i></td></tr>"
    1.74 +	done
    1.75 +	CONTENT="$CONTENT
    1.76 +</form>
    1.77 +<form method=\"post\" enctype=\"multipart/form-data\" action=\"?action=admin\">
    1.78 +<input type=\"hidden\" name=\"curpassword\" value=\"$curpassword\" />
    1.79 +<tr><td><h2>Locales</h2></td>
    1.80 +<td><input type=\"submit\" value=\"$DONE_BUTTON\" name=\"locales\" /></td></tr>
    1.81 +"
    1.82 +	for i in config-*.sh ; do
    1.83 +		j=${i#config-}
    1.84 +		j=${j%.sh}
    1.85 +		[ -n "$j" ] || continue
    1.86 +	CONTENT="$CONTENT
    1.87 +<tr><td><b>
    1.88 +<input type=checkbox $([ -x $i ] && echo 'checked=checked ') name=\"$i\" />
    1.89 +$j</b></td><td><i>$(. ./$i ; echo $WIKI_TITLE)</i></td></tr>
    1.90 +"
    1.91 +	done
    1.92 +	CONTENT="$CONTENT
    1.93 +</form>
    1.94 +<form method=\"post\" action=\"?action=admin\">
    1.95 +<input type=\"hidden\" name=\"curpassword\" value=\"$curpassword\" />
    1.96 +<tr><td><h2>Configuration</h2></td><td>
    1.97 +<select name="file">
    1.98 +$(for i in template.html style.css config*.sh; do
    1.99 +  [ -x $i ] && echo "<option>$i</option>"; done)
   1.100 +</select>
   1.101 +<input type=\"submit\" value=\"$DONE_BUTTON\" name=\"save\" />
   1.102 +<input type=\"submit\" value=\"$RESTORE\" name=\"restore\" /></td></tr>
   1.103 +</form>
   1.104 +</table>
   1.105 +"
   1.106 +}
     2.1 --- a/tazwikiss/rootfs/var/www/wiki/plugins/wkp_ListPlugins.sh	Sun Apr 03 01:00:19 2011 +0200
     2.2 +++ b/tazwikiss/rootfs/var/www/wiki/plugins/wkp_ListPlugins.sh	Sun Apr 03 16:54:16 2011 +0200
     2.3 @@ -62,10 +62,10 @@
     2.4  	CONTENT="$CONTENT
     2.5  <tr><td><br /><h2>Data</h2></td>
     2.6  <td><form method=\"post\" enctype=\"multipart/form-data\" action=\"?action=backup\">
     2.7 -<input type=\"submit\" name=\"save\" value=\"save\" />"
     2.8 +<input type=\"submit\" name=\"save\" value=\"$DONE_BUTTON\" />"
     2.9  	[ "$ALLOW_UPLOAD" == "yes" ] && CONTENT="$CONTENT
    2.10  <input type=\"file\" name=\"file\" value=\"file\" />
    2.11 -<input type=\"submit\" name=\"restore\" value=\"restore\" />"
    2.12 +<input type=\"submit\" name=\"restore\" value=\"$RESTORE\" />"
    2.13  	CONTENT="$CONTENT
    2.14  </form></td></tr>
    2.15  $(du -hs */ | awk '{ printf "<tr><td><b>%s</b></td><td><i>%s</i></td></tr>\n",$1,$2 }')