Module CGI Programs

The Webmin web server treats files with the extension .cgi as CGI programs, just like most other web servers. All the forms, menus and other pages in your module will be generated by CGI programs, so knowledge of the basic concepts of CGI programming and HTML are necessary for writing a module.

Assuming your module is being written in perl, you should begin by writing a perl script that contains functions used by the CGI programs in your module. This script is usually called something like lib.pl or foobar-lib.pl. A minimal example of such a script might look like :

# foobar-lib.pl
# Common functions used for managing the foobar user list

do '../web-lib.pl';      (1)
&init_config();          (2)

# list_users()           (3)
# Returns a list of all foobar users
sub list_users
{
...
}

The 3 important features of the example above are :

  1. do '../web-lib.pl';
    The file web-lib.pl in the Webmin root directory contains a large number of functions that are useful for developing Webmin modules. All CGI programs should indirectly or directly require this module.

  2. &init_config();
    This function (defined in web-lib.pl) initializes the following global variables :

  3. The list_users function
    This is an example of a function that might be used by various CGI programs in this module. Some module library files may also include another file containing functions specific to the current operating system or configuration. See the proc-lib.pl in the proc module as an example.