]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/remote.cgi
setup: add nic identify function.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / remote.cgi
CommitLineData
ac1cfefa 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
abcbbd1f 5# Copyright (C) 2007-2011 IPFire Team <info@ipfire.org> #
70df8302
MT
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
ac1cfefa
MT
21
22use strict;
23
24# enable only the following on debugging purpose
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
27
986e08d9 28require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
31
32my %remotesettings=();
33my %checked=();
34my $errormessage='';
113cd628 35my $counter = 0;
ac1cfefa
MT
36
37&Header::showhttpheaders();
38
39$remotesettings{'ENABLE_SSH'} = 'off';
ac1cfefa
MT
40$remotesettings{'ENABLE_SSH_PORTFW'} = 'off';
41$remotesettings{'ACTION'} = '';
42&Header::getcgihash(\%remotesettings);
43
05c71989 44if ( (($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
45{
46 # not existing here indicates the box is unticked
47 $remotesettings{'ENABLE_SSH_PASSWORDS'} = 'off' unless exists $remotesettings{'ENABLE_SSH_PASSWORDS'};
48 $remotesettings{'ENABLE_SSH_KEYS'} = 'off' unless exists $remotesettings{'ENABLE_SSH_KEYS'};
49
50
51 &General::writehash("${General::swroot}/remote/settings", \%remotesettings);
52 if ($remotesettings{'ENABLE_SSH'} eq 'on')
53 {
54 &General::log($Lang::tr{'ssh is enabled'});
55 if ($remotesettings{'ENABLE_SSH_PASSWORDS'} eq 'off'
56 and $remotesettings{'ENABLE_SSH_KEYS'} eq 'off')
57 {
58 $errormessage = $Lang::tr{'ssh no auth'};
59 }
9833e7d8 60 system ('/usr/bin/touch', "${General::swroot}/remote/enablessh");
ac1cfefa
MT
61 }
62 else
63 {
64 &General::log($Lang::tr{'ssh is disabled'});
65 unlink "${General::swroot}/remote/enablessh";
66 }
6624878a
JPT
67
68 if ($remotesettings{'SSH_PORT'} eq 'on')
69 {
70 &General::log("SSH Port 22");
71 }
72 else
73 {
74 &General::log("SSH Port 222");
75 }
76
113cd628
CS
77if ( $remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart15'} || $remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart30'} ){
78 if ($remotesettings{'ENABLE_SSH'} eq 'off')
79 {
80 system ('/usr/bin/touch', "${General::swroot}/remote/enablessh");
81 system('/usr/local/bin/sshctrl');
82 }
83 if ( $remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart15'} ) { $counter = 900;}
84 elsif ( $remotesettings{'ACTION'} eq $Lang::tr{'ssh tempstart30'} ) { $counter = 1800;}
85
86 system("/usr/local/bin/sshctrl tempstart $counter >/dev/null");
70db8683
CS
87 }
88else {
900832fa 89 system('/usr/local/bin/sshctrl') == 0
ac1cfefa 90 or $errormessage = "$Lang::tr{'bad return code'} " . $?/256;
70db8683 91 }
ac1cfefa
MT
92}
93
94&General::readhash("${General::swroot}/remote/settings", \%remotesettings);
95
96# not existing here means they're undefined and the default value should be
97# used
98 $remotesettings{'ENABLE_SSH_PASSWORDS'} = 'on' unless exists $remotesettings{'ENABLE_SSH_PASSWORDS'};
99 $remotesettings{'ENABLE_SSH_KEYS'} = 'on' unless exists $remotesettings{'ENABLE_SSH_KEYS'};
100
101$checked{'ENABLE_SSH'}{'off'} = '';
102$checked{'ENABLE_SSH'}{'on'} = '';
103$checked{'ENABLE_SSH'}{$remotesettings{'ENABLE_SSH'}} = "checked='checked'";
ac1cfefa
MT
104$checked{'ENABLE_SSH_PORTFW'}{'off'} = '';
105$checked{'ENABLE_SSH_PORTFW'}{'on'} = '';
106$checked{'ENABLE_SSH_PORTFW'}{$remotesettings{'ENABLE_SSH_PORTFW'}} = "checked='checked'";
107$checked{'ENABLE_SSH_PASSWORDS'}{'off'} = '';
108$checked{'ENABLE_SSH_PASSWORDS'}{'on'} = '';
109$checked{'ENABLE_SSH_PASSWORDS'}{$remotesettings{'ENABLE_SSH_PASSWORDS'}} = "checked='checked'";
110$checked{'ENABLE_SSH_KEYS'}{'off'} = '';
111$checked{'ENABLE_SSH_KEYS'}{'on'} = '';
112$checked{'ENABLE_SSH_KEYS'}{$remotesettings{'ENABLE_SSH_KEYS'}} = "checked='checked'";
6624878a
JPT
113$checked{'SSH_PORT'}{'off'} = '';
114$checked{'SSH_PORT'}{'on'} = '';
115$checked{'SSH_PORT'}{$remotesettings{'SSH_PORT'}} = "checked='checked'";
ac1cfefa
MT
116
117&Header::openpage($Lang::tr{'remote access'}, 1, '');
118
119&Header::openbigbox('100%', 'left', '', $errormessage);
120
121if ($errormessage) {
122 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
123 print "<FONT CLASS='base'>$errormessage&nbsp;</FONT>\n";
124 &Header::closebox();
125}
126
127print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
128
129&Header::openbox('100%', 'left', 'SSH:');
130print <<END
131<table width='100%'>
132<tr>
133 <td><input type='checkbox' name='ENABLE_SSH' $checked{'ENABLE_SSH'}{'on'} /></td>
134 <td class='base' colspan='2'>$Lang::tr{'ssh access'}</td>
135</tr>
ac1cfefa
MT
136<tr>
137 <td>&nbsp;</td>
138 <td><input type='checkbox' name='ENABLE_SSH_PORTFW' $checked{'ENABLE_SSH_PORTFW'}{'on'} /></td>
139 <td width='100%' class='base'>$Lang::tr{'ssh portfw'}</td>
140</tr>
141<tr>
142 <td>&nbsp;</td>
143 <td><input type='checkbox' name='ENABLE_SSH_PASSWORDS' $checked{'ENABLE_SSH_PASSWORDS'}{'on'} /></td>
144 <td width='100%' class='base'>$Lang::tr{'ssh passwords'}</td>
145</tr>
146<tr>
147 <td>&nbsp;</td>
148 <td><input type='checkbox' name='ENABLE_SSH_KEYS' $checked{'ENABLE_SSH_KEYS'}{'on'} /></td>
149 <td width='100%' class='base'>$Lang::tr{'ssh keys'}</td>
150</tr>
6624878a
JPT
151<tr>
152 <td>&nbsp;</td>
153 <td><input type='checkbox' name='SSH_PORT' $checked{'SSH_PORT'}{'on'} /></td>
154 <td width='100%' class='base'>$Lang::tr{'ssh port'}</td>
155</tr>
ac1cfefa 156<tr>
bba7212c
MT
157 <td align='center' colspan='3'><hr />
158 <input type='submit' name='ACTION' value='$Lang::tr{'ssh tempstart15'}' />
159 <input type='submit' name='ACTION' value='$Lang::tr{'ssh tempstart30'}' />
160 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
ac1cfefa
MT
161</tr>
162</table>
163END
164;
165&Header::closebox();
166
167print "</form>\n";
168
169&Header::openbox('100%', 'left', $Lang::tr{'ssh host keys'});
170
171print "<table>\n";
172
173print <<END
174<tr><td class='boldbase'><b>$Lang::tr{'ssh key'}</b></td>
175 <td class='boldbase'><b>$Lang::tr{'ssh fingerprint'}</b></td>
176 <td class='boldbase'><b>$Lang::tr{'ssh key size'}</b></td></tr>
177END
178;
179
180&viewkey("/etc/ssh/ssh_host_key.pub","RSA1");
181&viewkey("/etc/ssh/ssh_host_rsa_key.pub","RSA2");
182&viewkey("/etc/ssh/ssh_host_dsa_key.pub","DSA");
abcbbd1f 183&viewkey("/etc/ssh/ssh_host_ecdsa_key.pub","ECDSA");
ac1cfefa
MT
184
185print "</table>\n";
186
187&Header::closebox();
188
189&Header::closebigbox();
190
191&Header::closepage();
192
193
194sub viewkey
195{
196 my $key = $_[0];
197 my $name = $_[1];
198
199 if ( -e $key )
200 {
201 my @temp = split(/ /,`/usr/bin/ssh-keygen -l -f $key`);
202 my $keysize = &Header::cleanhtml($temp[0],"y");
203 my $fingerprint = &Header::cleanhtml($temp[1],"y");
204 print "<tr><td>$key ($name)</td><td><code>$fingerprint</code></td><td align='center'>$keysize</td></tr>\n";
205 }
206}