]>
Commit | Line | Data |
---|---|---|
ac1cfefa MT |
1 | #!/usr/bin/perl |
2 | # | |
3 | # SmoothWall CGIs | |
4 | # | |
5 | # This code is distributed under the terms of the GPL | |
6 | # | |
7 | # (c) The SmoothWall Team | |
8 | # | |
9 | # $Id: remote.cgi,v 1.6.2.8 2005/02/22 22:21:56 gespinasse Exp $ | |
10 | # | |
11 | ||
12 | use strict; | |
13 | ||
14 | # enable only the following on debugging purpose | |
15 | #use warnings; | |
16 | #use CGI::Carp 'fatalsToBrowser'; | |
17 | ||
986e08d9 | 18 | require '/var/ipfire/general-functions.pl'; |
ac1cfefa MT |
19 | require "${General::swroot}/lang.pl"; |
20 | require "${General::swroot}/header.pl"; | |
21 | ||
22 | my %remotesettings=(); | |
23 | my %checked=(); | |
24 | my $errormessage=''; | |
113cd628 | 25 | my $counter = 0; |
ac1cfefa MT |
26 | |
27 | &Header::showhttpheaders(); | |
28 | ||
29 | $remotesettings{'ENABLE_SSH'} = 'off'; | |
30 | $remotesettings{'ENABLE_SSH_PROTOCOL1'} = 'off'; | |
31 | $remotesettings{'ENABLE_SSH_PORTFW'} = 'off'; | |
32 | $remotesettings{'ACTION'} = ''; | |
33 | &Header::getcgihash(\%remotesettings); | |
34 | ||
05c71989 | 35 | if ( (($remotesettings{'ACTION'} eq $Lang::tr{'save'}) || ($remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart15'}) || ($remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart30'})) && $remotesettings{'ACTION'} ne "" ) |
ac1cfefa MT |
36 | { |
37 | # not existing here indicates the box is unticked | |
38 | $remotesettings{'ENABLE_SSH_PASSWORDS'} = 'off' unless exists $remotesettings{'ENABLE_SSH_PASSWORDS'}; | |
39 | $remotesettings{'ENABLE_SSH_KEYS'} = 'off' unless exists $remotesettings{'ENABLE_SSH_KEYS'}; | |
40 | ||
41 | ||
42 | &General::writehash("${General::swroot}/remote/settings", \%remotesettings); | |
43 | if ($remotesettings{'ENABLE_SSH'} eq 'on') | |
44 | { | |
45 | &General::log($Lang::tr{'ssh is enabled'}); | |
46 | if ($remotesettings{'ENABLE_SSH_PASSWORDS'} eq 'off' | |
47 | and $remotesettings{'ENABLE_SSH_KEYS'} eq 'off') | |
48 | { | |
49 | $errormessage = $Lang::tr{'ssh no auth'}; | |
50 | } | |
9833e7d8 | 51 | system ('/usr/bin/touch', "${General::swroot}/remote/enablessh"); |
ac1cfefa MT |
52 | } |
53 | else | |
54 | { | |
55 | &General::log($Lang::tr{'ssh is disabled'}); | |
56 | unlink "${General::swroot}/remote/enablessh"; | |
57 | } | |
58 | ||
59 | if ($remotesettings{'ENABLE_SSH_PROTOCOL1'} eq 'on') | |
60 | { | |
61 | &General::log($Lang::tr{'ssh1 enabled'}); | |
62 | } | |
63 | else | |
64 | { | |
65 | &General::log($Lang::tr{'ssh1 disabled'}); | |
66 | } | |
113cd628 CS |
67 | if ( $remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart15'} || $remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart30'} ){ |
68 | if ($remotesettings{'ENABLE_SSH'} eq 'off') | |
69 | { | |
70 | system ('/usr/bin/touch', "${General::swroot}/remote/enablessh"); | |
71 | system('/usr/local/bin/sshctrl'); | |
72 | } | |
73 | if ( $remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart15'} ) { $counter = 900;} | |
74 | elsif ( $remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart30'} ) { $counter = 1800;} | |
75 | ||
76 | system("/usr/local/bin/sshctrl tempstart $counter >/dev/null"); | |
70db8683 CS |
77 | } |
78 | else { | |
900832fa | 79 | system('/usr/local/bin/sshctrl') == 0 |
ac1cfefa | 80 | or $errormessage = "$Lang::tr{'bad return code'} " . $?/256; |
70db8683 | 81 | } |
ac1cfefa MT |
82 | } |
83 | ||
84 | &General::readhash("${General::swroot}/remote/settings", \%remotesettings); | |
85 | ||
86 | # not existing here means they're undefined and the default value should be | |
87 | # used | |
88 | $remotesettings{'ENABLE_SSH_PASSWORDS'} = 'on' unless exists $remotesettings{'ENABLE_SSH_PASSWORDS'}; | |
89 | $remotesettings{'ENABLE_SSH_KEYS'} = 'on' unless exists $remotesettings{'ENABLE_SSH_KEYS'}; | |
90 | ||
91 | $checked{'ENABLE_SSH'}{'off'} = ''; | |
92 | $checked{'ENABLE_SSH'}{'on'} = ''; | |
93 | $checked{'ENABLE_SSH'}{$remotesettings{'ENABLE_SSH'}} = "checked='checked'"; | |
94 | $checked{'ENABLE_SSH_PROTOCOL1'}{'off'} = ''; | |
95 | $checked{'ENABLE_SSH_PROTOCOL1'}{'on'} = ''; | |
96 | $checked{'ENABLE_SSH_PROTOCOL1'}{$remotesettings{'ENABLE_SSH_PROTOCOL1'}} = "checked='checked'"; | |
97 | $checked{'ENABLE_SSH_PORTFW'}{'off'} = ''; | |
98 | $checked{'ENABLE_SSH_PORTFW'}{'on'} = ''; | |
99 | $checked{'ENABLE_SSH_PORTFW'}{$remotesettings{'ENABLE_SSH_PORTFW'}} = "checked='checked'"; | |
100 | $checked{'ENABLE_SSH_PASSWORDS'}{'off'} = ''; | |
101 | $checked{'ENABLE_SSH_PASSWORDS'}{'on'} = ''; | |
102 | $checked{'ENABLE_SSH_PASSWORDS'}{$remotesettings{'ENABLE_SSH_PASSWORDS'}} = "checked='checked'"; | |
103 | $checked{'ENABLE_SSH_KEYS'}{'off'} = ''; | |
104 | $checked{'ENABLE_SSH_KEYS'}{'on'} = ''; | |
105 | $checked{'ENABLE_SSH_KEYS'}{$remotesettings{'ENABLE_SSH_KEYS'}} = "checked='checked'"; | |
106 | ||
107 | ||
108 | &Header::openpage($Lang::tr{'remote access'}, 1, ''); | |
109 | ||
110 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
111 | ||
112 | if ($errormessage) { | |
113 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); | |
114 | print "<FONT CLASS='base'>$errormessage </FONT>\n"; | |
115 | &Header::closebox(); | |
116 | } | |
117 | ||
118 | print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n"; | |
119 | ||
120 | &Header::openbox('100%', 'left', 'SSH:'); | |
121 | print <<END | |
122 | <table width='100%'> | |
123 | <tr> | |
124 | <td><input type='checkbox' name='ENABLE_SSH' $checked{'ENABLE_SSH'}{'on'} /></td> | |
125 | <td class='base' colspan='2'>$Lang::tr{'ssh access'}</td> | |
126 | </tr> | |
127 | <tr> | |
128 | <td> </td> | |
129 | <td><input type='checkbox' name='ENABLE_SSH_PROTOCOL1' $checked{'ENABLE_SSH_PROTOCOL1'}{'on'} /></td> | |
130 | <td width='100%' class='base'>$Lang::tr{'ssh1 support'}</td> | |
131 | </tr> | |
132 | <tr> | |
133 | <td> </td> | |
134 | <td><input type='checkbox' name='ENABLE_SSH_PORTFW' $checked{'ENABLE_SSH_PORTFW'}{'on'} /></td> | |
135 | <td width='100%' class='base'>$Lang::tr{'ssh portfw'}</td> | |
136 | </tr> | |
137 | <tr> | |
138 | <td> </td> | |
139 | <td><input type='checkbox' name='ENABLE_SSH_PASSWORDS' $checked{'ENABLE_SSH_PASSWORDS'}{'on'} /></td> | |
140 | <td width='100%' class='base'>$Lang::tr{'ssh passwords'}</td> | |
141 | </tr> | |
142 | <tr> | |
143 | <td> </td> | |
144 | <td><input type='checkbox' name='ENABLE_SSH_KEYS' $checked{'ENABLE_SSH_KEYS'}{'on'} /></td> | |
145 | <td width='100%' class='base'>$Lang::tr{'ssh keys'}</td> | |
146 | </tr> | |
147 | <tr> | |
bba7212c MT |
148 | <td align='center' colspan='3'><hr /> |
149 | <input type='submit' name='ACTION' value='$Lang::tr{'ssh tempstart15'}' /> | |
150 | <input type='submit' name='ACTION' value='$Lang::tr{'ssh tempstart30'}' /> | |
151 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td> | |
ac1cfefa MT |
152 | </tr> |
153 | </table> | |
154 | END | |
155 | ; | |
156 | &Header::closebox(); | |
157 | ||
158 | print "</form>\n"; | |
159 | ||
160 | &Header::openbox('100%', 'left', $Lang::tr{'ssh host keys'}); | |
161 | ||
162 | print "<table>\n"; | |
163 | ||
164 | print <<END | |
165 | <tr><td class='boldbase'><b>$Lang::tr{'ssh key'}</b></td> | |
166 | <td class='boldbase'><b>$Lang::tr{'ssh fingerprint'}</b></td> | |
167 | <td class='boldbase'><b>$Lang::tr{'ssh key size'}</b></td></tr> | |
168 | END | |
169 | ; | |
170 | ||
171 | &viewkey("/etc/ssh/ssh_host_key.pub","RSA1"); | |
172 | &viewkey("/etc/ssh/ssh_host_rsa_key.pub","RSA2"); | |
173 | &viewkey("/etc/ssh/ssh_host_dsa_key.pub","DSA"); | |
174 | ||
175 | print "</table>\n"; | |
176 | ||
177 | &Header::closebox(); | |
178 | ||
179 | &Header::closebigbox(); | |
180 | ||
181 | &Header::closepage(); | |
182 | ||
183 | ||
184 | sub viewkey | |
185 | { | |
186 | my $key = $_[0]; | |
187 | my $name = $_[1]; | |
188 | ||
189 | if ( -e $key ) | |
190 | { | |
191 | my @temp = split(/ /,`/usr/bin/ssh-keygen -l -f $key`); | |
192 | my $keysize = &Header::cleanhtml($temp[0],"y"); | |
193 | my $fingerprint = &Header::cleanhtml($temp[1],"y"); | |
194 | print "<tr><td>$key ($name)</td><td><code>$fingerprint</code></td><td align='center'>$keysize</td></tr>\n"; | |
195 | } | |
196 | } |