[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 socomputers |
---|
| 13 | { |
---|
| 14 | var $functions; |
---|
[396] | 15 | var $ldap_connection; |
---|
[2] | 16 | |
---|
| 17 | function socomputers() |
---|
| 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 write_ldap($dn, $info) |
---|
| 36 | { |
---|
[396] | 37 | if (ldap_add($this->ldap_connection, $dn, $info)) |
---|
[2] | 38 | { |
---|
[396] | 39 | ldap_close($this->ldap_connection); |
---|
[2] | 40 | return true; |
---|
| 41 | } |
---|
| 42 | else |
---|
| 43 | { |
---|
[396] | 44 | echo "Erro na escrita no LDAP, funcao so->write_ldap:" . ldap_error($this->ldap_connection); |
---|
| 45 | ldap_close($this->ldap_connection); |
---|
[2] | 46 | return false; |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | function exist_computer_uid($computer_cn) |
---|
| 51 | { |
---|
[396] | 52 | $search = ldap_search($this->ldap_connection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $computer_cn . '$'); |
---|
| 53 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
| 54 | ldap_close($this->ldap_connection); |
---|
[2] | 55 | if ($result['count'] == 0) |
---|
| 56 | return false; |
---|
| 57 | else |
---|
| 58 | return true; |
---|
| 59 | } |
---|
| 60 | |
---|
[64] | 61 | function get_computer_data($uidnumber) |
---|
[2] | 62 | { |
---|
[64] | 63 | $manager_acl = $this->functions->read_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid']); |
---|
| 64 | $manager_contexts = $manager_acl['contexts']; |
---|
[2] | 65 | |
---|
[64] | 66 | foreach ($manager_contexts as $index=>$context) |
---|
| 67 | { |
---|
[396] | 68 | $search = ldap_search($this->ldap_connection, $context, "uidNumber=$uidnumber"); |
---|
| 69 | $result = ldap_get_entries($this->ldap_connection, $search); |
---|
[2] | 70 | |
---|
[64] | 71 | if ($result['count']) |
---|
| 72 | { |
---|
| 73 | // Recupera o DN |
---|
| 74 | $computer_data['dn'] = $result[0]['dn']; |
---|
| 75 | |
---|
| 76 | //Recupera o Nome do Computador (CN) |
---|
| 77 | $computer_data['computer_cn'] = $result[0]['cn'][0]; |
---|
[2] | 78 | |
---|
[64] | 79 | //Recupera a flag SAMBA |
---|
| 80 | $computer_data['sambaAcctFlags'] = $result[0]['sambaacctflags'][0]; |
---|
[2] | 81 | |
---|
[64] | 82 | // Recupera a descrição |
---|
| 83 | $computer_data['computer_description'] = utf8_decode($result[0]['description'][0]); |
---|
[2] | 84 | |
---|
[64] | 85 | // Recupera o contexto do email_list |
---|
| 86 | $tmp = explode(",", $computer_data['dn']); |
---|
| 87 | for ($i = 1; $i < count($tmp); $i++) |
---|
| 88 | $computer_data['context'] .= $tmp[$i] . ','; |
---|
| 89 | $computer_data['context'] = substr($computer_data['context'],0,(strlen($computer_data['context']) - 1)); |
---|
[2] | 90 | |
---|
[64] | 91 | $a_tmp = explode("-", $result[0]['sambasid'][0]); |
---|
| 92 | array_pop($a_tmp); |
---|
| 93 | $computer_data['sambasid'] = implode("-", $a_tmp); |
---|
[27] | 94 | |
---|
[64] | 95 | return $computer_data; |
---|
| 96 | } |
---|
| 97 | } |
---|
[2] | 98 | } |
---|
| 99 | |
---|
| 100 | function delete_computer_ldap($dn) |
---|
| 101 | { |
---|
[396] | 102 | $result = ldap_delete($this->ldap_connection, $dn); |
---|
| 103 | ldap_close($this->ldap_connection); |
---|
[2] | 104 | return $result; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | function rename_ldap($old_dn, $new_rdn, $new_context) |
---|
| 108 | { |
---|
[396] | 109 | $result = ldap_rename($this->ldap_connection, $old_dn, $new_rdn, $new_context, true); |
---|
| 110 | ldap_close($this->ldap_connection); |
---|
[2] | 111 | return $result; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | function ldap_add_attribute($ldap_add_attribute, $dn) |
---|
| 115 | { |
---|
[396] | 116 | $result = ldap_mod_add($this->ldap_connection, $dn, $ldap_add_attribute); |
---|
| 117 | ldap_close($this->ldap_connection); |
---|
[2] | 118 | $this->functions->write_log($GLOBALS['phpgw']->accounts->data['account_lid'], 'add attributes in ldap in email list', $dn,'','',''); |
---|
| 119 | return $result; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | function ldap_remove_attribute($ldap_remove_attribute, $dn) |
---|
| 123 | { |
---|
[396] | 124 | $result = ldap_mod_del($this->ldap_connection, $dn, $ldap_remove_attribute); |
---|
| 125 | ldap_close($this->ldap_connection); |
---|
[2] | 126 | //Escreve no log |
---|
| 127 | $this->functions->write_log($GLOBALS['phpgw']->accounts->data['account_lid'], 'remove attributes in ldap in email list', $dn,'','',''); |
---|
| 128 | return $result; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | function ldap_replace_attribute($ldap_replace_attribute, $dn) |
---|
| 132 | { |
---|
[396] | 133 | $result = ldap_mod_replace($this->ldap_connection, $dn, $ldap_replace_attribute); |
---|
| 134 | ldap_close($this->ldap_connection); |
---|
[2] | 135 | return $result; |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | ?> |
---|