mirror of
https://github.com/webmin/webmin.git
synced 2026-05-04 22:30:33 +01:00
Start of work on module to call webmin functions on a schedule
This commit is contained in:
@@ -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" );
|
||||
|
||||
3
webmincron/module.info
Normal file
3
webmincron/module.info
Normal file
@@ -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
|
||||
87
webmincron/webmincron-lib.pl
Normal file
87
webmincron/webmincron-lib.pl
Normal file
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user