This document shows some examples of how to use Mod_Rexx to perform actions during the phases of an HTTP request to the server.
Compiling Mod_Rexx
Adding a Canned Footer to Pages
Controlling Access To Document(s)
Here are the steps to compile Mod_Rexx.
Note: It is not necessary to rename the makefile.
rexx make_mod_rexx.rex orexx <--- For Linux, Windows or AIX or rexx make_mod_rexx.rex regina <--- For Linux or Windows
For OS/2 run the following command.
make_mod_rexx orexx
You should now have the Mod_Rexx binary in the appropriate location in the bin subdirectory tree.
To add a canned footer to a set of HTML pages in a document subdirectory you need to place the following in your Apache Configuration file (httpd.conf).
<Location /mytest> SetHandler rexx_handler RexxHandler '/opt/IBMHTTPServer/rexx/footer.rex' </Location> |
The RexxHandler directive tells Apache to invoke the specified REXX script to process each HTML file contained within the /mytest document path.
When a document is retrieved from the specified document path then the REXX script will be invoked to read in the HTML file and add the canned footer.
http://www.myserver.com/mytest/testdoc.html |
The following is an example REXX script (footer.rex) which reads the testdoc.html document and adds the footer.
/* these are some typical Apache return codes */ OK = 0 /* Module has handled this stage. */ NOT_FOUND = 404 /* Main document not found. */ /* get the Apache request record ptr */ r = arg(1) body = '</BODY>' /* try to open the main document HTML file */ retc = stream(wwwfilename, 'c', 'open read') if retc <> 'READY:' then do return NOT_FOUND end /* set content-type and send the HTTP header */ call WWWSendHTTPHeader r, "text/html" /* read in the document and look for the </BODY> tag */ call on notready name seteof eof = 0 line = linein(wwwfilename) x = pos(body, translate(line)) do while x = 0 & eof = 0 say line line = linein(wwwfilename) x = pos(body, translate(line)) end if eof = 1 then return OK /* we found a </BODY> tag so send out the footer */ say substr(line, 1, x - 1) call send_footer say substr(line, x) /* read in the rest of the document */ line = linein(wwwfilename) do while eof = 0 say line line = linein(wwwfilename) end /* we are done */ return OK /* function which indicates end-of-file */ seteof: eof = 1 return /* send the footer */ send_footer: say '<br />' say '<hr />' say '<br />' say '© 2001 <a href="http://www.ibm.com/">IBM Corporation</a>' say '<br />' say '<em>Last Modified:' date()'</em>' say '<br />' return |
Note that REXX program files (on Unix variants) do NOT need to be marked executable in order for Mod_Rexx to execute them. If you do not mark them executable then they cannot be executed outside of the Mod_Rexx environment by accident or maliciously through the standard Apache CGI interface.
To control access to documents or pages from a set of ip addresses you need to place the following in your Apache Configuration file (httpd.conf).
<Location /mytest> RexxAccessHandler '/opt/IBMHTTPServer/rexx/access.rex' </Location> |
The RexxAccessHandler directive tells Apache to invoke the specified REXX script to check that the request originates from a specified set of ip address ranges.
When a document is retrieved from the specified document path then the REXX script will be invoked check the client's ip address.
http://www.myserver.com/mytest/testdoc.html |
The following is an example REXX script (access.rex) which ensures that the request originates from within the range 192.168.x.x.
/* these are some typical Apache return codes */ OK = 0 /* Module has handled this stage. */ FORBIDDEN = 403 /* Main document forbidden. */ /* get the Apache request record ptr */ r = arg(1) /* we add the ending period so REXX will see it as a string */ iprange = '192.168.' if substr(wwwremote_addr, 1, length(iprange)) <> iprange then return FORBIDDEN /* we are done */ return OK |
Note that REXX program files (on Unix variants) do NOT need to be marked executable in order for Mod_Rexx to execute them. If you do not mark them executable then they cannot be executed outside of the Mod_Rexx environment by accident or maliciously through the standard Apache CGI interface.