=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v retrieving revision 1.2 retrieving revision 1.10 diff -u -p -r1.2 -r1.10 --- OpenXM/src/kan96xx/Doc/httpd-rpc.sm1 2002/10/24 02:12:34 1.2 +++ OpenXM/src/kan96xx/Doc/httpd-rpc.sm1 2002/11/03 12:43:03 1.10 @@ -1,23 +1,42 @@ -%% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v 1.1 2002/10/23 13:38:50 takayama Exp $ +%% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v 1.9 2002/10/29 10:54:17 takayama Exp $ %% http server by sm1. Used for RPC. Generic example. [(parse) (httpd.sm1) pushfile] extension pop +%% keyword for rpc /httpd.textarea.name (rpc) def /httpd.textarea.name.aaa [(GET /?) httpd.textarea.name] cat (array) dc def -/httpd.port 8090 def + +[(getenv) (OXWEB_PORT)] extension tag 0 eq { + (Default httpd port : ) messagen + /httpd.port 8090 def +} { + /httpd.port [(getenv) (OXWEB_PORT)] extension .. (integer) dc def +} ifelse +(httpd.port = ) messagen httpd.port message + /httpd.serial 0 def +/httpd.oxasir.timer 1 def %% 1 to use timer, but it accepts only one command + %% 0 not to use timer. It accepts programs. + %%******* Put initialization codes for ox_asir here. /httpd.initialization - [ + [(if(1){) (XM_debug=0; ctrl("debug_window",0); Xm_noX=1;) ("Asirweb version 0.80. "+ " Risa/Asir oxasir version "+rtostr(version());) + (};) ] cat def +/httpd.asirman + ("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.2.1/doc/asir2000/html-eg/man_toc.html") +def +/httpd.asirman.ja + ("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.2.1/doc/asir2000/html-jp/man_toc.html") +def [(parse) (oxasir.sm1) pushfile] extension oxNoX @@ -44,13 +63,16 @@ oxNoX [ ox.win.start.0 aload pop (iexplore) %% Starting internet explorer (TM). - [(http://localhost:) httpd.port toString] cat + [(http://) [(sm1.socket) (gethostname) []] extension + (:) httpd.port toString] cat ] [ ] 3] extension }{ %% On unix. - [(sleep 3 ; netscape http://localhost:) httpd.port toString ( & ) ] cat + [(sleep 3 ; netscape http://) + [(sm1.socket) (gethostname) []] extension + (:) httpd.port toString ( & ) ] cat system } ifelse @@ -63,7 +85,7 @@ oxNoX /httpd_action { [/in-httpd /ff /httpd.com /httpd.result /sss /sss.engine /sss.web /err - /oxserver.vname + /oxserver.vname /scheck ] pushVariables [ { @@ -85,6 +107,20 @@ oxNoX httpd.com metaCommand { httpd.textarea.valid { + %%% Security check + [(regionMatches) httpd.com + httpd.refusedCommands] extension /scheck set + scheck 0 get -1 eq { + }{ + httpd.refusedCommands scheck 2 get get message + (Command is refused.) message + [ + httpd.refusedCommands scheck 2 get get + httpd.com + ] + send-page-refused exit + } ifelse + %%% Executing command, here. oxasir.ccc httpd.com cookedCommand @@ -183,10 +219,7 @@ oxNoX (Content-Type: text/html) sendln 0 sendln - (

Usage


) sendln - [(Ask by GET /?) httpd.textarea.name (=) ( encoded_codes HTTP/1.0)] cat - sendln - (
) sendln + (

OpenXM/Risa/Asir Online


) sendln [(getenv) (OXWEB_POST)] extension tag 0 eq { (
) sendln % use get }{ @@ -194,12 +227,30 @@ oxNoX } ifelse () sendln [()] cat sendln + ( rows=7 cols="80" wrap="soft">)] cat sendln (
) sendln - [$ Shutdown the server. , $ - ] cat sendln + (Input example---factorization: fctr(x^3-1)) sendln + (
) sendln + [( + AsirManual (En) , )] cat sendln + [( + AsirManual (Ja) )] cat sendln + httpd.oxasir.timer { + (
It accepts only one command. The limit of CPU time is 30 seconds. + Do not put ; + (semi-colon) after the command. + ) sendln + }{ } ifelse + (
) sendln + [(You can also retrieve the result by GET /?) httpd.textarea.name (=) ( encoded_codes HTTP/1.0)] cat + sendln + (
) sendln + [$ Shutdown the oxserver (and restart it). $ + ] cat sendln + (

Powered by OpenXM and httpd on Kan/sm1

_) sendln 0 sendln [(flush)] extension ] pop @@ -215,7 +266,8 @@ oxNoX /result arg1 def (HTTP/0.9 200 OK) sendln (Connection: close) sendln - (Content-Type: text/html) sendln + [(Content-length: ) result length toString ] cat sendln + (Content-Type: text/plain) sendln 0 sendln result sendln @@ -225,6 +277,32 @@ oxNoX popVariables } def +/send-page-refused { + /arg1 set + [/in-send-page-refused /reason] pushVariables + [ + /reason arg1 def + (HTTP/0.9 200 OK) sendln + (Connection: close) sendln + (Content-Type: text/html) sendln + 0 sendln + + (

Your request is refused.


) sendln + (Because your input contains the key word ) sendln + reason 0 get sendln + ( ) sendln + (

) sendln + (Your input is
) sendln + (
 ) sendln
+  reason 1 get sendln
+  (
) sendln + + 0 sendln + [(flush)] extension + ] pop + popVariables +} def + %% **** Overwrites the definition in httpd.sm1 /httpd_startserver { (httpd server accessible outside localhost.) message @@ -243,7 +321,7 @@ oxNoX } def %% ******* sample of cooked command -/cookedCommand { +/cookedCommand.simplest { /arg1 set [/in-cookedCommand /httpd.com] pushVariables [ @@ -254,3 +332,37 @@ oxNoX popVariables arg1 } def +/cookedCommand { + /arg1 set + [/in-cookedCommand /httpd.com /fff] pushVariables + [ + /httpd.com arg1 def + httpd.oxasir.timer not { + [(if (1) {) httpd.com (; };)] cat + /fff set + }{ +%% It does not work. +%% [$timer(30,eval_str("$ +%% (if (1) {) httpd.com (; };) +%% $"),"Computation is aborted with the resource limit ( 30 seconds)");$ +%% ] cat + [$timer(30,$ httpd.com + $,"Computation is aborted with the resource limit ( 30 seconds) or there was a syntax error.");$ + ] cat + /fff set + } ifelse + (cooked command is ) messagen fff message + /arg1 fff def + ] pop + popVariables + arg1 +} def +/httpd.refusedCommands + [(shell) (eval_str) (ox_) (sm1_) + (m_start) (m_N_) (m_Inverse) (m_TexForm) %(m_) + (connect) (load) (bload) (bsave) + (end) (quit) (output) (bload27) (open) + (plot) (ctrl) (debug) (error) (port) (bind) (accept) + (draw) (peek) (poke) + ] +def