[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - Setup * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 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 | |
---|
| 13 | $phpgw_info = array(); |
---|
| 14 | $phpgw_info["flags"] = array( |
---|
| 15 | 'noheader' => True, |
---|
| 16 | 'nonavbar' => True, |
---|
| 17 | 'currentapp' => 'home', |
---|
| 18 | 'noapi' => True |
---|
| 19 | ); |
---|
| 20 | include('./inc/functions.inc.php'); |
---|
| 21 | |
---|
| 22 | /* Authorize the user to use setup app and load the database */ |
---|
| 23 | if(!$GLOBALS['phpgw_setup']->auth('Config')) |
---|
| 24 | { |
---|
| 25 | Header('Location: index.php'); |
---|
| 26 | exit; |
---|
| 27 | } |
---|
| 28 | /* Does not return unless user is authorized */ |
---|
| 29 | |
---|
| 30 | class phpgw |
---|
| 31 | { |
---|
| 32 | var $common; |
---|
| 33 | var $accounts; |
---|
| 34 | var $applications; |
---|
| 35 | var $db; |
---|
| 36 | } |
---|
| 37 | $phpgw = new phpgw; |
---|
| 38 | $phpgw->common = CreateObject('phpgwapi.common'); |
---|
| 39 | |
---|
| 40 | $common = $phpgw->common; |
---|
| 41 | $GLOBALS['phpgw_setup']->loaddb(); |
---|
| 42 | copyobj($GLOBALS['phpgw_setup']->db,$phpgw->db); |
---|
| 43 | |
---|
| 44 | $tpl_root = $GLOBALS['phpgw_setup']->html->setup_tpl_dir('setup'); |
---|
| 45 | $setup_tpl = CreateObject('setup.Template',$tpl_root); |
---|
| 46 | $setup_tpl->set_file(array( |
---|
| 47 | 'ldap' => 'ldap.tpl', |
---|
| 48 | 'T_head' => 'head.tpl', |
---|
| 49 | 'T_footer' => 'footer.tpl', |
---|
| 50 | 'T_alert_msg' => 'msg_alert_msg.tpl' |
---|
| 51 | )); |
---|
| 52 | |
---|
[328] | 53 | $GLOBALS['phpgw_setup']->db->query("SELECT config_name,config_value FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name LIKE 'ldap%' OR config_name='account_repository'",__LINE__,__FILE__); |
---|
[2] | 54 | while($GLOBALS['phpgw_setup']->db->next_record()) |
---|
| 55 | { |
---|
| 56 | $config[$GLOBALS['phpgw_setup']->db->f('config_name')] = $GLOBALS['phpgw_setup']->db->f('config_value'); |
---|
| 57 | } |
---|
[328] | 58 | |
---|
[2] | 59 | $phpgw_info['server']['ldap_host'] = $config['ldap_host']; |
---|
| 60 | $phpgw_info['server']['ldap_context'] = $config['ldap_context']; |
---|
| 61 | $phpgw_info['server']['ldap_group_context'] = $config['ldap_group_context']; |
---|
| 62 | $phpgw_info['server']['ldap_root_dn'] = $config['ldap_root_dn']; |
---|
| 63 | $phpgw_info['server']['ldap_root_pw'] = $config['ldap_root_pw']; |
---|
| 64 | $phpgw_info['server']['account_repository'] = $config['account_repository']; |
---|
| 65 | $phpgw_info['server']['ldap_version3'] = $config['ldap_version3']; |
---|
| 66 | |
---|
| 67 | $phpgw->accounts = CreateObject('phpgwapi.accounts'); |
---|
| 68 | $acct = $phpgw->accounts; |
---|
| 69 | |
---|
| 70 | /* connect to ldap server */ |
---|
| 71 | if(!$ldap = $common->ldapConnect()) |
---|
| 72 | { |
---|
| 73 | $noldapconnection = True; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | if($noldapconnection) |
---|
| 77 | { |
---|
| 78 | Header('Location: config.php?error=badldapconnection'); |
---|
| 79 | exit; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | // Take the users from LDAP. |
---|
| 83 | $sr = ldap_search($ldap,$config['ldap_context'],'(|(uid=*))',array('cn','givenname','uid','uidnumber')); |
---|
| 84 | $info = ldap_get_entries($ldap, $sr); |
---|
| 85 | $tmp = ''; |
---|
| 86 | |
---|
| 87 | for($i=0; $i<$info['count']; $i++) |
---|
| 88 | { |
---|
| 89 | if(!$phpgw_info['server']['global_denied_users'][$info[$i]['uid'][0]]) |
---|
| 90 | { |
---|
| 91 | $account_info[$info[$i]['uidnumber'][0]] = $info[$i]; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | if($phpgw_info['server']['ldap_group_context']) |
---|
| 96 | { |
---|
| 97 | $srg = ldap_search($ldap,$config['ldap_group_context'],'(&(cn=*)(objectClass=posixGroup))',array('gidnumber','cn','memberuid')); |
---|
| 98 | $info = ldap_get_entries($ldap, $srg); |
---|
| 99 | $tmp = ''; |
---|
| 100 | |
---|
| 101 | for($i=0; $i<$info['count']; $i++) |
---|
| 102 | { |
---|
| 103 | if(!$phpgw_info['server']['global_denied_groups'][$info[$i]['cn'][0]] && |
---|
| 104 | !$account_info[$i][$info[$i]['cn'][0]]) |
---|
| 105 | { |
---|
| 106 | $group_info[$info[$i]['gidnumber'][0]] = $info[$i]; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | else |
---|
| 111 | { |
---|
| 112 | $group_info = array(); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | $GLOBALS['phpgw_setup']->db->query("SELECT app_name FROM phpgw_applications WHERE app_enabled!='0' AND app_enabled!='3' ORDER BY app_name",__LINE__,__FILE__); |
---|
| 116 | while($GLOBALS['phpgw_setup']->db->next_record()) |
---|
| 117 | { |
---|
| 118 | $apps[$GLOBALS['phpgw_setup']->db->f('app_name')] = lang($GLOBALS['phpgw_setup']->db->f('app_name')); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | if($cancel) |
---|
| 122 | { |
---|
| 123 | Header("Location: ldap.php"); |
---|
| 124 | exit; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | $GLOBALS['phpgw_setup']->html->show_header(lang('LDAP Modify'),False,'config',$GLOBALS['phpgw_setup']->ConfigDomain . '(' . $phpgw_domain[$GLOBALS['phpgw_setup']->ConfigDomain]['db_type'] . ')'); |
---|
| 128 | $setup_complete = False; |
---|
| 129 | if(isset($_POST['submit'])) |
---|
| 130 | { |
---|
| 131 | $acl = CreateObject('phpgwapi.acl'); |
---|
| 132 | copyobj($GLOBALS['phpgw_setup']->db,$acl->db); |
---|
| 133 | if(isset($_POST['ldapgroups'])) |
---|
| 134 | { |
---|
| 135 | $groups = CreateObject('phpgwapi.accounts'); |
---|
| 136 | copyobj($GLOBALS['phpgw_setup']->db,$groups->db); |
---|
| 137 | while(list($key,$groupid) = each($_POST['ldapgroups'])) |
---|
| 138 | { |
---|
| 139 | $id_exist = 0; |
---|
| 140 | $entry = array(); |
---|
| 141 | $thisacctid = $group_info[$groupid]['gidnumber'][0]; |
---|
| 142 | $thisacctlid = $group_info[$groupid]['cn'][0]; |
---|
| 143 | /* echo "Updating GROUPID : ".$thisacctlid."<br>\n"; */ |
---|
| 144 | $thisfirstname = $group_info[$groupid]['cn'][0]; |
---|
| 145 | $thismembers = $group_info[$groupid]['memberuid']; |
---|
| 146 | $thisdn = $group_info[$groupid]['dn']; |
---|
| 147 | |
---|
| 148 | /* Do some checks before we try to import the data. */ |
---|
| 149 | if(!empty($thisacctid) && !empty($thisacctlid)) |
---|
| 150 | { |
---|
| 151 | $groups->account_id = (int)$thisacctid; |
---|
| 152 | |
---|
| 153 | $sr = ldap_search($ldap,$config['ldap_group_context'],'cn='.$thisacctlid); |
---|
| 154 | $entry = ldap_get_entries($ldap, $sr); |
---|
| 155 | |
---|
| 156 | reset($entry[0]['objectclass']); |
---|
| 157 | $addclass = True; |
---|
| 158 | while(list($key,$value) = each($entry[0]['objectclass'])) |
---|
| 159 | { |
---|
| 160 | if(strtolower($value) == 'phpgwaccount') |
---|
| 161 | { |
---|
| 162 | $addclass = False; |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | if($addclass) |
---|
| 166 | { |
---|
| 167 | reset($entry[0]['objectclass']); |
---|
| 168 | $replace['objectclass'] = $entry[0]['objectclass']; |
---|
| 169 | unset($replace['objectclass']['count']); |
---|
| 170 | $replace['objectclass'][] = 'phpgwAccount'; |
---|
| 171 | sort($replace['objectclass']); |
---|
| 172 | ldap_mod_replace($ldap,$thisdn,$replace); |
---|
| 173 | unset($replace); |
---|
| 174 | unset($addclass); |
---|
| 175 | } |
---|
| 176 | unset($add); |
---|
| 177 | if(!@isset($entry[0]['phpgwaccountstatus'])) |
---|
| 178 | { |
---|
| 179 | $add['phpgwaccountstatus'][] = 'A'; |
---|
| 180 | } |
---|
| 181 | if(!@isset($entry[0]['phpgwaccounttype'])) |
---|
| 182 | { |
---|
| 183 | $add['phpgwaccounttype'][] = 'g'; |
---|
| 184 | } |
---|
| 185 | if(!@isset($entry[0]['phpgwaccountexpires'])) |
---|
| 186 | { |
---|
| 187 | $add['phpgwaccountexpires'][] = -1; |
---|
| 188 | } |
---|
| 189 | if(@isset($add)) |
---|
| 190 | { |
---|
| 191 | ldap_mod_add($ldap,$thisdn,$add); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | /* Now make the members a member of this group in phpgw. */ |
---|
| 195 | if(is_array($thismembers)) |
---|
| 196 | { |
---|
| 197 | foreach($thismembers as $key => $members) |
---|
| 198 | { |
---|
| 199 | if($key == 'count') |
---|
| 200 | { |
---|
| 201 | continue; |
---|
| 202 | } |
---|
| 203 | echo '<br>members: ' . $members; |
---|
| 204 | $tmpid = 0; |
---|
| 205 | @reset($account_info); |
---|
| 206 | while(list($x,$y) = each($account_info)) |
---|
| 207 | { |
---|
| 208 | //echo '<br>checking: '.$y['uid'][0]; |
---|
| 209 | if($members == $y['uid'][0]) |
---|
| 210 | { |
---|
| 211 | $tmpid = $y['uidnumber'][0]; |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | // Insert acls for this group based on memberuid field. |
---|
| 215 | // Since the group has app rights, we don't need to give users |
---|
| 216 | // these rights. Instead, we maintain group membership here. |
---|
| 217 | if($tmpid) |
---|
| 218 | { |
---|
| 219 | echo '<br>inserindo user_id: ' . $tmpid . ' em ' . $thisacctid; |
---|
| 220 | $acl->account_id = (int)$tmpid; |
---|
| 221 | $acl->read_repository(); |
---|
| 222 | |
---|
| 223 | $acl->delete('phpgw_group',$thisacctid,1); |
---|
| 224 | $acl->add('phpgw_group',$thisacctid,1); |
---|
| 225 | |
---|
| 226 | // Now add the acl to let them change their password |
---|
| 227 | $acl->delete('preferences','changepassword',1); |
---|
| 228 | $acl->add('preferences','changepassword',1); |
---|
| 229 | |
---|
| 230 | $acl->save_repository(); |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | /* Now give this group some rights */ |
---|
| 235 | $phpgw_info['user']['account_id'] = $thisacctid; |
---|
| 236 | $acl->account_id = (int)$thisacctid; |
---|
| 237 | $acl->read_repository(); |
---|
| 238 | @reset($_POST['s_apps']); |
---|
| 239 | while(list($key,$app) = @each($_POST['s_apps'])) |
---|
| 240 | { |
---|
| 241 | $acl->delete($app,'run',1); |
---|
| 242 | $acl->add($app,'run',1); |
---|
| 243 | } |
---|
| 244 | $acl->save_repository(); |
---|
| 245 | $defaultgroupid = $thisacctid; |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | if(isset($_POST['users'])) |
---|
| 251 | { |
---|
| 252 | $accounts = CreateObject('phpgwapi.accounts'); |
---|
| 253 | copyobj($GLOBALS['phpgw_setup']->db,$accounts->db); |
---|
| 254 | $users_process = 0; |
---|
| 255 | $new_uidnumber = 12011; |
---|
| 256 | while(list($key,$id) = each($_POST['users'])) |
---|
| 257 | { |
---|
| 258 | $id_exist = 0; |
---|
| 259 | $thisacctid = $account_info[$id]['uidnumber'][0]; |
---|
| 260 | $thisacctlid = $account_info[$id]['uid'][0]; |
---|
| 261 | $thisdn = $account_info[$id]['dn']; |
---|
| 262 | echo $thisdn . "<BR>\n"; |
---|
| 263 | echo "Updating USERID : ".$thisacctlid."<br>\n"; |
---|
| 264 | |
---|
| 265 | /* Do some checks before we try to import the data. */ |
---|
| 266 | if(!empty($thisacctid) && !empty($thisacctlid)) |
---|
| 267 | { |
---|
| 268 | $users_process++; |
---|
| 269 | |
---|
| 270 | $accounts->account_id = (int)$thisacctid; |
---|
| 271 | |
---|
| 272 | /* Insert default acls for this user. */ |
---|
| 273 | $acl->account_id = (int)$thisacctid; |
---|
| 274 | $acl->read_repository(); |
---|
| 275 | |
---|
| 276 | // Now add the acl to let them change their password |
---|
| 277 | $acl->delete('preferences','changepassword',1); |
---|
| 278 | $acl->add('preferences','changepassword',1); |
---|
| 279 | |
---|
| 280 | // Add user to a default group, previous created |
---|
| 281 | $acl->add('phpgw_group','12007',1); |
---|
| 282 | |
---|
| 283 | echo "Adding in ACL BD: ".$thisacctid."<br><br>\n"; |
---|
| 284 | /* Save these new acls. */ |
---|
| 285 | $acl->save_repository(); |
---|
| 286 | |
---|
| 287 | $new_uidnumber++; |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | $setup_complete = True; |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | if(isset($_GET['error'])) |
---|
| 295 | { |
---|
| 296 | /* echo '<br><center><b>Error:</b> '.$error.'</center>'; */ |
---|
| 297 | $GLOBALS['phpgw_setup']->html->show_alert_msg('Error',$_GET['error']); |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | if($setup_complete) |
---|
| 301 | { |
---|
| 302 | echo '<br><center>'.lang('Modifications have been completed!').' '.lang('Click <a href="index.php">here</a> to return to setup.').'<br><center>'; |
---|
| 303 | $GLOBALS['phpgw_setup']->html->show_footer(); |
---|
| 304 | exit; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | $setup_tpl->set_block('ldap','header','header'); |
---|
| 308 | $setup_tpl->set_block('ldap','user_list','user_list'); |
---|
| 309 | $setup_tpl->set_block('ldap','admin_list','admin_list'); |
---|
| 310 | $setup_tpl->set_block('ldap','group_list','group_list'); |
---|
| 311 | $setup_tpl->set_block('ldap','app_list','app_list'); |
---|
| 312 | $setup_tpl->set_block('ldap','submit','submit'); |
---|
| 313 | $setup_tpl->set_block('ldap','footer','footer'); |
---|
| 314 | |
---|
| 315 | $user_list = ''; |
---|
| 316 | while(list($key,$account) = @each($account_info)) |
---|
| 317 | { |
---|
| 318 | $user_list .= '<option value="' . $account['uidnumber'][0] . '">' . utf8_decode($account['cn'][0]) . ' (' . $account['uid'][0] . ')</option>'; |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | $admin_list = ''; |
---|
| 322 | @reset($account_info); |
---|
| 323 | while (list($key,$account) = @each($account_info)) |
---|
| 324 | { |
---|
| 325 | $admin_list .= '<option value="' . $account['uidnumber'][0] . '">' . utf8_decode($account['cn'][0]) . ' (' . $account['uid'][0] . ')</option>'; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | $group_list = ''; |
---|
| 329 | while(list($key,$group) = @each($group_info)) |
---|
| 330 | { |
---|
| 331 | $group_list .= '<option value="' . $group['gidnumber'][0] . '">' . utf8_decode($group['cn'][0]) . '</option>'; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | $app_list = ''; |
---|
| 335 | while(list($appname,$apptitle) = each($apps)) |
---|
| 336 | { |
---|
| 337 | if($appname == 'admin' || |
---|
| 338 | $appname == 'skel' || |
---|
| 339 | $appname == 'backup' || |
---|
| 340 | $appname == 'netsaint' || |
---|
| 341 | $appname == 'developer_tools' || |
---|
| 342 | $appname == 'phpsysinfo' || |
---|
| 343 | $appname == 'eldaptir' || |
---|
| 344 | $appname == 'qmailldap') |
---|
| 345 | { |
---|
| 346 | $app_list .= '<option value="' . $appname . '">' . $apptitle . '</option>'; |
---|
| 347 | } |
---|
| 348 | else |
---|
| 349 | { |
---|
| 350 | $app_list .= '<option value="' . $appname . '" selected>' . $apptitle . '</option>'; |
---|
| 351 | } |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | $setup_tpl->set_var('action_url','ldapmodify2.php'); |
---|
| 355 | $setup_tpl->set_var('users',$user_list); |
---|
| 356 | $setup_tpl->set_var('admins',$admin_list); |
---|
| 357 | $setup_tpl->set_var('ldapgroups',$group_list); |
---|
| 358 | $setup_tpl->set_var('s_apps',$app_list); |
---|
| 359 | |
---|
| 360 | $setup_tpl->set_var('ldap_import',lang('LDAP Modify')); |
---|
| 361 | $setup_tpl->set_var('description',lang("This section will help you setup your LDAP accounts for use with eGroupWare").'.'); |
---|
| 362 | $setup_tpl->set_var('select_users',lang('Select which user(s) will be modified')); |
---|
| 363 | $setup_tpl->set_var('select_admins',lang('Select which user(s) will also have admin privileges')); |
---|
| 364 | $setup_tpl->set_var('select_groups',lang('Select which group(s) will be modified (group membership will be maintained)')); |
---|
| 365 | $setup_tpl->set_var('select_apps',lang('Select the default applications to which your users will have access').'.'); |
---|
| 366 | $setup_tpl->set_var('form_submit',lang('Modify2')); |
---|
| 367 | $setup_tpl->set_var('cancel',lang('Cancel')); |
---|
| 368 | |
---|
| 369 | $setup_tpl->pfp('out','header'); |
---|
| 370 | $setup_tpl->pfp('out','user_list'); |
---|
| 371 | $setup_tpl->pfp('out','admin_list'); |
---|
| 372 | $setup_tpl->pfp('out','group_list'); |
---|
| 373 | $setup_tpl->pfp('out','app_list'); |
---|
| 374 | $setup_tpl->pfp('out','submit'); |
---|
| 375 | $setup_tpl->pfp('out','footer'); |
---|
| 376 | |
---|
| 377 | $GLOBALS['phpgw_setup']->html->show_footer(); |
---|
| 378 | ?> |
---|