From 5e93dfe6042ec192f0f413ccd24e78bf5848a4d8 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sun, 25 Mar 2018 21:15:45 +0200 Subject: [PATCH] postfixadmin-cli: drop (undocumented) -webroot etc. Dropping the -webroot parameter (which basically means hardcoding that ../common.php has to exist) allows to do quite some cleanup. Also unconditionally require_once('../common.php') to ensure that everything we expect in the global namespace (like the 'Conf' class) is there. This allows even more cleanup. We get rid of __bootstrap() and some constants, and can simplify parameter handling. --- scripts/postfixadmin-cli.php | 50 ++---------------------------------- 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/scripts/postfixadmin-cli.php b/scripts/postfixadmin-cli.php index 43784222..1399d611 100644 --- a/scripts/postfixadmin-cli.php +++ b/scripts/postfixadmin-cli.php @@ -1,10 +1,6 @@ #!/usr/bin/php stdout = fopen('php://stdout', 'w'); $this->stderr = fopen('php://stderr', 'w'); - if (!$this->__bootstrap()) { - $this->stderr(""); - $this->stderr("Unable to load."); - $this->stderr("\tMake sure /config.inc.php exists in " . PATH); - exit(1); - } - - if (basename(__FILE__) != basename($this->args[0])) { $this->stderr('Warning: the dispatcher may have been loaded incorrectly, which could lead to unexpected results...'); if ($this->getInput('Continue anyway?', array('y', 'n'), 'y') == 'n') { @@ -165,33 +148,6 @@ class PostfixAdmin { $this->shiftArgs(); } - /** - * Initializes the environment and loads the Cake core. - * - * @return boolean Success. - */ - private function __bootstrap() { - if ($this->params['webroot'] != '') { - define('PATH', $this->params['webroot']); - } else { - define('PATH', CORE_PATH); - } - - if (!file_exists(PATH)) { - $this->stderr(PATH . " don't exists"); - return false; - } - - # make sure global variables fron functions.inc.php end up in the global namespace, instead of being local to this function - global $version, $min_db_version; - - if (!require_once(PATH . '/common.php')) { - $this->stderr("Failed to load " . PATH . '/common.php'); - return false; - } - return true; - } - /** * Dispatches a CLI request */ @@ -374,10 +330,6 @@ class PostfixAdmin { public function parseParams($params) { $this->__parseParams($params); - $defaults = array('webroot' => CORE_PATH); - - $params = array_merge($defaults, array_intersect_key($this->params, $defaults)); - $isWin = array_filter(array_map('strpos', $params, array('\\'))); $params = str_replace('\\', '/', $params); @@ -476,6 +428,8 @@ class PostfixAdmin { define("POSTFIXADMIN_CLI", 1); +require_once(dirname(__FILE__) . '/../common.php'); + $dispatcher = new PostfixAdmin($argv); $dispatcher->dispatch();