2001-03-29 10:10:04 +02:00
|
|
|
<?php
|
2005-11-02 12:45:52 +01:00
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare API - Accounts manager for the contacts class *
|
|
|
|
* This file written by Miles Lott <milosch@groupwhere.org> *
|
|
|
|
* View and manipulate account records using the contacts class *
|
|
|
|
* Copyright (C) 2000, 2001 Miles Lott *
|
|
|
|
* -------------------------------------------------------------------------*
|
|
|
|
* This library is part of the eGroupWare API *
|
|
|
|
* http://www.egroupware.org/api *
|
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
/*
|
|
|
|
THIS NEEDS WORK!!!!!!!!! - Milosch
|
2003-08-28 16:31:11 +02:00
|
|
|
But it is a lot closer now...
|
2001-06-27 01:16:18 +02:00
|
|
|
*/
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw_info']['server']['global_denied_users'] = array(
|
2003-08-28 16:31:11 +02:00
|
|
|
'root' => True, 'bin' => True, 'daemon' => True,
|
|
|
|
'adm' => True, 'lp' => True, 'sync' => True,
|
|
|
|
'shutdown' => True, 'halt' => True, 'ldap' => True,
|
|
|
|
'mail' => True, 'news' => True, 'uucp' => True,
|
|
|
|
'operator' => True, 'games' => True, 'gopher' => True,
|
|
|
|
'nobody' => True, 'xfs' => True, 'pgsql' => True,
|
|
|
|
'mysql' => True, 'postgres' => True, 'oracle' => True,
|
|
|
|
'ftp' => True, 'gdm' => True, 'named' => True,
|
|
|
|
'alias' => True, 'web' => True, 'sweep' => True,
|
|
|
|
'cvs' => True, 'qmaild' => True, 'qmaill' => True,
|
|
|
|
'qmaillog' => True, 'qmailp' => True, 'qmailq' => True,
|
|
|
|
'qmailr' => True, 'qmails' => True, 'rpc' => True,
|
|
|
|
'rpcuser' => True, 'amanda' => True, 'apache' => True,
|
|
|
|
'pvm' => True, 'squid' => True, 'ident' => True,
|
|
|
|
'nscd' => True, 'mailnull' => True, 'cyrus' => True,
|
2001-06-27 01:54:34 +02:00
|
|
|
'backup' => True
|
|
|
|
);
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw_info']['server']['global_denied_groups'] = array(
|
2003-08-28 16:31:11 +02:00
|
|
|
'root' => True, 'bin' => True, 'daemon' => True,
|
|
|
|
'sys' => True, 'adm' => True, 'tty' => True,
|
|
|
|
'disk' => True, 'lp' => True, 'mem' => True,
|
|
|
|
'kmem' => True, 'wheel' => True, 'mail' => True,
|
|
|
|
'uucp' => True, 'man' => True, 'games' => True,
|
|
|
|
'dip' => True, 'ftp' => True, 'nobody' => True,
|
|
|
|
'floppy' => True, 'xfs' => True, 'console' => True,
|
|
|
|
'utmp' => True, 'pppusers' => True, 'popusers' => True,
|
|
|
|
'slipusers' => True, 'slocate' => True, 'mysql' => True,
|
|
|
|
'dnstools' => True, 'web' => True, 'named' => True,
|
|
|
|
'dba' => True, 'oinstall' => True, 'oracle' => True,
|
|
|
|
'gdm' => True, 'sweep' => True, 'cvs' => True,
|
|
|
|
'postgres' => True, 'qmail' => True, 'nofiles' => True,
|
|
|
|
'ldap' => True, 'backup' => True
|
2001-06-27 01:54:34 +02:00
|
|
|
);
|
2001-03-29 10:10:04 +02:00
|
|
|
|
|
|
|
class accounts_
|
|
|
|
{
|
|
|
|
var $db;
|
|
|
|
var $contacts;
|
|
|
|
var $account_id;
|
|
|
|
var $data;
|
2001-06-27 01:16:18 +02:00
|
|
|
var $debug = False;
|
|
|
|
var $qcols = array(
|
|
|
|
'fn' => 'fn',
|
|
|
|
'n_given' => 'n_given',
|
|
|
|
'n_family' => 'n_family',
|
|
|
|
'account_lastlogin' => 'account_lastlogin',
|
|
|
|
'account_lastloginfrom' => 'account_lastloginfrom',
|
|
|
|
'account_lastpwd_change' => 'account_lastpwd_change',
|
|
|
|
'account_status' => 'account_status',
|
|
|
|
'account_expires' => 'account_expires'
|
|
|
|
);
|
2001-03-29 10:10:04 +02:00
|
|
|
|
|
|
|
function accounts_()
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$this->db = $GLOBALS['egw']->db;
|
|
|
|
$this->contacts =& CreateObject('phpgwapi.contacts',0);
|
2001-03-29 10:10:04 +02:00
|
|
|
}
|
|
|
|
|
2001-05-01 11:18:20 +02:00
|
|
|
function makeobj()
|
2001-03-29 10:10:04 +02:00
|
|
|
{
|
2001-05-01 11:18:20 +02:00
|
|
|
if(!$this->contacts)
|
|
|
|
{
|
2005-03-24 14:15:12 +01:00
|
|
|
$this->contacts =& CreateObject('phpgwapi.contacts','0');
|
2001-05-01 11:18:20 +02:00
|
|
|
}
|
|
|
|
}
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2001-05-01 11:18:20 +02:00
|
|
|
function read_repository()
|
|
|
|
{
|
2001-06-27 01:16:18 +02:00
|
|
|
$this->makeobj();
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
$allValues = $this->contacts->read_single_entry($this->account_id,$this->qcols);
|
2001-03-29 10:10:04 +02:00
|
|
|
|
|
|
|
/* Now dump it into the array */
|
2001-06-27 01:16:18 +02:00
|
|
|
$this->data['userid'] = $allValues[0]['lid'];
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->data['account_id'] = $allValues[0]['id'];
|
|
|
|
$this->data['account_lid'] = $allValues[0]['lid'];
|
2001-06-15 23:35:07 +02:00
|
|
|
$this->data['account_type'] = $allValues[0]['tid'];
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->data['firstname'] = $allValues[0]['n_given'];
|
|
|
|
$this->data['lastname'] = $allValues[0]['n_family'];
|
|
|
|
$this->data['fullname'] = $allValues[0]['fn'];
|
2001-06-15 23:35:07 +02:00
|
|
|
$this->data['lastlogin'] = $allValues[0]['account_lastlogin'];
|
|
|
|
$this->data['lastloginfrom'] = $allValues[0]['account_lastloginfrom'];
|
|
|
|
$this->data['lastpasswd_change'] = $allValues[0]['account_lastpwd_change'];
|
|
|
|
$this->data['status'] = $allValues[0]['account_status'];
|
2001-06-27 01:16:18 +02:00
|
|
|
$this->data['expires'] = $allValues[0]['account_expires'];
|
2001-03-29 10:10:04 +02:00
|
|
|
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_repository()
|
|
|
|
{
|
2001-06-27 01:16:18 +02:00
|
|
|
$this->makeobj();
|
|
|
|
|
2001-06-15 23:35:07 +02:00
|
|
|
$entry['id'] = $this->data['account_id'];
|
|
|
|
$entry['lid'] = $this->data['account_lid'];
|
|
|
|
$entry['tid'] = $this->data['account_type'];
|
|
|
|
$entry['fn'] = sprintf("%s %s", $this->data['firstname'], $this->data['lastname']);
|
|
|
|
$entry['n_family'] = $this->data['lastname'];
|
|
|
|
$entry['n_given'] = $this->data['firstname'];
|
|
|
|
$entry['account_lastlogin'] = $this->data['lastlogin'];
|
|
|
|
$entry['account_lastloginfrom'] = $this->data['lastloginfrom'];
|
|
|
|
$entry['account_lastpasswd_change'] = $this->data['lastpwd_change'];
|
|
|
|
$entry['account_status'] = $this->data['status'];
|
2001-06-27 01:16:18 +02:00
|
|
|
$entry['account_expires'] = $this->data['expires'];
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2001-06-27 02:44:20 +02:00
|
|
|
if($this->debug) { echo '<br>Updating entry:<br>' . var_dump($entry); }
|
|
|
|
$this->contacts->update($entry['id'],0,$entry,'public','',$entry['tid']);
|
2001-03-29 10:10:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function add($account_name, $account_type, $first_name, $last_name, $passwd = False)
|
|
|
|
{
|
|
|
|
$this->create($account_name, $account_type, $first_name, $last_name, $passwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete($accountid = '')
|
|
|
|
{
|
2001-06-27 02:44:20 +02:00
|
|
|
$this->makeobj();
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2001-06-27 02:44:20 +02:00
|
|
|
if($this->debug) { echo '<br>Deleting entry:<br>' . $account_id; }
|
2001-03-29 10:10:04 +02:00
|
|
|
$account_id = get_account_id($accountid);
|
2001-04-26 16:09:03 +02:00
|
|
|
$this->contacts->delete($account_id);
|
2001-03-29 10:10:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_list($_type='both')
|
|
|
|
{
|
2001-06-27 01:16:18 +02:00
|
|
|
$this->makeobj();
|
2001-03-29 10:10:04 +02:00
|
|
|
|
|
|
|
switch($_type)
|
|
|
|
{
|
|
|
|
case 'accounts':
|
2001-06-15 23:35:07 +02:00
|
|
|
$filter = 'tid=u';
|
2001-03-29 10:10:04 +02:00
|
|
|
break;
|
|
|
|
case 'groups':
|
2001-06-15 23:35:07 +02:00
|
|
|
$filter = 'tid=g';
|
2001-03-29 10:10:04 +02:00
|
|
|
break;
|
|
|
|
default:
|
2001-06-15 23:35:07 +02:00
|
|
|
$filter = 'tid=u,tid=g';
|
2001-03-29 10:10:04 +02:00
|
|
|
}
|
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
$allValues = $this->contacts->read(0,0,$this->qcols,'',$filter);
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
/* get user information for each user/group */
|
|
|
|
for($i=0;$i<count($allValues);$i++)
|
|
|
|
{
|
2001-03-29 10:10:04 +02:00
|
|
|
$accounts[] = Array(
|
2001-06-15 23:35:07 +02:00
|
|
|
'account_id' => $allValues[$i]['id'],
|
|
|
|
'account_lid' => $allValues[$i]['lid'],
|
|
|
|
'account_type' => $allValues[$i]['tid'],
|
|
|
|
'account_firstname' => $allValues[$i]['n_given'],
|
2001-06-27 01:16:18 +02:00
|
|
|
'account_lastname' => $allValues[$i]['n_family'],
|
|
|
|
'account_status' => $allValues[$i]['account_status'],
|
|
|
|
'account_expires' => $allValues[$i]['account_expires']
|
2001-03-29 10:10:04 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $accounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
function name2id($account_lid)
|
|
|
|
{
|
|
|
|
$qcols = array('id' => 'id');
|
2001-05-01 11:18:20 +02:00
|
|
|
$this->makeobj();
|
2001-04-26 16:06:23 +02:00
|
|
|
$allValues = $this->contacts->read(0,0,$qcols,'',"lid=".$account_lid);
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
if($allValues[0]['id'])
|
|
|
|
{
|
2003-12-14 18:24:19 +01:00
|
|
|
return (int)$allValues[0]['id'];
|
2001-06-27 01:16:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-29 10:10:04 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function id2name($account_id)
|
|
|
|
{
|
2001-05-01 11:18:20 +02:00
|
|
|
$this->makeobj();
|
2001-06-27 01:16:18 +02:00
|
|
|
|
2001-03-29 10:10:04 +02:00
|
|
|
$allValues = $this->contacts->read_single_entry($account_id);
|
2001-06-27 01:16:18 +02:00
|
|
|
if($this->debug) { echo '<br>id2name: '.$allValues[0]['lid']; }
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2001-06-15 23:35:07 +02:00
|
|
|
if($allValues[0]['lid'])
|
|
|
|
{
|
2001-06-27 01:16:18 +02:00
|
|
|
return $allValues[0]['lid'];
|
2001-06-15 23:35:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-29 10:10:04 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_type($accountid = '')
|
|
|
|
{
|
2001-05-01 11:18:20 +02:00
|
|
|
$this->makeobj();
|
|
|
|
$account_id = get_account_id($accountid);
|
2001-03-29 10:10:04 +02:00
|
|
|
|
|
|
|
$allValues = $this->contacts->read_single_entry($account_id);
|
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
if ($allValues[0]['tid'])
|
|
|
|
{
|
2001-03-29 10:10:04 +02:00
|
|
|
return $allValues[0]['tid'];
|
2001-05-01 11:18:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-29 10:10:04 +02:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function exists($account_lid)
|
|
|
|
{
|
2001-05-01 11:18:20 +02:00
|
|
|
$this->makeobj();
|
2003-12-14 18:24:19 +01:00
|
|
|
if(is_int($account_lid))
|
2001-03-29 10:10:04 +02:00
|
|
|
{
|
|
|
|
$account_id = $account_lid;
|
2001-04-26 16:06:23 +02:00
|
|
|
settype($account_lid,'string');
|
2001-03-29 10:10:04 +02:00
|
|
|
$account_lid = $this->id2name($account_id);
|
|
|
|
}
|
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
$allValues = $this->contacts->read(0,0,array('n_given' => 'n_given'),'','lid='.$account_lid);
|
|
|
|
|
2001-05-01 11:18:20 +02:00
|
|
|
if ($allValues[0]['id'])
|
2001-03-29 10:10:04 +02:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-05-01 11:18:20 +02:00
|
|
|
return False;
|
2001-03-29 10:10:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
function create($account_info)
|
2001-03-29 10:10:04 +02:00
|
|
|
{
|
2001-06-27 02:44:20 +02:00
|
|
|
$this->makeobj();
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2001-06-27 02:44:20 +02:00
|
|
|
if (!$$account_info['account_id'])
|
|
|
|
{
|
|
|
|
$account_info['account_id'] = $this->get_nextid();
|
|
|
|
}
|
2005-03-24 14:15:12 +01:00
|
|
|
$owner = $GLOBALS['egw_info']['user']['account_id'];
|
2001-06-27 01:16:18 +02:00
|
|
|
$entry['id'] = $account_info['account_id'];
|
|
|
|
$entry['lid'] = $account_info['account_lid'];
|
|
|
|
$entry['n_given'] = $account_info['account_firstname'];
|
|
|
|
$entry['n_family'] = $account_info['account_lastname'];
|
|
|
|
$entry['password'] = $account_info['account_passwd'];
|
|
|
|
$entry['account_status'] = $account_info['account_status'];
|
|
|
|
$entry['account_expires'] = $account_info['account_expires'];
|
2001-03-29 10:10:04 +02:00
|
|
|
|
2001-06-27 02:44:20 +02:00
|
|
|
if($this->debug) { echo '<br>Adding entry:<br>' . var_dump($entry); }
|
|
|
|
/* 'public' access, no category id, tid set to account_type */
|
|
|
|
$this->contacts->add(0,$entry,'public','',$account_info['account_type']);
|
2001-03-29 10:10:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
function auto_add($accountname, $passwd, $default_prefs = False, $default_acls = False, $expiredate = 0, $account_status = 'A')
|
2001-03-29 10:10:04 +02:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
if (! $expiredate)
|
2001-06-27 01:16:18 +02:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
// expire in 30 days by default
|
|
|
|
$expiredate = time() + ( ( 60 * 60 ) * (30 * 24) );
|
2001-06-27 01:16:18 +02:00
|
|
|
}
|
|
|
|
|
2005-11-02 12:45:52 +01:00
|
|
|
$default_group_id = $this->name2id($GLOBALS['egw_info']['server']['default_group_lid']);
|
|
|
|
if (!$default_group_id)
|
|
|
|
{
|
|
|
|
$default_group_id = (int) $this->name2id('Default');
|
|
|
|
}
|
|
|
|
$primary_group = $GLOBALS['auto_create_acct']['primary_group'] &&
|
|
|
|
$this->get_type((int)$GLOBALS['auto_create_acct']['primary_group']) == 'g' ?
|
|
|
|
(int) $GLOBALS['auto_create_acct']['primary_group'] : $default_group_id;
|
|
|
|
|
2001-06-27 01:16:18 +02:00
|
|
|
$acct_info = array(
|
|
|
|
'account_lid' => $accountname,
|
|
|
|
'account_type' => 'u',
|
|
|
|
'account_passwd' => $passwd,
|
2005-11-02 12:45:52 +01:00
|
|
|
'account_firstname' => $GLOBALS['auto_create_acct']['firstname'] ? $GLOBALS['auto_create_acct']['firstname'] : 'New',
|
|
|
|
'account_lastname' => $GLOBALS['auto_create_acct']['lastname'] ? $GLOBALS['auto_create_acct']['lastname'] : 'User',
|
2001-06-27 01:16:18 +02:00
|
|
|
'account_status' => $account_status,
|
2005-11-02 12:45:52 +01:00
|
|
|
'account_expires' => mktime(2,0,0,date('n',$expiredate), (int)date('d',$expiredate), date('Y',$expiredate)),
|
|
|
|
'account_primary_group' => $primary_group,
|
2001-06-27 01:16:18 +02:00
|
|
|
);
|
2005-11-02 12:45:52 +01:00
|
|
|
if (isset($GLOBALS['auto_create_acct']['email']) == True && $GLOBALS['auto_create_acct']['email'] != '')
|
2001-06-27 01:16:18 +02:00
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
$acct_info['account_email'] = $GLOBALS['auto_create_acct']['email'];
|
2001-06-27 01:16:18 +02:00
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
elseif(isset($GLOBALS['egw_info']['server']['mail_suffix']) == True && $GLOBALS['egw_info']['server']['mail_suffix'] != '')
|
2001-06-27 01:16:18 +02:00
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
$acct_info['account_email'] = $accountname . '@' . $GLOBALS['egw_info']['server']['mail_suffix'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->create($acct_info);
|
|
|
|
$accountid = $this->name2id($accountname);
|
2002-04-21 19:42:40 +02:00
|
|
|
|
2005-11-02 12:45:52 +01:00
|
|
|
if ($accountid)
|
|
|
|
{
|
|
|
|
/* If we have a primary_group, add it as "regular" eGW group (via ACL) too. */
|
|
|
|
if ($primary_group)
|
2002-04-21 19:42:40 +02:00
|
|
|
{
|
2005-11-02 12:45:52 +01:00
|
|
|
$GLOBALS['egw']->acl->add_repository('phpgw_group', $primary_group,$accountid,1);
|
2002-04-21 19:42:40 +02:00
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
// call hook to notify other apps about the new account
|
|
|
|
$GLOBALS['hook_values']['account_lid'] = $acct_info['account_lid'];
|
|
|
|
$GLOBALS['hook_values']['account_id'] = $accountid;
|
|
|
|
$GLOBALS['hook_values']['new_passwd'] = $acct_info['account_passwd'];
|
|
|
|
$GLOBALS['hook_values']['account_status'] = $acct_info['account_status'];
|
|
|
|
$GLOBALS['hook_values']['account_firstname'] = $acct_info['account_firstname'];
|
|
|
|
$GLOBALS['hook_values']['account_lastname'] = $acct_info['account_lastname'];
|
|
|
|
$GLOBALS['egw']->hooks->process($GLOBALS['hook_values']+array(
|
|
|
|
'location' => 'addaccount'
|
|
|
|
),False,True); /* called for every app now, not only enabled ones */
|
2001-06-27 01:16:18 +02:00
|
|
|
}
|
|
|
|
return $accountid;
|
2001-03-29 10:10:04 +02:00
|
|
|
}
|
|
|
|
}
|