2016-04-20 20:52:55 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGgroupware admin - New et2 site configuration
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <rb@stylite.de>
|
|
|
|
* @package admin
|
2018-08-03 11:49:40 +02:00
|
|
|
* @copyright (c) 2016-18 by Ralf Becker <rb@stylite.de>
|
2016-04-20 20:52:55 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
|
|
|
|
use EGroupware\Api;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* New site configuration for all apps using eTemplate2 $app/templates/default/config.xet
|
|
|
|
*/
|
|
|
|
class admin_config
|
|
|
|
{
|
|
|
|
var $public_functions = array('index' => True);
|
|
|
|
|
2017-04-27 16:50:19 +02:00
|
|
|
/**
|
2017-04-28 12:40:33 +02:00
|
|
|
* Upload function to store anonymous images into instance files_dir/anon_images
|
2017-04-27 16:50:19 +02:00
|
|
|
*
|
2018-05-28 15:31:32 +02:00
|
|
|
* @param array $file file info array
|
|
|
|
* @param array|string $value current value of login_background_file
|
2017-04-27 16:50:19 +02:00
|
|
|
*
|
|
|
|
*/
|
2018-05-28 15:31:32 +02:00
|
|
|
function ajax_upload_anon_images ($file, $value)
|
2017-04-27 16:50:19 +02:00
|
|
|
{
|
2018-05-28 15:31:32 +02:00
|
|
|
if (!isset($GLOBALS['egw_info']['user']['apps']['admin'])) die('no rights to be here!');
|
2017-04-28 12:40:33 +02:00
|
|
|
$path = $GLOBALS['egw_info']['server']['files_dir'].'/anon-images';
|
2017-04-27 16:50:19 +02:00
|
|
|
$success = false;
|
|
|
|
$response = Api\Json\Response::get();
|
2017-04-28 12:40:33 +02:00
|
|
|
if (is_array($file) && is_writable(dirname($path)))
|
2017-04-27 16:50:19 +02:00
|
|
|
{
|
2017-04-28 12:40:33 +02:00
|
|
|
if (!is_dir($path)) mkdir ($path);
|
2017-04-27 16:50:19 +02:00
|
|
|
$tmp_file = array_keys($file);
|
2017-04-28 12:40:33 +02:00
|
|
|
$destination = $path.'/'.$file[$tmp_file[0]]['name'];
|
2017-04-27 16:50:19 +02:00
|
|
|
$success = rename($GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmp_file[0],$destination);
|
|
|
|
}
|
|
|
|
if ($success)
|
|
|
|
{
|
2018-05-28 15:31:32 +02:00
|
|
|
$value = array_merge($value, array(
|
|
|
|
$GLOBALS['egw_info']['server']['webserver_url'].'/api/anon_images.php?src='.urlencode($file[$tmp_file[0]]['name']).'&'.filemtime($destination),
|
2017-04-27 16:50:19 +02:00
|
|
|
));
|
2018-05-28 15:31:32 +02:00
|
|
|
$response->data($value);
|
2017-04-27 16:50:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$response->error(lang('Failed to upload %1',$destination));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-28 15:31:32 +02:00
|
|
|
/**
|
|
|
|
* Removes images from anon-images directory
|
|
|
|
*
|
|
|
|
* @param type $files
|
|
|
|
*/
|
|
|
|
function remove_anon_images ($files)
|
|
|
|
{
|
|
|
|
if (!isset($GLOBALS['egw_info']['user']['apps']['admin'])) die('no rights to be here!');
|
|
|
|
if ($files)
|
|
|
|
{
|
|
|
|
$base = $GLOBALS['egw_info']['server']['files_dir'].'/anon-images';
|
|
|
|
foreach ($files as $file)
|
|
|
|
{
|
2018-08-03 11:49:40 +02:00
|
|
|
$parts2 = explode('anon_images.php?src=', $file);
|
|
|
|
$parts = explode('&', $parts2[1]);
|
2018-05-28 15:31:32 +02:00
|
|
|
$path = $base.'/'.urldecode($parts[0]);
|
|
|
|
if (is_writable(dirname($base)) && file_exists($path))
|
|
|
|
{
|
|
|
|
unlink($path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of configs
|
|
|
|
*
|
|
|
|
* @param type $_content
|
|
|
|
* @throws Api\Exception\WrongParameter
|
|
|
|
*/
|
2016-04-20 20:52:55 +02:00
|
|
|
function index($_content=null)
|
|
|
|
{
|
|
|
|
if (is_array($_content))
|
|
|
|
{
|
|
|
|
$_appname = $_content['appname'];
|
|
|
|
}
|
|
|
|
elseif (!empty($_GET['appname']) && isset($GLOBALS['egw_info']['apps'][$_GET['appname']]))
|
|
|
|
{
|
|
|
|
$_appname = $_GET['appname'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new Api\Exception\WrongParameter("Wrong or missing appname parameter!");
|
|
|
|
}
|
|
|
|
if ($GLOBALS['egw']->acl->check('site_config_acce',1,'admin'))
|
|
|
|
{
|
2016-04-21 18:39:59 +02:00
|
|
|
Api\Framework::redirect_link('/index.php');
|
2016-04-20 20:52:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// load the translations of the app we show too, so they dont need to be in admin!
|
|
|
|
if ($_appname != 'admin')
|
|
|
|
{
|
|
|
|
Api\Translation::add_app($_appname);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch($_appname)
|
|
|
|
{
|
|
|
|
case 'admin':
|
|
|
|
case 'addressbook':
|
|
|
|
case 'calendar':
|
|
|
|
case 'preferences':
|
|
|
|
$appname = $_appname;
|
|
|
|
$config_appname = 'phpgwapi';
|
|
|
|
break;
|
|
|
|
case 'phpgwapi':
|
|
|
|
case '':
|
|
|
|
/* This keeps the admin from getting into what is a setup-only config */
|
2017-10-21 12:29:46 +02:00
|
|
|
Api\Framework::redirect_link('/admin/index.php?ajax=true');
|
2016-04-20 20:52:55 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$appname = $_appname;
|
|
|
|
$config_appname = $appname;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$c = new Api\Config($config_appname);
|
2018-08-22 11:10:11 +02:00
|
|
|
$old = (array)$c->read_repository();
|
2016-04-20 20:52:55 +02:00
|
|
|
if ($_content['cancel'] || ($_content['save'] || $_content['apply']) && $GLOBALS['egw']->acl->check('site_config_acce',2,'admin'))
|
|
|
|
{
|
2016-04-21 18:39:59 +02:00
|
|
|
Api\Framework::redirect_link('/admin/index.php?ajax=true');
|
2016-04-20 20:52:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($_content['save'] || $_content['apply'])
|
|
|
|
{
|
|
|
|
// support old validation hooks
|
|
|
|
$_POST = array('newsettings' => &$_content['newsettings']);
|
|
|
|
|
2018-05-28 15:31:32 +02:00
|
|
|
// Remove actual files (cleanup) of deselected urls from login_background_file
|
2018-08-22 11:10:11 +02:00
|
|
|
$this->remove_anon_images(array_diff((array)$c->config_data['login_background_file'], $_content['newsettings']['login_background_file']));
|
2018-05-28 15:31:32 +02:00
|
|
|
|
2016-04-20 20:52:55 +02:00
|
|
|
/* Load hook file with functions to validate each config (one/none/all) */
|
2019-07-17 11:15:32 +02:00
|
|
|
$errors = Api\Hooks::single(array(
|
2016-04-20 20:52:55 +02:00
|
|
|
'location' => 'config_validate',
|
2017-10-21 12:29:46 +02:00
|
|
|
)+(array)$_content['newsettings'], $appname);
|
2019-07-22 13:02:42 +02:00
|
|
|
if (!is_string($errors)) $errors = ''; // old hooks allways return true
|
2016-04-20 20:52:55 +02:00
|
|
|
|
|
|
|
foreach($_content['newsettings'] as $key => $config)
|
|
|
|
{
|
|
|
|
if ($config)
|
|
|
|
{
|
|
|
|
$c->config_data[$key] = $config;
|
|
|
|
if (in_array($key, (array)$GLOBALS['egw_info']['server']['found_validation_hook'], true) && function_exists($key))
|
|
|
|
{
|
|
|
|
call_user_func($key, $config, $c);
|
|
|
|
if($GLOBALS['config_error'])
|
|
|
|
{
|
|
|
|
$errors .= lang($GLOBALS['config_error']) . "\n";
|
|
|
|
$GLOBALS['config_error'] = False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// don't erase passwords, since we also don't print them
|
|
|
|
elseif(strpos($key,'passwd') === false && strpos($key,'password') === false && strpos($key,'root_pw') === false)
|
|
|
|
{
|
|
|
|
unset($c->config_data[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(in_array('final_validation', (array)$GLOBALS['egw_info']['server']['found_validation_hook']) &&
|
|
|
|
function_exists('final_validation'))
|
|
|
|
{
|
|
|
|
final_validation($_content['newsettings']);
|
|
|
|
if($GLOBALS['config_error'])
|
|
|
|
{
|
|
|
|
$errors .= lang($GLOBALS['config_error']) . "\n";
|
|
|
|
$GLOBALS['config_error'] = False;
|
|
|
|
}
|
|
|
|
unset($GLOBALS['egw_info']['server']['found_validation_hook']);
|
|
|
|
}
|
|
|
|
|
2019-07-17 11:15:32 +02:00
|
|
|
// do not allow to save config, if there are errors
|
2018-08-22 12:15:42 +02:00
|
|
|
if (!$errors)
|
|
|
|
{
|
2019-07-17 11:15:32 +02:00
|
|
|
// compute real changes and their old values (null for removals)
|
|
|
|
$modifications = array_udiff_assoc($c->config_data, $old, function($a, $b)
|
|
|
|
{
|
|
|
|
return (int)($a != $b); // necessary to kope with arrays
|
|
|
|
});
|
|
|
|
$removals = array_diff(array_udiff_assoc($old, $c->config_data, function($a, $b)
|
|
|
|
{
|
|
|
|
return (int)(!empty($a) && $a != $b);
|
|
|
|
}), array(null, ''));
|
|
|
|
$set = array_merge(array_fill_keys(array_keys($removals), null), $modifications);
|
|
|
|
$old = array_filter($old, function($key) use ($set)
|
|
|
|
{
|
|
|
|
return array_key_exists($key, $set);
|
|
|
|
}, ARRAY_FILTER_USE_KEY);
|
|
|
|
if ($set)
|
|
|
|
{
|
|
|
|
$cmd = new admin_cmd_config($_appname, $set, $old,
|
|
|
|
(array)$_content['admin_cmd'], $config_appname === 'phpgwapi');
|
|
|
|
$msg = $cmd->run();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$msg = lang('Nothing to save.');
|
|
|
|
}
|
2018-08-22 12:15:42 +02:00
|
|
|
// allow apps to hook into configuration dialog to eg. save some stuff outside configuration
|
|
|
|
$_content['location'] = 'config_after_save';
|
|
|
|
Api\Hooks::single($_content, $_appname);
|
|
|
|
}
|
2016-04-20 20:52:55 +02:00
|
|
|
if(!$errors && !$_content['apply'])
|
|
|
|
{
|
2018-08-20 17:27:11 +02:00
|
|
|
Api\Framework::message($msg, 'success');
|
2016-04-21 18:39:59 +02:00
|
|
|
Api\Framework::redirect_link('/index.php', array(
|
2016-04-20 20:52:55 +02:00
|
|
|
'menuaction' => 'admin.admin_ui.index',
|
|
|
|
'ajax' => 'true'
|
|
|
|
), 'admin');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($errors)
|
|
|
|
{
|
2016-04-21 18:39:59 +02:00
|
|
|
Api\Framework::message(lang('Error') . ': ' . $errors, 'error');
|
2016-04-20 20:52:55 +02:00
|
|
|
unset($errors);
|
|
|
|
unset($GLOBALS['config_error']);
|
2019-07-17 11:15:32 +02:00
|
|
|
|
|
|
|
// keep old content on error
|
|
|
|
$config = $_content['newsettings'];
|
2016-04-20 20:52:55 +02:00
|
|
|
}
|
2019-07-17 11:15:32 +02:00
|
|
|
else
|
2016-04-20 20:52:55 +02:00
|
|
|
{
|
2019-07-17 11:15:32 +02:00
|
|
|
if ($_content['apply'])
|
|
|
|
{
|
|
|
|
Api\Framework::message($msg, 'success');
|
|
|
|
}
|
|
|
|
$config = $c->read_repository();
|
2016-04-20 20:52:55 +02:00
|
|
|
}
|
2016-04-21 18:39:59 +02:00
|
|
|
$sel_options = $readonlys = array();
|
|
|
|
// call "config" hook, allowing apps to overwrite config, eg. set default values,
|
|
|
|
// or return options in "sel_options" keys
|
|
|
|
$config['location'] = 'config';
|
2019-07-17 11:15:32 +02:00
|
|
|
// let config hook know, this is an inital call and not one after user hits [Apply] button
|
|
|
|
$config['initial-call'] = is_null($_content);
|
2016-04-21 18:39:59 +02:00
|
|
|
$ret = Api\Hooks::single($config, $appname);
|
|
|
|
if (is_array($ret))
|
|
|
|
{
|
|
|
|
if (isset($ret['sel_options'])) $sel_options = $ret['sel_options'];
|
|
|
|
$config = array_merge($config, $ret);
|
|
|
|
}
|
2016-04-20 20:52:55 +02:00
|
|
|
|
|
|
|
$tmpl = new Api\Etemplate($appname.'.config');
|
|
|
|
$path = (parse_url($tmpl->rel_path, PHP_URL_SCHEME) !== 'vfs' ? EGW_SERVER_ROOT : '').$tmpl->rel_path;
|
2016-04-21 18:39:59 +02:00
|
|
|
$content = array(
|
2018-08-20 17:27:11 +02:00
|
|
|
'tabs' => $_content['tabs'],
|
|
|
|
'tabs2' => $_content['tabs2'],
|
2016-04-21 18:39:59 +02:00
|
|
|
'template' => $appname.'.config',
|
|
|
|
'newsettings' => array(),
|
|
|
|
);
|
2016-04-20 20:52:55 +02:00
|
|
|
|
|
|
|
// for security reasons we do not send all config to client-side, but only ones mentioned in templates
|
|
|
|
$matches = null;
|
2016-12-14 19:51:58 +01:00
|
|
|
preg_match_all('/id="newsettings\[([^]]+)\]/', file_get_contents($path), $matches, PREG_PATTERN_ORDER);
|
2016-04-20 20:52:55 +02:00
|
|
|
foreach($matches[1] as $name)
|
|
|
|
{
|
2016-10-04 14:29:31 +02:00
|
|
|
$content['newsettings'][$name] = isset($config[$name]) ? $config[$name] : '';
|
2016-04-20 20:52:55 +02:00
|
|
|
}
|
|
|
|
|
2016-04-21 18:39:59 +02:00
|
|
|
// make everything readonly and remove save/apply button, if user has not rights to store config
|
|
|
|
if ($GLOBALS['egw']->acl->check('site_config_acce',2,'admin'))
|
|
|
|
{
|
|
|
|
$readonlys[__ALL__] = true;
|
|
|
|
$readonlys['cancel'] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmpl->read('admin.site-config');
|
2016-12-14 19:51:58 +01:00
|
|
|
$method = (get_called_class() == __CLASS__) ? 'admin.admin_config.index' : "$appname.".get_called_class().'.'.__FUNCTION__;
|
|
|
|
$tmpl->exec($method, $content, $sel_options, $readonlys, array('appname' => $appname));
|
2016-04-20 20:52:55 +02:00
|
|
|
}
|
|
|
|
}
|