+++ /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('ipblocker', get_string('ipblocker', 'admin'));
+$temp->add(new admin_setting_configcheckbox('enableallowedip', get_string('enableallowedip', 'admin'), get_string('enableallowedipdesc', 'admin'), 0));
+$temp->add(new admin_setting_configiplist('allowedip', get_string('allowediplist', 'admin'),
+ '', ''));
+$temp->add(new admin_setting_configiplist('blockedip', get_string('blockediplist', 'admin'),
+ '', ''));
+$ADMIN->add('server', $temp);
$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['allowcategorythemes'] = 'Allow category themes';
$string['allowcoursethemes'] = 'Allow course themes';
$string['allowdeletes'] = 'Allow deletes';
+$string['allowediplist'] = 'Allowed IP list';
$string['allowemailaddresses'] = 'Allowed email domains';
$string['allowobjectembed'] = 'Allow EMBED and OBJECT tags';
$string['allowrenames'] = 'Allow renames';
$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['blockediplist'] = 'Blocked IP List';
$string['blockinstances'] = 'Instances';
$string['blockmultiple'] = 'Multiple';
$string['blocksettings'] = 'Manage blocks';
$string['enablerssfeeds'] = 'Enable RSS feeds';
$string['enablestats'] = 'Enable statistics';
$string['enabletrusttext'] = 'Enable Trusted Content';
+$string['enableallowedip'] = 'Allow clients from these IPs';
+$string['enableallowedipdesc'] = 'If this option enabled, only IPs entered in allowed list are permitted, IPs are in blocked list are blocked at the same time.';
$string['encoding'] = 'Encoding';
$string['enrolmultipleusers'] = 'Enrol the users';
$string['environment'] = 'Environment';
$string['invalidsection'] = 'Invalid section.';
$string['invaliduserchangeme'] = 'Username \"changeme\" is reserved -- you cannot create an account with it.';
$string['ipblocker'] = 'IP Blocker';
+$string['ipinblockedlist'] = 'This site is not available currently.';
+$string['ipoutallowedlist'] = 'This site is not available currently.';
$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.
$dbdirs[] = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$plugin.'/db';
}
}
-
+
/// Now quiz report plugins (mod/quiz/report/xxx/db)
if ($plugins = get_list_of_plugins('mod/quiz/report', 'db')) {
foreach ($plugins as $plugin) {
$data = 0;
}
// $data is a string
- $validated = $this->validate($data);
+ $validated = $this->validate($data);
if ($validated !== true) {
return $validated;
}
$defaultinfo = $default;
if (!is_null($default) and $default !== '') {
$defaultinfo = "\n".$default;
- }
+ }
return format_admin_setting($this, $this->visiblename,
'<div class="form-textarea form-textarea-advanced" ><textarea rows="'. $this->rows .'" cols="'. $this->cols .'" id="'. $this->get_id() .'" name="'. $this->get_full_name() .'">'. s($data) .'</textarea></div>',
$return .= '</div>';
return format_admin_setting($this, $this->visiblename, $return, $this->description, false, '', $defaultinfo, $query);
-
+
}
}
if (strpos($textlib->strtolower($value), $query) !== false) {
return true;
}
- }
+ }
return false;
}
}
+class admin_setting_configiplist extends admin_setting_configtextarea {
+ function validate($data) {
+ if(!empty($data)) {
+ $ips = explode("\n", $data);
+ } else {
+ return true;
+ }
+ $result = true;
+ foreach($ips as $ip) {
+ $ip = trim($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 = true;
+ } else {
+ $result = false;
+ break;
+ }
+ }
+ if($result){
+ return true;
+ } else {
+ return get_string('validateerror', 'admin');
+ }
+ }
+}
+
/**
* Special checkbox for calendar - resets SESSION vars.
*/
function write_setting($data) {
global $DB;
$data = trim($data);
- $validated = $this->validate($data);
+ $validated = $this->validate($data);
if ($validated !== true) {
return $validated;
}
}
return $return;
- }
+ }
}
/**
$defaultinfo[] = get_string('advanced');
}
$defaultinfo = implode(', ', $defaultinfo);
-
+
} else {
$defaultinfo = NULL;
}
/**
* Prints tables of detected plugins, one table per plugin type,
- * and prints whether they are part of the standard Moodle
+ * and prints whether they are part of the standard Moodle
* distribution or not.
*/
function print_plugin_tables() {
'scorm',
'survey',
'wiki');
-
+
$plugins_standard['blocks'] = array('activity_modules',
'admin',
'admin_bookmarks',
'tag_flickr',
'tag_youtube',
'tags');
-
+
$plugins_standard['filter'] = array('activitynames',
'algebra',
'censor',
$plugins_ondisk['mod'] = get_list_of_plugins('mod', 'db');
$plugins_ondisk['blocks'] = get_list_of_plugins('blocks', 'db');
$plugins_ondisk['filter'] = get_list_of_plugins('filter', 'db');
-
+
$strstandard = get_string('standard');
$strnonstandard = get_string('nonstandard');
$strmissingfromdisk = '(' . get_string('missingfromdisk') . ')';
$strabouttobeinstalled = '(' . get_string('abouttobeinstalled') . ')';
$html = '';
-
+
$html .= '<table class="generaltable plugincheckwrapper" cellspacing="4" cellpadding="1"><tr valign="top">';
foreach ($plugins_ondisk as $cat => $list_ondisk) {
$html .= '<tr class="r0"><th class="header c0">' . get_string('directory') . "</th>\n"
. '<th class="header c1">' . get_string('name') . "</th>\n"
. '<th class="header c2">' . get_string('status') . "</th>\n</tr>\n";
-
- $row = 1;
+
+ $row = 1;
foreach ($list_ondisk as $k => $plugin) {
$status = 'ok';
if (!in_array($plugin, $plugins_standard[$cat])) {
$standard = 'nonstandard';
$status = 'warning';
- }
-
+ }
+
// Get real name and full path of plugin
$plugin_name = "[[$plugin]]";
-
+
$plugin_path = "$cat/$plugin";
-
+
$plugin_name = get_plugin_name($plugin, $cat);
-
+
// Determine if the plugin is about to be installed
if ($cat != 'filter' && !in_array($plugin, $plugins_installed[$cat])) {
$note = $strabouttobeinstalled;
// If the plugin was both on disk and in the db, unset the value from the installed plugins list
if ($key = array_search($plugin, $plugins_installed[$cat])) {
unset($plugins_installed[$cat][$key]);
- }
- }
+ }
+ }
// If there are plugins left in the plugins_installed list, it means they are missing from disk
- foreach ($plugins_installed[$cat] as $k => $missing_plugin) {
+ foreach ($plugins_installed[$cat] as $k => $missing_plugin) {
// Make sure the plugin really is missing from disk
if (!in_array($missing_plugin, $plugins_ondisk[$cat])) {
$standard = 'standard';
. "<td class=\"cell c0\">?</td>\n"
. "<td class=\"cell c1\">$plugin_name</td>\n"
. "<td class=\"$standard $status cell c2\">" . ${'str' . $standard} . " $strmissingfromdisk</td>\n</tr>\n";
- $row++;
+ $row++;
}
}
$html .= '</table></td>';
}
-
+
$html .= '</tr></table><br />';
-
+
echo $html;
}
}
}
- $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'));
+ }
}
}