MDL-49087 mnet: Use real dataroot instead of user-provided
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
5f0bfb120f
commit
240e7be734
+32
-13
@@ -31,14 +31,12 @@
|
||||
* --typeroot=/var/www/moodle/htdocs/blocks
|
||||
* --name=loancalc
|
||||
* --md5=...
|
||||
* --dataroot=/var/www/moodle/data
|
||||
*
|
||||
* $ sudo -u apache php mdeploy.php --upgrade \
|
||||
* --package=https://moodle.org/plugins/download.php/...zip \
|
||||
* --typeroot=/var/www/moodle/htdocs/blocks
|
||||
* --name=loancalc
|
||||
* --md5=...
|
||||
* --dataroot=/var/www/moodle/data
|
||||
*
|
||||
* When called via HTTP, additional parameters returnurl, passfile and password must be
|
||||
* provided. Optional proxy configuration can be passed using parameters proxy, proxytype
|
||||
@@ -60,6 +58,13 @@ if (defined('MOODLE_INTERNAL')) {
|
||||
die('This is a standalone utility that should not be included by any other Moodle code.');
|
||||
}
|
||||
|
||||
// This stops immediately at the beginning of lib/setup.php.
|
||||
define('ABORT_AFTER_CONFIG', true);
|
||||
if (PHP_SAPI === 'cli') {
|
||||
// Called from the CLI - we need to set CLI_SCRIPT to ensure that appropriate CLI checks are made in setup.php.
|
||||
define('CLI_SCRIPT', true);
|
||||
}
|
||||
require(__DIR__ . '/config.php');
|
||||
|
||||
// Exceptions //////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -201,7 +206,6 @@ class input_manager extends singleton_pattern {
|
||||
array('', 'proxytype', input_manager::TYPE_RAW, 'Proxy type (HTTP or SOCKS5)'),
|
||||
array('', 'proxyuserpwd', input_manager::TYPE_RAW, 'Proxy username and password (e.g. \'username:password\')'),
|
||||
array('', 'returnurl', input_manager::TYPE_URL, 'Return URL (HTTP access only)'),
|
||||
array('d', 'dataroot', input_manager::TYPE_PATH, 'Full path to the dataroot (moodledata) directory'),
|
||||
array('h', 'help', input_manager::TYPE_FLAG, 'Prints usage information'),
|
||||
array('i', 'install', input_manager::TYPE_FLAG, 'Installation mode'),
|
||||
array('m', 'md5', input_manager::TYPE_MD5, 'Expected MD5 hash of the ZIP package to deploy'),
|
||||
@@ -909,17 +913,15 @@ class worker extends singleton_pattern {
|
||||
* @throws unauthorized_access_exception
|
||||
*/
|
||||
protected function authorize() {
|
||||
|
||||
if (PHP_SAPI === 'cli') {
|
||||
$this->log('Successfully authorized using the CLI SAPI');
|
||||
return;
|
||||
}
|
||||
|
||||
$dataroot = $this->input->get_option('dataroot');
|
||||
$passfile = $this->input->get_option('passfile');
|
||||
$password = $this->input->get_option('password');
|
||||
|
||||
$passpath = $dataroot.'/mdeploy/auth/'.$passfile;
|
||||
$passpath = $this->get_env('dataroot') . '/mdeploy/auth/' . $passfile;
|
||||
|
||||
if (!is_readable($passpath)) {
|
||||
throw new unauthorized_access_exception('Unable to read the passphrase file.');
|
||||
@@ -959,12 +961,11 @@ class worker extends singleton_pattern {
|
||||
* @return string
|
||||
*/
|
||||
protected function log_location() {
|
||||
|
||||
if (!is_null($this->logfile)) {
|
||||
return $this->logfile;
|
||||
}
|
||||
|
||||
$dataroot = $this->input->get_option('dataroot', '');
|
||||
$dataroot = $this->get_env('dataroot');
|
||||
|
||||
if (empty($dataroot)) {
|
||||
$this->logfile = false;
|
||||
@@ -988,8 +989,7 @@ class worker extends singleton_pattern {
|
||||
* @return string
|
||||
*/
|
||||
protected function target_location($source) {
|
||||
|
||||
$dataroot = $this->input->get_option('dataroot');
|
||||
$dataroot = $this->get_env('dataroot');
|
||||
$pool = $dataroot.'/mdeploy/var';
|
||||
|
||||
if (!is_dir($pool)) {
|
||||
@@ -1013,8 +1013,7 @@ class worker extends singleton_pattern {
|
||||
* @return string
|
||||
*/
|
||||
protected function backup_location($path) {
|
||||
|
||||
$dataroot = $this->input->get_option('dataroot');
|
||||
$dataroot = $this->get_env('dataroot');
|
||||
$pool = $dataroot.'/mdeploy/archive';
|
||||
|
||||
if (!is_dir($pool)) {
|
||||
@@ -1129,12 +1128,32 @@ class worker extends singleton_pattern {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch environment settings.
|
||||
*
|
||||
* @param string $key The key to fetch
|
||||
* @return mixed The value of the key if found, null if not found.
|
||||
*/
|
||||
protected function get_env($key) {
|
||||
global $CFG;
|
||||
|
||||
switch ($key) {
|
||||
case 'dataroot':
|
||||
if (isset($CFG->dataroot)) {
|
||||
return $CFG->dataroot;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location of ca certificates.
|
||||
* @return string absolute file path or empty if default used
|
||||
*/
|
||||
protected function get_cacert() {
|
||||
$dataroot = $this->input->get_option('dataroot');
|
||||
$dataroot = $this->get_env('dataroot');
|
||||
|
||||
// Bundle in dataroot always wins.
|
||||
if (is_readable($dataroot.'/moodleorgca.crt')) {
|
||||
|
||||
Reference in New Issue
Block a user