[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%'",__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 | } |
---|
| 58 | $phpgw_info['server']['ldap_host'] = $config['ldap_host']; |
---|
| 59 | $phpgw_info['server']['ldap_context'] = $config['ldap_context']; |
---|
| 60 | $phpgw_info['server']['ldap_group_context'] = $config['ldap_group_context']; |
---|
| 61 | $phpgw_info['server']['ldap_root_dn'] = $config['ldap_root_dn']; |
---|
| 62 | $phpgw_info['server']['ldap_root_pw'] = $config['ldap_root_pw']; |
---|
| 63 | $phpgw_info['server']['ldap_account_home'] = $config['ldap_account_home']; |
---|
| 64 | $phpgw_info['server']['ldap_account_shell'] = $config['ldap_account_shell']; |
---|
| 65 | $phpgw_info['server']['ldap_extra_attributes'] = $config['ldap_extra_attributes']; |
---|
| 66 | $phpgw_info['server']['ldap_version3'] = $config['ldap_version3']; |
---|
| 67 | |
---|
| 68 | $phpgw_info['server']['account_repository'] = 'ldap'; |
---|
| 69 | |
---|
| 70 | $phpgw->accounts = CreateObject('phpgwapi.accounts'); |
---|
| 71 | $acct = $phpgw->accounts; |
---|
| 72 | |
---|
| 73 | // First, see if we can connect to the LDAP server, if not send `em back to config.php with an |
---|
| 74 | // error message. |
---|
| 75 | |
---|
| 76 | // connect to ldap server |
---|
| 77 | if(!$ldap = $common->ldapConnect()) |
---|
| 78 | { |
---|
| 79 | $noldapconnection = True; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if($noldapconnection) |
---|
| 83 | { |
---|
| 84 | Header('Location: config.php?error=badldapconnection'); |
---|
| 85 | exit; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | $sql = "SELECT * FROM phpgw_accounts WHERE account_type='u'"; |
---|
| 89 | $GLOBALS['phpgw_setup']->db->query($sql,__LINE__,__FILE__); |
---|
| 90 | while($GLOBALS['phpgw_setup']->db->next_record()) |
---|
| 91 | { |
---|
| 92 | $i = $GLOBALS['phpgw_setup']->db->f('account_id'); |
---|
| 93 | $account_info[$i]['account_id'] = $GLOBALS['phpgw_setup']->db->f('account_id'); |
---|
| 94 | $account_info[$i]['account_lid'] = $GLOBALS['phpgw_setup']->db->f('account_lid'); |
---|
| 95 | $account_info[$i]['account_firstname'] = $GLOBALS['phpgw_setup']->db->f('account_firstname'); |
---|
| 96 | $account_info[$i]['account_lastname'] = $GLOBALS['phpgw_setup']->db->f('account_lastname'); |
---|
| 97 | $account_info[$i]['account_status'] = $GLOBALS['phpgw_setup']->db->f('account_status'); |
---|
| 98 | $account_info[$i]['account_expires'] = $GLOBALS['phpgw_setup']->db->f('account_expires'); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | while(list($key,$data) = @each($account_info)) |
---|
| 102 | { |
---|
| 103 | $tmp = $data['account_id']; |
---|
| 104 | $newaccount[$tmp] = $data; |
---|
| 105 | } |
---|
| 106 | $account_info = $newaccount; |
---|
| 107 | |
---|
| 108 | $sql = "SELECT * FROM phpgw_accounts WHERE account_type='g'"; |
---|
| 109 | $GLOBALS['phpgw_setup']->db->query($sql,__LINE__,__FILE__); |
---|
| 110 | while($GLOBALS['phpgw_setup']->db->next_record()) |
---|
| 111 | { |
---|
| 112 | $i = $GLOBALS['phpgw_setup']->db->f('account_id'); |
---|
| 113 | $group_info[$i]['account_id'] = $GLOBALS['phpgw_setup']->db->f('account_id'); |
---|
| 114 | $group_info[$i]['account_lid'] = $GLOBALS['phpgw_setup']->db->f('account_lid'); |
---|
| 115 | $group_info[$i]['account_firstname'] = $GLOBALS['phpgw_setup']->db->f('account_firstname'); |
---|
| 116 | $group_info[$i]['account_lastname'] = $GLOBALS['phpgw_setup']->db->f('account_lastname'); |
---|
| 117 | $group_info[$i]['account_status'] = $GLOBALS['phpgw_setup']->db->f('account_status'); |
---|
| 118 | $group_info[$i]['account_expires'] = $GLOBALS['phpgw_setup']->db->f('account_expires'); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | while(list($key,$data) = @each($group_info)) |
---|
| 122 | { |
---|
| 123 | $tmp = $data['account_id'][0]; |
---|
| 124 | $newgroup[$tmp] = $data; |
---|
| 125 | } |
---|
| 126 | $group_info = $newgroup; |
---|
| 127 | |
---|
| 128 | $cancel = get_var('cancel','POST'); |
---|
| 129 | $submit = get_var('submit','POST'); |
---|
| 130 | $users = get_var('users','POST'); |
---|
| 131 | $admins = get_var('admins','POST'); |
---|
| 132 | $s_apps = get_var('s_apps','POST'); |
---|
| 133 | $ldapgroups = get_var('ldapgroups','POST'); |
---|
| 134 | |
---|
| 135 | if($cancel) |
---|
| 136 | { |
---|
| 137 | Header('Location: ldap.php'); |
---|
| 138 | exit; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | if($submit) |
---|
| 142 | { |
---|
| 143 | if($ldapgroups) |
---|
| 144 | { |
---|
| 145 | while(list($key,$groupid) = each($ldapgroups)) |
---|
| 146 | { |
---|
| 147 | $id_exist = 0; |
---|
| 148 | $thisacctid = $group_info[$groupid]['account_id']; |
---|
| 149 | $thisacctlid = $group_info[$groupid]['account_lid']; |
---|
| 150 | $thisfirstname = $group_info[$groupid]['account_firstname']; |
---|
| 151 | $thislastname = $group_info[$groupid]['account_lastname']; |
---|
| 152 | $thismembers = $group_info[$groupid]['members']; |
---|
| 153 | |
---|
| 154 | // Do some checks before we try to import the data to LDAP. |
---|
| 155 | if(!empty($thisacctid) && !empty($thisacctlid)) |
---|
| 156 | { |
---|
| 157 | $groups = CreateObject('phpgwapi.accounts',(int)$thisacctid); |
---|
| 158 | copyobj($GLOBALS['phpgw_setup']->db,$groups->db); |
---|
| 159 | |
---|
| 160 | // Check if the account is already there. |
---|
| 161 | // If so, we won't try to create it again. |
---|
| 162 | $acct_exist = $acct->name2id($thisacctlid); |
---|
| 163 | if($acct_exist) |
---|
| 164 | { |
---|
| 165 | $thisacctid = $acct_exist; |
---|
| 166 | } |
---|
| 167 | $id_exist = $groups->exists((int)$thisacctid); |
---|
| 168 | |
---|
| 169 | echo '<br>accountid: ' . $thisacctid; |
---|
| 170 | echo '<br>accountlid: ' . $thisacctlid; |
---|
| 171 | echo '<br>exists: ' . $id_exist; |
---|
| 172 | |
---|
| 173 | /* If not, create it now. */ |
---|
| 174 | if(!$id_exist) |
---|
| 175 | { |
---|
| 176 | $thisaccount_info = array( |
---|
| 177 | 'account_type' => 'g', |
---|
| 178 | 'account_id' => $thisacctid, |
---|
| 179 | 'account_lid' => $thisacctlid, |
---|
| 180 | 'account_passwd' => 'x', |
---|
| 181 | 'account_firstname' => $thisfirstname, |
---|
| 182 | 'account_lastname' => $thislastname, |
---|
| 183 | 'account_status' => 'A', |
---|
| 184 | 'account_expires' => -1 |
---|
| 185 | ); |
---|
| 186 | $groups->create($thisaccount_info); |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | if($users) |
---|
| 193 | { |
---|
| 194 | while(list($key,$accountid) = each($users)) |
---|
| 195 | { |
---|
| 196 | $id_exist = 0; $acct_exist = 0; |
---|
| 197 | $thisacctid = $account_info[$accountid]['account_id']; |
---|
| 198 | $thisacctlid = $account_info[$accountid]['account_lid']; |
---|
| 199 | $thisfirstname = $account_info[$accountid]['account_firstname']; |
---|
| 200 | $thislastname = $account_info[$accountid]['account_lastname']; |
---|
| 201 | |
---|
| 202 | // Do some checks before we try to import the data. |
---|
| 203 | if(!empty($thisacctid) && !empty($thisacctlid)) |
---|
| 204 | { |
---|
| 205 | $accounts = CreateObject('phpgwapi.accounts',(int)$thisacctid); |
---|
| 206 | copyobj($GLOBALS['phpgw_setup']->db,$accounts->db); |
---|
| 207 | |
---|
| 208 | // Check if the account is already there. |
---|
| 209 | // If so, we won't try to create it again. |
---|
| 210 | $acct_exist = $acct->name2id($thisacctlid); |
---|
| 211 | if($acct_exist) |
---|
| 212 | { |
---|
| 213 | $thisacctid = $acct_exist; |
---|
| 214 | } |
---|
| 215 | $id_exist = $accounts->exists((int)$thisacctid); |
---|
| 216 | // If not, create it now. |
---|
| 217 | if(!$id_exist) |
---|
| 218 | { |
---|
| 219 | echo '<br>Adding' . $thisacctid; |
---|
| 220 | $thisaccount_info = array( |
---|
| 221 | 'account_type' => 'u', |
---|
| 222 | 'account_id' => $thisacctid, |
---|
| 223 | 'account_lid' => $thisacctlid, |
---|
| 224 | 'account_passwd' => 'x', |
---|
| 225 | 'account_firstname' => $thisfirstname, |
---|
| 226 | 'account_lastname' => $thislastname, |
---|
| 227 | 'account_status' => 'A', |
---|
| 228 | 'account_expires' => -1, |
---|
| 229 | 'homedirectory' => $config['ldap_account_home'] . '/' . $thisacctlid, |
---|
| 230 | 'loginshell' => $config['ldap_account_shell'] |
---|
| 231 | ); |
---|
| 232 | $accounts->create($thisaccount_info); |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | $setup_complete = True; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | $GLOBALS['phpgw_setup']->html->show_header(lang('LDAP Export'),False,'config',$GLOBALS['phpgw_setup']->ConfigDomain . '(' . $phpgw_domain[$GLOBALS['phpgw_setup']->ConfigDomain]['db_type'] . ')'); |
---|
| 241 | |
---|
| 242 | if($error) |
---|
| 243 | { |
---|
| 244 | //echo '<br><center><b>Error:</b> '.$error.'</center>'; |
---|
| 245 | $GLOBALS['phpgw_setup']->html->show_alert_msg('Error',$error); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | if($setup_complete) |
---|
| 249 | { |
---|
| 250 | echo '<br><center>'.lang('Export has been completed! You will need to set the user passwords manually.').'</center>'; |
---|
| 251 | echo '<br><center>'.lang('Click <a href="index.php">here</a> to return to setup.').'</center>'; |
---|
| 252 | $GLOBALS['phpgw_setup']->html->show_footer(); |
---|
| 253 | exit; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | $setup_tpl->set_block('ldap','header','header'); |
---|
| 257 | $setup_tpl->set_block('ldap','user_list','user_list'); |
---|
| 258 | $setup_tpl->set_block('ldap','admin_list','admin_list'); |
---|
| 259 | $setup_tpl->set_block('ldap','group_list','group_list'); |
---|
| 260 | $setup_tpl->set_block('ldap','app_list','app_list'); |
---|
| 261 | $setup_tpl->set_block('ldap','submit','submit'); |
---|
| 262 | $setup_tpl->set_block('ldap','footer','footer'); |
---|
| 263 | |
---|
| 264 | while(list($key,$account) = @each($account_info)) |
---|
| 265 | { |
---|
| 266 | $user_list .= '<option value="' . $account['account_id'] . '">' |
---|
| 267 | . $common->display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname']) |
---|
| 268 | . '</option>'; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | @reset($account_info); |
---|
| 272 | while(list($key,$account) = @each($account_info)) |
---|
| 273 | { |
---|
| 274 | $admin_list .= '<option value="' . $account['account_id'] . '">' |
---|
| 275 | . $common->display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname']) |
---|
| 276 | . '</option>'; |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | while(list($key,$group) = @each($group_info)) |
---|
| 280 | { |
---|
| 281 | $group_list .= '<option value="' . $group['account_id'] . '">' |
---|
| 282 | . $group['account_lid'] |
---|
| 283 | . '</option>'; |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | $setup_tpl->set_var('action_url','ldapexport.php'); |
---|
| 287 | $setup_tpl->set_var('users',$user_list); |
---|
| 288 | $setup_tpl->set_var('admins',$admin_list); |
---|
| 289 | $setup_tpl->set_var('ldapgroups',$group_list); |
---|
| 290 | $setup_tpl->set_var('s_apps',$app_list); |
---|
| 291 | |
---|
| 292 | $setup_tpl->set_var('ldap_import',lang('LDAP export users')); |
---|
| 293 | $setup_tpl->set_var('description',lang("This section will help you export users and groups from eGroupWare's account tables into your LDAP tree").'.'); |
---|
| 294 | $setup_tpl->set_var('select_users',lang('Select which user(s) will be exported')); |
---|
| 295 | $setup_tpl->set_var('select_groups',lang('Select which group(s) will be exported (group membership will be maintained)')); |
---|
| 296 | $setup_tpl->set_var('form_submit','export'); |
---|
| 297 | $setup_tpl->set_var('cancel',lang('Cancel')); |
---|
| 298 | |
---|
| 299 | $setup_tpl->pfp('out','header'); |
---|
| 300 | if($account_info) |
---|
| 301 | { |
---|
| 302 | $setup_tpl->pfp('out','user_list'); |
---|
| 303 | } |
---|
| 304 | if($group_info) |
---|
| 305 | { |
---|
| 306 | $setup_tpl->pfp('out','group_list'); |
---|
| 307 | } |
---|
| 308 | $setup_tpl->pfp('out','submit'); |
---|
| 309 | $setup_tpl->pfp('out','footer'); |
---|
| 310 | |
---|
| 311 | $GLOBALS['phpgw_setup']->html->show_footer(); |
---|
| 312 | ?> |
---|