More fixes for date sorting in logins list
authorJamie Cameron <jcameron@webmin.com>
Tue, 2 Nov 2010 23:37:22 +0000 (16:37 -0700)
committerJamie Cameron <jcameron@webmin.com>
Tue, 2 Nov 2010 23:37:22 +0000 (16:37 -0700)
https://sourceforge.net/tracker/?func=detail&atid=117457&aid=3101801&group_id=17457

mailboxes/boxes-lib.pl
useradmin/list_logins.cgi
useradmin/list_who.cgi

index 8f135f0..77eec95 100755 (executable)
@@ -2518,6 +2518,7 @@ sub parse_mail_date
 {
 local ($str) = @_;
 $str =~ s/^[, \t]+//;
+$str =~ s/\s+$//;
 open(OLDSTDERR, ">&STDERR");   # suppress STDERR from Time::Local
 close(STDERR);
 my $rv = eval {
@@ -2549,20 +2550,30 @@ my $rv = eval {
                                      $7 < 50 ? $7+100 : $7 < 1000 ? $7 : $7-1900);
                return $tm;
                }
-       elsif ($str =~ /^(\S+)\s+(\S+)\s+(\d{1,2})\s+(\d+):(\d+):(\d+)/) {
+       elsif ($str =~ /^(\S+)\s+(\S+)\s+(\d{1,2})\s+(\d+):(\d+):(\d+)/ &&
+              &month_to_number($2)) {
                # Format like Tue Dec  7 12:58:52
                local @now = localtime(time());
                local $tm = timelocal($6, $5, $4, $3, &month_to_number($2),
                                      $now[5]);
                return $tm;
                }
-       elsif ($str =~ /^(\S+)\s+(\S+)\s+(\d{1,2})\s+(\d+):(\d+)/) {
+       elsif ($str =~ /^(\S+)\s+(\S+)\s+(\d{1,2})\s+(\d+):(\d+)$/ &&
+              defined(&month_to_number($2))) {
                # Format like Tue Dec  7 12:58
                local @now = localtime(time());
                local $tm = timelocal(0, $5, $4, $3, &month_to_number($2),
                                      $now[5]);
                return $tm;
                }
+       elsif ($str =~ /^(\S+)\s+(\d{1,2})\s+(\d+):(\d+)$/ &&
+              defined(&month_to_number($1))) {
+               # Format like Dec  7 12:58
+               local @now = localtime(time());
+               local $tm = timelocal(0, $4, $3, $2, &month_to_number($1),
+                                     $now[5]);
+               return $tm;
+               }
        elsif ($str =~ /^(\S+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)\s+(\S+)/) {
                # Format like Dec  7 12:58:52 2004 GMT
                local $tm = timegm($5, $4, $3, $2, &month_to_number($1),
index 73f67f7..cc28c8e 100755 (executable)
@@ -4,7 +4,9 @@
 
 require './user-lib.pl';
 &ReadParse();
-&foreign_require("mailboxes");
+if (&foreign_check("mailboxes")) {
+       &foreign_require("mailboxes");
+       }
 
 # Work out who we can list for
 $u = $in{'username'};
@@ -23,12 +25,13 @@ elsif ($access{'logins'} ne "*") {
 # Build the table data
 @table = ( );
 foreach $l (&list_last_logins($u, $config{'last_count'})) {
-       $tm = &mailboxes::parse_mail_date($l->[3]);
+       $tm = defined(&mailboxes::parse_mail_date) ?
+               &mailboxes::parse_mail_date($l->[3]) : undef;
        push(@table, [
                $u ? ( ) : ( "<tt>".&html_escape($l->[0])."</tt>" ),
                &html_escape($l->[2]) || $text{'logins_local'},
                &html_escape($l->[1]),
-               &make_date($tm),
+               &html_escape($tm ? &make_date($tm) : $l->[3]),
                $l->[4] ? ( &html_escape($l->[4]),
                            &html_escape($l->[5]) )
                        : ( "<i>$text{'logins_still'}</i>", "" ),
index 931fe68..b7faf84 100755 (executable)
@@ -4,6 +4,9 @@
 
 require './user-lib.pl';
 $access{'logins'} || &error($text{'who_ecannot'});
+if (&foreign_check("mailboxes")) {
+       &foreign_require("mailboxes");
+       }
 
 &ui_print_header(undef, $text{'who_title'}, "");
 
@@ -11,11 +14,13 @@ $access{'logins'} || &error($text{'who_ecannot'});
 @whos = &logged_in_users();
 @table = ( );
 foreach $w (@whos) {
+       $tm = defined(&mailboxes::parse_mail_date) ?
+               &mailboxes::parse_mail_date($w->{'when'}) : undef;
        push(@table, [
                "<a href='list_logins.cgi?username=".&urlize($w->{'user'})."'>".
                &html_escape($w->{'user'})."</a>",
                &html_escape($w->{'tty'}),
-               &html_escape($w->{'when'}),
+               &html_escape($tm ? &make_date($tm) : $w->{'when'}),
                $w->{'from'} ? &html_escape($w->{'from'})
                             : $text{'logins_local'},
                ]);