?
*
* @access public
*
* @see PMA_getIp()
*/
function PMA_allowDeny($type)
{
global $cfg;
// Grabs true IP of the user and returns if it can't be found
$remote_ip = PMA_getIp();
if (empty($remote_ip)) {
return FALSE;
}
// copy username
$username = $cfg['Server']['user'];
// copy rule database
$rules = $cfg['Server']['AllowDeny']['rules'];
// lookup table for some name shortcuts
$shortcuts = array(
'all' => '0.0.0.0/0',
'localhost' => '127.0.0.1/8'
);
// Provide some useful shortcuts if server gives us address:
if (PMA_getenv('SERVER_ADDR')) {
$shortcuts['localnetA'] = PMA_getenv('SERVER_ADDR') . '/8';
$shortcuts['localnetB'] = PMA_getenv('SERVER_ADDR') . '/16';
$shortcuts['localnetC'] = PMA_getenv('SERVER_ADDR') . '/24';
}
foreach ($rules AS $rule) {
// extract rule data
$rule_data = explode(' ', $rule);
// check for rule type
if ($rule_data[0] != $type) {
continue;
}
// check for username
if (($rule_data[1] != '%') //wildcarded first
&& ($rule_data[1] != $username)) {
continue;
}
// check if the config file has the full string with an extra
// 'from' in it and if it does, just discard it
if ($rule_data[2] == 'from') {
$rule_data[2] = $rule_data[3];
}
// Handle shortcuts with above array
// DON'T use "array_key_exists" as it's only
PHP 4.1 and newer.
if (isset($shortcuts[$rule_data[2]])) {
$rule_data[2] = $shortcuts[$rule_data[2]];
}
// Add code for host lookups here
// Excluded for the moment
// Do the actual matching now
if (PMA_ipMaskTest($rule_data[2], $remote_ip)) {
return TRUE;
}
} // end while
return FALSE;
} // end of the "PMA_AllowDeny()" function
?>