[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 | include_once('class.ldap_functions.inc.php'); |
---|
| 13 | include_once('class.db_functions.inc.php'); |
---|
| 14 | include_once('class.imap_functions.inc.php'); |
---|
| 15 | include_once('class.functions.inc.php'); |
---|
| 16 | |
---|
| 17 | class user |
---|
| 18 | { |
---|
| 19 | var $ldap_functions; |
---|
| 20 | var $db_functions; |
---|
| 21 | var $imap_functions; |
---|
| 22 | var $functions; |
---|
| 23 | var $current_config; |
---|
| 24 | |
---|
| 25 | function user() |
---|
| 26 | { |
---|
| 27 | $this->ldap_functions = new ldap_functions; |
---|
| 28 | $this->db_functions = new db_functions; |
---|
| 29 | $this->imap_functions = new imap_functions; |
---|
| 30 | $this->functions = new functions; |
---|
| 31 | $this->current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin']; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | function create($params) |
---|
| 35 | { |
---|
| 36 | $return['status'] = true; |
---|
| 37 | |
---|
| 38 | // Verifica o acesso do gerente |
---|
| 39 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'add_users')) |
---|
| 40 | { |
---|
| 41 | // Adiciona a organização na frente do uid. |
---|
| 42 | if ($this->current_config['expressoAdmin_prefix_org'] == 'true') |
---|
| 43 | { |
---|
| 44 | $context_dn = ldap_explode_dn(strtolower($GLOBALS['phpgw_info']['server']['ldap_context']), 1); |
---|
| 45 | |
---|
| 46 | $explode_dn = ldap_explode_dn(strtolower($params['context']), 1); |
---|
| 47 | $explode_dn = array_reverse($explode_dn); |
---|
| 48 | //$params['uid'] = $explode_dn[3] . '-' . $params['uid']; |
---|
| 49 | $params['uid'] = $explode_dn[$context_dn['count']] . '-' . $params['uid']; |
---|
| 50 | } |
---|
| 51 | |
---|
[69] | 52 | // Leio o ID a ser usado na criação do objecto. Esta função já incrementa o ID no BD. |
---|
[64] | 53 | $next_id = ($this->db_functions->get_next_id('accounts')); |
---|
| 54 | if ((!is_numeric($next_id['id'])) || (!$next_id['status'])) |
---|
| 55 | { |
---|
| 56 | $return['status'] = false; |
---|
| 57 | $return['msg'] = "Problemas obtendo ID do usuário.\n" . $id['msg']; |
---|
| 58 | return $return; |
---|
| 59 | } |
---|
| 60 | else |
---|
| 61 | { |
---|
| 62 | $id = $next_id['id']; |
---|
| 63 | } |
---|
[2] | 64 | |
---|
| 65 | // Cria array para incluir no LDAP |
---|
[27] | 66 | $dn = 'uid=' . $params['uid'] . ',' . $params['context']; |
---|
[2] | 67 | |
---|
| 68 | $user_info = array(); |
---|
| 69 | $user_info['accountStatus'] = $params['accountstatus'] == 1 ? 'active' : 'desactive'; |
---|
| 70 | $user_info['cn'] = $params['givenname'] . ' ' . $params['sn']; |
---|
| 71 | $user_info['gidNumber'] = $params['gidnumber']; |
---|
| 72 | $user_info['givenName'] = $params['givenname']; |
---|
| 73 | $user_info['homeDirectory'] = '/home/' . $params['uid']; |
---|
| 74 | $user_info['mail'] = $params['mail']; |
---|
| 75 | $user_info['objectClass'][] = 'posixAccount'; |
---|
| 76 | $user_info['objectClass'][] = 'inetOrgPerson'; |
---|
| 77 | $user_info['objectClass'][] = 'shadowAccount'; |
---|
| 78 | $user_info['objectClass'][] = 'qmailuser'; |
---|
| 79 | $user_info['objectClass'][] = 'phpgwAccount'; |
---|
| 80 | $user_info['objectClass'][] = 'top'; |
---|
| 81 | $user_info['objectClass'][] = 'person'; |
---|
| 82 | $user_info['objectClass'][] = 'organizationalPerson'; |
---|
| 83 | $user_info['phpgwAccountExpires'] = '-1'; |
---|
| 84 | $user_info['phpgwAccountType'] = 'u'; |
---|
| 85 | $user_info['sn'] = $params['sn']; |
---|
| 86 | $user_info['uid'] = $params['uid']; |
---|
| 87 | $user_info['uidnumber'] = $id; |
---|
| 88 | $user_info['userPassword'] = '{md5}' . base64_encode(pack("H*",md5($params['password1']))); |
---|
[46] | 89 | |
---|
[72] | 90 | if ($params['passwd_expired'] == '1') |
---|
| 91 | $user_info['phpgwLastPasswdChange'] = '0'; |
---|
| 92 | |
---|
[46] | 93 | // Gerenciar senhas RFC2617 |
---|
| 94 | if ($this->current_config['expressoAdmin_userPasswordRFC2617'] == 'true') |
---|
| 95 | { |
---|
| 96 | $realm = $this->current_config['expressoAdmin_realm_userPasswordRFC2617']; |
---|
| 97 | $uid = $user_info['uid']; |
---|
| 98 | $password = $params['password1']; |
---|
| 99 | $user_info['userPasswordRFC2617'] = $realm . ': ' . md5("$uid:$realm:$password"); |
---|
| 100 | } |
---|
| 101 | |
---|
[2] | 102 | if ($params['phpgwaccountstatus'] == '1') |
---|
| 103 | $user_info['phpgwAccountStatus'] = 'A'; |
---|
| 104 | |
---|
| 105 | if ($params['departmentnumber'] != '') |
---|
| 106 | $user_info['departmentnumber'] = $params['departmentnumber']; |
---|
| 107 | |
---|
| 108 | if ($params['telephonenumber'] != '') |
---|
| 109 | $user_info['telephoneNumber'] = $params['telephonenumber']; |
---|
| 110 | |
---|
| 111 | // Cria user_info no caso de ter alias e forwarding email. |
---|
[81] | 112 | foreach ($params['mailalternateaddress'] as $index=>$mailalternateaddress) |
---|
| 113 | { |
---|
| 114 | if ($mailalternateaddress != '') |
---|
| 115 | $user_info['mailAlternateAddress'][] = $mailalternateaddress; |
---|
| 116 | } |
---|
[2] | 117 | |
---|
[81] | 118 | foreach ($params['mailforwardingaddress'] as $index=>$mailforwardingaddress) |
---|
| 119 | { |
---|
| 120 | if ($mailforwardingaddress != '') |
---|
| 121 | $user_info['mailForwardingAddress'][] = $mailforwardingaddress; |
---|
| 122 | } |
---|
[2] | 123 | |
---|
| 124 | if ($params['deliverymode']) |
---|
| 125 | $user_info['deliveryMode'] = 'forwardOnly'; |
---|
| 126 | |
---|
| 127 | //Ocultar da pesquisa e do catálogo |
---|
| 128 | if ($params['phpgwaccountvisible']) |
---|
| 129 | $user_info['phpgwAccountVisible'] = '-1'; |
---|
| 130 | |
---|
| 131 | // Suporte ao SAMBA |
---|
| 132 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($params['use_attrs_samba'] == 'on')) |
---|
| 133 | { |
---|
[317] | 134 | |
---|
| 135 | // Qualquer um que crie um usuário, deve ter permissão para adicionar a senha samba. |
---|
[63] | 136 | // Verifica o acesso do gerente aos atributos samba |
---|
[317] | 137 | //if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_sambausers_attributes')) |
---|
| 138 | //{ |
---|
[63] | 139 | //Verifica se o binario para criar as senhas do samba exite. |
---|
| 140 | if (!is_file('/home/expressolivre/mkntpwd')) |
---|
| 141 | { |
---|
| 142 | $return['status'] = false; |
---|
| 143 | $return['msg'] .= "O arquivo binário /home/expressolivre/mkntpwd não exite.\\nEle é necessário para a criação das senhas usadas pelo SAMBA.\\nInforme o administrador ExpressoLivre sobre isto."; |
---|
| 144 | } |
---|
| 145 | else |
---|
| 146 | { |
---|
| 147 | $user_info['objectClass'][] = 'sambaSamAccount'; |
---|
| 148 | $user_info['loginShell'] = '/bin/bash'; |
---|
| 149 | |
---|
| 150 | $user_info['sambaSID'] = $params['sambadomain'] . '-' . ((2 * $id)+1000); |
---|
| 151 | $user_info['sambaPrimaryGroupSID'] = $params['sambadomain'] . '-' . ((2 * $user_info['gidNumber'])+1001); |
---|
[27] | 152 | |
---|
[63] | 153 | $user_info['sambaAcctFlags'] = $params['sambaacctflags']; |
---|
[2] | 154 | |
---|
[63] | 155 | $user_info['sambaLogonScript'] = $params['sambalogonscript']; |
---|
| 156 | $user_info['homeDirectory'] = $params['sambahomedirectory']; |
---|
[2] | 157 | |
---|
[63] | 158 | $user_info['sambaLMPassword'] = exec('/home/expressolivre/mkntpwd -L '.$params['password1']); |
---|
| 159 | $user_info['sambaNTPassword'] = exec('/home/expressolivre/mkntpwd -N '.$params['password1']); |
---|
| 160 | $user_info['sambaPasswordHistory'] = '0000000000000000000000000000000000000000000000000000000000000000'; |
---|
[2] | 161 | |
---|
[63] | 162 | $user_info['sambaPwdCanChange'] = strtotime("now"); |
---|
| 163 | $user_info['sambaPwdLastSet'] = strtotime("now"); |
---|
| 164 | $user_info['sambaPwdMustChange'] = '2147483647'; |
---|
| 165 | } |
---|
[317] | 166 | //} |
---|
[2] | 167 | } |
---|
[63] | 168 | |
---|
| 169 | // Verifica o acesso do gerente aos atributos corporativos |
---|
| 170 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'manipulate_corporative_information')) |
---|
| 171 | { |
---|
[379] | 172 | //retira caracteres que não são números. |
---|
| 173 | $params['corporative_information_cpf'] = ereg_replace("[^0-9]", "", $params['corporative_information_cpf']); |
---|
[438] | 174 | //description |
---|
[63] | 175 | foreach ($params as $atribute=>$value) |
---|
| 176 | { |
---|
[64] | 177 | $pos = strstr($atribute, 'corporative_information_'); |
---|
[63] | 178 | if ($pos !== false) |
---|
| 179 | { |
---|
| 180 | if ($params[$atribute]) |
---|
| 181 | { |
---|
| 182 | $ldap_atribute = str_replace("corporative_information_", "", $atribute); |
---|
| 183 | $user_info[$ldap_atribute] = $params[$atribute]; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | |
---|
[2] | 189 | $result = $this->ldap_functions->ldap_add_entry($dn, $user_info); |
---|
| 190 | if (!$result['status']) |
---|
| 191 | { |
---|
| 192 | $return['status'] = false; |
---|
| 193 | $return['msg'] .= $result['msg']; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | // Chama funcao para salvar foto no OpenLDAP. |
---|
[107] | 197 | if ( ($_FILES['photo']['name'] != '') && ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users_picture')) ) |
---|
[2] | 198 | { |
---|
| 199 | $result = $this->ldap_functions->ldap_save_photo($dn, $_FILES['photo']['tmp_name']); |
---|
| 200 | if (!$result['status']) |
---|
| 201 | { |
---|
| 202 | $return['status'] = false; |
---|
| 203 | $return['msg'] .= $result['msg']; |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | //GROUPS |
---|
| 208 | if ($params['groups']) |
---|
| 209 | { |
---|
| 210 | foreach ($params['groups'] as $gidnumber) |
---|
| 211 | { |
---|
| 212 | $result = $this->ldap_functions->add_user2group($gidnumber, $user_info['uid']); |
---|
| 213 | if (!$result['status']) |
---|
| 214 | { |
---|
| 215 | $return['status'] = false; |
---|
| 216 | $return['msg'] .= $result['msg']; |
---|
| 217 | } |
---|
| 218 | $result = $this->db_functions->add_user2group($gidnumber, $id); |
---|
| 219 | if (!$result['status']) |
---|
| 220 | { |
---|
| 221 | $return['status'] = false; |
---|
| 222 | $return['msg'] .= $result['msg']; |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | // Inclusao do Mail do usuário nas listas de email selecionadas. |
---|
| 228 | if ($params['maillists']) |
---|
| 229 | { |
---|
[208] | 230 | foreach($params['maillists'] as $uid) |
---|
[2] | 231 | { |
---|
[208] | 232 | $result = $this->ldap_functions->add_user2maillist($uid, $user_info['mail']); |
---|
[2] | 233 | if (!$result['status']) |
---|
| 234 | { |
---|
| 235 | $return['status'] = false; |
---|
| 236 | $return['msg'] .= $result['msg']; |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | // APPS |
---|
| 242 | if (count($params['apps'])) |
---|
| 243 | { |
---|
| 244 | $result = $this->db_functions->add_id2apps($id, $params['apps']); |
---|
| 245 | if (!$result['status']) |
---|
| 246 | { |
---|
| 247 | $return['status'] = false; |
---|
| 248 | $return['msg'] .= $result['msg']; |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | // Chama funcao para incluir no pgsql as preferencia de alterar senha. |
---|
| 253 | if ($params['changepassword']) |
---|
| 254 | { |
---|
| 255 | $result = $this->db_functions->add_pref_changepassword($id); |
---|
| 256 | if (!$result['status']) |
---|
| 257 | { |
---|
| 258 | $return['status'] = false; |
---|
| 259 | $return['msg'] .= $result['msg']; |
---|
| 260 | } |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | // Chama funcao para criar mailbox do usuario, no imap-cyrus. |
---|
| 264 | $result = $this->imap_functions->create($params['uid'], $params['mailquota']); |
---|
| 265 | if (!$result['status']) |
---|
| 266 | { |
---|
| 267 | $return['status'] = false; |
---|
| 268 | $return['msg'] .= $result['msg']; |
---|
| 269 | } |
---|
| 270 | |
---|
[414] | 271 | $this->db_functions->write_log("created user",$dn); |
---|
[2] | 272 | } |
---|
| 273 | |
---|
| 274 | return $return; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | function save($new_values) |
---|
| 278 | { |
---|
| 279 | $return['status'] = true; |
---|
| 280 | |
---|
[64] | 281 | $old_values = $this->get_user_info($new_values['uidnumber']); |
---|
| 282 | |
---|
[2] | 283 | $dn = 'uid=' . $old_values['uid'] . ',' . strtolower($old_values['context']); |
---|
[379] | 284 | |
---|
| 285 | //retira caracteres que não são números. |
---|
| 286 | $new_values['corporative_information_cpf'] = ereg_replace("[^0-9]", "", $new_values['corporative_information_cpf']); |
---|
| 287 | |
---|
[2] | 288 | $diff = array_diff($new_values, $old_values); |
---|
[81] | 289 | |
---|
[72] | 290 | /* |
---|
| 291 | echo '<pre>'; |
---|
| 292 | echo '--- OLD: '; |
---|
[81] | 293 | print_r($old_values); |
---|
[72] | 294 | echo '<br>--- NEW: '; |
---|
[81] | 295 | print_r($new_values); |
---|
[72] | 296 | echo '<br>'; |
---|
[438] | 297 | exit; |
---|
| 298 | */ |
---|
[81] | 299 | |
---|
[32] | 300 | $manager_account_lid = $_SESSION['phpgw_session']['session_lid']; |
---|
| 301 | if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) && |
---|
| 302 | (!$this->functions->check_acl($manager_account_lid,'change_users_password')) && |
---|
[64] | 303 | (!$this->functions->check_acl($manager_account_lid,'edit_sambausers_attributes')) && |
---|
[317] | 304 | (!$this->functions->check_acl($manager_account_lid,'manipulate_corporative_information')) && |
---|
| 305 | (!$this->functions->check_acl($manager_account_lid,'edit_users_phonenumber')) |
---|
[32] | 306 | ) |
---|
| 307 | { |
---|
| 308 | $return['status'] = false; |
---|
[414] | 309 | $return['msg'] = lang('You do not have access to edit user informations') . '.'; |
---|
[32] | 310 | return $return; |
---|
| 311 | } |
---|
| 312 | |
---|
[438] | 313 | // Check manager access |
---|
[2] | 314 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) |
---|
| 315 | { |
---|
| 316 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 317 | // Change user organization |
---|
| 318 | if ($diff['context']) |
---|
| 319 | { |
---|
[355] | 320 | if (strcasecmp($old_values['context'], $new_values['context']) != 0) |
---|
[2] | 321 | { |
---|
[355] | 322 | $newrdn = 'uid=' . $new_values['uid']; |
---|
| 323 | $newparent = $new_values['context']; |
---|
| 324 | $result = $this->ldap_functions->change_user_context($dn, $newrdn, $newparent); |
---|
| 325 | if (!$result['status']) |
---|
| 326 | { |
---|
| 327 | $return['status'] = false; |
---|
| 328 | $return['msg'] .= $result['msg']; |
---|
| 329 | } |
---|
| 330 | else |
---|
| 331 | { |
---|
| 332 | $dn = $newrdn . ',' . $newparent; |
---|
[414] | 333 | $this->db_functions->write_log('modified user context', $dn . ': ' . $old_values['uid'] . '->' . $new_values['context']); |
---|
[355] | 334 | } |
---|
[2] | 335 | } |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 339 | // REPLACE some attributes |
---|
| 340 | if ($diff['givenname']) |
---|
| 341 | { |
---|
| 342 | $ldap_mod_replace['givenname'] = $new_values['givenname']; |
---|
| 343 | $ldap_mod_replace['cn'] = $new_values['givenname'] . ' ' . $new_values['sn']; |
---|
[414] | 344 | $this->db_functions->write_log("modified first name", "$dn: " . $old_values['givenname'] . "->" . $new_values['givenname']); |
---|
[2] | 345 | } |
---|
| 346 | if ($diff['sn']) |
---|
| 347 | { |
---|
| 348 | $ldap_mod_replace['sn'] = $new_values['sn']; |
---|
| 349 | $ldap_mod_replace['cn'] = $new_values['givenname'] . ' ' . $new_values['sn']; |
---|
[414] | 350 | $this->db_functions->write_log("modified last name", "$dn: " . $old_values['sn'] . "->" . $new_values['sn']); |
---|
[2] | 351 | } |
---|
| 352 | if ($diff['mail']) |
---|
| 353 | { |
---|
| 354 | $ldap_mod_replace['mail'] = $new_values['mail']; |
---|
| 355 | $this->ldap_functions->replace_user2maillists($new_values['mail'], $old_values['mail']); |
---|
[317] | 356 | $this->ldap_functions->replace_mail_from_institutional_account($new_values['mail'], $old_values['mail']); |
---|
[414] | 357 | $this->db_functions->write_log("modified user email", "$dn: " . $old_values['mail'] . "->" . $new_values['mail']); |
---|
[2] | 358 | } |
---|
[72] | 359 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 360 | // Passwd Expired - Com atributo |
---|
[414] | 361 | if (($old_values['passwd_expired'] != 0) && ($new_values['passwd_expired'] == '1')) |
---|
[72] | 362 | { |
---|
| 363 | $ldap_mod_replace['phpgwlastpasswdchange'] = '0'; |
---|
[414] | 364 | $this->db_functions->write_log("Expired user password","$dn"); |
---|
[72] | 365 | } |
---|
[2] | 366 | } |
---|
| 367 | |
---|
| 368 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
| 369 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'change_users_password')) ) |
---|
| 370 | { |
---|
| 371 | if ($diff['password1']) |
---|
| 372 | { |
---|
| 373 | $ldap_mod_replace['userPassword'] = '{md5}' . base64_encode(pack("H*",md5($new_values['password1']))); |
---|
[46] | 374 | |
---|
[2] | 375 | // Suporte ao SAMBA |
---|
| 376 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($new_values['userSamba']) && ($new_values['use_attrs_samba'] == 'on')) |
---|
| 377 | { |
---|
| 378 | $ldap_mod_replace['sambaLMPassword'] = exec('/home/expressolivre/mkntpwd -L '.$new_values['password1']); |
---|
| 379 | $ldap_mod_replace['sambaNTPassword'] = exec('/home/expressolivre/mkntpwd -N '.$new_values['password1']); |
---|
| 380 | } |
---|
[46] | 381 | |
---|
| 382 | // Gerenciar senhas RFC2617 |
---|
| 383 | if ($this->current_config['expressoAdmin_userPasswordRFC2617'] == 'true') |
---|
| 384 | { |
---|
| 385 | $realm = $this->current_config['expressoAdmin_realm_userPasswordRFC2617']; |
---|
| 386 | $uid = $new_values['uid']; |
---|
| 387 | $password = $new_values['password1']; |
---|
| 388 | $passUserRFC2617 = $realm . ': ' . md5("$uid:$realm:$password"); |
---|
| 389 | |
---|
| 390 | if ($old_values['userPasswordRFC2617'] != '') |
---|
| 391 | $ldap_mod_replace['userPasswordRFC2617'] = $passUserRFC2617; |
---|
| 392 | else |
---|
| 393 | $ldap_add['userPasswordRFC2617'] = $passUserRFC2617; |
---|
| 394 | } |
---|
| 395 | |
---|
[414] | 396 | $this->db_functions->write_log("modified user password",$dn); |
---|
[2] | 397 | } |
---|
| 398 | } |
---|
[317] | 399 | |
---|
| 400 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
| 401 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users_phonenumber')) ) |
---|
| 402 | { |
---|
| 403 | if (($diff['telephonenumber']) && ($old_values['telephonenumber'] != '')) |
---|
| 404 | { |
---|
| 405 | $ldap_mod_replace['telephonenumber'] = $new_values['telephonenumber']; |
---|
[414] | 406 | $this->db_functions->write_log('modified user telephonenumber', $dn . ': ' . $old_values['telephonenumber'] . '->' . $new_values['telephonenumber']); |
---|
[317] | 407 | } |
---|
| 408 | } |
---|
[63] | 409 | |
---|
| 410 | // REPLACE, ADD & REMOVE COPORATIVEs ATRIBUTES |
---|
| 411 | // Verifica o acesso do gerente aos atributos corporativos |
---|
[64] | 412 | |
---|
| 413 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
| 414 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'manipulate_corporative_information')) ) |
---|
[63] | 415 | { |
---|
| 416 | foreach ($new_values as $atribute=>$value) |
---|
| 417 | { |
---|
[64] | 418 | $pos = strstr($atribute, 'corporative_information_'); |
---|
[63] | 419 | if ($pos !== false) |
---|
| 420 | { |
---|
| 421 | $ldap_atribute = str_replace("corporative_information_", "", $atribute); |
---|
[414] | 422 | // REPLACE CORPORATIVE ATTRIBUTES |
---|
[63] | 423 | if (($diff[$atribute]) && ($old_values[$atribute] != '')) |
---|
| 424 | { |
---|
| 425 | $ldap_atribute = str_replace("corporative_information_", "", $atribute); |
---|
[414] | 426 | $ldap_mod_replace[$ldap_atribute] = utf8_encode($new_values[$atribute]); |
---|
| 427 | $this->db_functions->write_log('modified user attribute', $dn . ': ' . $ldap_atribute . ': ' . $old_values[$atribute] . '->' . $new_values[$atribute]); |
---|
[63] | 428 | } |
---|
[414] | 429 | //ADD CORPORATIVE ATTRIBUTES |
---|
[63] | 430 | elseif (($old_values[$atribute] == '') && ($new_values[$atribute] != '')) |
---|
| 431 | { |
---|
[414] | 432 | $ldap_add[$ldap_atribute] = utf8_encode($new_values[$atribute]); |
---|
| 433 | $this->db_functions->write_log('added user attribute', $dn . ': ' . $ldap_atribute . ': ' . $old_values[$atribute] . '->' . $new_values[$atribute]); |
---|
[63] | 434 | } |
---|
[414] | 435 | //REMOVE CORPORATIVE ATTRIBUTES |
---|
[63] | 436 | elseif (($old_values[$atribute] != '') && ($new_values[$atribute] == '')) |
---|
| 437 | { |
---|
| 438 | $ldap_remove[$ldap_atribute] = array(); |
---|
[414] | 439 | $this->db_functions->write_log('removed user attribute', $dn . ': ' . $ldap_atribute . ': ' . $old_values[$atribute] . '->' . $new_values[$atribute]); |
---|
[63] | 440 | } |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | } |
---|
| 444 | |
---|
[2] | 445 | //Suporte ao SAMBA |
---|
| 446 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
| 447 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_sambausers_attributes')) ) |
---|
| 448 | { |
---|
[355] | 449 | |
---|
| 450 | if ($diff['gidnumber']) |
---|
| 451 | { |
---|
| 452 | $ldap_mod_replace['gidnumber'] = $new_values['gidnumber']; |
---|
[414] | 453 | $this->db_functions->write_log('modified user primary group', $dn . ': ' . $old_values['gidnumber'] . '->' . $new_values['gidnumber']); |
---|
[355] | 454 | } |
---|
| 455 | |
---|
[2] | 456 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($new_values['userSamba']) && ($new_values['use_attrs_samba'] == 'on')) |
---|
| 457 | { |
---|
[355] | 458 | if ($diff['gidnumber']) |
---|
| 459 | { |
---|
| 460 | $ldap_mod_replace['sambaPrimaryGroupSID'] = $this->current_config['expressoAdmin_sambaSID'] . '-' . ((2 * $new_values['gidnumber'])+1001); |
---|
[414] | 461 | $this->db_functions->write_log('modified user sambaPrimaryGroupSID', $dn); |
---|
[355] | 462 | } |
---|
| 463 | |
---|
[2] | 464 | if ($diff['sambaacctflags']) |
---|
| 465 | { |
---|
| 466 | $ldap_mod_replace['sambaacctflags'] = $new_values['sambaacctflags']; |
---|
[414] | 467 | $this->db_functions->write_log("modified user sambaacctflags",$dn); |
---|
[2] | 468 | } |
---|
| 469 | if ($diff['sambalogonscript']) |
---|
| 470 | { |
---|
| 471 | $ldap_mod_replace['sambalogonscript'] = $new_values['sambalogonscript']; |
---|
[414] | 472 | $this->db_functions->write_log("modified user sambalogonscript",$dn); |
---|
[2] | 473 | } |
---|
| 474 | if ($diff['sambahomedirectory']) |
---|
| 475 | { |
---|
| 476 | $ldap_mod_replace['homedirectory'] = $new_values['sambahomedirectory']; |
---|
[414] | 477 | $this->db_functions->write_log("modified user homedirectory",$dn); |
---|
[2] | 478 | } |
---|
[27] | 479 | if ($diff['sambadomain']) |
---|
| 480 | { |
---|
| 481 | $ldap_mod_replace['sambaSID'] = $diff['sambadomain'] . '-' . ((2 * $old_values['uidnumber'])+1000); |
---|
| 482 | $ldap_mod_replace['sambaPrimaryGroupSID'] = $diff['sambadomain'] . '-' . ((2 * $old_values['gidnumber'])+1001); |
---|
[414] | 483 | $this->db_functions->write_log('modified user samba domain', $dn . ': ' . $old_values['sambadomain'] . '->' . $new_values['sambadomain']); |
---|
[27] | 484 | } |
---|
[2] | 485 | } |
---|
| 486 | } |
---|
| 487 | |
---|
| 488 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[81] | 489 | // ADD or REMOVE some attributes |
---|
[2] | 490 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[180] | 491 | |
---|
| 492 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 493 | // PHOTO |
---|
| 494 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users_picture')) |
---|
| 495 | { |
---|
| 496 | if ($new_values['delete_photo']) |
---|
| 497 | { |
---|
| 498 | $this->ldap_functions->ldap_remove_photo($dn); |
---|
[414] | 499 | $this->db_functions->write_log("removed user photo",$dn); |
---|
[180] | 500 | } |
---|
| 501 | elseif ($_FILES['photo']['name'] != '') |
---|
| 502 | { |
---|
[283] | 503 | |
---|
| 504 | if ($_FILES['photo']['size'] > 10000) |
---|
| 505 | { |
---|
| 506 | $return['status'] = false; |
---|
[414] | 507 | $return['msg'] .= lang('User photo could not be save because is bigger the 10 kb') . '.'; |
---|
[283] | 508 | } |
---|
| 509 | else |
---|
| 510 | { |
---|
[309] | 511 | if ($new_values['photo_exist']) |
---|
| 512 | { |
---|
| 513 | $photo_exist = true; |
---|
[414] | 514 | $this->db_functions->write_log("mofified user photo",$dn); |
---|
[309] | 515 | } |
---|
| 516 | else |
---|
| 517 | { |
---|
| 518 | $photo_exist = false; |
---|
[414] | 519 | $this->db_functions->write_log("added user photo",$dn); |
---|
[309] | 520 | } |
---|
| 521 | $this->ldap_functions->ldap_save_photo($dn, $_FILES['photo']['tmp_name'], $new_values['photo_exist'], $photo_exist); |
---|
[180] | 522 | } |
---|
| 523 | } |
---|
| 524 | } |
---|
[2] | 525 | |
---|
| 526 | // Verifica o acesso ára adicionar ou remover tais atributos |
---|
| 527 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) |
---|
| 528 | { |
---|
| 529 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 530 | // TELEPHONE |
---|
| 531 | if (($old_values['telephonenumber'] == '') && ($new_values['telephonenumber'] != '')) |
---|
| 532 | { |
---|
| 533 | $ldap_add['telephonenumber'] = $new_values['telephonenumber']; |
---|
[414] | 534 | $this->db_functions->write_log("added user phone",$dn); |
---|
[2] | 535 | } |
---|
| 536 | if (($old_values['telephonenumber'] != '') && ($new_values['telephonenumber'] == '')) |
---|
| 537 | { |
---|
| 538 | $ldap_remove['telephonenumber'] = array(); |
---|
[414] | 539 | $this->db_functions->write_log("removed user phone",$dn); |
---|
[2] | 540 | } |
---|
| 541 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[72] | 542 | // Passwd Expired - Sem atributo |
---|
| 543 | if (($old_values['passwd_expired'] == '') && ($new_values['passwd_expired'] == '1')) |
---|
| 544 | { |
---|
| 545 | $ldap_add['phpgwlastpasswdchange'] = '0'; |
---|
[414] | 546 | $this->db_functions->write_log("expired user password",$dn); |
---|
[72] | 547 | } |
---|
| 548 | if (($old_values['passwd_expired'] == '0') && ($new_values['passwd_expired'] == '')) |
---|
| 549 | { |
---|
| 550 | $ldap_remove['phpgwlastpasswdchange'] = array(); |
---|
[414] | 551 | $this->db_functions->write_log("removed expiry from user password",$dn); |
---|
[72] | 552 | } |
---|
| 553 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[2] | 554 | // PREF_CHANGEPASSWORD |
---|
| 555 | if (($old_values['changepassword'] == '') && ($new_values['changepassword'] != '')) |
---|
| 556 | { |
---|
| 557 | $this->db_functions->add_pref_changepassword($new_values['uidnumber']); |
---|
[414] | 558 | $this->db_functions->write_log("turn on changepassword",$dn); |
---|
[2] | 559 | } |
---|
| 560 | if (($old_values['changepassword'] != '') && ($new_values['changepassword'] == '')) |
---|
| 561 | { |
---|
| 562 | $this->db_functions->remove_pref_changepassword($new_values['uidnumber']); |
---|
[414] | 563 | $this->db_functions->write_log("turn of changepassword",$dn); |
---|
[2] | 564 | } |
---|
| 565 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 566 | // ACCOUNT STATUS |
---|
| 567 | if (($old_values['phpgwaccountstatus'] == '') && ($new_values['phpgwaccountstatus'] != '')) |
---|
| 568 | { |
---|
| 569 | $ldap_add['phpgwaccountstatus'] = 'A'; |
---|
[414] | 570 | $this->db_functions->write_log("turn on user account",$dn); |
---|
[2] | 571 | } |
---|
| 572 | if (($old_values['phpgwaccountstatus'] != '') && ($new_values['phpgwaccountstatus'] == '')) |
---|
| 573 | { |
---|
| 574 | $ldap_remove['phpgwaccountstatus'] = array(); |
---|
[414] | 575 | $this->db_functions->write_log("turn off user account",$dn); |
---|
[2] | 576 | } |
---|
| 577 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 578 | // ACCOUNT VISIBLE |
---|
| 579 | if (($old_values['phpgwaccountvisible'] == '') && ($new_values['phpgwaccountvisible'] != '')) |
---|
| 580 | { |
---|
| 581 | $ldap_add['phpgwaccountvisible'] = '-1'; |
---|
[414] | 582 | $this->db_functions->write_log("turn on phpgwaccountvisible",$dn); |
---|
[2] | 583 | } |
---|
| 584 | if (($old_values['phpgwaccountvisible'] != '') && ($new_values['phpgwaccountvisible'] == '')) |
---|
| 585 | { |
---|
| 586 | $ldap_remove['phpgwaccountvisible'] = array(); |
---|
[414] | 587 | $this->db_functions->write_log("turn off phpgwaccountvisible",$dn); |
---|
[2] | 588 | } |
---|
| 589 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 590 | // Mail Account STATUS |
---|
| 591 | if (($old_values['accountstatus'] == '') && ($new_values['accountstatus'] != '')) |
---|
| 592 | { |
---|
| 593 | $ldap_add['accountstatus'] = 'active'; |
---|
[414] | 594 | $this->db_functions->write_log("turn on user account email",$dn); |
---|
[2] | 595 | } |
---|
| 596 | if (($old_values['accountstatus'] != '') && ($new_values['accountstatus'] == '')) |
---|
| 597 | { |
---|
| 598 | $ldap_remove['accountstatus'] = array(); |
---|
[414] | 599 | $this->db_functions->write_log("turn off user account email",$dn); |
---|
[2] | 600 | } |
---|
| 601 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 602 | // MAILALTERNATEADDRESS |
---|
[81] | 603 | if (!$new_values['mailalternateaddress']) |
---|
| 604 | $new_values['mailalternateaddress'] = array(); |
---|
| 605 | if (!$old_values['mailalternateaddress']) |
---|
| 606 | $old_values['mailalternateaddress'] = array(); |
---|
| 607 | $add_mailalternateaddress = array_diff($new_values['mailalternateaddress'], $old_values['mailalternateaddress']); |
---|
| 608 | $remove_mailalternateaddress = array_diff($old_values['mailalternateaddress'], $new_values['mailalternateaddress']); |
---|
| 609 | foreach ($add_mailalternateaddress as $index=>$mailalternateaddress) |
---|
| 610 | { |
---|
| 611 | if ($mailalternateaddress != '') |
---|
| 612 | { |
---|
| 613 | $ldap_add['mailalternateaddress'][] = $mailalternateaddress; |
---|
[414] | 614 | $this->db_functions->write_log("added mailalternateaddress","$dn: $mailalternateaddress"); |
---|
[81] | 615 | } |
---|
| 616 | } |
---|
| 617 | foreach ($remove_mailalternateaddress as $index=>$mailalternateaddress) |
---|
| 618 | { |
---|
| 619 | if ($mailalternateaddress != '') |
---|
| 620 | { |
---|
| 621 | if ($index !== 'count') |
---|
| 622 | { |
---|
| 623 | $ldap_remove['mailalternateaddress'][] = $mailalternateaddress; |
---|
[414] | 624 | $this->db_functions->write_log("removed mailalternateaddress","$dn: $mailalternateaddress"); |
---|
[81] | 625 | } |
---|
| 626 | } |
---|
| 627 | } |
---|
| 628 | |
---|
| 629 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 630 | // MAILFORWARDINGADDRESS |
---|
| 631 | if (!$new_values['mailforwardingaddress']) |
---|
| 632 | $new_values['mailforwardingaddress'] = array(); |
---|
| 633 | if (!$old_values['mailforwardingaddress']) |
---|
| 634 | $old_values['mailforwardingaddress'] = array(); |
---|
| 635 | $add_mailforwardingaddress = array_diff($new_values['mailforwardingaddress'], $old_values['mailforwardingaddress']); |
---|
| 636 | $remove_mailforwardingaddress = array_diff($old_values['mailforwardingaddress'], $new_values['mailforwardingaddress']); |
---|
| 637 | foreach ($add_mailforwardingaddress as $index=>$mailforwardingaddress) |
---|
| 638 | { |
---|
| 639 | if ($mailforwardingaddress != '') |
---|
| 640 | { |
---|
| 641 | $ldap_add['mailforwardingaddress'][] = $mailforwardingaddress; |
---|
[414] | 642 | $this->db_functions->write_log("added mailforwardingaddress","$dn: $mailforwardingaddress"); |
---|
[81] | 643 | } |
---|
| 644 | } |
---|
| 645 | foreach ($remove_mailforwardingaddress as $index=>$mailforwardingaddress) |
---|
| 646 | { |
---|
| 647 | if ($mailforwardingaddress != '') |
---|
| 648 | { |
---|
| 649 | if ($index !== 'count') |
---|
| 650 | { |
---|
| 651 | $ldap_remove['mailforwardingaddress'][] = $mailforwardingaddress; |
---|
[414] | 652 | $this->db_functions->write_log("removed mailforwardingaddress","$dn: $mailforwardingaddress"); |
---|
[81] | 653 | } |
---|
| 654 | } |
---|
| 655 | } |
---|
| 656 | |
---|
| 657 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[2] | 658 | // Delivery Mode |
---|
| 659 | if (($old_values['deliverymode'] == '') && ($new_values['deliverymode'] != '')) |
---|
| 660 | { |
---|
| 661 | $ldap_add['deliverymode'] = 'forwardOnly'; |
---|
[414] | 662 | $this->db_functions->write_log("added forwardOnly", $dn); |
---|
[2] | 663 | } |
---|
| 664 | if (($old_values['deliverymode'] != '') && ($new_values['deliverymode'] == '')) |
---|
| 665 | { |
---|
| 666 | $ldap_remove['deliverymode'] = array(); |
---|
[414] | 667 | $this->db_functions->write_log("removed forwardOnly", $dn); |
---|
[2] | 668 | } |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
| 672 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'change_users_quote')) ) |
---|
| 673 | { |
---|
| 674 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 675 | // MAILQUOTA |
---|
| 676 | if ($diff['mailquota']) |
---|
| 677 | { |
---|
| 678 | $this->imap_functions->change_user_quota($new_values['uid'], $new_values['mailquota']); |
---|
[414] | 679 | $this->db_functions->write_log("modified user email quota", $dn); |
---|
[2] | 680 | } |
---|
| 681 | } |
---|
[63] | 682 | |
---|
[2] | 683 | if ( ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) || |
---|
| 684 | ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_sambausers_attributes')) ) |
---|
| 685 | { |
---|
| 686 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 687 | // REMOVE ATTRS OF SAMBA |
---|
| 688 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($new_values['userSamba']) && ($new_values['use_attrs_samba'] != 'on')) |
---|
| 689 | { |
---|
| 690 | $ldap_remove['objectclass'] = 'sambaSamAccount'; |
---|
| 691 | $ldap_remove['loginShell'] = array(); |
---|
| 692 | $ldap_remove['sambaSID'] = array(); |
---|
| 693 | $ldap_remove['sambaPrimaryGroupSID'] = array(); |
---|
| 694 | $ldap_remove['sambaAcctFlags'] = array(); |
---|
| 695 | $ldap_remove['sambaLogonScript'] = array(); |
---|
| 696 | $ldap_remove['sambaLMPassword'] = array(); |
---|
| 697 | $ldap_remove['sambaNTPassword'] = array(); |
---|
| 698 | $ldap_remove['sambaPasswordHistory'] = array(); |
---|
| 699 | $ldap_remove['sambaPwdCanChange'] = array(); |
---|
| 700 | $ldap_remove['sambaPwdLastSet'] = array(); |
---|
| 701 | $ldap_remove['sambaPwdMustChange'] = array(); |
---|
[414] | 702 | $this->db_functions->write_log("removed user samba attributes", $dn); |
---|
[2] | 703 | } |
---|
| 704 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 705 | // ADD ATTRS OF SAMBA |
---|
| 706 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && (!$new_values['userSamba']) && ($new_values['use_attrs_samba'] == 'on')) |
---|
| 707 | { |
---|
| 708 | if (!is_file('/home/expressolivre/mkntpwd')) |
---|
| 709 | { |
---|
| 710 | $return['status'] = false; |
---|
[414] | 711 | $return['msg'] .= lang("The file /home/expressolivre/mkntpwd does not exist") . ".\n"; |
---|
| 712 | $return['msg'] .= lang("It is necessery to create samba passwords") . ".\n"; |
---|
| 713 | $return['msg'] .= lang("Inform your system administrator about this") . ".\n"; |
---|
[2] | 714 | } |
---|
| 715 | else |
---|
| 716 | { |
---|
| 717 | $ldap_add['objectClass'][] = 'sambaSamAccount'; |
---|
| 718 | $ldap_mod_replace['loginShell'] = '/bin/bash'; |
---|
[47] | 719 | $ldap_add['sambaSID'] = $new_values['sambadomain'] . '-' . ((2 * $new_values['uidnumber'])+1000); |
---|
| 720 | $ldap_add['sambaPrimaryGroupSID'] = $new_values['sambadomain'] . '-' . ((2 * $new_values['gidnumber'])+1001); |
---|
[2] | 721 | $ldap_add['sambaAcctFlags'] = $new_values['sambaacctflags']; |
---|
| 722 | $ldap_add['sambaLogonScript'] = $new_values['sambalogonscript']; |
---|
| 723 | $ldap_mod_replace['homeDirectory'] = $new_values['sambahomedirectory']; |
---|
| 724 | $ldap_add['sambaLMPassword'] = exec('/home/expressolivre/mkntpwd -L '.'senha'); |
---|
| 725 | $ldap_add['sambaNTPassword'] = exec('/home/expressolivre/mkntpwd -N '.'senha'); |
---|
| 726 | $ldap_add['sambaPasswordHistory'] = '0000000000000000000000000000000000000000000000000000000000000000'; |
---|
| 727 | $ldap_add['sambaPwdCanChange'] = strtotime("now"); |
---|
| 728 | $ldap_add['sambaPwdLastSet'] = strtotime("now"); |
---|
| 729 | $ldap_add['sambaPwdMustChange'] = '2147483647'; |
---|
[414] | 730 | $this->db_functions->write_log("added user samba attribute", $dn); |
---|
[2] | 731 | } |
---|
| 732 | } |
---|
| 733 | } |
---|
| 734 | |
---|
| 735 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 736 | // GROUPS |
---|
[379] | 737 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_groups')) |
---|
[2] | 738 | { |
---|
[379] | 739 | // If the manager does not have the suficient access, the new_values.uid is empty. |
---|
| 740 | if (empty($new_values['uid'])) |
---|
| 741 | $user_uid = $old_values['uid']; |
---|
| 742 | else |
---|
| 743 | $user_uid = $new_values['uid']; |
---|
| 744 | |
---|
[2] | 745 | if (!$new_values['groups']) |
---|
| 746 | $new_values['groups'] = array(); |
---|
| 747 | if (!$old_values['groups']) |
---|
| 748 | $old_values['groups'] = array(); |
---|
| 749 | |
---|
| 750 | $add_groups = array_diff($new_values['groups'], $old_values['groups']); |
---|
| 751 | $remove_groups = array_diff($old_values['groups'], $new_values['groups']); |
---|
| 752 | |
---|
| 753 | if (count($add_groups)>0) |
---|
| 754 | { |
---|
| 755 | foreach($add_groups as $gidnumber) |
---|
| 756 | { |
---|
| 757 | $this->db_functions->add_user2group($gidnumber, $new_values['uidnumber']); |
---|
[379] | 758 | $this->ldap_functions->add_user2group($gidnumber, $user_uid); |
---|
[438] | 759 | $this->db_functions->write_log("included user to group", "uid:$user_uid -> gid:$gidnumber"); |
---|
[2] | 760 | } |
---|
| 761 | } |
---|
[64] | 762 | |
---|
[2] | 763 | if (count($remove_groups)>0) |
---|
| 764 | { |
---|
| 765 | foreach($remove_groups as $gidnumber) |
---|
| 766 | { |
---|
| 767 | foreach($old_values['groups_info'] as $group) |
---|
| 768 | { |
---|
| 769 | if (($group['gidnumber'] == $gidnumber) && ($group['group_disabled'] == 'false')) |
---|
| 770 | { |
---|
| 771 | $this->db_functions->remove_user2group($gidnumber, $new_values['uidnumber']); |
---|
[379] | 772 | $this->ldap_functions->remove_user2group($gidnumber, $user_uid); |
---|
[414] | 773 | $this->db_functions->write_log("removed user from group", "$dn: $gidnumber"); |
---|
[2] | 774 | } |
---|
| 775 | } |
---|
| 776 | } |
---|
| 777 | } |
---|
| 778 | } |
---|
| 779 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 780 | // LDAP_MOD_REPLACE |
---|
| 781 | if (count($ldap_mod_replace)) |
---|
| 782 | { |
---|
| 783 | $result = $this->ldap_functions->replace_user_attributes($dn, $ldap_mod_replace); |
---|
| 784 | if (!$result['status']) |
---|
| 785 | { |
---|
| 786 | $return['status'] = false; |
---|
| 787 | $return['msg'] .= $result['msg']; |
---|
| 788 | } |
---|
| 789 | } |
---|
| 790 | |
---|
| 791 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 792 | // LDAP_MOD_ADD |
---|
| 793 | if (count($ldap_add)) |
---|
| 794 | { |
---|
| 795 | $result = $this->ldap_functions->add_user_attributes($dn, $ldap_add); |
---|
| 796 | if (!$result['status']) |
---|
| 797 | { |
---|
| 798 | $return['status'] = false; |
---|
| 799 | $return['msg'] .= $result['msg']; |
---|
| 800 | } |
---|
| 801 | } |
---|
| 802 | |
---|
| 803 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 804 | // LDAP_MOD_REMOVE |
---|
| 805 | if (count($ldap_remove)) |
---|
| 806 | { |
---|
| 807 | $result = $this->ldap_functions->remove_user_attributes($dn, $ldap_remove); |
---|
| 808 | if (!$result['status']) |
---|
| 809 | { |
---|
| 810 | $return['status'] = false; |
---|
| 811 | $return['msg'] .= $result['msg']; |
---|
| 812 | } |
---|
| 813 | } |
---|
| 814 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 815 | |
---|
| 816 | |
---|
| 817 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_users')) |
---|
| 818 | { |
---|
| 819 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 820 | // MAILLISTS |
---|
| 821 | if (!$new_values['maillists']) |
---|
| 822 | $new_values['maillists'] = array(); |
---|
| 823 | if (!$old_values['maillists']) |
---|
| 824 | $old_values['maillists'] = array(); |
---|
[64] | 825 | |
---|
[2] | 826 | $add_maillists = array_diff($new_values['maillists'], $old_values['maillists']); |
---|
| 827 | $remove_maillists = array_diff($old_values['maillists'], $new_values['maillists']); |
---|
| 828 | |
---|
| 829 | if (count($add_maillists)>0) |
---|
| 830 | { |
---|
[208] | 831 | foreach($add_maillists as $uid) |
---|
[2] | 832 | { |
---|
[208] | 833 | $this->ldap_functions->add_user2maillist($uid, $new_values['mail']); |
---|
[438] | 834 | $this->db_functions->write_log("included user to maillist","$uid: $dn"); |
---|
[2] | 835 | } |
---|
| 836 | } |
---|
[414] | 837 | |
---|
[2] | 838 | if (count($remove_maillists)>0) |
---|
| 839 | { |
---|
[208] | 840 | foreach($remove_maillists as $uid) |
---|
[2] | 841 | { |
---|
[208] | 842 | $this->ldap_functions->remove_user2maillist($uid, $new_values['mail']); |
---|
[414] | 843 | $this->db_functions->write_log("removed user from maillist","$dn: $uid"); |
---|
[2] | 844 | } |
---|
| 845 | } |
---|
| 846 | |
---|
| 847 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 848 | // APPS |
---|
| 849 | $new_values2 = array(); |
---|
| 850 | $old_values2 = array(); |
---|
| 851 | if (count($new_values['apps'])>0) |
---|
| 852 | { |
---|
| 853 | foreach ($new_values['apps'] as $app=>$tmp) |
---|
| 854 | { |
---|
| 855 | $new_values2[] = $app; |
---|
| 856 | } |
---|
| 857 | } |
---|
| 858 | if (count($old_values['apps'])>0) |
---|
| 859 | { |
---|
| 860 | foreach ($old_values['apps'] as $app=>$tmp) |
---|
| 861 | { |
---|
| 862 | $old_values2[] = $app; |
---|
| 863 | } |
---|
| 864 | } |
---|
| 865 | $add_apps = array_flip(array_diff($new_values2, $old_values2)); |
---|
| 866 | $remove_apps = array_flip(array_diff($old_values2, $new_values2)); |
---|
| 867 | |
---|
| 868 | if (count($add_apps)>0) |
---|
| 869 | { |
---|
| 870 | $this->db_functions->add_id2apps($new_values['uidnumber'], $add_apps); |
---|
[9] | 871 | |
---|
| 872 | foreach ($add_apps as $app => $index) |
---|
[414] | 873 | $this->db_functions->write_log("added application to user","$dn: $app"); |
---|
[2] | 874 | } |
---|
| 875 | if (count($remove_apps)>0) |
---|
| 876 | { |
---|
[9] | 877 | //Verifica se o gerente tem acesso a aplicação antes de remove-la do usuario. |
---|
| 878 | $manager_apps = $this->db_functions->get_apps($_SESSION['phpgw_session']['session_lid']); |
---|
| 879 | |
---|
| 880 | foreach ($remove_apps as $app => $app_index) |
---|
| 881 | { |
---|
| 882 | if ($manager_apps[$app] == 'run') |
---|
| 883 | $remove_apps2[$app] = $app_index; |
---|
| 884 | } |
---|
| 885 | $this->db_functions->remove_id2apps($new_values['uidnumber'], $remove_apps2); |
---|
| 886 | |
---|
| 887 | foreach ($remove_apps2 as $app => $access) |
---|
[414] | 888 | $this->db_functions->write_log("removed application to user","$dn: $app"); |
---|
[2] | 889 | } |
---|
| 890 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 891 | } |
---|
| 892 | return $return; |
---|
| 893 | } |
---|
| 894 | |
---|
[64] | 895 | function get_user_info($uidnumber) |
---|
[2] | 896 | { |
---|
[64] | 897 | $user_info_ldap = $this->ldap_functions->get_user_info($uidnumber); |
---|
[2] | 898 | $user_info_db1 = $this->db_functions->get_user_info($uidnumber); |
---|
[64] | 899 | $user_info_db2 = $this->ldap_functions->gidnumbers2cn($user_info_db1['groups']); |
---|
[2] | 900 | $user_info_imap = $this->imap_functions->get_user_info($user_info_ldap['uid']); |
---|
| 901 | $user_info = array_merge($user_info_ldap, $user_info_db1, $user_info_db2, $user_info_imap); |
---|
| 902 | return $user_info; |
---|
| 903 | } |
---|
| 904 | |
---|
| 905 | function set_user_default_password($params) |
---|
| 906 | { |
---|
[458] | 907 | $return['status'] = 1; |
---|
[2] | 908 | $uid = $params['uid']; |
---|
| 909 | $defaultUserPassword = '{md5}'.base64_encode(pack("H*",md5($this->current_config['expressoAdmin_defaultUserPassword']))); |
---|
| 910 | |
---|
| 911 | if (!$this->db_functions->default_user_password_is_set($uid)) |
---|
| 912 | { |
---|
| 913 | $userPassword = $this->ldap_functions->set_user_password($uid, $defaultUserPassword); |
---|
| 914 | $this->db_functions->set_user_password($uid, $userPassword); |
---|
[458] | 915 | $this->db_functions->write_log("inserted default password",$uid); |
---|
[2] | 916 | } |
---|
| 917 | else |
---|
| 918 | { |
---|
[458] | 919 | $return['status'] = 0; |
---|
| 920 | $return['msg'] = $this->functions->lang('default password already registered') . '!'; |
---|
[2] | 921 | } |
---|
| 922 | |
---|
| 923 | return $return; |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | function return_user_password($params) |
---|
| 927 | { |
---|
[458] | 928 | $return['status'] = 1; |
---|
[2] | 929 | $uid = $params['uid']; |
---|
| 930 | |
---|
| 931 | if ($this->db_functions->default_user_password_is_set($uid)) |
---|
| 932 | { |
---|
| 933 | $userPassword = $this->db_functions->get_user_password($uid); |
---|
| 934 | $this->ldap_functions->set_user_password($uid, $userPassword); |
---|
| 935 | } |
---|
| 936 | else |
---|
| 937 | { |
---|
[458] | 938 | $return['status'] = 0; |
---|
| 939 | $return['msg'] = $this->functions->lang('default password not registered') . '!'; |
---|
[2] | 940 | } |
---|
| 941 | |
---|
[414] | 942 | $this->db_functions->write_log("returned user password",$uid); |
---|
[2] | 943 | |
---|
| 944 | return $return; |
---|
| 945 | } |
---|
| 946 | |
---|
| 947 | function delete($params) |
---|
| 948 | { |
---|
| 949 | $return['status'] = true; |
---|
| 950 | |
---|
| 951 | // Verifica o acesso do gerente |
---|
| 952 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_users')) |
---|
| 953 | { |
---|
| 954 | $uidnumber = $params['uidnumber']; |
---|
[64] | 955 | $user_info = $this->get_user_info($uidnumber); |
---|
[2] | 956 | |
---|
| 957 | //LDAP |
---|
| 958 | $result_ldap = $this->ldap_functions->delete_user($user_info); |
---|
| 959 | if (!$result_ldap['status']) |
---|
| 960 | { |
---|
| 961 | $return['status'] = false; |
---|
| 962 | $return['msg'] .= $result_ldap['msg']; |
---|
| 963 | } |
---|
[64] | 964 | else |
---|
[2] | 965 | { |
---|
[64] | 966 | //DB |
---|
| 967 | $result_db = $this->db_functions->delete_user($user_info); |
---|
| 968 | if (!$result_db['status']) |
---|
| 969 | { |
---|
| 970 | $return['status'] = false; |
---|
| 971 | $return['msg'] .= $result_ldap['msg']; |
---|
| 972 | } |
---|
[2] | 973 | |
---|
[64] | 974 | //IMAP |
---|
| 975 | $result_imap = $this->imap_functions->delete_user($user_info['uid']); |
---|
| 976 | if (!$result_imap['status']) |
---|
| 977 | { |
---|
| 978 | $return['status'] = false; |
---|
| 979 | $return['msg'] .= $result_ldap['msg']; |
---|
| 980 | } |
---|
[414] | 981 | $this->db_functions->write_log('deleted user', $user_info['uid']); |
---|
[2] | 982 | } |
---|
| 983 | } |
---|
| 984 | |
---|
| 985 | return $return; |
---|
| 986 | } |
---|
| 987 | |
---|
| 988 | |
---|
| 989 | function rename($params) |
---|
| 990 | { |
---|
| 991 | $return['status'] = true; |
---|
[64] | 992 | |
---|
| 993 | // Verifica acesso do gerente (OU) ao tentar renomear um usuário. |
---|
| 994 | if ( ! $this->ldap_functions->check_access_to_renamed($params['uid']) ) |
---|
| 995 | { |
---|
| 996 | $return['status'] = false; |
---|
[414] | 997 | $return['msg'] .= lang('You do not have access to delete user') . '.'; |
---|
[64] | 998 | return $return; |
---|
| 999 | } |
---|
[2] | 1000 | |
---|
[414] | 1001 | // Check if the new_uid is in use. |
---|
[396] | 1002 | if ( ! $this->ldap_functions->check_rename_new_uid($params['new_uid']) ) |
---|
| 1003 | { |
---|
| 1004 | $return['status'] = false; |
---|
[414] | 1005 | $return['msg'] = lang('New login already in use') . '.'; |
---|
[396] | 1006 | return $return; |
---|
| 1007 | } |
---|
| 1008 | |
---|
[2] | 1009 | // Verifica o acesso do gerente |
---|
| 1010 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'rename_users')) |
---|
| 1011 | { |
---|
| 1012 | $uid = $params['uid']; |
---|
| 1013 | $new_uid = $params['new_uid']; |
---|
| 1014 | $defaultUserPassword = '{md5}'.base64_encode(pack("H*",md5($this->current_config['expressoAdmin_defaultUserPassword']))); |
---|
| 1015 | $defaultUserPassword_plain = $this->current_config['expressoAdmin_defaultUserPassword']; |
---|
| 1016 | |
---|
| 1017 | $emailadmin_profiles = $this->db_functions->get_sieve_info(); |
---|
| 1018 | $sieve_enable = $emailadmin_profiles[0]['imapenablesieve']; |
---|
| 1019 | $sieve_server = $emailadmin_profiles[0]['imapsieveserver']; |
---|
| 1020 | $sieve_port = $emailadmin_profiles[0]['imapsieveport']; |
---|
| 1021 | |
---|
| 1022 | $imap_admin = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminUsername']; |
---|
| 1023 | $imap_passwd = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminPW']; |
---|
| 1024 | $imap_server = $_SESSION['phpgw_info']['expresso']['email_server']['imapServer']; |
---|
| 1025 | $imap_port = $_SESSION['phpgw_info']['expresso']['email_server']['imapPort']; |
---|
| 1026 | $imapDelimiter = $_SESSION['phpgw_info']['expresso']['email_server']['imapDelimiter']; |
---|
| 1027 | |
---|
| 1028 | //Verifica se está sendo usuado cyrus 2.2 ou superior |
---|
| 1029 | $sk = fsockopen ($imap_server,$imap_port); |
---|
| 1030 | $server_resp = fread($sk, 100); |
---|
| 1031 | $tmp = split('v2.', $server_resp); |
---|
| 1032 | $cyrus_version = '2' . $tmp[1][0]; |
---|
| 1033 | |
---|
[396] | 1034 | if ($cyrus_version < '22') |
---|
[2] | 1035 | { |
---|
[396] | 1036 | $return['status'] = false; |
---|
[414] | 1037 | $return['msg'] = "The rename user is only permitted with cyrus 2.2 or higher,"; |
---|
| 1038 | $return['msg'] .= "\nand with the option 'allowusermoves: yes' set in imapd.conf."; |
---|
| 1039 | |
---|
| 1040 | |
---|
[396] | 1041 | return $return; |
---|
| 1042 | } |
---|
| 1043 | |
---|
| 1044 | // Renomeia UID no openldap |
---|
| 1045 | $result = $this->ldap_functions->rename_uid($uid, $new_uid); |
---|
| 1046 | if (!$result['status']) |
---|
| 1047 | { |
---|
| 1048 | $return['status'] = false; |
---|
[414] | 1049 | $return['msg'] = lang("Error rename user in LDAP") . '.'; |
---|
[396] | 1050 | return $return; |
---|
| 1051 | } |
---|
| 1052 | |
---|
| 1053 | //Renomeia mailbox |
---|
| 1054 | $result = $this->imap_functions->rename_mailbox($uid, $new_uid); |
---|
| 1055 | if (!$result['status']) |
---|
| 1056 | { |
---|
| 1057 | // Back user uid. |
---|
| 1058 | $result = $this->ldap_functions->rename_uid($new_uid, $uid); |
---|
| 1059 | |
---|
| 1060 | $return['status'] = false; |
---|
[414] | 1061 | $return['msg'] = lang("Erro rename user in Cyrus") . '.'; |
---|
[396] | 1062 | return $return; |
---|
| 1063 | } |
---|
[30] | 1064 | |
---|
[396] | 1065 | |
---|
| 1066 | // Seta senha default |
---|
| 1067 | $user_password = $this->ldap_functions->set_user_password($new_uid, $defaultUserPassword); |
---|
| 1068 | |
---|
| 1069 | // Renomeia sieve script |
---|
| 1070 | include_once('sieve-php.lib.php'); |
---|
| 1071 | $sieve=new sieve($sieve_server, $sieve_port, $new_uid, $defaultUserPassword_plain); |
---|
[30] | 1072 | |
---|
[396] | 1073 | if ($sieve->sieve_login()) |
---|
| 1074 | { |
---|
| 1075 | $sieve->sieve_listscripts(); |
---|
| 1076 | $myactivescript=$sieve->response["ACTIVE"]; |
---|
| 1077 | $sieve->sieve_getscript($myactivescript); |
---|
| 1078 | |
---|
| 1079 | $script = ''; |
---|
| 1080 | if (!empty($sieve->response)) |
---|
[30] | 1081 | { |
---|
| 1082 | foreach($sieve->response as $result) |
---|
| 1083 | { |
---|
| 1084 | $script .= $result; |
---|
| 1085 | } |
---|
[396] | 1086 | } |
---|
[30] | 1087 | |
---|
[396] | 1088 | $scriptname = $new_uid; |
---|
| 1089 | if($sieve->sieve_sendscript($new_uid,$script)) |
---|
| 1090 | { |
---|
| 1091 | if ($sieve->sieve_setactivescript($new_uid)) |
---|
[30] | 1092 | { |
---|
[396] | 1093 | $sieve->sieve_deletescript($myactivescript); |
---|
[30] | 1094 | } |
---|
| 1095 | } |
---|
[396] | 1096 | else |
---|
[30] | 1097 | { |
---|
[414] | 1098 | $return['msg'] .= $result['msg'] . lang("Error renome sieve script") . '.'; |
---|
[30] | 1099 | } |
---|
[396] | 1100 | $sieve->sieve_logout(); |
---|
| 1101 | } |
---|
| 1102 | else |
---|
| 1103 | { |
---|
| 1104 | $return['status'] = false; |
---|
[414] | 1105 | $return['msg'] .= $result['msg'] . lang("Error renome sieve script") . '.'; |
---|
[396] | 1106 | } |
---|
[30] | 1107 | |
---|
[396] | 1108 | // Back user password. |
---|
| 1109 | $this->ldap_functions->set_user_password($new_uid, $user_password); |
---|
| 1110 | |
---|
[414] | 1111 | $this->db_functions->write_log("renamed user", "$uid -> $new_uid"); |
---|
[2] | 1112 | |
---|
[396] | 1113 | $return['exec_return'] = ""; |
---|
| 1114 | |
---|
[64] | 1115 | return $return; |
---|
[2] | 1116 | } |
---|
| 1117 | } |
---|
[63] | 1118 | |
---|
| 1119 | function write_log_from_ajax($params) |
---|
| 1120 | { |
---|
| 1121 | $this->db_functions->write_log($params['_action'],'',$params['userinfo'],'',''); |
---|
| 1122 | return true; |
---|
| 1123 | } |
---|
[2] | 1124 | } |
---|
| 1125 | ?> |
---|