array( 'noheader' => True, 'nonavbar' => True, 'currentapp' => 'home', 'noapi' => True )); include('./inc/functions.inc.php'); // Authorize the user to use setup app and load the database if (!$GLOBALS['egw_setup']->auth('Config')) { Header('Location: index.php'); exit; } // Does not return unless user is authorized class egw { var $common; var $accounts; var $applications; var $db; } $egw =& new egw; $egw->common =& CreateObject('phpgwapi.common'); $common =& $egw->common; $GLOBALS['egw_setup']->loaddb(); $egw->db = clone($GLOBALS['egw_setup']->db); $tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup'); $setup_tpl = CreateObject('setup.Template',$tpl_root); $setup_tpl->set_file(array( 'ldap' => 'ldap.tpl', 'T_head' => 'head.tpl', 'T_footer' => 'footer.tpl', 'T_alert_msg' => 'msg_alert_msg.tpl' )); $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'config_name,config_value',array( "config_name LIKE 'ldap%'", ),__LINE__,__FILE__); while ($GLOBALS['egw_setup']->db->next_record()) { $GLOBALS['egw_info']['server'][$GLOBALS['egw_setup']->db->f('config_name')] = $GLOBALS['egw_setup']->db->f('config_value'); } $GLOBALS['egw_info']['server']['account_repository'] = 'ldap'; $egw->accounts =& CreateObject('phpgwapi.accounts'); $acct =& $egw->accounts; // First, see if we can connect to the LDAP server, if not send `em back to config.php with an // error message. // connect to ldap server if(!$ldap = $common->ldapConnect()) { $noldapconnection = True; } if($noldapconnection) { Header('Location: config.php?error=badldapconnection'); exit; } // read all accounts & groups direct from SQL for export $group_info = $account_info = array(); $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->accounts_table,'*',false,__LINE__,__FILE__); while(($row = $GLOBALS['egw_setup']->db->row(true))) { if ($row['account_type'] == 'u') // account { $account_info[$row['account_id']] = $row; } else // group { $row['account_id'] *= -1; // group account_id is internally negative since 1.2 $group_info[(string)$row['account_id']] = $row; } } if($_POST['cancel']) { Header('Location: ldap.php'); exit; } $GLOBALS['egw_setup']->html->show_header(lang('LDAP Export'),False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')'); if($_POST['submit']) { if($_POST['users']) { foreach($_POST['users'] as $accountid) { if (!isset($account_info[$accountid])) continue; $accounts =& CreateObject('phpgwapi.accounts',(int)$accountid); // check if user already exists in ldap if ($accounts->exists($accountid)) { echo '
'.lang('%1 already exists in LDAP.',lang('User')." $accountid ({$account_info[$accountid]['account_lid']})")."
\n"; continue; } $account_info[$accountid]['homedirectory'] = $GLOBALS['egw_info']['server']['ldap_account_home'] . '/' . $account_info[$accountid]['account_lid']; $account_info[$accountid]['loginshell'] = $GLOBALS['egw_info']['server']['ldap_account_shell']; if (!$accounts->create($account_info[$accountid])) { echo ''.lang('Creation of %1 in LDAP failed !!!',lang('User')." $accountid ({$account_info[$accountid]['account_lid']})")."
\n"; continue; } echo ''.lang('%1 created in LDAP.',lang('User')." $accountid ({$account_info[$accountid]['account_lid']})")."
\n"; } } if($_POST['ldapgroups']) { foreach($_POST['ldapgroups'] as $groupid) { if (!isset($group_info[$groupid])) continue; $groups =& CreateObject('phpgwapi.accounts',(int)$groupid); // check if group already exists in ldap if (!$groups->exists($groupid)) { if (!$groups->create($group_info[$groupid])) { echo ''.lang('Creation of %1 failed !!!',lang('Group')." $groupid ({$group_info[$groupid]['account_lid']})")."
\n"; continue; } echo ''.lang('%1 created in LDAP.',lang('Group')." $groupid ({$group_info[$groupid]['account_lid']})")."
\n"; } else { echo ''.lang('%1 already exists in LDAP.',lang('Group')." $groupid ({$group_info[$groupid]['account_lid']})")."
\n"; if ($groups->id2name($groupid) != $group_info[$groupid]['account_lid']) { continue; // different group under that gidnumber in ldap! } } // now saving / updating the memberships $groups->read_repository(); if (!is_object($GLOBALS['egw']->acl)) { $GLOBALS['egw']->acl =& CreateObject('phpgwapi.acl'); } $groups->save_repository(); } } $setup_complete = True; } if($error) { //echo '