Horde Auth and other fruit

Max Kalika max@the-triumvirate.net
Fri, 13 Apr 2001 13:58:54 -0700


Hello all.

I did some work (with lots of direction from Chuck) locally to make IMP play 
nice on multi-server setups, primarily preventing login clashes for prefs and 
Turba.  As a side effect of this, Turba will not bring up a login screen if one 
is already logged into IMP and also Horde Auth can be configured to use IMP for 
authentication.  The patches are below.



Index: config/registry.php.dist
===================================================================
RCS file: /cvs/horde/horde/config/registry.php.dist,v
retrieving revision 1.29
diff -U0 -r1.29 registry.php.dist
--- config/registry.php.dist    2001/03/31 04:59:45     1.29
+++ config/registry.php.dist    2001/04/13 20:47:52
@@ -3,0 +4,2 @@
+$this->registry['auth']['login'] = 'imp';
+$this->registry['auth']['logout'] = 'imp';
@@ -83,0 +86,7 @@
+
+$this->services['imp']['auth']['login'] = array(
+    'link' => "%application%/login.php?action=redirect&url=|url|"
+);
+$this->services['imp']['auth']['logout'] = array(
+    'link' => "%application%/login.php?reason=logout&action=redirect&url=|url|"
+);



Index: login.php
===================================================================
RCS file: /cvs/horde/horde/login.php,v
retrieving revision 2.46
diff -U0 -r2.46 login.php
--- login.php   2001/03/29 15:47:46     2.46
+++ login.php   2001/04/13 20:47:50
@@ -17,0 +18 @@
+require_once './lib/Registry.php';
@@ -19,0 +21 @@
+$registry = new Registry();
@@ -25 +27,7 @@
-    Auth::clearAuth();
+    if ($registry->hasMethod('auth/logout')) {
+        if (!isset($url)) $url = Horde::selfURL();
+        header('Location: ' . Horde::url($registry->link('auth/logout', array
('url' => Horde::url($url, true))), true));
+        exit;
+    } else {
+        Auth::clearAuth();
+    }
@@ -49,0 +58,4 @@
+} elseif ($registry->hasMethod('auth/login')) {
+    if (!isset($url)) $url = Horde::selfURL();
+    header('Location: ' . Horde::url($registry->link('auth/login', array('url' 
=> Horde::url($url, true))), true));
+    exit;



Index: imp/config/servers.php.dist
===================================================================
RCS file: /cvs/horde/imp/config/servers.php.dist,v
retrieving revision 1.13
diff -U0 -r1.13 servers.php.dist
--- imp/config/servers.php.dist 2001/03/01 07:23:50     1.13
+++ imp/config/servers.php.dist 2001/04/13 20:47:53
@@ -57,0 +58,3 @@
+ * realm: What to append to usernames for preferences and Horde
+ * authentication to prevent login clashes on virtual host setups.
+ *
@@ -76,0 +80 @@
+    'realm' => 'example.com',
@@ -87,0 +92 @@
+    'realm' => 'example.com',
@@ -98,0 +104 @@
+    'realm' => 'example.com',



Index: imp/lib/IMP.php
===================================================================
RCS file: /cvs/horde/imp/lib/IMP.php,v
retrieving revision 1.159
diff -U0 -r1.159 IMP.php
--- imp/lib/IMP.php     2001/03/31 05:07:24     1.159
+++ imp/lib/IMP.php     2001/04/13 20:47:56
@@ -71,0 +72 @@
+/** @const LOGIN_REDIRECT Redirect to URL after login. */ define
('LOGIN_REDIRECT', 59);
@@ -120,6 +120,0 @@
-        /* Create a new preferences object and load the site defaults. */
-        $prefs = Prefs::factory($conf['prefs']['driver'], $registry->getApp(),
-            $imp['user'], Secret::read(Secret::getKey('imp'), $imp['pass']),
-            $conf['prefs']['params']);
-        $prefs->setDefaults(IMP_BASE . '/config/prefs.php');
-        
@@ -130,0 +126,14 @@
+
+        if ($conf['server']['server_list']
+            && isset($servers[$HTTP_POST_VARS['server']])
+            && is_array($servers[$HTTP_POST_VARS['server']])) {
+            $imp['realm'] = $servers[$HTTP_POST_VARS['server']]['realm'];
+        } else {
+            $imp['realm'] = $HTTP_POST_VARS['realm'];
+        }
+
+        /* Create a new preferences object and load the site defaults. */
+        $prefs = Prefs::factory($conf['prefs']['driver'], $registry->getApp(),
+            $imp['user'] . '@' . $imp['realm'], Secret::read(Secret::getKey
('imp'), $imp['pass']),
+            $conf['prefs']['params']);
+        $prefs->setDefaults(IMP_BASE . '/config/prefs.php');
@@ -201 +210 @@
-                $registry->getApp(), $GLOBALS['imp']['user'],
+                $registry->getApp(), $GLOBALS['imp']['user'] . '@' . $GLOBALS
['imp']['realm'],
@@ -328,0 +338,4 @@
+        }
+        include_once IMP_BASE . '/../lib/Auth.php';
+        if(!Auth::getAuth()) {
+            Auth::setAuth($imp['user'] . '@' . $imp['realm']);



Index: imp/login.php
===================================================================
RCS file: /cvs/horde/imp/login.php,v
retrieving revision 2.107
diff -U0 -r2.107 login.php
--- imp/login.php       2001/03/21 15:00:54     2.107
+++ imp/login.php       2001/04/13 20:47:53
@@ -82 +82 @@
-                $registry->getApp(), $imp['user'],
+                $registry->getApp(), $imp['user'] . '@' . $imp['realm'],
@@ -88,0 +89,4 @@
+        include_once IMP_BASE . "/../lib/Auth.php";
+        if (Auth::getAuth()) {
+            Auth::clearAuth();
+        }
@@ -91,0 +96,4 @@
+        include_once IMP_BASE . "/../lib/Auth.php";
+        if (Auth::getAuth()) {
+            Auth::clearAuth();
+        }
@@ -130,0 +139,4 @@
+} elseif ((isset($HTTP_GET_VARS['action']) && $HTTP_GET_VARS['action'] 
== 'redirect') ||
+    ($actionID == LOGIN_REDIRECT)) {
+    $actionID = LOGIN_REDIRECT;
+    $url = Horde::getFormData('url');
@@ -134,0 +147,6 @@
+/* Redirect the user on logout if controlling auth for Horde. */
+if ($reason == 'logout' && $actionID == LOGIN_REDIRECT && !empty($url)) {
+    header('Location: ' . $url);
+    exit;
+}
+
@@ -147,0 +166 @@
+$realm_value = $servers[$server_key]['realm'];



Index: imp/templates/login/login.inc
===================================================================
RCS file: /cvs/horde/imp/templates/login/login.inc,v
retrieving revision 2.79
diff -U0 -r2.79 login.inc
--- imp/templates/login/login.inc       2001/03/22 06:13:01     2.79
+++ imp/templates/login/login.inc       2001/04/13 20:47:59
@@ -54,0 +55,3 @@
+<?php if ($actionID == LOGIN_REDIRECT): ?>
+<input type="hidden" name="url" value="<?= $url ?>" />
+<?php else: ?>
@@ -55,0 +59 @@
+<?php endif; ?>
@@ -100,0 +105 @@
+        <input type="hidden" name="realm" value="<?= $realm_value ?>" />
@@ -127,0 +133 @@
+        <input type="hidden" name="realm" value="<?= $realm_value ?>" /


Index: imp/redirect.php
===================================================================
RCS file: /cvs/horde/imp/redirect.php,v
retrieving revision 1.13
diff -U0 -r1.13 redirect.php
--- imp/redirect.php    2001/03/14 17:04:49     1.13
+++ imp/redirect.php    2001/04/13 20:47:53
@@ -22 +22 @@
-    $actionID = IMP_LOGIN;
+    $actionID = Horde::getFormData('actionID', IMP_LOGIN);
@@ -52,0 +53,9 @@
+
+        if ($actionID == LOGIN_REDIRECT) {
+            $url = Horde::getFormData('url');
+            if (!empty($url)) {
+                header('Location: ' . $url);
+                exit;
+            }
+        }
+


-- 
/// max kalika
// max@the-triumvirate.net

"and after a while you'll stop making computers out of stuff and start making 
stuff out of computers" -- douglas adams 4/5/01