|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @package acp
|
|
|
4c79b5 |
* @version $Id: index.php 8591 2008-06-04 11:40:53Z Kellanved $
|
|
|
4c79b5 |
* @copyright (c) 2005 phpBB Group
|
|
|
4c79b5 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
define('IN_PHPBB', true);
|
|
|
4c79b5 |
define('ADMIN_START', true);
|
|
|
4c79b5 |
define('NEED_SID', true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Include files
|
|
|
4c79b5 |
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
|
|
|
4c79b5 |
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
|
|
4c79b5 |
require($phpbb_root_path . 'common.' . $phpEx);
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Start session management
|
|
|
4c79b5 |
$user->session_begin();
|
|
|
4c79b5 |
$auth->acl($user->data);
|
|
|
4c79b5 |
$user->setup('acp/common');
|
|
|
4c79b5 |
// End session management
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Have they authenticated (again) as an admin for this session?
|
|
|
4c79b5 |
if (!isset($user->data['session_admin']) || !$user->data['session_admin'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
login_box('', $user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], true, false);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Is user any type of admin? No, then stop here, each script needs to
|
|
|
4c79b5 |
// check specific permissions but this is a catchall
|
|
|
4c79b5 |
if (!$auth->acl_get('a_'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error('NO_ADMIN');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// We define the admin variables now, because the user is now able to use the admin related features...
|
|
|
4c79b5 |
define('IN_ADMIN', true);
|
|
|
4c79b5 |
$phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Some oft used variables
|
|
|
4c79b5 |
$safe_mode = (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) === 'on') ? true : false;
|
|
|
4c79b5 |
$file_uploads = (@ini_get('file_uploads') == '1' || strtolower(@ini_get('file_uploads')) === 'on') ? true : false;
|
|
|
4c79b5 |
$module_id = request_var('i', '');
|
|
|
4c79b5 |
$mode = request_var('mode', '');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Set custom template for admin area
|
|
|
4c79b5 |
$template->set_custom_template($phpbb_admin_path . 'style', 'admin');
|
|
|
4c79b5 |
$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// the acp template is never stored in the database
|
|
|
4c79b5 |
$user->theme['template_storedb'] = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Instantiate new module
|
|
|
4c79b5 |
$module = new p_master();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Instantiate module system and generate list of available modules
|
|
|
4c79b5 |
$module->list_modules('acp');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Select the active module
|
|
|
4c79b5 |
$module->set_active($module_id, $mode);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Assign data to the template engine for the list of modules
|
|
|
4c79b5 |
// We do this before loading the active module for correct menu display in trigger_error
|
|
|
4c79b5 |
$module->assign_tpl_vars(append_sid("{$phpbb_admin_path}index.$phpEx"));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Load and execute the relevant module
|
|
|
4c79b5 |
$module->load_active();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Generate the page
|
|
|
4c79b5 |
adm_page_header($module->get_page_title());
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->set_filenames(array(
|
|
|
4c79b5 |
'body' => $module->get_tpl_name(),
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
adm_page_footer();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Header for acp pages
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function adm_page_header($page_title)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $config, $db, $user, $template;
|
|
|
4c79b5 |
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (defined('HEADER_INC'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
define('HEADER_INC', true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// gzip_compression
|
|
|
4c79b5 |
if ($config['gzip_compress'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (@extension_loaded('zlib') && !headers_sent())
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
ob_start('ob_gzhandler');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'PAGE_TITLE' => $page_title,
|
|
|
4c79b5 |
'USERNAME' => $user->data['username'],
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'SID' => $SID,
|
|
|
4c79b5 |
'_SID' => $_SID,
|
|
|
4c79b5 |
'SESSION_ID' => $user->session_id,
|
|
|
4c79b5 |
'ROOT_PATH' => $phpbb_admin_path,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_LOGOUT' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout'),
|
|
|
4c79b5 |
'U_ADM_LOGOUT' => append_sid("{$phpbb_admin_path}index.$phpEx", 'action=admlogout'),
|
|
|
4c79b5 |
'U_ADM_INDEX' => append_sid("{$phpbb_admin_path}index.$phpEx"),
|
|
|
4c79b5 |
'U_INDEX' => append_sid("{$phpbb_root_path}index.$phpEx"),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'T_IMAGES_PATH' => "{$phpbb_root_path}images/",
|
|
|
4c79b5 |
'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/",
|
|
|
4c79b5 |
'T_AVATAR_PATH' => "{$phpbb_root_path}{$config['avatar_path']}/",
|
|
|
4c79b5 |
'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
|
|
|
4c79b5 |
'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/",
|
|
|
4c79b5 |
'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/",
|
|
|
4c79b5 |
'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/",
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'ICON_MOVE_UP' => '',
|
|
|
4c79b5 |
'ICON_MOVE_UP_DISABLED' => '',
|
|
|
4c79b5 |
'ICON_MOVE_DOWN' => '',
|
|
|
4c79b5 |
'ICON_MOVE_DOWN_DISABLED' => '',
|
|
|
4c79b5 |
'ICON_EDIT' => '',
|
|
|
4c79b5 |
'ICON_EDIT_DISABLED' => '',
|
|
|
4c79b5 |
'ICON_DELETE' => '',
|
|
|
4c79b5 |
'ICON_DELETE_DISABLED' => '',
|
|
|
4c79b5 |
'ICON_SYNC' => '',
|
|
|
4c79b5 |
'ICON_SYNC_DISABLED' => '',
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'S_USER_LANG' => $user->lang['USER_LANG'],
|
|
|
4c79b5 |
'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'],
|
|
|
4c79b5 |
'S_CONTENT_ENCODING' => 'UTF-8',
|
|
|
4c79b5 |
'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
|
|
|
4c79b5 |
'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// application/xhtml+xml not used because of IE
|
|
|
4c79b5 |
header('Content-type: text/html; charset=UTF-8');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
header('Cache-Control: private, no-cache="set-cookie"');
|
|
|
4c79b5 |
header('Expires: 0');
|
|
|
4c79b5 |
header('Pragma: no-cache');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Page footer for acp pages
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function adm_page_footer($copyright_html = true)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $config, $template, $user, $auth, $cache;
|
|
|
4c79b5 |
global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Output page creation time
|
|
|
4c79b5 |
if (defined('DEBUG'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$mtime = explode(' ', microtime());
|
|
|
4c79b5 |
$totaltime = $mtime[0] + $mtime[1] - $starttime;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!empty($_REQUEST['explain']) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_report('display');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($auth->acl_get('a_') && defined('DEBUG_EXTRA'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (function_exists('memory_get_usage'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($memory_usage = memory_get_usage())
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $base_memory_usage;
|
|
|
4c79b5 |
$memory_usage -= $base_memory_usage;
|
|
|
4c79b5 |
$memory_usage = get_formatted_filesize($memory_usage);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$debug_output .= ' | Memory Usage: ' . $memory_usage;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$debug_output .= ' | Explain';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '',
|
|
|
4c79b5 |
'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
|
|
|
4c79b5 |
'S_COPYRIGHT_HTML' => $copyright_html,
|
|
|
4c79b5 |
'VERSION' => $config['version'])
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->display('body');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
garbage_collection();
|
|
|
4c79b5 |
exit_handler();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Generate back link for acp pages
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function adm_back_link($u_action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
return '
« ' . $user->lang['BACK_TO_PREV'] . '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build select field options in acp pages
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function build_select($option_ary, $option_default = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$html = '';
|
|
|
4c79b5 |
foreach ($option_ary as $value => $title)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : '';
|
|
|
4c79b5 |
$html .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$title] . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $html;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build radio fields in acp pages
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function h_radio($name, &$input_ary, $input_default = false, $id = false, $key = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$html = '';
|
|
|
4c79b5 |
$id_assigned = false;
|
|
|
4c79b5 |
foreach ($input_ary as $value => $title)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : '';
|
|
|
4c79b5 |
$html .= '<label><input type="radio" name="' . $name . '"' . (($id && !$id_assigned) ? ' id="' . $id . '"' : '') . ' value="' . $value . '"' . $selected . (($key) ? ' accesskey="' . $key . '"' : '') . ' class="radio" /> ' . $user->lang[$title] . '</label>';
|
|
|
4c79b5 |
$id_assigned = true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $html;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build configuration template for acp configuration pages
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user, $module;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tpl = '';
|
|
|
4c79b5 |
$name = 'config[' . $config_key . ']';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($tpl_type[0])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'text':
|
|
|
4c79b5 |
case 'password':
|
|
|
4c79b5 |
$size = (int) $tpl_type[1];
|
|
|
4c79b5 |
$maxlength = (int) $tpl_type[2];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new[$config_key] . '" />';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'dimension':
|
|
|
4c79b5 |
$size = (int) $tpl_type[1];
|
|
|
4c79b5 |
$maxlength = (int) $tpl_type[2];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$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'] . '" />';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'textarea':
|
|
|
4c79b5 |
$rows = (int) $tpl_type[1];
|
|
|
4c79b5 |
$cols = (int) $tpl_type[2];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new[$config_key] . '</textarea>';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'radio':
|
|
|
4c79b5 |
$key_yes = ($new[$config_key]) ? ' checked="checked"' : '';
|
|
|
4c79b5 |
$key_no = (!$new[$config_key]) ? ' checked="checked"' : '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tpl_type_cond = explode('_', $tpl_type[1]);
|
|
|
4c79b5 |
$type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
|
|
|
4c79b5 |
$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>';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'select':
|
|
|
4c79b5 |
case 'custom':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$return = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($vars['method']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$call = array($module->module, $vars['method']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (isset($vars['function']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$call = $vars['function'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($vars['params']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$args = array();
|
|
|
4c79b5 |
foreach ($vars['params'] as $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case '{CONFIG_VALUE}':
|
|
|
4c79b5 |
$value = $new[$config_key];
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case '{KEY}':
|
|
|
4c79b5 |
$value = $key;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$args[] = $value;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$args = array($new[$config_key], $key);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$return = call_user_func_array($call, $args);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($tpl_type[0] == 'select')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$tpl = '<select id="' . $key . '" name="' . $name . '">' . $return . '</select>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$tpl = $return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($vars['append']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$tpl .= $vars['append'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $tpl;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int.
|
|
|
4c79b5 |
* 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.
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function validate_config_vars($config_vars, &$cfg_array, &$error)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $user;
|
|
|
4c79b5 |
$type = 0;
|
|
|
4c79b5 |
$min = 1;
|
|
|
4c79b5 |
$max = 2;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($config_vars as $config_name => $config_definition)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!isset($config_definition['validate']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$validator = explode(':', $config_definition['validate']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Validate a bit. ;) (0 = type, 1 = min, 2= max)
|
|
|
4c79b5 |
switch ($validator[$type])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'string':
|
|
|
4c79b5 |
$length = strlen($cfg_array[$config_name]);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// the column is a VARCHAR
|
|
|
4c79b5 |
$validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($validator[$min]) && $length < $validator[$min])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (isset($validator[$max]) && $length > $validator[2])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'bool':
|
|
|
4c79b5 |
$cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'int':
|
|
|
4c79b5 |
$cfg_array[$config_name] = (int) $cfg_array[$config_name];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Absolute path
|
|
|
4c79b5 |
case 'script_path':
|
|
|
4c79b5 |
if (!$cfg_array[$config_name])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$destination = str_replace('\\', '/', $cfg_array[$config_name]);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($destination !== '/')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Adjust destination path (no trailing slash)
|
|
|
4c79b5 |
if (substr($destination, -1, 1) == '/')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$destination = substr($destination, 0, -1);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$destination = str_replace(array('../', './'), '', $destination);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($destination[0] != '/')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$destination = '/' . $destination;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cfg_array[$config_name] = trim($destination);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Absolute path
|
|
|
4c79b5 |
case 'lang':
|
|
|
4c79b5 |
if (!$cfg_array[$config_name])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cfg_array[$config_name] = basename($cfg_array[$config_name]);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['WRONG_DATA_LANG'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Relative path (appended $phpbb_root_path)
|
|
|
4c79b5 |
case 'rpath':
|
|
|
4c79b5 |
case 'rwpath':
|
|
|
4c79b5 |
if (!$cfg_array[$config_name])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$destination = $cfg_array[$config_name];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Adjust destination path (no trailing slash)
|
|
|
4c79b5 |
if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$destination = substr($destination, 0, -1);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
|
|
|
4c79b5 |
if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$destination = '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cfg_array[$config_name] = trim($destination);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir...
|
|
|
4c79b5 |
case 'path':
|
|
|
4c79b5 |
case 'wpath':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$cfg_array[$config_name])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cfg_array[$config_name] = trim($cfg_array[$config_name]);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Make sure no NUL byte is present...
|
|
|
4c79b5 |
if (strpos($cfg_array[$config_name], "\0") !== false || strpos($cfg_array[$config_name], '%00') !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cfg_array[$config_name] = '';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!file_exists($phpbb_root_path . $cfg_array[$config_name]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check if the path is writable
|
|
|
4c79b5 |
if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !@is_writable($phpbb_root_path . $cfg_array[$config_name]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Checks whatever or not a variable is OK for use in the Database
|
|
|
4c79b5 |
* param mixed $value_ary An array of the form array(array('lang' => ..., 'value' => ..., 'column_type' =>))'
|
|
|
4c79b5 |
* param mixed $error The error array
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function validate_range($value_ary, &$error)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$column_types = array(
|
|
|
4c79b5 |
'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1),
|
|
|
4c79b5 |
'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535),
|
|
|
4c79b5 |
'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff),
|
|
|
4c79b5 |
'INT' => array('php_type' => 'int', 'min' => (int) 0x80000000, 'max' => (int) 0x7fffffff),
|
|
|
4c79b5 |
'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
foreach ($value_ary as $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$column = explode(':', $value['column_type']);
|
|
|
4c79b5 |
$max = $min = 0;
|
|
|
4c79b5 |
$type = 0;
|
|
|
4c79b5 |
if (!isset($column_types[$column[0]]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$type = $column_types[$column[0]];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($type['php_type'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'string' :
|
|
|
4c79b5 |
$max = (isset($column[1])) ? min($column[1],$type['max']) : $type['max'];
|
|
|
4c79b5 |
if (strlen($value['value']) > $max)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'int':
|
|
|
4c79b5 |
$min = (isset($column[1])) ? max($column[1],$type['min']) : $type['min'];
|
|
|
4c79b5 |
$max = (isset($column[2])) ? min($column[2],$type['max']) : $type['max'];
|
|
|
4c79b5 |
if ($value['value'] < $min)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$value['lang']], $min);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($value['value'] > $max)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$value['lang']], $max);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|