2004-11-20 16:09:20 +01:00
|
|
|
<?php
|
2008-10-02 17:30:44 +02:00
|
|
|
/**
|
|
|
|
* Setup
|
|
|
|
*
|
|
|
|
* @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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2014-04-23 16:36:08 +02:00
|
|
|
Set global flag to indicate for which config settings we have equally named validation methods
|
2008-10-02 17:30:44 +02:00
|
|
|
*/
|
2014-04-23 16:36:08 +02:00
|
|
|
$GLOBALS['egw_info']['server']['found_validation_hook'] = array(
|
|
|
|
'vfs_storage_mode',
|
|
|
|
'temp_dir',
|
|
|
|
'files_dir',
|
|
|
|
'backup_dir',
|
|
|
|
'mcrypt_algo',
|
2014-05-17 10:00:17 +02:00
|
|
|
'ldap_search_filter',
|
|
|
|
'auth_type',
|
2014-04-23 16:36:08 +02:00
|
|
|
);
|
2008-10-02 17:30:44 +02:00
|
|
|
|
2014-05-17 10:00:17 +02:00
|
|
|
/**
|
|
|
|
* Validate different auth-types
|
|
|
|
*
|
|
|
|
* @param array $settings
|
|
|
|
*/
|
|
|
|
function auth_type($settings)
|
|
|
|
{
|
|
|
|
switch($settings['auth_type'])
|
|
|
|
{
|
|
|
|
case 'mail':
|
|
|
|
try {
|
|
|
|
check_load_extension('imap', true);
|
|
|
|
}
|
|
|
|
catch (Exception $ex)
|
|
|
|
{
|
|
|
|
$GLOBALS['config_error'] = $ex->getMessage();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
/**
|
|
|
|
* Set vfs_fstab depending from what the user selected for vfs_storage_mode
|
|
|
|
*
|
|
|
|
* @param array $settings
|
|
|
|
*/
|
|
|
|
function vfs_storage_mode($settings)
|
|
|
|
{
|
|
|
|
switch($settings['vfs_storage_mode'])
|
2004-11-20 16:09:20 +01:00
|
|
|
{
|
2008-10-02 17:30:44 +02:00
|
|
|
case 'fs':
|
|
|
|
config::save_value('vfs_fstab','','phpgwapi');
|
|
|
|
break;
|
|
|
|
case 'db':
|
|
|
|
config::save_value('vfs_fstab',serialize(array(
|
|
|
|
'/' => 'sqlfs://$host/?storage=db',
|
|
|
|
'/apps' => 'links://$host/apps?storage=db',
|
|
|
|
)),'phpgwapi');
|
|
|
|
break;
|
2004-11-20 16:09:20 +01:00
|
|
|
}
|
2008-10-02 17:30:44 +02:00
|
|
|
}
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
function temp_dir($settings)
|
|
|
|
{
|
|
|
|
if (!setup_detection::check_dir($settings['temp_dir'],$error_msg))
|
2005-11-14 15:51:58 +01:00
|
|
|
{
|
2008-10-02 17:30:44 +02:00
|
|
|
$GLOBALS['config_error'] = lang("Your temporary directory '%1' %2",$settings['temp_dir'],$error_msg);
|
2004-11-20 16:09:20 +01:00
|
|
|
}
|
2008-10-02 17:30:44 +02:00
|
|
|
}
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
function files_dir($settings)
|
|
|
|
{
|
|
|
|
if ($settings['file_repository'] == 'sql' && $settings['file_store_contents'] == 'filesystem' &&
|
|
|
|
!setup_detection::check_dir($settings['files_dir'],$error_msg,true))
|
2004-11-20 16:09:20 +01:00
|
|
|
{
|
2008-10-02 17:30:44 +02:00
|
|
|
$GLOBALS['config_error'] = lang("Your files directory '%1' %2",$settings['files_dir'],$error_msg);
|
|
|
|
}
|
|
|
|
}
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
function backup_dir(&$settings)
|
|
|
|
{
|
|
|
|
if (@is_writeable($settings['files_dir']) && !$settings['backup_dir'] && $settings['file_store_contents'] == 'filesystem')
|
|
|
|
{
|
|
|
|
$settings['backup_dir'] = $settings['files_dir'].'/db_backup';
|
|
|
|
}
|
|
|
|
if (!setup_detection::check_dir($settings['backup_dir'],$error_msg,true))
|
|
|
|
{
|
|
|
|
$GLOBALS['config_error'] = lang("Your backup directory '%1' %2",$settings['backup_dir'],$error_msg);
|
|
|
|
}
|
|
|
|
}
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
function _mcrypt_test_module_mode($module,$mode)
|
|
|
|
{
|
|
|
|
/* Data */
|
|
|
|
$key = 'this is a very long key, even too long for the cipher';
|
|
|
|
$plain_text = 'very important data';
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
/* Open module, and create IV */
|
|
|
|
if(!$GLOBALS['td'] = @mcrypt_module_open($module, '',$mode, ''))
|
|
|
|
{
|
|
|
|
@mcrypt_module_close($GLOBALS['td']);
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
$key = substr($key, 0, mcrypt_enc_get_key_size($GLOBALS['td']));
|
|
|
|
$iv_size = mcrypt_enc_get_iv_size($GLOBALS['td']);
|
|
|
|
$iv = @mcrypt_create_iv($iv_size, MCRYPT_RAND);
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
/* Initialize encryption handle */
|
|
|
|
if(mcrypt_generic_init($GLOBALS['td'], $key, $iv) != -1)
|
|
|
|
{
|
|
|
|
/* Encrypt data */
|
|
|
|
$c_t = mcrypt_generic($GLOBALS['td'], $plain_text);
|
|
|
|
mcrypt_generic_deinit($GLOBALS['td']);
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
// close the module
|
|
|
|
mcrypt_module_close($GLOBALS['td']);
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
/* Reinitialize buffers for decryption */
|
|
|
|
/* Open module */
|
|
|
|
$GLOBALS['td'] = mcrypt_module_open($module, '', $mode, '');
|
|
|
|
$key = substr($key, 0, mcrypt_enc_get_key_size($GLOBALS['td']));
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
mcrypt_generic_init($GLOBALS['td'], $key, $iv);
|
|
|
|
$p_t = mdecrypt_generic($GLOBALS['td'], $c_t);
|
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
mcrypt_generic_deinit($GLOBALS['td']);
|
|
|
|
mcrypt_module_close($GLOBALS['td']);
|
|
|
|
}
|
|
|
|
else
|
2004-11-20 16:09:20 +01:00
|
|
|
{
|
2008-10-02 17:30:44 +02:00
|
|
|
@mcrypt_module_close($GLOBALS['td']);
|
|
|
|
}
|
|
|
|
return rtrim($p_t) === $plain_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* run a self-test through every listed cipher and mode - from robert at peakepro dot com (php.net manual) */
|
|
|
|
function mcrypt_check_sanity()
|
|
|
|
{
|
|
|
|
$modes = mcrypt_list_modes();
|
|
|
|
$algorithms = mcrypt_list_algorithms();
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
foreach($algorithms as $cipher)
|
|
|
|
{
|
|
|
|
if(mcrypt_module_self_test($cipher))
|
2004-11-20 16:09:20 +01:00
|
|
|
{
|
2008-10-02 17:30:44 +02:00
|
|
|
$GLOBALS['ciphers'][$cipher] = array();
|
|
|
|
foreach($modes as $mode)
|
2004-11-20 16:09:20 +01:00
|
|
|
{
|
2008-10-02 17:30:44 +02:00
|
|
|
if(_mcrypt_test_module_mode($cipher,$mode))
|
2004-11-20 16:09:20 +01:00
|
|
|
{
|
2008-10-02 17:30:44 +02:00
|
|
|
$result = True;
|
2004-11-20 16:09:20 +01:00
|
|
|
}
|
2008-10-02 17:30:44 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$result = False;
|
|
|
|
}
|
|
|
|
@$GLOBALS['ciphers'][$cipher][$mode] = $result;
|
2004-11-20 16:09:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-02 17:30:44 +02:00
|
|
|
ksort($GLOBALS['ciphers']);
|
|
|
|
/* _debug_array($GLOBALS['ciphers']); */
|
|
|
|
}
|
2004-11-20 16:09:20 +01:00
|
|
|
|
2008-10-02 17:30:44 +02:00
|
|
|
function mcrypt_algo($settings)
|
|
|
|
{
|
|
|
|
/* _debug_array($settings);exit; */
|
|
|
|
if(@function_exists('mcrypt_list_modes'))
|
2004-11-20 16:09:20 +01:00
|
|
|
{
|
2008-10-02 17:30:44 +02:00
|
|
|
mcrypt_check_sanity();
|
|
|
|
if(!@$GLOBALS['ciphers'][$settings['mcrypt_algo']][$settings['mcrypt_mode']])
|
2004-11-20 16:09:20 +01:00
|
|
|
{
|
2008-10-02 17:30:44 +02:00
|
|
|
$GLOBALS['config_error'] = lang('Invalid Mcrypt Algorithm/Mode combination');
|
2004-11-20 16:09:20 +01:00
|
|
|
}
|
|
|
|
}
|
2008-10-02 17:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add bracket around the ldap_search_filter, if admin forgot it
|
|
|
|
*
|
|
|
|
* @param array $settings
|
|
|
|
*/
|
|
|
|
function ldap_search_filter(&$settings)
|
|
|
|
{
|
|
|
|
$filter =& $settings['ldap_search_filter'];
|
|
|
|
|
|
|
|
if ($filter && $filter{0} != '(') $filter = '('.$filter.')';
|
|
|
|
}
|