Handle hostnames with upper-case letters
[webmin.git] / apache / log_parser.pl
1 # log_parser.pl
2 # Functions for parsing this module's logs
3
4 do 'apache-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 local $typestr = "<i>".$text{"type_$type"}."</i>";
12 if ($action eq 'global') {
13         return &text('log_global', $typestr);
14         }
15 elsif ($action eq 'manual') {
16         return &text('log_manual', "<tt>$p->{'file'}</tt>");
17         }
18 elsif ($action eq 'virt') {
19         $object = &html_escape($object);
20         if ($type eq 'create') {
21                 return &text('log_virtc', "<tt>$object</tt>");
22                 }
23         elsif ($type eq 'save') {
24                 return &text('log_virts', "<tt>$object</tt>");
25                 }
26         elsif ($type eq 'delete') {
27                 return &text('log_virtd', "<tt>$object</tt>");
28                 }
29         elsif ($type eq 'manual') {
30                 return &text('log_virtm', "<tt>$object</tt>");
31                 }
32         else {
33                 return &text('log_virt', $typestr, "<tt>$object</tt>");
34                 }
35         }
36 elsif ($action eq 'dir') {
37         local ($virt, $dir);
38         if ($object =~ /^([^:]+):(\d+):(.*)$/) {
39                 $virt = "$1:$2"; $dir = $3;
40                 }
41         elsif ($object =~ /^([^:]+):(.*)$/) {
42                 $virt = $1; $dir = $2;
43                 }
44         $virt = &html_escape($virt);
45         $dir = &html_escape($dir);
46         if ($type eq 'create') {
47                 return &text($long ? 'log_dirc_l' : 'log_dirc',
48                              "<tt>$dir</tt>", "<tt>$virt</tt>");
49                 }
50         elsif ($type eq 'save') {
51                 return &text($long ? 'log_dirs_l' : 'log_dirs',
52                              "<tt>$dir</tt>", "<tt>$virt</tt>");
53                 }
54         elsif ($type eq 'delete') {
55                 return &text($long ? 'log_dird_l' : 'log_dird',
56                              "<tt>$dir</tt>", "<tt>$virt</tt>");
57                 }
58         elsif ($type eq 'manual') {
59                 return &text($long ? 'log_dirm_l' : 'log_dirm',
60                              "<tt>$dir</tt>", "<tt>$virt</tt>");
61                 }
62         else {
63                 return &text($long ? 'log_dir_l' : 'log_dir', $typestr,
64                              "<tt>$dir</tt>", "<tt>$virt</tt>");
65                 }
66         }
67 elsif ($action eq 'htaccess') {
68         $object = &html_escape($object);
69         $virt = &html_escape($virt);
70         if ($type eq 'create') {
71                 return &text('log_htaccessc',
72                              "<tt>$object</tt>", "<tt>$virt</tt>");
73                 }
74         elsif ($type eq 'delete') {
75                 return &text('log_htaccessd',
76                              "<tt>$object</tt>", "<tt>$virt</tt>");
77                 }
78         elsif ($type eq 'manual') {
79                 return &text('log_htaccessm',
80                              "<tt>$object</tt>", "<tt>$virt</tt>");
81                 }
82         else {
83                 return &text('log_htaccess', $typestr,
84                              "<tt>$object</tt>", "<tt>$virt</tt>");
85                 }
86         }
87 elsif ($action eq 'files') {
88         local ($file, $path);
89         if ($object =~ /^([^:]+):(.*)$/) {
90                 $file = $1; $path = $2;
91                 }
92         $file = &html_escape($file);
93         $path = &html_escape($path);
94         if ($type eq 'create') {
95                 return &text($long ? 'log_filesc_l' : 'log_filesc',
96                              "<tt>$path</tt>", "<tt>$file</tt>");
97                 }
98         elsif ($type eq 'save') {
99                 return &text($long ? 'log_filess_l' : 'log_filess',
100                              "<tt>$path</tt>", "<tt>$file</tt>");
101                 }
102         elsif ($type eq 'delete') {
103                 return &text($long ? 'log_filesd_l' : 'log_filesd',
104                              "<tt>$path</tt>", "<tt>$file</tt>");
105                 }
106         elsif ($type eq 'manual') {
107                 return &text($long ? 'log_filesm_l' : 'log_filesm',
108                              "<tt>$path</tt>", "<tt>$file</tt>");
109                 }
110         else {
111                 return &text($long ? 'log_files_l' : 'log_files', $typestr,
112                              "<tt>$path</tt>", "<tt>$file</tt>");
113                 }
114         }
115 elsif ($action eq 'mime') {
116         $object = &html_escape($object);
117         return &text("log_mime_$type", "<tt>$object</tt>");
118         }
119 elsif ($action eq 'defines') {
120         return $text{'log_defines'};
121         }
122 elsif ($action eq 'reconfig') {
123         return $text{'log_reconfig'};
124         }
125 elsif ($action eq 'mods') {
126         return $text{'log_mods'};
127         }
128 elsif ($action eq 'stop') {
129         return $text{'log_stop'};
130         }
131 elsif ($action eq 'start') {
132         return $text{'log_start'};
133         }
134 elsif ($action eq 'apply') {
135         return $text{'log_apply'};
136         }
137 elsif ($action eq 'virts') {
138         return &text('log_virts_'.$type, $object);
139         }
140 else {
141         return undef;
142         }
143 }
144