--- /dev/null
+<?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();
+?>
$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'),
$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';
$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.
}
}
+ $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
?>