Janus Web Server application example

From m204wiki
Revision as of 00:23, 24 February 2012 by JAL2 (talk | contribs) (Created page with "The code for the following sample Web application is in file <var>SIRIUS</var> (file <var>JANUS</var>, if prior to <var class="product">Sirius Mods</var> version 6.8) on the Siri...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The code for the following sample Web application is in file SIRIUS (file JANUS, if prior to Sirius Mods version 6.8) on the Sirius product tape, which should be installed in the Janus Web Server online.

Several more examples of web applications are provided on the Sirius web site.

Sample application: command processor

This sample application demonstrates a simple way to execute Model 204 commands from a web browser. While this is a modest use of the Web Server, and one that you may not ever implement in a production application system, it presents an example whose purpose is readily understood. More important, it describes the use of forms for obtaining and processing user input and demonstrates the common processes used in a simple web server program.

Note that this example does take advantage of several special purpose Sirius $functions, such as those for creating and manipulating $lists which provide a useful way to manipulate arrays of data. These functions are available as a separately purchased option.

PROCEDURE DEMO_COMMAND * Submit a command-level command to Model 204. * This sample program provides both the form and the * response to the form. You determine whether a user is * getting a form or submitting it by querying the * 'METHOD' parameter in the form's header (using * $Web_Hdr_Parm). If METHOD=POST, you are supposed * to respond to the user's request. Begin * Declare and initialize. %listo is float %rc is float %x is float %cform is string len 10 %command is string len 100 %listo = $listnew * Set the global "TITLE" and use $Web_Sub to make it * appear on the page. %rc = $setg('TITLE', - 'Data Access Demonstrations /' - WITH ' Janus Web Server' ) %rc = $web_type('TEXT/HTML') %rc = $web_sub('@@') * Route terminal output to the user. %rc = $web_on * Get the value of the form parameter 'CFORM'. %cform = $upcase($web_form_parm('CFORM')) * Send the page header that's in procedure 'HTML_HEADER' * (use 'MORE' so we can continue sending). %rc = $web_procsend(,'HTML_HEADER','MORE') * Send the body of the page. Print '<H1>Model 204 Command Processor</H1>' Print '<hr>' Print 'Here's a novel idea: Bring all the power and' Print 'elegance of a 3270 screen into your Web' Print 'browser. This shows how terminal output is' Print 'routed to your browser.' Print '<p>' Print 'Would you like to' Print '<A HREF="/DEMO_COMMAND">see the code</A>' Print 'that generates this form?' Print '</p>' Print '<hr>' * Send the body of the form. Print '<FORM NAME="CFORM" METHOD="POST"' Print ' ACTION="' WITH $WEB_HDR_PARM('URL') WITH '">' Print 'Command: <INPUT TYPE="TEXT" SIZE=50' WITH ' NAME="CMD"' Print 'VALUE="' WITH %CFORM WITH '">' Print '<INPUT TYPE="SUBMIT" VALUE="Submit">' Print '</FORM>' * If the form was POST'ed to us, process the command. If $web_hdr_parm('method') eq 'post' Then %command = $upcase($web_form_parm('CMD')) If $index(%command,'EOJ') or - $index(%command,'EOD') or - $index(%command,'BUMP') or - $index(%command,'JANUS FORCE') or - $index(%command,'JANUS DRAIN') or - $index(%command,'INITIALIZE') Then Print 'Good try. But it wouldn't' - With ' have worked' Print 'anyway because you don't have the' Print 'privilege for that command.' Stop End If * Submit command for "sdaemon" processing. %rc = $comndl( $upcase($web_form_parm('CMD')), , %listo) * Print the return. Print '<tt>' For %x from 1 to $listcnt(%listo) Print $listinf(%listo,%x) With '<br>' End For Print '</tt>' End If * Send the pre-defined page footer from procedure 'HTML_FOOTER'. %rc = $web_procsend(,'HTML_FOOTER') End END PROCEDURE DEMO_COMMAND

Sample configuration deck

This is a sample set of JANUS subcommands that define a web server. These commands are described further in "Defining Web rules".

* If the port is running, stop it and delete it. JANUS FORCE JANWEB JANUS DELETE JANWEB * Redefine the web port, allowing 100 connections JANUS DEFINE JANWEB 80 WEBSERV 100 WEBUSER WEBUSER - DEBUG 3 UPCASE OBSIZE 10240 OPEN FILE JANWEB * Build a set of IP addresses that we'll grant access to. JANUS DELETEIPGROUP SIRIUS JANUS DEFINEIPGROUP SIRIUS 198.242.244.0/255.255.255.0 - 166.84.192.69 * Build a set of userids that we'll grant access to. JANUS DELETEUSGROUP SIRIUS JANUS DEFINEUSGROUP SIRIUS ALAN* ALEX* TOM* DME* JEFF* - GARY* DAVE* PETE* DARREN* EUROPE* * Turn off redirection. JANUS WEB JANWEB NOREDIRECT * * Let everybody in. JANUS WEB JANWEB ALLOW * * Now selectively protect certain "directories", * providing access only to the above-defined IPGROUP and USGROUP. JANUS WEB DISALLOW /MANUALS/* JANUS WEB DISALLOW /FIXES/* JANUS WEB JANWEB ALLOW /MANUALS/* IPGROUP SIRIUS USGROUP SIRIUS JANUS WEB JANWEB ALLOW /FIXES/* IPGROUP SIRIUS USGROUP SIRIUS * Set some content types for which Janus Web doesn't supply defaults. JANUS WEB JANWEB TYPE *.HTM TEXT/HTML JANUS WEB JANWEB TYPE *.PDF APPLICATION/PDF JANUS WEB JANWEB TYPE *.JAV APPLET/JAVA JANUS WEB JANWEB TYPE *.JAVA APPLET/JAVA * Set the rules for what we do when specific URLs come in. JANUS WEB JANWEB ON /* SEND * JANUS WEB JANWEB ON / SEND HTML_MAIN JANUS WEB JANWEB ON /JANUS SEND HTML_MAIN * These re-mappings aren't really necessary, they are * just done so Model 204 procedures that have similar * contents can be sorted together because they start * with the same characters. In other words, when a URL * comes in for the picture 'FASTCAR.GIF' we will have * actually stored it in a procedure called GIF_FASTCAR * just to make procedure management simpler. JANUS WEB JANWEB ON /*.HTML SEND HTML_* JANUS WEB JANWEB ON /*.HTM SEND HTML_* JANUS WEB JANWEB ON /*.GIF SEND GIF_* JANUS WEB JANWEB ON /*.JPG SEND JPG_* JANUS WEB JANWEB ON /*.JAV SEND JAVA_* JANUS WEB JANWEB ON /*.JAVA SEND JAVA_* JANUS WEB JANWEB ON /*.PDF SEND PDF_* * These ON commands invoke procedures. If a URL * requests anything in directory CMD or COMMAND, we * just execute the URL itself at the Model 204 command level. JANUS WEB JANWEB ON /COMMAND/* CMD * JANUS WEB JANWEB ON /CMD/* CMD * JANUS WEB JANWEB ON /DEMO/* CMD 'IN FILE JANWEB INCLUDE *' JANUS WEB JANWEB ON /SUBSYS/* CMD 'APSYMGMT *' * Start the server. JANUS START JANWEB

For more configuration commands, see "Defining Web rules".