Handle hostnames with upper-case letters
[webmin.git] / syslog-ng / edit_source.cgi
1 #!/usr/local/bin/perl
2 # Show a form for editing or creating a log source
3
4 require './syslog-ng-lib.pl';
5 &ReadParse();
6
7 # Show title and get the source
8 $conf = &get_config();
9 if ($in{'new'}) {
10         &ui_print_header(undef, $text{'source_title1'}, "");
11         }
12 else {
13         &ui_print_header(undef, $text{'source_title2'}, "");
14         @sources = &find("source", $conf);
15         ($source) = grep { $_->{'value'} eq $in{'name'} } @sources;
16         $source || &error($text{'source_egone'});
17         }
18
19 # Form header
20 print &ui_form_start("save_source.cgi", "post");
21 print &ui_hidden("new", $in{'new'}),"\n";
22 print &ui_hidden("old", $in{'name'}),"\n";
23 print &ui_table_start($text{'source_header'}, undef, 2);
24
25 # Source name
26 print &ui_table_row($text{'source_name'},
27                     &ui_textbox("name", $source->{'value'}, 20));
28
29 # Show internal option
30 $ttable = "<table>\n";
31 $internal = &find("internal", $source->{'members'});
32 $ttable .= "<tr> <td colspan=2>".&ui_checkbox("internal", 1, "<b>$text{'sources_typei'}</b>", $internal ? 1 : 0)."</td> </tr>\n";
33
34 # Show Unix stream and dgram socket options
35 foreach $t ("unix-stream", "unix-dgram") {
36         $unix = &find($t, $source->{'members'});
37         local ($unix_name, $unix_owner, $unix_group, $unix_perm,
38                $unix_keep, $unix_max);
39         if ($unix) {
40           $unix_name = $unix->{'value'};
41           $unix_owner = &find_value("owner", $unix->{'members'});
42           $unix_group = &find_value("group", $unix->{'members'});
43           $unix_perm = &find_value("perm", $unix->{'members'});
44           $unix_keep = &find_value("keep-alive", $unix->{'members'});
45           $unix_max = &find_value("max-connections", $unix->{'members'});
46           }
47         $msg = $t eq "unix-stream" ? 'sources_types' : 'sources_typed';
48         $ttable .= "<tr> <td valign=top>".&ui_checkbox($t, 1, "<b>$text{$msg}</b>", $unix ? 1 : 0)."</td> <td><table>\n";
49
50         # Socket filename
51         $ttable .= "<tr> <td>$text{'destination_file'}</td> <td>".
52                    &ui_textbox($t."_name", $unix_name, 35)." ".
53                    &file_chooser_button("unix_name")."</td> </tr>\n";
54
55         # Socket owner and group
56         $ttable .= "<tr> <td>$text{'source_owner'}</td> <td>".
57            &ui_opt_textbox($t."_owner", $unix_owner, 15, $text{'default'})." ".
58            &user_chooser_button($t."_owner")."</td> </tr>\n";
59         $ttable .= "<tr> <td>$text{'source_group'}</td> <td>".
60            &ui_opt_textbox($t."_group", $unix_group, 15, $text{'default'})." ".
61            &group_chooser_button($t."_group")."</td> </tr>\n";
62
63         # File permissions, keep-alive and max connetions
64         $ttable .= "<tr> <td>$text{'source_perm'}</td> <td>".
65                    &ui_opt_textbox($t."_perm", $unix_perm, 5,$text{'default'}).
66                    "</td> </tr>\n";
67         if ($t eq "unix-stream") {
68                 $ttable .= "<tr> <td>$text{'source_keep'}</td> <td>".
69                            &ui_radio($t."_keep", $unix_keep,
70                                  [ [ 'y', $text{'yes'} ],
71                                    [ 'n', $text{'no'} ],
72                                    [ '', $text{'default'} ] ])."</td> </tr>\n";
73                 $ttable .= "<tr> <td>$text{'source_max'}</td> <td>".
74                            &ui_opt_textbox($t."_max", $unix_max, 5,
75                                            $text{'default'})."</td> </tr>\n";
76                 }
77
78         $ttable .= "</table>\n";
79         $ttable .= "</td> </tr>\n";
80         }
81
82 # TCP and UDP network sockets
83 foreach $t ('tcp', 'udp') {
84         $net = &find($t, $source->{'members'});
85         local ($net_ip, $net_port, $net_keep, $net_tkeep, $net_max);
86         if ($net) {
87                 $net_ip = &find_value("ip", $net->{'members'}) ||
88                           &find_value("localip", $net->{'members'});
89                 $net_port = &find_value("port", $net->{'members'}) ||
90                             &find_value("localport", $net->{'members'});
91                 $net_keep = &find_value("keep-alive", $net->{'members'});
92                 $net_tkeep = &find_value("tcp-keep-alive", $net->{'members'});
93                 $net_max = &find_value("max-connections", $net->{'members'});
94                 }
95         $msg = $t eq "tcp" ? 'sources_typet' : 'sources_typeu';
96         $ttable .= "<tr> <td valign=top>".&ui_checkbox($t, 1, "<b>$text{$msg}</b>", $net ? 1 : 0)."</td> <td><table>\n";
97
98         # Local IP and port
99         $ttable .= "<tr> <td>$text{'source_ip'}</td> <td>".
100            &ui_opt_textbox($t."_ip", $net_ip, 15, $text{'source_any'}).
101            "</td> </tr>\n";
102         $ttable .= "<tr> <td>$text{'source_port'}</td> <td>".
103            &ui_opt_textbox($t."_port", $net_port, 6, $text{'default'}." (514)").
104            "</td> </tr>\n";
105
106         # TCP-specific options and max connections
107         if ($t eq "tcp") {
108                 $ttable .= "<tr> <td>$text{'source_keep'}</td> <td>".
109                            &ui_radio($t."_keep", $net_keep,
110                                  [ [ 'y', $text{'yes'} ],
111                                    [ 'n', $text{'no'} ],
112                                    [ '', $text{'default'} ] ])."</td> </tr>\n";
113                 $ttable .= "<tr> <td>$text{'source_tkeep'}</td> <td>".
114                            &ui_radio($t."_tkeep", $net_tkeep,
115                                  [ [ 'y', $text{'yes'} ],
116                                    [ 'n', $text{'no'} ],
117                                    [ '', $text{'default'} ] ])."</td> </tr>\n";
118                 }
119         $ttable .= "<tr> <td>$text{'source_max'}</td> <td>".
120                    &ui_opt_textbox($t."_max", $net_max, 5,
121                                    $text{'default'})."</td> </tr>\n";
122
123         $ttable .= "</table>\n";
124         $ttable .= "</td> </tr>\n";
125         }
126
127 # Kernel log file
128 $file = &find("file", $source->{'members'});
129 if ($file) {
130         $file_name = $file->{'value'};
131         $file_prefix = &find_value("log_prefix", $file->{'members'});
132         }
133 $ttable .= "<tr> <td valign=top>".&ui_checkbox("file", 1, "<b>$text{'sources_typef'}</b>", $file ? 1 : 0)."</td> <td><table>\n";
134
135 # Log filename
136 $ttable .= "<tr> <td>$text{'destination_file'}</td> <td>".
137            &ui_textbox("file_name", $file_name, 35)." ".
138            &file_chooser_button("file_name")."</td> </tr>\n";
139
140 # Message prefix
141 $ttable .= "<tr> <td>$text{'source_prefix'}</td> <td>".
142            &ui_opt_textbox("file_prefix", $file_prefix, 20,
143                            $text{'source_none'})."</td> </tr>\n";
144 $ttable .= "</table>\n";
145 $ttable .= "</td> </tr>\n";
146
147
148 # Pipe file
149 $pipe = &find("pipe", $source->{'members'});
150 if ($pipe) {
151         $pipe_name = $pipe->{'value'};
152         $pipe_prefix = &find_value("log_prefix", $pipe->{'members'});
153         $pad_size = &find_value("pad_size", $pipe->{'members'});
154         }
155 $ttable .= "<tr> <td valign=top>".&ui_checkbox("pipe", 1, "<b>$text{'sources_typep'}</b>", $pipe ? 1 : 0)."</td> <td><table>\n";
156
157 # Log pipename
158 $ttable .= "<tr> <td>$text{'destination_file'}</td> <td>".
159            &ui_textbox("pipe_name", $pipe_name, 35)." ".
160            &file_chooser_button("pipe_name")."</td> </tr>\n";
161
162 # Message prefix and pad size
163 $ttable .= "<tr> <td>$text{'source_prefix'}</td> <td>".
164            &ui_opt_textbox("pipe_prefix", $pipe_prefix, 20,
165                            $text{'source_none'})."</td> </tr>\n";
166 $ttable .= "<tr> <td>$text{'source_pad'}</td> <td>".
167            &ui_opt_textbox("pad_size", $pad_size, 20,
168                            $text{'source_none'})."</td> </tr>\n";
169 $ttable .= "</table>\n";
170 $ttable .= "</td> </tr>\n";
171
172
173 if (&supports_sun_streams()) {
174         # Sun streams file
175         $sun_streams = &find("sun-streams", $source->{'members'});
176         if ($sun_streams) {
177                 $sun_streams_name = $sun_streams->{'value'};
178                 $sun_streams_door = &find_value("door", $sun_streams->{'members'});
179                 }
180         $ttable .= "<tr> <td valign=top>".&ui_checkbox("sun-streams", 1, "<b>$text{'sources_typen'}</b>", $sun_streams ? 1 : 0)."</td> <td><table>\n";
181
182         # Log filename
183         $ttable .= "<tr> <td>$text{'destination_file'}</td> <td>".
184                    &ui_textbox("sun_streams_name", $sun_streams_name, 35)." ".
185                    &file_chooser_button("sun_streams_name")."</td> </tr>\n";
186
187         # Door name
188         $ttable .= "<tr> <td>$text{'source_door'}</td> <td>".
189                    &ui_textbox("sun_streams_door", $sun_streams_door, 35)." ".
190                    &file_chooser_button("sun_streams_name")."</td> </tr>\n";
191         $ttable .= "</table>\n";
192         $ttable .= "</td> </tr>\n";
193         }
194
195 # Show types table
196 $ttable .= "</table>\n";
197 print "<tr> <td colspan=2><b>$text{'source_type'}</b><br>\n";
198 print $ttable;
199 print "</td> </tr>\n";
200
201 # Form footer and buttons
202 print &ui_table_end();
203 if ($in{'new'}) {
204         print &ui_form_end([ [ "create", $text{'create'} ] ]);
205         }
206 else {
207         print &ui_form_end([ [ "save", $text{'save'} ],
208                              [ "delete", $text{'delete'} ] ]);
209         }
210 &ui_print_footer("list_sources.cgi", $text{'sources_return'});