MDL-15244, add ability to block ip addresses.

This commit is contained in:
dongsheng 2008-07-16 02:16:42 +00:00
parent 972485277e
commit 4e63912156
5 changed files with 90 additions and 79 deletions

View file

@ -527,15 +527,33 @@ global $HTTPSPAGEREQUIRED;
}
}
$iplist = unserialize(get_config(null, 'blockedip'));
if(!empty($iplist)) {
foreach($iplist as $ip) {
$allowediponly = get_config(null, 'enableallowedip');
if(!empty($allowediponly)){
$allowediplist = get_config(null, 'allowedip');
$blockediplist = get_config(null, 'blockedip');
} else {
$blockediplist = get_config(null, 'blockedip');
}
if(!empty($blockediplist)) {
$blockediplist = explode("\n", $blockediplist);
foreach($blockediplist as $ip) {
$ip = trim($ip);
if(address_in_subnet(getremoteaddr(), $ip)){
// Telling the banned user the site is not
// available currently.
echo get_string('sitemaintenance', 'admin');
die;
}
die(get_string('ipinblockedlist', 'admin'));
}
}
}
if(!empty($allowediplist)) {
$allowediplist = explode("\n", $allowediplist);
foreach($allowediplist as $ip) {
$ip = trim($ip);
if(!address_in_subnet(getremoteaddr(), $ip)){
// Telling users only specfied users are
// allowed accessing this site.
die(get_string('ipoutallowedlist', 'admin'));
}
}
}