root/10kz/shell/decode-form-post.jm3

Revision 45, 3.1 kB (checked in by jm3, 2 years ago)
  • added additional config file variable and removed some hardcoded references to the root dir.
  • Nb. there are *still* some hardcoded paths inside the perl file... *we have* to fix these before we can beta!!!
  • added additional error dump to gm script
  • Property svn:keywords set to Id
Line 
1 #!/bin/bash
2
3 # pull in config params like KEY_HOME, GPG_HOME, and app ROOT
4 . configure.sh
5
6 echo Content-type: text/plain
7 echo
8 if [ -z "$CONTENT_LENGTH" ]
9 then
10         echo "<h1>Your browser did not send a 'POST' HTTP request; bailing.</h1> "
11         exit 1
12 fi
13        
14 root=$ROOT/shell
15
16 #echo "<pre>"
17 #echo \$CONTENT_LENGTH is $CONTENT_LENGTH
18 #echo \$REQUEST_METHOD is $REQUEST_METHOD
19 #echo "</pre>"
20 #echo
21
22 # bash / posix / something seems to barf on input lines (which is the form post in this case) longer than 4k
23 # so we force-wrap the single long line on entry and then recombine them so we don't gnarl up the data
24 # also, split up the HTTP request name=value params
25 fold -w 80 | awk '/./{printf "%s",$0;next}{print}' | sed "s/&/ /g" | tr " " "\n" > /tmp/params
26
27 # parse out params and toss LHS
28 while read name_value_pair; do
29         read name value << HERE
30                 $(IFS==; echo $name_value_pair)
31 HERE
32         echo name is $name
33         echo raw value is $value
34
35
36         decoded=`echo $safe_value | $root/urldecode | sed "s/^'//" | sed "s/'$//"`
37         echo decoded value is \'$decoded\'
38         export `echo $name`="`echo '$value' | $root/urldecode`"
39         echo
40 done </tmp/params
41         echo \$passphrase $passphrase
42
43         while read tokens; do
44                 if echo $tokens | grep "HEX:" >/dev/null; then
45                         t=`echo $t | sed s/HEX://`
46                         tok=`printf "%d" 0x$t | awk '{printf("%c", $1)}'`
47                         full="$full$tok"
48                 else
49                         tok=`echo $t | sed "s/__SPACE__/ /g"`
50                         full="$full$tok"
51                 fi
52         done </tmp/half-decoded
53
54
55
56
57
58
59
60 # good so far
61
62 exit 1
63        
64 OIFS="$IFS"
65 read key_id passphrase recipients plaintext << HERE
66         $(IFS=\&; cat /tmp/params)
67 HERE
68 IFS="$OIFS"
69
70 echo key_id = $key_id
71 echo
72
73 exit 1
74
75 #unset IFS
76 for param in "foo bar"
77 do
78         echo param is $param
79         #OIFS="$IFS"
80         #read name value << HERE
81                 #$(IFS==; echo $param)
82 #HERE
83 #IFS="$OIFS"
84         #echo name is $name
85         #echo value is $value
86 done
87 #export `echo $var`="$val"
88
89 exit 1
90
91 while read name_value_pair; do
92        
93         read name value << HERE
94                 $(IFS==; echo $name_value_pair)
95 HERE
96         echo parsing name/value pair -\> name: $name, value: $value
97
98
99         sed "s/=/__N__ /" /tmp/params |
100         while read nov; do
101                 if echo $nov | grep "__N__" >/dev/null; then
102                         echo "FOUND PARAM: `echo $nov | sed s/__N__//`"
103                         #export `echo $var`="$val"
104                 else
105                         # cache value in file since it can be long:
106                        
107                         echo WITH RAW, UNDECODED VALUE:
108                         echo $nov | sed "s/\+/__SPACE__/g" | sed "s/%26/__AMP__/g" | sed "s/%\([0-9A-F][0-9A-F]\)/ HEX:\1 /g" > /tmp/half-decoded
109                        
110                         echo INTERIM DECODED VAR:
111                         cat /tmp/half-decoded
112
113                         while read tokens; do
114                         echo TOK
115                                 if echo $token | grep "HEX:" >/dev/null; then
116                                         t=`echo $t | sed s/HEX://`
117                                         tok=`printf "%d" 0x$t | awk '{printf("%c", $1)}'`
118                                         full="$full$tok"
119                                 else
120                                         tok=`echo $t | sed "s/__SPACE__/ /g"`
121                                         full="$full$tok"
122                                 fi
123                         done </tmp/half-decoded
124                         echo done:
125                         echo $full
126
127                 fi
128         done
129 done </tmp/params
130
131         exit 1
132         tokens=`echo $p | sed "s/\+/__SPACE__/g" | sed "s/%26/__AMP__/g" | sed "s/%\([0-9A-F][0-9A-F]\)/ HEX:\1 /g"`
133         full=""
134         for t in $tokens
135         do
136                 echo $t | grep -q HEX:
137                 if [ $? = 0 ]
138                 then
139                         t=`echo $t | sed s/HEX://`
140                         tok=`printf "%d" 0x$t | awk '{printf("%c", $1)}'`
141                         full="$full$tok"
142                 else
143                         tok=`echo $t | sed "s/__SPACE__/ /g"`
144                         full="$full$tok"
145                 fi
146         done
147         echo
148
Note: See TracBrowser for help on using the browser.