3 # Create, update or delete a client host
5 require (-r 'sshd-lib.pl' ? './sshd-lib.pl' : './ssh-lib.pl');
7 &lock_file($config{'client_config'});
8 $hconf = &get_client_config();
9 &error_setup($text{'host_err'});
11 # Get version and type
12 if (&get_product_name() eq 'usermin') {
13 $version_type = &get_ssh_type();
14 $version_number = &get_ssh_version();
17 $version_type = $version{'type'};
18 $version_number = $version{'number'};
22 # Just delete the host
23 $host = $hconf->[$in{'idx'}];
27 # Saving or creating a host
28 $host = $hconf->[$in{'idx'}] if (!$in{'new'});
29 if ($in{'name_def'}) {
30 $host->{'values'} = [ '*' ];
33 $in{'name'} =~ /^\S+$/ || &error($text{'host_ename'});
34 $host->{'values'} = [ $in{'name'} ];
37 # Create empty host structure
43 $conf = $host->{'members'};
45 # Validate and store host options
46 if ($in{'user_def'}) {
47 &save_directive("User", $conf);
50 $in{'user'} =~ /^\S+$/ || &error($text{'host_euser'});
51 &save_directive("User", $conf, $in{'user'});
54 &save_directive("KeepAlive", $conf,
55 $in{'keep'} == 2 ? undef : $in{'keep'} ? 'yes' : 'no');
57 if ($in{'hostname_def'}) {
58 &save_directive("HostName", $conf);
61 &to_ipaddress($in{'hostname'}) ||
62 &to_ip6address($in{'hostname'}) ||
63 &error($text{'host_ehostname'});
64 &save_directive("HostName", $conf, $in{'hostname'});
67 &save_directive("BatchMode", $conf,
68 $in{'batch'} == 2 ? undef : $in{'batch'} ? 'yes' : 'no');
70 if ($in{'port_def'}) {
71 &save_directive("Port", $conf);
74 $in{'port'} =~ /^\d+$/ || &error($text{'host_eport'});
75 &save_directive("Port", $conf, $in{'port'});
78 if ($version_type ne 'ssh' || $version_number < 3) {
79 &save_directive("Compression", $conf,
80 $in{'comp'} == 2 ? undef : $in{'comp'} ? 'yes' : 'no');
83 if ($in{'escape_def'} == 1) {
84 &save_directive("EscapeChar", $conf);
86 elsif ($in{'escape_def'} == 2) {
87 &save_directive("EscapeChar", $conf, "none");
90 $in{'escape'} =~ /^\S$/ || $in{'escape'} =~ /^\^\S$/ ||
91 &error($text{'host_eescape'});
92 &save_directive("EscapeChar", $conf, $in{'escape'});
96 if ($version_type ne 'ssh' || $version_number < 3) {
97 if ($in{'clevel_def'}) {
98 &save_directive("CompressionLevel", $conf);
101 &save_directive("CompressionLevel", $conf,
105 if ($in{'attempts_def'}) {
106 &save_directive("ConnectionAttempts", $conf);
109 $in{'attempts'} =~ /^\d+$/ ||
110 &error($text{'host_eattempts'});
111 &save_directive("ConnectionAttempts", $conf,
115 &save_directive("UsePrivilegedPort", $conf,
116 $in{'priv'} == 2 ? undef : $in{'priv'} ? 'yes' : 'no');
118 &save_directive("FallBackToRsh", $conf,
119 $in{'rsh'} == 2 ? undef : $in{'rsh'} ? 'yes' : 'no');
121 &save_directive("UseRsh", $conf,
122 $in{'usersh'} == 2 ? undef : $in{'usersh'} ? 'yes' : 'no');
125 &save_directive("ForwardAgent", $conf,
126 $in{'agent'} == 2 ? undef : $in{'agent'} ? 'yes' : 'no');
128 &save_directive("ForwardX11", $conf,
129 $in{'x11'} == 2 ? undef : $in{'x11'} ? 'yes' : 'no');
131 &save_directive("StrictHostKeyChecking", $conf,
132 $in{'strict'} == 2 ? undef : $in{'strict'} == 1 ? 'yes' :
133 $in{'strict'} == 0 ? 'no' : 'ask');
135 if ($version_type eq 'openssh') {
136 &save_directive("CheckHostIP", $conf,
137 $in{'checkip'} == 2 ? undef : $in{'checkip'} ? 'yes' : 'no');
139 &save_directive("Protocol", $conf, $in{'prots'} || undef);
142 for($i=0; defined($in{"llport_$i"}); $i++) {
143 next if (!$in{"llport_$i"} && !$in{"lrhost_$i"} &&
145 $in{"llport_$i"} =~ /^\d+$/ || &error($text{'host_elport'});
146 $in{"lrhost_$i"} =~ /^\S+$/ || &error($text{'host_erhost'});
147 $in{"lrport_$i"} =~ /^\d+$/ || &error($text{'host_erport'});
148 push(@lforward, sprintf("%d %s:%d", $in{"llport_$i"},
149 $in{"lrhost_$i"}, $in{"lrport_$i"}));
151 &save_directive("LocalForward", $conf, @lforward);
153 for($i=0; defined($in{"rrport_$i"}); $i++) {
154 next if (!$in{"rrport_$i"} && !$in{"rlhost_$i"} &&
156 $in{"rrport_$i"} =~ /^\d+$/ || &error($text{'host_erport'});
157 $in{"rlhost_$i"} =~ /^\S+$/ || &error($text{'host_elhost'});
158 $in{"rlport_$i"} =~ /^\d+$/ || &error($text{'host_elport'});
159 push(@rforward, sprintf("%d %s:%d", $in{"rrport_$i"},
160 $in{"rlhost_$i"}, $in{"rlport_$i"}));
162 &save_directive("RemoteForward", $conf, @rforward);
166 &unlock_file($config{'client_config'});
167 if (&get_product_name() ne 'usermin') {
168 &webmin_log($in{'new'} ? "create" : $in{'delete'} ? "delete" : "update",
169 "host", $host->{'values'}->[0]);
171 &redirect("list_hosts.cgi");