diff --git a/classes/module/ModuleHandler.class.php b/classes/module/ModuleHandler.class.php index ec48e4c5b..14975b103 100644 --- a/classes/module/ModuleHandler.class.php +++ b/classes/module/ModuleHandler.class.php @@ -1226,6 +1226,38 @@ class ModuleHandler extends Handler $oDisplayHandler->printContent($oModule); } + /** + * Process command line arguments. + * + * @param array $args + * @return void + */ + public static function procCommandLineArguments(array $args) + { + $command = count($args) > 1 ? $args[1] : ''; + $args = count($args) > 2 ? array_slice($args, 2) : []; + if (!$command) + { + echo 'Command not supplied.' . PHP_EOL; + exit(1); + } + if (!preg_match('/^([a-z0-9_-]+)\.([a-z0-9_-]+)$/', $command, $matches)) + { + echo 'Invalid command: ' . $command . PHP_EOL; + exit(1); + } + + $path = sprintf('%s%s/scripts/%s.php', \RX_BASEDIR , $matches[1] === 'common' ? 'common' : ('modules/' . $matches[1]), $matches[2]); + if (!file_exists($path) || !is_readable($path)) + { + echo 'Command not found: ' . $command . PHP_EOL; + exit(1); + } + + require_once \RX_BASEDIR . 'common/scripts/common.php'; + require_once $path; + } + /** * returns module's path * @param string $module module name diff --git a/common/scripts/common.php b/common/scripts/common.php index 53fd332dd..17abecdb3 100644 --- a/common/scripts/common.php +++ b/common/scripts/common.php @@ -34,10 +34,13 @@ if ($uid === 0) echo "This script must NOT be executed by the root user.\n"; exit(2); } -$web_server_uid = fileowner(RX_BASEDIR . 'files/config/config.php'); -if ($uid !== $web_server_uid) +if (file_exists(\RX_BASEDIR . 'files/config/config.php')) { - $web_server_uid = posix_getpwuid($web_server_uid); - echo "This script must be executed by the same user as the usual web server process ({$web_server_uid['name']}).\n"; - exit(3); + $web_server_uid = fileowner(\RX_BASEDIR . 'files/config/config.php'); + if ($uid !== $web_server_uid) + { + $web_server_uid = posix_getpwuid($web_server_uid); + echo "This script must be executed by the same user as the usual web server process ({$web_server_uid['name']}).\n"; + exit(3); + } } diff --git a/index.php b/index.php index 06c06039f..701e4ed92 100644 --- a/index.php +++ b/index.php @@ -47,6 +47,14 @@ Context::init(); /** * Initialize and execute the requested module. */ -$oModuleHandler = new ModuleHandler(); -$oModuleHandler->init() && $oModuleHandler->displayContent($oModuleHandler->procModule()); -Context::close(); +if (PHP_SAPI !== 'cli') +{ + $oModuleHandler = new ModuleHandler(); + $oModuleHandler->init() && $oModuleHandler->displayContent($oModuleHandler->procModule()); + Context::close(); +} +else +{ + Rhymix\Framework\Debug::disable(); + ModuleHandler::procCommandLineArguments($argv); +}