Handle hostnames with upper-case letters
[webmin.git] / inetd / edit_serv.cgi
1 #!/usr/local/bin/perl
2 # edit_inet.cgi
3 # Display a form for editing or creating an internet service
4
5 require './inetd-lib.pl';
6 &ReadParse();
7
8 if ($in{'new'}) {
9         &ui_print_header(undef, $text{'editserv_title1'}, "");
10         }
11 else {
12         local @servs = &list_services();
13         local @inets = &list_inets();
14         &ui_print_header(undef, $text{'editserv_title2'}, "");
15         if (defined($in{'name'})) {
16                 local $i;
17                 for($i=0; $i<@servs; $i++) {
18                         $in{'spos'} = $i if ($servs[$i]->[1] eq $in{'name'} &&
19                                              $servs[$i]->[3] eq $in{'proto'});
20                         }
21                 defined($in{'spos'}) || &error($text{'editserv_ename'});
22                 for($i=0; $i<@inets; $i++) {
23                         $in{'ipos'} = $i if ($inets[$i]->[3] eq $in{'name'} &&
24                                              $inets[$i]->[5] eq $in{'proto'});
25                         }
26                 }
27         @serv = @{$servs[$in{'spos'}]};
28         if ($in{'ipos'} =~ /\d/) {
29                 @inet = @{$inets[$in{'ipos'}]};
30                 }
31         }
32
33 print "<form action=\"save_serv.cgi\" method=post>\n";
34 if (@serv) {
35         print "<input type=hidden name=spos value=$in{'spos'}>\n";
36         print "<input type=hidden name=ipos value=$in{'ipos'}>\n";
37         }
38 print "<table border width=100%>\n";
39 print "<tr $tb> <td><b>$text{'editserv_detail'}</b></td> </tr>\n";
40 print "<tr $cb> <td><table width=100%>\n";
41
42 print "<tr> <td nowrap><b>$text{'editserv_name'}</b></td>\n";
43 print "<td><input size=20 name=name value=\"$serv[1]\"></td>\n";
44
45 print "<td nowrap><b>$text{'editserv_port'}</b></td>\n";
46 print "<td nowrap><input size=10 name=port value=\"$serv[2]\"></td> </tr>\n";
47
48 print "<tr> <td valign=top><b>$text{'editrpc_protocol'}</b></td>\n";
49 print "<td valign=top><select name=protocol>\n";
50 foreach $p (&list_protocols()) {
51         printf "<option value=$p %s>%s %s\n",
52                 $serv[3] eq $p || (!@serv && $p eq "tcp") ? "selected" : "",
53                 uc($p), $prot_name{$p} ? "($prot_name{$p})" : "";
54         }
55 print "</select></td>\n";
56
57 print "<td valign=top><b>$text{'editrpc_aliase'}</b></td>\n";
58 printf "<td valign=top><textarea name=aliases ".
59        "rows=3 cols=20>%s</textarea></td> </tr>\n",
60         join("\n", split(/\s+/, $serv[4]));
61
62 print "</table></td> </tr></table><p>\n";
63
64 print "<table border width=100%>\n";
65 print "<tr $tb> <td><b>$text{'editrpc_server'}</b></td> </tr>\n";
66 print "<tr $cb> <td><table width=100%>\n";
67
68 print "<tr> <td colspan=4>\n";
69 printf "<input type=radio name=act value=0 %s> $text{'editrpc_noassigned'}\n",
70         @inet ? "" : "checked";
71 printf "<input type=radio name=act value=1 %s> $text{'editrpc_disable'}\n",
72         @inet && !$inet[1] ? "checked" : "";
73 printf "<input type=radio name=act value=2 %s> $text{'editrpc_enable'}\n",
74         $inet[1] ? "checked" : "";
75 print "</td> </tr>\n";
76
77 print "<tr> <td><b>$text{'editserv_program'}</b></td>\n";
78 print "<td colspan=3>";
79 if (!$config{'no_internal'}) {
80         printf "<input type=radio name=serv value=1 %s>\n",
81                 $inet[8] eq "internal" ? "checked" : "";
82         print "$text{'editserv_inetd'}</td> </tr>\n";
83         }
84
85 $qm = ($inet[8] =~ s/^\?//);
86 $tcpd = (-x $config{'tcpd_path'} && $inet[8] eq $config{'tcpd_path'});
87 print "<tr> <td></td>\n";
88 print "<td colspan=3>";
89 if (!$config{'no_internal'}) {
90         printf "<input type=radio name=serv value=2 %s> $text{'editrpc_command'}\n",
91                 $inet[8] ne "internal" && !$tcpd ? "checked" : "";
92         printf "<input name=program size=30 value=\"%s\">\n",
93                 $inet[8] ne "internal" && !$tcpd ? $inet[8] : "";
94         print &file_chooser_button("program", 0);
95         printf "$text{'editserv_args'} <input name=args size=30 value=\"%s\">\n",
96                $inet[5] ne "internal" && !$tcpd ? $inet[9] : "";
97
98 } else {
99         printf "<input type=radio name=serv value=2 %s> $text{'editrpc_command'}\n",
100                 !$tcpd ? "checked" : "";
101         printf "<input name=program size=30 value=\"%s\">\n",
102                 !$tcpd ? $inet[8] : "";
103         print &file_chooser_button("program", 0);
104         printf "$text{'editserv_args'} <input name=args size=30 value=\"%s\">\n",
105                 !$tcpd ? $inet[9] : "";
106         }
107 if ($config{'qm_mode'}) {
108         print "<br>","&nbsp;" x 5;
109         printf "<input type=checkbox name=qm value=1 %s> %s\n",
110                 $qm ? "checked" : "", $text{'editserv_qm'};
111         }
112 print "</td> </tr>\n";
113
114 if (-x $config{'tcpd_path'}) {
115         print "<tr> <td></td>\n";
116         printf "<td colspan=3><input type=radio name=serv value=3 %s>\n",
117                 $tcpd ? "checked" : "";
118         print "$text{'editserv_wrapper'}\n";
119         $inet[9] =~ /^(\S+)\s*(.*)$/;
120         printf "<input name=tcpd size=15 value=\"%s\">\n", $tcpd ? $1 : "";
121         printf "$text{'editserv_args'} <input name=args2 size=30 value=\"%s\"></td> </tr>\n",
122                 $tcpd ? $2 : "";
123         }
124
125 @op1 = split(/[:\.\/]/, $inet[6]);
126 @op2 = split(/[:\.\/]/, $inet[7]);
127 if ($inet[7] =~ /\// && $inet[7] !~ /:/) {
128         # class but no group!
129         splice(@op2, 1, 0, undef);
130         }
131 print "<tr> <td nowrap><b>$text{'editrpc_waitmode'}</b></td> <td nowrap>\n";
132 printf "<input type=radio name=wait value=wait %s> $text{'editrpc_wait'}\n",
133         $op1[0] eq "wait" ? "checked" : "";
134 printf "<input type=radio name=wait value=nowait %s> $text{'editrpc_nowait'}</td>\n",
135         $op1[0] ne "wait" ? "checked" : "";
136
137 print "<td nowrap><b>$text{'editrpc_execasuser'}</b></td>\n";
138 print "<td nowrap><input name=user size=8 value=\"$op2[0]\"> ",
139       &user_chooser_button("user", 0),"</td> </tr>\n";
140
141 if ($config{'extended_inetd'} == 1) {
142         # Display max per minute and group options
143         # This is for systems like Linux
144         print "<tr> <td nowrap><b>$text{'editrpc_max'}</b></td> <td nowrap>\n";
145         printf "<input type=radio name=permin_def value=1 %s> $text{'editrpc_default'}\n",
146                 @op1 < 2 ? "checked" : "";
147         printf "&nbsp; <input type=radio name=permin_def value=0 %s>\n",
148                 @op1 < 2 ? "" : "checked";
149         printf "<input name=permin size=5 value=\"%s\"></td>\n",
150                 @op1 < 2 ? "" : $op1[1];
151
152         print "<td nowrap><b>$text{'editrpc_execasgrp'}</b></td> <td nowrap>\n";
153         printf "<input type=radio name=group_def value=1 %s> %s\n",
154                 $op2[1] ? "" : "checked", $text{'default'};
155         printf "<input type=radio name=group_def value=0 %s>\n",
156                 $op2[1] ? "checked" : "";
157         print &unix_group_input("group", $op2[1]),"</td> </tr>\n";
158         }
159 elsif ($config{'extended_inetd'} == 2) {
160         # Display max child, max per minute, group and login class options
161         # This is for systems like FreeBSD
162         print "<tr> <td nowrap><b>$text{'editrpc_max'}</b></td> <td nowrap>\n";
163         printf "<input type=radio name=permin_def value=1 %s> $text{'editrpc_default'}\n",
164                 @op1 < 3 ? "checked" : "";
165         printf "&nbsp; <input type=radio name=permin_def value=0 %s>\n",
166                 @op1 < 3 ? "" : "checked";
167         printf "<input name=permin size=5 value=\"%s\"></td>\n",
168                 @op1 < 3 ? "" : $op1[2];
169
170         print "<td nowrap><b>$text{'editrpc_execasgrp'}</b></td>\n";
171         print "<td nowrap><select name=group>\n";
172         printf "<option value=\"\" %s> $text{'editrpc_default'}",
173                 $op2[1] ? "" : "selected";
174         setgrent();
175         while(@ginfo = getgrent()) {
176                 printf "<option value=\"$ginfo[0]\" %s>$ginfo[0]\n",
177                         $ginfo[0] eq $op2[1] ? "selected" : "";
178                 }
179         print "</select></td> </tr>\n";
180         endgrent() if ($gconfig{'os_type'} ne 'hpux');
181
182         print "<tr> <td nowrap><b>$text{'editserv_maxchild'}</b></td> <td nowrap>\n";
183         printf "<input type=radio name=child_def value=1 %s> $text{'editrpc_default'}\n",
184                 @op1 < 2 ? "checked" : "";
185         printf "&nbsp; <input type=radio name=child_def value=0 %s>\n",
186                 @op1 < 2 ? "" : "checked";
187         printf "<input name=child size=5 value=\"%s\"></td>\n",
188                 @op1 < 2 ? "" : $op1[1];
189
190         print "<td nowrap><b>$text{'editserv_execlogin'}</b></td>\n";
191         print "<td><input name=class size=10 value=\"$op2[2]\"></td> </tr>\n";
192         }
193
194 print "</table></td></tr></table>\n";
195 if (!$in{'new'}) {
196         print "<table width=100%>\n";
197         print "<tr> <td><input type=submit value=$text{'index_save'}></td>\n";
198         print "</form><form action=\"delete_serv.cgi\">\n";
199         print "<input type=hidden name=spos value=\"$in{'spos'}\">\n";
200         print "<input type=hidden name=ipos value=\"$in{'ipos'}\">\n";
201         print "<td align=right><input type=submit value=$text{'index_delete'}></td> </tr>\n";
202         print "</form></table><p>\n";
203         }
204 else {
205         print "<input type=submit value=$text{'index_create'}></form><p>\n";
206         }
207
208 &ui_print_footer("", $text{'index_list'});