wok-tiny view wiki/stuff/var/www/wiki/plugins/wkp_Password.sh @ rev 142

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 27 17:43:23 2019 +0100 (6 months ago)
parents 48d2c4c7a227
children
line source
1 plugin="Password"
2 description_fr="Ajoute un mot de passe &agrave; une page avec {PASSWORD=code}"
3 description="Add a password to a page with {PASSWORD=something}"
5 pagepass_hash()
6 {
7 echo $1 | md5sum | cut -c1-8
8 }
10 init()
11 {
12 if grep -qs '{HASHPASSWORD=' $1; then
13 case "$(GET action)" in
14 pagepass|'') return ;;
15 esac
16 hash="$(sed '/{HASHPASSWORD=.*}/!d;s/.*{HASHPASSWORD=\([^}]*\)}.*/\1/;q' <$1)"
17 cookie="pagepass$(pagepass_hash $PWD$PAGE_txt)"
18 [ "$(COOKIE $cookie)" = "$hash" ] && return
19 header
20 echo "<script> history.go(-1); </script>"
21 exit 0
22 fi
23 }
25 action()
26 {
27 [ "$1" = "pagepass" ] || return 1
28 uri="$SCRIPT_NAME?page=$(POST page)&auth=$(POST auth)"
29 if [ "$(pagepass_hash $(POST pass))" = "$(POST hash)" ]; then
30 header "HTTP/1.0 302 Found" \
31 "location: $uri" \
32 "Set-Cookie: $(POST cookie)=$(POST hash)"
33 ## "Set-Cookie: $(POST cookie)=$(POST hash); Max-Age=3600; Path=$(dirname $SCRIPT_NAME); HttpOnly"
34 else
35 header "HTTP/1.0 302 Found" \
36 "location: $uri&error=1"
37 fi
38 exit 0
39 }
41 formatBegin()
42 {
43 hash="$(sed '/{HASHPASSWORD=.*}/!d;s/.*{HASHPASSWORD=\([^}]*\)}.*/\1/;q' <<EOT
44 $CONTENT
45 EOT
46 )"
47 cookie="pagepass$(pagepass_hash $PWD$PAGE_txt)"
48 if [ "$(COOKIE $cookie)" != "$hash" ]; then
49 editable=false
50 CONTENT="<form method=\"post\" action=\"?action=pagepass\">
51 <input type=\"hidden\" name=\"page\" value=\"$(GET page)\" /> \
52 <input type=\"hidden\" name=\"auth\" value=\"$(GET auth)\" /> \
53 <input type=\"hidden\" name=\"hash\" value=\"$hash\" /> \
54 <input type=\"hidden\" name=\"cookie\" value=\"$cookie\" /> \
55 $MDP <input type=\"text\" name=\"pass\" /> \
56 <input type=\"submit\" value=\"$DONE_BUTTON\" />
57 </form>"
58 else
59 CONTENT="$(sed 's/{HASHPASSWORD=[^}]*}//' <<EOT
60 $CONTENT
61 EOT
62 )"
63 fi
64 }
66 pagepass_sedexpr()
67 {
68 sed '/{PASSWORD=.*}/!d;s/.*{PASSWORD=\([^}]*\)}.*/\1/' $1 | \
69 while read pass; do
70 echo -n "-e 's|{PASSWORD=$pass|{HASHPASSWORD=$(pagepass_hash $pass)|' "
71 done
72 echo -n "-e 's|{PASSWORD=}||' "
73 }
75 writedPage()
76 {
77 eval sed -i $(pagepass_sedexpr $1) $1 $BACKUP_DIR$PAGE_TITLE/\*.bak
78 }