[dev] Patch for AutoLogin (hordeauth) for IMP and Gollem

Joel Vandal jvandal at infoteck.qc.ca
Fri Oct 3 21:11:03 PDT 2003


> Neither of these are valid patches either - looks like you cut & pasted
them out
> of an editor that cuts off long lines with $ on the end of the line.
>
> -chuck

Oh shit! Sorry... ;) I resend the patch ;P

--
Joel Vandal
-------------- next part --------------
Index: lib/Gollem.php
===================================================================
RCS file: /repository/gollem/lib/Gollem.php,v
retrieving revision 1.106
diff -u -r1.106 Gollem.php
--- lib/Gollem.php 3 Oct 2003 21:23:52 -0000 1.106
+++ lib/Gollem.php 4 Oct 2003 04:08:12 -0000
@@ -205,12 +205,12 @@
         if (empty($backend_key)) {
             $backend_key = Gollem::getCurrentBackend();
         }
-
+ 
         return ((count($GLOBALS['backends']) == 1 || $force) &&
                 ((count($GLOBALS['vfs'][$backend_key]->getRequiredCredentials()) == 0) ||
                  (Auth::getAuth() &&
-                  implode(',', $vfs[$backend_key]->getRequiredCredentials()) == 'username,password' &&
-                  !empty($backends[$backend_key]['hordeauth']))));
+                  implode(',', $GLOBALS['vfs'][$backend_key]->getRequiredCredentials()) == 'username,password' &&
+                  !empty($GLOBALS['backends'][$backend_key]['hordeauth']))));
     }
 
     /**
-------------- next part --------------
===================================================================
RCS file: /repository/imp/login.php,v
retrieving revision 2.188
diff -u -r2.188 login.php
--- login.php 2 Oct 2003 12:11:52 -0000 2.188
+++ login.php 4 Oct 2003 04:05:58 -0000
@@ -36,6 +36,7 @@
 
 /* Get the actionID, checking for the action=compose variable. */
 $actionID = Util::getFormData('actionID');
+$server_key = Util::getFormData('server_key');
 if (Util::getFormData('action') == 'compose') {
     $actionID = 'login_compose';
 }
@@ -129,6 +130,42 @@
 Secret::setKey('imp');
 if ($imp_auth) {
     Secret::setKey('auth');
+}
+
+$used_servers = $servers;
+if ($conf['server']['server_list'] != 'shown') {
+    
+    $server_key = Util::getFormData('server_key');
+    if (is_null($server_key)) {
+ /* Grab some default values from the first entry in
+ *          * config/servers.php. */
+ foreach ($servers as $key => $curServer) {
+     if (is_null($server_key) && substr($key, 0, 1) != '_') {
+ $server_key = $key;
+     }
+     if (IMP::isPreferredServer($curServer)) {
+ $server_key = $key;
+ break;
+     }
+ }
+    }
+    $used_servers = array($server_key => $servers[$server_key]);
+    $autologin = Util::getFormData('autologin');
+}
+
+if (($reason == 'login') &&
+    IMP::canAutoLogin($server_key, $autologin)) {
+    $url = Horde::applicationUrl('redirect.php', true);
+    if (count($used_servers) == 1) {
+ reset($used_servers);
+ list($server_key, $curServer) = each($used_servers);
+ $url = Util::addParameter($url, 'server_key', $server_key);
+    }
+    $url = Util::addParameter($url, 'actionID', 'login');
+    $url = Util::addParameter($url, 'autologin', true);
+    $url = Util::addParameter($url, 'frameset', true);
+    header('Location: ' . $url);
+    exit;
 }
 
 $title = sprintf(_("Welcome to %s"), $registry->getParam('name', ($imp_auth) ? 'horde' : null));
Index: lib/IMP.php
===================================================================
RCS file: /repository/imp/lib/IMP.php,v
retrieving revision 1.399
diff -u -r1.399 IMP.php
--- lib/IMP.php 23 Sep 2003 22:10:25 -0000 1.399
+++ lib/IMP.php 4 Oct 2003 04:05:58 -0000
@@ -53,7 +53,50 @@
  * @package imp
  */
 class IMP {
-
+    
+    /**
+     * Get the AutoLogin server key.
+     *
+     * @access public
+     *
+     * @return string  The server key.
+     */
+    function getAutoLoginServer()
+    {
+ require IMP_BASE . '/config/servers.php';
+ foreach ($servers as $key => $curServer) {
+     if (empty($server_key) && substr($key, 0, 1) != '_') {
+ $server_key = $key;
+     }
+     if (IMP::isPreferredServer($curServer)) {
+ $server_key = $key;
+     }
+ }
+        return $server_key;
+    }
+    
+    /**
+     * Can we log in without a login screen for $server_key?
+     *
+     * @param string  $server_key   (optional) The server to check. Defaults to
+     *                              IMP::getCurrentServer().
+     * @param boolean $force        (optional) If true, check $server_key even if there
+     *                              is more than one server available. Defaults to false.
+     *
+     * @return boolean  True or false.
+     */
+    function canAutoLogin($server_key = '', $force = false)
+    {
+ require IMP_BASE . '/config/servers.php';
+ 
+        if (empty($server_key)) {
+            $server_key = IMP::getAutoLoginServer();
+ }
+        return ((count(IMP::getAutoLoginServer()) == 1 || $force) &&
+ (Auth::getAuth() &&
+ !empty($servers[$server_key]['hordeauth'])));
+    }
+    
     /**
      * Make sure the user has been authenticated to view the page.
      *
@@ -138,7 +181,7 @@
 
         return false;
     }
-
+    
     /**
      * Tack on any prefixes that need to be put at the beginning of
      * the folder path.

Index: templates/menu/menu.inc
===================================================================
RCS file: /repository/imp/templates/menu/menu.inc,v
retrieving revision 2.179
diff -u -r2.179 menu.inc
--- templates/menu/menu.inc 16 Sep 2003 23:05:21 -0000 2.179
+++ templates/menu/menu.inc 4 Oct 2003 04:06:00 -0000
@@ -58,13 +58,15 @@
 Menu::appLinks();
 
 /* Logout */
-if ((Auth::getProvider() == 'imp') && $conf['menu']['display']) {
-    $menu_logout_url = $registry->getParam('webroot', 'horde') . '/login.php';
-    Menu::printItem(Util::addParameter($menu_logout_url, 'reason', 'logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'), '_parent');
-} else {
-    $menu_logout_url = Horde::applicationUrl('login.php');
-    Menu::printItem(Util::addParameter($menu_logout_url, 'reason', 'logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'));
-}
+if (!IMP::canAutoLogin()) {
+    if ((Auth::getProvider() == 'imp') && $conf['menu']['display']) {
+        $menu_logout_url = $registry->getParam('webroot', 'horde') . '/login.php';
+        Menu::printItem(Util::addParameter($menu_logout_url, 'reason', 'logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'), '_parent');
+    } else {
+        $menu_logout_url = Horde::applicationUrl('login.php');
+        Menu::printItem(Util::addParameter($menu_logout_url, 'reason', 'logout'), _("Logout"), 'logout.gif', $registry->getParam('graphics', 'horde'));
+    }
+}    
 
 ?>
 


More information about the dev mailing list