From 0cfd34d672fd2e600e6d0d1c4e446f5081f2aebe Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Thu, 13 May 2010 14:09:11 -0700 Subject: [PATCH] Start of work on module to call webmin functions on a schedule --- makedist.pl | 4 +- webmincron/module.info | 3 ++ webmincron/webmincron-lib.pl | 87 ++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 webmincron/module.info create mode 100644 webmincron/webmincron-lib.pl diff --git a/makedist.pl b/makedist.pl index dbc8fba0b..ab460a567 100755 --- a/makedist.pl +++ b/makedist.pl @@ -44,7 +44,7 @@ $zipdir = "zips"; if ($min) { # Only those required by others @mlist = ("cron", "init", "inittab", "proc", "webmin", "acl", "servers", - "man", "webminlog", "system-status"); + "man", "webminlog", "system-status", "webmincron"); } else { # All the modules @@ -71,7 +71,7 @@ else { "tunnel", "zones", "cluster-usermin", "dovecot", "syslog-ng", "mailcap", "blue-theme", "ldap-client", "phpini", "filter", "bacula-backup", "ldap-server", "exim", "tcpwrappers", - "package-updates", "system-status", + "package-updates", "system-status", "webmincron", ); } @dirlist = ( "Webmin" ); diff --git a/webmincron/module.info b/webmincron/module.info new file mode 100644 index 000000000..96da91eb3 --- /dev/null +++ b/webmincron/module.info @@ -0,0 +1,3 @@ +desc=Scheduled Webmin Functions +longdesc=Define Webmin module functions that are called on a regular schedule by the Webmin webserver +category=webmin diff --git a/webmincron/webmincron-lib.pl b/webmincron/webmincron-lib.pl new file mode 100644 index 000000000..007cd2fbe --- /dev/null +++ b/webmincron/webmincron-lib.pl @@ -0,0 +1,87 @@ +=head1 webmincron-lib.pl + +Functions for creating and listing Webmin scheduled functions. + +=cut + +BEGIN { push(@INC, ".."); }; +use WebminCore; +&init_config(); +$webmin_crons_directory = "$module_config_directory/crons"; + +=head2 list_webmin_crons + +Returns a list of all scheduled Webmin functions. Each of which is a hash ref +with keys : + +=item id - A unique ID number + +=item module - The module in which the function is defined + +=item file - File in which the function is declared + +=item func - Name of the function to call + +=item arg0,arg1,etc.. - Strings to pass to the function as parameters + +=item interval - Number of seconds between runs + +=cut +sub list_webmin_crons +{ +my @rv; +opendir(CRONS, $webmin_crons_directory) || return ( ); +foreach my $f (readdir(CRONS)) { + if ($f =~ /^(\d+)\.cron$/) { + my %cron; + &read_file_cached("$webmin_crons_directory/$f", \%cron); + $cron{'id'} = $1; + push(@rv, \%cron); + } + } +return @rv; +} + +=head2 save_webmin_crons(&cron) + +Create or update a webmin cron function. Also locks the file being written to. + +=cut +sub save_webmin_cron +{ +my ($cron) = @_; +if (!-d $webmin_crons_directory) { + &make_dir($webmin_crons_directory, 0700); + } +if (!$cron->{'id'}) { + $cron->{'id'} = time().$$; + } +my $file = "$webmin_crons_directory/$cron->{'id'}.cron"; +&lock_file($file); +&write_file($file, $cron); +&unlock_file($file); +} + +=head2 delete_webmin_cron(&cron) + +Deletes the file for a webmin cron function. Also does locking. + +=cut +sub delete_webmin_cron +{ +my ($cron) = @_; +my $file = "$webmin_crons_directory/$cron->{'id'}.cron"; +&lock_file($file); +&unlink_file($file); +&unlock_file($file); +} + +=head2 create_webmin_cron(module, function, interval, &args) + +=cut +sub create_webmin_cron +{ +} + +1; +