57.1. Module Design and CGI Programs

As Chapter 10 explains, this module lets a user view, edit, and create Cron jobs for all UNIX users on a system. It gets the lists of jobs by reading several different files, such as those in the /var/spool/cron directory, those in /etc/cron.d, and those in /etc/crontab. The exact paths depend upon the operating system on which Webmin is running, as every UNIX variant seems to have its own implementation of Cron.

In addition to editing jobs, the module can also be used to execute those that have already been defined and view their output. Users can also edit the files that control which users have access to Cron, usually named /etc/cron.allow and /etc/cron.deny.

The CGI programs that make up this module are:

index.cgi Displays a list of jobs that the current Webmin user is allowed to access, each of which is a link to the editing page created by edit_cron.cgi with a parameter identifying the index of the job to edit. The actual list comes from the list_cron_jobs function in cron-lib.pl.

edit_cron.cgi Produces HTML for a form for either editing an existing job or creating a new one, depending on the idx and new parameters. Again, the details of a job being edited are taken from idx.

The list_cron_jobs function At the bottom of the generated page are buttons that submit to either save_cron.cgi or delete_cron.cgi.

save_cron.cgi Calls ReadParse to get the form inputs from edit_cron.cgi and validates them to make sure all of the required fields have been filled. If so, functions from cron-lib.pl are called to either create a new job or update an existing job and then a redirect is called to make the user's browser return to index.cgi. If an error is detected, however, the standard error function is called instead.

When changing the user that a job runs as, this program needs to delete and recreate it so that it ends up in the right file, instead of just changing it in place.

delete_cron.cgi Runs when the Delete button on the editing form is clicked. Just calls a function from cron-lib.pl to remove the job specified by the idx parameter and then redirects the browser to index.cgi.

exec_cron.cgi This CGI uses the safe_process_exec function from the Running Processes module to run the command for a specified Cron job as the user who owns it and displays the output. It also deletes any environment variables that are specific to Webmin, so that programs run by the Cron job do not get confused and think that they are being called as CGI programs when this is not really the case.

edit_allow.cgi Just displays a form for entering either a list of users who are allowed to use Cron or a list of those who cannot. The current settings are obtained by calling functions in cron-lib.pl.

save_allow.cgi Saves the inputs from the form created by edit_allow.cgi back to the original files, again by calling functions from the module's library.

This module follows a design common to many others—a single page listing objects to edit, each of which is a link to a form for editing. Your modules should use the same layout where appropriate, instead of displaying a huge table for editing multiple objects at once. It is a good idea to imitate this module's use of multiple CGI programs, as well, instead of trying to output everything in a single script. In all of the standard modules, a separate program generates each page and, if the page is a form, it is submitted to yet another program. This makes each one simpler and easier to understand instead of putting both the form generating and processing code into a single script. The redirect function is used by all of the form processing save_ CGIs to return the user's browser to the module's main page, rather than back to the editing form.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.105.72