Start of work on module to call webmin functions on a schedule
authorJamie Cameron <jcameron@webmin.com>
Thu, 13 May 2010 21:09:11 +0000 (14:09 -0700)
committerJamie Cameron <jcameron@webmin.com>
Thu, 13 May 2010 21:09:11 +0000 (14:09 -0700)
makedist.pl
webmincron/module.info [new file with mode: 0644]
webmincron/webmincron-lib.pl [new file with mode: 0644]

index dbc8fba..ab460a5 100755 (executable)
@@ -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 (file)
index 0000000..96da91e
--- /dev/null
@@ -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 (file)
index 0000000..007cd2f
--- /dev/null
@@ -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;
+