Handle hostnames with upper-case letters
[webmin.git] / webalizer / edit_log.cgi
1 #!/usr/local/bin/perl
2 # edit_log.cgi
3 # Display a form for adding a new logfile or editing an existing one.
4 # Allows you to set the schedule on which the log is analysed
5
6 require './webalizer-lib.pl';
7 &foreign_require("cron", "cron-lib.pl");
8 &ReadParse();
9 $access{'view'} && &error($text{'edit_ecannot'});
10 if ($in{'new'}) {
11         $access{'add'} || &error($text{'edit_ecannot'});
12         &ui_print_header(undef, $text{'edit_title1'}, "");
13         }
14 else {
15         &can_edit_log($in{'file'}) || &error($text{'edit_ecannot'});
16         &ui_print_header(undef, $text{'edit_title2'}, "");
17         $lconf = &get_log_config($in{'file'});
18         }
19
20 print "<form action=save_log.cgi>\n";
21 print "<input type=hidden name=new value='$in{'new'}'>\n";
22 print "<input type=hidden name=oldfile value='$in{'file'}'>\n";
23
24 print "<table border width=100% class='ui_table'>\n";
25 print "<tr $tb> <td><b>$text{'edit_header'}</b></td> </tr>\n";
26 print "<tr $cb> <td><table width=100%>\n";
27
28 print "<tr> <td><b>$text{'edit_file'}</b></td> <td colspan=3>\n";
29 if ($in{'new'}) {
30         print "<input name=file size=50> ",&file_chooser_button("file");
31         }
32 else {
33         print "<input type=hidden name=file value='$in{'file'}'>\n";
34         print "<tt>$in{'file'}</tt>";
35         }
36 print "</td> </tr>\n";
37
38 if (!$in{'new'}) {
39         @all = &all_log_files($in{'file'});
40         if (@all > 1) {
41                 print "<tr> <td valign=top><b>$text{'edit_files'}</b></td> ",
42                       "<td colspan=3><font size=-1>\n";
43                 foreach $a (@all) {
44                         print "$a<br>\n";
45                         }
46                 print "</font></td> </tr>\n";
47                 }
48         }
49
50 print "<tr> <td><b>$text{'edit_type'}</b></td> <td>\n";
51 if ($in{'new'}) {
52         print "<select name=type>\n";
53         for($i=1; defined($t = $text{'index_type'.$i}); $i++) {
54                 print "<option value=$i>$t\n";
55                 }
56         print "</select>\n";
57         }
58 else {
59         print "<input type=hidden name=type value='$in{'type'}'>\n";
60         print $text{'index_type'.$in{'type'}};
61         }
62 print "</td>\n";
63
64 print "<tr> <td><b>$text{'edit_dir'}</b></td> <td colspan=3>\n";
65 printf "<input name=dir size=50 value='%s'> %s</td> </tr>\n",
66         $lconf->{'dir'}, &file_chooser_button("dir", 1);
67
68 print "<tr> <td><b>$text{'edit_user'}</b></td>\n";
69 if ($access{'user'} eq '*') {
70         # User that webalizer runs as can be chosen
71         printf "<td><input name=user size=13 value='%s'> %s</td> </tr>\n",
72                 $lconf->{'user'} || "root";
73         }
74 else {
75         # User is fixed
76         printf "<td><tt>%s</tt></td> </tr>\n",
77                 !$in{'new'} && $lconf->{'dir'} ? $lconf->{'user'} || "root" :
78                 $access{'user'} eq "" ? $remote_user : $access{'user'};
79         }
80
81 print "<tr> <td><b>$text{'edit_over'}</b></td>\n";
82 printf "<td><input type=radio name=over value=1 %s> %s\n",
83         $lconf->{'over'} ? "checked" : "", $text{'yes'};
84 printf "<input type=radio name=over value=0 %s> %s</td> </tr>\n",
85         $lconf->{'over'} ? "" : "checked", $text{'no'};
86
87 $cfile = &config_file_name($in{'file'});
88 $cmode = -l $cfile ? 2 : -r $cfile ? 1 : 0;
89 print "<tr> <td><b>$text{'edit_conf'}</b></td> <td nowrap>\n";
90 printf "<input type=radio name=cmode value=0 %s> %s\n",
91         $cmode == 0 ? "checked" : "", $text{'edit_cmode0'};
92 printf "<input type=radio name=cmode value=1 %s> %s\n",
93         $cmode == 1 ? "checked" : "", $text{'edit_cmode1'};
94 printf "<input type=radio name=cmode value=2 %s> %s\n",
95         $cmode == 2 ? "checked" : "", $text{'edit_cmode2'};
96 printf "<input name=cfile size=20 value='%s'> %s</td> </tr>\n",
97         $cmode == 2 ? readlink($cfile) : "", &file_chooser_button("cfile");
98
99 print "<tr> <td><b>$text{'edit_sched'}</b></td> <td colspan=3>\n";
100 printf "<input type=radio name=sched value=0 %s> %s\n",
101         $lconf->{'sched'} ? "" : "checked", $text{'edit_sched0'};
102 printf "<input type=radio name=sched value=1 %s> %s</td> </tr>\n",
103         $lconf->{'sched'} ? "checked" : "", $text{'edit_sched1'};
104
105 print "<tr> <td><b>$text{'edit_clear'}</b></td>\n";
106 printf "<td><input type=radio name=clear value=1 %s> %s\n",
107         $lconf->{'clear'} ? "checked" : "", $text{'yes'};
108 printf "<input type=radio name=clear value=0 %s> %s</td> </tr>\n",
109         $lconf->{'clear'} ? "" : "checked", $text{'no'};
110
111 print "</table>\n";
112
113 print "<table border width=100%>\n";
114 if ($lconf->{'mins'} eq '') {
115         $lconf->{'mins'} = $lconf->{'hours'} = 0;
116         $lconf->{'days'} = $lconf->{'months'} = $lconf->{'weekdays'} = '*';
117         }
118 &foreign_call("cron", "show_times_input", $lconf);
119
120 print "</table>\n";
121 print "</td></tr></table>\n";
122
123 if ($in{'new'}) {
124         push(@b, "<input type=submit value='$text{'create'}'>");
125         }
126 else {
127         push(@b, "<input type=submit value='$text{'save'}'>");
128         push(@b, "<input type=submit name=global value='$text{'edit_global'}'>")
129                 if ($cmode);
130         if ($lconf->{'dir'}) {
131                 push(@b, "<input type=submit name=run value='$text{'edit_run'}'>");
132                 }
133         if ($lconf->{'dir'} && -r "$lconf->{'dir'}/index.html") {
134                 push(@b, "<input type=submit name=view value='$text{'edit_view'}'>");
135                 }
136         if ($in{'custom'}) {
137                 push(@b, "<input type=submit name=delete value='$text{'delete'}'>");
138                 }
139         }
140 &spaced_buttons(@b);
141 print "</form>\n";
142
143 &ui_print_footer("", $text{'index_return'});
144