s4

view s4-cgi.sh @ 206:c761ce8ff963

Quoting changed
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 25 Apr 2016 19:46:25 +0859
parents 3590c50e0cbd
children 36b6354de5cb
line source
1 #
2 # cgi functions
3 #
4 cgi_form() {
5 # $1=stage
6 : ${myname:?'Sure to set $myname to this script name'}
7 cont=`cat`
8 cat<<EOF
9 <form action="$myname" method="POST" enctype="multipart/form-data">
10 $cont
11 <input type="hidden" name="stage" value="$1">
12 <input type="submit" value="送信">
13 <input type="reset" value="リセット">
14 </form>
15 EOF
16 }
17 cgi_submit() {
18 cat<<EOF
19 <input type="submit" value="$1">
20 EOF
21 }
22 cgi_reset() {
23 cat<<EOF
24 <input type="reset" value="$1">
25 EOF
26 }
27 cgi_radio() {
28 echo "<input type=\"radio\" name=\"$1\" ${2:+value=\"$2\"} $3>"
29 }
30 cgi_checkbox() {
31 echo "<input type=\"checkbox\" name=\"$1\" ${2:+value=\"$2\"} $3>"
32 }
33 cgi_hidden() {
34 echo "<input type=\"hidden\" name=\"$1\" value=\"$2\" $3>"
35 }
36 cgi_passwd() {
37 cat<<EOF
38 <table class="pswd">
39 <tr><td>現パスワード</td><td><input type="password" name="pswd"></td></tr>
40 <tr><td>新パスワード</td><td><input type="password" name="pswd1"></td></tr>
41 <tr><td>新パスワード(確認)</td><td><input type="password" name="pswd2"></td></tr>
42 </table>
43 EOF
44 }
45 cgi_text() {
46 echo "<input type=\"text\" name=\"$1\" value=\"$2\" $3>"
47 }
48 cgi_textarea() {
49 cat<<EOF
50 <textarea name="$1" $3>$2</textarea>
51 EOF
52 }
53 cgi_file() ( # In a subshell
54 # $1=name $2=val(as filename) $3=args(if any)
55 # Using global variable $dir
56 if [ -s $dir/$2 -a -s $dir/$2.content-type ]; then
57 file=$dir/$2
58 bn=${file##*/}
59 ct=`cat $dir/$2.content-type`
60 data=`percenthex $file`
61 icon="<img src=\"data:$ct,$data\">"
62 fi
63 cat<<EOF
64 ${icon}
65 <input type="file" name="$1" value="$bn" $3>
66 EOF
67 )
68 cgi_multi() (
69 # $1=name $2=dir $3=func $4=args...
70 # `dir' should contain $name.count and $name.N where N is 1 upto N
71 i=1 name=$1 dir=$2 func=$3
72 n=`cat $dir/$name.count`
73 echo '<table class="text">'
74 while [ $i -le $n ]; do
75 file=$name.$i ctf=$dir/$name.content-type
76 vname=$file.`cat $dir/$file.rowid`
77 if [ -s $ctf ]; then
78 case `cat $ctf` in
79 *:[Ii]mage:*)
81 ;;
83 esac
84 fi
85 val="`cat $dir/$file`"
86 cat<<EOF
87 <tr><td>($i)</td><td>
88 <input class="action" type="radio" name="action.$vname" id="keep.$vname"
89 value="keep"><label for="keep.$vname">温存</label>
90 <input class="action" type="radio" name="action.$vname" id="edit.$vname"
91 value="edit"><label for="edit.$vname">修正</label>
92 <input class="action" type="radio" name="action.$vname" id="rm.$vname"
93 value="rm"><label for="rm.$vname">削除</label>
94 <label class="confirm">本当に消します<input class="confirm" type="checkbox"
95 name="confirm.$vname" value="yes">はい</label><br>
96 `$func $vname "$val" "$4"`<span>$val</span>
97 </td></tr>
98 EOF
99 i=$((i+1))
100 done
101 cat<<EOF
102 <tr><td>(新規)</td><td>`$func $name "" "$4"`</td></tr>
103 </table>
104 EOF
105 )
106 # In these functions, $2 should be quoted because it can be null
107 cgi_multi_text() {
108 cgi_multi $1 "$2" cgi_text "$3"
109 }
110 cgi_multi_textarea() {
111 cgi_multi $1 "$2" cgi_textarea "$3"
112 }
113 cgi_multi_file() {
114 # $1=name $2=val(filename)
115 cgi_multi $1 "$2" cgi_file "$3"
116 }
118 html() {
119 echo "<$*>"
120 cat
121 echo "</$1>"
122 }