'
' VB script example to use CGI interface of ApplicGate.exe
' List directory content
' reinhold.leitner@applicgate.com (C) March 2019
'
' Argument 0: form data coming from GET request e.g. getDir?path=TestPost&email=reinhold.leitner%40applicgate.com
' or Name of input file with POST data that contains form data, e.g.
' path=TestPost&email=reinhold.leitner%40applicgate.com
' if email=echo: input StandardInput will be displayed
' Argument 1: IP address of caller
' Argument 2: logged on user (email)
'
Option Explicit
Dim StdIn, StdOut, objArgs, fso, a, line, objH, email, myPath, myArray, field, f, sf, fc, f1, outData, outLen, maxData
' Prepare header for output
Wscript.Echo "<!DOCTYPE html><html><meta charset='UTF-8'><body><div style='color:blue;'>"
Wscript.Echo Date & " " & Time & "<br>"
Set objArgs = WScript.Arguments
If objArgs.Count > 1 then Wscript.Echo "Your IP address is " & objArgs(1) & "<br>"
If objArgs.Count > 2 then Wscript.Echo "Your logon is " & objArgs(2) & "<br>"
If objArgs.Count > 0 then
Set fso = CreateObject("Scripting.FileSystemObject")
'Check if form data has been sent via GET request:
MyArray = Split(objArgs(0), "?", -1, 1)
if UBound(MyArray) > 0 then
line = MyArray(1)
else
'Read input file:
line = ""
On Error Resume next
Set a = fso.OpenTextFile (objArgs(0))
If Err.number <> 0 then
Wscript.Echo Err.Description
Err.Clear
Else
line = a.ReadLine()
a.close
End If
End If
If line <> "" Then
' Declare function to decode form data:
Set objH = CreateObject("htmlfile")
objH.parentWindow.execScript "function decode(s) {return decodeURIComponent(s)}", "jscript"
' Parse input data:
email = ""
myPath = ""
myArray = Split(line, "&", -1,1)
For Each field in myArray
if Left(field,5) = "path=" Then myPath = objH.parentWindow.decode(Right(field,Len(field)-5))
if Left(field,6) = "email=" Then email = objH.parentWindow.decode(Right(field,Len(field)-6))
Next
If email <> "" then Wscript.Echo "Your email address is " & email & "<br>"
Wscript.Echo "<br>"
' Just for test: Echo input ?
If email = "echo" Then
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
Do While Not StdIn.AtEndOfStream
StdOut.WriteLine StdIn.ReadLine & "<br>"
Loop
StdOut.WriteLine "<br>"
End If
'
if myPath <> "" then
Wscript.Echo "List directory " & myPath & "<br><br>"
On Error Resume Next
Set f = fso.GetFolder(myPath)
If Err.number = 0 then
Set sf = f.SubFolders
For Each f1 in sf
outdata = f1.name & " <DIR><BR>"
Wscript.Echo outdata
Next
Set fc = f.Files
For Each f1 in fc
outdata = f1.name & "<BR>"
Wscript.Echo outdata
Next
Else
Wscript.Echo Err.Description
Err.Clear
'Wscript.Echo "Path not found!"
End If
Else
Wscript.Echo "Path is missing!"
End If
Else
Wscript.Echo "Input is missing!"
End If
Else
Wscript.Echo "Input data/file is missing!"
End If
Ende:
' Prepare trailer
Wscript.Echo "</div></body></html>"
| reinhold.leitner@applicgate.com (C) October 2025 www.applicgate.com |