Home API Documentation FAQ Articles Buy PLUS Releases Contacts

← Back to Articles

CGI

CGI (Common Gateway Interface) is a feature that allows the server to run scripts or executables in response to certain HTTP requests and return the script's output as the response. At the time of writing, this feature isn't very practical on most Android setups because Android has many limitations regarding running custom command-line programs. The most likely use case is if you manually install some interpreters on a rooted Android device. It is useful for dynamic content, form handling, or integrating with local tools. Note that CGI is not available when using some file access methods on Android (e.g. Storage Access Framework or Media Store); the File API is required.

Enabling the feature

CGI is enabled by checking the corresponding checkbox in the Handlers section of the app settings. When you enable it, you can configure how requests are mapped to scripts.

CGI - Enabling the feature
CGI - Enabling the feature

Configuration screen

On the configuration screen you can set:

  • CGI root directory — The root directory for CGI scripts. All scripts must be placed within this directory or a subdirectory of it. If you leave this field empty, the server will use the document root directory (the directory that contains the files you want to serve) as the CGI root directory. Use this with caution as it can be a security risk. Better to set it to a dedicated directory for CGI scripts. If you still decide to use the document root directory, make sure to uncheck the "Allow file modification" checkbox in the Allow file modification section of the app settings.
  • CGI path prefix — A prefix for the URL path. Only requests whose path starts with this prefix are considered for CGI. This prefix will be excluded from the script path. For example, if you set the prefix to /cgi and the request path is /cgi/script.php, the script will be looked for in [cgi root]/script.php path.
  • List of file types — A list of file types that will be treated as CGI scripts (see its description below).
CGI - Configuration screen
CGI - Configuration screen

File types

You can set the file types that will be treated as CGI scripts. When a request is received, the server will check if the requested file has one of the specified file types. If it does, the server will treat it as a CGI script and run it. The script will be run with the following environment variables:

  • Extension — The extension of the file. For example, if you set the extension to .php, the server will treat files with .php extension as CGI scripts.
  • Mode — The mode of the script. There are two modes available: CGI and Simple. Difference between them is that in CGI mode the server trying to follow the CGI protocol (RFC 3875) while passing all the request data to the script as environment variables, while in Simple mode the server will simply transform url query parameters named "arg" as script arguments.
  • Execute with — The command to execute the script. For example, if you set the command to python, the server will execute the script using Python interpreter.
  • Execution timeout — The timeout for the script execution. If the script execution takes longer than the timeout, the server will kill the script and return a 500 Internal Server Error response.
CGI - File types
CGI - File types