Handle hostnames with upper-case letters
[webmin.git] / adsl-client / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display ADSL configuration options
4 # XXX new-style ADSL config in redhat 7.2 and above!
5 #       XXX effects start/stop and bootup as well
6
7 require './adsl-client-lib.pl';
8 $vers = &get_pppoe_version(\$out);
9 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
10         &help_search_link("pppoe", "man", "doc"), undef, undef,
11         $vers ? &text('index_version', $vers) : undef);
12
13 if (!$vers) {
14         # Not installed
15         print "<p>",&text('index_eadsl', "<tt>$config{'pppoe_cmd'}</tt>",
16                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
17         }
18 elsif (!($conf = &get_config())) {
19         # Missing config file
20         if ($config{'conf_style'} == 0) {
21                 # Just give up
22                 print "<p>",
23                       &text('index_econfig', "<tt>$config{'pppoe_conf'}</tt>",
24                       "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
25                 }
26         else {
27                 # On redhat systems, the file needs to be created by this
28                 # module :-(
29                 print "<p>",&text('index_esetup',
30                         "<tt>$config{'pppoe_conf'}</tt>"),"<p>\n";
31                 print "<center><form action=setup.cgi>\n";
32                 print "<input type=submit value='$text{'index_setup'}'>\n";
33                 print "</form></center>\n";
34                 }
35         }
36 elsif (&find("TYPE", $conf) =~ /modem/i) {
37         # For a modem on a redhat system
38         $config{'pppoe_conf'} =~ /^(.*)\//;
39         print "<p>",&text('index_emodem', "<tt>$1</tt>",
40                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
41         }
42 else {
43         # Show configuration form
44         $conf = &get_config();
45         print "$text{'index_desc'}<p>\n";
46         print "<form action=save.cgi method=post>\n";
47         print "<table border width=100%>\n";
48         print "<tr $tb> <td><b>$text{'index_header'}</b></td> </tr>\n";
49         print "<tr $cb> <td><table width=100%>\n";
50
51         # Show network interface field
52         &foreign_require("net", "net-lib.pl");
53         $eth = &find("ETH", $conf);
54         print "<tr> <td><b>",&hlink($text{'index_eth'}, "eth"),"</b></td>\n";
55         @ifcs = &net::active_interfaces(1);
56         print "<td><select name=eth>\n";
57         $found = !$eth;
58         foreach $i (@ifcs) {
59                 next if ($i->{'fullname'} !~ /^eth(\d+)$/);
60                 printf "<option value='%s' %s>%s\n",
61                         $i->{'name'}, $eth eq $i->{'name'} ? "selected" : "",
62                         $i->{'name'};
63                 $found++ if ($eth eq $i->{'name'});
64                 }
65         printf "<option value='' %s>%s\n",
66                 $found ? "" : "selected", $text{'index_other'};
67         print "</select>\n";
68         printf "<input name=other size=6 value='%s'></td>\n",
69                 $found ? "" : $eth;
70
71         # Show on-demand field
72         $demand = &find("DEMAND", $conf);
73         print "<td><b>",&hlink($text{'index_demand'},"demand"),"</b></td>\n";
74         printf "<td nowrap><input type=radio name=demand value=yes %s> %s\n",
75                 $demand !~ /^\d+$/i ? "" : "checked", $text{'index_timeout'};
76         printf "<input name=timeout value='%s' size=4>\n",
77                 $demand !~ /^\d+$/i ? "" : $demand;
78         printf "<input type=radio name=demand value=no %s> %s</td> </tr>\n",
79                 $demand !~ /^\d+$/i ? "checked" : "", $text{'no'};
80
81         # Show username field
82         $user = &find("USER", $conf);
83         print "<tr> <td><b>",&hlink($text{'index_user'},"user"),"</b></td>\n";
84         printf "<td><input name=user size=20 value='%s'></td>\n",
85                 $user;
86
87         # Show password field (from pap-secrets)
88         ($sec) = grep { $_->{'client'} eq $user } &list_secrets();
89         print "<td><b>",&hlink($text{'index_sec'},"sec"),"</b></td>\n";
90         printf "<td><input type=password name=sec size=20 value='%s'></td> </tr>\n",
91                 $sec->{'secret'};
92
93         # Show DNS config buttons
94         $dns = &find("USEPEERDNS", $conf) || &find("PEERDNS", $conf);
95         print "<tr> <td><b>",&hlink($text{'index_dns'}, "dns"),"</b></td>\n";
96         printf "<td><input type=radio name=dns value=yes %s> %s\n",
97                 $dns =~ /yes/i ? "checked" : "", $text{'yes'};
98         printf "<input type=radio name=dns value=no %s> %s</td>\n",
99                 $dns =~ /yes/i ? "" : "checked", $text{'no'};
100
101         # Show connect timeout field
102         $connect = &find("CONNECT_TIMEOUT", $conf);
103         print "<td><b>",&hlink($text{'index_connect'},"connect"),"</b></td>\n";
104         printf "<td nowrap><input type=radio name=connect_def value=1 %s> %s\n",
105                 $connect == 0 ? "checked" : "", $text{'index_forever'};
106         printf "<input type=radio name=connect_def value=0 %s>\n",
107                 $connect == 0 ? "" : "checked";
108         printf "<input name=connect size=4 value='%s'> %s</td> </tr>\n",
109                 $connect == 0 ? "" : $connect, $text{'index_secs'};
110
111         # Show MSS field
112         $mss = &find("CLAMPMSS", $conf);
113         print "<tr> <td><b>",&hlink($text{'index_mss'},"mss"),"</b></td>\n";
114         printf "<td nowrap><input type=radio name=mss value=yes %s> %s\n",
115                 $mss =~ /no/i ? "" : "checked", $text{'index_psize'};
116         printf "<input name=psize value='%s' size=5> %s\n",
117                 $mss =~ /no/i ? "" : $mss, $text{'index_bytes'};
118         printf "<input type=radio name=mss value=no %s> %s</td>\n",
119                 $mss =~ /no/i ? "checked" : "", $text{'no'};
120
121         # Show firewall menu
122         $fw = &find("FIREWALL", $conf);
123         $fw ||= "NONE";
124         if ($fw ne "NONE") {
125                 print "<td><b>",&hlink($text{'index_fw'},"fw"),"</b></td>\n";
126                 print "<td><select name=fw>\n";
127                 foreach $f ('NONE', 'STANDALONE', 'MASQUERADE') {
128                         printf "<option value=%s %s>%s\n",
129                                 $f, lc($f) eq lc($fw) ? "selected" : "",
130                                 $text{'index_fw_'.lc($f)};
131                         }
132                 print "</select></td> </tr>\n";
133                 }
134         else {
135                 print "</tr>\n";
136                 }
137
138         print "</table></td></tr></table>\n";
139         print "<input type=submit value='$text{'index_save'}'></form>\n";
140
141         # Show connected/disconnect buttons
142         print &ui_hr();
143         print &ui_buttons_start();
144         local ($dev, $ip) = &get_adsl_ip();
145         if ($ip) {
146                 # Offer to shut down
147                 print &ui_buttons_row("stop.cgi", $text{'index_stop'},
148                                       &text('index_stopdesc', "<tt>$ip</tt>",
149                                             "<tt>$config{'stop_cmd'}</tt>"));
150                 }
151         elsif ($dev eq "demand") {
152                 # Offer to cancel on-demand connection
153                 print &ui_buttons_row("stop.cgi", $text{'index_cdemand'},
154                                       &text('index_cdemanddesc',
155                                             "<tt>$config{'stop_cmd'}</tt>"));
156                 }
157         elsif ($dev) {
158                 # Offer to cancel connect
159                 print &ui_buttons_row("stop.cgi", $text{'index_cancel'},
160                                       &text('index_canceldesc',
161                                             "<tt>$config{'stop_cmd'}</tt>"));
162                 }
163         else {
164                 # Offer to start up
165                 print &ui_buttons_row("start.cgi", $text{'index_start'},
166                                       &text('index_startdesc',
167                                             "<tt>$config{'start_cmd'}</tt>"));
168                 }
169
170         # Show boot-time button
171         if ($config{'conf_style'} == 1 && ($onboot = find("ONBOOT", $conf))) {
172                 # Offer to turn on/off starting at boot
173                 print &ui_buttons_row("rbootup.cgi", $text{'index_boot'},
174                                       $text{'index_bootdesc'}, undef,
175                                       &ui_yesno_radio("onboot",
176                                                  $onboot =~ /yes/i ? 1 : 0));
177                 }
178         elsif (&foreign_check("init")) {
179                 # Offer to enable/disable init script
180                 &foreign_require("init", "init-lib.pl");
181                 $boot = &init::action_status("adsl");
182                 if ($boot > 0) {
183                         print &ui_buttons_row("bootup.cgi", $text{'index_boot'},
184                                               $text{'index_bootdesc'}, undef,
185                                               &ui_yesno_radio("boot",
186                                                          $boot == 2 ? 1 : 0));
187                         }
188                 }
189
190         print &ui_buttons_end();
191         }
192
193 &ui_print_footer("/", $text{'index'});
194