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

tazwikss: add password plugin
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jun 11 11:12:29 2011 +0200 (2011-06-11)
parents
children 554d43dafb26
line source
1 # WARNING: not secure! You can add &action=edit to the URI and remove HASHPASSWORD...
2 plugin="Password"
3 description_fr="Ajoute un mot de passe &agrave; une page avec {PASSWORD=code}"
4 description="Add a password to a page with {PASSWORD=something}"
6 pagepass_hash()
7 {
8 echo $1 | md5sum | cut -c1-8
9 }
11 action()
12 {
13 [ "$1" == "pagepass" ] || return 1
14 uri="$SCRIPT_NAME?page=$(POST page)&auth=$(POST auth)"
15 if [ "$(pagepass_hash $(POST pass))" == "$(POST hash)" ]; then
16 header "HTTP/1.0 302 Found" \
17 "location: $uri" \
18 "Set-Cookie: $(POST cookie)=$(POST hash)"
19 ## "Set-Cookie: $(POST cookie)=$(POST hash); Max-Age=3600; Path=$(dirname $SCRIPT_NAME); HttpOnly"
20 else
21 header "HTTP/1.0 302 Found" \
22 "location: $uri&error=1"
23 fi
24 exit 0
25 }
27 formatBegin()
28 {
29 hash="$(sed '/{HASHPASSWORD=.*}/!d;s/.*{HASHPASSWORD=\([^}]*\)}.*/\1/;q' <<EOT
30 $CONTENT
31 EOT
32 )"
33 cookie="pagepass$(pagepass_hash $PWD$PAGE_txt)"
34 if [ "$(COOKIE $cookie)" != "$hash" ]; then
35 editable=false
36 CONTENT="<form method=\"post\" action=\"?action=pagepass\">
37 <input type=\"hidden\" name=\"page\" value=\"$(GET page)\" /> \
38 <input type=\"hidden\" name=\"auth\" value=\"$(GET auth)\" /> \
39 <input type=\"hidden\" name=\"hash\" value=\"$hash\" /> \
40 <input type=\"hidden\" name=\"cookie\" value=\"$cookie\" /> \
41 $MDP <input type=\"text\" name=\"pass\" /> \
42 <input type=\"submit\" value=\"$DONE_BUTTON\" />
43 </form>"
44 else
45 CONTENT="$(sed 's/{HASHPASSWORD=[^}]*}//' <<EOT
46 $CONTENT
47 EOT
48 )"
49 fi
50 }
52 pagepass_sedexpr()
53 {
54 sed '/{PASSWORD=.*}/!d;s/.*{PASSWORD=\([^}]*\)}.*/\1/' $1 | \
55 while read pass; do
56 echo -n "-e 's|{PASSWORD=$pass|{HASHPASSWORD=$(pagepass_hash $pass)|' "
57 done
58 echo -n "-e 's|{PASSWORD=}||' "
59 }
61 writedPage()
62 {
63 eval sed -i $(pagepass_sedexpr $1) $1 $BACKUP_DIR$PAGE_TITLE/*.bak
64 }