diff --git a/lang/en/admin.php b/lang/en/admin.php index 275640438ca..dca5bfa8846 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -503,7 +503,7 @@ $string['errorsetting'] = 'Could not save setting:'; $string['errorwithsettings'] = 'Some settings were not changed due to an error.'; $string['everyonewhocan'] = 'Everyone who can \'{$a}\''; $string['exceptions'] = 'exceptions'; -$string['execpathnotallowed'] = 'Setting executable paths disabled in config.php'; +$string['execpathnotallowed'] = 'Setting executable and local paths disabled in config.php'; $string['experimental'] = 'Experimental'; $string['experimentalsettings'] = 'Experimental settings'; $string['extendedusernamechars'] = 'Allow extended characters in usernames'; diff --git a/lib/adminlib.php b/lib/adminlib.php index f2c96b5c097..b4be4cdf01b 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -2418,6 +2418,7 @@ class admin_setting_configfile extends admin_setting_configtext { * @return string XHTML field */ public function output_html($data, $query='') { + global $CFG; $default = $this->get_defaultsetting(); if ($data) { @@ -2429,9 +2430,14 @@ class admin_setting_configfile extends admin_setting_configtext { } else { $executable = ''; } + $readonly = ''; + if (!empty($CFG->preventexecpath)) { + $this->visiblename .= '
'.get_string('execpathnotallowed', 'admin').'
'; + $readonly = 'readonly="readonly"'; + } return format_admin_setting($this, $this->visiblename, - '
'.$executable.'
', + '
'.$executable.'
', $this->description, true, '', $default, $query); } @@ -2483,12 +2489,14 @@ class admin_setting_configexecutable extends admin_setting_configfile { } else { $executable = ''; } + $readonly = ''; if (!empty($CFG->preventexecpath)) { $this->visiblename .= '
'.get_string('execpathnotallowed', 'admin').'
'; + $readonly = 'readonly="readonly"'; } return format_admin_setting($this, $this->visiblename, - '
'.$executable.'
', + '
'.$executable.'
', $this->description, true, '', $default, $query); } } @@ -2509,6 +2517,7 @@ class admin_setting_configdirectory extends admin_setting_configfile { * @return string XHTML */ public function output_html($data, $query='') { + global $CFG; $default = $this->get_defaultsetting(); if ($data) { @@ -2520,9 +2529,14 @@ class admin_setting_configdirectory extends admin_setting_configfile { } else { $executable = ''; } + $readonly = ''; + if (!empty($CFG->preventexecpath)) { + $this->visiblename .= '
'.get_string('execpathnotallowed', 'admin').'
'; + $readonly = 'readonly="readonly"'; + } return format_admin_setting($this, $this->visiblename, - '
'.$executable.'
', + '
'.$executable.'
', $this->description, true, '', $default, $query); } } diff --git a/lib/tests/admintree_test.php b/lib/tests/admintree_test.php index 24677af09ff..8a377b7598e 100644 --- a/lib/tests/admintree_test.php +++ b/lib/tests/admintree_test.php @@ -272,7 +272,7 @@ class core_admintree_testcase extends advanced_testcase { $setting->write_setting('/mm/nn'); $this->assertSame('', get_config('abc_cde', 'execpath')); - // This also (most probably incorrectly) affects admin_setting_configfile. + // This also affects admin_setting_configfile and admin_setting_configdirectory. set_config('preventexecpath', 0); set_config('execpath', null, 'abc_cde'); @@ -297,5 +297,27 @@ class core_admintree_testcase extends advanced_testcase { $setting->write_setting('/mm/nn'); $this->assertSame('', get_config('abc_cde', 'execpath')); + set_config('preventexecpath', 0); + set_config('execpath', null, 'abc_cde'); + $this->assertFalse(get_config('abc_cde', 'execpath')); + $setting = new admin_setting_configdirectory('abc_cde/execpath', 'some desc', '', '/xx/yy'); + $setting->write_setting('/oo/pp'); + $this->assertSame('/oo/pp', get_config('abc_cde', 'execpath')); + + // Prevent changes. + set_config('preventexecpath', 1); + $setting->write_setting('/mm/nn'); + $this->assertSame('/oo/pp', get_config('abc_cde', 'execpath')); + + // Use default in install. + set_config('execpath', null, 'abc_cde'); + $setting->write_setting('/mm/nn'); + $this->assertSame('/xx/yy', get_config('abc_cde', 'execpath')); + + // Use empty value if no default. + $setting = new admin_setting_configdirectory('abc_cde/execpath', 'some desc', '', null); + set_config('execpath', null, 'abc_cde'); + $setting->write_setting('/mm/nn'); + $this->assertSame('', get_config('abc_cde', 'execpath')); } }