Handle hostnames with upper-case letters
[webmin.git] / pap / edit_options.cgi
1 #!/usr/local/bin/perl
2 # edit_options.cgi
3 # Display list of options for PPP, and show if mgetty has autoPPP mode enabled
4
5 require './pap-lib.pl';
6 $access{'options'} || &error($text{'options_ecannot'});
7 &ReadParse();
8 &ui_print_header(undef, $text{'options_title'}, "");
9 $of = $config{'ppp_options'};
10 if ($in{'file'} =~ /^\Q$of\E\.ttyS(\d+)$/) {
11         $tty = "ttyS$1";
12         print "<center><font size=+1>",&text('options_serial', $1+1),
13               "</font></center>\n";
14         }
15 elsif ($in{'file'} =~ /^\Q$of\E\.(\S+)$/) {
16         $tty = $1;
17         $tty =~ s/\./\//g;
18         print "<center><font size=+1>",&text('options_dev', "<tt>$tty</tt>"),
19               "</font></center>\n";
20         }
21
22 # Check if the PPP daemon is actually installed
23 if (!&has_command($config{'pppd'})) {
24         print "<p>",&text('options_ecmd', "<tt>$config{'pppd'}</tt>"),"<p>\n";
25         &ui_print_footer("", $text{'index_return'});
26         exit;
27         }
28
29 # Check if the pppd is the linux one
30 $out = `$config{'pppd'} -v 2>&1`;
31 if ($out !~ /version\s+([0-9\.]+)/) {
32         print "<p>",&text('options_epppd', "<tt>$config{'pppd'}</tt>"),"<p>\n";
33         &ui_print_footer("", $text{'index_return'});
34         exit;
35         }
36
37 @opts = &parse_ppp_options($in{'file'} || $of);
38 if (!$in{'file'}) {
39         # Check for the mgetty login config file
40         if (!-r $config{'login_config'}) {
41                 print "<p>",&text('options_elogin',
42                     "<tt>$config{'login_config'}</tt>",
43                     "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
44                 &ui_print_footer("", $text{'index_return'});
45                 exit;
46                 }
47         @login = &parse_login_config();
48         }
49
50 print "<p>$text{'options_desc'}<p>\n" if (!$in{'file'});
51
52 print "<form action=save_options.cgi>\n";
53 print "<input type=hidden name=file value='$in{'file'}'>\n";
54 print "<input type=hidden name=tty value='$tty'>\n";
55 print "<table border width=100%>\n";
56 print "<tr $tb> <td><b>$text{'options_header'}</b></td> </tr>\n";
57 print "<tr $cb> <td><table width=100%>\n";
58
59 if (!$in{'file'}) {
60         # Show if autoPPP is being used or not
61         ($auto) = grep { $_->{'user'} eq "/AutoPPP/" } @login;
62         print "<tr> <td colspan=2><b>$text{'options_autoppp'}</b></td>\n";
63         printf "<td><input name=auto type=radio value=1 %s> %s\n",
64                 $auto ? "checked" : "", $text{'yes'};
65         printf "<input name=auto type=radio value=0 %s> %s</td> </tr>\n",
66                 $auto ? "" : "checked", $text{'no'};
67         print "<tr> <td colspan=4><hr></td> </tr>\n";
68         }
69
70 ($ip) = grep { $_->{'local'} } @opts;
71 print "<tr> <td><b>$text{'options_ip'}</b></td>\n";
72 printf "<td colspan=3><input type=radio name=ip_def value=1 %s> %s\n",
73         $ip ? "" : "checked", $text{'options_auto'};
74 printf "<input type=radio name=ip_def value=0 %s>\n",
75         $ip ? "checked" : "";
76 printf "%s <input name=local size=15 value='%s'>\n",
77         $text{'options_local'}, $ip->{'local'};
78 printf "%s <input name=remote size=15 value='%s'></td> </tr>\n",
79         $text{'options_remote'}, $ip->{'remote'};
80
81 $nm = &find("netmask", \@opts);
82 print "<tr> <td><b>$text{'options_netmask'}</b></td>\n";
83 printf "<td><input type=radio name=netmask_def value=1 %s> %s\n",
84         $nm ? "" : "checked", $text{'default'};
85 printf "<input type=radio name=netmask_def value=0 %s>\n",
86         $nm ? "checked" : "";
87 printf "<input name=netmask size=15 value='%s'></td>\n", $nm->{'value'};
88
89 $proxy = &find("proxyarp", \@opts);
90 print "<td><b>$text{'options_proxyarp'}</b></td>\n";
91 printf "<td><input type=radio name=proxyarp value=1 %s> %s\n",
92         $proxy ? "checked" : "", $text{'yes'};
93 printf "<input type=radio name=proxyarp value=0 %s> %s</td> </tr>\n",
94         $proxy ? "" : "checked", $text{'no'};
95
96 $lock = &find("lock", \@opts);
97 print "<tr> <td><b>$text{'options_lock'}</b></td>\n";
98 printf "<td><input type=radio name=lock value=1 %s> %s\n",
99         $lock ? "checked" : "", $text{'yes'};
100 printf "<input type=radio name=lock value=0 %s> %s</td>\n",
101         $lock ? "" : "checked", $text{'no'};
102
103 $modem = &find("modem", \@opts);
104 $local = &find("local", \@opts);
105 print "<td><b>$text{'options_ctrl'}</b></td>\n";
106 print "<td><select name=ctrl>\n";
107 printf "<option value=0 %s> %s\n",
108         $local ? "selected" : "", $text{'options_ctrl0'};
109 printf "<option value=1 %s> %s\n",
110         $modem ? "selected" : "", $text{'options_ctrl1'};
111 printf "<option value=2 %s> %s\n",
112         $modem || $local ? "" : "selected", $text{'default'};
113 print "</select></td> </tr>\n";
114
115 $auth = &find("auth", \@opts);
116 $noauth = &find("noauth", \@opts);
117 print "<tr> <td><b>$text{'options_auth'}</b></td>\n";
118 printf "<td colspan=3><input type=radio name=auth value=0 %s> %s\n",
119         $noauth || $auth ? "" : "checked", $text{'options_auth0'};
120 printf "<input type=radio name=auth value=1 %s> %s\n",
121         $noauth ? "checked" : "", $text{'options_auth1'};
122 printf "<input type=radio name=auth value=2 %s> %s</td> </tr>\n",
123         $auth ? "checked" : "", $text{'options_auth2'};
124
125 $login = &find("login", \@opts);
126 print "<tr> <td><b>$text{'options_login'}</b></td>\n";
127 printf "<td><input type=radio name=login value=1 %s> %s\n",
128         $login ? "checked" : "", $text{'yes'};
129 printf "<input type=radio name=login value=0 %s> %s</td>\n",
130         $login ? "" : "checked", $text{'no'};
131
132 $idle = &find("idle", \@opts);
133 print "<td><b>$text{'options_idle'}</b></td>\n";
134 printf "<td><input type=radio name=idle_def value=1 %s> %s\n",
135         $idle ? "" : "checked", $text{'options_idle_def'};
136 printf "<input type=radio name=idle_def value=0 %s>\n",
137         $idle ? "checked" : "";
138 printf "<input name=idle size=8 value='%s'> %s</td> </tr>\n",
139         $idle->{'value'}, $text{'mgetty_secs'};
140
141 @dns = &find("ms-dns", \@opts);
142 print "<tr> <td><b>$text{'options_dns'}</b></td>\n";
143 printf "<td colspan=3><input name=dns size=50 value='%s'></td> </tr>\n",
144         join(" ", map { $_->{'value'} } @dns);
145
146 print "</table></td></tr></table>\n";
147 print "<input type=submit value='$text{'save'}'></form>\n";
148
149 if ($in{'file'}) {
150         &ui_print_footer("list_mgetty.cgi", $text{'mgetty_return'});
151         }
152 else {
153         &ui_print_footer("", $text{'index_return'});
154         }
155