Handle hostnames with upper-case letters
[webmin.git] / sshd / edit_host.cgi
1 #!/usr/local/bin/perl
2 # edit_host.cgi
3 # Display options for a new or existing host config
4
5 require (-r 'sshd-lib.pl' ? './sshd-lib.pl' : './ssh-lib.pl');
6 &ReadParse();
7 if ($in{'new'}) {
8         &ui_print_header(undef, $text{'host_create'}, "", "chost");
9         }
10 else {
11         &ui_print_header(undef, $text{'host_edit'}, "", "ehost");
12         $hconf = &get_client_config();
13         $host = $hconf->[$in{'idx'}];
14         $conf = $host->{'members'};
15         }
16
17 # Get version and type
18 if (&get_product_name() eq 'usermin') {
19         $version_type = &get_ssh_type();
20         $version_number = &get_ssh_version();
21         }
22 else {
23         $version_type = $version{'type'};
24         $version_number = $version{'number'};
25         }
26
27 print &ui_form_start("save_host.cgi", "post");
28 print &ui_hidden("idx", $in{'idx'});
29 print &ui_hidden("new", $in{'new'});
30 print &ui_table_start($text{'host_header'}, "width=100%", 2);
31
32 # Name for this host
33 print &ui_table_row($text{'host_name'},
34         &ui_opt_textbox("name", $host->{'values'}->[0] eq '*' ? '' :
35                                  $host->{'values'}->[0],
36                         50, $text{'hosts_all'}));
37
38 # Default user to login as
39 $user = &find_value("User", $conf);
40 print &ui_table_row($text{'host_user'},
41         &ui_opt_textbox("user", $user, 20, $text{'host_user_def'}));
42
43 # Send keep-alive packets?
44 $keep = &find_value("KeepAlive", $conf);
45 print &ui_table_row($text{'host_keep'},
46         &yes_no_default_radio("keep", $keep));
47
48 # Real hostname to connect to
49 $hostname = &find_value("HostName", $conf);
50 print &ui_table_row($text{'host_hostname'},
51         &ui_opt_textbox("hostname", $hostname, 30, $text{'host_hostname_def'}));
52
53 # Port to use
54 $port = &find_value("Port", $conf);
55 print &ui_table_row($text{'host_port'},
56         &ui_opt_textbox("port", $port, 6, $text{'default'}." (22)"));
57
58 # Ask for password if needed, or fail fast?
59 $batch = &find_value("BatchMode", $conf);
60 print &ui_table_row($text{'host_batch'},
61         &yes_no_default_radio("batch", $batch));
62
63 # Compress SSH?
64 $comp = &find_value("Compression", $conf);
65 print &ui_table_row($text{'host_comp'},
66         &yes_no_default_radio("comp", $comp));
67
68 # Escape character in session
69 $escape = &find_value("EscapeChar", $conf);
70 print &ui_table_row($text{'host_escape'},
71         &ui_radio("escape_def", $escape eq "" ? 1 :
72                                 $escape eq "none" ? 2 : 0,
73                   [ [ 1, $text{'default'}." (~.)" ],
74                     [ 2, $text{'host_escape_none'} ],
75                     [ 0, &ui_textbox("escape",
76                                 $escape eq "none" ? "" : $escape, 4) ] ]));
77
78 if ($version_type ne 'ssh' || $version_number < 3) {
79         # SSH compression level
80         $clevel = &find_value("CompressionLevel", $conf);
81         print &ui_table_row($text{'host_clevel'},
82                 &ui_radio("clevel_def", $clevel ? 0 : 1,
83                   [ [ 1, $text{'default'} ],
84                     [ 0, &ui_select("clevel", $clevel,
85                            [ map { [ $_, $text{"host_clevel_".$_} ] }
86                                  (1 .. 9) ]) ] ]));
87
88         # Number of times to attempt connection
89         $attempts = &find_value("ConnectionAttempts", $conf);
90         print &ui_table_row($text{'host_attempts'},
91                 &ui_opt_textbox("attempts", $attempts, 5, $text{'default'}));
92
93         # Use local privileged port?
94         $priv = &find_value("UsePrivilegedPort", $conf);
95         print &ui_table_row($text{'host_priv'},
96                 &yes_no_default_radio("priv", $priv));
97
98         # Try RSH if SSH fails?
99         $rsh = &find_value("FallBackToRsh", $conf);
100         print &ui_table_row($text{'host_rsh'},
101                  &yes_no_default_radio("rsh", $rsh));
102
103         # Use RSH only?
104         $usersh = &find_value("UseRsh", $conf);
105         print &ui_table_row($text{'host_usersh'},
106                 &yes_no_default_radio("usersh", $usersh));
107         }
108
109 # Forward SSH agent?
110 $agent = &find_value("ForwardAgent", $conf);
111 print &ui_table_row($text{'host_agent'},
112         &yes_no_default_radio('agent', $agent));
113
114 # Forward X connection?
115 $x11 = &find_value("ForwardX11", $conf);
116 print &ui_table_row($text{'host_x11'},
117         &yes_no_default_radio('x11', $x11));
118
119 # Strictly check host keys?
120 $strict = &find_value("StrictHostKeyChecking", $conf);
121 print &ui_table_row($text{'host_strict'},
122         &ui_radio('strict', lc($strict) eq 'no' ? 0 :
123                             lc($strict) eq 'yes' ? 1 :
124                             lc($strict) eq 'ask' ? 3 : 2,
125                   [ [ 0, $text{'yes'} ], [ 1, $text{'no'} ],
126                     [ 3, $text{'host_ask'} ], [ 2, $text{'default'} ] ]));
127
128 if ($version_type eq 'openssh') {
129         # Double-check remote host IP?
130         $checkip = &find_value("CheckHostIP", $conf);
131         print &ui_table_row($text{'host_checkip'},
132                 &yes_no_default_radio('checkip', $checkip));
133
134         # SSH protocols to try
135         $prots = &find_value("Protocol", $conf);
136         print &ui_table_row($text{'host_prots'},
137                 &ui_select("prots", $prots,
138                            [ [ '', $text{'default'} ],
139                              [ 1, $text{'host_prots1'} ],
140                              [ 2, $text{'host_prots2'} ],
141                              [ '1,2', $text{'host_prots12'} ],
142                              [ '2,1', $text{'host_prots21'} ] ], 1, 0, 1));
143         }
144
145 print &ui_table_hr();
146
147 # Local ports to forward
148 @lforward = &find("LocalForward", $conf);
149 @ltable = ( );
150 $i = 0;
151 foreach $l (@lforward, { }) {
152         local ($lp, $rh, $rp) = ( $l->{'values'}->[0],
153                                   split(/:/, $l->{'values'}->[1]) );
154         push(@ltable, [ &ui_textbox("llport_$i", $lp, 8),
155                         &ui_textbox("lrhost_$i", $rh, 8),
156                         &ui_textbox("lrport_$i", $rp, 8) ]);
157         $i++;
158         }
159 print &ui_table_row($text{'host_lforward'},
160         &ui_columns_table([ $text{'host_llport'}, $text{'host_lrhost'},
161                             $text{'host_lrport'} ],
162                           50, \@ltable));
163
164 print &ui_table_hr();
165
166 # Remote ports to forward
167 @rforward = &find("RemoteForward", $conf);
168 @rtable = ( );
169 $i = 0;
170 foreach $r (@rforward, { }) {
171         local ($rp, $lh, $lp) = ( $r->{'values'}->[0],
172                                   split(/:/, $r->{'values'}->[1]) );
173         push(@rtable, [ &ui_textbox("rrport_$i", $rp, 8),
174                         &ui_textbox("rlhost_$i", $lh, 40),
175                         &ui_textbox("rlport_$i", $lp, 8) ]);
176         $i++;
177         }
178 print &ui_table_row($text{'host_rforward'},
179         &ui_columns_table([ $text{'host_rrport'}, $text{'host_rlhost'},
180                             $text{'host_rlport'} ],
181                           50, \@rtable));
182
183 print &ui_table_end();
184 if ($in{'new'}) {
185         print &ui_form_end([ [ undef, $text{'create'} ] ]);
186         }
187 else {
188         print &ui_form_end([ [ undef, $text{'save'} ],
189                              [ 'delete', $text{'delete'} ] ]);
190         }
191
192 &ui_print_footer("list_hosts.cgi", $text{'hosts_return'},
193                  "", $text{'index_return'});
194