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 :
- 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.
- &init_config();
This function (defined in web-lib.pl) initializes the following
global variables :
- %config
Contains the current configuration for this module. This typically
is used to store user editable options and operating system specific
information. Module config files are described in more detail
below.
- %gconfig
Contains the global Webmin configuration. See below for more
details.
- $module_name
The name of this module, which is just the name of the directory
the module is in.
- $module_config_directory
The directory in which this module's config file is stored.
If your module creates permanent files or programs for some
reason (such as print driver scripts), they should be created
in or under this directory.
- $tb
The background colour for table headers.
- $cb
The background colour for table bodies.
- $scriptname
The name of the CGI program currently being run, relative to
the directory it is in (such as save_foo.cgi).
- 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.