Ignore:
Timestamp:
04/13/11 10:07:27 (13 years ago)
Author:
emersonfaria
Message:

Ticket #1746 - Criada autenticacao dos Backends no LDAP e corrigido bug de login alfanumerico

File:
1 edited

Legend:

Unmodified
Added
Removed
  • contrib/z-push/backend/BackendContactsExpresso.php

    r3637 r4000  
    1111 * Consult LICENSE file for details 
    1212 ************************************************/ 
    13 include_once('diffbackend.php'); 
    14 include_once('include/z_RTF.php'); 
    15 include_once "include/dbconnect.php"; 
     13require_once("diffbackend.php"); 
     14require_once("include/z_RTF.php"); 
     15require_once("include/dbconnect.php"); 
     16require_once("include/authldap.php"); 
    1617 
    1718class BackendContactsExpresso extends BackendDiff { 
    18         var $_user; 
    19         var $_devid; 
    20         var $_protocolversion; 
    2119        var $db; 
     20        var $_uidnumber; 
    2221 
    2322        function __construct() 
     
    2625 
    2726                if (!$this->db) { 
    28                         echo "A DB connect error occured.\n"; 
     27                        echo "Erro de conexao com o Banco.\n"; 
    2928                        exit; 
    3029                } 
     30        } 
     31 
     32        function Logon($username, $domain, $password) { 
     33                $this->_uidnumber = $this->authUser($this->parseUser($username), $password); 
     34                if(! $this->_uidnumber) return false; 
     35                else return true; 
    3136        } 
    3237 
     
    3540                $this->_devid = $devid; 
    3641                $this->_protocolversion = $protocolversion; 
    37                 //TODO: Autenticar Usuario no LDAP 
    3842 
    3943                return true; 
     
    4953 
    5054        function GetMessageList($folderid, $cutoffdate) { 
    51                 $id_owner = $this->parseOwner($this->_user); 
    52                 if ($id_owner == false) return false; 
    53  
    54                 debugLog('ContactsExpresso::GetMessageList('.$id_owner.')'); 
     55                debugLog('ContactsExpresso::GetMessageList('.$this->_uidnumber.')'); 
    5556                $messages = array(); 
    5657                $ids = array(); 
     
    5859                        $result = pg_query($this->db,"BEGIN;"); 
    5960                        if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 
    60                         $result = pg_query($this->db, "select given_names, family_names, last_update, id_contact from phpgw_cc_contact where id_owner = " . $id_owner . ";"); 
     61                        $result = pg_query($this->db, "select given_names, family_names, last_update, id_contact from phpgw_cc_contact where id_owner = " . $this->_uidnumber . ";"); 
    6162                        if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 
    6263                        while ($row = pg_fetch_row($result)) { 
     
    7879        function GetFolderList() { 
    7980                debugLog('ContactsExpresso::GetFolderList()'); 
    80                 $contacts = array(); 
    8181                $folder = $this->StatFolder("root"); 
    82                 $contacts[] = $folder; 
    8382                return $folder; 
    84                 //return $contacts; 
    8583        } 
    8684 
     
    117115                debugLog('ContactsExpresso::StatMessage('.$folderid.', '.$id.')'); 
    118116                if($folderid != "root") return false; 
    119  
    120                 $id_owner = $this->parseOwner($this->_user); 
    121                 if ($id_owner == false) return false; 
    122117 
    123118                try { 
     
    149144 
    150145                // Parse the database into object 
    151                 $id_owner = $this->parseOwner($this->_user); 
    152                 if ($id_owner == false) return; 
    153  
    154146                $message = new SyncContact(); 
    155147                try { 
     
    354346                debugLog('ContactsExpresso::DeleteMessage('.$folderid.', '.$id.', ..)'); 
    355347 
    356                 $id_owner = $this->parseOwner($this->_user); 
    357                 if ($id_owner == false) return false; 
    358  
    359348                $result = pg_query($this->db,"BEGIN;"); 
    360349                try { 
     
    416405                debugLog('ContactsExpresso::ChangeMessage('.$folderid.', '.$id.', ..)'); 
    417406 
    418                 $id_owner = $this->parseOwner($this->_user); 
    419                 if ($id_owner == false) return false; 
    420407                try { 
    421408                        $result = pg_query($this->db,"BEGIN;"); 
     
    666653                        if (!$found_id_contact){ 
    667654                                $arrayContact["id_contact"] = $id_contact; 
    668                                 $arrayContact["id_owner"] = $id_owner; 
     655                                $arrayContact["id_owner"] = $this->_uidnumber; 
    669656                                $result = pg_insert($this->db, 'phpgw_cc_contact', $arrayContact); 
    670657                                if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 
     
    10321019                                if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 
    10331020                        } 
    1034                          
     1021 
    10351022                        //TODO : Permitir mais de um número de telefone para Trabalho, Celular e Casa. O Expresso ainda não suporta isso :( 
    10361023 
     
    10681055                $data = str_replace("\r", "\n", $data); 
    10691056                $data = str_replace(array('\\', ';', ',', "\n"), array('\\\\', '\\;', '\\,', '\\n'), $data); 
    1070                 //return u2wi($data); 
    10711057                return $data; 
    10721058        } 
     
    10881074        } 
    10891075 
    1090         function parseOwner($id_owner) 
     1076        function parseUser($id_user) 
    10911077        { 
    1092                 $pos = strripos($id_owner, '\\'); 
     1078                $pos = strripos($id_user, '\\'); 
    10931079                if ($pos === false) { 
    1094                         if (strlen($id_owner) <= 2) return false; 
    1095                         else return substr($id_owner, 0, strlen($id_owner)-2); 
     1080                        if (strlen($id_user) < 1) return false; 
     1081                        else return $id_user; 
    10961082                } else { 
    1097                         if (strlen($id_owner) <= $pos + 3) { 
     1083                        if (strlen($id_user) <= $pos + 1) { 
    10981084                                return false; 
    10991085                        } else { 
    1100                                 return substr(substr($id_owner, $pos + 1), 0, strlen(substr($id_owner, $pos + 1))-2); 
     1086                                return substr(substr($id_user, $pos + 1), 0, strlen(substr($id_user, $pos + 1))); 
    11011087                        } 
    11021088                } 
     1089        } 
     1090 
     1091        // Authenticate user and return UIDNumber attribute on success 
     1092        function authUser($user, $pwd) { 
     1093                $ldap = new AuthLDAP(); 
     1094                $uid_number = ($ldap->bind($user,$pwd)); 
     1095                $ldap->disconnect(); 
     1096                unset($ldap); 
     1097                if (! $uid_number) return false; 
     1098                return $uid_number; 
    11031099        } 
    11041100}; 
Note: See TracChangeset for help on using the changeset viewer.