Changeset 4018 in subversion


Ignore:
Timestamp:
Sep 30, 2010 2:50:48 AM (3 years ago)
Author:
alec
Message:
  • Extend virtuser_query with email2user and user2host mapping (#1486750)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/virtuser_query/virtuser_query.php

    r4010 r4018  
    55 * 
    66 * Add it to the plugins list in config/main.inc.php and set 
    7  * SQL query to resolve user names and e-mail addresses from the database 
     7 * SQL queries to resolve usernames, e-mail addresses and hostnames from the database 
    88 * %u will be replaced with the current username for login. 
    9  * The query should select the user's e-mail address as first column 
    10  * and optional identity data columns in specified order: 
     9 * %m will be replaced with the current e-mail address for login. 
     10 * 
     11 * Queries should select the user's e-mail address, username or the imap hostname as first column 
     12 * The email query could optionally select identity data columns in specified order: 
    1113 *    name, organization, reply-to, bcc, signature, html_signature 
    1214 * 
    13  * $rcmail_config['virtuser_query'] = ''; 
     15 * $rcmail_config['virtuser_query'] = array('email' => '', 'user' => '', 'host' => ''); 
    1416 * 
    15  * @version 1.0 
     17 * @version 1.1 
    1618 * @author Aleksander Machniak 
     19 * @author Steffen Vogel 
    1720 */ 
    1821class virtuser_query extends rcube_plugin 
    1922{ 
    20     private $query; 
     23    private $config; 
    2124    private $app; 
    2225 
     
    2427    { 
    2528            $this->app = rcmail::get_instance(); 
    26             $this->query = $this->app->config->get('virtuser_query'); 
     29            $this->config = $this->app->config->get('virtuser_query'); 
    2730 
    28             if ($this->query) { 
    29                 $this->add_hook('user2email', array($this, 'user2email')); 
    30 //              $this->add_hook('email2user', array($this, 'email2user')); 
    31             } 
     31        if (!empty($this->config)) { 
     32            if (is_string($this->config)) { 
     33                $this->config = array('email' => $this->config); 
     34            } 
     35 
     36            if ($this->config['email']) { 
     37                $this->add_hook('user2email', array($this, 'user2email')); 
     38            } 
     39            if ($this->config['user']) { 
     40                $this->add_hook('email2user', array($this, 'email2user')); 
     41            } 
     42            if ($this->config['host']) { 
     43                $this->add_hook('authenticate', array($this, 'user2host')); 
     44            } 
     45        } 
    3246    } 
    3347 
     
    3953            $dbh = $this->app->get_dbh(); 
    4054 
    41             $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->query)); 
     55            $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['email'])); 
    4256 
    4357            while ($sql_arr = $dbh->fetch_array($sql_result)) { 
     
    6276                } 
    6377            } 
    64          
     78 
    6579            $p['email'] = $result; 
    6680 
     
    6882    } 
    6983 
     84    /** 
     85     * EMail > User 
     86     */ 
     87    function email2user($p) 
     88    { 
     89        $dbh = $this->app->get_dbh(); 
     90 
     91        $sql_result = $dbh->query(preg_replace('/%m/', $dbh->escapeSimple($p['email']), $this->config['user'])); 
     92 
     93        if ($sql_arr = $dbh->fetch_array($sql_result)) { 
     94            $p['user'] = $sql_arr[0]; 
     95        } 
     96 
     97        return $p; 
     98    } 
     99 
     100    /** 
     101     * User > Host 
     102     */ 
     103    function user2host($p) 
     104    { 
     105        $dbh = $this->app->get_dbh(); 
     106 
     107        $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['host'])); 
     108 
     109        if ($sql_arr = $dbh->fetch_array($sql_result)) { 
     110            $p['host'] = $sql_arr[0]; 
     111        } 
     112 
     113        return $p; 
     114    } 
     115 
    70116} 
     117 
Note: See TracChangeset for help on using the changeset viewer.