Handle hostnames with upper-case letters
[webmin.git] / syslog-ng / edit_destination.cgi
1 #!/usr/local/bin/perl
2 # Show a form for editing or creating a log destination
3
4 require './syslog-ng-lib.pl';
5 &ReadParse();
6
7 # Show title and get the destination
8 $conf = &get_config();
9 if ($in{'new'}) {
10         &ui_print_header(undef, $text{'destination_title1'}, "");
11         }
12 else {
13         &ui_print_header(undef, $text{'destination_title2'}, "");
14         @dests = &find("destination", $conf);
15         ($dest) = grep { $_->{'value'} eq $in{'name'} } @dests;
16         $dest || &error($text{'destination_egone'});
17         }
18
19 # Form header
20 print &ui_form_start("save_destination.cgi", "post");
21 print &ui_hidden("new", $in{'new'}),"\n";
22 print &ui_hidden("old", $in{'name'}),"\n";
23 print &ui_table_start($text{'destination_header'}, undef, 2);
24
25 # Destination name
26 print &ui_table_row($text{'destination_name'},
27                     &ui_textbox("name", $dest->{'value'}, 20));
28
29 # Work out type
30 $file = &find("file", $dest->{'members'});
31 $usertty = &find("usertty", $dest->{'members'});
32 $program = &find("program", $dest->{'members'});
33 $pipe = &find("pipe", $dest->{'members'});
34 $udp = &find("udp", $dest->{'members'});
35 $tcp = &find("tcp", $dest->{'members'});
36 $dgram = &find("unix-dgram", $dest->{'members'});
37 $stream = &find("unix-stream", $dest->{'members'});
38 $type = $file ? 0 :
39         $usertty ? 1 :
40         $program ? 2 :
41         $pipe ? 3 :
42         $tcp ? 4 :
43         $udp ? 5 :
44         $dgram ? 6 :
45         $stream ? 7 : 0;
46
47 $dtable = "<table>\n";
48
49 # File destination
50 if ($file) {
51         $file_name = $file->{'value'};
52         $file_owner = &find_value("owner", $file->{'members'});
53         $file_group = &find_value("group", $file->{'members'});
54         $file_perm = &find_value("perm", $file->{'members'});
55         $file_create_dirs = &find_value("create_dirs", $file->{'members'});
56         $file_dir_perm = &find_value("dir_perm", $file->{'members'});
57         $file_fsync = &find_value("fsync", $file->{'members'});
58         $file_sync_freq = &find_value("sync_freq", $file->{'members'});
59         }
60 $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 0, "<b>$text{'destinations_typef'}</b>", $type == 0)."</td> <td valign=top><table>\n";
61 $dtable .= "<tr> <td>$text{'destination_file'}</td> <td>".
62            &ui_textbox("file_name", $file_name, 35)." ".
63            &file_chooser_button("file_name")."</td> </tr>\n";
64 $dtable .= "<tr> <td>$text{'destination_owner'}</td> <td>".
65            &ui_opt_textbox("file_owner", $file_owner, 15, $text{'default'})." ".
66            &user_chooser_button("file_owner").
67            "</td> </tr>\n";
68 $dtable .= "<tr> <td>$text{'destination_group'}</td> <td>".
69            &ui_opt_textbox("file_group", $file_group, 15, $text{'default'})." ".
70            &group_chooser_button("file_owner").
71            "</td> </tr>\n";
72 $dtable .= "<tr> <td>$text{'destination_perm'}</td> <td>".
73            &ui_opt_textbox("file_perm", $file_perm, 5, $text{'default'}).
74            "</td> </tr>\n";
75 $dtable .= "<tr> <td>$text{'destination_create_dirs'}</td> <td>".
76            &ui_radio("file_create_dirs", $file_create_dirs,
77                      [ [ 'yes', $text{'yes'} ],
78                        [ 'no', $text{'no'} ],
79                        [ '', $text{'default'} ] ]).
80            "</td> </tr>\n";
81 $dtable .= "<tr> <td>$text{'destination_dir_perm'}</td> <td>".
82            &ui_opt_textbox("file_dir_perm", $file_dir_perm, 5,$text{'default'}).
83            "</td> </tr>\n";
84 $dtable .= "<tr> <td>$text{'destination_fsync'}</td> <td>".
85            &ui_radio("file_fsync", $file_fsync,
86                      [ [ 'yes', $text{'yes'} ],
87                        [ 'no', $text{'no'} ],
88                        [ '', $text{'default'} ] ]).
89            "</td> </tr>\n";
90 $dtable .= "<tr> <td>$text{'destination_sync_freq'}</td> <td>".
91            &ui_opt_textbox("file_sync_freq", $file_sync_freq, 5, $text{'default'}).
92            "</td> </tr>\n";
93 $dtable .= "</table></td> </tr>";
94
95 # User TTY destination
96 if ($usertty) {
97         $usertty_user = $usertty->{'value'};
98         }
99 $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 1, "<b>$text{'destinations_typeu'}</b>", $type == 1)."</td> <td valign=top>\n";
100 $dtable .= &ui_opt_textbox("usertty_user", $usertty_user eq "*" ? undef : $usertty_user, 20, $text{'destinations_allusers'}, $text{'destination_users'})." ".&user_chooser_button("usertty_user", 1);
101 $table .= "</td> </tr>";
102
103 # Program destination
104 if ($program) {
105         $program_prog = $program->{'value'};
106         }
107 $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 2, "<b>$text{'destinations_typep'}</b>", $type == 2)."</td> <td valign=top>\n";
108 $dtable .= &ui_textbox("program_prog", $program_prog, 50);
109 $table .= "</td> </tr>";
110
111 # Pipe destination
112 if ($pipe) {
113         $pipe_name = $pipe->{'value'};
114         }
115 $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 3, "<b>$text{'destinations_typei'}</b>", $type == 3)."</td> <td valign=top>\n";
116 $dtable .= &ui_textbox("pipe_name", $pipe_name, 30)." ".
117            &file_chooser_button("pipe_name");
118 $dtable .= "</td> </tr>";
119
120 # TCP or UDP socket
121 $net = $tcp || $udp;
122 if ($net) {
123         $net_host = $net->{'value'};
124         $net_port = &find_value("port", $net->{'members'});
125         $net_localip = &find_value("localip", $net->{'members'});
126         $net_localport = &find_value("localport", $net->{'members'});
127         }
128 $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 4, "<b>$text{'destination_net'}</b>", $type == 4 || $type == 5)."</td> <td valign=top><table>\n";
129 $dtable .= "<tr> <td>$text{'destination_proto'}</td> ".
130            "<td>".&ui_select("net_proto", $type == 5 ? "udp" : "tcp",
131                      [ [ "tcp", "TCP" ], [ "udp", "UDP" ] ])."</td> </tr>\n";
132 $dtable .= "<tr> <td>$text{'destination_host'}</td> ".
133            "<td>".&ui_textbox("net_host", $net_host, 20)."</td> </tr>\n";
134 $dtable .= "<tr> <td>$text{'destination_port'}</td> ".
135            "<td>".&ui_opt_textbox("net_port", $net_port, 5, "$text{'default'} (514)")."</td> </tr>\n";
136 $dtable .= "<tr> <td>$text{'destination_localip'}</td> ".
137            "<td>".&ui_opt_textbox("net_localip", $net_localip, 15, $text{'default'})."</td> </tr>\n";
138 $dtable .= "<tr> <td>$text{'destination_localport'}</td> ".
139            "<td>".&ui_opt_textbox("net_localport", $net_localport, 5, $text{'default'})."</td> </tr>\n";
140 $dtable .= "</table></td> </tr>";
141
142 # Datagram or stream socket
143 $unix = $dgram || $stream;
144 if ($unix) {
145         $unix_name = $unix->{'value'};
146         }
147 $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 6, "<b>$text{'destination_unix'}</b>", $type == 6 || $type == 7)."</td> <td valign=top><table>\n";
148 $dtable .= "<tr> <td>$text{'destination_utype'}</td> ".
149            "<td>".&ui_select("unix_type",
150                      $type == 6 ? "unix-dgram" : "unix-stream",
151                      [ [ "unix-stream", $text{'destinations_types'} ],
152                        [ "unix-dgram", $text{'destinations_typeg'} ] ]).
153            "</td> </tr>\n";
154 $dtable .= "<tr> <td>$text{'destination_socket'}</td> ".
155            "<td>".&ui_textbox("unix_name", $unix_name, 30)."\n".
156                   &file_chooser_button("unix_name")."</td> </tr>\n";
157 $dtable .= "</table></td> </tr>";
158
159 # Actually show the destination
160 $dtable .= "</table>\n";
161 print &ui_table_row($text{'destination_type'}, $dtable);
162
163 # Form footer and buttons
164 print &ui_table_end();
165 if ($in{'new'}) {
166         print &ui_form_end([ [ "create", $text{'create'} ] ]);
167         }
168 else {
169         print &ui_form_end([ [ "save", $text{'save'} ],
170                              [ "delete", $text{'delete'} ] ]);
171         }
172 &ui_print_footer("list_destinations.cgi", $text{'destinations_return'});
173