Handle hostnames with upper-case letters
[webmin.git] / sshd / save_net.cgi
1 #!/usr/local/bin/perl
2 # save_net.cgi
3 # save networking sshd options
4
5 require './sshd-lib.pl';
6 &ReadParse();
7 &error_setup($text{'net_err'});
8 &lock_file($config{'sshd_config'});
9 $conf = &get_sshd_config();
10
11 if ($version{'type'} eq 'openssh' && $version{'number'} >= 3) {
12         # Save multiple
13         if ($in{'listen_def'}) {
14                 &save_directive("ListenAddress", $conf);
15                 }
16         else {
17                 for($i=0; defined($in{"mode_$i"}); $i++) {
18                         next if ($in{"mode_$i"} == 0);
19                         if ($in{"mode_$i"} == 1) {
20                                 $a = "0.0.0.0";
21                                 }
22                         elsif ($in{"mode_$i"} == 2) {
23                                 $a = "[::]";
24                                 }
25                         elsif ($in{"mode_$i"} == 3) {
26                                 $a = $in{"address_$i"};
27                                 &check_ipaddress($a) || &check_ip6address($a) ||
28                                         &error(&text('net_eladdress', $a));
29                                 $a = "[$a]" if (&check_ip6address($a));
30                                 }
31                         if ($in{"port_${i}_def"}) {
32                                 push(@listens, $a);
33                                 }
34                         else {
35                                 $in{"port_$i"} =~ /^\d+$/ ||
36                                     &error(&text('net_elport', $in{"port_$i"}));
37                                 push(@listens, $a.":".$in{"port_$i"});
38                                 }
39                         }
40                 @listens || &error($text{'net_elisten2'});
41                 &save_directive("ListenAddress", $conf, @listens);
42                 }
43         }
44 else {
45         # Save just one address
46         if ($in{'listen_def'}) {
47                 &save_directive("ListenAddress", $conf);
48                 }
49         else {
50                 &check_ipaddress($in{'listen'}) ||
51                   ($version{'number'} >= 2 && &to_ipaddress($in{'listen'})) ||
52                     &error($text{'net_elisten'});
53                 &save_directive("ListenAddress", $conf, $in{'listen'});
54                 }
55         }
56
57 if ($in{'port_def'}) {
58         &save_directive("Port", $conf);
59         }
60 else {
61         @ports = split(/\s+/, $in{'port'});
62         @ports || &error($text{'net_eport'});
63         foreach $p (@ports) {
64                 $p =~ /^\d+$/ || &error($text{'net_eport'});
65                 }
66         &save_directive("Port", $conf, \@ports, "ListenAddress");
67         }
68
69 if ($version{'type'} eq 'openssh' && $version{'number'} >= 2) {
70         @prots = split(/\0/, $in{'prots'});
71         @prots || &error($text{'net_eprots'});
72         &save_directive("Protocol", $conf, join(",", @prots));
73         }
74
75 if ($version{'type'} eq 'ssh' &&
76     ($version{'number'} < 2 || $version{'number'} >= 3)) {
77         if ($in{'idle_def'}) {
78                 &save_directive("IdleTimeout", $conf);
79                 }
80         else {
81                 $in{'idle'} =~ /^\d+$/ || &error($text{'net_eidle'});
82                 &save_directive("IdleTimeout", $conf,
83                                 $in{'idle'}.$in{'idle_units'});
84                 }
85         }
86
87 &save_directive("KeepAlive", $conf, $in{'keep'} ? 'yes' : 'no');
88
89 if ($in{'grace_def'}) {
90         &save_directive("LoginGraceTime", $conf);
91         }
92 else {
93         $in{'grace'} =~ /^\d+$/ || &error($text{'net_egrace'});
94         &save_directive("LoginGraceTime", $conf, $in{'grace'});
95         }
96
97 if ($version{'type'} ne 'openssh' || $version{'number'} >= 2) {
98         &save_directive("AllowTcpForwarding", $conf, $in{'tcp'} ? 'yes' : 'no');
99         }
100
101 if ($version{'type'} eq 'openssh' && $version{'number'} >= 2) {
102         &save_directive("GatewayPorts", $conf, $in{'gateway'} ? 'yes' : 'no');
103
104         if ($version{'number'} > 2.3 && $version{'number'} < 3.7) {
105                 &save_directive("ReverseMappingCheck", $conf,
106                                 $in{'reverse'} ? 'yes' : 'no');
107                 }
108         }
109
110 &flush_file_lines();
111 &unlock_file($config{'sshd_config'});
112 &webmin_log("net");
113 &redirect("");
114