#!/usr/bin/perl # ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2017-2018 Stephan Feddersen # # All Rights Reserved. # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### # # Version: 2018/02/27 16:54:23 # # This wio.cgi is based on the Code from the IPCop WIO Addon # and is extremly adapted to work with IPFire. # # Autor: Stephan Feddersen # Co-Autor: Alexander Marx # Co-Autor: Frank Mainz # use strict; # enable only the following on debugging purpose #use warnings; #no warnings 'once'; #use CGI::Carp 'fatalsToBrowser'; my $debug = 0; use Socket; use POSIX qw(strftime); use File::Copy; use Fatal qw/ open /; use Net::Telnet; require '/var/ipfire/general-functions.pl'; require '/var/ipfire/network-functions.pl'; require '/var/ipfire/lang.pl'; require '/var/ipfire/header.pl'; require '/usr/lib/wio/wio-lib.pl'; require '/usr/lib/wio/wio-graphs.pl'; my $logdir = "/var/log/wio"; my ( %mainsettings, %mailsettings, %wiosettings, %cgiparams, %netsettings, %ipshash, %vpnconfighash, %ovpnconfighash, %ovpnccdconfhash, %ovpnsettings, %checked, %selected, %color ) = (); &General::readhash('/var/ipfire/main/settings', \%mainsettings); &General::readhash('/var/ipfire/ethernet/settings', \%netsettings); &General::readhash('/var/ipfire/dma/mail.conf', \%mailsettings); &General::readhash('/var/ipfire/wio/wio.conf', \%wiosettings); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); &General::readhasharray('/var/ipfire/ovpn/ovpnconfig', \%ovpnconfighash); &General::readhash('/var/ipfire/ovpn/settings', \%ovpnsettings); &General::readhasharray('/var/ipfire/ovpn/ccd.conf', \%ovpnccdconfhash); &General::readhasharray('/var/ipfire/vpn/config', \%vpnconfighash); my $ipadrfile = "$logdir/wioips"; my $onoffip = "$logdir/wioscip"; my $wiosettings = "/var/ipfire/wio/wio.conf"; my $dyndnsconfig = "/var/ipfire/ddns/config"; my $importfile = "$logdir/importfile"; my $wiofile = "$logdir/wiofile"; my $editfile = "$logdir/editfile"; my $hostfile = "/var/ipfire/main/hosts"; my $dhcpfile = "/var/ipfire/dhcp/fixleases"; my $imgstatic = "/images/wio"; my $rrddir = "/var/log/rrd/wio"; my $refreshbox = ''; my $sortstring = '^IPADR|^HOST'; my $ovpnaddon = "/var/ipfire/ovpn"; my $ovpnpid = "/var/run/openvpn.pid"; my $vpnpid = "/var/run/charon.pid"; my $redactive = "/var/ipfire/red/active"; my $redip = '-'; my $now = strftime "%Y-%m-%d", localtime; if ( -e $redactive ) { open(IPADDR, "/var/ipfire/red/local-ipaddress"); $redip = ; close IPADDR; chomp($redip); } my $i = 0; my $idarp = 0; my $iddyndns = 0; my $idvpn = 0; my $idovpn = 0; my $idsort = 0; my $nr = 0; my $count = 0; my $showcount = 0; my $arpbuttontext = "$Lang::tr{'wio_show_table_on'}"; my $clientimportbuttontext = "$Lang::tr{'wio_show_table_on'}"; my $networksearchbuttontext = "$Lang::tr{'wio_show_table_on'}"; my ( $message, $infomessage, $errormessage, $importmessage ) = ''; my ( $buttontext, $host, $timestamp, $ipadr, $on, $remark, $dyndns, $dyndnsip, $sendemailon, $net, $dev, $iprange, $output, $write, $webinterface, $sendemailoff, $pingmethode, $online, $color, $bgcolor, $exitcode, $id, $line, $interface, $counter, $vpnn2nip, $vpnn2nmask, $ddns, $edc, $edd, $wmon, $wmoff, $ipfqdn, $http, $wioscan, $statustxt, $status, $key, $ic, $text, $image ) = (); my ( @temp, @dates, @ipaddresses, @names, @remark, @sendemailon, @sendemailoff, @current, @ddns, @match, @webinterface, @arpcache, @arpadd, @line, @hosts, @vpnstatus, @ovpnstatus, @activ, @dyndns, @pingmethode, @status, @id, @write, @log ); my @nosaved = ('ACTION','ID','CLIENTID','TIMESTAMP','IPADR','HOST','REMARK','DYNDNS','SENDEMAILON','SENDEMAILOFF','PINGMETHODE','ONLINE','WEBINTERFACE'); my @devs_color = ('GREEN','BLUE','ORANGE','RED'); my @devs_net = ('green0','blue0','orange0','red0'); my @devs_img = ('green.png','blue.png','orange.png','red.png'); my @devs_alt = ('green','blue','orange','red'); my %ifacecolor = ( GREEN => 'wio_run_green', BLUE => 'wio_run_blue', ORANGE => 'wio_run_orange'); &loadips(); ## some wio settings $wiosettings{'ACTION'} = ''; $wiosettings{'COUNT'} = ''; $wiosettings{'ID'} = ''; $wiosettings{'CLIENTID'} = ''; $wiosettings{'SORT'} = 'IPADR'; $wiosettings{'HOST'} = ''; $wiosettings{'IPADR'} = ''; $wiosettings{'EN'} = 'on'; $wiosettings{'REMARK'} = ''; $wiosettings{'DYNDNS'} = ''; $wiosettings{'CLIENTREMARK'} = ''; $wiosettings{'SENDEMAILON'} = ''; $wiosettings{'SENDEMAILOFF'} = ''; $wiosettings{'PINGMETHODE'} = 'ip'; $wiosettings{'WEBINTERFACE'} = '----'; $wiosettings{'TIMEOUT'} = '1'; $wiosettings{'TIMESTAMP'} = ''; $wiosettings{'ONLINE'} = 'off'; $wiosettings{'CRON'} = '15'; $wiosettings{'OVPNCRON'} = '5'; $wiosettings{'ENABLE'} = 'off'; $wiosettings{'LOGGING'} = 'off'; $wiosettings{'MAILREMARK'} = 'off'; $wiosettings{'MAILSTYLE'} = 'email'; $wiosettings{'OVPNRWMAIL'} = 'off'; $wiosettings{'SHUTDOWN'} = 'off'; $wiosettings{'WIOGUISHOWARPTABLE'} = ''; $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} = ''; $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} = ''; &Header::getcgihash(\%wiosettings); &Header::getcgihash(\%mainsettings); &Header::getcgihash(\%mailsettings); &Header::getcgihash(\%netsettings); if ( $mailsettings{'USEMAIL'} eq 'on' ) { $wiosettings{'SENDEMAIL'} = 'on'; } else { $wiosettings{'SENDEMAIL'} = 'off'; } if ( -e $wiofile ) { goto WIOSCAN; } ## get network ips foreach (@devs_color) { if ( $netsettings{"${_}_DEV"} ne '' ) { $wiosettings{"${_}_IPLOW"} = &Network::find_next_ip_address($netsettings{"${_}_NETADDRESS"}, 1); $wiosettings{"${_}_IPHIGH"} = &Network::find_next_ip_address($netsettings{"${_}_BROADCAST"}, -1); } } ## save wio settings if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_save'}.'1' ) { unless ( `ps -A | grep wio.pl` ) { $cgiparams{'SORT'} = $wiosettings{'SORT'}; $cgiparams{'CRON'} = $wiosettings{'CRON'}; $cgiparams{'OVPNCRON'} = $wiosettings{'OVPNCRON'}; $cgiparams{'ENABLE'} = $wiosettings{'ENABLE'}; $cgiparams{'LOGGING'} = $wiosettings{'LOGGING'}; $cgiparams{'TIMEOUT'} = $wiosettings{'TIMEOUT'}; $cgiparams{'ACTION'} = $wiosettings{'ACTION'}; $cgiparams{'CLIENTREMARK'} = $wiosettings{'CLIENTREMARK'}; $cgiparams{'MAILREMARK'} = $wiosettings{'MAILREMARK'}; $cgiparams{'MAILSTYLE'} = $wiosettings{'MAILSTYLE'}; $cgiparams{'OVPNRWMAIL'} = $wiosettings{'OVPNRWMAIL'}; $cgiparams{'SHUTDOWN'} = $wiosettings{'SHUTDOWN'}; &General::writehash($wiosettings, \%cgiparams); &General::readhash($wiosettings, \%wiosettings); if ( $wiosettings{'ENABLE'} eq 'off' ) { &WIO::clearfile($ipadrfile); unlink glob "$rrddir/*"; } } else { $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## save imported clients if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_save'}.'2' ) { unless ( `ps -A | grep wio.pl` ) { while ( $count < $wiosettings{'COUNT'} ) { if ( defined($wiosettings{"USE$count"}) && $wiosettings{"USE$count"} eq 'on' ) { $wiosettings{'CLIENTID'} = $wiosettings{'CLIENTID$count'}; $wiosettings{'TIMESTAMP'} = $wiosettings{"TIMESTAMP$count"}; $wiosettings{'IPADR'} = $wiosettings{"IPADR$count"}; $wiosettings{'HOST'} = $wiosettings{"HOST$count"}; $wiosettings{'EN'} = $wiosettings{"EN$count"}; $wiosettings{'REMARK'} = $wiosettings{"REMARK$count"}; $wiosettings{'DYNDNS'} = $wiosettings{"DYNDNS$count"}; $wiosettings{'SENDEMAILON'} = $wiosettings{"SENDEMAILON$count"}; $wiosettings{'SENDEMAILOFF'} = $wiosettings{"SENDEMAILOFF$count"}; $wiosettings{'PINGMETHODE'} = $wiosettings{"PINGMETHODE$count"}; $wiosettings{'ONLINE'} = $wiosettings{"ONLINE$count"}; &validSave(); if ($errormessage) { open(FILE, ">> $editfile"); print FILE "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n"; close(FILE); $importmessage = $errormessage; } else { $wiosettings{'CLIENTID'} = &General::findhasharraykey (\%ipshash); unshift (@current, "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n"); &SortDataFile('',@current); } } $count++; } map ($wiosettings{$_} = '' ,@nosaved); unlink ($importfile); if ( -e "$editfile" ) { goto EDIT; } } else { $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## add or update client if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_client_add'} ) { unless ( `ps -A | grep wio.pl` ) { &validSave(); unless ($errormessage) { if ( $wiosettings{'ID'} eq '' && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} ) { $wiosettings{'CLIENTID'} = &General::findhasharraykey (\%ipshash); unshift (@current, "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n"); } else { @current[$wiosettings{'ID'}] = "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n"; } } else { goto ERROR; } map ($wiosettings{$_} = '' ,@nosaved); &SortDataFile('',@current); } else { $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## show / hide arptable if ( $wiosettings{'WIOGUISHOWARPTABLE'} eq 'arptable' ) { if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_show_table_off'} ) { $wiosettings{'WIOGUISHOWARPTABLE'} = 'off'; $arpbuttontext = "$Lang::tr{'wio_show_table_on'}"; } else { $wiosettings{'WIOGUISHOWARPTABLE'} = 'on'; $arpbuttontext = "$Lang::tr{'wio_show_table_off'}"; } } ## show / hide clientimporttable if ( $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} eq 'clientimport' ) { if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_show_table_off'} ) { $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} = 'off'; $clientimportbuttontext = "$Lang::tr{'wio_show_table_on'}"; } else { $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} = 'on'; $clientimportbuttontext = "$Lang::tr{'wio_show_table_off'}"; } } ## show / hide networksearchtable if ( $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} eq 'networksearch' ) { if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_show_table_off'} ) { $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} = 'off'; $networksearchbuttontext = "$Lang::tr{'wio_show_table_on'}"; } else { $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} = 'on'; $networksearchbuttontext = "$Lang::tr{'wio_show_table_off'}"; } } ## add arp client if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_add'} ) { unless ( `ps -A | grep wio.pl` ) { open(FILE, "$logdir/.arpcache"); @arpadd = ; close (FILE); chomp(@arpadd[$wiosettings{'ID'}]); @temp = split (/\,/, @arpadd[$wiosettings{'ID'}]); $wiosettings{'CLIENTID'} = &General::findhasharraykey (\%ipshash); $wiosettings{'IPADR'} = $temp[1]; $wiosettings{'HOST'} = $temp[2]; $wiosettings{'EN'} = 'on'; $wiosettings{'PINGMETHODE'} = 'ip'; $wiosettings{'ONLINE'} = 'off'; open(FILE, ">> $editfile"); print FILE "$wiosettings{'CLIENTID'},$wiosettings{'TIMESTAMP'},$wiosettings{'IPADR'},$wiosettings{'HOST'},$wiosettings{'EN'},$wiosettings{'REMARK'},$wiosettings{'DYNDNS'},$wiosettings{'SENDEMAILON'},$wiosettings{'SENDEMAILOFF'},$wiosettings{'PINGMETHODE'},$wiosettings{'ONLINE'},$wiosettings{'WEBINTERFACE'}\n"; close(FILE); goto EDIT; } else { undef($wiosettings{'ID'}); $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## enable / disable client || enable / disable dyndns || enable / disable sendemailon || enable / disable sendemailoff || change ip / fqdn if ( $wiosettings{'ACTION'} eq $Lang::tr{'enable disable client'} ) { $edc = 'on'; } if ( $wiosettings{'ACTION'} eq $Lang::tr{'enable disable dyndns'} ) { $edd = 'on'; } if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_mail_online'} ) { $wmon = 'on'; } if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_mail_offline'} ) { $wmoff = 'on'; } if (( $wiosettings{'ACTION'} eq $Lang::tr{'wio_ip_on'} ) || ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_fqdn_on'} )) { $ipfqdn = 'on'; } if ( defined($edc) || defined($edd) || defined($wmon) || defined($wmoff) || defined($ipfqdn) ) { unless ( `ps -A | grep wio.pl` ) { chomp(@current[$wiosettings{'ID'}]); @temp = split (/\,/, @current[$wiosettings{'ID'}]); if ( $edc eq 'on' ) { $temp[4] = $temp[4] ne '' ? '' : 'on'; $temp[10] = ''; $temp[11] = ''; $temp[1] = ''; unlink "$rrddir/$temp[0].rrd"; } elsif ( $edd eq 'on' ) { $temp[6] = $temp[6] ne '' ? '' : 'on'; } elsif ( $wmon eq 'on' ) { $temp[7] = $temp[7] ne '' ? '' : 'on'; } elsif ( $wmoff eq 'on' ) { $temp[8] = $temp[8] ne '' ? '' : 'on'; } elsif ( $ipfqdn eq 'on' ) { $temp[9] = $temp[9] eq 'fqdn' ? 'ip' : 'fqdn'; } @current[$wiosettings{'ID'}] = join (',', @temp)."\n"; undef($wiosettings{'ID'}); &writeips(); } else { undef($wiosettings{'ID'}); $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## refresh wio status || refresh single client status if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_refresh'} || $wiosettings{'ACTION'} eq $Lang::tr{'wio_sc_refresh'} ) { if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_sc_refresh'} ) { open(FILE, "> $onoffip"); print FILE @current[$wiosettings{'ID'}]; close(FILE); undef($wiosettings{'ID'}); } unless ( `ps -A | grep wio.pl` ) { &Header::showhttpheaders(); &Header::openpage($Lang::tr{'wio'}, 1, $refreshbox); &Header::openbigbox('100%', 'left', ''); &Header::openbox('100%', 'left', $Lang::tr{'wio_info'}); print"
$Lang::tr{'wio_msg'}
 
