Add option to log logins and logouts from Webmin
authorJamie Cameron <jcameron@webmin.com>
Thu, 27 Aug 2009 20:35:10 +0000 (13:35 -0700)
committerJamie Cameron <jcameron@webmin.com>
Thu, 27 Aug 2009 20:35:10 +0000 (13:35 -0700)
14 files changed:
cron/cron-lib.pl
makedist.pl
record-login.pl [new file with mode: 0755]
record-logout.pl [new file with mode: 0755]
webmin/CHANGELOG
webmin/change_log.cgi
webmin/edit_log.cgi
webmin/lang/en
webmin/webmin-lib.pl
webminlog/index.cgi
webminlog/lang/en
webminlog/search.cgi
webminlog/view.cgi
webminlog/webminlog-lib.pl

index 266709c..6e95384 100755 (executable)
@@ -1057,8 +1057,14 @@ if ($gconfig{'os_type'} eq 'windows') {
        }
 else {
        # Can use exec on Unix systems
-       &print_tempfile(CMD, "chdir(\"\$root/$_[1]\");\n");
-       &print_tempfile(CMD, "exec(\"\$root/$_[1]/$_[2]\", \@ARGV) || die \"Failed to run \$root/$_[1]/$_[2] : \$!\";\n");
+       if ($_[1]) {
+               &print_tempfile(CMD, "chdir(\"\$root/$_[1]\");\n");
+               &print_tempfile(CMD, "exec(\"\$root/$_[1]/$_[2]\", \@ARGV) || die \"Failed to run \$root/$_[1]/$_[2] : \$!\";\n");
+               }
+       else {
+               &print_tempfile(CMD, "chdir(\"\$root\");\n");
+               &print_tempfile(CMD, "exec(\"\$root/$_[2]\", \@ARGV) || die \"Failed to run \$root/$_[2] : \$!\";\n");
+               }
        }
 &close_tempfile(CMD);
 chmod(0755, $_[0]);
index ccb8161..dc971a6 100755 (executable)
@@ -39,6 +39,7 @@ $zipdir = "zips";
          "module_chooser.cgi", "config-windows", "xmlrpc.cgi",
          "uptracker.cgi", "create-module.pl", "webmin_search.cgi",
          "webmin-search-lib.pl", "WebminCore.pm",
+         "record-login.pl", "record-logout.pl",
         );
 if ($min) {
        # Only those required by others
diff --git a/record-login.pl b/record-login.pl
new file mode 100755 (executable)
index 0000000..791f20e
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/local/bin/perl
+# Write an actions log for a login
+
+BEGIN { push(@INC, ".."); };
+use WebminCore;
+
+&init_config();
+($username, $sid, $remoteip) = @ARGV;
+$WebminCore::remote_user = $remote_user = $username;
+$main::session_id = $sid;
+$0 = "miniserv.pl";
+&webmin_log("login", undef, undef, undef, "global", undef,
+           undef, $remoteip);
diff --git a/record-logout.pl b/record-logout.pl
new file mode 100755 (executable)
index 0000000..c49f166
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/local/bin/perl
+# Write an actions log for a logout
+
+BEGIN { push(@INC, ".."); };
+use WebminCore;
+
+&init_config();
+($username, $sid, $remoteip) = @ARGV;
+$WebminCore::remote_user = $remote_user = $username;
+$main::session_id = $sid;
+$0 = "miniserv.pl";
+&webmin_log("logout", undef, undef, undef, "global", undef,
+           undef, $remoteip);
index 953d304..467c47b 100644 (file)
@@ -94,3 +94,4 @@ Detect and ignore failures when checking if other modules are installed.
 Added a field to the Operating System and Environment page for additional Perl module directories.
 ---- Changes since 1.480 ----
 Removed the option to select an OSDN mirror, as Sourceforge now does sensible location-based redirects automatically.
+Added an option on the Logging page to record logins and logouts from Webmin, for display in the Webmin Actions Log module.
index fe1a4ef..47e19dd 100755 (executable)
@@ -22,6 +22,21 @@ else {
        $in{'perms'} =~ /^[0-7]{3,4}$/ || &error($text{'log_eperms'});
        $miniserv{'logperms'} = $in{'perms'};
        }
+if (defined($in{'login'})) {
+       if ($in{'login'}) {
+               # Create and user login wrapper scripts
+               &foreign_require("cron");
+               &cron::create_wrapper($record_login_cmd,"","record-login.pl");
+               &cron::create_wrapper($record_logout_cmd,"","record-logout.pl");
+               $miniserv{'login_script'} = $record_login_cmd;
+               $miniserv{'logout_script'} = $record_logout_cmd;
+               }
+       else {
+               # Stop using
+               delete($miniserv{'login_script'});
+               delete($miniserv{'logout_script'});
+               }
+       }
 &put_miniserv_config(\%miniserv);
 &unlock_file($ENV{'MINISERV_CONFIG'});
 
index 6afc4b4..05de198 100755 (executable)
@@ -57,6 +57,14 @@ print &ui_table_row($text{'log_inmods'},
                                   &get_all_module_infos() ],
                   5, 1));
 
