ApplicGate
(v13.0.9671.29536 started 2026-06-24 14:33:07 on VM2)

'
' VB script example to use CGI interface of ApplicGate.exe
'    List directory content
'    reinhold.leitner@applicgate.com (C) March 2026
'
'   example only — restrict the path (see below)
'
' 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=store&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, allowedPathArray,allowedPathFields, allowedPath, PathOk
'
'  allowedPaths must be adjusted !!!
allowedPathArray = "store|c:\xy"
'
' 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
    '
    ' Check if path is allowed
    allowedPathFields = Split(allowedPathArray,"|",-1,1)
    PathOk = 0
    'Wscript.Echo myPath
    For Each allowedPath in allowedPathFields
      'Wscript.Echo allowedPath
      If myPath = allowedPath then 
        PathOk = 1
        Exit For
      End If
    Next

    If PathOk = 1 then
      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 & " &lt;DIR&gt;<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 "Path not allowed!"
    End If
  Else
    Wscript.Echo "Input is missing!"
  End If
Else
  Wscript.Echo "Input data/file is missing!"
End If
' Prepare trailer
Wscript.Echo "</div></body></html>"

ApplicGate Logo  reinhold.leitner@applicgate.com (C) June 2026
www.applicgate.com