Handle hostnames with upper-case letters
[webmin.git] / adsl-client / save.cgi
1 #!/usr/local/bin/perl
2 # save.cgi
3 # Save the ADSL client configuration
4
5 require './adsl-client-lib.pl';
6 &error_setup($text{'save_err'});
7 &lock_file($config{'pppoe_conf'});
8 $conf = &get_config();
9 &ReadParse();
10
11 # Validate and store inputs
12 $eth = $in{'eth'} || $in{'other'};
13 $eth =~ /^\S+$/ || &error($text{'save_eeth'});
14 &save_directive($conf, "ETH", $eth);
15
16 if ($in{'demand'} eq 'yes') {
17         $in{'timeout'} =~ /^\d+$/ || &error($text{'save_etimeout'});
18         &save_directive($conf, "DEMAND", $in{'timeout'});
19         }
20 else {
21         &save_directive($conf, "DEMAND", 'no');
22         }
23  
24 $olduser = &find("USER", $conf);
25 $in{'user'} =~ /^\S+$/ || &error($text{'save_euser'});
26 &save_directive($conf, "USER", $in{'user'});
27
28 $dnsdir = &find("USEPEERDNS", $conf) ? "USEPEERDNS" : "PEERDNS";
29 &save_directive($conf, $dnsdir, $in{'dns'});
30
31 if ($in{'connect_def'}) {
32         &save_directive($conf, "CONNECT_TIMEOUT", 0);
33         }
34 else {
35         $in{'connect'} =~ /^\d+$/ || &error($text{'save_econnect'});
36         &save_directive($conf, "CONNECT_TIMEOUT", $in{'connect'});
37         }
38
39 if ($in{'mss'} eq 'yes') {
40         $in{'psize'} =~ /^\d+$/ || &error($text{'save_emss'});
41         &save_directive($conf, "CLAMPMSS", $in{'psize'});
42         }
43 else {
44         &save_directive($conf, "CLAMPMSS", 'no');
45         }
46
47 if ($in{'fw'}) {
48         &save_directive($conf, "FIREWALL", $in{'fw'});
49         }
50
51 # Actually save the directives, and update the pap-secrets file
52 &flush_file_lines();
53 &unlock_file($config{'pppoe_conf'});
54 &lock_file($config{'pap_file'});
55 @secs = &list_secrets();
56 ($sec) = grep { $_->{'client'} eq $olduser } @secs;
57 if (!$sec) {
58         ($sec) = grep { $_->{'client'} eq $in{'user'} } @secs;
59         }
60 if ($sec) {
61         $sec->{'secret'} = $in{'sec'};
62         $sec->{'client'} = $in{'user'};
63         &change_secret($sec);
64         }
65 else {
66         $sec = { 'secret' => $in{'sec'},
67                  'client' => $in{'user'},
68                  'server' => '*' };
69         &create_secret($sec);
70         }
71 &unlock_file($config{'pap_file'});
72 &webmin_log("save");
73
74 # Tell the user
75 &ui_print_header(undef, $text{'save_title'}, "");
76
77 print "<p>$text{'save_desc'}<p>\n";
78
79 &ui_print_footer("", $text{'index_return'});
80