2000-11-17 16:05:15 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - Setup *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2001-03-10 13:26:54 +01:00
|
|
|
$phpgw_info["flags"] = array(
|
2001-03-10 21:13:52 +01:00
|
|
|
'noheader' => True,
|
|
|
|
'nonavbar' => True,
|
|
|
|
'currentapp' => 'home',
|
|
|
|
'noapi' => True
|
2001-03-10 13:26:54 +01:00
|
|
|
);
|
|
|
|
|
2001-03-10 21:13:52 +01:00
|
|
|
include('../header.inc.php');
|
|
|
|
include('./inc/functions.inc.php');
|
2001-03-10 13:26:54 +01:00
|
|
|
|
|
|
|
// Authorize the user to use setup app and load the database
|
2001-03-10 21:13:52 +01:00
|
|
|
if (!$phpgw_setup->auth('Config')){
|
|
|
|
Header('Location: index.php');
|
2001-03-10 13:26:54 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
// Does not return unless user is authorized
|
2001-03-10 15:58:00 +01:00
|
|
|
class phpgw {
|
|
|
|
var $common;
|
2001-03-24 03:13:40 +01:00
|
|
|
var $accounts;
|
|
|
|
var $applications;
|
2001-03-24 03:32:21 +01:00
|
|
|
var $db;
|
2001-03-10 15:58:00 +01:00
|
|
|
}
|
|
|
|
$phpgw = new phpgw;
|
2001-03-10 21:13:52 +01:00
|
|
|
$phpgw->common = CreateObject('phpgwapi.common');
|
2001-03-10 15:58:00 +01:00
|
|
|
|
2001-03-24 03:13:40 +01:00
|
|
|
$common = $phpgw->common;
|
2001-03-10 13:26:54 +01:00
|
|
|
$phpgw_setup->loaddb();
|
2001-03-24 03:32:21 +01:00
|
|
|
$phpgw->db = $phpgw_setup->db;
|
2001-03-10 13:26:54 +01:00
|
|
|
|
2001-03-10 21:13:52 +01:00
|
|
|
$phpgw_info['server']['auth_type'] = 'ldap';
|
2001-03-24 03:13:40 +01:00
|
|
|
$phpgw->accounts = CreateObject('phpgwapi.accounts');
|
|
|
|
$acct = $phpgw->accounts;
|
|
|
|
$phpgw->applications = CreateObject('phpgwapi.applications');
|
|
|
|
$applications = $phpgw->applications;
|
2001-03-10 13:26:54 +01:00
|
|
|
|
|
|
|
$phpgw_setup->db->query("select config_name,config_value from phpgw_config where config_name like 'ldap%'",__LINE__,__FILE__);
|
|
|
|
while ($phpgw_setup->db->next_record()) {
|
2001-03-10 21:13:52 +01:00
|
|
|
$config[$phpgw_setup->db->f('config_name')] = $phpgw_setup->db->f('config_value');
|
2001-03-10 13:26:54 +01:00
|
|
|
}
|
2001-03-10 21:13:52 +01:00
|
|
|
$phpgw_info['server']['ldap_host'] = $config['ldap_host'];
|
|
|
|
$phpgw_info['server']['ldap_context'] = $config['ldap_context'];
|
|
|
|
$phpgw_info['server']['ldap_root_dn'] = $config['ldap_root_dn'];
|
|
|
|
$phpgw_info['server']['ldap_root_pw'] = $config['ldap_root_pw'];
|
2001-03-10 13:26:54 +01:00
|
|
|
|
|
|
|
// 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
|
2001-03-10 15:58:00 +01:00
|
|
|
if (! $ldap = $common->ldapConnect()) {
|
2001-03-10 13:26:54 +01:00
|
|
|
$noldapconnection = True;
|
|
|
|
}
|
2000-11-17 16:05:15 +01:00
|
|
|
|
2001-03-10 13:26:54 +01:00
|
|
|
if ($noldapconnection) {
|
2001-03-10 21:13:52 +01:00
|
|
|
Header('Location: config.php?error=badldapconnection');
|
2001-03-10 13:26:54 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2001-03-10 21:13:52 +01:00
|
|
|
$sr = ldap_search($ldap,$config['ldap_context'],'(|(uid=*))',array('sn','givenname','uid','uidnumber'));
|
2001-03-10 13:26:54 +01:00
|
|
|
$info = ldap_get_entries($ldap, $sr);
|
2000-11-17 16:05:15 +01:00
|
|
|
|
2001-03-10 21:13:52 +01:00
|
|
|
for ($i=0; $i<$info['count']; $i++) {
|
|
|
|
if (! $phpgw_info['server']['global_denied_users'][$info[$i]['uid'][0]]) {
|
|
|
|
$account_info[$i]['account_id'] = $info[$i]['uidnumber'][0];
|
|
|
|
$account_info[$i]['account_lid'] = $info[$i]['uid'][0];
|
|
|
|
$account_info[$i]['account_firstname'] = $info[$i]['givenname'][0];
|
|
|
|
$account_info[$i]['account_lastname'] = $info[$i]['sn'][0];
|
2001-03-06 13:58:54 +01:00
|
|
|
}
|
2001-03-10 13:26:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$phpgw_setup->db->query("select app_name,app_title from phpgw_applications where app_enabled != '0' and "
|
|
|
|
. "app_name != 'administration'",__LINE__,__FILE__);
|
|
|
|
while ($phpgw_setup->db->next_record()) {
|
2001-03-10 21:13:52 +01:00
|
|
|
$apps[$phpgw_setup->db->f('app_name')] = $phpgw_setup->db->f('app_title');
|
2001-03-10 13:26:54 +01:00
|
|
|
}
|
2001-03-06 13:58:54 +01:00
|
|
|
|
2001-03-10 13:26:54 +01:00
|
|
|
if ($submit) {
|
|
|
|
if (! count($admins)) {
|
2001-03-10 21:13:52 +01:00
|
|
|
$error = '<br>You must select at least 1 admin';
|
2001-03-10 13:26:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! count($s_apps)) {
|
2001-03-10 21:13:52 +01:00
|
|
|
$error .= '<br>You must select at least 1 application';
|
2001-03-10 13:26:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $error) {
|
|
|
|
// Create the 'Default' group
|
2001-03-14 19:55:36 +01:00
|
|
|
mt_srand((double)microtime()*1000000);
|
2001-04-05 21:43:38 +02:00
|
|
|
$defaultgroupid = mt_rand (100, 65535);
|
2001-03-10 13:26:54 +01:00
|
|
|
|
|
|
|
$acct = CreateObject('phpgwapi.accounts',$defaultgroupid);
|
|
|
|
$acct->db = $phpgw_setup->db;
|
|
|
|
|
2001-03-14 17:49:39 +01:00
|
|
|
// Check if the group account is already there.
|
|
|
|
// If so, set our group_id to that account's id for use below.
|
2001-03-14 17:19:45 +01:00
|
|
|
$acct_exist = $acct->name2id('Default');
|
2001-05-09 13:37:26 +02:00
|
|
|
if ($acct_exist)
|
|
|
|
{
|
2001-03-14 17:19:45 +01:00
|
|
|
$defaultgroupid = $acct_exist;
|
|
|
|
}
|
|
|
|
$id_exist = $acct->exists(intval($defaultgroupid));
|
2001-03-14 17:49:39 +01:00
|
|
|
// if not, create it, using our original groupid.
|
2001-05-09 13:37:26 +02:00
|
|
|
$thisgroup_info = array(
|
2001-05-10 11:34:47 +02:00
|
|
|
'account_type' => 'g',
|
|
|
|
'account_id' => $defaultgroupid,
|
|
|
|
'account_lid' => 'Default',
|
|
|
|
'account_passwd' => $passwd,
|
|
|
|
'account_firstname' => 'Default',
|
|
|
|
'account_lastname' => 'Group',
|
|
|
|
'account_status' => 'A',
|
|
|
|
'account_expires' => -1
|
2001-05-09 13:37:26 +02:00
|
|
|
);
|
|
|
|
if(!$id_exist)
|
|
|
|
{
|
|
|
|
$acct->create($thisgroup_info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-14 19:55:36 +01:00
|
|
|
// Delete first, so ldap does not return an error, then recreate
|
2001-03-14 17:49:39 +01:00
|
|
|
$acct->delete($defaultgroupid);
|
2001-05-09 13:37:26 +02:00
|
|
|
$acct->create($thisgroup_info);
|
2001-03-10 13:26:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$acl = CreateObject('phpgwapi.acl',$defaultgroupid);
|
|
|
|
$acl->db = $phpgw_setup->db;
|
|
|
|
$acl->read_repository();
|
2001-05-09 13:37:26 +02:00
|
|
|
while ($app = each($s_apps))
|
|
|
|
{
|
2001-03-14 18:13:43 +01:00
|
|
|
$acl->delete($app[1],'run',1);
|
2001-03-10 13:26:54 +01:00
|
|
|
$acl->add($app[1],'run',1);
|
|
|
|
}
|
|
|
|
$acl->save_repository();
|
|
|
|
|
2001-04-05 21:43:38 +02:00
|
|
|
while ($account = each($account_info))
|
|
|
|
{
|
2001-03-14 17:19:45 +01:00
|
|
|
$id_exist = 0;
|
2001-04-05 21:43:38 +02:00
|
|
|
$thisacctid = $account[1]['account_id'];
|
|
|
|
$thisacctlid = $account[1]['account_lid'];
|
|
|
|
$thisfirstname = $account[1]['account_firstname'];
|
|
|
|
$thislastname = $account[1]['account_lastname'];
|
|
|
|
|
2001-03-14 17:49:39 +01:00
|
|
|
// Do some checks before we try to import the data.
|
2001-04-05 21:43:38 +02:00
|
|
|
if (!empty($thisacctid) && !empty($thisacctlid))
|
|
|
|
{
|
|
|
|
$accounts = CreateObject('phpgwapi.accounts',intval($thisacctid));
|
2001-03-10 13:26:54 +01:00
|
|
|
$accounts->db = $phpgw_setup->db;
|
|
|
|
|
2001-03-14 17:49:39 +01:00
|
|
|
// Check if the account is already there.
|
|
|
|
// If so, we won't try to create it again.
|
2001-04-05 22:00:34 +02:00
|
|
|
$acct_exist = $acct->name2id($thisacctlid);
|
2001-04-05 21:43:38 +02:00
|
|
|
if ($acct_exist)
|
|
|
|
{
|
|
|
|
$thisacctid = $acct_exist;
|
2001-03-14 17:19:45 +01:00
|
|
|
}
|
2001-04-05 21:43:38 +02:00
|
|
|
$id_exist = $accounts->exists(intval($thisacctid));
|
2001-03-14 17:49:39 +01:00
|
|
|
// If not, create it now.
|
2001-04-05 21:43:38 +02:00
|
|
|
if(!$id_exist)
|
|
|
|
{
|
2001-05-09 13:37:26 +02:00
|
|
|
$thisaccount_info = array(
|
2001-05-10 11:34:47 +02:00
|
|
|
'account_type' => 'u',
|
|
|
|
'account_lid' => $thisacctlid,
|
|
|
|
'account_passwd' => 'x',
|
|
|
|
'account_firstname' => $thisfirstname,
|
|
|
|
'account_lastname' => $thislastname,
|
|
|
|
'account_status' => 'A',
|
|
|
|
'account_expires' => -1
|
2001-05-09 13:37:26 +02:00
|
|
|
);
|
|
|
|
$accounts->create($thisaccount_info);
|
2001-03-06 13:58:54 +01:00
|
|
|
}
|
|
|
|
|
2001-03-14 17:49:39 +01:00
|
|
|
// Insert default acls for this user.
|
|
|
|
// Since the group has app rights, we don't need to give users
|
|
|
|
// these rights. Instead, we make the user a member of the Default group
|
|
|
|
// below.
|
2001-04-05 21:43:38 +02:00
|
|
|
$acl = CreateObject('phpgwapi.acl',intval($thisacctid));
|
2001-03-14 17:49:39 +01:00
|
|
|
$acl->db = $phpgw_setup->db;
|
|
|
|
$acl->read_repository();
|
|
|
|
|
|
|
|
// Only give them admin if we asked for them to have it.
|
|
|
|
// This is typically an exception to apps for run rights
|
|
|
|
// as a group member.
|
2001-04-05 21:43:38 +02:00
|
|
|
for ($a=0;$a<count($admins);$a++)
|
|
|
|
{
|
|
|
|
if ($admins[$a] == $thisacctid)
|
|
|
|
{
|
2001-03-14 18:13:43 +01:00
|
|
|
$acl->delete('admin','run',1);
|
2001-03-14 17:49:39 +01:00
|
|
|
$acl->add('admin','run',1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now make them a member of the 'Default' group.
|
|
|
|
// But, only if the current user is not the group itself.
|
2001-04-05 21:43:38 +02:00
|
|
|
if ($defaultgroupid != $thisacctid)
|
|
|
|
{
|
2001-03-14 17:49:39 +01:00
|
|
|
$acl->delete('phpgw_group',$defaultgroupid,1);
|
|
|
|
$acl->add('phpgw_group',$defaultgroupid,1);
|
|
|
|
}
|
|
|
|
|
2001-04-17 18:32:14 +02:00
|
|
|
// Now add the acl to let them change their password
|
|
|
|
$acl->delete('preferences','changepassword',$thisacctid,1);
|
|
|
|
$acl->add('preferences','changepassword',$thisacctid,1);
|
|
|
|
|
2001-03-14 17:49:39 +01:00
|
|
|
// Save these new acls.
|
2001-03-10 13:26:54 +01:00
|
|
|
$acl->save_repository();
|
2001-03-06 13:58:54 +01:00
|
|
|
}
|
2001-03-10 13:26:54 +01:00
|
|
|
$setup_complete = True;
|
2001-03-01 17:10:16 +01:00
|
|
|
}
|
2001-03-06 13:58:54 +01:00
|
|
|
}
|
2001-04-05 21:43:38 +02:00
|
|
|
}
|
2001-01-30 04:57:09 +01:00
|
|
|
|
2001-04-05 21:43:38 +02:00
|
|
|
// Add a check to see if there are no users in LDAP, if not create a default user.
|
2000-11-17 16:05:15 +01:00
|
|
|
|
2001-03-10 13:26:54 +01:00
|
|
|
$phpgw_setup->show_header();
|
2000-11-17 16:05:15 +01:00
|
|
|
|
2001-03-10 13:26:54 +01:00
|
|
|
if ($error) {
|
2001-03-10 21:13:52 +01:00
|
|
|
echo '<br><center><b>Error:</b> '.$error.'</center>';
|
2001-03-10 13:26:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($setup_complete) {
|
|
|
|
$phpgw_setup->db->query("select config_value from phpgw_config where config_name='webserver_url'",__LINE__,__FILE__);
|
|
|
|
$phpgw_setup->db->next_record();
|
|
|
|
echo '<br><center>Setup has been completed! Click <a href="' . $phpgw_setup->db->f("config_value")
|
|
|
|
. '/login.php">here</a> to login</center>';
|
|
|
|
exit;
|
|
|
|
}
|
2000-11-17 16:05:15 +01:00
|
|
|
?>
|
|
|
|
|
|
|
|
<form action="ldap.php" method="POST">
|
|
|
|
<table border="0" align="center" width="70%">
|
|
|
|
<tr bgcolor="486591">
|
|
|
|
<td colspan="2"> <font color="fefefe">LDAP import users</font></td>
|
|
|
|
</tr>
|
|
|
|
<tr bgcolor="e6e6e6">
|
|
|
|
<td colspan="2"> This section will help you import users from your LDAP tree into phpGroupWare's account tables.<br> </td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr bgcolor="e6e6e6">
|
|
|
|
<td align="left" valign="top">
|
|
|
|
Select which user(s) will have the admin privileges
|
|
|
|
</td>
|
|
|
|
<td align="center">
|
|
|
|
<select name="admins[]" multiple size="5">
|
|
|
|
<?php
|
|
|
|
while ($account = each($account_info)) {
|
2001-03-10 21:13:52 +01:00
|
|
|
echo '<option value="' . $account[1]['account_id'] . '">'
|
|
|
|
. $common->display_fullname($account[1]['account_lid'],$account[1]['account_firstname'],$account[1]['account_lastname'])
|
2000-11-17 16:05:15 +01:00
|
|
|
. '</option>';
|
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</select>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr bgcolor="e6e6e6">
|
|
|
|
<td align="left" valign="top">
|
|
|
|
Select the default applications your users will have access to.
|
|
|
|
<br> Note: You will be able to customize this later.
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<select name="s_apps[]" multiple size="5">
|
|
|
|
<?php
|
|
|
|
while ($app = each($apps)) {
|
2001-01-30 05:06:42 +01:00
|
|
|
echo '<option value="' . $app[0] . '" selected>' . $app[1] . '</option>';
|
2000-11-17 16:05:15 +01:00
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</select>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<tr bgcolor="e6e6e6">
|
|
|
|
<td colspan="2" align="center">
|
|
|
|
<input type="submit" name="submit" value="import">
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
</table>
|
|
|
|
</form>
|