fix to get IP-ranges working

This commit is contained in:
Ralf Becker 2004-05-04 09:51:17 +00:00
parent 257b69a6fb
commit 3b632d36c7

View File

@ -283,61 +283,38 @@
function checkip($remoteip='')
{
$allowed_ips = split(',',$GLOBALS['phpgw_info']['server']['setup_acl']);
if(!empty($GLOBALS['phpgw_info']['server']['setup_acl']) && is_array($allowed_ips) && count($allowed_ips) > 0)
//echo "<p>setup::checkip($remoteip) against setup_acl='".$GLOBALS['phpgw_info']['server']['setup_acl']."'</p>\n";
$allowed_ips = explode(',',$GLOBALS['phpgw_info']['server']['setup_acl']);
if(empty($GLOBALS['phpgw_info']['server']['setup_acl']) || !is_array($allowed_ips))
{
$foundip = False;
return True; // no test
}
$remotes = explode('.',$remoteip);
foreach($allowed_ips as $value)
{
if (!preg_match('/^[0-9.]$/',$value))
if (!preg_match('/^[0-9.]+$/',$value))
{
$value = gethostbyname($value); // resolve domain-name, eg. a dyndns account
$value = gethostbyname($was=$value); // resolve domain-name, eg. a dyndns account
//echo "resolving '$was' to '$value'<br>\n";
}
$test = split("\.",$value);
if(count($test) < 3)
$values = explode('.',$value);
for($i = 0; $i < count($values); ++$i)
{
$value .= ".0.0";
$tmp = split("\.",$remoteip);
$tmp[2] = 0;
$tmp[3] = 0;
$testremoteip = join('.',$tmp);
}
elseif(count($test) < 4)
if ((int) $values[$i] != (int) $remotes[$i])
{
$value .= ".0";
$tmp = split("\.",$remoteip);
$tmp[3] = 0;
$testremoteip = join('.',$tmp);
}
elseif(count($test) == 4 &&
(int)$test[3] == 0)
{
$tmp = split("\.",$remoteip);
$tmp[3] = 0;
$testremoteip = join('.',$tmp);
}
else
{
$testremoteip = $remoteip;
}
//echo '<br>testing: ' . $testremoteip . ' compared to ' . $value;
if($testremoteip == $value)
{
//echo ' - PASSED!';
$foundip = True;
break;
}
}
if(!$foundip)
if ($i == count($values))
{
return True; // match
}
}
$GLOBALS['phpgw_info']['setup']['HeaderLoginMSG'] = '';
$GLOBALS['phpgw_info']['setup']['ConfigLoginMSG'] = lang('Invalid IP address');
return False;
}
}
return True;
}
/*!
@function get_major