2001-07-30 17:59:25 +02:00
|
|
|
<?php
|
2008-08-20 08:04:28 +02:00
|
|
|
/**
|
2016-05-01 17:56:49 +02:00
|
|
|
* EGroupWare Setup - System configuration
|
2008-08-20 08:04:28 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package setup
|
|
|
|
* @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$
|
|
|
|
*/
|
|
|
|
|
2016-03-05 15:02:13 +01:00
|
|
|
use EGroupware\Api;
|
2016-05-01 17:56:49 +02:00
|
|
|
use EGroupware\Api\Framework;
|
2016-03-05 15:02:13 +01:00
|
|
|
|
2008-08-20 08:04:28 +02:00
|
|
|
include('./inc/functions.inc.php');
|
|
|
|
|
|
|
|
/*
|
|
|
|
Authorize the user to use setup app and load the database
|
|
|
|
Does not return unless user is authorized
|
|
|
|
*/
|
|
|
|
if(!$GLOBALS['egw_setup']->auth('Config') || @$_POST['cancel'])
|
|
|
|
{
|
|
|
|
Header('Location: index.php');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup');
|
2016-05-01 17:56:49 +02:00
|
|
|
$setup_tpl = new Framework\Template($tpl_root);
|
2008-08-20 08:04:28 +02:00
|
|
|
|
|
|
|
$setup_tpl->set_file(array(
|
|
|
|
'T_head' => 'head.tpl',
|
|
|
|
'T_footer' => 'footer.tpl',
|
|
|
|
'T_alert_msg' => 'msg_alert_msg.tpl',
|
|
|
|
'T_config_pre_script' => 'config_pre_script.tpl',
|
|
|
|
'T_config_post_script' => 'config_post_script.tpl'
|
|
|
|
));
|
2016-05-01 17:56:49 +02:00
|
|
|
$setup_tpl->set_var('hidden_vars', Api\Html::input_hidden('csrf_token', Api\Csrf::token(__FILE__)));
|
2014-05-01 08:26:09 +02:00
|
|
|
|
|
|
|
// check CSRF token for POST requests with any content (setup uses empty POST to call it's modules!)
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST)
|
|
|
|
{
|
2016-03-05 15:02:13 +01:00
|
|
|
Api\Csrf::validate($_POST['csrf_token'], __FILE__);
|
2014-05-01 08:26:09 +02:00
|
|
|
}
|
2008-08-20 08:04:28 +02:00
|
|
|
|
|
|
|
/* Following to ensure windows file paths are saved correctly */
|
|
|
|
$GLOBALS['egw_setup']->loaddb();
|
|
|
|
|
|
|
|
/* Check api version, use correct table */
|
|
|
|
$setup_info = $GLOBALS['egw_setup']->detection->get_db_versions();
|
|
|
|
|
|
|
|
$newsettings = $_POST['newsettings'];
|
|
|
|
|
2016-05-03 00:26:40 +02:00
|
|
|
if(@$_POST['submit'] && @$newsettings)
|
2008-08-20 08:04:28 +02:00
|
|
|
{
|
|
|
|
/* Load hook file with functions to validate each config (one/none/all) */
|
|
|
|
$GLOBALS['egw_setup']->hook('config_validate','setup');
|
|
|
|
|
2020-05-28 23:23:54 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// allow apps to register hooks throwing Exceptions for errors
|
|
|
|
Api\Hooks::process([
|
|
|
|
'location' => 'setup_config',
|
|
|
|
'newsettings' => &$newsettings,
|
|
|
|
], [], true);
|
|
|
|
}
|
|
|
|
catch (\Exception $e) {
|
|
|
|
$GLOBALS['error'] .= '<b>'.$e->getMessage()."</b><br />\n";
|
|
|
|
}
|
|
|
|
|
2016-02-01 13:50:34 +01:00
|
|
|
$newsettings['tz_offset'] = date('Z')/3600;
|
2001-11-15 00:17:27 +01:00
|
|
|
|
2008-08-20 08:04:28 +02:00
|
|
|
$GLOBALS['egw_setup']->db->transaction_begin();
|
|
|
|
foreach($newsettings as $setting => $value)
|
2001-07-30 17:59:25 +02:00
|
|
|
{
|
2014-04-23 16:36:08 +02:00
|
|
|
if(in_array($setting, (array)$GLOBALS['egw_info']['server']['found_validation_hook']) && function_exists($setting))
|
2002-08-14 01:39:39 +02:00
|
|
|
{
|
2008-08-20 08:04:28 +02:00
|
|
|
$setting($newsettings);
|
|
|
|
if($GLOBALS['config_error'])
|
|
|
|
{
|
|
|
|
$GLOBALS['error'] .= '<b>'.$GLOBALS['config_error'] ."</b><br />\n";
|
|
|
|
$GLOBALS['config_error'] = '';
|
|
|
|
/* Bail out, stop writing config data */
|
2002-08-14 01:39:39 +02:00
|
|
|
break;
|
2008-08-20 08:04:28 +02:00
|
|
|
}
|
|
|
|
$value = $newsettings[$setting]; // it might be changed by the validation hook
|
2002-08-14 01:39:39 +02:00
|
|
|
}
|
2008-08-20 08:04:28 +02:00
|
|
|
/* Don't erase passwords, since we also do not print them below */
|
2014-07-04 14:43:11 +02:00
|
|
|
if(!empty($value) || !(stristr($setting,'passwd') || stristr($setting,'password') || stristr($setting,'root_pw')))
|
2001-07-30 17:59:25 +02:00
|
|
|
{
|
2016-03-05 15:02:13 +01:00
|
|
|
Api\Config::save_value($setting, $value, 'phpgwapi');
|
2001-07-30 17:59:25 +02:00
|
|
|
}
|
|
|
|
}
|
2008-08-20 08:04:28 +02:00
|
|
|
if(!$GLOBALS['error'])
|
2001-07-30 17:59:25 +02:00
|
|
|
{
|
2008-08-20 08:04:28 +02:00
|
|
|
$GLOBALS['egw_setup']->db->transaction_commit();
|
2011-09-13 11:25:25 +02:00
|
|
|
// unset cached config, as this is the primary source for configuration now
|
2016-04-05 18:51:43 +02:00
|
|
|
Api\Cache::unsetInstance('config', 'configs');
|
2008-08-20 08:04:28 +02:00
|
|
|
|
|
|
|
Header('Location: index.php');
|
|
|
|
exit;
|
2006-03-08 10:41:53 +01:00
|
|
|
}
|
2008-08-20 08:04:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$GLOBALS['egw_setup']->html->show_header(lang('Configuration'),False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')');
|
|
|
|
|
2023-07-06 15:50:53 +02:00
|
|
|
$current_config = [];
|
2008-08-20 08:04:28 +02:00
|
|
|
// if we have an validation error, use the new settings made by the user and not the stored config
|
|
|
|
if($GLOBALS['error'] && is_array($newsettings))
|
|
|
|
{
|
2023-07-06 15:50:53 +02:00
|
|
|
$current_config = $newsettings;
|
2008-08-20 08:04:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-06 07:25:42 +01:00
|
|
|
foreach($GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'*',false,__LINE__,__FILE__) as $row)
|
2006-03-08 10:41:53 +01:00
|
|
|
{
|
2023-07-06 15:50:53 +02:00
|
|
|
$current_config[$row['config_name']] = $row['config_value'];
|
2001-07-30 17:59:25 +02:00
|
|
|
}
|
2023-11-17 09:17:29 +01:00
|
|
|
// migrate old fallback types to auth_fallback="True"
|
|
|
|
switch ($current_config['auth_type'])
|
|
|
|
{
|
|
|
|
case 'fallback':
|
|
|
|
$current_config['auth_type'] = 'ldap';
|
|
|
|
$current_config['auth_fallback'] = 'True';
|
|
|
|
break;
|
|
|
|
case 'fallbackmail2sql':
|
|
|
|
$current_config['auth_type'] = 'mail';
|
|
|
|
$current_config['auth_fallback'] = 'True';
|
|
|
|
break;
|
|
|
|
case 'fallbackads2sql':
|
|
|
|
case 'fallbackad2sql':
|
|
|
|
$current_config['auth_type'] = 'ads';
|
|
|
|
$current_config['auth_fallback'] = 'True';
|
|
|
|
break;
|
|
|
|
}
|
2008-08-20 08:04:28 +02:00
|
|
|
}
|
|
|
|
$setup_tpl->pparse('out','T_config_pre_script');
|
|
|
|
|
|
|
|
/* Now parse each of the templates we want to show here */
|
2023-07-06 15:50:53 +02:00
|
|
|
class egw
|
2008-08-20 08:04:28 +02:00
|
|
|
{
|
|
|
|
var $accounts;
|
|
|
|
var $applications;
|
|
|
|
var $db;
|
|
|
|
}
|
2023-07-06 15:50:53 +02:00
|
|
|
$GLOBALS['egw'] = new egw;
|
2008-08-20 08:04:28 +02:00
|
|
|
$GLOBALS['egw']->db =& $GLOBALS['egw_setup']->db;
|
|
|
|
|
2016-05-01 17:56:49 +02:00
|
|
|
$t = new Framework\Template(Framework\Template::get_dir('setup'));
|
2008-08-20 08:04:28 +02:00
|
|
|
|
|
|
|
$t->set_unknowns('keep');
|
|
|
|
$t->set_file(array('config' => 'config.tpl'));
|
|
|
|
$t->set_block('config','body','body');
|
|
|
|
|
|
|
|
$vars = $t->get_undefined('body');
|
|
|
|
$GLOBALS['egw_setup']->hook('config','setup');
|
|
|
|
|
|
|
|
foreach($vars as $value)
|
|
|
|
{
|
|
|
|
$valarray = explode('_',$value);
|
2017-02-05 14:00:20 +01:00
|
|
|
$type = array_shift($valarray);
|
|
|
|
$newval = implode(' ',$valarray);
|
2001-09-21 22:14:04 +02:00
|
|
|
|
2008-08-20 08:04:28 +02:00
|
|
|
switch ($type)
|
2004-11-28 19:38:50 +01:00
|
|
|
{
|
2008-08-20 08:04:28 +02:00
|
|
|
case 'lang':
|
|
|
|
$t->set_var($value,lang($newval));
|
|
|
|
break;
|
|
|
|
case 'value':
|
|
|
|
$newval = str_replace(' ','_',$newval);
|
|
|
|
/* Don't show passwords in the form */
|
|
|
|
if(strpos($value,'passwd') !== false || strpos($value,'password') !== false || strpos($value,'root_pw') !== false)
|
|
|
|
{
|
2004-11-28 19:38:50 +01:00
|
|
|
$t->set_var($value,'');
|
2008-08-20 08:04:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-06 15:50:53 +02:00
|
|
|
$t->set_var($value, $current_config[$newval]);
|
2008-08-20 08:04:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'selected':
|
2023-07-06 15:50:53 +02:00
|
|
|
case 'checked':
|
2008-08-20 08:04:28 +02:00
|
|
|
$newvals = explode(' ',$newval);
|
2014-07-04 20:45:22 +02:00
|
|
|
$setting = array_pop($newvals);
|
|
|
|
$config = implode('_',$newvals);
|
2024-07-19 15:15:09 +02:00
|
|
|
if (!isset($current_config[$config]))
|
|
|
|
{
|
|
|
|
$setting = array_pop($newvals).'_'.$setting;
|
|
|
|
$config = implode('_', $newvals);
|
|
|
|
}
|
2008-08-20 08:04:28 +02:00
|
|
|
/* echo $config . '=' . $current_config[$config]; */
|
2023-07-06 15:50:53 +02:00
|
|
|
if($current_config[$config] == $setting)
|
2008-08-20 08:04:28 +02:00
|
|
|
{
|
2023-07-06 15:50:53 +02:00
|
|
|
$t->set_var($value,' '.$type);
|
2008-08-20 08:04:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$t->set_var($value,'');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'hook':
|
|
|
|
$newval = str_replace(' ','_',$newval);
|
|
|
|
$t->set_var($value,$newval($current_config));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$t->set_var($value,'');
|
|
|
|
break;
|
2004-11-28 19:38:50 +01:00
|
|
|
}
|
2008-08-20 08:04:28 +02:00
|
|
|
}
|
2004-11-28 19:38:50 +01:00
|
|
|
|
2008-08-20 08:04:28 +02:00
|
|
|
if($GLOBALS['error'])
|
|
|
|
{
|
|
|
|
if($GLOBALS['error'] == 'badldapconnection')
|
2004-11-28 19:38:50 +01:00
|
|
|
{
|
2008-08-20 08:04:28 +02:00
|
|
|
/* Please check the number and dial again :) */
|
|
|
|
$GLOBALS['egw_setup']->html->show_alert_msg('Error',
|
|
|
|
lang('There was a problem trying to connect to your LDAP server. <br />'
|
|
|
|
.'please check your LDAP server configuration') . '.');
|
2004-11-28 19:38:50 +01:00
|
|
|
}
|
|
|
|
|
2008-08-20 08:04:28 +02:00
|
|
|
$GLOBALS['egw_setup']->html->show_alert_msg('Error',$GLOBALS['error'].'<p>');
|
|
|
|
}
|
|
|
|
|
|
|
|
$t->pfp('out','body');
|
|
|
|
unset($t);
|
2001-09-21 22:14:04 +02:00
|
|
|
|
2008-08-20 08:04:28 +02:00
|
|
|
$setup_tpl->set_var('more_configs',lang('Please login to egroupware and run the admin application for additional site configuration') . '.');
|
2001-07-30 17:59:25 +02:00
|
|
|
|
2008-08-20 08:04:28 +02:00
|
|
|
$setup_tpl->set_var('lang_submit',lang('Save'));
|
|
|
|
$setup_tpl->set_var('lang_cancel',lang('Cancel'));
|
|
|
|
$setup_tpl->pparse('out','T_config_post_script');
|
2002-03-03 22:53:00 +01:00
|
|
|
|
2023-07-06 15:50:53 +02:00
|
|
|
$GLOBALS['egw_setup']->html->show_footer();
|