=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v retrieving revision 1.1 retrieving revision 1.4 diff -u -p -r1.1 -r1.4 --- OpenXM/src/kan96xx/Doc/httpd-rpc.sm1 2002/10/23 13:38:50 1.1 +++ OpenXM/src/kan96xx/Doc/httpd-rpc.sm1 2002/10/24 05:42:00 1.4 @@ -1,4 +1,4 @@ -%% $OpenXM$ +%% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v 1.3 2002/10/24 02:48:59 takayama Exp $ %% http server by sm1. Used for RPC. Generic example. [(parse) (httpd.sm1) pushfile] extension pop @@ -9,7 +9,14 @@ def /httpd.port 8090 def /httpd.serial 0 def -/httpd.image.name (kobeuniv2.jpg) def +%%******* Put initialization codes for ox_asir here. +/httpd.initialization + [ + (XM_debug=0; ctrl("debug_window",0); Xm_noX=1;) + ("Asirweb version 0.80. "+ + " Risa/Asir oxasir version "+rtostr(version());) + ] cat +def [(parse) (oxasir.sm1) pushfile] extension @@ -20,6 +27,9 @@ oxNoX [(x^2-1) (x)] fctr pop oxasir.ccc oxmathcap oxasir.ccc oxsetmathcap + oxasir.ccc httpd.initialization oxexecutestring ; + (Initialization returns ...: ) messagen + oxasir.ccc oxpopcmo message ; } ifelse /webrpc { @@ -34,13 +44,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 @@ -53,15 +66,15 @@ oxNoX /httpd_action { [/in-httpd /ff /httpd.com /httpd.result /sss /sss.engine /sss.web /err - /oxserver.vname + /oxserver.vname /scheck ] pushVariables [ { [(sm1.socket) (select) [httpd.server.fd 0 get -1]] extension %% wait for ever [(sm1.socket) (readHTTP) [httpd.server.fd 0 get ]] extension /ff set - ff length 0 eq { - (connection is closed.) message + ff tag 0 eq { + (connection is closed.) message exit } { (------------ start ----------------------) message @@ -71,12 +84,24 @@ oxNoX [(httpd.com=) httpd.com] cat message (------------ end ----------------------) message ( ) message - httpd.serial 0 eq { - /httpd.com httpd.initialization def - } { } ifelse + 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 @@ -120,8 +145,10 @@ oxNoX httpd.result message (----------------------------------) message ( ) message - + + (----------- error -------------) message err message + (-------------------------------) message err [ ] eq { } { oxasir.ccc cleanErrors @@ -205,7 +232,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 @@ -215,15 +243,49 @@ oxNoX popVariables } def -%%******* Put initialization codes for ox_asir here. -/httpd.initialization - [ - (XM_debug=0; ctrl("debug_window",0); Xm_noX=1;) - ("Asirweb version 0.80. "+ - " Risa/Asir oxasir version "+rtostr(version());) - ] cat -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 + %% get the hostname of this machine. + [(sm1.socket) (open) [httpd.port + [(sm1.socket) (gethostname) [ ] ]extension ] ] + extension + /httpd.server.fdAndPort set + (sm1.socket.open returns ) messagen httpd.server.fdAndPort message + [(sm1.socket) (accept) [httpd.server.fdAndPort 0 get]] extension + /httpd.server.fd set + (connected.) message + (sm1.socket.accept returns ) messagen + httpd.server.fd message + +} def + %% ******* sample of cooked command /cookedCommand { /arg1 set @@ -236,3 +298,8 @@ def popVariables arg1 } def +/httpd.refusedCommands + [(shell) (eval_str) (ox_) (sm1_) (m_) + (connect) (load) + ] +def