Handle hostnames with upper-case letters
[webmin.git] / syslog / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display syslog rules
4
5 require './syslog-lib.pl';
6 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
7         &help_search_link("syslog", "man", "doc"));
8
9 if ($config{'m4_conf'}) {
10         # Does the config file need to be passed through m4?
11         if (&needs_m4()) {
12                 # syslog.conf has m4 directives .. ask the user if he wants
13                 # to filter the file
14                 print "<p>",&text('index_m4msg',
15                                   "<tt>$config{'syslog_conf'}</tt>"),"\n";
16                 print "<center><form action=m4.cgi>\n";
17                 print "<input type=submit value='$text{'index_m4'}'>\n";
18                 print "</form></center>\n";
19                 &ui_print_footer("/", $text{'index'});
20                 exit;
21                 }
22         }
23
24 if (!-r $config{'syslog_conf'}) {
25         # Not installed (maybe using syslog-ng)
26         &ui_print_endpage(&text('index_econf', "<tt>$config{'syslog_conf'}</tt>", "../config.cgi?$module_name"));
27         }
28
29 # Display syslog rules
30 @links = ( );
31 if ($access{'syslog'}) {
32         $conf = &get_config();
33         push(@links, "<a href='edit_log.cgi?new=1'>$text{'index_add'}</a>")
34                 if (!$access{'noedit'});
35         }
36 print &ui_links_row(\@links);
37 print &ui_columns_start([
38         $text{'index_to'},
39         $config{'tags'} ? ( $text{'index_tag'} ) : ( ),
40         $text{'index_active'},
41         $text{'index_rule'}, "" ], 100);
42 if ($access{'syslog'}) {
43         foreach $c (@$conf) {
44                 next if ($c->{'tag'});
45                 next if (!&can_edit_log($c));
46                 local @cols;
47                 local $name;
48                 if ($c->{'file'}) {
49                         $name = &text('index_file',
50                                 "<tt>".&html_escape($c->{'file'})."</tt>");
51                         }
52                 elsif ($c->{'pipe'} && $config{'pipe'} == 1) {
53                         $name = &text('index_pipe',
54                                 "<tt>".&html_escape($c->{'pipe'})."</tt>");
55                         }
56                 elsif ($c->{'pipe'} && $config{'pipe'} == 2) {
57                         $name = &text('index_pipe2',
58                                 "<tt>".&html_escape($c->{'pipe'})."</tt>");
59                         }
60                 elsif ($c->{'host'}) {
61                         $name = &text('index_host',
62                                 "<tt>".&html_escape($c->{'host'})."</tt>");
63                         }
64                 elsif ($c->{'socket'}) {
65                         $name = &text('index_socket',
66                                 "<tt>".&html_escape($c->{'socket'})."</tt>");
67                         }
68                 elsif ($c->{'all'}) {
69                         $name = $text{'index_all'};
70                         }
71                 else {
72                         $name = &text('index_users',
73                                 "<tt>".join(" ", map { &html_escape($_) }
74                                                  @{$c->{'users'}})."</tt>");
75                         }
76                 if ($access{'noedit'}) {
77                         push(@cols, $name);
78                         }
79                 else {
80                         push(@cols, "<a href='edit_log.cgi?".
81                                     "idx=$c->{'index'}'>$name</a>");
82                         }
83                 if ($config{'tags'}) {
84                         push(@cols, $c->{'section'}->{'tag'} eq '*' ?
85                                       $text{'all'} : $c->{'section'}->{'tag'});
86                         }
87                 push(@cols, $c->{'active'} ? $text{'yes'} :
88                                 "<font color=#ff0000>$text{'no'}</font>");
89                 push(@cols, join("&nbsp;;&nbsp;",
90                            map { &html_escape($_) } @{$c->{'sel'}}));
91                 if ($c->{'file'} && -f $c->{'file'}) {
92                         push(@cols, "<a href='save_log.cgi?idx=$c->{'index'}&".
93                               "view=1'>$text{'index_view'}</a>\n");
94                         }
95                 else {
96                         push(@cols, "");
97                         }
98                 print &ui_columns_row(\@cols);
99                 }
100         }
101
102 # Display logs from other modules
103 if ($config{'others'} && $access{'others'}) {
104         @others = &get_other_module_logs();
105         }
106 if (@others) {
107         $cols = $config{'tags'} ? 5 : 4;
108         foreach $o (@others) {
109                 next if (!&can_edit_log($o));
110                 local @cols;
111                 if ($o->{'file'}) {
112                         push(@cols, &text('index_file',$o->{'file'}));
113                         }
114                 else {
115                         push(@cols, &text('index_cmd',$o->{'cmd'}));
116                         }
117                 if ($config{'tags'}) {
118                         push(@cols, "");
119                         }
120                 push(@cols, $o->{'active'} ? $text{'yes'} :
121                                     "<font color=#ff0000>$text{'no'}</font>");
122                 push(@cols, $o->{'desc'});
123                 push(@cols, "<a href='save_log.cgi?oidx=$o->{'mindex'}".
124                            "&omod=$o->{'mod'}&view=1'>$text{'index_view'}</a>");
125                 print &ui_columns_row(\@cols);
126                 }
127         }
128
129 # Display extra log files
130 foreach $e (&extra_log_files()) {
131         next if (!&can_edit_log($e));
132         local @cols;
133         push(@cols, &text('index_file', $e->{'file'}));
134         if ($config{'tags'}) {
135                 push(@cols, "");
136                 }
137         push(@cols, $text{'yes'});
138         push(@cols, $e->{'desc'});
139         push(@cols, "<a href='save_log.cgi?extra=$e->{'file'}&view=1'>".
140                     "$text{'index_view'}</a>");
141         print &ui_columns_row(\@cols);
142         }
143
144 print &ui_columns_end();
145 print &ui_links_row(\@links);
146 print "<p>\n";
147
148 if ($access{'any'}) {
149         # Can view any log (under allowed dirs)
150         print &ui_form_start("save_log.cgi");
151         print &ui_hidden("view", 1),"\n";
152         print "<b>$text{'index_viewfile'}</b>\n",
153               &ui_textbox("file", undef, 50),"\n",
154               &file_chooser_button("file", 0, 1),"\n",
155               &ui_submit($text{'index_viewok'}),"\n";
156         print &ui_form_end();
157         }
158
159 # Buttons to restart/start syslogd
160 if (!$access{'noedit'}) {
161         print &ui_hr();
162         $pid = &get_syslog_pid();
163         print &ui_buttons_start();
164         if ($pid) {
165                 print &ui_buttons_row("restart.cgi",
166                                       $text{'index_restart'},
167                                       $text{'index_restartmsg'});
168                 }
169         else {
170                 print &ui_buttons_row("start.cgi",
171                                       $text{'index_start'},
172                                       &text('index_startmsg',
173                                             "<tt>$config{'syslogd'}</tt>"));
174                 }
175         print &ui_buttons_end();
176         }
177
178 &ui_print_footer("/", $text{'index'});
179