}
}
&General::writehasharray("$confighost", \%customhost);
-
-
-
$fwhostsettings{'actualize'} = 'on';
$fwhostsettings{'ACTION'} = 'savehost';
}
my $count=0;
my $needrules=0;
$errormessage=&checkports(\%customservice);
-
if (!$errormessage){
&General::readhasharray("$configsrv", \%customservice);
foreach my $key (keys %customservice)
$fwhostsettings{'SRV_NAME'} = '';
$fwhostsettings{'SRV_PORT'} = '';
$fwhostsettings{'PROT'} = '';
-
}else{
$fwhostsettings{'SRV_NAME'} = $fwhostsettings{'oldsrvname'};
$fwhostsettings{'SRV_PORT'} = $fwhostsettings{'oldsrvport'};
$fwhostsettings{'PROT'} = $fwhostsettings{'oldsrvprot'};
$fwhostsettings{'updatesrv'}= 'on';
}
-
if($needrules eq 'on'){
$errormessage="reread!";
&rules;
}
-
&addservice;
}
# save
my $count=0;
my $needrules=0;
if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
-
#check if all fields are set
if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
{
if(&General::iporsubtocidr($fwhostsettings{'SUBNET'}) eq '32')
{
$errormessage=$errormessage.$Lang::tr{'fwhost err sub32'};
-
}
if($fwhostsettings{'error'} ne 'on'){
#check if we use one of ipfire's networks (green,orange,blue)
if (!$errormessage){
&plausicheck("editnet");
}
-
#check if network ip is part of an already used one
if(&checksubnet(\%customnetwork))
{
$errormessage=$errormessage.$Lang::tr{'fwhost err partofnet'};
$fwhostsettings{'HOSTNAME'} = $fwhostsettings{'orgname'};
}
-
if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newnet'} ne 'on' && $errormessage)
{
$fwhostsettings{'actualize'} = '';
&General::writehasharray("$confignet", \%customnetwork);
undef %customnetwork;
}
-
if (!$errormessage){
&General::readhasharray("$confignet", \%customnetwork);
if ($fwhostsettings{'ACTION'} eq 'updatenet'){
&viewtablenet;
}
}
-
}
if ($fwhostsettings{'ACTION'} eq 'savehost')
{
my $count=0;
my $needrules=0;
if ($fwhostsettings{'orgname'} eq ''){$fwhostsettings{'orgname'}=$fwhostsettings{'HOSTNAME'};}
-
$fwhostsettings{'SUBNET'}='32';
-
#check if all fields are set
if ($fwhostsettings{'HOSTNAME'} eq '' || $fwhostsettings{'IP'} eq '' || $fwhostsettings{'SUBNET'} eq '')
{
$errormessage=$errormessage.$Lang::tr{'fwhost err empty'};
$fwhostsettings{'ACTION'} = 'edithost';
}else{
-
if($fwhostsettings{'type'} eq 'ip' && $fwhostsettings{'IP'}=~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/){
$fwhostsettings{'type'} = 'mac';
}elsif($fwhostsettings{'type'} eq 'mac' && $fwhostsettings{'IP'}=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/){
$fwhostsettings{'type'} = '';
$errormessage=$Lang::tr{'fwhost err ipmac'};
}
-
if($fwhostsettings{'type'} eq 'mac' )
{
if ($fwhostsettings{'IP'}!~/^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$/ )
{
$errormessage=$Lang::tr{'fwhost err mac'};
-
}
}
#CHECK IP-PART
$errormessage.=$errormessage.$Lang::tr{'fwhost err ip'};
$fwhostsettings{'error'}='on';
}
-
}elsif(rindex($fwhostsettings{'IP'},'/') ne '-1' ){
$errormessage=$errormessage.$Lang::tr{'fwhost err ipwithsub'};
$fwhostsettings{'error'}='on';
$errormessage=$Lang::tr{'fwhost err hostip'};
}
}
-
-
-
#only check plausi when no error till now
if (!$errormessage){
&plausicheck("edithost");
}
-
if($fwhostsettings{'actualize'} eq 'on' && $fwhostsettings{'newhost'} ne 'on' && $errormessage){
$fwhostsettings{'actualize'} = '';
my $key = &General::findhasharraykey (\%customhost);
$customhost{$key}[3] = $fwhostsettings{'count'};
&General::writehasharray("$confighost", \%customhost);
undef %customhost;
-
}
-
if (!$errormessage){
#get count if host was edited
if($fwhostsettings{'actualize'} eq 'on'){
if($fwhostsettings{'newhost'} eq 'on'){$count=0;}
$customhost{$key}[3] = $count;
&General::writehasharray("$confighost", \%customhost);
-
#$fwhostsettings{'IP'} = $fwhostsettings{'IP'}."/".&General::iporsubtodec($fwhostsettings{'SUBNET'});
undef %customhost;
$fwhostsettings{'HOSTNAME'}='';
&addhost;
&viewtablehost;
}
-
}
-
}
if ($fwhostsettings{'ACTION'} eq 'savegrp')
{
&General::readhasharray("$confignet", \%customnetwork);
&General::readhasharray("$confighost", \%customhost);
$grp=$fwhostsettings{'grp_name'};
-
- if (!&General::validhostname($grp)){$errormessage=$errormessage.$Lang::tr{'fwhost err name'};}
+ if (!&validhostname($grp)){$errormessage=$errormessage.$Lang::tr{'fwhost err name'};}
###check standard networks
if ($fwhostsettings{'grp2'} eq 'std_net'){
@target=$fwhostsettings{'DEFAULT_SRC_ADR'};
$customgrp{$key}[4] = $count;
}
&General::writehasharray("$configgrp", \%customgrp);
-
#update counter in Host/Net
if($updcounter eq 'net'){
foreach my $key (keys %customnetwork) {
if ($fwhostsettings{'ACTION'} eq 'saveservice')
{
my $ICMP;
-
&General::readhasharray("$configsrv", \%customservice );
$errormessage=&checkports(\%customservice);
-
if ($fwhostsettings{'PROT'} eq 'ICMP'){
&General::readhasharray("${General::swroot}/fwhosts/icmp-types", \%icmptypes);
foreach my $key (keys %icmptypes){
}
if($ICMP eq ''){$ICMP='BLANK';}
if (!$errormessage){
-
my $key = &General::findhasharraykey (\%customservice);
foreach my $i (0 .. 4) { $customservice{$key}[$i] = "";}
$customservice{$key}[0] = $fwhostsettings{'SRV_NAME'};
$fwhostsettings{'SRV_PORT'}='';
$fwhostsettings{'PROT'}='';
$fwhostsettings{'ICMP_TYPES'}='';
-
}
-
&addservice;
-
}
if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
{
my $count=0;
&General::readhasharray("$configsrvgrp", \%customservicegrp );
&General::readhasharray("$configsrv", \%customservice );
-
$errormessage=&checkservicegroup;
-
if (!$errormessage){
#on first save, we have to enter a dummy value
if ($fwhostsettings{'CUST_SRV'} eq ''){$fwhostsettings{'CUST_SRV'}=$Lang::tr{'fwhost empty'};}
-
#on update, we have to delete the dummy entry
foreach my $key (keys %customservicegrp){
if ($customservicegrp{$key}[2] eq $Lang::tr{'fwhost empty'}){
}
}
&General::writehasharray("$configsrv", \%customservice );
-
my $key = &General::findhasharraykey (\%customservicegrp);
foreach my $i (0 .. 3) { $customservice{$key}[$i] = "";}
$customservicegrp{$key}[0] = $fwhostsettings{'SRVGRP_NAME'};
$customservicegrp{$key}[1] = $fwhostsettings{'SRVGRP_REMARK'};
$customservicegrp{$key}[2] = $fwhostsettings{'CUST_SRV'};
$customservicegrp{$key}[3] = $count;
-
&General::writehasharray("$configsrvgrp", \%customservicegrp );
$fwhostsettings{'updatesrvgrp'}='on';
}
}
&addhost;
&viewtablehost;
-
}
if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
{
#check name
- if ( ! &General::validhostname($fwhostsettings{'SRVGRP_NAME'}))
+ if ( ! &validhostname($fwhostsettings{'SRVGRP_NAME'}))
{
$errormessage.=$Lang::tr{'fwhost err name'}."<br>";
return $errormessage;
$errormessage=$Lang::tr{'fwhost err port'};
}
#check valid name
- if (! &General::validhostname($fwhostsettings{'SRV_NAME'})){
+ if (! &validhostname($fwhostsettings{'SRV_NAME'})){
$errormessage="<br>".$Lang::tr{'fwhost err name'};
}
#change dashes with :
if (length ($hostname) < 1 || length ($hostname) > 63) {
return 0;}
# Only valid characters are a-z, A-Z, 0-9 and -
- if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-\s]*$/) {
+ if ($hostname !~ /^[a-zA-ZäöüÖÄÜ0-9-_()\/\s]*$/) {
return 0;}
# First character can only be a letter or a digit
if (substr ($hostname, 0, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
return 0;}
# Last character can only be a letter or a digit
- if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9]*$/) {
+ if (substr ($hostname, -1, 1) !~ /^[a-zA-ZöäüÖÄÜ0-9()]*$/) {
return 0;}
return 1;
}