[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; |
---|
[2] | 16 | |
---|
| 17 | function sosectors() |
---|
| 18 | { |
---|
| 19 | $this->functions = createobject('expressoAdmin1_2.functions'); |
---|
[396] | 20 | |
---|
| 21 | if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) && |
---|
| 22 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) && |
---|
| 23 | (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) ) |
---|
| 24 | { |
---|
| 25 | $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'], |
---|
| 26 | $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'], |
---|
| 27 | $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']); |
---|
| 28 | } |
---|
| 29 | else |
---|
| 30 | { |
---|
| 31 | $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 32 | } |
---|
[2] | 33 | } |
---|
| 34 | |
---|
| 35 | function exist_sector_name($sector_name, $context) |
---|
| 36 | { |
---|
[396] | 37 | $search = ldap_list($this->ldap_connection, $context, "ou=" . $sector_name); |
---|
| 38 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 39 | |
---|
| 40 | if ($result['count'] == 0) |
---|
| 41 | return false; |
---|
| 42 | else |
---|
| 43 | return true; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | function write_ldap($dn, $info) |
---|
| 47 | { |
---|
[396] | 48 | if (ldap_add($this->ldap_connection, $dn, $info)) |
---|
[2] | 49 | { |
---|
| 50 | //Escreve no log |
---|
| 51 | $this->functions->write_log2($GLOBALS['phpgw']->accounts->data['account_lid'], 'write in ldap', $dn,'','',''); |
---|
[396] | 52 | ldap_close($this->ldap_connection); |
---|
[2] | 53 | return true; |
---|
| 54 | } |
---|
| 55 | else |
---|
| 56 | { |
---|
| 57 | echo 'Erro na escrita no LDAP, funcao write_ldap'; |
---|
[396] | 58 | ldap_close($this->ldap_connection); |
---|
[2] | 59 | return false; |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | function get_sector_users($context) |
---|
| 64 | { |
---|
| 65 | $justthese = array("cn", "uidNumber", "uid"); |
---|
| 66 | $filter="(&(phpgwAccountType=u)(uid=*))"; |
---|
[396] | 67 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
| 68 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 69 | return $result; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | function get_sector_groups($context) |
---|
| 73 | { |
---|
| 74 | $justthese = array("cn", "gidnumber"); |
---|
| 75 | $filter="(&(phpgwAccountType=g)(cn=*))"; |
---|
[396] | 76 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
| 77 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 78 | return $result; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | function get_sector_subsectors($context) |
---|
| 82 | { |
---|
| 83 | $justthese = array("ou"); |
---|
| 84 | $filter="(objectClass=organizationalUnit)"; |
---|
[396] | 85 | $search=ldap_search($this->ldap_connection, $context, $filter, $justthese); |
---|
| 86 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 87 | return $result; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | function delete_sector_ldap_recursively($connection, $dn) |
---|
| 91 | { |
---|
| 92 | //searching for sub entries |
---|
| 93 | $search=ldap_list($connection,$dn,"ObjectClass=organizationalUnit",array("")); |
---|
| 94 | $info = ldap_get_entries($connection, $search); |
---|
| 95 | |
---|
| 96 | for($i=0;$i<$info['count'];$i++) |
---|
| 97 | { |
---|
| 98 | //deleting recursively sub entries |
---|
| 99 | $result=$this->delete_sector_ldap_recursively($connection,$info[$i]['dn']); |
---|
| 100 | if(!$result) |
---|
| 101 | { |
---|
| 102 | //return result code, if delete fails |
---|
| 103 | return($result); |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | return(ldap_delete($connection,$dn)); |
---|
| 107 | } |
---|
[32] | 108 | |
---|
| 109 | function get_info($context) |
---|
| 110 | { |
---|
| 111 | $filter="(objectClass=organizationalUnit)"; |
---|
[396] | 112 | $search=ldap_search($this->ldap_connection, $context, $filter); |
---|
| 113 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[32] | 114 | return $result; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | function add_attribute($dn, $info) |
---|
| 118 | { |
---|
[396] | 119 | if (ldap_mod_add($this->ldap_connection, $dn, $info)) |
---|
[32] | 120 | { |
---|
[396] | 121 | ldap_close($this->ldap_connection); |
---|
[32] | 122 | return true; |
---|
| 123 | } |
---|
| 124 | else |
---|
| 125 | { |
---|
[396] | 126 | echo 'Erro na escrita no LDAP, funcao add_attribute: ' . ldap_error($this->ldap_connection); |
---|
| 127 | ldap_close($this->ldap_connection); |
---|
[32] | 128 | return false; |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | function remove_attribute($dn, $info) |
---|
| 133 | { |
---|
[396] | 134 | if (ldap_mod_del($this->ldap_connection, $dn, $info)) |
---|
[32] | 135 | { |
---|
[396] | 136 | ldap_close($this->ldap_connection); |
---|
[32] | 137 | return true; |
---|
| 138 | } |
---|
| 139 | else |
---|
| 140 | { |
---|
[396] | 141 | echo 'Erro na escrita no LDAP, funcao remove_attribute: ' . ldap_error($this->ldap_connection); |
---|
| 142 | ldap_close($this->ldap_connection); |
---|
[32] | 143 | return false; |
---|
| 144 | } |
---|
| 145 | } |
---|
[2] | 146 | } |
---|
| 147 | ?> |
---|