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