More work on status collection module
authorJamie Cameron <jcameron@webmin.com>
Mon, 5 Oct 2009 23:24:09 +0000 (16:24 -0700)
committerJamie Cameron <jcameron@webmin.com>
Mon, 5 Oct 2009 23:24:09 +0000 (16:24 -0700)
cron/cron-lib.pl
makedist.pl
system-status/config [new file with mode: 0644]
system-status/system-status-lib.pl
webmin/change_status.cgi [new file with mode: 0644]
webmin/edit_status.cgi [new file with mode: 0644]
webmin/images/status.gif [new file with mode: 0644]
webmin/index.cgi
webmin/lang/en

index 64904b8..56a78cf 100755 (executable)
@@ -1209,12 +1209,12 @@ if (!$proc && $cmd =~ /^$config_directory\/(.*\.pl)(.*)$/) {
 return $proc;
 }
 
-=head2 find_virtualmin_cron_job(command, [&jobs], [user])
+=head2 find_cron_job(command, [&jobs], [user])
 
 Returns the cron job object that runs some command (perhaps with redirection)
 
 =cut
-sub find_virtualmin_cron_job
+sub find_cron_job
 {
 my ($cmd, $jobs, $user) = @_;
 if (!$jobs) {
index bb7f23b..7794216 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");
+                 "man", "webminlog", "system-status");
        }
 else {
        # All the modules
diff --git a/system-status/config b/system-status/config
new file mode 100644 (file)
index 0000000..1e5b112
--- /dev/null
@@ -0,0 +1,2 @@
+collect_interval=none
+collect_pkgs=1
index 514aea2..a0ac448 100755 (executable)
@@ -1,16 +1,16 @@
 # Functions for collecting general system info
 #
-# XXX Webmin module page to enable background collection
 # XXX Use on main page of blue theme
 # XXX Show package updates on blue theme main page
 # XXX Collect from Cloudmin
 # XXX Cloudmin should enable background collection
+# XXX Check new Webmin version and module updates too?
 
 BEGIN { push(@INC, ".."); };
 eval "use WebminCore;";
 &init_config();
 $systeminfo_cron_cmd = "$module_config_directory/systeminfo.pl";
-&foreign_require("cron", "cron-lib.pl");
+$collected_info_file = "$module_config_directory/info";
 
 # collect_system_info()
 # Returns a hash reference containing system information
@@ -27,13 +27,7 @@ if (&foreign_check("proc")) {
                }
        local @procs = &proc::list_processes();
        $info->{'procs'} = scalar(@procs);
-       if ($config{'mem_cmd'}) {
-               # Get from custom command
-               local $out = &backquote_command($config{'mem_cmd'});
-               local @lines = split(/\r?\n/, $out);
-               $info->{'mem'} = [ map { $_/1024 } @lines ];
-               }
-       elsif (defined(&proc::get_memory_info)) {
+       if (defined(&proc::get_memory_info)) {
                local @m = &proc::get_memory_info();
                $info->{'mem'} = \@m;
                if ($m[0] > 128*1024*1024 && $gconfig{'os_type'} eq 'freebsd') {
@@ -44,35 +38,9 @@ if (&foreign_check("proc")) {
                        }
                }
        if (&foreign_check("mount")) {
-               &require_useradmin();
-               &foreign_require("mount", "mount-lib.pl");
-               local @mounted = &mount::list_mounted();
-               local $total = 0;
-               local $free = 0;
-               local $donezone;
-               foreach my $m (@mounted) {
-                       if ($m->[2] =~ /^ext/ ||
-                           $m->[2] eq "reiserfs" || $m->[2] eq "ufs" ||
-                           $m->[2] eq "zfs" || $m->[2] eq "simfs" ||
-                           $m->[2] eq "xfs" || $m->[2] eq "jfs" ||
-                           $m->[1] =~ /^\/dev\// || $m->[1] eq $home_base) {
-                               if ($m->[1] =~ /^(zones|zonas)\/([^\/]+)/ &&
-                                   $m->[2] eq "zfs" &&
-                                   $donezone{$2}++) {
-                                       # Only count each zone once, as there
-                                       # may be mounts from zones/foo/bar
-                                       # and zones/foo/smeg that really refer
-                                       # to the zone source.
-                                       next;
-                                       }
-                               local ($t, $f) =
-                                       &mount::disk_space($m->[2], $m->[0]);
-                               $total += $t*1024;
-                               $free += $f*1024;
-                               }
-                       }
-               $info->{'disk_total'} = $total;
-               $info->{'disk_free'} = $free;
+               &foreign_require("mount");
+               ($info->{'disk_total'}, $info->{'disk_free'}) =
+                       &mount::local_disk_space();
                }
        }
 
@@ -85,8 +53,8 @@ $info->{'kernel'} = { 'version' => $r,
                      'os' => $o };
 
 # Available package updates
-if (&foreign_check("package-updates")) {
-       &foreign_require("package-updates"):
+if (&foreign_check("package-updates") && $config{'collect_pkgs'}) {
+       &foreign_require("package-updates");
        local @poss = &package_updates::list_possible_updates(2);
        $info->{'poss'} = \@poss;
        }
@@ -141,9 +109,9 @@ sub refresh_possible_packages
 local ($pkgs) = @_;
 local %pkgs = map { $_, 1 } @$pkgs;
 local $info = &get_collected_info();
-if ($info->{'poss'} && &foreign_check("security-updates")) {
-       &foreign_require("security-updates", "security-updates-lib.pl");
-       local @poss = &security_updates::list_possible_updates(2);
+if ($info->{'poss'} && &foreign_check("package-updates")) {
+       &foreign_require("package-updates");
+       local @poss = &package_updates::list_possible_updates(2);
        $info->{'poss'} = \@poss;
        }
 &save_collected_info($info);
@@ -178,68 +146,6 @@ if ($info->{'disk_total'}) {
                       $info->{'disk_total'}-$info->{'disk_free'},
                       $info->{'disk_total'} ]);
        }
-push(@stats, [ "doms", $info->{'fcount'}->{'doms'} ]);
-push(@stats, [ "users", $info->{'fcount'}->{'users'} ]);
-push(@stats, [ "aliases", $info->{'fcount'}->{'aliases'} ]);
-local $qlimit = 0;
-local $qused = 0;
-foreach my $q (@{$info->{'quota'}}) {
-       $qlimit += $q->[2];
-       $qused += $q->[1]+$q->[3];
-       }
-push(@stats, [ "quotalimit", $qlimit ]);
-push(@stats, [ "quotaused", $qused ]);
-
-# Get mail since the last collection time
-local $now = time();
-if (-r $procmail_log_file) {
-       # Get last seek position
-       local $lastinfo = &read_file_contents("$historic_info_dir/procmailpos");
-       local @st = stat($procmail_log_file);
-       local ($lastpos, $lastinode, $lasttime);
-       if (defined($lastinfo)) {
-               ($lastpos, $lastinode, $lasttime) = split(/\s+/, $lastinfo);
-               }
-       else {
-               # For the first run, start at the end of the file
-               $lastpos = $st[7];
-               $lastinode = $st[1];
-               $lasttime = time();
-               }
-
-       open(PROCMAILLOG, $procmail_log_file);
-       if ($st[1] == $lastinode && $lastpos) {
-               seek(PROCMAILLOG, $lastpos, 0);
-               }
-       else {
-               $lastpos = 0;
-               }
-       local ($mailcount, $spamcount, $viruscount) = (0, 0, 0);
-       while(<PROCMAILLOG>) {
-               $lastpos += length($_);
-               s/\r|\n//g;
-               local %log = map { split(/:/, $_, 2) } split(/\s+/, $_);
-               if ($log{'User'}) {
-                       $mailcount++;
-                       if ($log{'Mode'} eq 'Spam') {
-                               $spamcount++;
-                               }
-                       elsif ($log{'Mode'} eq 'Virus') {
-                               $viruscount++;
-                               }
-                       }
-               }
-       close(PROCMAILLOG);
-       local $mins = ($now - $lasttime) / 60.0;
-       push(@stats, [ "mailcount", $mins ? $mailcount / $mins : 0 ]);
-       push(@stats, [ "spamcount", $mins ? $spamcount / $mins : 0 ]);
-       push(@stats, [ "viruscount", $mins ? $viruscount / $mins : 0 ]);
-
-       # Save last seek
-       &open_tempfile(PROCMAILPOS, ">$historic_info_dir/procmailpos");
-       &print_tempfile(PROCMAILPOS, $lastpos," ",$st[1]," ",$now."\n");
-       &close_tempfile(PROCMAILPOS);
-       }
 
 # Get network traffic counts since last run
 if (&foreign_check("net") && $gconfig{'os_type'} =~ /-linux$/) {
@@ -252,7 +158,7 @@ if (&foreign_check("net") && $gconfig{'os_type'} =~ /-linux$/) {
                }
        else {
                # Get list from net module
-               &foreign_require("net", "net-lib.pl");
+               &foreign_require("net");
                foreach my $i (&net::active_interfaces()) {
                        if ($i->{'virtual'} eq '' &&
                            $i->{'name'} =~ /^(eth|ppp|wlan|ath|wlan)/) {
@@ -427,6 +333,8 @@ return @rv;
 # set in the module config.
 sub setup_collectinfo_job
 {
+&foreign_require("cron");
+
 # Work out correct steps
 local $step = $config{'collect_interval'};
 $step = 5 if (!$step || $step eq 'none');
diff --git a/webmin/change_status.cgi b/webmin/change_status.cgi
new file mode 100644 (file)
index 0000000..8b94de4
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/local/bin/perl
+# Save status collection options
+
+require './webmin-lib.pl';
+&ReadParse();
+&foreign_require("system-status");
+&error_setup($text{'status_err'});
+
+# Save collection interval
+if ($in{'interval_def'}) {
+       $system_status::config{'collect_interval'} = 'none';
+       }
+else {
+       $in{'interval'} =~ /^\d+$/ && $in{'interval'} > 0 &&
+          $in{'interval'} <= 60 || &error($text{'status_einterval'});
+       }
+
+# Save package collection option
+$system_status::config{'collect_pkgs'} = $in{'pkgs'};
+
+&lock_file($system_status::module_config_file);
+&save_module_config(\%system_status::config, 'system-status');
+&unlock_file($system_status::module_config_file);
+&system_status::setup_collectinfo_job();
+
+&webmin_log("status");
+&redirect("");
+
diff --git a/webmin/edit_status.cgi b/webmin/edit_status.cgi
new file mode 100644 (file)
index 0000000..69bcc07
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/local/bin/perl
+# Display status collection options
+
+require './webmin-lib.pl';
+&foreign_require("system-status");
+&ui_print_header(undef, $text{'status_title'}, "");
+
+print &ui_form_start("change_status.cgi", "post");
+print &ui_table_start($text{'status_header'}, undef, 2);
+
+# Status collection enabled and gap
+$i = $system_status::config{'collect_interval'};
+print &ui_table_row($text{'status_interval'},
+       &ui_opt_textbox("interval", $i eq 'none' ? undef : $i, 5,
+                       $text{'status_interval1'}, $text{'status_interval0'}).
+       " ".$text{'status_mins'});
+
+# Collect packages?
+print &ui_table_row($text{'status_pkgs'},
+       &ui_yesno_radio("pkgs", $system_status::config{'collect_pkgs'}));
+
+print &ui_table_end();
+print &ui_form_end([ [ "save", $text{'save'} ] ]);
+
+&ui_print_footer("", $text{'index_return'});
+
diff --git a/webmin/images/status.gif b/webmin/images/status.gif
new file mode 100644 (file)
index 0000000..3929e52
Binary files /dev/null and b/webmin/images/status.gif differ
index 9c6fc90..310df47 100755 (executable)
@@ -15,8 +15,8 @@ $ver = &get_webmin_version();
            "edit_upgrade.cgi", "edit_session.cgi", "edit_assignment.cgi",
            "edit_categories.cgi", "edit_descs.cgi", "edit_themes.cgi",
            "edit_referers.cgi", "edit_anon.cgi", "edit_lock.cgi",
-           "edit_mobile.cgi", "edit_blocked.cgi", "edit_advanced.cgi",
-           "edit_debug.cgi" );
+           "edit_mobile.cgi", "edit_blocked.cgi", "edit_status.cgi",
+            "edit_advanced.cgi", "edit_debug.cgi" );
 @wtitles = ( $text{'access_title'}, $text{'bind_title'},
             $text{'log_title'}, $text{'proxy_title'},
             $text{'ui_title'}, $text{'mods_title'},
@@ -27,7 +27,8 @@ $ver = &get_webmin_version();
             $text{'themes_title'}, $text{'referers_title'},
             $text{'anon_title'}, $text{'lock_title'},
             $text{'mobile_title'}, $text{'blocked_title'},
-            $text{'advanced_title'}, $text{'debug_title'}, );
+            $text{'status_title'}, $text{'advanced_title'},
+            $text{'debug_title'}, );
 @wicons = ( "images/access.gif", "images/bind.gif", "images/log.gif",
            "images/proxy.gif", "images/ui.gif", "images/mods.gif",
            "images/os.gif", "images/lang.gif", "images/startpage.gif",
@@ -35,7 +36,8 @@ $ver = &get_webmin_version();
            "images/assignment.gif", "images/categories.gif",
            "images/descs.gif", "images/themes.gif", "images/referers.gif",
            "images/anon.gif", "images/lock.gif", "images/mobile.gif",
-           "images/blocked.gif", "images/advanced.gif", "images/debug.gif" );
+           "images/blocked.gif", "images/status.gif",
+           "images/advanced.gif", "images/debug.gif" );
 if ($gconfig{'eazel'}) {
        push(@wlinks, "edit_syslet.cgi");
        push(@wtitles, $text{'syslet_title'});
index ef54291..3b50656 100644 (file)
@@ -872,3 +872,11 @@ notify_updatemod=Module
 notify_updatever=Version
 notify_updatedesc=Fixes problem
 notif_updateok=Install Updates Now
+
+status_title=Background Status Collection
+status_header=Status collection job settings
+status_interval=Collect system status in background?
+status_interval1=Never
+status_interval0=Every
+status_mins=minutes
+status_pkgs=Collect available package updates?