Annotation of OpenXM/src/kan96xx/Doc/cgiasir.sm1, Revision 1.4
1.4 ! takayama 1: %$Id: cgiasir.sm1,v 1.16 2005/02/27 07:29:49 taka Exp $
! 2: %$OpenXM: OpenXM/src/kan96xx/Doc/cgiasir.sm1,v 1.3 2005/02/27 07:08:11 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: [
1.4 ! takayama 62: %% They are required by the system
! 63: (ox103_reset)
! 64: %%%%%%%%%%%%%%%%%%%%%%%%%%
1.1 takayama 65: % (primadec)
66: % (fctr)
67: % (dp_gr_main)
68: % (nd_gr_main)
69: ]
70: def
71: /ox_cgiAsirConnectMethod {
72: oxasir.ccc [ ] eq {
73: ox_asirConnectMethod
74: oxasirSetDefaultSecureFlags
75:
76: [(getenv) (CGI_ASIR_ALLOW)] extension isString {
77: [(getenv) (CGI_ASIR_ALLOW)] extension /cgiAsirAllow.s set
78: [(parse) cgiAsirAllow.s] extension pop /cgiAsirAllow.p set
79: cgiAsirAllow.p isArray {
80: cgiAsirAllow.p /cgiAsirAllow set
81: } { } ifelse
82: } { } ifelse
83: cgiAsirAllow {oxasirSetSecureFlag} map
84:
85: oxasirSetSecureMode
86: } { } ifelse
87: } def
88:
89: /cgiAsir {
90: {
91: [(getenv) (CONTENT_LENGTH)] extension /cgi.content_length set
92: cgi.content_length isString {
93: } {
94: cgiAsir.errorMessage message exit
95: } ifelse
96: cgi.content_length .. (integer) dc /cgi.content_length set
97: cgi.content_length 1 lt {
98: cgiAsir.errorMessage message exit
99: } { } ifelse
100: [(read) 0 cgi.content_length] extension /cgi.query_string set
101: cgi.query_string isString {
102: cgi.query_string length 0 eq {
103: cgiAsir.errorMessage message exit
104: } { } ifelse
105: }
106: {
107: cgiAsir.errorMessage message exit
108: } ifelse
109: cgi.body.http0 message
110: cgi.query_string cgiAsir.0
111: cgi.body cgiReplyInHttp0 /cgi.body.http set
112: cgi.body.http message
113: exit
114: } loop
115: [(flush)] extension
116: } def
117:
118: /cgiAsir.errorMessage
119: [ (Content-Type: text/html) nl
120: nl
121: (<html><body>) nl
122: (Input <br> asir-command <br> without semicolon. <br> <br>) nl
123: (<pre> Example) nl
124: $primadec([x^3-1],[x])$ nl
125: $ $ nl
126: $Commands accepted are $ nl
127: [(getenv) (CGI_ASIR_ALLOW)] extension tag 0 eq not {
128: [(getenv) (CGI_ASIR_ALLOW)] extension nl nl
129: } { } ifelse
130: $Execution CPU time limit is $
131: cgiasir.tlimit toString ( seconds.) nl nl
132: (</pre>) nl
133: (<form method="POST">) nl
134: (<input type=submit>) nl
135: (<textarea name="oxMessageBody") nl
136: ( rows=10 cols="80" wrap="soft"></textarea>) nl
137: (</form>) nl
138: (</body></html>) nl
139: ] cat
140: def
141:
142: /cgiAsir.0 {
1.3 takayama 143: cgiAsir.0a
144: cgiAsir.0b
145: } def
146:
147: /cgiAsir.0a {
1.1 takayama 148: /arg1 set
149: [/sss /kv /comm /i /acti0 /pError] pushVariables
150: [
151: /sss arg1 def
152: % Step 1. analyze the query string in URL encoding.
153: [(cgiUrlEncodingToKeyValuePair) sss] extension /kv set
154: kv (oxMessageBody) getNode /comm set
155: % [nl nl] cat message sss message kv message % for debug.
156: comm /cgi.body set
157:
158: % Step 2. Enclosed cgi.body by timer(limit, expr, "interrupted.");
159: [(getenv) (CGI_ASIR_TLIMIT)] extension tag 0 eq {
160: } {
161: [(getenv) (CGI_ASIR_TLIMIT)] extension toString /cgiasir.tlimit set
162: } ifelse
163: [ $timer($ cgiasir.tlimit $,$
164: cgi.body
165: $, "Exceeded the CPU time resource (<$
166: cgiasir.tlimit
167: $ seconds) or the command is not allowed or the syntax error.");$
168: ] cat /cgi.body set
169:
170: % Step 3. Calling asir
171: oxasir.ccc [ ] eq { ox_cgiAsirConnectMethod } { } ifelse
172: oxasir.ccc cgi.body oxsubmit
1.3 takayama 173: ] pop
174: popVariables
175: } def
176:
177: /cgiAsir.0b {
178: % Step 4. Request the result
1.1 takayama 179: oxasir.ccc oxpopstring /cgi_body set
180: % set for cgiReplyInHttp0
181: /@@@stdout (NONE) def /@@@stderr (NONE) def
182: /cgi.body cgi_body def
183: } def
184:
185: /cgi.test2 {
186: [
187: [(oxMessageBody)
188: [$primadec([x^2-1],[x])$
189: ] cat
190: ]] /ff set
191: [(cgiKeyValuePairToUrlEncodingString) ff] extension /ff1 set
192: ff1 message
193: ff1 cgiAsir.0
194: cgi.body message
195: } def
196:
197: % test2.txt : oxMessageBody=2-1%0A
198: % env=CONTENT_LENGTH=20 cgi-asir.sh <test2.txt
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>