| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | *
|
|---|
| 4 | * @package acp
|
|---|
| 5 | * @version $Id$
|
|---|
| 6 | * @copyright (c) 2005 phpBB Group
|
|---|
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | */
|
|---|
| 13 | define('IN_PHPBB', true);
|
|---|
| 14 | define('ADMIN_START', true);
|
|---|
| 15 | define('NEED_SID', true);
|
|---|
| 16 |
|
|---|
| 17 | // Include files
|
|---|
| 18 | $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
|
|---|
| 19 | $phpEx = substr(strrchr(__FILE__, '.'), 1);
|
|---|
| 20 | require($phpbb_root_path . 'common.' . $phpEx);
|
|---|
| 21 | require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|---|
| 22 | require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
|
|---|
| 23 |
|
|---|
| 24 | // Start session management
|
|---|
| 25 | $user->session_begin();
|
|---|
| 26 | $auth->acl($user->data);
|
|---|
| 27 | $user->setup('acp/common');
|
|---|
| 28 | // End session management
|
|---|
| 29 |
|
|---|
| 30 | // Have they authenticated (again) as an admin for this session?
|
|---|
| 31 | if (!isset($user->data['session_admin']) || !$user->data['session_admin'])
|
|---|
| 32 | {
|
|---|
| 33 | login_box('', $user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], true, false);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | // Is user any type of admin? No, then stop here, each script needs to
|
|---|
| 37 | // check specific permissions but this is a catchall
|
|---|
| 38 | if (!$auth->acl_get('a_'))
|
|---|
| 39 | {
|
|---|
| 40 | trigger_error('NO_ADMIN');
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | // We define the admin variables now, because the user is now able to use the admin related features...
|
|---|
| 44 | define('IN_ADMIN', true);
|
|---|
| 45 | $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './';
|
|---|
| 46 |
|
|---|
| 47 | // Some oft used variables
|
|---|
| 48 | $safe_mode = (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) === 'on') ? true : false;
|
|---|
| 49 | $file_uploads = (@ini_get('file_uploads') == '1' || strtolower(@ini_get('file_uploads')) === 'on') ? true : false;
|
|---|
| 50 | $module_id = request_var('i', '');
|
|---|
| 51 | $mode = request_var('mode', '');
|
|---|
| 52 |
|
|---|
| 53 | // Set custom template for admin area
|
|---|
| 54 | $template->set_custom_template($phpbb_admin_path . 'style', 'admin');
|
|---|
| 55 | $template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
|
|---|
| 56 |
|
|---|
| 57 | // the acp template is never stored in the database
|
|---|
| 58 | $user->theme['template_storedb'] = false;
|
|---|
| 59 |
|
|---|
| 60 | // Instantiate new module
|
|---|
| 61 | $module = new p_master();
|
|---|
| 62 |
|
|---|
| 63 | // Instantiate module system and generate list of available modules
|
|---|
| 64 | $module->list_modules('acp');
|
|---|
| 65 |
|
|---|
| 66 | // Select the active module
|
|---|
| 67 | $module->set_active($module_id, $mode);
|
|---|
| 68 |
|
|---|
| 69 | // Assign data to the template engine for the list of modules
|
|---|
| 70 | // We do this before loading the active module for correct menu display in trigger_error
|
|---|
| 71 | $module->assign_tpl_vars(append_sid("{$phpbb_admin_path}index.$phpEx"));
|
|---|
| 72 |
|
|---|
| 73 | // Load and execute the relevant module
|
|---|
| 74 | $module->load_active();
|
|---|
| 75 |
|
|---|
| 76 | // Generate the page
|
|---|
| 77 | adm_page_header($module->get_page_title());
|
|---|
| 78 |
|
|---|
| 79 | $template->set_filenames(array(
|
|---|
| 80 | 'body' => $module->get_tpl_name(),
|
|---|
| 81 | ));
|
|---|
| 82 |
|
|---|
| 83 | adm_page_footer();
|
|---|
| 84 |
|
|---|
| 85 | /**
|
|---|
| 86 | * Header for acp pages
|
|---|
| 87 | */
|
|---|
| 88 | function adm_page_header($page_title)
|
|---|
| 89 | {
|
|---|
| 90 | global $config, $db, $user, $template;
|
|---|
| 91 | global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
|
|---|
| 92 |
|
|---|
| 93 | if (defined('HEADER_INC'))
|
|---|
| 94 | {
|
|---|
| 95 | return;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | define('HEADER_INC', true);
|
|---|
| 99 |
|
|---|
| 100 | // gzip_compression
|
|---|
| 101 | if ($config['gzip_compress'])
|
|---|
| 102 | {
|
|---|
| 103 | if (@extension_loaded('zlib') && !headers_sent())
|
|---|
| 104 | {
|
|---|
| 105 | ob_start('ob_gzhandler');
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | $template->assign_vars(array(
|
|---|
| 110 | 'PAGE_TITLE' => $page_title,
|
|---|
| 111 | 'USERNAME' => $user->data['username'],
|
|---|
| 112 |
|
|---|
| 113 | 'SID' => $SID,
|
|---|
| 114 | '_SID' => $_SID,
|
|---|
| 115 | 'SESSION_ID' => $user->session_id,
|
|---|
| 116 | 'ROOT_PATH' => $phpbb_admin_path,
|
|---|
| 117 |
|
|---|
| 118 | 'U_LOGOUT' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout'),
|
|---|
| 119 | 'U_ADM_LOGOUT' => append_sid("{$phpbb_admin_path}index.$phpEx", 'action=admlogout'),
|
|---|
| 120 | 'U_ADM_INDEX' => append_sid("{$phpbb_admin_path}index.$phpEx"),
|
|---|
| 121 | 'U_INDEX' => append_sid("{$phpbb_root_path}index.$phpEx"),
|
|---|
| 122 |
|
|---|
| 123 | 'T_IMAGES_PATH' => "{$phpbb_root_path}images/",
|
|---|
| 124 | 'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/",
|
|---|
| 125 | 'T_AVATAR_PATH' => "{$phpbb_root_path}{$config['avatar_path']}/",
|
|---|
| 126 | 'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
|
|---|
| 127 | 'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/",
|
|---|
| 128 | 'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/",
|
|---|
| 129 | 'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/",
|
|---|
| 130 |
|
|---|
| 131 | 'ICON_MOVE_UP' => '<img src="' . $phpbb_admin_path . 'images/icon_up.gif" alt="' . $user->lang['MOVE_UP'] . '" title="' . $user->lang['MOVE_UP'] . '" />',
|
|---|
| 132 | 'ICON_MOVE_UP_DISABLED' => '<img src="' . $phpbb_admin_path . 'images/icon_up_disabled.gif" alt="' . $user->lang['MOVE_UP'] . '" title="' . $user->lang['MOVE_UP'] . '" />',
|
|---|
| 133 | 'ICON_MOVE_DOWN' => '<img src="' . $phpbb_admin_path . 'images/icon_down.gif" alt="' . $user->lang['MOVE_DOWN'] . '" title="' . $user->lang['MOVE_DOWN'] . '" />',
|
|---|
| 134 | 'ICON_MOVE_DOWN_DISABLED' => '<img src="' . $phpbb_admin_path . 'images/icon_down_disabled.gif" alt="' . $user->lang['MOVE_DOWN'] . '" title="' . $user->lang['MOVE_DOWN'] . '" />',
|
|---|
| 135 | 'ICON_EDIT' => '<img src="' . $phpbb_admin_path . 'images/icon_edit.gif" alt="' . $user->lang['EDIT'] . '" title="' . $user->lang['EDIT'] . '" />',
|
|---|
| 136 | 'ICON_EDIT_DISABLED' => '<img src="' . $phpbb_admin_path . 'images/icon_edit_disabled.gif" alt="' . $user->lang['EDIT'] . '" title="' . $user->lang['EDIT'] . '" />',
|
|---|
| 137 | 'ICON_DELETE' => '<img src="' . $phpbb_admin_path . 'images/icon_delete.gif" alt="' . $user->lang['DELETE'] . '" title="' . $user->lang['DELETE'] . '" />',
|
|---|
| 138 | 'ICON_DELETE_DISABLED' => '<img src="' . $phpbb_admin_path . 'images/icon_delete_disabled.gif" alt="' . $user->lang['DELETE'] . '" title="' . $user->lang['DELETE'] . '" />',
|
|---|
| 139 | 'ICON_SYNC' => '<img src="' . $phpbb_admin_path . 'images/icon_sync.gif" alt="' . $user->lang['RESYNC'] . '" title="' . $user->lang['RESYNC'] . '" />',
|
|---|
| 140 | 'ICON_SYNC_DISABLED' => '<img src="' . $phpbb_admin_path . 'images/icon_sync_disabled.gif" alt="' . $user->lang['RESYNC'] . '" title="' . $user->lang['RESYNC'] . '" />',
|
|---|
| 141 |
|
|---|
| 142 | 'S_USER_LANG' => $user->lang['USER_LANG'],
|
|---|
| 143 | 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'],
|
|---|
| 144 | 'S_CONTENT_ENCODING' => 'UTF-8',
|
|---|
| 145 | 'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
|
|---|
| 146 | 'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
|
|---|
| 147 | ));
|
|---|
| 148 |
|
|---|
| 149 | // application/xhtml+xml not used because of IE
|
|---|
| 150 | header('Content-type: text/html; charset=UTF-8');
|
|---|
| 151 |
|
|---|
| 152 | header('Cache-Control: private, no-cache="set-cookie"');
|
|---|
| 153 | header('Expires: 0');
|
|---|
| 154 | header('Pragma: no-cache');
|
|---|
| 155 |
|
|---|
| 156 | return;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | /**
|
|---|
| 160 | * Page footer for acp pages
|
|---|
| 161 | */
|
|---|
| 162 | function adm_page_footer($copyright_html = true)
|
|---|
| 163 | {
|
|---|
| 164 | global $db, $config, $template, $user, $auth, $cache;
|
|---|
| 165 | global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
|---|
| 166 |
|
|---|
| 167 | // Output page creation time
|
|---|
| 168 | if (defined('DEBUG'))
|
|---|
| 169 | {
|
|---|
| 170 | $mtime = explode(' ', microtime());
|
|---|
| 171 | $totaltime = $mtime[0] + $mtime[1] - $starttime;
|
|---|
| 172 |
|
|---|
| 173 | if (!empty($_REQUEST['explain']) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report'))
|
|---|
| 174 | {
|
|---|
| 175 | $db->sql_report('display');
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
|
|---|
| 179 |
|
|---|
| 180 | if ($auth->acl_get('a_') && defined('DEBUG_EXTRA'))
|
|---|
| 181 | {
|
|---|
| 182 | if (function_exists('memory_get_usage'))
|
|---|
| 183 | {
|
|---|
| 184 | if ($memory_usage = memory_get_usage())
|
|---|
| 185 | {
|
|---|
| 186 | global $base_memory_usage;
|
|---|
| 187 | $memory_usage -= $base_memory_usage;
|
|---|
| 188 | $memory_usage = get_formatted_filesize($memory_usage);
|
|---|
| 189 |
|
|---|
| 190 | $debug_output .= ' | Memory Usage: ' . $memory_usage;
|
|---|
| 191 | }
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | $debug_output .= ' | <a href="' . build_url() . '&explain=1">Explain</a>';
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | $template->assign_vars(array(
|
|---|
| 199 | 'DEBUG_OUTPUT' => (defined('DEBUG')) ? $debug_output : '',
|
|---|
| 200 | 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
|
|---|
| 201 | 'S_COPYRIGHT_HTML' => $copyright_html,
|
|---|
| 202 | 'VERSION' => $config['version'])
|
|---|
| 203 | );
|
|---|
| 204 |
|
|---|
| 205 | $template->display('body');
|
|---|
| 206 |
|
|---|
| 207 | garbage_collection();
|
|---|
| 208 | exit_handler();
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | /**
|
|---|
| 212 | * Generate back link for acp pages
|
|---|
| 213 | */
|
|---|
| 214 | function adm_back_link($u_action)
|
|---|
| 215 | {
|
|---|
| 216 | global $user;
|
|---|
| 217 | return '<br /><br /><a href="' . $u_action . '">« ' . $user->lang['BACK_TO_PREV'] . '</a>';
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | /**
|
|---|
| 221 | * Build select field options in acp pages
|
|---|
| 222 | */
|
|---|
| 223 | function build_select($option_ary, $option_default = false)
|
|---|
| 224 | {
|
|---|
| 225 | global $user;
|
|---|
| 226 |
|
|---|
| 227 | $html = '';
|
|---|
| 228 | foreach ($option_ary as $value => $title)
|
|---|
| 229 | {
|
|---|
| 230 | $selected = ($option_default !== false && $value == $option_default) ? ' selected="selected"' : '';
|
|---|
| 231 | $html .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$title] . '</option>';
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | return $html;
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | /**
|
|---|
| 238 | * Build radio fields in acp pages
|
|---|
| 239 | */
|
|---|
| 240 | function h_radio($name, &$input_ary, $input_default = false, $id = false, $key = false)
|
|---|
| 241 | {
|
|---|
| 242 | global $user;
|
|---|
| 243 |
|
|---|
| 244 | $html = '';
|
|---|
| 245 | $id_assigned = false;
|
|---|
| 246 | foreach ($input_ary as $value => $title)
|
|---|
| 247 | {
|
|---|
| 248 | $selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : '';
|
|---|
| 249 | $html .= '<label><input type="radio" name="' . $name . '"' . (($id && !$id_assigned) ? ' id="' . $id . '"' : '') . ' value="' . $value . '"' . $selected . (($key) ? ' accesskey="' . $key . '"' : '') . ' class="radio" /> ' . $user->lang[$title] . '</label>';
|
|---|
| 250 | $id_assigned = true;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | return $html;
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | /**
|
|---|
| 257 | * Build configuration template for acp configuration pages
|
|---|
| 258 | */
|
|---|
| 259 | function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
|
|---|
| 260 | {
|
|---|
| 261 | global $user, $module;
|
|---|
| 262 |
|
|---|
| 263 | $tpl = '';
|
|---|
| 264 | $name = 'config[' . $config_key . ']';
|
|---|
| 265 |
|
|---|
| 266 | // Make sure there is no notice printed out for non-existent config options (we simply set them)
|
|---|
| 267 | if (!isset($new[$config_key]))
|
|---|
| 268 | {
|
|---|
| 269 | $new[$config_key] = '';
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | switch ($tpl_type[0])
|
|---|
| 273 | {
|
|---|
| 274 | case 'text':
|
|---|
| 275 | case 'password':
|
|---|
| 276 | $size = (int) $tpl_type[1];
|
|---|
| 277 | $maxlength = (int) $tpl_type[2];
|
|---|
| 278 |
|
|---|
| 279 | $tpl = '<input id="' . $key . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $new[$config_key] . '" />';
|
|---|
| 280 | break;
|
|---|
| 281 |
|
|---|
| 282 | case 'dimension':
|
|---|
| 283 | $size = (int) $tpl_type[1];
|
|---|
| 284 | $maxlength = (int) $tpl_type[2];
|
|---|
| 285 |
|
|---|
| 286 | $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'] . '" />';
|
|---|
| 287 | break;
|
|---|
| 288 |
|
|---|
| 289 | case 'textarea':
|
|---|
| 290 | $rows = (int) $tpl_type[1];
|
|---|
| 291 | $cols = (int) $tpl_type[2];
|
|---|
| 292 |
|
|---|
| 293 | $tpl = '<textarea id="' . $key . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $new[$config_key] . '</textarea>';
|
|---|
| 294 | break;
|
|---|
| 295 |
|
|---|
| 296 | case 'radio':
|
|---|
| 297 | $key_yes = ($new[$config_key]) ? ' checked="checked"' : '';
|
|---|
| 298 | $key_no = (!$new[$config_key]) ? ' checked="checked"' : '';
|
|---|
| 299 |
|
|---|
| 300 | $tpl_type_cond = explode('_', $tpl_type[1]);
|
|---|
| 301 | $type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
|
|---|
| 302 |
|
|---|
| 303 | $tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
|
|---|
| 304 | $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>';
|
|---|
| 305 |
|
|---|
| 306 | $tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . $tpl_no : $tpl_no . $tpl_yes;
|
|---|
| 307 | break;
|
|---|
| 308 |
|
|---|
| 309 | case 'select':
|
|---|
| 310 | case 'custom':
|
|---|
| 311 |
|
|---|
| 312 | $return = '';
|
|---|
| 313 |
|
|---|
| 314 | if (isset($vars['method']))
|
|---|
| 315 | {
|
|---|
| 316 | $call = array($module->module, $vars['method']);
|
|---|
| 317 | }
|
|---|
| 318 | else if (isset($vars['function']))
|
|---|
| 319 | {
|
|---|
| 320 | $call = $vars['function'];
|
|---|
| 321 | }
|
|---|
| 322 | else
|
|---|
| 323 | {
|
|---|
| 324 | break;
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | if (isset($vars['params']))
|
|---|
| 328 | {
|
|---|
| 329 | $args = array();
|
|---|
| 330 | foreach ($vars['params'] as $value)
|
|---|
| 331 | {
|
|---|
| 332 | switch ($value)
|
|---|
| 333 | {
|
|---|
| 334 | case '{CONFIG_VALUE}':
|
|---|
| 335 | $value = $new[$config_key];
|
|---|
| 336 | break;
|
|---|
| 337 |
|
|---|
| 338 | case '{KEY}':
|
|---|
| 339 | $value = $key;
|
|---|
| 340 | break;
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | $args[] = $value;
|
|---|
| 344 | }
|
|---|
| 345 | }
|
|---|
| 346 | else
|
|---|
| 347 | {
|
|---|
| 348 | $args = array($new[$config_key], $key);
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | $return = call_user_func_array($call, $args);
|
|---|
| 352 |
|
|---|
| 353 | if ($tpl_type[0] == 'select')
|
|---|
| 354 | {
|
|---|
| 355 | $tpl = '<select id="' . $key . '" name="' . $name . '">' . $return . '</select>';
|
|---|
| 356 | }
|
|---|
| 357 | else
|
|---|
| 358 | {
|
|---|
| 359 | $tpl = $return;
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | break;
|
|---|
| 363 |
|
|---|
| 364 | default:
|
|---|
| 365 | break;
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | if (isset($vars['append']))
|
|---|
| 369 | {
|
|---|
| 370 | $tpl .= $vars['append'];
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | return $tpl;
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | /**
|
|---|
| 377 | * Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int.
|
|---|
| 378 | * 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.
|
|---|
| 379 | */
|
|---|
| 380 | function validate_config_vars($config_vars, &$cfg_array, &$error)
|
|---|
| 381 | {
|
|---|
| 382 | global $phpbb_root_path, $user;
|
|---|
| 383 | $type = 0;
|
|---|
| 384 | $min = 1;
|
|---|
| 385 | $max = 2;
|
|---|
| 386 |
|
|---|
| 387 | foreach ($config_vars as $config_name => $config_definition)
|
|---|
| 388 | {
|
|---|
| 389 | if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
|
|---|
| 390 | {
|
|---|
| 391 | continue;
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | if (!isset($config_definition['validate']))
|
|---|
| 395 | {
|
|---|
| 396 | continue;
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | $validator = explode(':', $config_definition['validate']);
|
|---|
| 400 |
|
|---|
| 401 | // Validate a bit. ;) (0 = type, 1 = min, 2= max)
|
|---|
| 402 | switch ($validator[$type])
|
|---|
| 403 | {
|
|---|
| 404 | case 'string':
|
|---|
| 405 | $length = strlen($cfg_array[$config_name]);
|
|---|
| 406 |
|
|---|
| 407 | // the column is a VARCHAR
|
|---|
| 408 | $validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255;
|
|---|
| 409 |
|
|---|
| 410 | if (isset($validator[$min]) && $length < $validator[$min])
|
|---|
| 411 | {
|
|---|
| 412 | $error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]);
|
|---|
| 413 | }
|
|---|
| 414 | else if (isset($validator[$max]) && $length > $validator[2])
|
|---|
| 415 | {
|
|---|
| 416 | $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]);
|
|---|
| 417 | }
|
|---|
| 418 | break;
|
|---|
| 419 |
|
|---|
| 420 | case 'bool':
|
|---|
| 421 | $cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0;
|
|---|
| 422 | break;
|
|---|
| 423 |
|
|---|
| 424 | case 'int':
|
|---|
| 425 | $cfg_array[$config_name] = (int) $cfg_array[$config_name];
|
|---|
| 426 |
|
|---|
| 427 | if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min])
|
|---|
| 428 | {
|
|---|
| 429 | $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]);
|
|---|
| 430 | }
|
|---|
| 431 | else if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max])
|
|---|
| 432 | {
|
|---|
| 433 | $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]);
|
|---|
| 434 | }
|
|---|
| 435 | break;
|
|---|
| 436 |
|
|---|
| 437 | // Absolute path
|
|---|
| 438 | case 'script_path':
|
|---|
| 439 | if (!$cfg_array[$config_name])
|
|---|
| 440 | {
|
|---|
| 441 | break;
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | $destination = str_replace('\\', '/', $cfg_array[$config_name]);
|
|---|
| 445 |
|
|---|
| 446 | if ($destination !== '/')
|
|---|
| 447 | {
|
|---|
| 448 | // Adjust destination path (no trailing slash)
|
|---|
| 449 | if (substr($destination, -1, 1) == '/')
|
|---|
| 450 | {
|
|---|
| 451 | $destination = substr($destination, 0, -1);
|
|---|
| 452 | }
|
|---|
| 453 |
|
|---|
| 454 | $destination = str_replace(array('../', './'), '', $destination);
|
|---|
| 455 |
|
|---|
| 456 | if ($destination[0] != '/')
|
|---|
| 457 | {
|
|---|
| 458 | $destination = '/' . $destination;
|
|---|
| 459 | }
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | $cfg_array[$config_name] = trim($destination);
|
|---|
| 463 |
|
|---|
| 464 | break;
|
|---|
| 465 |
|
|---|
| 466 | // Absolute path
|
|---|
| 467 | case 'lang':
|
|---|
| 468 | if (!$cfg_array[$config_name])
|
|---|
| 469 | {
|
|---|
| 470 | break;
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | $cfg_array[$config_name] = basename($cfg_array[$config_name]);
|
|---|
| 474 |
|
|---|
| 475 | if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/'))
|
|---|
| 476 | {
|
|---|
| 477 | $error[] = $user->lang['WRONG_DATA_LANG'];
|
|---|
| 478 | }
|
|---|
| 479 | break;
|
|---|
| 480 |
|
|---|
| 481 | // Relative path (appended $phpbb_root_path)
|
|---|
| 482 | case 'rpath':
|
|---|
| 483 | case 'rwpath':
|
|---|
| 484 | if (!$cfg_array[$config_name])
|
|---|
| 485 | {
|
|---|
| 486 | break;
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | $destination = $cfg_array[$config_name];
|
|---|
| 490 |
|
|---|
| 491 | // Adjust destination path (no trailing slash)
|
|---|
| 492 | if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
|
|---|
| 493 | {
|
|---|
| 494 | $destination = substr($destination, 0, -1);
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
|
|---|
| 498 | if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
|
|---|
| 499 | {
|
|---|
| 500 | $destination = '';
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | $cfg_array[$config_name] = trim($destination);
|
|---|
| 504 |
|
|---|
| 505 | // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir...
|
|---|
| 506 | case 'path':
|
|---|
| 507 | case 'wpath':
|
|---|
| 508 |
|
|---|
| 509 | if (!$cfg_array[$config_name])
|
|---|
| 510 | {
|
|---|
| 511 | break;
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | $cfg_array[$config_name] = trim($cfg_array[$config_name]);
|
|---|
| 515 |
|
|---|
| 516 | // Make sure no NUL byte is present...
|
|---|
| 517 | if (strpos($cfg_array[$config_name], "\0") !== false || strpos($cfg_array[$config_name], '%00') !== false)
|
|---|
| 518 | {
|
|---|
| 519 | $cfg_array[$config_name] = '';
|
|---|
| 520 | break;
|
|---|
| 521 | }
|
|---|
| 522 |
|
|---|
| 523 | if (!file_exists($phpbb_root_path . $cfg_array[$config_name]))
|
|---|
| 524 | {
|
|---|
| 525 | $error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]);
|
|---|
| 526 | }
|
|---|
| 527 |
|
|---|
| 528 | if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name]))
|
|---|
| 529 | {
|
|---|
| 530 | $error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]);
|
|---|
| 531 | }
|
|---|
| 532 |
|
|---|
| 533 | // Check if the path is writable
|
|---|
| 534 | if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath')
|
|---|
| 535 | {
|
|---|
| 536 | if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !@is_writable($phpbb_root_path . $cfg_array[$config_name]))
|
|---|
| 537 | {
|
|---|
| 538 | $error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]);
|
|---|
| 539 | }
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | break;
|
|---|
| 543 | }
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | return;
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | /**
|
|---|
| 550 | * Checks whatever or not a variable is OK for use in the Database
|
|---|
| 551 | * param mixed $value_ary An array of the form array(array('lang' => ..., 'value' => ..., 'column_type' =>))'
|
|---|
| 552 | * param mixed $error The error array
|
|---|
| 553 | */
|
|---|
| 554 | function validate_range($value_ary, &$error)
|
|---|
| 555 | {
|
|---|
| 556 | global $user;
|
|---|
| 557 |
|
|---|
| 558 | $column_types = array(
|
|---|
| 559 | 'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1),
|
|---|
| 560 | 'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535),
|
|---|
| 561 | 'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff),
|
|---|
| 562 | 'INT' => array('php_type' => 'int', 'min' => (int) 0x80000000, 'max' => (int) 0x7fffffff),
|
|---|
| 563 | 'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127),
|
|---|
| 564 |
|
|---|
| 565 | 'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255),
|
|---|
| 566 | );
|
|---|
| 567 | foreach ($value_ary as $value)
|
|---|
| 568 | {
|
|---|
| 569 | $column = explode(':', $value['column_type']);
|
|---|
| 570 | $max = $min = 0;
|
|---|
| 571 | $type = 0;
|
|---|
| 572 | if (!isset($column_types[$column[0]]))
|
|---|
| 573 | {
|
|---|
| 574 | continue;
|
|---|
| 575 | }
|
|---|
| 576 | else
|
|---|
| 577 | {
|
|---|
| 578 | $type = $column_types[$column[0]];
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | switch ($type['php_type'])
|
|---|
| 582 | {
|
|---|
| 583 | case 'string' :
|
|---|
| 584 | $max = (isset($column[1])) ? min($column[1],$type['max']) : $type['max'];
|
|---|
| 585 | if (strlen($value['value']) > $max)
|
|---|
| 586 | {
|
|---|
| 587 | $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max);
|
|---|
| 588 | }
|
|---|
| 589 | break;
|
|---|
| 590 |
|
|---|
| 591 | case 'int':
|
|---|
| 592 | $min = (isset($column[1])) ? max($column[1],$type['min']) : $type['min'];
|
|---|
| 593 | $max = (isset($column[2])) ? min($column[2],$type['max']) : $type['max'];
|
|---|
| 594 | if ($value['value'] < $min)
|
|---|
| 595 | {
|
|---|
| 596 | $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$value['lang']], $min);
|
|---|
| 597 | }
|
|---|
| 598 | else if ($value['value'] > $max)
|
|---|
| 599 | {
|
|---|
| 600 | $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$value['lang']], $max);
|
|---|
| 601 | }
|
|---|
| 602 | break;
|
|---|
| 603 | }
|
|---|
| 604 | }
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | ?>
|
|---|