From d03753f33432c790d7ed6c2487080e09bf884254 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 9 Sep 2021 11:09:12 -0400 Subject: Update CGI documentation and add testable examples for CGI support (Issue #5940) --- doc/help/cgi.html | 97 ++++++++++++++++--------------------------------------- doc/test.cgi | 7 ++++ doc/test.php | 20 ++++++++++++ 3 files changed, 55 insertions(+), 69 deletions(-) create mode 100755 doc/test.cgi create mode 100755 doc/test.php (limited to 'doc') diff --git a/doc/help/cgi.html b/doc/help/cgi.html index 34c6debb3..150bacdbc 100644 --- a/doc/help/cgi.html +++ b/doc/help/cgi.html @@ -1,82 +1,41 @@ - + + - - Using CGI Programs - - - + + Using CGI Programs + + + +

Using CGI Programs

-

Using CGI Programs

+

CUPS provides a dynamic web interface through dedicated CGI programs that are executed when users open special directories on the CUPS server. Each CGI performs administration, class, help, job, and printer functions as directed by the user, but the actual programs that are run and functions that are available are limited to those that were originally designed into the scheduler.

-

CUPS provides a dynamic web interface through dedicated CGI programs that -are executed when users open special directories on the CUPS server. Each CGI -performs administration, class, help, job, and printer functions as directed by -the user, but the actual programs that are run and functions that are available -are limited to those that were originally designed into the scheduler.

+

CUPS also supports CGI scripts/programs for pages you want to provide, although this functionality is disabled by default. The "application/x-httpd-cgi" MIME media type is used to identify CGI content and can be associated with any filename extension. The scheduler requires CGI content to have the execute bit set, not have world or group write permissions, and any CGI scripts need to include a #! line as the first line of a script to identify the script interpreter. For example, a PHP script would look like:

-

CUPS also supports CGI programs and specific scripting languages (Java, Perl, -PHP, and Python) for pages you want to provide. The interpreters for these -languages are currently configured at compile time and are associated with -MIME media types. Table 1 shows the MIME media types that -are reserved for each type of page and are the same as those used by the Apache -web server.

+
+#!/usr/bin/php -fn
+<?php
+...
+?>
+
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
Table 1: CGI MIME Media Types
MIME Media TypeDescription
application/x-httpd-cgiCGI script/program
application/x-httpd-javaJava program
application/x-httpd-perlPerl script
application/x-httpd-phpPHP script
application/x-httpd-pythonPython script
-

Configuring the Server

+

Configuring the Server

-

In order to enable the corresponding type, you must create a -new /etc/cups/cgi.types file which maps the filename -extensions to the appropriate MIME types, for example:

+

In order to enable the corresponding type, you must create a new /etc/cups/cgi.types file which maps the filename extensions you use to the appropriate MIME types. For example, the following will support CGI programs/scripts with the "cgi" extension:

-
+    
 application/x-httpd-cgi cgi
-application/x-httpd-java class
-application/x-httpd-perl pl
-application/x-httpd-php php
-application/x-httpd-python py
-
+
-

CGI scripts/programs (application/x-httpd-cgi) also must be owned by root, have execution permissions, and not have world or group write permissions to be treated as a CGI script or program.

-

Limitations

+

Limitations

-

CUPS implements most of the CGI/1.1 specification, with the -following exceptions:

+

CUPS implements most of the CGI/1.1 specification, with the following exceptions:

- - - - + + + diff --git a/doc/test.cgi b/doc/test.cgi new file mode 100755 index 000000000..6d98759a3 --- /dev/null +++ b/doc/test.cgi @@ -0,0 +1,7 @@ +#!/bin/sh +echo "Content-Type: text/plain" +echo "" +echo "POSIX shell CGI test page." +echo "" +echo "ps ax" +ps ax diff --git a/doc/test.php b/doc/test.php new file mode 100755 index 000000000..f33a54f74 --- /dev/null +++ b/doc/test.php @@ -0,0 +1,20 @@ +#!/usr/bin/php -nf +\n" + ."\n" + ." \n" + ." PHP script CGI test page\n" + ." \n" + ." \n" + ."

PHP script CGI test page

\n" + ."
ps ax\n");
+$fp = popen("ps ax", "r");
+while ($line = fgets($fp, 1024))
+{
+  print(htmlspecialchars($line));
+}
+print("
\n" + ." \n" + ."\n"); +?> -- cgit v1.2.1