+# Log logins and logouts?
+if (!$miniserv{'login_script'} ||
+    $miniserv{'login_script'} eq $record_login_cmd) {
+       print &ui_table_row($text{'log_login'},
+               &ui_yesno_radio("login",
+                   $miniserv{'login_script'} eq $record_login_cmd));
+       }
+
 print &ui_table_row($text{'log_files'},
        &ui_yesno_radio("logfiles", int($gconfig{'logfiles'})));
 
index 6abdd8c..ef54291 100644 (file)
@@ -78,6 +78,7 @@ log_ediff=Your system does not have the command $1 needed for logging file chang
 log_perms=Permissions for log files
 log_eperms=Missing or invalid octal permissions (like 755)
 log_syslog=Also log to syslog?
+log_login=Include Webmin logins and logouts in actions log?
 
 proxy_title=Proxy Servers and Downloads
 proxy_desc=If the host on which Webmin is running is behind a firewall of some kind, you may need to set the proxy server to use for accessing web and FTP sites. Certain modules, such as <tt>Software Packages</tt>, will use these proxies when downloading files or programs.
index c827eea..05056b9 100755 (executable)
@@ -49,6 +49,9 @@ $detect_operating_system_cache = "$module_config_directory/oscache";
 
 @debug_what_events = ( 'start', 'read', 'write', 'ops', 'procs', 'diff', 'cmd', 'net', 'sql' );
 
+$record_login_cmd = "$config_directory/login.pl";
+$record_logout_cmd = "$config_directory/logout.pl";
+
 =head2 setup_ca
 
 Internal function to create all the configuration files needed for the Webmin
index 79ba238..74b7ca8 100755 (executable)
@@ -40,6 +40,9 @@ else {
        }
 
 # Modules to search
+if (&can_mod("global")) {
+       push(@mods, [ "global", $text{'index_global'} ]);
+       }
 foreach $m (sort { $a->{'desc'} cmp $b->{'desc'} } &get_all_module_infos()) {
        next if (!&can_mod($m->{'dir'}));
        $mdir = &module_root_directory($m->{'dir'});
index 1faa124..9133861 100644 (file)
@@ -27,6 +27,7 @@ index_dall=Any change
 index_diff=Changes containing
 index_stimes=Actions on dates
 index_shost=Source Webmin server
+index_global=&lt;Not in any module&gt;
 
 search_title=Search Results
 search_date=Date
@@ -49,6 +50,9 @@ search_critt2=on $1
 search_config=Changed module configuration
 search_etime=Invalid start or end time
 search_err=Search failed
+search_global=None
+search_global_login=Logged into Webmin
+search_global_logout=Logged out of Webmin
 
 view_title=Action Details
 view_header=Details of logged action $1
index 5b36d7c..a0d4510 100755 (executable)
@@ -144,7 +144,9 @@ if (@match) {
                local @tm = localtime($act->{'time'});
                local $m = $act->{'module'};
                local $d;
-               $minfo = $minfo_cache{$m};
+               $minfo = $m eq "global" ? 
+                               { 'desc' => $text{'search_global'} } :
+                               $minfo_cache{$m};
                if (!$minfo) {
                        # first time seeing module ..
                        local %minfo = &get_module_info($m);
index 79836c8..f7ee116 100755 (executable)
@@ -25,12 +25,19 @@ print &ui_hidden_table_start(&text('view_header', $act->{'id'}),
 print &ui_table_row($text{'view_action'}."",
                    &get_action_description($act, 1), 3);
 
-%minfo = &get_module_info($act->{'module'});
+%minfo = $act->{'module'} eq 'global' ?
+               ( 'desc' => $text{'search_global'} ) :
+               &get_module_info($act->{'module'});
 print &ui_table_row($text{'view_module'},
                    $minfo{'desc'});
 
-print &ui_table_row($text{'view_script'},
-                   "<tt>$act->{'module'}/$act->{'script'}</tt>");
+if ($act->{'module'} ne 'global') {
+       print &ui_table_row($text{'view_script'},
+                           "<tt>$act->{'module'}/$act->{'script'}</tt>");
+       }
+else {
+       print &ui_table_row($text{'view_script'}, "<tt>$act->{'script'}</tt>");
+       }
 
 print &ui_table_row($text{'view_user'},
                    $act->{'user'});
index 96d02b7..2151ede 100755 (executable)
@@ -376,11 +376,16 @@ if (!defined($parser_cache{$act->{'module'}})) {
        }
 local $d;
 if ($parser_cache{$act->{'module'}}) {
+       # Module can return string
        $d = &foreign_call($act->{'module'}, "parse_webmin_log",
                           $act->{'user'}, $act->{'script'},
                           $act->{'action'}, $act->{'type'},
                           $act->{'object'}, $act->{'param'}, $long);
        }
+elsif ($act->{'module'} eq 'global') {
+       # This module converts global actions
+       $d = $text{'search_global_'.$act->{'action'}};
+       }
 return $d ? $d :
        $act->{'action'} eq '_config_' ? $text{'search_config'} :
                join(" ", $act->{'action'}, $act->{'type'}, $act->{'object'});