Annotation of OpenXM/src/kan96xx/Doc/cgiasir.sm1, Revision 1.3
1.3 ! takayama 1: %$Id: cgiasir.sm1,v 1.14 2005/02/27 07:06:03 taka Exp $
! 2: %$OpenXM: OpenXM/src/kan96xx/Doc/cgiasir.sm1,v 1.2 2005/02/25 11:30:58 takayama Exp $
1.1 takayama 3: [(parse) (ox.sm1) pushfile] extension
4: [(parse) (cgi.sm1) pushfile] extension
5:
6: % Default value of timer
7: /cgiasir.tlimit (120) def
8: % ------------------ set security flags of ox_asir.
9: [(oxasirSetDefaultSecureFlags)
10: [(It sets default secure flags for oxasir.sm1)]
11: ] putUsages
12: /oxasirSetDefaultSecureFlags {
13: oxasir.ccc [ ] eq { ox_asirConnectMethod } { } ifelse
14: % cf. oxasir.asir
15: (ox_ptod) oxasirSetSecureFlag
16: (ox_dtop) oxasirSetSecureFlag
17: (sm1_ptozp_subst) oxasirSetSecureFlag
18: (sm1_rat2plist) oxasirSetSecureFlag
19: } def
20:
21: [(oxasirSetSecureMode)
22: [(oxasirSetSecureMode)
23: (It starts the restricted asir.)
24: (cf. oxSecureFlag)
25: ]] putUsages
26: /oxasirSetSecureMode {
27: oxasir.ccc [ ] eq { ox_asirConnectMethod } { } ifelse
28: oxasir.ccc $ctrl("error_in_timer",1);$ oxsubmit
29: oxasir.ccc $set_secure_mode(1);$ oxsubmit
30: } def
31:
32: [(oxasirSetSecureFlag)
33: [(name oxasirSetSecureFlag)
34: (It sets the export flag for the function <<name>>)
35: (cf. oxSetSecureMode)
36: ]] putUsages
37: /oxasirSetSecureFlag {
38: /arg1 set
39: [/fff ] pushVariables
40: [
41: /fff arg1 def
42: oxasir.ccc [ ] eq { ox_asirConnectMethod } { } ifelse
43: oxasir.ccc [$set_secure_flag("$ fff toString $",1);$] cat oxsubmit
44: oxasir.ccc oxpopcmo
45: ] pop
46: popVariables
47: } def
48:
49:
50: /cgiAsir.test {
51: oxasirSetDefaultSecureFlags
52: (primadec) oxasirSetSecureFlag
53: oxasirSetSecureMode
54: } def
55:
56:
57: %---------- server side ----------------------
58: % This is a default value. This is used when the environment variable
59: % CGI_ASIR_ALLOW is not used.
60: /cgiAsirAllow
61: [
62: % (primadec)
63: % (fctr)
64: % (dp_gr_main)
65: % (nd_gr_main)
66: ]
67: def
68: /ox_cgiAsirConnectMethod {
69: oxasir.ccc [ ] eq {
70: ox_asirConnectMethod
71: oxasirSetDefaultSecureFlags
72:
73: [(getenv) (CGI_ASIR_ALLOW)] extension isString {
74: [(getenv) (CGI_ASIR_ALLOW)] extension /cgiAsirAllow.s set
75: [(parse) cgiAsirAllow.s] extension pop /cgiAsirAllow.p set
76: cgiAsirAllow.p isArray {
77: cgiAsirAllow.p /cgiAsirAllow set
78: } { } ifelse
79: } { } ifelse
80: cgiAsirAllow {oxasirSetSecureFlag} map
81:
82: oxasirSetSecureMode
83: } { } ifelse
84: } def
85:
86: /cgiAsir {
87: {
88: [(getenv) (CONTENT_LENGTH)] extension /cgi.content_length set
89: cgi.content_length isString {
90: } {
91: cgiAsir.errorMessage message exit
92: } ifelse
93: cgi.content_length .. (integer) dc /cgi.content_length set
94: cgi.content_length 1 lt {
95: cgiAsir.errorMessage message exit
96: } { } ifelse
97: [(read) 0 cgi.content_length] extension /cgi.query_string set
98: cgi.query_string isString {
99: cgi.query_string length 0 eq {
100: cgiAsir.errorMessage message exit
101: } { } ifelse
102: }
103: {
104: cgiAsir.errorMessage message exit
105: } ifelse
106: cgi.body.http0 message
107: cgi.query_string cgiAsir.0
108: cgi.body cgiReplyInHttp0 /cgi.body.http set
109: cgi.body.http message
110: exit
111: } loop
112: [(flush)] extension
113: } def
114:
115: /cgiAsir.errorMessage
116: [ (Content-Type: text/html) nl
117: nl
118: (<html><body>) nl
119: (Input <br> asir-command <br> without semicolon. <br> <br>) nl
120: (<pre> Example) nl
121: $primadec([x^3-1],[x])$ nl
122: $ $ nl
123: $Commands accepted are $ nl
124: [(getenv) (CGI_ASIR_ALLOW)] extension tag 0 eq not {
125: [(getenv) (CGI_ASIR_ALLOW)] extension nl nl
126: } { } ifelse
127: $Execution CPU time limit is $
128: cgiasir.tlimit toString ( seconds.) nl nl
129: (</pre>) nl
130: (<form method="POST">) nl
131: (<input type=submit>) nl
132: (<textarea name="oxMessageBody") nl
133: ( rows=10 cols="80" wrap="soft"></textarea>) nl
134: (</form>) nl
135: (</body></html>) nl
136: ] cat
137: def
138:
139: /cgiAsir.0 {
1.3 ! takayama 140: cgiAsir.0a
! 141: cgiAsir.0b
! 142: } def
! 143:
! 144: /cgiAsir.0a {
1.1 takayama 145: /arg1 set
146: [/sss /kv /comm /i /acti0 /pError] pushVariables
147: [
148: /sss arg1 def
149: % Step 1. analyze the query string in URL encoding.
150: [(cgiUrlEncodingToKeyValuePair) sss] extension /kv set
151: kv (oxMessageBody) getNode /comm set
152: % [nl nl] cat message sss message kv message % for debug.
153: comm /cgi.body set
154:
155: % Step 2. Enclosed cgi.body by timer(limit, expr, "interrupted.");
156: [(getenv) (CGI_ASIR_TLIMIT)] extension tag 0 eq {
157: } {
158: [(getenv) (CGI_ASIR_TLIMIT)] extension toString /cgiasir.tlimit set
159: } ifelse
160: [ $timer($ cgiasir.tlimit $,$
161: cgi.body
162: $, "Exceeded the CPU time resource (<$
163: cgiasir.tlimit
164: $ seconds) or the command is not allowed or the syntax error.");$
165: ] cat /cgi.body set
166:
167: % Step 3. Calling asir
168: oxasir.ccc [ ] eq { ox_cgiAsirConnectMethod } { } ifelse
169: oxasir.ccc cgi.body oxsubmit
1.3 ! takayama 170: ] pop
! 171: popVariables
! 172: } def
! 173:
! 174: /cgiAsir.0b {
! 175: % Step 4. Request the result
1.1 takayama 176: oxasir.ccc oxpopstring /cgi_body set
177: % set for cgiReplyInHttp0
178: /@@@stdout (NONE) def /@@@stderr (NONE) def
179: /cgi.body cgi_body def
180: } def
181:
182: /cgi.test2 {
183: [
184: [(oxMessageBody)
185: [$primadec([x^2-1],[x])$
186: ] cat
187: ]] /ff set
188: [(cgiKeyValuePairToUrlEncodingString) ff] extension /ff1 set
189: ff1 message
190: ff1 cgiAsir.0
191: cgi.body message
192: } def
193:
194: % test2.txt : oxMessageBody=2-1%0A
195: % env=CONTENT_LENGTH=20 cgi-asir.sh <test2.txt
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>