Annotation of OpenXM/src/kan96xx/Doc/cgiasir.sm1, Revision 1.6
1.4 takayama 1: %$Id: cgiasir.sm1,v 1.16 2005/02/27 07:29:49 taka Exp $
1.6 ! takayama 2: %$OpenXM: OpenXM/src/kan96xx/Doc/cgiasir.sm1,v 1.5 2013/02/15 05:39:45 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
1.6 ! takayama 121: (<html><meta http-equiv="Content-Type" name="viewport" content="text/html; charset=UTF-8; width=device-width"><body>) nl
1.1 takayama 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
1.5 takayama 133: [(getenv) (CGI_ASIR_MSG)] extension tag 0 eq not {
134: [(getenv) (CGI_ASIR_MSG)] extension nl nl
135: } { } ifelse
1.1 takayama 136: (<form method="POST">) nl
137: (<input type=submit>) nl
138: (<textarea name="oxMessageBody") nl
139: ( rows=10 cols="80" wrap="soft"></textarea>) nl
140: (</form>) nl
141: (</body></html>) nl
142: ] cat
143: def
144:
145: /cgiAsir.0 {
1.3 takayama 146: cgiAsir.0a
147: cgiAsir.0b
148: } def
149:
150: /cgiAsir.0a {
1.1 takayama 151: /arg1 set
152: [/sss /kv /comm /i /acti0 /pError] pushVariables
153: [
154: /sss arg1 def
155: % Step 1. analyze the query string in URL encoding.
156: [(cgiUrlEncodingToKeyValuePair) sss] extension /kv set
157: kv (oxMessageBody) getNode /comm set
158: % [nl nl] cat message sss message kv message % for debug.
159: comm /cgi.body set
160:
161: % Step 2. Enclosed cgi.body by timer(limit, expr, "interrupted.");
162: [(getenv) (CGI_ASIR_TLIMIT)] extension tag 0 eq {
163: } {
164: [(getenv) (CGI_ASIR_TLIMIT)] extension toString /cgiasir.tlimit set
165: } ifelse
166: [ $timer($ cgiasir.tlimit $,$
167: cgi.body
168: $, "Exceeded the CPU time resource (<$
169: cgiasir.tlimit
170: $ seconds) or the command is not allowed or the syntax error.");$
171: ] cat /cgi.body set
172:
173: % Step 3. Calling asir
174: oxasir.ccc [ ] eq { ox_cgiAsirConnectMethod } { } ifelse
175: oxasir.ccc cgi.body oxsubmit
1.3 takayama 176: ] pop
177: popVariables
178: } def
179:
180: /cgiAsir.0b {
181: % Step 4. Request the result
1.1 takayama 182: oxasir.ccc oxpopstring /cgi_body set
183: % set for cgiReplyInHttp0
184: /@@@stdout (NONE) def /@@@stderr (NONE) def
185: /cgi.body cgi_body def
186: } def
187:
188: /cgi.test2 {
189: [
190: [(oxMessageBody)
191: [$primadec([x^2-1],[x])$
192: ] cat
193: ]] /ff set
194: [(cgiKeyValuePairToUrlEncodingString) ff] extension /ff1 set
195: ff1 message
196: ff1 cgiAsir.0
197: cgi.body message
198: } def
199:
200: % test2.txt : oxMessageBody=2-1%0A
201: % env=CONTENT_LENGTH=20 cgi-asir.sh <test2.txt
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>