2002-03-03 22:47:30 +01:00
|
|
|
<?php
|
2006-05-29 04:56:16 +02:00
|
|
|
/**
|
|
|
|
* Setup
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package setup
|
|
|
|
* @author Joseph Engo <jengo@phpgroupware.org>
|
|
|
|
* @author Dan Kuykendall <seek3r@phpgroupware.org>
|
|
|
|
* @author Mark Peters <skeeter@phpgroupware.org>
|
|
|
|
* @author Miles Lott <milos@groupwhere.org>
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2005-07-20 14:46:59 +02:00
|
|
|
class egw_dummy {
|
|
|
|
var $db;
|
|
|
|
var $common;
|
|
|
|
var $accounts;
|
2005-07-27 12:59:30 +02:00
|
|
|
|
|
|
|
function invalidate_session_cache() { }
|
2005-07-20 14:46:59 +02:00
|
|
|
}
|
|
|
|
|
2002-03-03 22:47:30 +01:00
|
|
|
class setup
|
|
|
|
{
|
|
|
|
var $db;
|
2005-11-02 12:45:52 +01:00
|
|
|
var $config_table = 'egw_config';
|
|
|
|
var $applications_table = 'egw_applications';
|
|
|
|
var $acl_table = 'egw_acl';
|
|
|
|
var $accounts_table = 'egw_accounts';
|
2005-11-13 08:49:56 +01:00
|
|
|
var $prefs_table = 'egw_preferences';
|
2005-11-04 19:35:09 +01:00
|
|
|
var $lang_table = 'egw_lang';
|
|
|
|
var $languages_table = 'egw_languages';
|
2005-11-13 07:58:38 +01:00
|
|
|
var $hooks_table = 'egw_hooks';
|
2005-11-05 23:58:51 +01:00
|
|
|
var $cats_table = 'egw_categories';
|
2002-03-04 05:49:42 +01:00
|
|
|
var $oProc;
|
2006-07-09 08:55:35 +02:00
|
|
|
var $cookie_domain;
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2005-11-27 08:48:22 +01:00
|
|
|
var $detection;
|
|
|
|
var $process;
|
|
|
|
var $lang;
|
|
|
|
var $html;
|
|
|
|
|
|
|
|
var $system_charset;
|
2003-10-22 13:28:17 +02:00
|
|
|
|
|
|
|
/* table name vars */
|
2003-10-05 04:06:11 +02:00
|
|
|
var $tbl_apps;
|
|
|
|
var $tbl_config;
|
|
|
|
var $tbl_hooks;
|
2006-05-29 04:56:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var float $required_php_version php version required by eGroupWare
|
|
|
|
*/
|
2007-12-09 09:03:56 +01:00
|
|
|
var $required_php_version = 5.1;
|
|
|
|
var $recommended_php_version = '5.1+';
|
2002-03-03 22:47:30 +01:00
|
|
|
|
|
|
|
function setup($html=False, $translation=False)
|
|
|
|
{
|
2005-11-27 08:48:22 +01:00
|
|
|
// setup us as $GLOBALS['egw_setup'], as this gets used in our sub-objects
|
|
|
|
$GLOBALS['egw_setup'] =& $this;
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
$this->detection =& CreateObject('setup.setup_detection');
|
|
|
|
$this->process =& CreateObject('setup.setup_process');
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2005-11-27 08:48:22 +01:00
|
|
|
if ($_REQUEST['system_charset']) $this->system_charset = $_REQUEST['system_charset'];
|
|
|
|
|
2002-03-03 22:47:30 +01:00
|
|
|
/* The setup application needs these */
|
2005-11-27 08:48:22 +01:00
|
|
|
if ($html) $this->html =& CreateObject('setup.setup_html');
|
|
|
|
if ($translation) $this->translation =& CreateObject('setup.setup_translation');
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* include api db class for the ConfigDomain and connect to the db
|
|
|
|
*/
|
2004-11-21 10:44:02 +01:00
|
|
|
function loaddb($connect_and_setcharset=true)
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2004-01-06 14:38:45 +01:00
|
|
|
if(!isset($this->ConfigDomain) || empty($this->ConfigDomain))
|
|
|
|
{
|
|
|
|
$this->ConfigDomain = get_var('ConfigDomain',array('COOKIE','POST'),$_POST['FormDomain']);
|
|
|
|
}
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['server']['db_type'] = $GLOBALS['egw_domain'][$this->ConfigDomain]['db_type'];
|
2002-03-03 22:47:30 +01:00
|
|
|
|
2005-03-04 13:40:28 +01:00
|
|
|
if ($GLOBALS['egw_info']['server']['db_type'] == 'pgsql')
|
2004-06-28 11:29:44 +02:00
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['server']['db_persistent'] = False;
|
2004-06-28 11:29:44 +02:00
|
|
|
}
|
2005-06-19 14:43:00 +02:00
|
|
|
$this->db =& CreateObject('phpgwapi.egw_db');
|
2005-03-04 13:40:28 +01:00
|
|
|
$this->db->Host = $GLOBALS['egw_domain'][$this->ConfigDomain]['db_host'];
|
|
|
|
$this->db->Port = $GLOBALS['egw_domain'][$this->ConfigDomain]['db_port'];
|
|
|
|
$this->db->Type = $GLOBALS['egw_domain'][$this->ConfigDomain]['db_type'];
|
|
|
|
$this->db->Database = $GLOBALS['egw_domain'][$this->ConfigDomain]['db_name'];
|
|
|
|
$this->db->User = $GLOBALS['egw_domain'][$this->ConfigDomain]['db_user'];
|
|
|
|
$this->db->Password = $GLOBALS['egw_domain'][$this->ConfigDomain]['db_pass'];
|
2004-09-18 16:55:02 +02:00
|
|
|
|
|
|
|
$this->db->set_app('phpgwapi');
|
2004-11-21 10:44:02 +01:00
|
|
|
|
|
|
|
if ($connect_and_setcharset)
|
|
|
|
{
|
2005-05-19 08:32:42 +02:00
|
|
|
$this->db->Halt_On_Error = 'no'; // table might not be created at that stage
|
2004-11-21 10:44:02 +01:00
|
|
|
|
2005-11-02 12:45:52 +01:00
|
|
|
$this->set_table_names(); // sets/checks config- and applications-table-name
|
|
|
|
|
2004-11-21 10:44:02 +01:00
|
|
|
// Set the DB's client charset if a system-charset is set
|
2005-11-02 12:45:52 +01:00
|
|
|
$this->db->select($this->config_table,'config_value',array(
|
|
|
|
'config_app' => 'phpgwapi',
|
|
|
|
'config_name' => 'system_charset',
|
|
|
|
),__LINE__,__FILE__);
|
2004-11-21 10:44:02 +01:00
|
|
|
if ($this->db->next_record() && $this->db->f(0))
|
|
|
|
{
|
2005-11-04 19:35:09 +01:00
|
|
|
$this->system_charset = $this->db->f(0);
|
|
|
|
$this->db_charset_was = $this->db->Link_ID->GetCharSet(); // needed for the update
|
|
|
|
|
|
|
|
// we can NOT set the DB charset for mysql, if the api version < 1.0.1.019, as it would mess up the DB content!!!
|
|
|
|
if (substr($this->db->Type,0,5) == 'mysql') // we need to check the api version
|
|
|
|
{
|
|
|
|
$this->db->select($this->applications_table,'app_version',array(
|
|
|
|
'app_name' => 'phpgwapi',
|
|
|
|
),__LINE__,__FILE__);
|
|
|
|
$api_version = $this->db->next_record() ? $this->db->f(0) : false;
|
|
|
|
}
|
|
|
|
if (!$api_version || !$this->alessthanb($api_version,'1.0.1.019'))
|
|
|
|
{
|
|
|
|
$this->db->Link_ID->SetCharSet($this->system_charset);
|
|
|
|
}
|
2004-11-21 10:44:02 +01:00
|
|
|
}
|
|
|
|
$this->db->Halt_On_Error = 'yes'; // setting the default again
|
|
|
|
}
|
2004-01-06 14:38:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the domain used for cookies
|
|
|
|
*
|
|
|
|
* @return string domain
|
|
|
|
*/
|
|
|
|
function set_cookiedomain()
|
|
|
|
{
|
2006-07-09 08:55:35 +02:00
|
|
|
// Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy
|
|
|
|
$this->cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
|
2004-05-01 11:58:38 +02:00
|
|
|
|
|
|
|
// remove port from HTTP_HOST
|
|
|
|
if (preg_match("/^(.*):(.*)$/",$this->cookie_domain,$arr))
|
2004-01-06 14:38:45 +01:00
|
|
|
{
|
2004-05-01 11:58:38 +02:00
|
|
|
$this->cookie_domain = $arr[1];
|
2004-01-06 14:38:45 +01:00
|
|
|
}
|
2004-05-01 11:58:38 +02:00
|
|
|
if (count(explode('.',$this->cookie_domain)) <= 1)
|
2004-01-06 14:38:45 +01:00
|
|
|
{
|
2004-05-01 11:58:38 +02:00
|
|
|
// setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in
|
2004-01-06 14:38:45 +01:00
|
|
|
$this->cookie_domain = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a cookie
|
|
|
|
*
|
|
|
|
* @param string $cookiename name of cookie to be set
|
|
|
|
* @param string $cookievalue value to be used, if unset cookie is cleared (optional)
|
|
|
|
* @param int $cookietime when cookie should expire, 0 for session only (optional)
|
|
|
|
*/
|
|
|
|
function set_cookie($cookiename,$cookievalue='',$cookietime=0)
|
|
|
|
{
|
2006-07-09 08:55:35 +02:00
|
|
|
if(!isset($this->cookie_domain))
|
2004-01-06 14:38:45 +01:00
|
|
|
{
|
|
|
|
$this->set_cookiedomain();
|
|
|
|
}
|
2004-05-25 00:33:48 +02:00
|
|
|
setcookie($cookiename,$cookievalue,$cookietime,'/',$this->cookie_domain);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* authenticate the setup user
|
|
|
|
*
|
|
|
|
* @param $auth_type ???
|
|
|
|
*/
|
2002-03-06 03:47:47 +01:00
|
|
|
function auth($auth_type='Config')
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2003-09-28 17:45:07 +02:00
|
|
|
#phpinfo();
|
2004-01-18 22:03:56 +01:00
|
|
|
$FormLogout = get_var('FormLogout', array('GET','POST'));
|
2007-03-19 10:53:03 +01:00
|
|
|
$ConfigLang = get_var('ConfigLang', array('POST','COOKIE'));
|
2004-01-06 14:38:45 +01:00
|
|
|
if(!$FormLogout)
|
2002-05-11 21:30:10 +02:00
|
|
|
{
|
2004-01-06 14:38:45 +01:00
|
|
|
$ConfigLogin = get_var('ConfigLogin', array('POST'));
|
|
|
|
$HeaderLogin = get_var('HeaderLogin', array('POST'));
|
|
|
|
$FormDomain = get_var('FormDomain', array('POST'));
|
2004-01-18 22:03:56 +01:00
|
|
|
$FormUser = get_var('FormUser', array('POST'));
|
2004-01-06 14:38:45 +01:00
|
|
|
$FormPW = get_var('FormPW', array('POST'));
|
2002-05-11 21:30:10 +02:00
|
|
|
|
2004-01-06 14:38:45 +01:00
|
|
|
$this->ConfigDomain = get_var('ConfigDomain',array('POST','COOKIE'));
|
2004-01-18 22:03:56 +01:00
|
|
|
$ConfigUser = get_var('ConfigUser', array('POST','COOKIE'));
|
2004-01-06 14:38:45 +01:00
|
|
|
$ConfigPW = get_var('ConfigPW', array('POST','COOKIE'));
|
2004-01-18 22:03:56 +01:00
|
|
|
$HeaderUser = get_var('HeaderUser', array('POST','COOKIE'));
|
2004-01-06 14:38:45 +01:00
|
|
|
$HeaderPW = get_var('HeaderPW', array('POST','COOKIE'));
|
2004-01-18 22:03:56 +01:00
|
|
|
|
|
|
|
/* Setup defaults to aid in header upgrade to version 1.26.
|
|
|
|
* This was the first version to include the following values.
|
|
|
|
*/
|
2005-03-04 13:40:28 +01:00
|
|
|
if(!@isset($GLOBALS['egw_domain'][$FormDomain]['config_user']) && isset($GLOBALS['egw_domain'][$FormDomain]))
|
2004-01-18 22:03:56 +01:00
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
@$GLOBALS['egw_domain'][$FormDomain]['config_user'] = 'admin';
|
2004-01-18 22:03:56 +01:00
|
|
|
}
|
2005-03-04 13:40:28 +01:00
|
|
|
if(!@isset($GLOBALS['egw_info']['server']['header_admin_user']))
|
2004-01-18 22:03:56 +01:00
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
@$GLOBALS['egw_info']['server']['header_admin_user'] = 'admin';
|
2004-01-18 22:03:56 +01:00
|
|
|
}
|
2004-01-06 14:38:45 +01:00
|
|
|
}
|
2002-03-04 03:55:53 +01:00
|
|
|
|
2004-05-04 11:08:28 +02:00
|
|
|
$remoteip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
if(!empty($remoteip) && !$this->checkip($remoteip)) { return False; }
|
2002-03-06 03:40:30 +01:00
|
|
|
|
2004-01-06 14:38:45 +01:00
|
|
|
/* If FormLogout is set, simply invalidate the cookies (LOGOUT) */
|
|
|
|
switch(strtolower($FormLogout))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2004-01-06 14:38:45 +01:00
|
|
|
case 'config':
|
2002-03-04 03:55:53 +01:00
|
|
|
/* config logout */
|
2004-01-06 14:38:45 +01:00
|
|
|
$expire = time() - 86400;
|
2004-01-18 22:03:56 +01:00
|
|
|
$this->set_cookie('ConfigUser','',$expire,'/');
|
2004-01-06 14:38:45 +01:00
|
|
|
$this->set_cookie('ConfigPW','',$expire,'/');
|
|
|
|
$this->set_cookie('ConfigDomain','',$expire,'/');
|
2007-03-19 10:53:03 +01:00
|
|
|
// $this->set_cookie('ConfigLang','',$expire,'/');
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['setup']['LastDomain'] = $_COOKIE['ConfigDomain'];
|
|
|
|
$GLOBALS['egw_info']['setup']['ConfigLoginMSG'] = lang('You have successfully logged out');
|
|
|
|
$GLOBALS['egw_info']['setup']['HeaderLoginMSG'] = '';
|
2002-03-03 22:47:30 +01:00
|
|
|
return False;
|
2004-01-06 14:38:45 +01:00
|
|
|
case 'header':
|
2002-03-04 03:55:53 +01:00
|
|
|
/* header admin logout */
|
2004-01-06 14:38:45 +01:00
|
|
|
$expire = time() - 86400;
|
2004-01-18 22:03:56 +01:00
|
|
|
$this->set_cookie('HeaderUser','',$expire,'/');
|
2004-01-06 14:38:45 +01:00
|
|
|
$this->set_cookie('HeaderPW','',$expire,'/');
|
2007-03-19 10:53:03 +01:00
|
|
|
// $this->set_cookie('ConfigLang','',$expire,'/');
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['setup']['HeaderLoginMSG'] = lang('You have successfully logged out');
|
|
|
|
$GLOBALS['egw_info']['setup']['ConfigLoginMSG'] = '';
|
2002-03-04 03:55:53 +01:00
|
|
|
return False;
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2004-01-06 14:38:45 +01:00
|
|
|
|
|
|
|
/* We get here if FormLogout is not set (LOGIN or subsequent pages) */
|
|
|
|
/* Expire login if idle for 20 minutes. The cookies are updated on every page load. */
|
|
|
|
$expire = (int)(time() + (1200*9));
|
|
|
|
|
|
|
|
switch(strtolower($auth_type))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2004-01-06 14:38:45 +01:00
|
|
|
case 'header':
|
|
|
|
if(!empty($HeaderLogin))
|
|
|
|
{
|
|
|
|
/* header admin login */
|
2004-01-18 22:03:56 +01:00
|
|
|
/* New test is md5, cleartext version is for header < 1.26 */
|
2005-03-04 13:40:28 +01:00
|
|
|
if ($this->check_auth($FormUser,$FormPW,$GLOBALS['egw_info']['server']['header_admin_user'],
|
|
|
|
$GLOBALS['egw_info']['server']['header_admin_password']))
|
2004-01-06 14:38:45 +01:00
|
|
|
{
|
2005-05-19 08:32:42 +02:00
|
|
|
$this->set_cookie('HeaderUser',$FormUser,$expire,'/');
|
|
|
|
$this->set_cookie('HeaderPW',md5($FormPW),$expire,'/');
|
|
|
|
$this->set_cookie('ConfigLang',$ConfigLang,$expire,'/');
|
2004-01-06 14:38:45 +01:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['setup']['HeaderLoginMSG'] = lang('Invalid password');
|
|
|
|
$GLOBALS['egw_info']['setup']['ConfigLoginMSG'] = '';
|
2004-01-06 14:38:45 +01:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif(!empty($HeaderPW) && $auth_type == 'Header')
|
|
|
|
{
|
|
|
|
// Returning after login to header admin
|
2004-01-18 22:03:56 +01:00
|
|
|
/* New test is md5, cleartext version is for header < 1.26 */
|
2005-03-04 13:40:28 +01:00
|
|
|
if ($this->check_auth($HeaderUser,$HeaderPW,$GLOBALS['egw_info']['server']['header_admin_user'],
|
|
|
|
$GLOBALS['egw_info']['server']['header_admin_password']))
|
2004-01-06 14:38:45 +01:00
|
|
|
{
|
2005-05-19 08:32:42 +02:00
|
|
|
$this->set_cookie('HeaderUser',$HeaderUser,$expire,'/');
|
|
|
|
$this->set_cookie('HeaderPW',$HeaderPW,$expire,'/');
|
|
|
|
$this->set_cookie('ConfigLang',$ConfigLang,$expire,'/');
|
2004-01-06 14:38:45 +01:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['setup']['HeaderLoginMSG'] = lang('Invalid password');
|
|
|
|
$GLOBALS['egw_info']['setup']['ConfigLoginMSG'] = '';
|
2004-01-06 14:38:45 +01:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'config':
|
|
|
|
if(!empty($ConfigLogin))
|
|
|
|
{
|
|
|
|
/* config login */
|
2004-01-18 22:03:56 +01:00
|
|
|
/* New test is md5, cleartext version is for header < 1.26 */
|
2005-03-04 13:40:28 +01:00
|
|
|
if (isset($GLOBALS['egw_domain'][$FormDomain]) &&
|
|
|
|
$this->check_auth($FormUser,$FormPW,@$GLOBALS['egw_domain'][$FormDomain]['config_user'],
|
|
|
|
@$GLOBALS['egw_domain'][$FormDomain]['config_passwd']))
|
2004-01-06 14:38:45 +01:00
|
|
|
{
|
2005-05-19 08:32:42 +02:00
|
|
|
$this->set_cookie('ConfigUser',$FormUser,$expire,'/');
|
|
|
|
$this->set_cookie('ConfigPW',md5($FormPW),$expire,'/');
|
|
|
|
$this->set_cookie('ConfigDomain',$FormDomain,$expire,'/');
|
2004-01-06 14:38:45 +01:00
|
|
|
/* Set this now since the cookie will not be available until the next page load */
|
2005-05-19 08:32:42 +02:00
|
|
|
$this->ConfigDomain = $FormDomain;
|
|
|
|
$this->set_cookie('ConfigLang',$ConfigLang,$expire,'/');
|
2004-01-06 14:38:45 +01:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['setup']['ConfigLoginMSG'] = lang('Invalid password');
|
|
|
|
$GLOBALS['egw_info']['setup']['HeaderLoginMSG'] = '';
|
2004-01-06 14:38:45 +01:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif(!empty($ConfigPW))
|
|
|
|
{
|
|
|
|
// Returning after login to config
|
2004-01-18 22:03:56 +01:00
|
|
|
/* New test is md5, cleartext version is for header < 1.26 */
|
2005-03-04 13:40:28 +01:00
|
|
|
if ($this->check_auth($ConfigUser,$ConfigPW,@$GLOBALS['egw_domain'][$this->ConfigDomain]['config_user'],
|
|
|
|
@$GLOBALS['egw_domain'][$this->ConfigDomain]['config_passwd']))
|
2004-01-06 14:38:45 +01:00
|
|
|
{
|
2005-05-19 08:32:42 +02:00
|
|
|
$this->set_cookie('ConfigUser',$ConfigUser,$expire,'/');
|
|
|
|
$this->set_cookie('ConfigPW',$ConfigPW,$expire,'/');
|
2004-01-06 14:38:45 +01:00
|
|
|
$this->set_cookie('ConfigDomain',$this->ConfigDomain,$expire,'/');
|
2005-05-19 08:32:42 +02:00
|
|
|
$this->set_cookie('ConfigLang',$ConfigLang,$expire,'/');
|
2004-01-06 14:38:45 +01:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['setup']['ConfigLoginMSG'] = lang('Invalid password');
|
|
|
|
$GLOBALS['egw_info']['setup']['HeaderLoginMSG'] = '';
|
2004-01-06 14:38:45 +01:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2004-01-06 14:38:45 +01:00
|
|
|
|
|
|
|
return False;
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
|
2005-10-15 09:57:06 +02:00
|
|
|
/**
|
|
|
|
* check if username and password is valid
|
|
|
|
*
|
|
|
|
* this function compares the supplied and stored username and password
|
2005-05-29 10:03:01 +02:00
|
|
|
* as any of the passwords can be clear text or md5 we convert them to md5
|
|
|
|
* internal and compare always the md5 hashs
|
2005-10-15 09:57:06 +02:00
|
|
|
*
|
|
|
|
* @param string $user the user supplied username
|
|
|
|
* @param string $pw the user supplied password
|
|
|
|
* @param string $conf_user the configured username
|
|
|
|
* @param string $conf_pw the configured password
|
|
|
|
* @returns bool
|
|
|
|
*/
|
2004-02-23 11:07:55 +01:00
|
|
|
function check_auth($user,$pw,$conf_user,$conf_pw)
|
|
|
|
{
|
2005-05-29 10:03:01 +02:00
|
|
|
#echo "<p>setup::check_auth('$user','$pw','$conf_user','$conf_pw')</p>\n";exit;
|
2004-02-23 11:07:55 +01:00
|
|
|
if ($user != $conf_user)
|
|
|
|
{
|
|
|
|
return False; // wrong username
|
|
|
|
}
|
2005-05-29 10:03:01 +02:00
|
|
|
|
|
|
|
// Verify that $pw is not already encoded as md5
|
|
|
|
if(!preg_match('/^[0-9a-f]{32}$/',$conf_pw))
|
2004-02-23 11:07:55 +01:00
|
|
|
{
|
2005-05-29 10:03:01 +02:00
|
|
|
$conf_pw = md5($conf_pw);
|
2004-02-23 11:07:55 +01:00
|
|
|
}
|
2005-05-29 10:03:01 +02:00
|
|
|
|
2005-05-16 02:42:05 +02:00
|
|
|
|
2005-05-29 10:03:01 +02:00
|
|
|
// Verify that $pw is not already encoded as md5
|
|
|
|
if(!preg_match('/^[0-9a-f]{32}$/',$pw))
|
|
|
|
{
|
|
|
|
$pw = md5($pw);
|
|
|
|
}
|
|
|
|
|
2004-02-23 11:07:55 +01:00
|
|
|
return $pw == $conf_pw;
|
2005-05-29 10:03:01 +02:00
|
|
|
|
2004-02-23 11:07:55 +01:00
|
|
|
}
|
|
|
|
|
2002-05-11 21:30:10 +02:00
|
|
|
function checkip($remoteip='')
|
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
//echo "<p>setup::checkip($remoteip) against setup_acl='".$GLOBALS['egw_info']['server']['setup_acl']."'</p>\n";
|
|
|
|
$allowed_ips = explode(',',@$GLOBALS['egw_info']['server']['setup_acl']);
|
|
|
|
if(empty($GLOBALS['egw_info']['server']['setup_acl']) || !is_array($allowed_ips))
|
2002-05-11 21:30:10 +02:00
|
|
|
{
|
2004-05-04 11:51:17 +02:00
|
|
|
return True; // no test
|
|
|
|
}
|
|
|
|
$remotes = explode('.',$remoteip);
|
|
|
|
foreach($allowed_ips as $value)
|
|
|
|
{
|
|
|
|
if (!preg_match('/^[0-9.]+$/',$value))
|
2002-05-11 21:30:10 +02:00
|
|
|
{
|
2004-05-04 11:51:17 +02:00
|
|
|
$value = gethostbyname($was=$value); // resolve domain-name, eg. a dyndns account
|
|
|
|
//echo "resolving '$was' to '$value'<br>\n";
|
|
|
|
}
|
|
|
|
$values = explode('.',$value);
|
|
|
|
for($i = 0; $i < count($values); ++$i)
|
|
|
|
{
|
|
|
|
if ((int) $values[$i] != (int) $remotes[$i])
|
2002-05-11 21:30:10 +02:00
|
|
|
{
|
2004-05-04 11:51:17 +02:00
|
|
|
break;
|
2002-05-11 21:30:10 +02:00
|
|
|
}
|
|
|
|
}
|
2004-05-04 11:51:17 +02:00
|
|
|
if ($i == count($values))
|
2002-05-11 21:30:10 +02:00
|
|
|
{
|
2004-05-04 11:51:17 +02:00
|
|
|
return True; // match
|
2002-05-11 21:30:10 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['setup']['HeaderLoginMSG'] = '';
|
|
|
|
$GLOBALS['egw_info']['setup']['ConfigLoginMSG'] = lang('Invalid IP address');
|
2004-05-04 11:51:17 +02:00
|
|
|
|
|
|
|
return False;
|
2002-05-11 21:30:10 +02:00
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Return X.X.X major version from X.X.X.X versionstring
|
|
|
|
*
|
|
|
|
* @param $
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function get_major($versionstring)
|
|
|
|
{
|
|
|
|
if(!$versionstring)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2004-05-04 11:51:17 +02:00
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
$version = str_replace('pre','.',$versionstring);
|
2002-03-03 22:47:30 +01:00
|
|
|
$varray = explode('.',$version);
|
|
|
|
$major = implode('.',array($varray[0],$varray[1],$varray[2]));
|
|
|
|
|
|
|
|
return $major;
|
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Clear system/user level cache so as to have it rebuilt with the next access
|
2005-11-04 19:35:09 +01:00
|
|
|
*
|
2005-11-13 10:16:31 +01:00
|
|
|
* @deprecated AFAIK this code is not used anymore -- RalfBecker 2005/11/04
|
2005-03-24 14:15:12 +01:00
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function clear_session_cache()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Add an application to the phpgw_applications table
|
|
|
|
*
|
|
|
|
* @param $appname Application 'name' with a matching $setup_info[$appname] array slice
|
|
|
|
* @param $enable * optional, set to True/False to override setup.inc.php setting
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function register_app($appname,$enable=99)
|
|
|
|
{
|
|
|
|
$setup_info = $GLOBALS['setup_info'];
|
|
|
|
|
|
|
|
if(!$appname)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($enable==99)
|
|
|
|
{
|
|
|
|
$enable = $setup_info[$appname]['enable'];
|
|
|
|
}
|
2003-11-04 15:14:57 +01:00
|
|
|
$enable = (int)$enable;
|
2002-03-03 22:47:30 +01:00
|
|
|
|
|
|
|
if($GLOBALS['DEBUG'])
|
|
|
|
{
|
|
|
|
echo '<br>register_app(): ' . $appname . ', version: ' . $setup_info[$appname]['version'] . ', table: ' . $appstbl . '<br>';
|
|
|
|
// _debug_array($setup_info[$appname]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($setup_info[$appname]['version'])
|
|
|
|
{
|
|
|
|
if($setup_info[$appname]['tables'])
|
|
|
|
{
|
|
|
|
$tables = implode(',',$setup_info[$appname]['tables']);
|
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($setup_info[$appname]['tables_use_prefix'] == True)
|
|
|
|
{
|
2004-09-18 16:55:02 +02:00
|
|
|
if($GLOBALS['DEBUG'])
|
|
|
|
{
|
|
|
|
echo "<br>$appname uses tables_use_prefix, storing ". $setup_info[$appname]['tables_prefix']." as prefix for tables\n";
|
|
|
|
}
|
|
|
|
$this->db->insert($this->config_table,array(
|
|
|
|
'config_app' => $appname,
|
|
|
|
'config_name' => $appname.'_tables_prefix',
|
|
|
|
'config_value' => $setup_info[$appname]['tables_prefix'],
|
|
|
|
),False,__LINE__,__FILE__);
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2004-09-18 16:55:02 +02:00
|
|
|
$this->db->insert($this->applications_table,array(
|
|
|
|
'app_name' => $appname,
|
|
|
|
'app_enabled' => $enable,
|
|
|
|
'app_order' => $setup_info[$appname]['app_order'],
|
|
|
|
'app_tables' => $tables,
|
|
|
|
'app_version' => $setup_info[$appname]['version'],
|
|
|
|
),False,__LINE__,__FILE__);
|
|
|
|
|
2002-03-03 22:47:30 +01:00
|
|
|
$this->clear_session_cache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Check if an application has info in the db
|
|
|
|
*
|
|
|
|
* @param $appname Application 'name' with a matching $setup_info[$appname] array slice
|
|
|
|
* @param $enabled optional, set to False to not enable this app
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function app_registered($appname)
|
|
|
|
{
|
|
|
|
$setup_info = $GLOBALS['setup_info'];
|
|
|
|
|
|
|
|
if(!$appname)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(@$GLOBALS['DEBUG'])
|
|
|
|
{
|
2004-09-18 16:55:02 +02:00
|
|
|
echo '<br>app_registered(): checking ' . $appname . ', table: ' . $this->applications_table;
|
2002-03-03 22:47:30 +01:00
|
|
|
// _debug_array($setup_info[$appname]);
|
|
|
|
}
|
|
|
|
|
2004-09-18 16:55:02 +02:00
|
|
|
$this->db->select($this->applications_table,'COUNT(*)',array('app_name' => $appname),__LINE__,__FILE__);
|
2005-11-04 19:35:09 +01:00
|
|
|
if($this->db->next_record() && $this->db->f(0))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
|
|
|
if(@$GLOBALS['DEBUG'])
|
|
|
|
{
|
|
|
|
echo '... app previously registered.';
|
|
|
|
}
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
if(@$GLOBALS['DEBUG'])
|
|
|
|
{
|
|
|
|
echo '... app not registered';
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Update application info in the db
|
|
|
|
*
|
|
|
|
* @param $appname Application 'name' with a matching $setup_info[$appname] array slice
|
|
|
|
* @param $enabled optional, set to False to not enable this app
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function update_app($appname)
|
|
|
|
{
|
|
|
|
$setup_info = $GLOBALS['setup_info'];
|
|
|
|
|
|
|
|
if(!$appname)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($GLOBALS['DEBUG'])
|
|
|
|
{
|
2004-09-18 16:55:02 +02:00
|
|
|
echo '<br>update_app(): ' . $appname . ', version: ' . $setup_info[$appname]['currentver'] . ', table: ' . $this->applications_table . '<br>';
|
2002-03-03 22:47:30 +01:00
|
|
|
// _debug_array($setup_info[$appname]);
|
|
|
|
}
|
|
|
|
|
2004-09-18 16:55:02 +02:00
|
|
|
if(!$this->app_registered($appname))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($setup_info[$appname]['version'])
|
|
|
|
{
|
|
|
|
//echo '<br>' . $setup_info[$appname]['version'];
|
|
|
|
if($setup_info[$appname]['tables'])
|
|
|
|
{
|
|
|
|
$tables = implode(',',$setup_info[$appname]['tables']);
|
|
|
|
}
|
2004-09-18 16:55:02 +02:00
|
|
|
$this->db->update($this->applications_table,array(
|
|
|
|
'app_enabled' => $setup_info[$appname]['enable'],
|
|
|
|
'app_order' => $setup_info[$appname]['app_order'],
|
|
|
|
'app_tables' => $tables,
|
|
|
|
'app_version' => $setup_info[$appname]['version'],
|
|
|
|
),array('app_name'=>$appname),__LINE__,__FILE__);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Update application version in applications table, post upgrade
|
|
|
|
*
|
|
|
|
* @param $setup_info * Array of application information (multiple apps or single)
|
|
|
|
* @param $appname * Application 'name' with a matching $setup_info[$appname] array slice
|
|
|
|
* @param $tableschanged ???
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function update_app_version($setup_info, $appname, $tableschanged = True)
|
|
|
|
{
|
|
|
|
if(!$appname)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($tableschanged == True)
|
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
$GLOBALS['egw_info']['setup']['tableschanged'] = True;
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
if($setup_info[$appname]['currentver'])
|
|
|
|
{
|
2004-09-18 16:55:02 +02:00
|
|
|
$this->db->update($this->applications_table,array(
|
|
|
|
'app_version' => $setup_info[$appname]['currentver'],
|
|
|
|
),array('app_name'=>$appname),__LINE__,__FILE__);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
return $setup_info;
|
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* de-Register an application
|
|
|
|
*
|
|
|
|
* @param $appname Application 'name' with a matching $setup_info[$appname] array slice
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function deregister_app($appname)
|
|
|
|
{
|
|
|
|
if(!$appname)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$setup_info = $GLOBALS['setup_info'];
|
|
|
|
|
|
|
|
//echo 'DELETING application: ' . $appname;
|
2004-09-18 16:55:02 +02:00
|
|
|
$this->db->delete($this->applications_table,array('app_name'=>$appname),__LINE__,__FILE__);
|
2002-03-03 22:47:30 +01:00
|
|
|
$this->clear_session_cache();
|
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Register an application's hooks
|
|
|
|
*
|
|
|
|
* @param $appname Application 'name' with a matching $setup_info[$appname] array slice
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function register_hooks($appname)
|
|
|
|
{
|
|
|
|
$setup_info = $GLOBALS['setup_info'];
|
|
|
|
|
|
|
|
if(!$appname)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2005-11-13 07:58:38 +01:00
|
|
|
if(!$this->hooks_table) // No hooks table yet
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2003-04-28 00:26:04 +02:00
|
|
|
if (!is_object($this->hooks))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2005-11-13 07:58:38 +01:00
|
|
|
$this->hooks =& CreateObject('phpgwapi.hooks',$this->db,$this->hooks_table);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2003-04-28 00:26:04 +02:00
|
|
|
$this->hooks->register_hooks($appname,$setup_info[$appname]['hooks']);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Update an application's hooks
|
|
|
|
*
|
|
|
|
* @param $appname Application 'name' with a matching $setup_info[$appname] array slice
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function update_hooks($appname)
|
|
|
|
{
|
2003-04-28 00:26:04 +02:00
|
|
|
$this->register_hooks($appname);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* de-Register an application's hooks
|
|
|
|
*
|
|
|
|
* @param $appname Application 'name' with a matching $setup_info[$appname] array slice
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function deregister_hooks($appname)
|
|
|
|
{
|
2005-11-13 07:58:38 +01:00
|
|
|
if(!$this->hooks_table) // No hooks table yet
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$appname)
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
2003-04-28 00:26:04 +02:00
|
|
|
|
2002-03-03 22:47:30 +01:00
|
|
|
//echo "DELETING hooks for: " . $setup_info[$appname]['name'];
|
2003-04-28 00:26:04 +02:00
|
|
|
if (!is_object($this->hooks))
|
|
|
|
{
|
2005-11-13 07:58:38 +01:00
|
|
|
$this->hooks =& CreateObject('phpgwapi.hooks',$this->db,$this->hooks_table);
|
2003-04-28 00:26:04 +02:00
|
|
|
}
|
|
|
|
$this->hooks->register_hooks($appname);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* call the hooks for a single application
|
|
|
|
*
|
|
|
|
* @param $location hook location - required
|
|
|
|
* @param $appname application name - optional
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function hook($location, $appname='')
|
|
|
|
{
|
2003-04-28 00:26:04 +02:00
|
|
|
if (!is_object($this->hooks))
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
2005-11-13 07:58:38 +01:00
|
|
|
$this->hooks =& CreateObject('phpgwapi.hooks',$this->db,$this->hooks_table);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
2003-04-28 10:25:59 +02:00
|
|
|
return $this->hooks->single($location,$appname,True,True);
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* egw version checking, is param 1 < param 2 in phpgw versionspeak?
|
|
|
|
* @param $a phpgw version number to check if less than $b
|
|
|
|
* @param $b phpgw version number to check $a against
|
|
|
|
* @return True if $a < $b
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function alessthanb($a,$b,$DEBUG=False)
|
|
|
|
{
|
|
|
|
$num = array('1st','2nd','3rd','4th');
|
|
|
|
|
|
|
|
if($DEBUG)
|
|
|
|
{
|
|
|
|
echo'<br>Input values: '
|
|
|
|
. 'A="'.$a.'", B="'.$b.'"';
|
|
|
|
}
|
2003-11-04 15:14:57 +01:00
|
|
|
$newa = str_replace('pre','.',$a);
|
|
|
|
$newb = str_replace('pre','.',$b);
|
2002-03-03 22:47:30 +01:00
|
|
|
$testa = explode('.',$newa);
|
|
|
|
if(@$testa[1] == '')
|
|
|
|
{
|
|
|
|
$testa[1] = 0;
|
|
|
|
}
|
2004-07-10 12:56:09 +02:00
|
|
|
|
2002-03-03 22:47:30 +01:00
|
|
|
$testb = explode('.',$newb);
|
|
|
|
if(@$testb[1] == '')
|
|
|
|
{
|
|
|
|
$testb[1] = 0;
|
|
|
|
}
|
|
|
|
if(@$testb[3] == '')
|
|
|
|
{
|
|
|
|
$testb[3] = 0;
|
|
|
|
}
|
|
|
|
$less = 0;
|
|
|
|
|
|
|
|
for($i=0;$i<count($testa);$i++)
|
|
|
|
{
|
2003-11-04 15:14:57 +01:00
|
|
|
if($DEBUG) { echo'<br>Checking if '. (int)$testa[$i] . ' is less than ' . (int)$testb[$i] . ' ...'; }
|
|
|
|
if((int)$testa[$i] < (int)$testb[$i])
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
|
|
|
if ($DEBUG) { echo ' yes.'; }
|
|
|
|
$less++;
|
|
|
|
if($i<3)
|
|
|
|
{
|
|
|
|
/* Ensure that this is definitely smaller */
|
|
|
|
if($DEBUG) { echo" This is the $num[$i] octet, so A is definitely less than B."; }
|
|
|
|
$less = 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-11-04 15:14:57 +01:00
|
|
|
elseif((int)$testa[$i] > (int)$testb[$i])
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
|
|
|
if($DEBUG) { echo ' no.'; }
|
|
|
|
$less--;
|
|
|
|
if($i<2)
|
|
|
|
{
|
|
|
|
/* Ensure that this is definitely greater */
|
|
|
|
if($DEBUG) { echo" This is the $num[$i] octet, so A is definitely greater than B."; }
|
|
|
|
$less = -5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-10 12:56:09 +02:00
|
|
|
if($DEBUG) { echo ' no, they are equal or of different length.'; }
|
|
|
|
// makes sure eg. '1.0.0' is counted less the '1.0.0.xxx' !
|
|
|
|
$less = count($testa) < count($testb) ? 1 : 0;
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if($DEBUG) { echo '<br>Check value is: "'.$less.'"'; }
|
|
|
|
if($less>0)
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo '<br>A is less than B'; }
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
elseif($less<0)
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo '<br>A is greater than B'; }
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo '<br>A is equal to B'; }
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* egw version checking, is param 1 > param 2 in phpgw versionspeak?
|
|
|
|
*
|
|
|
|
* @param $a phpgw version number to check if more than $b
|
|
|
|
* @param $b phpgw version number to check $a against
|
|
|
|
* @return True if $a < $b
|
|
|
|
*/
|
2002-03-03 22:47:30 +01:00
|
|
|
function amorethanb($a,$b,$DEBUG=False)
|
|
|
|
{
|
|
|
|
$num = array('1st','2nd','3rd','4th');
|
|
|
|
|
|
|
|
if($DEBUG)
|
|
|
|
{
|
|
|
|
echo'<br>Input values: '
|
|
|
|
. 'A="'.$a.'", B="'.$b.'"';
|
|
|
|
}
|
2003-11-04 15:14:57 +01:00
|
|
|
$newa = str_replace('pre','.',$a);
|
|
|
|
$newb = str_replace('pre','.',$b);
|
2002-03-03 22:47:30 +01:00
|
|
|
$testa = explode('.',$newa);
|
|
|
|
if($testa[3] == '')
|
|
|
|
{
|
|
|
|
$testa[3] = 0;
|
|
|
|
}
|
|
|
|
$testb = explode('.',$newb);
|
|
|
|
if($testb[3] == '')
|
|
|
|
{
|
|
|
|
$testb[3] = 0;
|
|
|
|
}
|
|
|
|
$less = 0;
|
|
|
|
|
|
|
|
for($i=0;$i<count($testa);$i++)
|
|
|
|
{
|
2003-11-04 15:14:57 +01:00
|
|
|
if($DEBUG) { echo'<br>Checking if '. (int)$testa[$i] . ' is more than ' . (int)$testb[$i] . ' ...'; }
|
|
|
|
if((int)$testa[$i] > (int)$testb[$i])
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
|
|
|
if($DEBUG) { echo ' yes.'; }
|
|
|
|
$less++;
|
|
|
|
if($i<3)
|
|
|
|
{
|
|
|
|
/* Ensure that this is definitely greater */
|
|
|
|
if($DEBUG) { echo" This is the $num[$i] octet, so A is definitely greater than B."; }
|
|
|
|
$less = 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-11-04 15:14:57 +01:00
|
|
|
elseif((int)$testa[$i] < (int)$testb[$i])
|
2002-03-03 22:47:30 +01:00
|
|
|
{
|
|
|
|
if($DEBUG) { echo ' no.'; }
|
|
|
|
$less--;
|
|
|
|
if($i<2)
|
|
|
|
{
|
|
|
|
/* Ensure that this is definitely smaller */
|
|
|
|
if($DEBUG) { echo" This is the $num[$i] octet, so A is definitely less than B."; }
|
|
|
|
$less = -5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo ' no, they are equal.'; }
|
|
|
|
$less = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($DEBUG) { echo '<br>Check value is: "'.$less.'"'; }
|
|
|
|
if($less>0)
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo '<br>A is greater than B'; }
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
elseif($less<0)
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo '<br>A is less than B'; }
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if($DEBUG) { echo '<br>A is equal to B'; }
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
2003-09-11 20:13:49 +02:00
|
|
|
|
2003-12-29 22:05:06 +01:00
|
|
|
function setup_account_object()
|
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
if (!is_object($GLOBALS['egw']->accounts))
|
2003-12-29 22:05:06 +01:00
|
|
|
{
|
|
|
|
if (!is_object($this->db))
|
|
|
|
{
|
|
|
|
$this->loaddb();
|
|
|
|
}
|
|
|
|
/* Load up some configured values */
|
2006-06-08 01:10:06 +02:00
|
|
|
$this->db->select($this->config_table,'config_name,config_value',
|
|
|
|
"config_name LIKE 'ldap%' OR config_name LIKE 'account_%' OR config_name LIKE '%encryption%' OR config_name='auth_type'",__LINE__,__FILE__);
|
|
|
|
while(($row = $this->db->row(true)))
|
2003-12-29 22:05:06 +01:00
|
|
|
{
|
2006-06-08 01:10:06 +02:00
|
|
|
if (!isset($GLOBALS['egw_info']['server'][$row['config_name']])) // dont overwrite
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['server'][$row['config_name']] = $row['config_value'];
|
|
|
|
}
|
2003-12-29 22:05:06 +01:00
|
|
|
}
|
2006-06-08 01:10:06 +02:00
|
|
|
if (!is_object($GLOBALS['egw']))
|
2003-12-29 22:05:06 +01:00
|
|
|
{
|
2005-07-20 14:46:59 +02:00
|
|
|
$GLOBALS['egw'] =& new egw_dummy();
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['phpgw'] =& $GLOBALS['egw'];
|
2003-12-29 22:05:06 +01:00
|
|
|
}
|
2005-03-24 14:15:12 +01:00
|
|
|
$GLOBALS['egw']->db = clone($this->db);
|
|
|
|
$GLOBALS['egw']->common =& CreateObject('phpgwapi.common');
|
|
|
|
$GLOBALS['egw']->accounts =& CreateObject('phpgwapi.accounts');
|
2003-12-29 22:05:06 +01:00
|
|
|
|
2005-03-04 13:40:28 +01:00
|
|
|
if(($GLOBALS['egw_info']['server']['account_repository'] == 'ldap') &&
|
|
|
|
!$GLOBALS['egw']->accounts->ds)
|
2003-12-29 22:05:06 +01:00
|
|
|
{
|
2005-03-04 13:40:28 +01:00
|
|
|
printf("<b>Error: Error connecting to LDAP server %s!</b><br>",$GLOBALS['egw_info']['server']['ldap_host']);
|
2007-05-08 13:44:43 +02:00
|
|
|
return false;
|
2003-12-29 22:05:06 +01:00
|
|
|
}
|
|
|
|
}
|
2007-05-08 13:44:43 +02:00
|
|
|
return true;
|
2003-12-29 22:05:06 +01:00
|
|
|
}
|
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* add an user account or a user group
|
|
|
|
*
|
|
|
|
* if the $username already exists, only the id is returned, no new user / group gets created
|
|
|
|
*
|
2006-05-29 04:56:16 +02:00
|
|
|
* @param string $username alphanumerical username or groupname (account_lid)
|
|
|
|
* @param string $first first name
|
|
|
|
* @param string $last last name
|
2005-03-24 14:15:12 +01:00
|
|
|
* @param $passwd string cleartext pw
|
2006-07-09 19:23:35 +02:00
|
|
|
* @param string/boolean $primary_group Groupname for users primary group or False for a group, default 'Default'
|
|
|
|
* @param boolean $changepw user has right to change pw, default False = Pw change NOT allowed
|
2006-05-29 04:56:16 +02:00
|
|
|
* @param string $email
|
|
|
|
* @return int the numerical user-id
|
2005-03-24 14:15:12 +01:00
|
|
|
*/
|
2006-07-09 19:23:35 +02:00
|
|
|
function add_account($username,$first,$last,$passwd,$primary_group='Default',$changepw=False,$email='')
|
2003-12-29 22:05:06 +01:00
|
|
|
{
|
|
|
|
$this->setup_account_object();
|
|
|
|
|
2006-07-09 19:23:35 +02:00
|
|
|
$primary_group_id = $primary_group ? $GLOBALS['egw']->accounts->name2id($primary_group) : False;
|
2003-12-29 22:05:06 +01:00
|
|
|
|
2005-03-04 13:40:28 +01:00
|
|
|
if(!($accountid = $GLOBALS['egw']->accounts->name2id($username)))
|
2003-12-29 22:05:06 +01:00
|
|
|
{
|
2006-06-08 23:11:07 +02:00
|
|
|
$account = array(
|
2006-07-09 19:23:35 +02:00
|
|
|
'account_type' => $primary_group ? 'u' : 'g',
|
2003-12-29 22:05:06 +01:00
|
|
|
'account_lid' => $username,
|
|
|
|
'account_passwd' => $passwd,
|
|
|
|
'account_firstname' => $first,
|
|
|
|
'account_lastname' => $last,
|
|
|
|
'account_status' => 'A',
|
2006-07-09 19:23:35 +02:00
|
|
|
'account_primary_group' => $primary_group_id,
|
2006-05-29 04:56:16 +02:00
|
|
|
'account_expires' => -1,
|
|
|
|
'account_email' => $email,
|
2007-03-19 10:53:03 +01:00
|
|
|
'account_members' => ''
|
2006-06-08 23:11:07 +02:00
|
|
|
);
|
|
|
|
if (!($accountid = $GLOBALS['egw']->accounts->save($account)))
|
2006-06-07 01:44:50 +02:00
|
|
|
{
|
2006-07-09 19:23:35 +02:00
|
|
|
error_log("setup::add_account('$username','$first','$last',\$passwd,'$primary_group',$changepw,'$email') failed! accountid=$accountid");
|
2006-06-07 01:44:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2006-07-09 19:23:35 +02:00
|
|
|
if ($primary_group) // only for users, NOT groups
|
2003-12-29 22:05:06 +01:00
|
|
|
{
|
2006-07-09 19:23:35 +02:00
|
|
|
$memberships = $GLOBALS['egw']->accounts->memberships($accountid,true);
|
|
|
|
|
|
|
|
if($primary_group_id && !in_array($primary_group_id,$memberships))
|
|
|
|
{
|
|
|
|
$memberships[] = $primary_group_id;
|
|
|
|
|
|
|
|
$GLOBALS['egw']->accounts->set_memberships($memberships,$accountid);
|
|
|
|
}
|
|
|
|
if (!$changepw) $this->add_acl('preferences','nopasswordchange',$accountid);
|
2003-12-29 22:05:06 +01:00
|
|
|
}
|
2006-07-09 19:23:35 +02:00
|
|
|
error_log("setup::add_account('$username','$first','$last',\$passwd,'$primary_group',$changepw,'$email') successfull created accountid=$accountid");
|
2003-12-29 22:05:06 +01:00
|
|
|
return $accountid;
|
|
|
|
}
|
2005-10-15 09:57:06 +02:00
|
|
|
|
2006-06-07 01:44:50 +02:00
|
|
|
/**
|
|
|
|
* Set the memberships of an account
|
|
|
|
*
|
|
|
|
* @param array $groups array of group-id's
|
|
|
|
* @param int $user account_id
|
|
|
|
*/
|
|
|
|
function set_memberships($groups,$user)
|
|
|
|
{
|
|
|
|
$this->setup_account_object();
|
|
|
|
|
|
|
|
return $GLOBALS['egw']->accounts->set_memberships($groups,$user);
|
|
|
|
}
|
|
|
|
|
2005-10-15 09:57:06 +02:00
|
|
|
/**
|
|
|
|
* Check if accounts other then the automatically installed anonymous account exist
|
|
|
|
*
|
|
|
|
* We check via the account object, to deal with different account-storages
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function accounts_exist()
|
|
|
|
{
|
2007-05-08 13:44:43 +02:00
|
|
|
if (!$this->setup_account_object()) return false;
|
2005-10-15 09:57:06 +02:00
|
|
|
|
|
|
|
$accounts = $GLOBALS['egw']->accounts->search(array(
|
|
|
|
'type' => 'accounts',
|
|
|
|
'start' => 0,
|
2007-03-19 10:53:03 +01:00
|
|
|
'offset' => 2 // we only need to check 2 accounts, if we just check for not anonymous
|
2005-10-15 09:57:06 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
if (!$accounts || !is_array($accounts) || !count($accounts))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
foreach($accounts as $account)
|
|
|
|
{
|
|
|
|
if ($account['account_lid'] != 'anonymous')
|
|
|
|
{
|
|
|
|
// we might add further checks, eg. if the account really has admin rights here
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2003-12-29 22:05:06 +01:00
|
|
|
|
2005-03-24 14:15:12 +01:00
|
|
|
/**
|
|
|
|
* Add ACL rights
|
|
|
|
*
|
2006-06-07 01:44:50 +02:00
|
|
|
* Dont use it to set group-membership, use set_memberships instead!
|
|
|
|
*
|
2005-03-24 14:15:12 +01:00
|
|
|
* @param $app string/array with app-names
|
|
|
|
* @param $locations string eg. run
|
|
|
|
* @param $account int/string accountid or account_lid
|
|
|
|
* @param $rights int rights to set, default 1
|
|
|
|
*/
|
2003-12-29 22:05:06 +01:00
|
|
|
function add_acl($apps,$location,$account,$rights=1)
|
|
|
|
{
|
2006-07-09 19:23:35 +02:00
|
|
|
error_log("setup::add_acl(".(is_array($apps) ? "array('".implode("','",$apps)."')" : "'$apps'").",'$location',$account,$rights)");
|
|
|
|
if (!is_numeric($account))
|
2003-12-29 22:05:06 +01:00
|
|
|
{
|
|
|
|
$this->setup_account_object();
|
2005-03-04 13:40:28 +01:00
|
|
|
$account = $GLOBALS['egw']->accounts->name2id($account);
|
2003-12-29 22:05:06 +01:00
|
|
|
}
|
2004-02-05 02:35:53 +01:00
|
|
|
if(!is_object($this->db))
|
|
|
|
{
|
|
|
|
$this->loaddb();
|
|
|
|
}
|
2003-12-29 22:05:06 +01:00
|
|
|
|
2004-02-05 02:35:53 +01:00
|
|
|
if(!is_array($apps))
|
|
|
|
{
|
|
|
|
$apps = array($apps);
|
|
|
|
}
|
2003-12-29 22:05:06 +01:00
|
|
|
foreach($apps as $app)
|
|
|
|
{
|
2005-11-04 19:35:09 +01:00
|
|
|
$this->db->delete($this->acl_table,array(
|
|
|
|
'acl_appname' => $app,
|
|
|
|
'acl_location' => $location,
|
2007-03-19 10:53:03 +01:00
|
|
|
'acl_account' => $account
|
2005-11-04 19:35:09 +01:00
|
|
|
),__LINE__,__FILE__);
|
|
|
|
|
|
|
|
if ((int) $rights)
|
2004-02-23 14:22:59 +01:00
|
|
|
{
|
2005-11-04 19:35:09 +01:00
|
|
|
$this->db->insert($this->acl_table,array(
|
|
|
|
'acl_rights' => $rights
|
|
|
|
),array(
|
|
|
|
'acl_appname' => $app,
|
|
|
|
'acl_location' => $location,
|
|
|
|
'acl_account' => $account,
|
|
|
|
),__LINE__,__FILE__);
|
2005-11-02 12:45:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checks if one of the given tables exist, returns the first match
|
|
|
|
*
|
|
|
|
* @param array $tables array with possible table-names
|
|
|
|
* @return string/boolean tablename or false
|
|
|
|
*/
|
2006-01-06 17:21:51 +01:00
|
|
|
function table_exist($tables,$force_refresh=False)
|
2005-11-02 12:45:52 +01:00
|
|
|
{
|
2006-01-06 17:21:51 +01:00
|
|
|
static $table_names = False;
|
2005-11-02 12:45:52 +01:00
|
|
|
|
2006-01-06 17:21:51 +01:00
|
|
|
if (!$table_names || $force_refresh) $table_names = $this->db->table_names();
|
2005-11-02 12:45:52 +01:00
|
|
|
|
|
|
|
if (!$table_names) return false;
|
|
|
|
|
|
|
|
foreach($table_names as $data)
|
|
|
|
{
|
|
|
|
if (($key = array_search($data['table_name'],$tables)) !== false)
|
|
|
|
{
|
|
|
|
return $tables[$key];
|
2004-02-23 14:22:59 +01:00
|
|
|
}
|
2003-12-29 22:05:06 +01:00
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks and set the names of the tables, which get accessed before an update: eg. config- and applications-table
|
|
|
|
*
|
|
|
|
* Other tables can always use the most up to date name
|
|
|
|
*/
|
2006-01-06 17:21:51 +01:00
|
|
|
function set_table_names($force_refresh=False)
|
2005-11-02 12:45:52 +01:00
|
|
|
{
|
|
|
|
foreach(array(
|
|
|
|
'config_table' => array('egw_config','phpgw_config','config'),
|
|
|
|
'applications_table' => array('egw_applications','phpgw_applications','applications'),
|
2006-01-06 17:21:51 +01:00
|
|
|
'accounts_table' => array('egw_accounts','phpgw_accounts'),
|
|
|
|
'acl_table' => array('egw_acl','phpgw_acl'),
|
2005-11-02 12:45:52 +01:00
|
|
|
'lang_table' => array('egw_lang','phpgw_lang','lang'),
|
|
|
|
'languages_table' => array('egw_languages','phpgw_languages','languages'),
|
|
|
|
) as $name => $tables)
|
|
|
|
{
|
2006-01-06 17:21:51 +01:00
|
|
|
$table = $this->table_exist($tables,$force_refresh);
|
2005-11-04 19:35:09 +01:00
|
|
|
|
|
|
|
if ($table && $table != $this->$name) // only overwrite the default name, if we realy got one (important for new installs)
|
|
|
|
{
|
|
|
|
$this->$name = $table;
|
|
|
|
}
|
2005-11-02 12:45:52 +01:00
|
|
|
//echo "<p>setup::set_table_names: $name = '{$this->$name}'</p>\n";
|
|
|
|
}
|
2003-12-29 22:05:06 +01:00
|
|
|
}
|
2002-03-03 22:47:30 +01:00
|
|
|
}
|