"; &Header::closebox(); &Header::closebigbox(); &Header::closepage(); while ( system("/usr/local/bin/wiohelper", "&") ) {} exit 0; } else { $infomessage = "$Lang::tr{'wio_already_running'}"; unlink($onoffip); } } ## refresh dyndns ip if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_dyndns_refresh'} ) { unless ( `ps -A | grep wio.pl` ) { chomp(@current[$wiosettings{'ID'}]); @temp = split (/\,/, @current[$wiosettings{'ID'}]); ($temp[2], $infomessage) = &WIO::getdyndnsip($temp[2], $temp[3]); @current[$wiosettings{'ID'}] = join (',', @temp)."\n"; &writeips(); undef($wiosettings{'ID'}); } else { $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## edit client if ( $wiosettings{'ACTION'} eq $Lang::tr{'edit'} ) { unless ( `ps -A | grep wio.pl` ) { chomp(@current[$wiosettings{'ID'}]); @temp = split (/\,/, @current[$wiosettings{'ID'}]); $wiosettings{'CLIENTID'} = $temp[0]; $wiosettings{'TIMESTAMP'} = $temp[1]; $wiosettings{'IPADR'} = $temp[2]; $wiosettings{'HOST'} = $temp[3]; $wiosettings{'EN'} = $temp[4]; $wiosettings{'REMARK'} = $temp[5]; $wiosettings{'DYNDNS'} = $temp[6]; $wiosettings{'SENDEMAILON'} = $temp[7]; $wiosettings{'SENDEMAILOFF'} = $temp[8]; $wiosettings{'PINGMETHODE'} = $temp[9]; $wiosettings{'ONLINE'} = $temp[10]; $wiosettings{'WEBINTERFACE'} = $temp[11]; } else { undef($wiosettings{'ACTION'}); $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## remove client if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_remove_client'} ) { unless ( `ps -A | grep wio.pl` ) { chomp(@current[$wiosettings{'ID'}]); @temp = split (/\,/, @current[$wiosettings{'ID'}]); unlink "$rrddir/$temp[0].rrd"; splice (@current,$wiosettings{'ID'},1); &writeips(); undef($wiosettings{'ID'}); } else { undef($wiosettings{'ID'}); $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## remove all clients if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_remove_all'} ) { unless ( `ps -A | grep wio.pl` ) { &WIO::clearfile($ipadrfile); unlink glob "$rrddir/*"; undef(@current); } else { $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## back function if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_back'} ) { if ( -e "$importfile" ) { unlink ($importfile); } map ($wiosettings{$_} = '' ,@nosaved); undef($errormessage); } ## import hosts, fixleases or csv file || scan networks (green/blue/orange) if ( $wiosettings{'ACTION'} eq 'wio_run_green' || $wiosettings{'ACTION'} eq 'wio_run_blue' || $wiosettings{'ACTION'} eq 'wio_run_orange') { $wioscan = 'on'; } if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'1' || $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' || $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'3' || defined($wioscan) || defined($importmessage) ) { unless ( `ps -A | grep wio.pl` ) { if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'1' && $importmessage eq '' ) { &Header::getcgihash(\%wiosettings, {'wantfile' => 1, 'filevar' => 'CSVFILE'}); if ( $wiosettings{'CSVFILE'} eq '' ) { $errormessage = $Lang::tr{'wio_no_file_selected'}; $message = 2; goto ERROR; } if ( $wiosettings{'CSVFILE'} =~ /[^a-z0-9A-Z\ \.\-\_\:\\]+/ ) { $errormessage = $Lang::tr{'wio_no_csv_error'}; $message = 2; goto ERROR; } if ( !($wiosettings{'CSVFILE'} =~ /.csv$/) ) { $errormessage = $Lang::tr{'wio_no_csv'}; $message = 2; goto ERROR; } if (copy($wiosettings{'CSVFILE'}, "$logdir/importfile") != 1) { $errormessage = $!; $message = 2; goto ERROR; } } EDIT: &General::readhash($wiosettings, \%wiosettings); &Header::showhttpheaders(); &Header::openpage($Lang::tr{'wio'}, 1, ''); &Header::openbigbox('100%', 'left'); if ($importmessage) { &Header::openbox('100%', 'left', $Lang::tr{'wio_error'}, 'error'); print"
$importmessage
"; &Header::closebox(); } if ( -e "$editfile" ) { open(FILE, "< $editfile" ); } elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'1' ) { open(FILE, "< $importfile" ); } elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' ) { open(FILE, "< $hostfile" ); } elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'3' ) { open(FILE, "< $dhcpfile" ); } elsif ( $wioscan eq 'on' ) { foreach (keys(%ifacecolor)) { if ( $netsettings{"${_}_DEV"} eq $wiosettings{'ID'} ) { $dev = $netsettings{"${_}_DEV"}; $iprange = $wiosettings{"${_}_IPLOW"} . "-" . $wiosettings{"${_}_IPHIGH"}; if ( $_ eq 'GREEN' ) { $color = "$Header::colourgreen"; $net = $Lang::tr{'wio_msg_green'}; } elsif ( $_ eq 'BLUE' ) { $color = "$Header::colourblue"; $net = $Lang::tr{'wio_msg_blue'}; } else { $color = "$Header::colourorange"; $net = $Lang::tr{'wio_msg_orange'}; } } } &Header::openbox('100%', 'left', $Lang::tr{'wio_info'}); print"
$Lang::tr{'wio_msg_left'} $net $Lang::tr{'wio_msg_center'} $dev $Lang::tr{'wio_msg_right'} $Lang::tr{'wio_msg_hint'}
 
"; &Header::closebox(); &Header::closebigbox(); open(FILE, "/usr/local/bin/wioscan -wsa $dev $iprange |" ); } @hosts = ; close(FILE); if ( $wioscan ne 'on' && ! -e $wiofile ) { @hosts = sort @hosts; } else { open(FILE, "> $wiofile"); print FILE @hosts; close(FILE); print""; exit 0; } WIOSCAN: if ( -e $wiofile ) { open(FILE, "< $wiofile"); @hosts = ; close (FILE); &General::readhash($wiosettings, \%wiosettings); &Header::showhttpheaders(); &Header::openpage($Lang::tr{'wio'}, 1, ''); &Header::openbigbox('100%', 'left'); } foreach (@hosts) { chomp; @line = split (/\,/, $_); if ( -e $editfile || -e $importfile ) { $wiosettings{'CLIENTID$count'} = $line[0]; $wiosettings{'TIMESTAMP$count'} = $line[1]; $wiosettings{'IPADR$count'} = $line[2]; $wiosettings{'HOST$count'} = $line[3]; $wiosettings{'EN$count'} = $line[4]; $wiosettings{'REMARK$count'} = $line[5]; $wiosettings{'DYNDNS$count'} = $line[6]; $wiosettings{'SENDEMAILON$count'} = $line[7]; $wiosettings{'SENDEMAILOFF$count'} = $line[8]; $wiosettings{'PINGMETHODE$count'} = $line[9]; $wiosettings{'ONLINE$count'} = $line[10]; $wiosettings{'WEBINTERFACE$count'} = $line[11]; $wiosettings{'USE$count'} = 'on'; } else { $wiosettings{'IPADR$count'} = $line[1]; $wiosettings{'EN$count'} = 'on'; $wiosettings{'PINGMETHODE$count'} = 'ip'; $wiosettings{'USE$count'} = 'on'; if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' ) { $wiosettings{'HOST$count'} = $line[2]; $wiosettings{'DOM$count'} = $line[3]; $wiosettings{'REMARK$count'} = ''; } elsif ( $wioscan eq 'on' || -e $wiofile ) { $wiosettings{'HOST$count'} = gethostbyaddr(inet_aton($line[1]), AF_INET); if ($wiosettings{'HOST$count'} eq '') { $wiosettings{'HOST$count'} = $line[1]; } $wiosettings{'REMARK$count'} = ''; $wiosettings{'WEBINTERFACE$count'} = ''; } else { $wiosettings{'HOST$count'} = $line[7]; $wiosettings{'REMARK$count'} = $line[6]; } } $checked{'EN$count'}{'on'} = ($wiosettings{'EN$count'} eq '' ) ? '' : "checked='checked'"; $checked{'DYNDNS$count'}{'on'} = ($wiosettings{'DYNDNS$count'} eq '' ) ? '' : "checked='checked'"; $checked{'SENDEMAILON$count'}{'on'} = ($wiosettings{'SENDEMAILON$count'} eq '' ) ? '' : "checked='checked'"; $checked{'SENDEMAILOFF$count'}{'on'} = ($wiosettings{'SENDEMAILOFF$count'} eq '' ) ? '' : "checked='checked'"; $checked{'PINGMETHODE$count'}{'ip'} = $checked{'PINGMETHODE$count'}{'fqdn'} = ''; $checked{'PINGMETHODE$count'}{$wiosettings{'PINGMETHODE$count'}} = "checked='checked'"; $checked{'USE$count'}{'on'} = ($wiosettings{'USE$count'} eq '' ) ? '' : "checked='checked'"; $selected{'WEBINTERFACE$count'}{'----'} = ''; $selected{'WEBINTERFACE$count'}{'HTTP'} = ''; $selected{'WEBINTERFACE$count'}{'HTTPS'} = ''; $selected{'WEBINTERFACE$count'}{$wiosettings{'WEBINTERFACE$count'}} = "selected='selected'"; if (! &WIO::checkinto($wiosettings{'IPADR$count'}, $wiosettings{'HOST$count'}, @current) ) { if ( $importmessage ) { &Header::openbox('100%', 'left', "$Lang::tr{'wio_import_data'}'$wiosettings{'HOST$count'}'$Lang::tr{'wio_import_data1'}"); } elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'1' || $wioscan eq 'on' || -e $wiofile || -e $editfile ) { &Header::openbox('100%', 'left', "$Lang::tr{'wio_import_data'}'$wiosettings{'HOST$count'}'$Lang::tr{'wio_import_data2'}"); } elsif ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' ) { &Header::openbox('100%', 'left', "$Lang::tr{'wio_import_data'}'$wiosettings{'HOST$count'}.$wiosettings{'DOM$count'}'$Lang::tr{'wio_import_data2'}"); } else { &Header::openbox('100%', 'left', $Lang::tr{'wio_import_leases'}); } print"
"; if ( $wiosettings{'ACTION'} eq $Lang::tr{'wio_import'}.'2' ) { print""; } else { print""; } print" "; if ( $wiosettings{'SENDEMAIL'} eq 'on' ) { print""; } else { print""; } print"
$Lang::tr{'wio_use'}
$Lang::tr{'wio_client_enable'}
$Lang::tr{'host ip'}: $Lang::tr{'hostname'}:$Lang::tr{'remark'}:
$Lang::tr{'wio_ping_send'}:  IP      FQDN $Lang::tr{'wio_dyndns'}: $Lang::tr{'wio_sendemail'}:  $Lang::tr{'wio_online'}      $Lang::tr{'wio_offline'} 
$Lang::tr{'wio_link_open'}:
"; &Header::closebox(); $showcount++; } $count++; } if ( $showcount gt 0 ) { &Header::openbox('100%', 'left', $Lang::tr{'wio_import_infos'}); print" "; if ($importmessage) { print""; } else { print""; } print"
 $Lang::tr{'wio_import_infos_csv'}
 
 
 
"; &Header::closebox(); &Header::closebigbox(); &Header::closepage(); } else { print""; } if ( -e "$editfile" ) { unlink ($editfile); } if ( -e "$wiofile" ) { unlink($wiofile); } exit 0; } else { $infomessage = "$Lang::tr{'wio_error_function'}"; } } ## skript function if ($ENV{'QUERY_STRING'} =~ /$sortstring/ ) { my $string = $ENV{'QUERY_STRING'}; if ( $string eq 'INFO' ) { $infomessage = $Lang::tr{'wio_import_info_csv'}; } else { &General::readhash($wiosettings, \%wiosettings); my $actual = $wiosettings{'SORT'}; if ($actual =~ $string) { my $Rev = ''; if ($actual !~ 'Rev') { $Rev = 'Rev'; } $string.=$Rev; } system("/bin/sed -i 's#$wiosettings{'SORT'}#$string#g' $wiosettings"); $wiosettings{'SORT'} = $string; map ($wiosettings{$_} = '' ,@nosaved); &SortDataFile('',@current); } } ## main part ERROR: unless($message == 1) { &General::readhash($wiosettings, \%wiosettings); } for ($i=5; $i<=60; $i+=5) { $selected{'CRON'}{$i} = ''; } $selected{'CRON'}{$wiosettings{'CRON'}} = "selected='selected'"; for ($i=1; $i<=15; $i++) { $selected{'TIMEOUT'}{$i} = ''; $selected{'OVPNCRON'}{$i} = ''; } $selected{'TIMEOUT'}{$wiosettings{'TIMEOUT'}} = "selected='selected'"; $selected{'OVPNCRON'}{$wiosettings{'OVPNCRON'}} = "selected='selected'"; $checked{'ENABLE'}{'off'} = $checked{'ENABLE'}{'on'} = ''; $checked{'ENABLE'}{$wiosettings{'ENABLE'}} = "checked='checked'"; $checked{'LOGGING'}{'off'} = $checked{'LOGGING'}{'on'} = ''; $checked{'LOGGING'}{$wiosettings{'LOGGING'}} = "checked='checked'"; $checked{'CLIENTREMARK'}{'off'} = $checked{'CLIENTREMARK'}{'on'} = ''; $checked{'CLIENTREMARK'}{$wiosettings{'CLIENTREMARK'}} = "checked='checked'"; $checked{'MAILREMARK'}{'off'} = $checked{'MAILREMARK'}{'on'} = ''; $checked{'MAILREMARK'}{$wiosettings{'MAILREMARK'}} = "checked='checked'"; $checked{'OVPNRWMAIL'}{'off'} = $checked{'OVPNRWMAIL'}{'on'} = ''; $checked{'OVPNRWMAIL'}{$wiosettings{'OVPNRWMAIL'}} = "checked='checked'"; $checked{'SHUTDOWN'}{'off'} = $checked{'SHUTDOWN'}{'on'} = ''; $checked{'SHUTDOWN'}{$wiosettings{'SHUTDOWN'}} = "checked='checked'"; $checked{'MAILSTYLE'}{'smail'} = $checked{'MAILSTYLE'}{'email'} = ''; $checked{'MAILSTYLE'}{$wiosettings{'MAILSTYLE'}} = "checked='checked'"; &Header::showhttpheaders(); &Header::openpage($Lang::tr{'wio'}, 1, ""); &Header::openbigbox('100%', 'left', ''); ## DEBUG / ERROR / INFO / UPDATE if ( $debug ) { &Header::openbox('100%', 'left', 'DEBUG', 'warning'); print"errormessage: $errormessage
\n"; print"infomessage: $infomessage
\n"; &hrline(); my $wiodebug = 0; foreach (sort keys %wiosettings) { print"$_ = $wiosettings{$_}
\n"; $wiodebug++; } &hrline(); my $netdebug = 0; foreach (sort keys %netsettings) { print"$_ = $netsettings{$_}
\n"; $netdebug++; } &Header::closebox(); } if ( $errormessage ) { &Header::openbox('100%', 'left', $Lang::tr{'wio_error'}, 'error'); print"
$errormessage
"; &Header::closebox(); } if ( $infomessage ) { &Header::openbox('100%', 'left', $Lang::tr{'wio_info'}, 'warning'); print"
$infomessage
"; &Header::closebox(); } ## wio configuration if ( $wiosettings{'ACTION'} eq $Lang::tr{'edit'}.'1' || $message == 1 || $wiosettings{'ENABLE'} eq 'off' ) { &Header::openbox('100%', 'left', $Lang::tr{'wio settings'}); print"
"; print""; if ( $wiosettings{'ENABLE'} eq 'on' ) { print""; } else { print""; } print" "; if ( $wiosettings{'SENDEMAIL'} eq 'on' ) { print" "; } if ( -e "$ovpnaddon" || ! -z "/var/ipfire/vpn/config" ) { print" "; } print"
 $Lang::tr{'wio_settings_msg'}    
 
$Lang::tr{'wio_settings_msg_hint'}
 
$Lang::tr{'wio enabled'} 
 
$Lang::tr{'wio_shutdown'}  
 
$Lang::tr{'wio cron'}    $Lang::tr{'wio min'}
 
$Lang::tr{'wio timeout'}    $Lang::tr{'wio sec'}
 
$Lang::tr{'wio_logging'}  
 
$Lang::tr{'wio_clientremark'}  
 
$Lang::tr{'wio_mail_style'}:    $Lang::tr{'wio_mail_smail'}      $Lang::tr{'wio_mail_email'}
 
$Lang::tr{'wio_mailremark_enabled'}  
 
$Lang::tr{'wio_mail_ovpnrw'}  
 
$Lang::tr{'wio_ovpn_cron'}    $Lang::tr{'wio min'}
 
 
  " .($wiosettings{'ENABLE'} ne 'off' ? "     " : "") ."
"; &Header::closebox(); &Header::closebigbox(); &Header::closepage(); exit 0; } ## wio client status if ( $wiosettings{'ENABLE'} eq 'on') { if ( !$errormessage && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} || $message == 2 ) { &Header::openbox('100%', 'left', $Lang::tr{'wio stat'}); foreach (@current) { chomp; ($id,$timestamp,$ipadr,$host,$on,$remark,$dyndns,$sendemailon,$sendemailoff,$pingmethode,$online,$webinterface) = split (/\,/, $_); if ( defined($dyndns) && ( $dyndns =~ 'on' ) ) { ($dyndnsip, $infomessage) = &WIO::getdyndnsip($ipadr, $host); if ( $dyndnsip ne $ipadr ) { $ipadr = $dyndnsip; $write = 'on'; } } push (@id,($id)); if ( $on eq 'on' ) { push (@dates,($timestamp)); } else { push (@dates,('-')); } push (@ipaddresses,($ipadr)); push (@names,($host)); push (@activ,($on)); push (@remark,($remark)); push (@dyndns,($dyndns)); push (@sendemailon,($sendemailon)); push (@sendemailoff,($sendemailoff)); push (@pingmethode,($pingmethode)); push (@status,($online)); push (@webinterface,($webinterface)); push (@write, "$id,$timestamp,$ipadr,$host,$on,$remark,$dyndns,$sendemailon,$sendemailoff,$pingmethode,$online,$webinterface\n"); $nr++; } if ( defined($write) ) { &writeips(); } ## wan connection print"
 $Lang::tr{'wio_wan_con'}  
 
$Lang::tr{'wio_id'} $Lang::tr{'wio ipadress'} $Lang::tr{'wio network'} $Lang::tr{'wio_lanname'} $Lang::tr{'wio_wanname'} $Lang::tr{'wio_dyndns_hosts'} $Lang::tr{'wio image'} $Lang::tr{'wio_connected'}
01 $redip $Lang::tr{ ".$mainsettings{'HOSTNAME'}.".".$mainsettings{'DOMAINNAME'}." ".( $redip ne '-' ? (gethostbyaddr(pack("C4", split (/\./, $redip)), 2))[0] : '-' )." "; if ( -s "$dyndnsconfig" ) { open(FILE, "< $dyndnsconfig"); @ddns = ; close (FILE); $ddns = @ddns; $bgcolor = "blue"; foreach (@ddns) { chomp; @temp = split (/\,/, $_); if ( $temp[7] eq "on" ) { $bgcolor = ( &General::DyndnsServiceSync (&General::GetDyndnsRedIP,$temp[1],$temp[2]) ? "$Header::colourgreen" : "$Header::colourred" ); } print"$temp[1].$temp[2]"; if ( $iddyndns++ ne ($ddns-1) ) { print", "; } } } else { print" - "; } print"
".( -e $redactive ? $Lang::tr{'wio_wan_up'} : $Lang::tr{'wio_wan_down'} )."
".( -e "$redactive" ? &General::age("$redactive") : '-' )."
"; &hrline(); ## vpn connection(s) if ( -e "$vpnpid" ) { @vpnstatus = `/usr/local/bin/ipsecctrl I`; print"
 $Lang::tr{'wio_vpn_con'}  
 
"; foreach $key (sort SortByTunnelName (keys(%vpnconfighash))) { my $vpncheck = ''; if ( -e '/var/log/wio/.vpncache' ) { $vpncheck = strftime("%d.%m.%Y - %H:%M:%S",localtime(((stat('/var/log/wio/.vpncache'))[9]))); } $status = "bgcolor='${Header::colourred}'"; $statustxt = "$Lang::tr{'capsclosed'}"; if ($vpnconfighash{$key}[0] eq 'off') { $status = "bgcolor='${Header::colourblue}'"; $statustxt = "$Lang::tr{'capsclosed'}"; } foreach (@vpnstatus) { if ($_ =~ /$vpnconfighash{$key}[1]\{.*INSTALLED/) { $status = "bgcolor='${Header::colourgreen}'"; $statustxt = "$Lang::tr{'capsopen'}"; last; } } print""; my $vpnnr = $idvpn+1; printf ("", $vpnnr); print" "; if ($vpnconfighash{$key}[25] && $wiosettings{'CLIENTREMARK'} eq 'on') { print""; } print""; $idvpn++ } print"
$Lang::tr{'wio_id'} $Lang::tr{'wio checked'} $Lang::tr{'name'} $Lang::tr{'type'} $Lang::tr{'wio_common_name'} $Lang::tr{'wio image'} $Lang::tr{'wio_connected'}
%02d$vpncheck $vpnconfighash{$key}[1] $Lang::tr{ ".($vpnconfighash{$key}[2] eq '%auth-dn' ? "$vpnconfighash{$key}[9]" : ($vpnconfighash{$key}[4] eq 'cert' ? "$vpnconfighash{$key}[2]" : ($vpnconfighash{$key}[8] ne '' ? "$vpnconfighash{$key}[10]" : " ")))."
$statustxt
 
 $vpnconfighash{$key}[25]
"; &hrline(); } ## openvpn connection(s) if ( -e "$ovpnpid" ) { @ovpnstatus = `cat /var/run/ovpnserver.log`; print"
 $Lang::tr{'wio_ovpn_con'}  
 
"; foreach $key (keys %ovpnconfighash) { my ( $ovpnclt, $ovpntime, $ovpnrwip, $ovpncheck ) = ''; if ( -e '/var/log/wio/.ovpncache' ) { $ovpncheck = strftime("%d.%m.%Y - %H:%M:%S",localtime(((stat('/var/log/wio/.ovpncache'))[9]))); } print""; my $ovpnnr = $idovpn+1; printf ("", $ovpnnr); if ($ovpnconfighash{$key}[3] eq 'net') { $image = "$imgstatic/ovpnn2n.png"; $text = "$Lang::tr{'wio_n2n'}"; } else { $image = "$imgstatic/ovpnrw.png"; $text = "$Lang::tr{'wio_rw'}"; } if ( $ovpnconfighash{$key}[0] eq 'off' ) { $status = "${Header::colourblue}"; $statustxt = "$Lang::tr{'capsclosed'}"; } else { if ($ovpnconfighash{$key}[3] eq 'net') { if (-e "/var/run/$ovpnconfighash{$key}[1]n2n.pid") { my @output = ""; my @tustate = ""; my $tport = $ovpnconfighash{$key}[22]; my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); if ($tport ne '') { $tnet->open('127.0.0.1'); @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); @tustate = split(/\,/, $output[1]); $ovpntime = &WIO::contime(scalar localtime($tustate[0])); if (($tustate[1] eq 'CONNECTED')) { $status = "${Header::colourgreen}"; $statustxt = "$Lang::tr{'capsopen'}"; }else { $status = "${Header::colourred}"; $statustxt = "$tustate[1]"; } } } } else { foreach (@ovpnstatus) { if ( $_ =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/ ) { @match = split (m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $_); $match[1] =~ s/[_]/ /g; } if ( $match[1] ne "Common Name" && ($match[1] eq $ovpnconfighash{$key}[2]) ) { $ovpnclt = $match[1]; $ovpntime = &WIO::contime($match[5]); } if ( $_ =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/ ) { @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $_); } if ( $match[1] ne "Virtual Address" && $match[2] eq $ovpnclt ) { $ovpnrwip = $match[1]; $ovpncheck = &WIO::statustime($match[4]); } if ( $ovpnclt eq $ovpnconfighash{$key}[2] ) { $status = "${Header::colourgreen}"; $statustxt = "$Lang::tr{'capsopen'}"; } else { $status = "${Header::colourred}"; $statustxt = "$Lang::tr{'capsclosed'}"; } } } } print" "; if ($ovpnconfighash{$key}[25] && $wiosettings{'CLIENTREMARK'} eq 'on') { print""; } print""; $idovpn++ } print"
$Lang::tr{'wio_id'} $Lang::tr{'wio checked'} $Lang::tr{'wio ipadress'} $Lang::tr{'type'} $Lang::tr{'common name'} $Lang::tr{'wio image'} $Lang::tr{'wio_connected'}
%02d$ovpncheck ".( defined($ovpnrwip)? "$ovpnrwip" : " ")." $text ".($ovpnconfighash{$key}[2] eq '%auth-dn' ? "$ovpnconfighash{$key}[9]" : ($ovpnconfighash{$key}[4] eq 'cert' ? "$ovpnconfighash{$key}[2]": " "))."
$statustxt
".(defined($ovpntime)? "$ovpntime" : " ")."
 $ovpnconfighash{$key}[25]
"; &hrline(); } #} ## client status print"
 $Lang::tr{'wio_clients'}  
 
"; for (my $a=0; $a<$nr; $a++) { my $gif = 'off.gif'; my $gdesc = $Lang::tr{'wio_client_off'}; my $dyndnsimg = 'on.gif'; my $dyndnsimgtxt = $Lang::tr{'wio_dyndns_on'}; my $mailonimg = 'wio/mailgreenon.png'; my $mailonimgtxt = $Lang::tr{'wio_mail_online_on'}; my $mailoffimg = 'wio/mailredon.png'; my $mailoffimgtxt = $Lang::tr{'wio_mail_offline_on'}; my $pingimg = ''; my $pingtxt = ''; my $webimg = ''; if ( $activ[$a] eq 'on' ) { $gif = 'on.gif'; $gdesc = $Lang::tr{'wio_client_on'}; } if ( $dyndns[$a] ne 'on' ) { $dyndnsimg = 'off.gif'; $dyndnsimgtxt = $Lang::tr{'wio_dyndns_off'}; } if ( $sendemailon[$a] ne 'on' ) { $mailonimg = 'wio/mailgreenoff.png'; $mailonimgtxt = $Lang::tr{'wio_mail_online_off'}; } if ( $sendemailoff[$a] ne 'on' ) { $mailoffimg = 'wio/mailredoff.png'; $mailoffimgtxt = $Lang::tr{'wio_mail_offline_off'}; } if ( $webinterface[$a] eq 'HTTP' ) { $webimg = 'wio/http.png'; } elsif ( $webinterface[$a] eq 'HTTPS' ) { $webimg = 'wio/https.png'; } else { $webimg = 'wio/none.png'; } $bgcolor = $status[$a] eq "on" ? "${Header::colourgreen}" : ($status[$a] eq "off" && $dates[$a] eq "") ? "${Header::colourblue}" : "${Header::colourred}"; $statustxt = $status[$a] eq "on" ? "$Lang::tr{'wio up'}" : ($status[$a] eq "off" && $dates[$a] eq "") ? "$Lang::tr{'wio_no_image'}" : "$Lang::tr{'wio down'}"; print""; printf ("", $a+1); print""; if ( $pingmethode[$a] eq 'ip') { print""; } else { print""; } print""; print""; if ( $webinterface[$a] eq 'HTTP' ) { print""; } elsif ( $webinterface[$a] eq 'HTTPS' ) { print""; } else { print""; } my $dotip = length($ipaddresses[$a]) - rindex($ipaddresses[$a],'.'); SWITCH: { foreach (@devs_color) { my $in = 0; $ic = "${_}"; foreach $interface (@devs_net) { next if ( $netsettings{"$ic"."_DEV"} eq 'red0' && ($netsettings{"RED_TYPE"} eq 'DHCP' || $netsettings{"RED_TYPE"} eq 'PPPOE')); if ( $netsettings{"$ic"."_DEV"} eq $interface ) { if ( &General::IpInSubnet($ipaddresses[$a], $netsettings{"$ic"."_NETADDRESS"}, $netsettings{"$ic"."_NETMASK"}) ) { print""; last SWITCH; } } $in++; } } if ( -e "$vpnpid" ) { foreach $key (keys(%vpnconfighash)) { next unless ($vpnconfighash{$key}[3] eq 'net'); my $convertip = &General::ipcidr2msk($vpnconfighash{$key}[11]); my @net = split ("/", $convertip); $vpnn2nip = $net[0]; $vpnn2nmask = length($net[1]) - rindex($net[1],'.'); if (substr($ipaddresses[$a],0,length($ipaddresses[$a])-$dotip) eq substr($vpnn2nip,0,length($vpnn2nip)-$vpnn2nmask)) { print""; last SWITCH; } } } if ( $ovpnsettings{'DOVPN_SUBNET'} ne '' ) { @match = split ("/", $ovpnsettings{'DOVPN_SUBNET'}); if ( &General::IpInSubnet($ipaddresses[$a], $match[0], $match[1]) ) { print""; last SWITCH; } } if ( %ovpnccdconfhash ne '' ) { foreach $key (keys(%ovpnccdconfhash)) { my $convertip = &General::ipcidr2msk($ovpnccdconfhash{$key}[1]); my @net = split ("/", $convertip); $vpnn2nip = $net[0]; $vpnn2nmask = length($net[1]) - rindex($net[1],'.'); if (substr($ipaddresses[$a],0,length($ipaddresses[$a])-$dotip) eq substr($vpnn2nip,0,length($vpnn2nip)-$vpnn2nmask)) { print""; last SWITCH; } } } if ($netsettings{"RED_TYPE"} eq 'DHCP' || $netsettings{"RED_TYPE"} eq 'PPPOE') { my $redipadr = qx'ip addr | grep red0 | grep inet | awk "{print \$2}"'; my @rednet = split ("/", $redipadr); chomp ($rednet[1]); my $red_netmask = General::iporsubtodec($rednet[1]); my $red_netaddress = Network::get_netaddress("$rednet[0]/$red_netmask"); if ( &General::IpInSubnet($ipaddresses[$a], $red_netaddress, $red_netmask) ) { print""; last SWITCH; } else { print""; last SWITCH; } } } if ( $webinterface[$a] eq 'HTTP' ) { print""; } elsif ( $webinterface[$a] eq 'HTTPS' ) { print""; } else { print""; } print" "; if ( defined($dyndns[$a]) && ($dyndns[$a] eq 'on') ) { print""; } else { print""; } if ( -e "/var/log/rrd/wio/$id[$a].rrd" ) { print" "; } else { print ""; } if ( $wiosettings{'SENDEMAIL'} eq 'on') { print""; } else { print""; } print" "; if ($remark[$a] && $wiosettings{'CLIENTREMARK'} eq 'on') { print""; } print""; } print"
$Lang::tr{'wio_id'} $Lang::tr{'wio_activ'} $Lang::tr{'wio_check'} $Lang::tr{'wio checked'} $Lang::tr{'wio_webinterface'} $Lang::tr{'wio ipadress'} $Lang::tr{'wio network'} $Lang::tr{'wio name'} $Lang::tr{'wio image'}
$Lang::tr{'wio_dyndns'} $Lang::tr{'action'}
%02d
$dates[$a]$ipaddresses[$a]$ipaddresses[$a]$ipaddresses[$a]$Lang::tr{$devs_alt[$in]}IPSecOpenVPNOpenVPN$Lang::tr{$Lang::tr{$names[$a]$names[$a]$names[$a]
$statustxt
-
$Lang::tr{
- -
 $remark[$a]
"; &Header::closebox(); } ## add / modify client $checked{'EN'}{'on'} = ($wiosettings{'EN'} eq '' ) ? '' : "checked='checked'"; $checked{'DYNDNS'}{'off'} = $checked{'DYNDNS'}{'on'} = ''; $checked{'DYNDNS'}{$wiosettings{'DYNDNS'}} = "checked='checked'"; $checked{'SENDEMAILON'}{'off'} = $checked{'SENDEMAILON'}{'on'} = ''; $checked{'SENDEMAILON'}{$wiosettings{'SENDEMAILON'}} = "checked='checked'"; $checked{'SENDEMAILOFF'}{'off'} = $checked{'SENDEMAILOFF'}{'on'} = ''; $checked{'SENDEMAILOFF'}{$wiosettings{'SENDEMAILOFF'}} = "checked='checked'"; if (! defined($errormessage) && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} ) { $wiosettings{'PINGMETHODE'} = 'ip'; } $checked{'PINGMETHODE'}{'ip'} = $checked{'PINGMETHODE'}{'fqdn'} = ''; $checked{'PINGMETHODE'}{$wiosettings{'PINGMETHODE'}} = "checked='checked'"; $selected{'WEBINTERFACE'}{'----'} = ''; $selected{'WEBINTERFACE'}{'HTTP'} = ''; $selected{'WEBINTERFACE'}{'HTTPS'} = ''; $selected{'WEBINTERFACE'}{$wiosettings{'WEBINTERFACE'}} = "selected='selected'"; $buttontext = $Lang::tr{'wio_client_add'}; if ( $wiosettings{'ACTION'} eq $Lang::tr{'edit'} || defined($errormessage) && ! defined($message) ) { &Header::openbox('100%', 'left', $Lang::tr{'wio_edit_client'}); $buttontext = $Lang::tr{'update'}; } else { &Header::openbox('100%', 'left', $Lang::tr{'wio_edit_settings'}); } if (! defined($errormessage) && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} ) { print"
 $Lang::tr{'wio_add'}  
 
"; } print"
"; print" "; if ( $wiosettings{'SENDEMAIL'} eq 'on' ) { print""; } else { print""; } print"
$Lang::tr{'wio_client_enable'}  
$Lang::tr{'wio ipadress'}: $Lang::tr{'wio name'}: $Lang::tr{'remark'}:
$Lang::tr{'wio_ping_send'}:  IP              FQDN $Lang::tr{'wio_dyndns'}: $Lang::tr{'wio_sendemail'}:  $Lang::tr{'wio_online'}      $Lang::tr{'wio_offline'} 
$Lang::tr{'wio_link_open'}:
"; if ( $buttontext eq $Lang::tr{'update'} && ( defined($errormessage) || $wiosettings{'ACTION'} eq $Lang::tr{'edit'}) && ! defined($message) ) { print""; } else { print""; } print"
          
"; if ( $wiosettings{'ENABLE'} eq 'on' && !$errormessage && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} || $message == 2 ) { &hrline(); ## arp table entries print"
 $Lang::tr{'wio_arp_table_entries'}
"; if ( $wiosettings{'WIOGUISHOWARPTABLE'} eq 'on' ) { print" "; $output = `/sbin/ip neigh list`; $output = &Header::cleanhtml($output,"y"); my $arpcnt = 0; foreach $line (split(/\n/, $output)) { if ($line =~ m/^(.*) dev ([^ ]+) lladdr ([0-9a-f:]*) (.*)$/) { my $arphost = gethostbyaddr(inet_aton($1), AF_INET); if ( $arphost eq 'localhost' ) { $arphost = ''; } push (@arpcache, "$3,$1,$arphost,$2\n"); } elsif ($line =~ m/^(.*) dev ([^ ]+) (.*)$/) { my $arphost = gethostbyaddr(inet_aton($1), AF_INET); if ( $arphost eq 'localhost' ) { $arphost = ''; } push (@arpcache, ",$1,$arphost,$2\n"); } $arpcnt++; } &SortDataFile('arpcache',@arpcache); foreach (@arpcache) { chomp; @line = split (/\,/, $_); print""; printf ("", $idarp+1); print""; SWITCH: { foreach (@devs_color) { my $in = 0; $ic = "${_}"; foreach $interface (@devs_net) { next if ( $netsettings{"$ic"."_DEV"} eq 'red0' && ($netsettings{"RED_TYPE"} eq 'DHCP' || $netsettings{"RED_TYPE"} eq 'PPPOE')); if ($netsettings{"$ic"."_DEV"} eq $interface) { if ( &General::IpInSubnet($line[1], $netsettings{"$ic"."_NETADDRESS"}, $netsettings{"$ic"."_NETMASK"}) ) { print""; last SWITCH; } } $in++; } } if ($netsettings{"RED_TYPE"} eq 'DHCP' || $netsettings{"RED_TYPE"} eq 'PPPOE') { my $redipadr = qx'ip addr | grep red0 | grep inet | awk "{print \$2}"'; my @rednet = split ("/", $redipadr); chomp ($rednet[1]); my $red_netmask = General::iporsubtodec($rednet[1]); my $red_netaddress = Network::get_netaddress("$rednet[0]/$red_netmask"); if ( &General::IpInSubnet($line[1], $red_netaddress, $red_netmask) ) { print""; last SWITCH; } else { print""; last SWITCH; } } } print""; unless (&WIO::checkinto($line[1], '', @current)) { print""; } else { print""; } print""; print""; $idarp++ } print"
 
$Lang::tr{'wio_id'} $Lang::tr{'wio_hwaddress'} $Lang::tr{'wio ipadress'} $Lang::tr{'wio network'} $Lang::tr{'wio name'} $Lang::tr{'wio_iface'} $Lang::tr{'action'}
%02d$line[0] $line[1]$Lang::tr{$devs_alt[$in]}$Lang::tr{$Lang::tr{$line[2] ".&WIO::color_devices($line[3])."
$Lang::tr{
"; } &hrline(); print"
 $Lang::tr{'wio_import_file'}
"; if ( $wiosettings{'WIOGUISHOWCLIENTIMPORTTABLE'} eq 'on' ) { print"
 
$Lang::tr{'wio_import_csv'} 
 
$Lang::tr{'wio_import_hosts'}   
 
$Lang::tr{'wio_import_fixleases'}   
"; } &hrline; print"
 $Lang::tr{'wio_net_scan'}
"; if ( $wiosettings{'WIOGUISHOWNETWORKSEARCHTABLE'} eq 'on' ) { print" "; foreach (keys(%ifacecolor)) { if ( $_ eq 'GREEN' ) { $color = "$Header::colourgreen"; $net = $Lang::tr{'wio_net_scan_green'}; } elsif ( $_ eq 'BLUE' ) { $color = "$Header::colourblue"; $net = $Lang::tr{'wio_net_scan_blue'}; } else { $color = "$Header::colourorange"; $net = $Lang::tr{'wio_net_scan_orange'}; } if ( $netsettings{"${_}_DEV"} eq 'disabled' || $netsettings{"${_}_DEV"} eq '' || $netsettings{"${_}_ADDRESS"} eq '' ) { next; } else { print < END } } print"
 
$Lang::tr{'wio_net_scan_vl'} $net $Lang::tr{'wio_net_scan_l'} $netsettings{"${_}_DEV"} $Lang::tr{'wio_net_scan_r'}
-
 
"; } &Header::closebox(); } if ( $wiosettings{'ENABLE'} eq 'on' && !$errormessage && $wiosettings{'ACTION'} ne $Lang::tr{'edit'} || $message == 2 ) { &Header::openbox('100%', 'left', $Lang::tr{'wio_service'}); print" "; if ( $wiosettings{'LOGGING'} eq 'on' ) { print""; } print"
"; } &Header::closebox(); } &Header::closebigbox(); &Header::closepage(); ############################################################################################################################ sub SortDataFile { my ($data,@checkfile) = @_; my $idsort = 0; our %entries = (); sub sortips { my $qs = ''; if (rindex ($wiosettings{'SORT'},'Rev') != -1) { $qs = substr ($wiosettings{'SORT'},0,length($wiosettings{'SORT'})-3); if ($qs eq 'IPADR') { my @a = split (/\./,$entries{$a}->{$qs}); my @b = split (/\./,$entries{$b}->{$qs}); ($b[0]<=>$a[0]) || ($b[1]<=>$a[1]) || ($b[2]<=>$a[2]) || ($b[3]<=>$a[3]); } else { $entries{$b}->{$qs} cmp $entries{$a}->{$qs}; } } else { $qs = $wiosettings{'SORT'}; if ($qs eq 'IPADR') { my @a = split (/\./,$entries{$a}->{$qs}); my @b = split (/\./,$entries{$b}->{$qs}); ($a[0]<=>$b[0]) || ($a[1]<=>$b[1]) || ($a[2]<=>$b[2]) || ($a[3]<=>$b[3]); } else { $entries{$a}->{$qs} cmp $entries{$b}->{$qs}; } } } if ($data eq 'arpcache') { foreach (@checkfile) { chomp; @temp = split (',', $_); my @record = ('KEY',$idsort++,'MAC',$temp[0],'IPADR',$temp[1],'HOST',$temp[2],'REMARK',$temp[3],'IFACE',$temp[4]); my $record = (); %{$record} = @record; $entries{$record->{KEY}} = $record; } open(FILE, "> $logdir/.arpcache"); foreach (sort sortips keys %entries) { print FILE "$entries{$_}->{MAC},$entries{$_}->{IPADR},$entries{$_}->{HOST},$entries{$_}->{REMARK},$entries{$_}->{IFACE},$entries{$_}->{HW}\n"; } close(FILE); open (FILE, "$logdir/.arpcache"); @arpcache = ; close (FILE); } else { foreach (@checkfile) { chomp; @temp = split (',', $_); my @record = ('KEY',$idsort++,'CLIENTID',$temp[0],'TIMESTAMP',$temp[1],'IPADR',$temp[2],'HOST',$temp[3],'EN',$temp[4],'REMARK',$temp[5],'DYNDNS',$temp[6],'SENDEMAILON',$temp[7],'SENDEMAILOFF',$temp[8],'PINGMETHODE',$temp[9],'ONLINE',$temp[10],'WEBINTERFACE',$temp[11]); my $record = (); %{$record} = @record; $entries{$record->{KEY}} = $record; } open(FILE, "> $ipadrfile"); foreach (sort sortips keys %entries) { print FILE "$entries{$_}->{CLIENTID},$entries{$_}->{TIMESTAMP},$entries{$_}->{IPADR},$entries{$_}->{HOST},$entries{$_}->{EN},$entries{$_}->{REMARK},$entries{$_}->{DYNDNS},$entries{$_}->{SENDEMAILON},$entries{$_}->{SENDEMAILOFF},$entries{$_}->{PINGMETHODE},$entries{$_}->{ONLINE},$entries{$_}->{WEBINTERFACE}\n"; } close(FILE); &loadips(); } } ############################################################################################################################ sub hrline { print"

"; } ############################################################################################################################ sub back { print"
$Lang::tr{ 
"; } ############################################################################################################################ sub loadips { &General::readhasharray($ipadrfile, \%ipshash); open(FILE, "< $ipadrfile"); @current = ; close (FILE); } ############################################################################################################################ sub writeips { open(FILE, "> $ipadrfile"); if ( defined($write) ) { print FILE @write; } else { print FILE @current; } close(FILE); } ############################################################################################################################ sub SortByTunnelName { if ($vpnconfighash{$a}[1] lt $vpnconfighash{$b}[1]) { return -1; } elsif ($vpnconfighash{$a}[1] gt $vpnconfighash{$b}[1]) { return 1; } else { return 0; } } ############################################################################################################################ sub validSave { if ( $wiosettings{'IPADR'} eq '' && $wiosettings{'PINGMETHODE'} eq 'ip' && $wiosettings{'DYNDNS'} eq '' ) { $errormessage = $Lang::tr{'wio_ip_empty'}; } if ( $wiosettings{'IPADR'} ne '' && (! &General::validip($wiosettings{'IPADR'})) ) { $errormessage = $Lang::tr{'wio_ip_error'}; } if ( $wiosettings{'HOST'} eq '' && $wiosettings{'PINGMETHODE'} eq 'fqdn' ) { $errormessage = $Lang::tr{'wio_host_empty'}; } if ( $wiosettings{'HOST'} ne '' && (! &General::validdomainname($wiosettings{'HOST'})) ) { $errormessage = $Lang::tr{'wio_host_error'}; } if ( $wiosettings{'DYNDNS'} eq 'on' && (! defined($errormessage)) ) { unless(&General::validfqdn($wiosettings{'HOST'})) { $errormessage = $Lang::tr{'wio_fqdn_error'}; } ( $wiosettings{'IPADR'}, $infomessage ) = &WIO::getdyndnsip($wiosettings{'IPADR'}, $wiosettings{'HOST'}); $wiosettings{'PINGMETHODE'} = 'fqdn'; } if ( $wiosettings{'ID'} eq '' && ! defined($errormessage) ) { $errormessage = &WIO::checkinto($wiosettings{'IPADR'}, $wiosettings{'HOST'}, @current); } if ( $wiosettings{'REMARK'} ne '' ) { $wiosettings{'REMARK'} =~ s/,/,/g; } }