#!/bin/ksh APPX_RESULT=/tmp/$RANDOM.html export APPXPATH=/users/appx/data /users/appx/appx -a=WWW -d=WWW -t=OUTPUT -p=APPX_HOME_PAGE >/dev/null echo "Content-type: text/html" echo "" cat $APPX_RESULT rm $APPX_RESULTNote: If you are running on an APPX Promotional license, or any other license type that presents a start-up message screen (Release 4.1.8 and higher), the command above that invokes APPX must also include the "session flag", entered as -session or -s. It should look like this:
/users/appx/appx -a=WWW -d=WWW -t=OUTPUT -p=APPX_HOME_PAGE -s >/dev/nullThis will suppress all attempted screen displays by internally issuing an END option whenever a screen is presented. Two cautions: (1) If you're invoking a job that includes a disposition process, the END issued when the disposition runs will cancel the job, so be sure to remove any disposition processes from the job that you execute; (2) Release 4.1.8 had a bug that caused this to cancel the entire session, so upgrading to a newer release is required. You can call this script appxhome.cgi and anytime it is requested by a browser, the server will run the script to get the document. There is a little bit of trickery going on within the APPX process to get the print file back to the server. So, let us review the script a line at a time:
New URL = "/appx.cgi?DOCID=APPX+HOMEPAGE" #!/bin/ksh APPX_RESULT=/tmp/$RANDOM.html export APPXPATH=/users/appx/data /users/appx/appx -a=WWW -d=WWW -t=SUBR -p=APPX_WEB_SERVER >/dev/null cat $APPX_RESULT rm $APPX_RESULTWe have moved the Content-type lines into APPX for more control. That way, we are not limited to a certain document type. The APPX process can now decide if we are serving text/plain or text/html. Another thing you may seem to be missing here. How does the APPX subroutine know what document is being requested? The web server creates some special environment variables before it runs the CGI script. One of these is QUERY_STRING which contains the trailing data portion of the URL. So, our APPX subroutine only needs to check the value of this variable to find out what to do. There is an alternate method on calling a CGI script that involves feeding the CGI data as stdin to the script. This is good for large amounts of data that may otherwise overflow an environment variable. This difference is controlled by the web page being used to submit the request. You may also notice that our URL in this example does not contain the Application / Database / Process-Type / Process Name of the APPX process we want to run. We could do this, but creating a translation table file within your APPX server application makes the document less complex and increases security. This way, someone can't edit your document source within their browser and run some process you don't want them to run.
SET --- TEMP 32K = QUERY_STRING SET --- LI = 32767 SET --- NEW PAGE AFTER = N PASS --- TEMP 32K FIELD SHARE? Y PASS --- LI FIELD SHARE? Y CALL ,RT_GETENV RESIDENT? Y END? N FAIL 0The TEMP 32K field will contain one of two possible values. If the variable did not exist, then the value is unchanged. If the variable did exist, then the variable now contains the vaule of the requested environment variable. The other argument is just a limit on the number of bytes the function should try to shove into our alpha field. This is required and must be passed using a 32bit binary/numeric field.
SCRATCH CTS ARGLIST FAIL 0 CREATE CTS ARGLIST SHARE? Y FAIL 0 * SET CTS ARGLIST KEYWORD = REMOTE HOST SET --- TEMP 32K = CTS ARGLIST KEYWORD GOSUB :GETENV SET CTS ARGLIST VALUE = --- TEMP 32K WRITE CTS ARGLIST FAIL 0 * SET --- TEMP 32K = QUERY_STRING GOSUB :GETENV IF --- TEMP 32K EQ APPX_QUERY_STRING OR --- TEMP 32K EQ T END * SET --- PI = 0 BEG LOOP WI = 000 TO 001 STEP 000 RESTORE CTS ARGLIST DEFAULT RECORD GOSUB :GET KEYWORD GOSUB :GET VALUE WRITE CTS ARGLIST FAIL 0 IF --- TEMP 32K NE T END LOOP WI * END * =========================================================== LABEL :GETENV * ----------------------------------------------------------- SET --- LI = 32767 SET --- NEW PAGE AFTER = N PASS --- TEMP 32K FIELD SHARE? Y PASS --- LI FIELD SHARE? Y CALL ,RT_GETENV RESIDENT? Y END? N FAIL 0 RETURN * =========================================================== LABEL :GET KEYWORD * ----------------------------------------------------------- SET --- OI = 1 BEG LOOP XI = 000 TO 001 STEP 000 COMPUTE --- PI + 1 SET TEMP 1 AT 001 FOR 001 FROM PI OF --- TEMP 32K IF --- TEMP 1 NE = AND --- TEMP 1 NE T IF --- TEMP 1 EQ + TT SET --- TEMP 1 EQ TF IF --- TEMP 1 EQ % TFT GOSUB :CONVERT FROM HEX T SET TEMP 1 AT 001 FOR 001 INTO OI OF CTS ARGLIST KEYWORD T COMPUTE --- OI + 1 - SET --- TEMP 1 = - SET TEMP 32K AT PI FOR 001 FROM 001 OF --- TEMP 1 T END LOOP XI RETURN * =========================================================== LABEL :GET VALUE * ----------------------------------------------------------- SET --- OI = 1 BEG LOOP XI = 000 TO 001 STEP 000 COMPUTE --- PI + 1 SET TEMP 1 AT 001 FOR 001 FROM PI OF --- TEMP 32K IF --- TEMP 1 NE & AND --- TEMP 1 NE T IF --- TEMP 1 EQ + TT SET --- TEMP 1 EQ TF IF --- TEMP 1 EQ % TFT GOSUB :CONVERT FROM HEX T SET TEMP 1 AT 001 FOR 001 INTO OI OF CTS ARGLIST VALUE T COMPUTE --- OI + 1 - SET --- TEMP 1 = - SET TEMP 32K AT PI FOR 001 FROM 001 OF --- TEMP 1 T END LOOP XI RETURN * =========================================================== LABEL :CONVERT FROM HEX * ----------------------------------------------------------- SET --- TEMP 1 = SET TEMP 32K AT PI FOR 001 FROM 001 OF --- TEMP 1 COMPUTE --- PI + 1 SET TEMP 1 AT 001 FOR 001 FROM PI OF --- TEMP 32K CNV BIN --- YI = --- TEMP 1 COMPUTE --- YI - 48 IF --- YI GT 9 T COMPUTE --- YI - 7 COMPUTE --- YI * 16 SET --- ZI = --- YI SET --- TEMP 1 = SET TEMP 32K AT PI FOR 001 FROM 001 OF --- TEMP 1 COMPUTE --- PI + 1 SET TEMP 1 AT 001 FOR 001 FROM PI OF --- TEMP 32K CNV BIN --- YI = --- TEMP 1 COMPUTE --- YI - 48 IF --- YI GT 9 T COMPUTE --- YI - 7 COMPUTE --- ZI + --- YI CNV BIN --- TEMP 1 = --- ZI RETURNNow, after this routine is run, you can access any of the Data by setting the ARGLIST KEYWORD to the variable name, reading the ARGLIST memory file, and using the value of the ARGLIST VALUE field.
SET CTS ARGLIST KEYWORD = DOCID READ CTS ARGLIST HOLD 0 FAIL 0 KEY IS ARGLIST KEYWORD F SET CTS WORK ERROR TEXT = DOCID Not on File! F SET CTS REQUEST PROCESS = STANDARD ERROR
SET --- NEXT PROCESS NAME = CTS REQUEST PROCESS JOB SUBPROCESS END? N FAIL 0
SET --- TEMP 132 = mv APPEND --- TEMP 132 1 --- PRINT FILE PATHNAME APPEND --- TEMP 132 1 CTS WORK APPX RESULT APPEND --- TEMP 132 1 >/dev/null 2>&1 SET --- NEW PAGE AFTER = N RUN --- TEMP 132 END? N FAIL 0