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