Handle hostnames with upper-case letters
[webmin.git] / pap / save_options.cgi
1 #!/usr/local/bin/perl
2 # save_options.cgi
3 # Save PPP options
4
5 require './pap-lib.pl';
6 $access{'options'} || &error($text{'options_ecannot'});
7 &ReadParse();
8 &error_setup($text{'options_err'});
9 $file = $in{'file'} || $config{'ppp_options'};
10 &lock_file($file);
11 @opts = &parse_ppp_options($file);
12
13 # Validate inputs
14 if (!$in{'ip_def'}) {
15         &check_ipaddress($in{'local'}) || &error($text{'options_elocal'});
16         &check_ipaddress($in{'remote'}) || &error($text{'options_eremote'});
17         }
18 if (!$in{'netmask_def'}) {
19         &check_ipaddress($in{'netmask'}) || &error($text{'options_enetmask'});
20         }
21 if (!$in{'idle_def'}) {
22         $in{'idle'} =~ /^\d+$/ || &error($text{'options_eidle'});
23         }
24 @dns = split(/\s+/, $in{'dns'});
25 foreach $d (@dns) {
26         &check_ipaddress($d) || &error(&text('options_edns', $d));
27         }
28
29 if (!$in{'file'}) {
30         # Save AutoPPP setting
31         &lock_file($config{'login_config'});
32         @login = &parse_login_config();
33         ($auto) = grep { $_->{'user'} eq "/AutoPPP/" } @login;
34         if ($auto && !$in{'auto'}) {
35                 # Delete AutoPPP entry
36                 &delete_login_config(\@login, $auto);
37                 }
38         elsif (!$auto && $in{'auto'}) {
39                 &create_login_config(\@login, 
40                     { 'user' => '/AutoPPP/', 'userid' => '-',
41                       'utmp' => 'a_ppp', 'program' => &has_command("pppd") });
42                 }
43         }
44
45 # Save PPP options
46 ($ip) = grep { $_->{'local'} } @opts;
47 &save_ppp_option(\@opts, $file, $ip, $in{'ip_def'} ? undef :
48         { 'local' => $in{'local'}, 'remote' => $in{'remote'} });
49 &save_ppp_option(\@opts, $file, "netmask", $in{'netmask_def'} ? undef :
50         { 'name' => 'netmask', 'value' => $in{'netmask'} });
51 &save_ppp_option(\@opts, $file, "proxyarp",
52                  $in{'proxyarp'} ? { 'name' => 'proxyarp' } : undef);
53 &save_ppp_option(\@opts, $file, "lock",
54                  $in{'lock'} ? { 'name' => 'lock' } : undef);
55 if ($in{'ctrl'} == 0) {
56         &save_ppp_option(\@opts, $file, "modem", undef);
57         &save_ppp_option(\@opts, $file, "local", { 'name' => 'local' });
58         }
59 elsif ($in{'ctrl'} == 1) {
60         &save_ppp_option(\@opts, $file, "local", undef);
61         &save_ppp_option(\@opts, $file, "modem", { 'name' => 'modem' });
62         }
63 else {
64         &save_ppp_option(\@opts, $file, "modem", undef);
65         &save_ppp_option(\@opts, $file, "local", undef);
66         }
67 if ($in{'auth'} == 0) {
68         &save_ppp_option(\@opts, $file, "auth", undef);
69         &save_ppp_option(\@opts, $file, "noauth", undef);
70         }
71 elsif ($in{'auth'} == 1) {
72         &save_ppp_option(\@opts, $file, "auth", undef);
73         &save_ppp_option(\@opts, $file, "noauth", { 'name' => 'noauth' });
74         }
75 else {
76         &save_ppp_option(\@opts, $file, "noauth", undef);
77         &save_ppp_option(\@opts, $file, "auth", { 'name' => 'auth' });
78         }
79 &save_ppp_option(\@opts, $file, "login",
80                  $in{'login'} ? { 'name' => 'login' } : undef);
81 &save_ppp_option(\@opts, $file, "idle", $in{'idle_def'} ? undef :
82                 { 'name' => 'idle', 'value' => $in{'idle'} } );
83 @olddns = &find("ms-dns", \@opts);
84 for($i=0; $i<@dns || $i<@olddns; $i++) {
85         &save_ppp_option(\@opts, $file, $olddns[$i],
86                          $dns[$i] ? { 'name' => 'ms-dns', 'value' => $dns[$i] }
87                                   : undef);
88         }
89
90 # All done
91 &flush_file_lines();
92 &unlock_file($file);
93 &unlock_file($config{'login_config'}) if (!$in{'file'});
94 &webmin_log("options", undef, $in{'tty'}, \%in);
95 &redirect($in{'file'} ? "list_mgetty.cgi" : "");
96