From: Gunnar Wrobel
Date: Sun, 10 May 2009 06:19:44 +0000 (+0200) Subject: Fixed the CLI interface. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f7690feb5244dfb915bc9dc65e55cfcddb502a9d;p=horde.git Fixed the CLI interface. --- diff --git a/koward/lib/Koward.php b/koward/lib/Koward.php index a0d110c99..7c7d143c8 100644 --- a/koward/lib/Koward.php +++ b/koward/lib/Koward.php @@ -47,7 +47,8 @@ class Koward { $this->search = Horde::loadConfiguration('search.php', 'search'); } - public static function dispatch($koward) + public static function dispatch($koward, $request_class = 'Horde_Controller_Request_Http', + $webroot = null) { global $registry, $notification, $browser; @@ -63,17 +64,19 @@ class Koward { $notification = Notification::singleton(); $notification->attach('status'); - $registry = Registry::singleton(); + $registry = Registry::singleton(); /* Browser detection object. */ if (class_exists('Horde_Browser')) { $browser = Horde_Browser::singleton(); } - $webroot = Koward::_detectWebroot($koward); + if ($webroot === null) { + $webroot = Koward::_detectWebroot($koward); + } // Set up our request and routing objects - $request = new Horde_Controller_Request_Http(); + $request = new $request_class(); $mapper = new Horde_Routes_Mapper(); // Application routes are relative only to the application. Let the mapper know @@ -230,6 +233,10 @@ class Koward { $session = Horde_Kolab_Session::singleton(); if (!empty($session->user_uid)) { $user = $this->getObject($session->user_uid); + if (get_class($user) == $this->conf['koward']['cli_admin'] + && Horde_CLI::runningFromCLI()) { + return true; + } $type = $this->getType($user); if (isset($this->objects[$type]['permission'])) { return $this->_hasPermission($this->objects[$type]['permission'], diff --git a/koward/lib/Koward/Cli.php b/koward/lib/Koward/Cli.php index 43b31bccf..81aa3ef30 100644 --- a/koward/lib/Koward/Cli.php +++ b/koward/lib/Koward/Cli.php @@ -59,7 +59,7 @@ class Koward_Cli extends Horde_Controller_Request_Base ); list($this->_argv, $args) = $parser->parseArgs(); if (!count($args)) { - throw new Horde_Controller_Exception('unknown command: ' . implode(' ', $args)); + throw new Koward_Exception('unknown command: ' . implode(' ', $args)); } /** @@ -80,12 +80,21 @@ class Koward_Cli extends Horde_Controller_Request_Base } } + if (is_a(($pushed = $registry->pushApp('koward', + empty($this->auth_handler) + || $this->auth_handler != $this->params[':action'])), 'PEAR_Error')) { + if ($pushed->getCode() == 'permission_denied') { + header('Location: ' . $this->urlFor(array('controller' => 'index', 'action' => 'login'))); + exit; + } + } + /** * A rough command line handler that allows us to map CLI requests into * the web view of the system. */ switch ($args[0]) { - case 'object/edit': + case 'object/add': $this->_cmd_argv['formname'] = 'koward_form_object'; /** Has the object type been set? */ @@ -116,7 +125,7 @@ class Koward_Cli extends Horde_Controller_Request_Base * to use the standard form mechanisms via CLI. Think of some * alternatives here. */ - $koward = &Koward_Koward::singleton(); + $koward = &Koward::singleton(); $token = $koward->getRequestToken('cli'); $this->_cmd_argv['koward_form_object_formToken'] = $token; @@ -178,7 +187,7 @@ class Koward_Cli extends Horde_Controller_Request_Base /** * Provide a token for immediate deletion. */ - $koward = &Koward_Koward::singleton(); + $koward = &Koward::singleton(); $this->_cmd_argv['token'] = $koward->getRequestToken('object.delete'); break; diff --git a/koward/script/Koward/koward.php b/koward/script/Koward/koward.php index 9a4775a73..f85634ccd 100644 --- a/koward/script/Koward/koward.php +++ b/koward/script/Koward/koward.php @@ -38,56 +38,25 @@ $cli = Horde_CLI::singleton(); $cli->init(); /** - * Hm, the fact that we need the registry at this point for identifying the - * location where we installed the application is not really satisfying. The - * whole "app" dir should probably be in "lib", too. That way we can install it - * in a defined location via PEAR. + * Hm, the fact that we need the registry at this point for + * identifying the location where we installed the application is not + * really satisfying. We need it to know the location of the + * configuration though. */ -require_once $opts->base . '/lib/base.php'; - -/** Configure the Autoloader */ -$app = 'koward'; -Horde_Autoloader::addClassPattern('/^Koward_/', $registry->get('fileroot', $app) . '/lib/'); -Horde_Autoloader::addClassPattern('/^Koward_/', $registry->get('fileroot', $app) . '/app/controllers/'); +require_once $opts->base . '/koward/config/base.php'; /** * FIXME END */ -/** Initialize the command line handler */ -$request = new Koward_Cli(); - -/** - * The following is an extract from rampage.php and only a rough draft. Calling - * Controller actions this way is still rather complicated on the command line - * this way. For one thing you need to provide the application installation base - * which is knowledge we'd rather hide from the user and the full path to the - * Controller action (including the path to the app identified by the registry) - * has to be provided. This should be handled via other CLI parameters. - */ -$mapper = new Horde_Routes_Mapper(); - -$routeFile = $registry->get('fileroot', $app) . '/config/routes.php'; -if (!file_exists($routeFile)) { - throw new Horde_Controller_Exception('Not routable'); -} -$mapper->prefix = $registry->get('webroot', 'horde') . '/' . $app; -include $routeFile; - -$context = array( - 'mapper' => $mapper, - 'controllerDir' => $registry->get('fileroot', $app) . '/app/controllers', - 'viewsDir' => $registry->get('fileroot', $app) . '/app/views', - // 'logger' => '', -); +/** Configure the Autoloader to handle the "Koward" pattern */ +Horde_Autoloader::addClassPattern('/^Koward_/', 'Koward/'); +/** Dispatch the request. */ try { - $dispatcher = Horde_Controller_Dispatcher::singleton($context); - $dispatcher->dispatch($request); + Koward::dispatch($opts->base . '/htdocs/koward/koward.php', 'Koward_Cli', '/koward'); } catch (Exception $e) { // @TODO Make nicer echo '
'; var_dump($e); echo ''; } - -exit(0); diff --git a/koward/www/htdocs/koward/koward.php b/koward/www/htdocs/koward/koward.php index c327063bd..6e4a98336 100644 --- a/koward/www/htdocs/koward/koward.php +++ b/koward/www/htdocs/koward/koward.php @@ -14,7 +14,7 @@ Horde_Autoloader::addClassPattern('/^Koward_/', 'Koward/'); /** Dispatch the request. */ try { - Koward::dispatch(__FILE__); + Koward::dispatch(__FILE__, 'Horde_Controller_Request_Http'); } catch (Exception $e) { // @TODO Make nicer echo '