Fix the login procedures and allow logout.
authorGunnar Wrobel <p@rdus.de>
Thu, 30 Apr 2009 09:57:49 +0000 (11:57 +0200)
committerGunnar Wrobel <p@rdus.de>
Thu, 30 Apr 2009 09:57:49 +0000 (11:57 +0200)
koward/lib/Koward.php
koward/lib/Koward/Controller/Application.php
koward/lib/Koward/Controller/IndexController.php
koward/lib/Koward/Controller/LoginController.php [deleted file]
koward/lib/Koward/View/Index/login.html.php [new file with mode: 0644]
koward/lib/Koward/View/Login/login.html.php [deleted file]

index ad3116e..f68fad8 100644 (file)
@@ -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');
         }
index f348835..3705460 100644 (file)
@@ -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;
     }
 }
index 52dba4c..67e6c93 100644 (file)
@@ -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('<br />', ' ', $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 (file)
index 0fbe30d..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-/**
- * @package Koward
- */
-
-/**
- * @package Koward
- */
-class LoginController extends Koward_Controller_Application
-{
-    protected $welcome;
-
-    protected $auth_handler = true;
-
-    public function login()
-    {
-        $auth = Auth::getAuth();
-        if (!empty($auth)) {
-            header('Location: ' . $this->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('<br />', ' ', $reason), 'horde.message');
-        }
-
-    }
-}
\ No newline at end of file
diff --git a/koward/lib/Koward/View/Index/login.html.php b/koward/lib/Koward/View/Index/login.html.php
new file mode 100644 (file)
index 0000000..c63827a
--- /dev/null
@@ -0,0 +1,28 @@
+<?= $this->renderPartial('header'); ?>
+
+<div id="menu">
+ <h1 style="text-align:center"><?= $this->welcome ?></h1>
+</div>
+
+<?php $this->koward->notification->notify(array('listeners' => 'status')) ?>
+
+<form name="koward_login" method="post" action="<?= $this->post ?>">
+<table width="100%"><tr><td align="center"><table width="300" align="center">
+
+<tr>
+    <td class="light rightAlign"><strong><?php echo Horde::label('horde_user', _("Username")) ?></strong>&nbsp;</td>
+    <td class="leftAlign"><input type="text" id="horde_user" name="horde_user" value="<?php echo htmlspecialchars(Util::getFormData('horde_user')) ?>" style="direction:ltr" /></td>
+</tr>
+
+<tr>
+    <td class="light rightAlign"><strong><?php echo Horde::label('horde_pass', _("Password")) ?></strong>&nbsp;</td>
+    <td class="leftAlign"><input type="password" id="horde_pass" name="horde_pass" value="" style="direction:ltr" /></td>
+</tr>
+
+<tr>
+    <td>&nbsp;</td>
+    <td class="light leftAlign"><input name="loginButton" class="button" value="<?php echo _("Log in") ?>" type="submit" onclick="return submit_login();" /></td>
+</tr>
+
+</table></td></tr></table>
+</form>
diff --git a/koward/lib/Koward/View/Login/login.html.php b/koward/lib/Koward/View/Login/login.html.php
deleted file mode 100644 (file)
index 48dc91c..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?= $this->renderPartial('header'); ?>
-
-<div id="menu">
- <h1 style="text-align:center"><?= $this->welcome ?></h1>
-</div>
-
-<?php $this->koward->notification->notify(array('listeners' => 'status')) ?>
-
-<form name="koward_login" method="post" action="<?= $this->post ?>"
-<table width="100%"><tr><td align="center"><table width="300" align="center">
-
-<tr>
-    <td class="light rightAlign"><strong><?php echo Horde::label('horde_user', _("Username")) ?></strong>&nbsp;</td>
-    <td class="leftAlign"><input type="text" id="horde_user" name="horde_user" value="<?php echo htmlspecialchars(Util::getFormData('horde_user')) ?>" style="direction:ltr" /></td>
-</tr>
-
-<tr>
-    <td class="light rightAlign"><strong><?php echo Horde::label('horde_pass', _("Password")) ?></strong>&nbsp;</td>
-    <td class="leftAlign"><input type="password" id="horde_pass" name="horde_pass" value="" style="direction:ltr" /></td>
-</tr>
-
-<tr>
-    <td>&nbsp;</td>
-    <td class="light leftAlign"><input name="loginButton" class="button" value="<?php echo _("Log in") ?>" type="submit" onclick="return submit_login();" /></td>
-</tr>
-
-</table></td></tr></table>
-</form>