Fwd: [imp] setting the mail server via LDAP in IMP 4.0.1? also, syslog logging.

Marcos Monge mmonge at gmail.com
Wed Feb 9 12:04:04 PST 2005


---------- Forwarded message ----------
From: Marcos Monge <mmonge at gmail.com>
Date: Wed, 9 Feb 2005 21:03:41 +0100
Subject: Re: [imp] setting the mail server via LDAP in IMP 4.0.1?
also, syslog logging.
To: Sheeri Kritzer <sheeri.kritzer at tufts.edu>


Hi

I have do some modifications to do exactely this, read the mailhost
attribute from the ldap, and it's working OK. This are the files I
modify. This can be included for next release (well with a little
improve in the way I implement it). Sorry for some comments that are
in spanish, but I think it's easy to understand:

In horde/conf/hooks.php, define this function:

if (!function_exists('_imp_hook_buscaserver')) {
    function _imp_hook_buscaserver ($type = 'ldap') {
        $ldapServer = "ldap.mydomain.es";
        $ldapPort = "389";
        $searchBase = "o=mydomain.es";

        if ($type == 'pordefecto') {
            return $_SESSION['imp']['server'];
        } elseif ($type == "ldap") {

               $ds = @ldap_connect($ldapServer, $ldapPort);
               $busqueda = 'uid=' . $_SESSION['imp']['user'];
               $searchResult = @ldap_search($ds, $searchBase, $busqueda);

               if (@ldap_count_entries($ds, $searchResult) == 1) {
                       $info = @ldap_get_entries($ds, $searchResult);
                       if ($info[0]['mailhost'][0] != '') {
                               $salida = $info[0]["mailhost"][0];
                       } else {
                               $salida = $_SESSION['imp']['server'];
                       }
               } else {
                       $salida = $_SESSION['imp']['server'];
               }

               ldap_close($ds);
               return $salida;
        } else {
            return PEAR::raiseError('Funcion _imp_hook_buscaserver.
Tipo invalido: ' . $type);
        }

    }
}

In horde/imp/config/conf.xml I add a new entry for this hook:

# diff conf.xml conf.xml-original
244,246d243
<    <configboolean name="server" required="false" desc="Usar un custom hook
<    para buscar el servidor imap del usuario en LDAP? Si es afirmativo,
<    activar _imp_hook_buscaserver en
horde/config/hooks.php.">false</configboolean>

And regenerate the conf.php from the web interface activating this hook.

And the last file to modify is horde/imp/lib/Session.php, to call this
new function:
# diff Session.php Session.php.original
206,214d205
< /* Sobreescribimos el valor del servidor buscandolo en ldap
< */
<         if (!empty($conf['hooks']['server'])) {
<             require_once HORDE_BASE . '/config/hooks.php';
<             if (function_exists('_imp_hook_buscaserver')) {
<                 $_SESSION['imp']['server'] =
call_user_func('_imp_hook_buscaserver');
<             }
<         }
<

With this you overwrite the value of _SESSION['imp']['server'] with
the ldap search. This is working fine for me.

Best Regards
Marcos


On Wed,  9 Feb 2005 11:12:44 -0500, Sheeri Kritzer
<sheeri.kritzer at tufts.edu> wrote:
> For the syslog stuff, I believe it's relevant that 1) I'm using solaris 8 (5.8)
> and 2) regular syslog logging to /var/log/syslog is working just fine.
>
> -Sheeri Kritzer
> Systems Administrator
> University Systems Group
> Tufts University
> 617-627-3925
> sheeri.kritzer at tufts.edu
>
> Quoting Sheeri Kritzer <sheeri.kritzer at tufts.edu>:
>
> > Hello,
> >
> > I am in the process of upgrading our webmail system from Horde 2 /IMP 3 to
> > Horde
> > 3/ IMP 4.
> >
> > I configured everything with a basic configuration, hard-coding the mail
> > server
> > in config/servers.php and everything worked -- IMP 4.0.1 was able to read
> > e-mail
> > off our IMAP server as well as send mail successfully.  (Some of the new
> > features are awesome, like the keyboard shortcuts. . . whee!)
> >
> > Now that I have basic functionality, I'm doing the more advanced
> > configuration.
> > One of the problems I'm having is getting horde to log via syslog.  File
> > logging
> > works fine, and we had syslog logging before, so I'm not sure what I'm doing
> > wrong.  Relevant conf:
> >
> > /etc/syslog.conf:
> >
> > local4.info                /var/log/imp.log
> >
> > horde/config/conf.php
> >
> > $conf['log']['priority'] = PEAR_LOG_ALL;
> > $conf['log']['ident'] = 'HORDE';
> > $conf['log']['params'] = array();
> > $conf['log']['name'] = 'local4';
> > $conf['log']['params']['append'] = true;
> > $conf['log']['type'] = 'syslog';
> > $conf['log']['enabled'] = true;
> >
> > I've also tried it with:
> > $conf['log']['name'] = 'LOG_LOCAL4';
> >
> > What am I doing wrong?
> >
> > The other problem I'm having is migrating one of our custom hooks -- we
> > determine what mail server to use based on a field in LDAP.
> >
> > Relevant conf:
> > in horde/config/conf.php:
> >
> > $conf['hooks']['getserver'] = true;
> >
> > in horde/imp/config/conf.php:
> >
> > $conf['server']['server_list'] = 'hidden';
> > $conf['server']['change_server'] = false;
> > $conf['server']['change_port'] = false;
> > $conf['server']['change_protocol'] = false;
> > $conf['server']['change_folders'] = false;
> > $conf['server']['sort_limit'] = '0';
> > $conf['server']['cache_folders'] = false;
> > $conf['hooks']['server'] = _imp_hook_getserver;
> >
> > in hooks.php:
> >
> > if( !function_exists('_imp_hook_getserver') ){
> >         function _imp_hook_getserver( $userId ){
> >                 $val = fetch_ldap_attr($userId,
> > 'tuftsedutrumpetermailhost');
> >                 if( $val == false ){
> >                         return false;
> >                 }
> >
> >                 $imp['server'] = $val;
> >                 $imp['maildomain'] = $imp['server'];
> >                 return true;
> >         }
> > }
> >
> > (and yes, fetch_ldap_attr is a defined function, but it includes passwords
> > and
> > such.  I've been able to determine that the function works, and horde
> > actually
> > binds to LDAP and gets the value.  I'm guessing that what's wrong is that
> > $imp['server'] is no longer the variable to change for the server. . .)
> >
> > in horde/lib/Horde/Auth.php, I added:
> >         if (!empty($conf['hooks']['getserver'])) {
> >             include_once HORDE_BASE . '/config/hooks.php';
> >             if (function_exists('_imp_hook_getserver')) {
> >                 if (!call_user_func('_imp_hook_getserver', $userId)) {
> >                     $this->_setAuthError(AUTH_REASON_LDAP);
> >                     return false;
> >                 }
> >             }
> >         }
> >
> > (and I also defined what AUTH_REASON_LDAP is)
> >
> > in horde/imp/config/servers.php:
> >
> > $servers[''] = array(
> >     'name' => 'IMAP Server',
> >     'server' => '',
> >     'hordeauth' => false,
> >     'protocol' => 'imap/ssl/novalidate-cert',
> >     'port' => '993',
> >     'folders' => '',
> >     'namespace' => '',
> >     'maildomain' => '',
> >     'smtphost' => 'smtp.tufts.edu',
> >     'smtpport' => '25',
> >     'realm' => '',
> >     'preferred' => '',
> >     'dotfiles' => false,
> >     'hierarchies' => array()
> > );
> >
> > Thanx for your time!
> >
> > -Sheeri Kritzer
> > Systems Administrator
> > University Systems Group
> > Tufts University
> > 617-627-3925
> > sheeri.kritzer at tufts.edu
> >
> >
> >
> >
> > --
> > IMP mailing list - Join the hunt: http://horde.org/bounties/#imp
> > Frequently Asked Questions: http://horde.org/faq/
> > To unsubscribe, mail: imp-unsubscribe at lists.horde.org
> >
>
> --
> IMP mailing list - Join the hunt: http://horde.org/bounties/#imp
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: imp-unsubscribe at lists.horde.org
>


More information about the imp mailing list