[2] | 1 | <?php |
---|
| 2 | /**********************************************************************************\ |
---|
| 3 | * Expresso Administração * |
---|
| 4 | * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br) * |
---|
| 5 | * ----------------------------------------------------------------------------------* |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \***********************************************************************************/ |
---|
| 11 | |
---|
| 12 | class sosectors |
---|
| 13 | { |
---|
| 14 | var $functions; |
---|
[396] | 15 | var $ldap_connection; |
---|
[471] | 16 | var $db_functions; |
---|
[2] | 17 | |
---|
| 18 | function sosectors() |
---|
| 19 | { |
---|
| 20 | $this->functions = createobject('expressoAdmin1_2.functions'); |
---|
[471] | 21 | $this->db_functions = CreateObject('expressoAdmin1_2.db_functions'); |
---|
[396] | 22 | |
---|
| 23 | if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) && |
---|
| 24 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) && |
---|
| 25 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) ) |
---|
| 26 | { |
---|
| 27 | $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'], |
---|
| 28 | $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'], |
---|
| 29 | $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']); |
---|
| 30 | } |
---|
| 31 | else |
---|
| 32 | { |
---|
| 33 | $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 34 | } |
---|
[2] | 35 | } |
---|
| 36 | |
---|
| 37 | function exist_sector_name($sector_name, $context) |
---|
| 38 | { |
---|
[396] | 39 | $search = ldap_list($this->ldap_connection, $context, "ou=" . $sector_name); |
---|
| 40 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 41 | |
---|
| 42 | if ($result['count'] == 0) |
---|
| 43 | return false; |
---|
| 44 | else |
---|
| 45 | return true; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | function write_ldap($dn, $info) |
---|
| 49 | { |
---|
[5133] | 50 | $info['ou'] = utf8_encode($info['ou']); |
---|
| 51 | |
---|
| 52 | if (ldap_add($this->ldap_connection, utf8_encode($dn), $info)) |
---|
[2] | 53 | { |
---|
[414] | 54 | $this->db_functions->write_log("write on ldap", "$dn"); |
---|
[396] | 55 | ldap_close($this->ldap_connection); |
---|
[2] | 56 | return true; |
---|
| 57 | } |
---|
| 58 | else |
---|
| 59 | { |
---|
[5133] | 60 | echo lang('Error written in LDAP, function write_ldap'); |
---|
[396] | 61 | ldap_close($this->ldap_connection); |
---|
[2] | 62 | return false; |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | function get_sector_users($context) |
---|
| 67 | { |
---|
| 68 | $justthese = array("cn", "uidNumber", "uid"); |
---|
| 69 | $filter="(&(phpgwAccountType=u)(uid=*))"; |
---|
[396] | 70 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
| 71 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 72 | return $result; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | function get_sector_groups($context) |
---|
| 76 | { |
---|
| 77 | $justthese = array("cn", "gidnumber"); |
---|
| 78 | $filter="(&(phpgwAccountType=g)(cn=*))"; |
---|
[396] | 79 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
| 80 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 81 | return $result; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | function get_sector_subsectors($context) |
---|
| 85 | { |
---|
| 86 | $justthese = array("ou"); |
---|
| 87 | $filter="(objectClass=organizationalUnit)"; |
---|
[396] | 88 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
| 89 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 90 | return $result; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | function delete_sector_ldap_recursively($connection, $dn) |
---|
| 94 | { |
---|
| 95 | //searching for sub entries |
---|
[1394] | 96 | $search=ldap_list($connection,$dn,"ObjectClass=*",array("")); |
---|
[2] | 97 | $info = ldap_get_entries($connection, $search); |
---|
| 98 | |
---|
| 99 | for($i=0;$i<$info['count'];$i++) |
---|
| 100 | { |
---|
| 101 | //deleting recursively sub entries |
---|
| 102 | $result=$this->delete_sector_ldap_recursively($connection,$info[$i]['dn']); |
---|
| 103 | if(!$result) |
---|
| 104 | { |
---|
| 105 | //return result code, if delete fails |
---|
| 106 | return($result); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | return(ldap_delete($connection,$dn)); |
---|
| 110 | } |
---|
[32] | 111 | |
---|
| 112 | function get_info($context) |
---|
| 113 | { |
---|
| 114 | $filter="(objectClass=organizationalUnit)"; |
---|
[396] | 115 | $search=ldap_search($this->ldap_connection, $context, $filter); |
---|
| 116 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[32] | 117 | return $result; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | function add_attribute($dn, $info) |
---|
| 121 | { |
---|
[396] | 122 | if (ldap_mod_add($this->ldap_connection, $dn, $info)) |
---|
[32] | 123 | { |
---|
[396] | 124 | ldap_close($this->ldap_connection); |
---|
[32] | 125 | return true; |
---|
| 126 | } |
---|
| 127 | else |
---|
| 128 | { |
---|
[493] | 129 | echo lang('Error written in LDAP, function add_attribute'). ldap_error($this->ldap_connection); |
---|
[396] | 130 | ldap_close($this->ldap_connection); |
---|
[32] | 131 | return false; |
---|
| 132 | } |
---|
| 133 | } |
---|
[1516] | 134 | |
---|
[6553] | 135 | function replace_attribute($dn, $info) |
---|
| 136 | { |
---|
| 137 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 138 | |
---|
| 139 | if (ldap_mod_replace($connection, $dn, $info)) |
---|
| 140 | { |
---|
| 141 | ldap_close($connection); |
---|
| 142 | return true; |
---|
| 143 | } |
---|
| 144 | else |
---|
| 145 | { |
---|
| 146 | echo 'Erro na escrita no LDAP, funcao replace_attribute: ' . ldap_error($connection); |
---|
| 147 | ldap_close($connection); |
---|
| 148 | return false; |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
[32] | 152 | function remove_attribute($dn, $info) |
---|
| 153 | { |
---|
[396] | 154 | if (ldap_mod_del($this->ldap_connection, $dn, $info)) |
---|
[32] | 155 | { |
---|
[396] | 156 | ldap_close($this->ldap_connection); |
---|
[32] | 157 | return true; |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
[493] | 161 | echo lang('Error written in LDAP, function remove_attribute'). ldap_error($this->ldap_connection); |
---|
[396] | 162 | ldap_close($this->ldap_connection); |
---|
[32] | 163 | return false; |
---|
| 164 | } |
---|
| 165 | } |
---|
[2] | 166 | } |
---|
[1394] | 167 | ?> |
---|