Annotation of OpenXM/src/kan96xx/Doc/cgiasir.sm1, Revision 1.1
1.1 ! takayama 1: %$Id: cgiasir.sm1,v 1.11 2005/02/24 05:54:59 taka Exp $
! 2: %$OpenXM$
! 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 {
! 140: /arg1 set
! 141: [/sss /kv /comm /i /acti0 /pError] pushVariables
! 142: [
! 143: /sss arg1 def
! 144: % Step 1. analyze the query string in URL encoding.
! 145: [(cgiUrlEncodingToKeyValuePair) sss] extension /kv set
! 146: kv (oxMessageBody) getNode /comm set
! 147: % [nl nl] cat message sss message kv message % for debug.
! 148: comm /cgi.body set
! 149:
! 150: % Step 2. Enclosed cgi.body by timer(limit, expr, "interrupted.");
! 151: [(getenv) (CGI_ASIR_TLIMIT)] extension tag 0 eq {
! 152: } {
! 153: [(getenv) (CGI_ASIR_TLIMIT)] extension toString /cgiasir.tlimit set
! 154: } ifelse
! 155: [ $timer($ cgiasir.tlimit $,$
! 156: cgi.body
! 157: $, "Exceeded the CPU time resource (<$
! 158: cgiasir.tlimit
! 159: $ seconds) or the command is not allowed or the syntax error.");$
! 160: ] cat /cgi.body set
! 161:
! 162: % Step 3. Calling asir
! 163: oxasir.ccc [ ] eq { ox_cgiAsirConnectMethod } { } ifelse
! 164: oxasir.ccc cgi.body oxsubmit
! 165: oxasir.ccc oxpopstring /cgi_body set
! 166: % set for cgiReplyInHttp0
! 167: /@@@stdout (NONE) def /@@@stderr (NONE) def
! 168: /cgi.body cgi_body def
! 169: ] pop
! 170: popVariables
! 171: } def
! 172:
! 173: /cgi.test2 {
! 174: [
! 175: [(oxMessageBody)
! 176: [$primadec([x^2-1],[x])$
! 177: ] cat
! 178: ]] /ff set
! 179: [(cgiKeyValuePairToUrlEncodingString) ff] extension /ff1 set
! 180: ff1 message
! 181: ff1 cgiAsir.0
! 182: cgi.body message
! 183: } def
! 184:
! 185: % test2.txt : oxMessageBody=2-1%0A
! 186: % env=CONTENT_LENGTH=20 cgi-asir.sh <test2.txt
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>