]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/index.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2012 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
25 # enable only the following on debugging purpose
27 #use CGI::Carp 'fatalsToBrowser';
29 require '/var/ipfire/general-functions.pl' ;
30 require "${General::swroot}/lang.pl" ;
31 require "${General::swroot}/header.pl" ;
32 require "/opt/pakfire/lib/functions.pl" ;
46 & Header
:: showhttpheaders
();
48 $cgiparams { 'ACTION' } = '' ;
49 & Header
:: getcgihash
( \
%cgiparams );
50 $pppsettings { 'VALID' } = '' ;
51 $pppsettings { 'PROFILENAME' } = 'None' ;
52 & General
:: readhash
( "${General::swroot}/ppp/settings" , \
%pppsettings );
53 & General
:: readhash
( "${General::swroot}/modem/settings" , \
%modemsettings );
54 & General
:: readhash
( "${General::swroot}/ethernet/settings" , \
%netsettings );
55 & General
:: readhash
( "${General::swroot}/ddns/settings" , \
%ddnssettings );
58 my %mainsettings = ();
59 & General
:: readhash
( "${General::swroot}/main/settings" , \
%mainsettings );
60 & General
:: readhash
( "/srv/web/ipfire/html/themes/" . $mainsettings { 'THEME' }. "/include/colors.txt" , \
%color );
62 my $connstate = & Header
:: connectionstatus
();
64 if ( - e
"/var/ipfire/main/gpl-accepted" ) {
65 if ( $connstate =~ /$Lang::tr{'connecting'}/ || /$Lang::tr{'connection closed'}/ ){
66 $refresh = "<meta http-equiv='refresh' content='5;'>" ;
67 } elsif ( $connstate =~ /$Lang::tr{'dod waiting'}/ || - e
"${General::swroot}/main/refreshindex" ) {
68 $refresh = "<meta http-equiv='refresh' content='30;'>" ;
72 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dial profile' })
74 my $profile = $cgiparams { 'PROFILE' };
75 my %tempcgiparams = ();
76 $tempcgiparams { 'PROFILE' } = '' ;
77 & General
:: readhash
( "${General::swroot}/ppp/settings- $cgiparams {'PROFILE'}" ,
80 # make a link from the selected profile to the "default" one.
81 unlink ( "${General::swroot}/ppp/settings" );
82 link ( "${General::swroot}/ppp/settings- $cgiparams {'PROFILE'}" ,
83 "${General::swroot}/ppp/settings" );
84 system ( "/usr/bin/touch" , "${General::swroot}/ppp/updatesettings" );
86 # read in the new params "early" so we can write secrets.
88 & General
:: readhash
( "${General::swroot}/ppp/settings" , \
%cgiparams );
89 $cgiparams { 'PROFILE' } = $profile ;
90 $cgiparams { 'BACKUPPROFILE' } = $profile ;
91 & General
:: writehash
( "${General::swroot}/ppp/settings- $cgiparams {'PROFILE'}" ,
95 open ( FILE
, ">/${General::swroot}/ppp/secrets" ) or die "Unable to write secrets file." ;
97 my $username = $cgiparams { 'USERNAME' };
98 my $password = $cgiparams { 'PASSWORD' };
99 print FILE
"' $username ' * ' $password ' \n " ;
100 chmod 0600 , "${General::swroot}/ppp/secrets" ;
103 & General
:: log ( " $Lang ::tr{'profile made current'} $tempcgiparams {'PROFILENAME'}" );
104 $cgiparams { 'ACTION' } = " $Lang ::tr{'dial'}" ;
107 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'dial' }) {
108 system ( '/usr/local/bin/redctrl start > /dev/null' ) == 0
109 or & General
:: log ( "Dial failed: $?" ); sleep 1 ;}
110 elsif ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'hangup' }) {
111 system ( '/usr/local/bin/redctrl stop > /dev/null' ) == 0
112 or & General
:: log ( "Hangup failed: $?" ); sleep 1 ;}
116 my @profilenames = ();
118 for ( $c = 1 ; $c <= $maxprofiles ; $c ++)
120 my %temppppsettings = ();
121 $temppppsettings { 'PROFILENAME' } = '' ;
122 & General
:: readhash
( "${General::swroot}/ppp/settings- $c " , \
%temppppsettings );
123 $profilenames [ $c ] = $temppppsettings { 'PROFILENAME' };
126 for ( $c = 1 ; $c <= $maxprofiles ; $c ++) {
127 $selected { 'PROFILE' }{ $c } = '' ;
129 $selected { 'PROFILE' }{ $pppsettings { 'PROFILE' }} = "selected='selected'" ;
130 my $dialButtonDisabled = "disabled='disabled'" ;
133 & Header
:: openpage
( $Lang :: tr
{ 'main page' }, 1 , $refresh );
134 & Header
:: openbigbox
( '' , 'center' );
137 if ( $cgiparams { 'ACTION' } eq $Lang :: tr
{ 'yes' } && $cgiparams { 'gpl_accepted' } eq '1' ) {
138 system ( 'touch /var/ipfire/main/gpl_accepted' )
140 if ( - e
"/var/ipfire/main/gpl_accepted" ) {
141 & Header
:: openbox
( '100%' , 'center' , '' );
144 if ( ( $pppsettings { 'VALID' } eq 'yes' && $modemsettings { 'VALID' } eq 'yes' ) || ( $netsettings { 'CONFIG_TYPE' } =~ /^(1|2|3|4)$/ && $netsettings { 'RED_TYPE' } =~ /^(DHCP|STATIC)$/ )) {
145 if ( open ( IPADDR
, "${General::swroot}/ddns/ipcache" )) {
150 if ( open ( IPADDR
, "${General::swroot}/red/local-ipaddress" )) {
155 } elsif ( $modemsettings { 'VALID' } eq 'no' ) {
156 print " $Lang ::tr{'modem settings have errors'} \n </b></font> \n " ;
158 print " $Lang ::tr{'profile has errors'} \n </b></font> \n " ;
162 <!-- Table of networks -->
163 <table width=80% class='tbl'>
164 <tr> <th bgcolor=' $color {'color20'}'> $Lang ::tr{'network'}</th>
165 <th bgcolor=' $color {'color20'}'>IP</th>
166 <th bgcolor=' $color {'color20'}'> $Lang ::tr{'status'}</th></tr>
167 <tr> <td align='center' bgcolor=' $Header ::colourred' width='25%'><a href="/cgi-bin/pppsetup.cgi"><font size='2' color='white'><b> $Lang ::tr{'internet'}</b></font></a><br></td>
168 <td width='30%' align='center'> $ipaddr </td>
169 <td width='45%' align='center'> $connstate
171 my $HOSTNAME = ( gethostbyaddr ( pack ( "C4" , split ( /\./ , $ipaddr )), 2 ))[ 0 ];
172 if ( " $HOSTNAME " ne "" ) {
174 <tr><td><b>Hostname:</b><td align='center'> $HOSTNAME <td>
178 if ( - e
"/var/ipfire/red/remote-ipaddress" ) {
179 my $GATEWAY = `cat /var/ipfire/red/remote-ipaddress` ;
182 <tr><td><b>Gateway:</b><td align='center'> $GATEWAY <td>
186 my $DNS1 = `cat /var/ipfire/red/dns1` ;
187 my $DNS2 = `cat /var/ipfire/red/dns2` ;
191 if ( $DNS1 ) { print <<END;
192 <tr><td><b>DNS-Server:</b><td align='center'> $DNS1
195 if ( $DNS2 ) { print <<END;
196 <td align='center'> $DNS2
198 } else { print <<END;
206 if ( $netsettings { 'RED_TYPE' } ne "STATIC" && $netsettings { 'RED_TYPE' } ne "DHCP" ){
207 print `/usr/local/bin/dialctrl.pl show` ;
212 <form method='post' action=' $ENV {'SCRIPT_NAME'}'> $Lang ::tr{'profile'}:
213 <select name='PROFILE'>
215 for ( $c = 1 ; $c <= $maxprofiles ; $c ++)
217 if ( $profilenames [ $c ] ne '' ) {
218 $dialButtonDisabled = "" ;
219 print " \t <option value=' $c ' $selected {'PROFILE'}{ $c }> $c . $profilenames [ $c ]</option> \n " ;
222 $dialButtonDisabled = "disabled='disabled'" if (- e
'/var/run/ppp-ipfire.pid' || - e
"${General::swroot}/red/active" );
223 if ( ( $pppsettings { 'VALID' } eq 'yes' ) || ( $netsettings { 'CONFIG_TYPE' } =~ /^(1|2|3|4)$/ && $netsettings { 'RED_TYPE' } =~ /^(DHCP|STATIC)$/ ) ) {
226 <input type='submit' name='ACTION' value=' $Lang ::tr{'dial profile'}' $dialButtonDisabled />
229 <table width='100%' border='0'>
231 <td width='50%' align='right'> <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
232 <input type='submit' name='ACTION' value=' $Lang ::tr{'dial'}'>
234 <td width='50%' align='left'> <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
235 <input type='submit' name='ACTION' value=' $Lang ::tr{'hangup'}'>
240 print " $Lang ::tr{'profile has errors'} \n </b></font> \n " ;
242 print "</tr></table>" ;
244 if ( $netsettings { 'GREEN_DEV' } ) {
245 my $sub =& General
:: iporsubtocidr
( $netsettings { 'GREEN_NETMASK' });
248 <table width='80%' class='tbl'>
250 <th> $Lang ::tr{'network'}</th>
252 <th> $Lang ::tr{'status'}</th>
254 <tr><td align='center' bgcolor=' $Header ::colourgreen' width='25%'><a href="/cgi-bin/dhcp.cgi"><font size='2' color='white'><b> $Lang ::tr{'lan'}</b></font></a>
255 <td width='30%' align='center'> $netsettings {'GREEN_ADDRESS'}/ $sub
256 <td width='45%' align='center'>
258 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE=on` ) {
259 print $Lang :: tr
{ 'advproxy on' };
260 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT=on` ) { print " (transparent)" ; }
261 } else { print $Lang :: tr
{ 'advproxy off' }; }
263 if ( $netsettings { 'BLUE_DEV' } ) {
264 my $sub =& General
:: iporsubtocidr
( $netsettings { 'BLUE_NETMASK' });
266 <tr><td align='center' bgcolor=' $Header ::colourblue' width='25%'><a href="/cgi-bin/wireless.cgi"><font size='2' color='white'><b> $Lang ::tr{'wireless'}</b></font></a><br>
267 <td width='30%' align='center'> $netsettings {'BLUE_ADDRESS'}/ $sub
268 <td width='45%' align='center'>
270 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^ENABLE_BLUE=on` ) {
271 print $Lang :: tr
{ 'advproxy on' };
272 if ( `cat /var/ipfire/proxy/advanced/settings | grep ^TRANSPARENT_BLUE=on` ) { print " (transparent)" ; }
273 } else { print $Lang :: tr
{ 'advproxy off' }; }
275 if ( $netsettings { 'ORANGE_DEV' } ) {
276 my $sub =& General
:: iporsubtocidr
( $netsettings { 'ORANGE_NETMASK' });
278 <tr><td align='center' bgcolor=' $Header ::colourorange' width='25%'><a href="/cgi-bin/firewall.cgi"><font size='2' color='white'><b> $Lang ::tr{'dmz'}</b></font></a><br>
279 <td width='30%' align='center'> $netsettings {'ORANGE_ADDRESS'}/ $sub
280 <td width='45%' align='center'><font color= $Header ::colourgreen>Online</font>
283 #check if IPSEC is running
284 if ( `cat /var/ipfire/vpn/settings | grep ^ENABLED=on` ||
285 `cat /var/ipfire/vpn/settings | grep ^ENABLED_BLUE=on` ) {
287 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-` ;
289 <tr><td align='center' bgcolor=' $Header ::colourvpn' width='25%'><a href="/cgi-bin/vpnmain.cgi"><font size='2' color='white'><b> $Lang ::tr{'vpn'}</b></font></a><br>
290 <td width='30%' align='center'> $ipsecip
291 <td width='45%' align='center'><font color= $Header ::colourgreen>Online</font>
295 #check if OpenVPN is running
297 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%confighash );
299 if (( $confighash { 'ENABLED' } eq "on" ) ||
300 ( $confighash { 'ENABLED_BLUE' } eq "on" ) ||
301 ( $confighash { 'ENABLED_ORANGE' } eq "on" )) {
302 my ( $ovpnip , $sub ) = split ( "/" , $confighash { 'DOVPN_SUBNET' });
303 $sub =& General
:: iporsubtocidr
( $sub );
304 $ovpnip = " $ovpnip / $sub " ;
308 <td align='center' bgcolor=' $Header ::colourovpn' width='25%'>
309 <a href="/cgi-bin/ovpnmain.cgi"><font size='2' color='white'><b>OpenVPN</b></font></a><br>
311 <td width='30%' align='center'> $ovpnip
312 <td width='45%' align='center'><font color= $Header ::colourgreen>Online</font>
315 print "</td></tr></table>" ;
318 # Start of Box wich contains all vpn connections
319 & Header
:: openbox
( '100%' , 'center' , $Lang :: tr
{ 'vpn' }) if ( $haveipsec || $haveovpn );
321 #show ipsec connectiontable
323 my $ipsecip = `cat /var/ipfire/vpn/settings | grep ^VPN_IP= | cut -c 8-` ;
324 my @status = `/usr/local/bin/ipsecctrl I` ;
326 & General
:: readhasharray
( "${General::swroot}/vpn/config" , \
%confighash );
329 <table width='80%' class='tbl'>
331 <th> $Lang ::tr{'ipsec network'}</th>
333 <th> $Lang ::tr{'status'}</th>
339 foreach my $key ( sort { uc ( $confighash { $a }[ 1 ]) cmp uc ( $confighash { $b }[ 1 ]) } keys %confighash ) {
340 if ( $confighash { $key }[ 0 ] eq 'on' ) { $gif = 'on.gif' ; } else { $gif = 'off.gif' ; }
343 $col = "bgcolor=' $color {'color20'}'" ;
344 print "<tr><td align='left' nowrap='nowrap' bgcolor=' $Header ::colourvpn' width='50%'><font color=white> $confighash { $key }[1] / " . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td><td align='center' $col > $confighash { $key }[11]</td>" ;
346 $col = "bgcolor=' $color {'color22'}'" ;
347 print "<tr></td><td align='left' nowrap='nowrap' bgcolor=' $Header ::colourvpn' width='50%'><font color=white> $confighash { $key }[1] / " . $Lang :: tr
{ " $confighash { $key }[3]" } . " (" . $Lang :: tr
{ " $confighash { $key }[4]" } . ")</td><td align='center' $col > $confighash { $key }[11]</td>" ;
350 my $active = "<td bgcolor='${Header::colourred}' width='15%' align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b></td>" ;
351 if ( $confighash { $key }[ 0 ] eq 'off' ) {
352 $active = "<td bgcolor='${Header::colourblue}' width='15%' align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsclosed'}</font></b></td>" ;
354 foreach my $line ( @status ) {
355 if (( $line =~ /\"$confighash{$key}[1]\".*IPsec SA established/ ) ||
356 ( $line =~ /$confighash{$key}[1]\{.*INSTALLED/ ))
358 $active = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='100%'><tr><td align='center'><b><font color='#FFFFFF'> $Lang ::tr{'capsopen'}</font></b></td></tr></table>" ;
362 print " $active </td>" ;
364 print "</tr></table>" ;
368 # Check if there is any OpenVPN connection configured.
375 <table width='80%' class='tbl'>
377 <th> $Lang ::tr{'openvpn network'}</th>
379 <th> $Lang ::tr{'status'}</th>
381 # Check if the OpenVPN server for Road Warrior Connections is running and display status information.
384 & General
:: readhash
( "${General::swroot}/ovpn/settings" , \
%confighash );
385 # Print the OpenVPN N2N connection status.
386 if ( - d
"${General::swroot}/ovpn/n2nconf" ) {
389 & General
:: readhasharray
( "${General::swroot}/ovpn/ovpnconfig" , \
%confighash );
392 foreach my $dkey ( keys %confighash ) {
394 if (( $confighash { $dkey }[ 3 ] eq 'net' ) && (- e
"/var/run/ $confighash { $dkey }[1]n2n.pid" )) {
395 my $tport = $confighash { $dkey }[ 22 ];
396 next if ( $tport eq '' );
398 my $tnet = new Net
:: Telnet
( Timeout
=> 5 , Errmode
=> 'return' , Port
=> $tport );
399 $tnet -> open ( '127.0.0.1' );
400 my @output = $tnet -> cmd ( String
=> 'state' , Prompt
=> '/(END.* \n |ERROR:.* \n )/' );
401 my @tustate = split ( /\,/ , $output [ 1 ]);
404 my $display_colour = $Header :: colourred
;
405 if ( $tustate [ 1 ] eq 'CONNECTED' ) {
406 $display_colour = $Header :: colourgreen
;
407 $display = $Lang :: tr
{ 'capsopen' };
409 $display = $tustate [ 1 ];
412 $col = "bgcolor=' $color {'color20'}'" ;
414 $col = "bgcolor=' $color {'color22'}'" ;
418 <td align='left' nowrap='nowrap' bgcolor=' $Header ::colourovpn' width='50%'><font color=white>
419 $confighash { $dkey }[1]
421 <td align='center' $col >
422 $confighash { $dkey }[11]
424 <td align='center' bgcolor=' $display_colour ' width='15%'>
426 <font color='#FFFFFF'>
439 if ( ! - e
"/var/ipfire/main/send_profile" ) {
440 $warnmessage .= "<li><a style='color: white;' href='fireinfo.cgi'> $Lang ::tr{'fireinfo please enable'}</a></li>" ;
443 # Memory usage warning
444 my @free = `/usr/bin/free` ;
445 $free [ 1 ] =~ m/(\d+)/ ;
447 $free [ 2 ] =~ m/(\d+)/ ;
449 my $pct = int 100 * ( $mem - $used ) / $mem ;
450 if ( $used / $mem > 90 ) {
451 $warnmessage .= "<li> $Lang ::tr{'high memory usage'}: $pct % !</li> \n " ;
454 # Diskspace usage warning
457 my @df = `/bin/df -B M -P -x rootfs` ;
458 foreach my $line ( @df ) {
459 next if $line =~ m/^Filesystem/ ;
460 if ( $line =~ m/root/ ) {
461 $line =~ m/^.* (\d+)M.*$/ ;
462 @temp = split ( / +/ , $line );
464 # available:plain value in MB, and not %used as 10% is too much to waste on small disk
465 # and root size should not vary during time
466 $warnmessage .= "<li> $Lang ::tr{'filesystem full'}: $temp [0] <b> $Lang ::tr{'free'}= $1M </b> !</li> \n " ;
470 # $line =~ m/^.* (\d+)m.*$/;
471 $line =~ m/^.* (\d+)\%.*$/ ;
473 @temp = split ( / / , $line );
475 $warnmessage .= "<li> $Lang ::tr{'filesystem full'}: $temp [0] <b> $Lang ::tr{'free'}= $temp2 %</b> !</li> \n " ;
480 # S.M.A.R.T. health warning
481 my @files = `/bin/ls /var/run/smartctl_out_hddtemp-* 2>/dev/null` ;
482 foreach my $file ( @files ) {
484 my $disk = `echo $file | cut -d"-" -f2` ;
486 if ( `/bin/grep "SAVE ALL DATA" $file ` ) {
487 $warnmessage .= "<li> $Lang ::tr{'smartwarn1'} /dev/ $disk $Lang ::tr{'smartwarn2'} !</li> \n\n " ;
492 my @files = `mount | grep " reiser4 (" 2>/dev/null` ;
493 foreach my $disk ( @files ) {
495 $warnmessage .= "<li> $disk - $Lang ::tr{'deprecated fs warn'}</li> \n\n " ;
500 print "<tr><td align='center' bgcolor= $Header ::colourred colspan='3'><font color='white'> $warnmessage </font></table>" ;
506 & Pakfire
:: dblist
( "upgrade" , "notice" );
509 if ( - e
"/var/run/need_reboot" ) {
510 print "<br /><br /><font color='red'> $Lang ::tr{'needreboot'}!</font>" ;
516 & Header
:: openbox
( '100%' , 'left' , $Lang :: tr
{ 'gpl license agreement' });
518 $Lang ::tr{'gpl please read carefully the general public license and accept it below'}.
522 if ( - e
"/usr/share/doc/licenses/GPLv3" ) {
523 print '<textarea rows= \' 25 \' cols= \' 75 \' readonly= \' true \' >' ;
524 print `cat /usr/share/doc/licenses/GPLv3` ;
528 print '<br /><a href= \' http://www.gnu.org/licenses/gpl-3.0.txt \' target= \' _blank \' >GNU GENERAL PUBLIC LICENSE</a><br />' ;
532 <form method='post' action=' $ENV {'SCRIPT_NAME'}'>
533 <input type='checkbox' name='gpl_accepted' value='1'/> $Lang ::tr{'gpl i accept these terms and conditions'}.
535 <input type='submit' name='ACTION' value= $Lang ::tr{'yes'} />
538 <a href='http://www.gnu.org/licenses/translations.html' target='_blank'> $Lang ::tr{'gpl unofficial translation of the general public license v3'}</a>
545 & Header
:: closebigbox
();
546 & Header
:: closepage
();