ApplicGate
(v12.0.8889.39591 started 2024-05-03 21:03:28 on VM2)

CGI examples: Usage of keywords POST, STARTG and STARTP:

GatewayIP2 is web, DIR:TestPost ... subdirectory of default directory

Example 1 ... GET request http://server/Outp.bat
STARTG:Outp.bat!TestPost\*!!10!H!TestPost/PostResponse.htm
When URL Outp.bat has been received: Start file TestPost\Outp.bat, wait maximum 10 seconds and convert output to an HTML-encoded string.
Sample content of Outp.bat:
 @echo off
 echo Date: %Date%
 echo Time: %Time%
 dir C:\ 
Sample content of PostResponse.htm:
<!DOCTYPE html><html><body><div style="color:red;"><pre>
%output%
</pre></div></body></html>
Note: string %output% will be replaced by standard output of Outp.bat

Example 2 ... GET request http://server/Outp2.bat
STARTG:Outp2.bat!TestPost\* ... start file Outp2.bat
Sample content of Outp2.bat:
 @echo off
 type testpost\htmlstart.txt
 ipconfig /all
 type testpost\htmlend.txt
 
Sample content of htmlstart.txt:
 <!DOCTYPE html><html><meta charset="UTF-8"><body><pre> 
Sample content of htmlend.txt:
 </pre></body></html> 
Note:
- As there is no reformatting of the output: <meta charset="UTF-8"> and <pre> (formats CRLF) should be specified.

Example 3 ... POST request http://server/Outp3.bat
Input data comes from an HTML form by POST, e.g.:
 computername0=A&company=ApplicGate&email=reinhold.leitner%40applicgate.com
POST:"TestPost\*$|.txt" ... name of file for POST data has a timestamp and the extension .txt
STARTP:Outp3.bat!TestPost\*!!10!DUH!TestPost/PostResponse.htm ... start file Outp3.bat, UrlDecode and HtmlEncode output, delete posted file
Sample content of Outp3.bat:
 @echo off
 rem Remove quotes of input file name:
 FOR /F %%i IN (%1) DO set file=%%i
 rem Parse form data and set environment variables:
 FOR /F "delims=& tokens=1-3" %%i IN (%file%) DO SET %%i&SET %%j&SET %%k
 echo The license for computer %computername0% will be sent to %email%. 
Note: PostResponse.htm has the same content as in example 1 above

Response will be:
The license for computer A will be sent to reinhold.leitner@applicgate.com.
Warning: No error handling when tokens are missing and any environment variable can be overridden!

Example 4 ... GET request http://server/showhttp
Returns the http header and the arguments:
STARTG:showhttp!cmd.exe!/Cmore & echo !10!HB

Example 5 ... Visual Basic and Java script processing with GET and POST:
STARTG:*.vbs?*.js!cscript.exe!//NoLogo TestPost\*
STARTP:*.vbs?*.js!cscript.exe!//NoLogo TestPost\*!!D
Input data comes from an HTML form by GET or POST, e.g. for directory example below:
 path=c%3A%5C&email=reinhold.leitner%40applicgate.com
Directory Example with Visual Basic Script: Dir.vbs

Listing of input parameters with Java script:
var stdin = WScript.StdIn;
var stdout = WScript.StdOut;
var objArgs = WScript.Arguments;
stdout.WriteLine("<!DOCTYPE html><html><meta charset='UTF-8'><body><div style='color:blue;'>");
for (i = 0; i < objArgs.length; i++)  {
    stdout.WriteLine("Argument " + i + ": " + objArgs(i) + "<BR>");
}
while (!stdin.AtEndOfStream) {
    var str = stdin.ReadLine();
    stdout.WriteLine("Line " + (stdin.Line - 1) + ": " + str + "<br>");
}
stdout.WriteLine("</div></body></html>");

Example 6 ... Simple command interface:
STARTG:*!cmd.exe!/CTestPost\mycmd.bat *!10!Q!.txt
respfile .txt sets media type text/plain
Sample content of mycmd.bat:
@echo off
Rem Remove quotes of input:
FOR /F "delims=&" %%i IN (%1) DO set mycmd=%%i
echo %mycmd%
%mycmd%
Note: Special characters must be masked in URL, e.g. "\" --> "%5C"

ApplicGate Logo  reinhold.leitner@applicgate.com (C) May 2024
www.applicgate.com