2006-05-28 02:55:41 +02:00
|
|
|
<?php
|
2006-05-29 04:56:16 +02:00
|
|
|
/**
|
|
|
|
* Setup - Manage the eGW config file header.inc.php
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package setup
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @author Miles Lott <milos@groupwhere.org>
|
|
|
|
* @author Tony Puglisi (Angles)
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2006-05-28 02:55:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to manage the eGW config file header.inc.php
|
2008-10-09 19:08:52 +02:00
|
|
|
*
|
2006-05-28 02:55:41 +02:00
|
|
|
* Used by manageheader.php and the new setup command line interface setup-cli.php
|
|
|
|
*
|
|
|
|
* @package setup
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
class setup_header
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array with php-extension / ADOdb drive names => describtiv label
|
|
|
|
*/
|
|
|
|
var $db_fullnames = array(
|
2013-05-26 11:32:41 +02:00
|
|
|
'mysqli' => 'MySQLi (recommended, incl. transactions)',
|
|
|
|
'mysql' => 'MySQL (deprecated)',
|
|
|
|
'mysqlt' => 'MySQL (deprecated, transactions)',
|
2006-05-28 02:55:41 +02:00
|
|
|
'pgsql' => 'PostgreSQL',
|
|
|
|
'mssql' => 'MS SQL Server',
|
|
|
|
'odbc_mssql' => 'MS SQL Server via ODBC',
|
|
|
|
'oracle' => 'Oracle',
|
|
|
|
'odbc_oracle' => 'Oracle via ODBC',
|
|
|
|
'sapdb' => 'SAP/Max DB via ODBC',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array with php-extension / ADOdb drive names => default port used by database
|
|
|
|
*/
|
|
|
|
var $default_db_ports = array(
|
|
|
|
'pgsql' => 5432,
|
|
|
|
'mysql' => 3306,
|
|
|
|
'mysqli' => 3306,
|
2008-09-27 08:56:36 +02:00
|
|
|
'mysqlt' => 3306,
|
2006-05-28 02:55:41 +02:00
|
|
|
'mssql' => 1433,
|
|
|
|
'odbc_mssql' => '',
|
|
|
|
'oracle' => 1521,
|
|
|
|
'odbc_oracle' => '',
|
|
|
|
'sapdb' => '',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detect settings or set defaults for the header.inc.php file (used if it does not yet exist)
|
2008-10-09 19:08:52 +02:00
|
|
|
*
|
2006-05-28 02:55:41 +02:00
|
|
|
* Sets $GLOBALS['egw_info'], $GLOBALS['egw_domains'] and the defines EGW_SERVER_ROOT and EGW_INCLUDE_ROOT,
|
|
|
|
* as if the header has been included
|
2008-10-09 19:08:52 +02:00
|
|
|
*
|
2006-05-28 02:55:41 +02:00
|
|
|
* @param string $domain='default' domain to set
|
|
|
|
*/
|
|
|
|
function defaults($domain='default')
|
|
|
|
{
|
|
|
|
$egw_root = realpath(dirname(__FILE__).'/../..');
|
|
|
|
$GLOBALS['egw_info']['server']['server_root'] = $GLOBALS['egw_info']['server']['include_root'] = $egw_root;
|
|
|
|
define('EGW_SERVER_ROOT',$egw_root); // this is usally already defined by setup and cant be changed
|
|
|
|
define('EGW_INCLUDE_ROOT',$egw_root);
|
2008-10-09 19:08:52 +02:00
|
|
|
|
2006-05-28 02:55:41 +02:00
|
|
|
$GLOBALS['egw_info']['server']['header_admin_user'] = 'admin';
|
|
|
|
$GLOBALS['egw_info']['server']['header_admin_password'] = '';
|
|
|
|
$GLOBALS['egw_info']['server']['setup_acl'] = '';
|
|
|
|
|
|
|
|
if ($domain) $GLOBALS['egw_domain'][$domain] = $this->domain_defaults();
|
2008-10-09 19:08:52 +02:00
|
|
|
|
2006-05-28 02:55:41 +02:00
|
|
|
$GLOBALS['egw_info']['server']['show_domain_selectbox'] = false;
|
|
|
|
$GLOBALS['egw_info']['server']['db_persistent'] = True;
|
|
|
|
$GLOBALS['egw_info']['login_template_set'] = 'idots';
|
|
|
|
$GLOBALS['egw_info']['server']['mcrypt_enabled'] = False;
|
|
|
|
$GLOBALS['egw_info']['server']['versions']['mcrypt'] = '';
|
|
|
|
$GLOBALS['egw_info']['server']['mcrypt_iv'] = $this->generate_mcyrpt_iv();
|
|
|
|
}
|
2008-10-09 19:08:52 +02:00
|
|
|
|
2006-05-28 02:55:41 +02:00
|
|
|
function domain_defaults($user='admin',$passwd='',$supported_db=null)
|
|
|
|
{
|
|
|
|
if (is_null($supported_db)) $supported_db = $this->check_db_support($null);
|
2013-05-26 11:32:41 +02:00
|
|
|
$default_db = count($supported_db) ? $supported_db[0] : 'mysqli';
|
2006-05-28 02:55:41 +02:00
|
|
|
|
|
|
|
return array(
|
|
|
|
'db_host' => 'localhost',
|
|
|
|
'db_port' => $this->default_db_ports[$default_db],
|
|
|
|
'db_name' => 'egroupware',
|
|
|
|
'db_user' => 'egroupware',
|
|
|
|
'db_pass' => '',
|
|
|
|
'db_type' => $default_db,
|
|
|
|
'config_user' => $user,
|
|
|
|
'config_passwd' => $passwd,
|
|
|
|
);
|
|
|
|
}
|
2008-10-09 19:08:52 +02:00
|
|
|
|
2006-05-28 02:55:41 +02:00
|
|
|
/**
|
|
|
|
* Checks the values of the (included) header.inc.php file
|
2008-10-09 19:08:52 +02:00
|
|
|
*
|
2006-05-28 02:55:41 +02:00
|
|
|
* The values are set in $GLOBALS['egw_info'], $GLOBALS['egw_domain'] and EGW_SERVER_ROOT
|
|
|
|
*
|
|
|
|
* @return array with errors or null if no errors
|
|
|
|
*/
|
2008-10-09 19:08:52 +02:00
|
|
|
function validation_errors($path=EGW_SERVER_ROOT)
|
2006-05-28 02:55:41 +02:00
|
|
|
{
|
|
|
|
$errors = null;
|
|
|
|
|
2008-10-09 19:08:52 +02:00
|
|
|
if (!is_dir($path) || !is_readable($path) || !is_dir($path.'/phpgwapi'))
|
2006-05-28 02:55:41 +02:00
|
|
|
{
|
2008-10-09 19:08:52 +02:00
|
|
|
$errors[] = lang("%1 '%2' does NOT exist, is not readable by the webserver or contains no eGroupWare installation!",lang('Server root'),$path);
|
2006-05-28 02:55:41 +02:00
|
|
|
}
|
|
|
|
if(!$GLOBALS['egw_info']['server']['header_admin_password'])
|
|
|
|
{
|
|
|
|
$errors[] = lang("You didn't enter a header admin password");
|
|
|
|
}
|
|
|
|
if(!$GLOBALS['egw_info']['server']['header_admin_user'])
|
|
|
|
{
|
|
|
|
$errors[] = lang("You didn't enter a header admin username");
|
|
|
|
}
|
|
|
|
if (!is_array($GLOBALS['egw_domain']) || !count($GLOBALS['egw_domain']))
|
|
|
|
{
|
|
|
|
$errors[] = lang('You need to add at least one eGroupWare domain / database instance.');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach($GLOBALS['egw_domain'] as $domain => $data)
|
|
|
|
{
|
|
|
|
if (!$data['config_passwd'])
|
|
|
|
{
|
|
|
|
$errors[] = lang("You didn't enter a config password for domain %1",$domain);
|
|
|
|
}
|
|
|
|
if(!$data['config_user'])
|
|
|
|
{
|
|
|
|
$errors[] = lang("You didn't enter a config username for domain %1",$domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $errors;
|
|
|
|
}
|
2008-10-09 19:08:52 +02:00
|
|
|
|
2006-05-28 02:55:41 +02:00
|
|
|
/**
|
|
|
|
* generate header.inc.php file from given values
|
|
|
|
*
|
2006-06-03 16:45:49 +02:00
|
|
|
* setup_header::generate($GLOBALS['egw_info'],$GLOBALS['egw_domains'])
|
2006-05-28 02:55:41 +02:00
|
|
|
* should write an identical header.inc.php as the one include
|
2008-10-09 19:08:52 +02:00
|
|
|
*
|
2006-05-28 02:55:41 +02:00
|
|
|
* @param array $egw_info usual content (in server key) plus keys server_root and include_root
|
|
|
|
* @param array $egw_domains info about the existing eGW domains / DB instances
|
|
|
|
* @return string content of header.inc.php
|
|
|
|
*/
|
|
|
|
function generate($egw_info,$egw_domain)
|
|
|
|
{
|
2007-12-09 09:03:56 +01:00
|
|
|
$tpl =& CreateObject('phpgwapi.Template','../');
|
2006-05-28 02:55:41 +02:00
|
|
|
$tpl->set_file(array('header' => 'header.inc.php.template'));
|
|
|
|
$tpl->set_block('header','domain','domain');
|
|
|
|
|
|
|
|
foreach($egw_domain as $domain => $data)
|
|
|
|
{
|
|
|
|
$var = array('DB_DOMAIN' => $domain);
|
|
|
|
foreach($data as $name => $value)
|
|
|
|
{
|
|
|
|
if ($name == 'db_port' && !$value) $value = $this->default_db_ports[$data['db_type']];
|
|
|
|
if ($name == 'config_passwd')
|
|
|
|
{
|
|
|
|
$var['CONFIG_PASS'] = $this->is_md5($value) ? $value : md5($value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$var[strtoupper($name)] = addslashes($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$tpl->set_var($var);
|
|
|
|
$tpl->parse('domains','domain',True);
|
|
|
|
}
|
|
|
|
$tpl->set_var('domain','');
|
2008-10-09 19:08:52 +02:00
|
|
|
|
2006-05-28 02:55:41 +02:00
|
|
|
$var = Array();
|
|
|
|
foreach($egw_info['server'] as $name => $value)
|
|
|
|
{
|
|
|
|
if ($name == 'header_admin_password' && !$this->is_md5($value)) $value = md5($value);
|
|
|
|
if ($name == 'versions')
|
|
|
|
{
|
|
|
|
$name = 'mcrypt_version';
|
|
|
|
$value = $value['mcrypt'];
|
|
|
|
}
|
|
|
|
static $bools = array(
|
|
|
|
'mcrypt_enabled' => 'ENABLE_MCRYPT',
|
|
|
|
'db_persistent' => 'db_persistent',
|
|
|
|
'show_domain_selectbox' => 'DOMAIN_SELECTBOX',
|
|
|
|
);
|
|
|
|
if (isset($bools[$name]))
|
|
|
|
{
|
|
|
|
$name = $bools[$name];
|
|
|
|
$value = $value ? 'true' : 'false';
|
|
|
|
}
|
|
|
|
$var[strtoupper($name)] = addslashes($value);
|
|
|
|
}
|
|
|
|
$tpl->set_var($var);
|
|
|
|
|
|
|
|
return $tpl->parse('out','header');
|
|
|
|
}
|
2008-10-09 19:08:52 +02:00
|
|
|
|
2006-05-28 02:55:41 +02:00
|
|
|
/**
|
|
|
|
* Gernerate a random mcrypt_iv vector
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function generate_mcyrpt_iv()
|
|
|
|
{
|
|
|
|
srand((double)microtime()*1000000);
|
|
|
|
$random_char = array(
|
|
|
|
'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f',
|
|
|
|
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
|
|
|
|
'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L',
|
|
|
|
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
|
|
|
|
);
|
|
|
|
|
|
|
|
$iv = '';
|
|
|
|
for($i=0; $i<30; $i++)
|
|
|
|
{
|
|
|
|
$iv .= $random_char[rand(1,count($random_char))];
|
|
|
|
}
|
|
|
|
return $iv;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_db_support(&$detected)
|
|
|
|
{
|
|
|
|
$supported_db = $detected = array();
|
|
|
|
foreach(array(
|
|
|
|
// short => array(extension,func_to_check,supported_db(s))
|
2006-06-28 18:50:05 +02:00
|
|
|
'mysqli' => array('mysql','mysqli_connect','mysqli'),
|
2013-05-26 11:32:41 +02:00
|
|
|
'mysql' => array('mysql','mysql_connect','mysql'),
|
2008-09-27 08:56:36 +02:00
|
|
|
'mysqlt' => array('mysql','mysql_connect','mysqlt'),
|
2006-05-28 02:55:41 +02:00
|
|
|
'pgsql' => array('pgsql','pg_connect','pgsql'),
|
|
|
|
'mssql' => array('mssql','mssql_connect','mssql'),
|
|
|
|
'odbc' => array('odbc',false,'sapdb','odbc_mssql','odbc_oracle'),
|
|
|
|
'oracle' => array('oci8',false,'oracle'),
|
|
|
|
) as $db => $data)
|
|
|
|
{
|
|
|
|
$ext = array_shift($data);
|
|
|
|
$func_to_check = array_shift($data);
|
|
|
|
$name = isset($this->db_fullnames[$db]) ? $this->db_fullnames[$db] : strtoupper($db);
|
2009-04-20 14:43:44 +02:00
|
|
|
if (check_load_extension($ext) || $func_to_check && function_exists($func_to_check))
|
2006-05-28 02:55:41 +02:00
|
|
|
{
|
|
|
|
$detected[] = lang('You appear to have %1 support.',$name);
|
|
|
|
$supported_db = array_merge($supported_db,$data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$detected[] .= lang('No %1 support found. Disabling',$name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $supported_db;
|
|
|
|
}
|
2008-10-09 19:08:52 +02:00
|
|
|
|
2008-09-27 08:56:36 +02:00
|
|
|
static function is_md5($str)
|
2006-05-28 02:55:41 +02:00
|
|
|
{
|
|
|
|
return preg_match('/^[0-9a-f]{32}$/',$str);
|
|
|
|
}
|
2008-10-09 19:08:52 +02:00
|
|
|
}
|
2006-05-28 02:55:41 +02:00
|
|
|
|
|
|
|
// some constanst for pre php4.3
|
|
|
|
if (!defined('PHP_SHLIB_SUFFIX'))
|
|
|
|
{
|
|
|
|
define('PHP_SHLIB_SUFFIX',strtoupper(substr(PHP_OS, 0,3)) == 'WIN' ? 'dll' : 'so');
|
|
|
|
}
|
|
|
|
if (!defined('PHP_SHLIB_PREFIX'))
|
|
|
|
{
|
|
|
|
define('PHP_SHLIB_PREFIX',PHP_SHLIB_SUFFIX == 'dll' ? 'php_' : '');
|
|
|
|
}
|