From a48d4862a016130c85a7a4d84398217423758f78 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Thu, 30 Apr 2009 11:57:49 +0200 Subject: [PATCH] Fix the login procedures and allow logout. --- koward/lib/Koward.php | 9 +--- koward/lib/Koward/Controller/Application.php | 33 ++++++++++---- koward/lib/Koward/Controller/IndexController.php | 52 +++++++++++++++++++++ koward/lib/Koward/Controller/LoginController.php | 53 ---------------------- .../Koward/View/{Login => Index}/login.html.php | 2 +- 5 files changed, 79 insertions(+), 70 deletions(-) delete mode 100644 koward/lib/Koward/Controller/LoginController.php rename koward/lib/Koward/View/{Login => Index}/login.html.php (99%) diff --git a/koward/lib/Koward.php b/koward/lib/Koward.php index ad3116e3a..f68fad89b 100644 --- a/koward/lib/Koward.php +++ b/koward/lib/Koward.php @@ -30,7 +30,7 @@ class Koward { $this->auth = &Auth::singleton($conf['auth']['driver']); - $this->conf = Horde::loadConfiguration('koward.php', 'koward'); + $this->conf = Horde::loadConfiguration('conf.php', 'conf'); $this->objects = Horde::loadConfiguration('objects.php', 'objects'); $this->attributes = Horde::loadConfiguration('attributes.php', 'attributes'); $this->labels = Horde::loadConfiguration('labels.php', 'labels'); @@ -60,11 +60,6 @@ class Koward { $browser = Horde_Browser::singleton(); } - $result = $registry->pushApp('koward', false); - if ($result instanceOf PEAR_Error) { - $notification->push($result); - } - $webroot = Koward::_detectWebroot($koward); // Set up our request and routing objects @@ -85,7 +80,7 @@ class Koward { } // Check for route definitions. - $routeFile = dirname($koward) . '/../config/routes.php'; + $routeFile = dirname($koward) . '/../../koward/config/routes.php'; if (!file_exists($routeFile)) { throw new Horde_Controller_Exception('Not routable'); } diff --git a/koward/lib/Koward/Controller/Application.php b/koward/lib/Koward/Controller/Application.php index f3488357b..37054601e 100644 --- a/koward/lib/Koward/Controller/Application.php +++ b/koward/lib/Koward/Controller/Application.php @@ -6,24 +6,31 @@ class Koward_Controller_Application extends Horde_Controller_Base { global $registry; - $this->koward = Koward::singleton(); - - if (is_a(($pushed = $registry->pushApp('horde', empty($this->auth_handler))), 'PEAR_Error')) { + 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' => 'login', 'action' => 'login'))); + header('Location: ' . $this->urlFor(array('controller' => 'index', 'action' => 'login'))); exit; } } + $this->koward = Koward::singleton(); + + if ($this->koward->objects instanceOf PEAR_Error) { + return; + } - $this->types = array_keys($this->koward->objects); - if (empty($this->types)) { + if (!empty($this->koward->objects)) { + $this->types = array_keys($this->koward->objects); + } else { throw new Koward_Exception('No object types have been configured!'); } $this->menu = $this->getMenu(); - $this->theme = isset($this->koward->conf['theme']) ? $this->koward->conf['theme'] : 'koward'; + $this->theme = isset($this->koward->conf['koward']['theme']) ? $this->koward->conf['koward']['theme'] : 'koward'; + } /** @@ -42,9 +49,17 @@ class Koward_Controller_Application extends Horde_Controller_Base _("_Add"), 'plus.png', $registry->getImageDir('horde')); $menu->add($this->urlFor(array('controller' => 'object', 'action' => 'search')), _("_Search"), 'search.png', $registry->getImageDir('horde')); - $menu->add(Horde::applicationUrl('Queries'), _("_Queries"), 'query.png', $registry->getImageDir('koward')); - $menu->add($this->urlFor(array('controller' => 'check', 'action' => 'show')), + if (!empty($this->koward->conf['koward']['menu']['queries'])) { + $menu->add(Horde::applicationUrl('Queries'), _("_Queries"), 'query.png', $registry->getImageDir('koward')); + } + if (!empty($this->koward->conf['koward']['menu']['test'])) { + $menu->add($this->urlFor(array('controller' => 'check', 'action' => 'show')), _("_Test"), 'problem.png', $registry->getImageDir('horde')); + } + if (Auth::getAuth()) { + $menu->add($this->urlFor(array('controller' => 'index', 'action' => 'logout')), + _("_Logout"), 'logout.png', $registry->getImageDir('horde')); + } return $menu; } } diff --git a/koward/lib/Koward/Controller/IndexController.php b/koward/lib/Koward/Controller/IndexController.php index 52dba4c2d..67e6c931d 100644 --- a/koward/lib/Koward/Controller/IndexController.php +++ b/koward/lib/Koward/Controller/IndexController.php @@ -10,9 +10,61 @@ class IndexController extends Koward_Controller_Application { protected $welcome; + protected $auth_handler = 'login'; + public function index() { $this->title = _("Index"); $this->welcome = _("Welcome to the Koward administration interface"); } + + public function login() + { + $auth = Auth::getAuth(); + if (!empty($auth)) { + header('Location: ' . $this->urlFor(array('controller' => 'index', 'action' => 'index'))); + exit; + } + + $this->title = _("Login"); + $this->welcome = _("Welcome."); + + $this->post = $this->urlFor(array('controller' => 'index', + 'action' => 'login')); + + if (isset($_POST['horde_user']) && isset($_POST['horde_pass'])) { + /* Destroy any existing session on login and make sure to use a + * new session ID, to avoid session fixation issues. */ + Horde::getCleanSession(); + if ($this->koward->auth->authenticate(Util::getPost('horde_user'), + array('password' => Util::getPost('horde_pass')))) { + $entry = sprintf('Login success for %s [%s] to Horde', + Auth::getAuth(), $_SERVER['REMOTE_ADDR']); + Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_NOTICE); + header('Location: ' . $this->urlFor(array('controller' => 'index', 'action' => 'index'))); + exit; + } else { + $entry = sprintf('FAILED LOGIN for %s [%s] to Horde', + Util::getFormData('horde_user'), $_SERVER['REMOTE_ADDR']); + Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_ERR); + } + } + + if ($reason = $this->koward->auth->getLogoutReasonString()) { + $this->koward->notification->push(str_replace('
', ' ', $reason), 'horde.message'); + } + + } + + public function logout() + { + $entry = sprintf('User %s [%s] logged out of Horde', + Auth::getAuth(), $_SERVER['REMOTE_ADDR']); + Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_NOTICE); + Auth::clearAuth(); + @session_destroy(); + + header('Location: ' . $this->urlFor(array('controller' => 'index', 'action' => 'login'))); + exit; + } } \ No newline at end of file diff --git a/koward/lib/Koward/Controller/LoginController.php b/koward/lib/Koward/Controller/LoginController.php deleted file mode 100644 index 0fbe30de8..000000000 --- a/koward/lib/Koward/Controller/LoginController.php +++ /dev/null @@ -1,53 +0,0 @@ -urlFor(array('controller' => 'index'))); - exit; - } - - $this->title = _("Login"); - $this->welcome = _("Welcome."); - - $this->post = $this->urlFor(array('controller' => 'login', - 'action' => 'login')); - - if (isset($_POST['horde_user']) && isset($_POST['horde_pass'])) { - /* Destroy any existing session on login and make sure to use a - * new session ID, to avoid session fixation issues. */ - Horde::getCleanSession(); - if ($this->koward->auth->authenticate(Util::getPost('horde_user'), - array('password' => Util::getPost('horde_pass')))) { - $entry = sprintf('Login success for %s [%s] to Horde', - Auth::getAuth(), $_SERVER['REMOTE_ADDR']); - Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_NOTICE); - - header('Location: ' . $this->urlFor(array('controller' => 'index'))); - exit; - } else { - $entry = sprintf('FAILED LOGIN for %s [%s] to Horde', - Util::getFormData('horde_user'), $_SERVER['REMOTE_ADDR']); - Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_ERR); - } - } - - if ($reason = $this->koward->auth->getLogoutReasonString()) { - $this->koward->notification->push(str_replace('
', ' ', $reason), 'horde.message'); - } - - } -} \ No newline at end of file diff --git a/koward/lib/Koward/View/Login/login.html.php b/koward/lib/Koward/View/Index/login.html.php similarity index 99% rename from koward/lib/Koward/View/Login/login.html.php rename to koward/lib/Koward/View/Index/login.html.php index 48dc91c5f..c63827a2a 100644 --- a/koward/lib/Koward/View/Login/login.html.php +++ b/koward/lib/Koward/View/Index/login.html.php @@ -6,7 +6,7 @@ koward->notification->notify(array('listeners' => 'status')) ?> -
-- 2.11.0