mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-15244, add ability to block ip addresses for HEAD.
This commit is contained in:
parent
fb94cd4848
commit
ab99c8f014
44
admin/ipblocker.php
Normal file
44
admin/ipblocker.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php // $Id$
|
||||
require('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$iplist = optional_param('list', '', PARAM_CLEAN);
|
||||
admin_externalpage_setup('ipblocker');
|
||||
|
||||
if ($form = data_submitted()) {
|
||||
if (confirm_sesskey()) {
|
||||
$ips = explode("\n", $iplist);
|
||||
$result = array();
|
||||
foreach($ips as $ip) {
|
||||
if(preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}$#', $ip, $match) ||
|
||||
preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}(\/\d{1,2})$#', $ip, $match) ||
|
||||
preg_match('#^(\d{1,3})(\.\d{1,3}){3}(-\d{1,3})$#', $ip, $match)) {
|
||||
$result[] = $ip;
|
||||
}
|
||||
}
|
||||
set_config('blockedip', serialize($result));
|
||||
}
|
||||
}
|
||||
|
||||
admin_externalpage_print_header();
|
||||
$iplist = unserialize(get_config(null, 'blockedip'));
|
||||
if(empty($iplist)) {
|
||||
$iplist = array();
|
||||
}
|
||||
$str = '';
|
||||
foreach($iplist as $ip){
|
||||
$str .= $ip."\n";
|
||||
}
|
||||
|
||||
echo '<div style="text-align:center;">';
|
||||
echo '<form method="post">';
|
||||
echo '<h1>'.get_string('blockediplist', 'admin').'</h1>';
|
||||
print_textarea(false, 20, 50, 600, 400, "list", $str);
|
||||
echo '<p><input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
echo '<input type="submit" value="'.get_string('submit').'" />';
|
||||
echo helpbutton('blockip', 'Help');
|
||||
echo '</p>';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
|
||||
admin_externalpage_print_footer();
|
||||
?>
|
@ -161,6 +161,8 @@ $ADMIN->add('server', $temp);
|
||||
|
||||
$ADMIN->add('server', new admin_externalpage('maintenancemode', get_string('sitemaintenancemode', 'admin'), "$CFG->wwwroot/$CFG->admin/maintenance.php"));
|
||||
|
||||
$ADMIN->add('server', new admin_externalpage('ipblocker', get_string('ipblocker', 'admin'), "$CFG->wwwroot/$CFG->admin/ipblocker.php"));
|
||||
|
||||
|
||||
$temp = new admin_settingpage('cleanup', get_string('cleanup', 'admin'));
|
||||
$temp->add(new admin_setting_configselect('longtimenosee', get_string('longtimenosee', 'admin'), get_string('configlongtimenosee', 'admin'), 120, array(0 => get_string('never'),
|
||||
|
@ -27,6 +27,7 @@ $string['backups'] = 'Backups';
|
||||
$string['badwordsconfig'] = 'Enter your list of bad words separated by commas.';
|
||||
$string['badwordsdefault'] = 'If the custom list is empty, a default list from the language pack will be used.';
|
||||
$string['badwordslist'] = 'Custom bad words list';
|
||||
$string['blockediplist'] = 'Blocked IP Address List';
|
||||
$string['blockinstances'] = 'Instances';
|
||||
$string['blockmultiple'] = 'Multiple';
|
||||
$string['blocksettings'] = 'Manage blocks';
|
||||
@ -413,6 +414,7 @@ $string['installedlangs'] = 'Installed language packs';
|
||||
$string['intcachemax'] = 'Int. cache max';
|
||||
$string['invalidsection'] = 'Invalid section.';
|
||||
$string['invaliduserchangeme'] = 'Username \"changeme\" is reserved -- you cannot create an account with it.';
|
||||
$string['ipblocker'] = 'IP Blocker';
|
||||
$string['iplookup'] = 'IP address lookup';
|
||||
$string['iplookupinfo'] = '
|
||||
By default Moodle uses the free online NetGeo (The Internet Geographic Database) server to lookup location of IP addresses, unfortunately this database is not maintained anymore and may return <em>wildly incorrect</em> data.
|
||||
|
@ -527,6 +527,18 @@ global $HTTPSPAGEREQUIRED;
|
||||
}
|
||||
}
|
||||
|
||||
$iplist = unserialize(get_config(null, 'blockedip'));
|
||||
if(!empty($iplist)) {
|
||||
foreach($iplist as $ip) {
|
||||
if(address_in_subnet(getremoteaddr(), $ip)){
|
||||
// Telling the banned user the site is not
|
||||
// available currently.
|
||||
echo get_string('sitemaintenance', 'admin');
|
||||
die;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// note: we can not block non utf-8 installatrions here, because empty mysql database
|
||||
/// might be converted to utf-8 in admin/index.php during installation
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user