adm/index.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/adm/index.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,625 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package acp
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +*/
    1.16 +define('IN_PHPBB', true);
    1.17 +define('ADMIN_START', true);
    1.18 +define('NEED_SID', true);
    1.19 +
    1.20 +// Include files
    1.21 +$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
    1.22 +$phpEx = substr(strrchr(__FILE__, '.'), 1);
    1.23 +require($phpbb_root_path . 'common.' . $phpEx);
    1.24 +require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
    1.25 +require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
    1.26 +
    1.27 +// Start session management
    1.28 +$user->session_begin();
    1.29 +$auth->acl($user->data);
    1.30 +$user->setup('acp/common');
    1.31 +// End session management
    1.32 +
    1.33 +// Have they authenticated (again) as an admin for this session?
    1.34 +if (!isset($user->data['session_admin']) || !$user->data['session_admin'])
    1.35 +{
    1.36 +	login_box('', $user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], true, false);
    1.37 +}
    1.38 +
    1.39 +// Is user any type of admin? No, then stop here, each script needs to
    1.40 +// check specific permissions but this is a catchall
    1.41 +if (!$auth->acl_get('a_'))
    1.42 +{
    1.43 +	trigger_error('NO_ADMIN');
    1.44 +}
    1.45 +
    1.46 +// We define the admin variables now, because the user is now able to use the admin related features...
    1.47 +define('IN_ADMIN', true);
    1.48 +$phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './';
    1.49 +
    1.50 +// Some oft used variables
    1.51 +$safe_mode		= (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) === 'on') ? true : false;
    1.52 +$file_uploads	= (@ini_get('file_uploads') == '1' || strtolower(@ini_get('file_uploads')) === 'on') ? true : false;
    1.53 +$module_id		= request_var('i', '');
    1.54 +$mode			= request_var('mode', '');
    1.55 +
    1.56 +// Set custom template for admin area
    1.57 +$template->set_custom_template($phpbb_admin_path . 'style', 'admin');
    1.58 +$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
    1.59 +
    1.60 +// the acp template is never stored in the database
    1.61 +$user->theme['template_storedb'] = false;
    1.62 +
    1.63 +// Instantiate new module
    1.64 +$module = new p_master();
    1.65 +
    1.66 +// Instantiate module system and generate list of available modules
    1.67 +$module->list_modules('acp');
    1.68 +
    1.69 +// Select the active module
    1.70 +$module->set_active($module_id, $mode);
    1.71 +
    1.72 +// Assign data to the template engine for the list of modules
    1.73 +// We do this before loading the active module for correct menu display in trigger_error
    1.74 +$module->assign_tpl_vars(append_sid("{$phpbb_admin_path}index.$phpEx"));
    1.75 +
    1.76 +// Load and execute the relevant module
    1.77 +$module->load_active();
    1.78 +
    1.79 +// Generate the page
    1.80 +adm_page_header($module->get_page_title());
    1.81 +
    1.82 +$template->set_filenames(array(
    1.83 +	'body' => $module->get_tpl_name(),
    1.84 +));
    1.85 +
    1.86 +adm_page_footer();
    1.87 +
    1.88 +/**
    1.89 +* Header for acp pages
    1.90 +*/
    1.91 +function adm_page_header($page_title)
    1.92 +{
    1.93 +	global $config, $db, $user, $template;
    1.94 +	global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
    1.95 +
    1.96 +	if (defined('HEADER_INC'))
    1.97 +	{
    1.98 +		return;
    1.99 +	}
   1.100 +
   1.101 +	define('HEADER_INC', true);
   1.102 +
   1.103 +	// gzip_compression
   1.104 +	if ($config['gzip_compress'])
   1.105 +	{
   1.106 +		if (@extension_loaded('zlib') && !headers_sent())
   1.107 +		{
   1.108 +			ob_start('ob_gzhandler');
   1.109 +		}
   1.110 +	}
   1.111 +
   1.112 +	$template->assign_vars(array(
   1.113 +		'PAGE_TITLE'			=> $page_title,
   1.114 +		'USERNAME'				=> $user->data['username'],
   1.115 +
   1.116 +		'SID'					=> $SID,
   1.117 +		'_SID'					=> $_SID,
   1.118 +		'SESSION_ID'			=> $user->session_id,
   1.119 +		'ROOT_PATH'				=> $phpbb_admin_path,
   1.120 +
   1.121 +		'U_LOGOUT'				=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout'),
   1.122 +		'U_ADM_LOGOUT'			=> append_sid("{$phpbb_admin_path}index.$phpEx", 'action=admlogout'),
   1.123 +		'U_ADM_INDEX'			=> append_sid("{$phpbb_admin_path}index.$phpEx"),
   1.124 +		'U_INDEX'				=> append_sid("{$phpbb_root_path}index.$phpEx"),
   1.125 +
   1.126 +		'T_IMAGES_PATH'			=> "{$phpbb_root_path}images/",
   1.127 +		'T_SMILIES_PATH'		=> "{$phpbb_root_path}{$config['smilies_path']}/",
   1.128 +		'T_AVATAR_PATH'			=> "{$phpbb_root_path}{$config['avatar_path']}/",
   1.129 +		'T_AVATAR_GALLERY_PATH'	=> "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
   1.130 +		'T_ICONS_PATH'			=> "{$phpbb_root_path}{$config['icons_path']}/",
   1.131 +		'T_RANKS_PATH'			=> "{$phpbb_root_path}{$config['ranks_path']}/",
   1.132 +		'T_UPLOAD_PATH'			=> "{$phpbb_root_path}{$config['upload_path']}/",
   1.133 +
   1.134 +		'ICON_MOVE_UP'				=> '<img src="' . $phpbb_admin_path . 'images/icon_up.gif" alt="' . $user->lang['MOVE_UP'] . '" title="' . $user->lang['MOVE_UP'] . '" />',
   1.135 +		'ICON_MOVE_UP_DISABLED'		=> '<img src="' . $phpbb_admin_path . 'images/icon_up_disabled.gif" alt="' . $user->lang['MOVE_UP'] . '" title="' . $user->lang['MOVE_UP'] . '" />',
   1.136 +		'ICON_MOVE_DOWN'			=> '<img src="' . $phpbb_admin_path . 'images/icon_down.gif" alt="' . $user->lang['MOVE_DOWN'] . '" title="' . $user->lang['MOVE_DOWN'] . '" />',
   1.137 +		'ICON_MOVE_DOWN_DISABLED'	=> '<img src="' . $phpbb_admin_path . 'images/icon_down_disabled.gif" alt="' . $user->lang['MOVE_DOWN'] . '" title="' . $user->lang['MOVE_DOWN'] . '" />',
   1.138 +		'ICON_EDIT'					=> '<img src="' . $phpbb_admin_path . 'images/icon_edit.gif" alt="' . $user->lang['EDIT'] . '" title="' . $user->lang['EDIT'] . '" />',
   1.139 +		'ICON_EDIT_DISABLED'		=> '<img src="' . $phpbb_admin_path . 'images/icon_edit_disabled.gif" alt="' . $user->lang['EDIT'] . '" title="' . $user->lang['EDIT'] . '" />',
   1.140 +		'ICON_DELETE'				=> '<img src="' . $phpbb_admin_path . 'images/icon_delete.gif" alt="' . $user->lang['DELETE'] . '" title="' . $user->lang['DELETE'] . '" />',
   1.141 +		'ICON_DELETE_DISABLED'		=> '<img src="' . $phpbb_admin_path . 'images/icon_delete_disabled.gif" alt="' . $user->lang['DELETE'] . '" title="' . $user->lang['DELETE'] . '" />',
   1.142 +		'ICON_SYNC'					=> '<img src="' . $phpbb_admin_path . 'images/icon_sync.gif" alt="' . $user->lang['RESYNC'] . '" title="' . $user->lang['RESYNC'] . '" />',
   1.143 +		'ICON_SYNC_DISABLED'		=> '<img src="' . $phpbb_admin_path . 'images/icon_sync_disabled.gif" alt="' . $user->lang['RESYNC'] . '" title="' . $user->lang['RESYNC'] . '" />',
   1.144 +
   1.145 +		'S_USER_LANG'			=> $user->lang['USER_LANG'],
   1.146 +		'S_CONTENT_DIRECTION'	=> $user->lang['DIRECTION'],
   1.147 +		'S_CONTENT_ENCODING'	=> 'UTF-8',
   1.148 +		'S_CONTENT_FLOW_BEGIN'	=> ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
   1.149 +		'S_CONTENT_FLOW_END'	=> ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
   1.150 +	));
   1.151 +
   1.152 +	// application/xhtml+xml not used because of IE
   1.153 +	header('Content-type: text/html; charset=UTF-8');
   1.154 +
   1.155 +	header('Cache-Control: private, no-cache="set-cookie"');
   1.156 +	header('Expires: 0');
   1.157 +	header('Pragma: no-cache');
   1.158 +
   1.159 +	return;
   1.160 +}
   1.161 +
   1.162 +/**
   1.163 +* Page footer for acp pages
   1.164 +*/
   1.165 +function adm_page_footer($copyright_html = true)
   1.166 +{
   1.167 +	global $db, $config, $template, $user, $auth, $cache;
   1.168 +	global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx;
   1.169 +
   1.170 +	// Output page creation time
   1.171 +	if (defined('DEBUG'))
   1.172 +	{
   1.173 +		$mtime = explode(' ', microtime());
   1.174 +		$totaltime = $mtime[0] + $mtime[1] - $starttime;
   1.175 +
   1.176 +		if (!empty($_REQUEST['explain']) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report'))
   1.177 +		{
   1.178 +			$db->sql_report('display');
   1.179 +		}
   1.180 +
   1.181 +		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
   1.182 +
   1.183 +		if ($auth->acl_get('a_') && defined('DEBUG_EXTRA'))
   1.184 +		{
   1.185 +			if (function_exists('memory_get_usage'))
   1.186 +			{
   1.187 +				if ($memory_usage = memory_get_usage())
   1.188 +				{
   1.189 +					global $base_memory_usage;
   1.190 +					$memory_usage -= $base_memory_usage;
   1.191 +					$memory_usage = get_formatted_filesize($memory_usage);
   1.192 +
   1.193 +					$debug_output .= ' | Memory Usage: ' . $memory_usage;
   1.194 +				}
   1.195 +			}
   1.196 +
   1.197 +			$debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
   1.198 +		}
   1.199 +	}
   1.200 +
   1.201 +	$template->assign_vars(array(
   1.202 +		'DEBUG_OUTPUT'		=> (defined('DEBUG')) ? $debug_output : '',
   1.203 +		'TRANSLATION_INFO'	=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
   1.204 +		'S_COPYRIGHT_HTML'	=> $copyright_html,
   1.205 +		'VERSION'			=> $config['version'])
   1.206 +	);
   1.207 +
   1.208 +	$template->display('body');
   1.209 +
   1.210 +	garbage_collection();
   1.211 +	exit_handler();
   1.212 +}
   1.213 +
   1.214 +/**
   1.215 +* Generate back link for acp pages
   1.216 +*/
   1.217 +function adm_back_link($u_action)
   1.218 +{
   1.219 +	global $user;
   1.220 +	return '<br /><br /><a href="' . $u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>';
   1.221 +}
   1.222 +
   1.223 +/**
   1.224 +* Build select field options in acp pages
   1.225 +*/
   1.226 +function build_select($option_ary, $option_default = false)
   1.227 +{
   1.228 +	global $user;
   1.229 +
   1.230 +	$html = '';
   1.231 +	foreach ($option_ary as $value => $title)
   1.232 +	{
   1.233 +		$selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : '';
   1.234 +		$html .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$title] . '</option>';
   1.235 +	}
   1.236 +
   1.237 +	return $html;
   1.238 +}
   1.239 +
   1.240 +/**
   1.241 +* Build radio fields in acp pages
   1.242 +*/
   1.243 +function h_radio($name, $input_ary, $input_default = false, $id = false, $key = false, $separator = '')
   1.244 +{
   1.245 +	global $user;
   1.246 +
   1.247 +	$html = '';
   1.248 +	$id_assigned = false;
   1.249 +	foreach ($input_ary as $value => $title)
   1.250 +	{
   1.251 +		$selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : '';
   1.252 +		$html .= '<label><input type="radio" name="' . $name . '"' . (($id && !$id_assigned) ? ' id="' . $id . '"' : '') . ' value="' . $value . '"' . $selected . (($key) ? ' accesskey="' . $key . '"' : '') . ' class="radio" /> ' . $user->lang[$title] . '</label>' . $separator;
   1.253 +		$id_assigned = true;
   1.254 +	}
   1.255 +
   1.256 +	return $html;
   1.257 +}
   1.258 +
   1.259 +/**
   1.260 +* Build configuration template for acp configuration pages
   1.261 +*/
   1.262 +function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
   1.263 +{
   1.264 +	global $user, $module;
   1.265 +
   1.266 +	$tpl = '';
   1.267 +	$name = 'config[' . $config_key . ']';
   1.268 +
   1.269 +	// Make sure there is no notice printed out for non-existent config options (we simply set them)
   1.270 +	if (!isset($new[$config_key]))
   1.271 +	{
   1.272 +		$new[$config_key] = '';
   1.273 +	}
   1.274 +
   1.275 +	switch ($tpl_type[0])
   1.276 +	{
   1.277 +		case 'text':
   1.278 +		case 'password':
   1.279 +			$size = (int) $tpl_type[1];
   1.280 +			$maxlength = (int) $tpl_type[2];
   1.281 +
   1.282 +			$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new[$config_key] . '"' . (($tpl_type[0] === 'password') ?  ' autocomplete="off"' : '') . ' />';
   1.283 +		break;
   1.284 +
   1.285 +		case 'dimension':
   1.286 +			$size = (int) $tpl_type[1];
   1.287 +			$maxlength = (int) $tpl_type[2];
   1.288 +
   1.289 +			$tpl = '<input id="' . $key . '" type="text"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="config[' . $config_key . '_width]" value="' . $new[$config_key . '_width'] . '" /> x <input type="text"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="config[' . $config_key . '_height]" value="' . $new[$config_key . '_height'] . '" />';
   1.290 +		break;
   1.291 +
   1.292 +		case 'textarea':
   1.293 +			$rows = (int) $tpl_type[1];
   1.294 +			$cols = (int) $tpl_type[2];
   1.295 +
   1.296 +			$tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new[$config_key] . '</textarea>';
   1.297 +		break;
   1.298 +
   1.299 +		case 'radio':
   1.300 +			$key_yes	= ($new[$config_key]) ? ' checked="checked"' : '';
   1.301 +			$key_no		= (!$new[$config_key]) ? ' checked="checked"' : '';
   1.302 +
   1.303 +			$tpl_type_cond = explode('_', $tpl_type[1]);
   1.304 +			$type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
   1.305 +
   1.306 +			$tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
   1.307 +			$tpl_yes = '<label><input type="radio" id="' . $key . '" name="' . $name . '" value="1"' . $key_yes . ' class="radio" /> ' . (($type_no) ? $user->lang['YES'] : $user->lang['ENABLED']) . '</label>';
   1.308 +
   1.309 +			$tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes;
   1.310 +		break;
   1.311 +
   1.312 +		case 'select':
   1.313 +		case 'custom':
   1.314 +
   1.315 +			$return = '';
   1.316 +
   1.317 +			if (isset($vars['method']))
   1.318 +			{
   1.319 +				$call = array($module->module, $vars['method']);
   1.320 +			}
   1.321 +			else if (isset($vars['function']))
   1.322 +			{
   1.323 +				$call = $vars['function'];
   1.324 +			}
   1.325 +			else
   1.326 +			{
   1.327 +				break;
   1.328 +			}
   1.329 +
   1.330 +			if (isset($vars['params']))
   1.331 +			{
   1.332 +				$args = array();
   1.333 +				foreach ($vars['params'] as $value)
   1.334 +				{
   1.335 +					switch ($value)
   1.336 +					{
   1.337 +						case '{CONFIG_VALUE}':
   1.338 +							$value = $new[$config_key];
   1.339 +						break;
   1.340 +
   1.341 +						case '{KEY}':
   1.342 +							$value = $key;
   1.343 +						break;
   1.344 +					}
   1.345 +
   1.346 +					$args[] = $value;
   1.347 +				}
   1.348 +			}
   1.349 +			else
   1.350 +			{
   1.351 +				$args = array($new[$config_key], $key);
   1.352 +			}
   1.353 +
   1.354 +			$return = call_user_func_array($call, $args);
   1.355 +
   1.356 +			if ($tpl_type[0] == 'select')
   1.357 +			{
   1.358 +				$tpl = '<select id="' . $key . '" name="' . $name . '">' . $return . '</select>';
   1.359 +			}
   1.360 +			else
   1.361 +			{
   1.362 +				$tpl = $return;
   1.363 +			}
   1.364 +
   1.365 +		break;
   1.366 +
   1.367 +		default:
   1.368 +		break;
   1.369 +	}
   1.370 +
   1.371 +	if (isset($vars['append']))
   1.372 +	{
   1.373 +		$tpl .= $vars['append'];
   1.374 +	}
   1.375 +
   1.376 +	return $tpl;
   1.377 +}
   1.378 +
   1.379 +/**
   1.380 +* Going through a config array and validate values, writing errors to $error. The validation method  accepts parameters separated by ':' for string and int.
   1.381 +* The first parameter defines the type to be used, the second the lower bound and the third the upper bound. Only the type is required.
   1.382 +*/
   1.383 +function validate_config_vars($config_vars, &$cfg_array, &$error)
   1.384 +{
   1.385 +	global $phpbb_root_path, $user;
   1.386 +	$type	= 0;
   1.387 +	$min	= 1;
   1.388 +	$max	= 2;
   1.389 +
   1.390 +	foreach ($config_vars as $config_name => $config_definition)
   1.391 +	{
   1.392 +		if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
   1.393 +		{
   1.394 +			continue;
   1.395 +		}
   1.396 +
   1.397 +		if (!isset($config_definition['validate']))
   1.398 +		{
   1.399 +			continue;
   1.400 +		}
   1.401 +
   1.402 +		$validator = explode(':', $config_definition['validate']);
   1.403 +
   1.404 +		// Validate a bit. ;) (0 = type, 1 = min, 2= max)
   1.405 +		switch ($validator[$type])
   1.406 +		{
   1.407 +			case 'string':
   1.408 +				$length = utf8_strlen($cfg_array[$config_name]);
   1.409 +
   1.410 +				// the column is a VARCHAR
   1.411 +				$validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255;
   1.412 +
   1.413 +				if (isset($validator[$min]) && $length < $validator[$min])
   1.414 +				{
   1.415 +					$error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]);
   1.416 +				}
   1.417 +				else if (isset($validator[$max]) && $length > $validator[2])
   1.418 +				{
   1.419 +					$error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]);
   1.420 +				}
   1.421 +			break;
   1.422 +
   1.423 +			case 'bool':
   1.424 +				$cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0;
   1.425 +			break;
   1.426 +
   1.427 +			case 'int':
   1.428 +				$cfg_array[$config_name] = (int) $cfg_array[$config_name];
   1.429 +
   1.430 +				if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min])
   1.431 +				{
   1.432 +					$error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]);
   1.433 +				}
   1.434 +				else if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max])
   1.435 +				{
   1.436 +					$error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]);
   1.437 +				}
   1.438 +
   1.439 +				if (strpos($config_name, '_max') !== false)
   1.440 +				{
   1.441 +					// Min/max pairs of settings should ensure that min <= max
   1.442 +					// Replace _max with _min to find the name of the minimum
   1.443 +					// corresponding configuration variable
   1.444 +					$min_name = str_replace('_max', '_min', $config_name);
   1.445 +
   1.446 +					if (isset($cfg_array[$min_name]) && is_numeric($cfg_array[$min_name]) && $cfg_array[$config_name] < $cfg_array[$min_name])
   1.447 +					{
   1.448 +						// A minimum value exists and the maximum value is less than it
   1.449 +						$error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], (int) $cfg_array[$min_name]);
   1.450 +					}
   1.451 +				}
   1.452 +			break;
   1.453 +
   1.454 +			// Absolute path
   1.455 +			case 'script_path':
   1.456 +				if (!$cfg_array[$config_name])
   1.457 +				{
   1.458 +					break;
   1.459 +				}
   1.460 +
   1.461 +				$destination = str_replace('\\', '/', $cfg_array[$config_name]);
   1.462 +
   1.463 +				if ($destination !== '/')
   1.464 +				{
   1.465 +					// Adjust destination path (no trailing slash)
   1.466 +					if (substr($destination, -1, 1) == '/')
   1.467 +					{
   1.468 +						$destination = substr($destination, 0, -1);
   1.469 +					}
   1.470 +
   1.471 +					$destination = str_replace(array('../', './'), '', $destination);
   1.472 +
   1.473 +					if ($destination[0] != '/')
   1.474 +					{
   1.475 +						$destination = '/' . $destination;
   1.476 +					}
   1.477 +				}
   1.478 +
   1.479 +				$cfg_array[$config_name] = trim($destination);
   1.480 +
   1.481 +			break;
   1.482 +
   1.483 +			// Absolute path
   1.484 +			case 'lang':
   1.485 +				if (!$cfg_array[$config_name])
   1.486 +				{
   1.487 +					break;
   1.488 +				}
   1.489 +
   1.490 +				$cfg_array[$config_name] = basename($cfg_array[$config_name]);
   1.491 +
   1.492 +				if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/'))
   1.493 +				{
   1.494 +					$error[] = $user->lang['WRONG_DATA_LANG'];
   1.495 +				}
   1.496 +			break;
   1.497 +
   1.498 +			// Relative path (appended $phpbb_root_path)
   1.499 +			case 'rpath':
   1.500 +			case 'rwpath':
   1.501 +				if (!$cfg_array[$config_name])
   1.502 +				{
   1.503 +					break;
   1.504 +				}
   1.505 +
   1.506 +				$destination = $cfg_array[$config_name];
   1.507 +
   1.508 +				// Adjust destination path (no trailing slash)
   1.509 +				if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
   1.510 +				{
   1.511 +					$destination = substr($destination, 0, -1);
   1.512 +				}
   1.513 +
   1.514 +				$destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
   1.515 +				if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
   1.516 +				{
   1.517 +					$destination = '';
   1.518 +				}
   1.519 +
   1.520 +				$cfg_array[$config_name] = trim($destination);
   1.521 +
   1.522 +			// Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir...
   1.523 +			case 'path':
   1.524 +			case 'wpath':
   1.525 +
   1.526 +				if (!$cfg_array[$config_name])
   1.527 +				{
   1.528 +					break;
   1.529 +				}
   1.530 +
   1.531 +				$cfg_array[$config_name] = trim($cfg_array[$config_name]);
   1.532 +
   1.533 +				// Make sure no NUL byte is present...
   1.534 +				if (strpos($cfg_array[$config_name], "\0") !== false || strpos($cfg_array[$config_name], '%00') !== false)
   1.535 +				{
   1.536 +					$cfg_array[$config_name] = '';
   1.537 +					break;
   1.538 +				}
   1.539 +
   1.540 +				if (!file_exists($phpbb_root_path . $cfg_array[$config_name]))
   1.541 +				{
   1.542 +					$error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]);
   1.543 +				}
   1.544 +
   1.545 +				if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name]))
   1.546 +				{
   1.547 +					$error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]);
   1.548 +				}
   1.549 +
   1.550 +				// Check if the path is writable
   1.551 +				if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath')
   1.552 +				{
   1.553 +					if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !phpbb_is_writable($phpbb_root_path . $cfg_array[$config_name]))
   1.554 +					{
   1.555 +						$error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]);
   1.556 +					}
   1.557 +				}
   1.558 +
   1.559 +			break;
   1.560 +		}
   1.561 +	}
   1.562 +
   1.563 +	return;
   1.564 +}
   1.565 +
   1.566 +/**
   1.567 +* Checks whatever or not a variable is OK for use in the Database
   1.568 +* param mixed $value_ary An array of the form array(array('lang' => ..., 'value' => ..., 'column_type' =>))'
   1.569 +* param mixed $error The error array
   1.570 +*/
   1.571 +function validate_range($value_ary, &$error)
   1.572 +{
   1.573 +	global $user;
   1.574 +
   1.575 +	$column_types = array(
   1.576 +		'BOOL'	=> array('php_type' => 'int', 		'min' => 0, 				'max' => 1),
   1.577 +		'USINT'	=> array('php_type' => 'int',		'min' => 0, 				'max' => 65535),
   1.578 +		'UINT'	=> array('php_type' => 'int', 		'min' => 0, 				'max' => (int) 0x7fffffff),
   1.579 +		// Do not use (int) 0x80000000 - it evaluates to different
   1.580 +		// values on 32-bit and 64-bit systems.
   1.581 +		// Apparently -2147483648 is a float on 32-bit systems,
   1.582 +		// despite fitting in an int, thus explicit cast is needed.
   1.583 +		'INT'	=> array('php_type' => 'int', 		'min' => (int) -2147483648,	'max' => (int) 0x7fffffff),
   1.584 +		'TINT'	=> array('php_type' => 'int',		'min' => -128,				'max' => 127),
   1.585 +
   1.586 +		'VCHAR'	=> array('php_type' => 'string', 	'min' => 0, 				'max' => 255),
   1.587 +	);
   1.588 +	foreach ($value_ary as $value)
   1.589 +	{
   1.590 +		$column = explode(':', $value['column_type']);
   1.591 +		$max = $min = 0;
   1.592 +		$type = 0;
   1.593 +		if (!isset($column_types[$column[0]]))
   1.594 +		{
   1.595 +			continue;
   1.596 +		}
   1.597 +		else
   1.598 +		{
   1.599 +			$type = $column_types[$column[0]];
   1.600 +		}
   1.601 +
   1.602 +		switch ($type['php_type'])
   1.603 +		{
   1.604 +			case 'string' :
   1.605 +				$max = (isset($column[1])) ? min($column[1],$type['max']) : $type['max'];
   1.606 +				if (utf8_strlen($value['value']) > $max)
   1.607 +				{
   1.608 +					$error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max);
   1.609 +				}
   1.610 +			break;
   1.611 +
   1.612 +			case 'int':
   1.613 +				$min = (isset($column[1])) ? max($column[1],$type['min']) : $type['min'];
   1.614 +				$max = (isset($column[2])) ? min($column[2],$type['max']) : $type['max'];
   1.615 +				if ($value['value'] < $min)
   1.616 +				{
   1.617 +					$error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$value['lang']], $min);
   1.618 +				}
   1.619 +				else if ($value['value'] > $max)
   1.620 +				{
   1.621 +					$error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$value['lang']], $max);
   1.622 +				}
   1.623 +			break;
   1.624 +		}
   1.625 +	}
   1.626 +}
   1.627 +
   1.628 +?>
   1.629 \ No newline at end of file