Handle hostnames with upper-case letters
[webmin.git] / sendmail / log_parser.pl
1 # log_parser.pl
2 # Functions for parsing this module's logs
3
4 do 'sendmail-lib.pl';
5
6 # parse_webmin_log(user, script, action, type, object, &params)
7 # Converts logged information from this module into human-readable form
8 sub parse_webmin_log
9 {
10 local ($user, $script, $action, $type, $object, $p, $long) = @_;
11 if ($type eq 'alias' || $type eq 'virtuser' || $type eq 'mailer' ||
12     $type eq 'generic' || $type eq 'domain' || $type eq 'access') {
13         return &text("log_${type}_${action}",
14                      "<tt>".&html_escape($object)."</tt>");
15         }
16 elsif ($type eq 'aliases' || $type eq 'virtusers' || $type eq 'mailers' ||
17        $type eq 'generics' || $type eq 'domains' || $type eq 'accesses') {
18         return &text("log_${action}_${type}", $object);
19         }
20 elsif ($type eq 'feature') {
21         return &text("log_feature_${action}",
22                      "<tt>".&html_escape($p->{'text'})."</tt>");
23         }
24 elsif ($action eq 'delmailq') {
25         if ($p->{'from'}) {
26                 return &text("log_delmailq",
27                              &html_escape(&extract_email($p->{'from'})));
28                 }
29         else {
30                 return &text("log_delmailqs", $p->{'count'});
31                 }
32         }
33 elsif ($action eq 'delmail') {
34         local @d = split(/\0/, $p->{'d'});
35         return &text("log_delmail", scalar(@d), "<tt>$p->{'user'}</tt>");
36         }
37 elsif ($action eq 'movemail') {
38         local @d = split(/\0/, $p->{'d'});
39         local $to = $p->{'move1'} ? $p->{'moveto1'} : $p->{'moveto2'};
40         return &text("log_movemail", scalar(@d), "<tt>$p->{'user'}</tt>",
41                      "<tt>$to</tt>");
42         }
43 elsif ($action eq 'send') {
44         return &text('log_send', &html_escape(&extract_email($p->{'to'})));
45         }
46 elsif ($text{"log_$action"}) {
47         return $text{"log_$action"};
48         }
49 else {
50         return undef;
51         }
52 }
53
54 sub extract_email
55 {
56 if ($_[0] =~ /([^<>"' \(\)]+\@[^<>"' \(\)]+)/) {
57         return $1;
58         }
59 elsif ($_[0] =~ /<(\S+)>/) {
60         return $1;
61         }
62 else {
63         return $_[0];
64         }
65 }
66