1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
|
<?php
/**
* Function library read in upon startup
*
* $Id: lib.inc.php,v 1.123 2008/04/06 01:10:35 xzilla Exp $
*/
include_once('./libraries/decorator.inc.php');
include_once('./lang/translations.php');
// Do not show depreciation warnings.
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
// Application name
$appName = 'phpPgAdmin';
// Application version
$appVersion = '7.14.7-mod';
// PostgreSQL and PHP minimum version
global $postgresqlMinVer;
$postgresqlMinVer = '7.4';
$phpMinVer = '7.2';
// Check the version of PHP
if (version_compare(phpversion(), $phpMinVer, '<'))
exit(sprintf('Version of PHP not supported. Please upgrade to version %s or later.', $phpMinVer));
// Check to see if the configuration file exists, if not, explain
if (file_exists('conf/config.inc.php')) {
$conf = array();
include('./conf/config.inc.php');
}
else {
echo 'Configuration error: Copy conf/config.inc.php-dist to conf/config.inc.php and edit appropriately.';
exit;
}
// Configuration file version. If this is greater than that in config.inc.php, then
// the app will refuse to run. This and $conf['version'] should be incremented whenever
// backwards incompatible changes are made to config.inc.php-dist.
$conf['base_version'] = 16;
// Always include english.php, since it's the master language file
if (!isset($conf['default_lang'])) $conf['default_lang'] = 'english';
$lang = array();
require_once('./lang/english.php');
// Create Misc class references
require_once('./classes/Misc.php');
$misc = new Misc();
// Session start: if extra_session_security is on, make sure cookie_samesite
// is on (exit if we fail); otherwise, just start the session
$our_session_name = 'PPA_ID';
if (($conf['extra_session_security'] ?? true) === true) {
if (version_compare(phpversion(), '7.3', '<')) {
exit('phpPgAdmin cannot be fully secured while running under PHP versions before 7.3. Please upgrade PHP if possible. If you cannot upgrade, and you\'re willing to assume the risk of CSRF attacks, you can change the value of "extra_session_security" to false in your config.inc.php file.');
}
if (ini_get('session.auto_start')) {
// If session.auto_start is on, and the session doesn't have
// session.cookie_samesite set, destroy and re-create the session
if (session_name() !== $our_session_name) {
$setting = strtolower(ini_get('session.cookie_samesite'));
if ($setting !== 'lax' && $setting !== 'strict') {
session_destroy();
session_name($our_session_name);
ini_set('session.cookie_samesite', 'Strict');
session_start();
}
}
} else {
session_name($our_session_name);
ini_set('session.cookie_samesite', 'Strict');
session_start();
}
} else {
if (!ini_get('session.auto_start')) {
session_name($our_session_name);
session_start();
}
}
$misc->setHREF();
$misc->setForm();
// Enforce PHP environment
ini_set('arg_separator.output', '&');
// If login action is set, then set session variables
if (isset($_POST['loginServer']) && isset($_POST['loginUsername']) &&
isset($_POST['loginPassword_'.md5($_POST['loginServer'])])) {
$_server_info = $misc->getServerInfo($_POST['loginServer']);
$_server_info['username'] = $_POST['loginUsername'];
$_server_info['password'] = $_POST['loginPassword_'.md5($_POST['loginServer'])];
$misc->setServerInfo(null, $_server_info, $_POST['loginServer']);
// Check for shared credentials
if (isset($_POST['loginShared'])) {
$_SESSION['sharedUsername'] = $_POST['loginUsername'];
$_SESSION['sharedPassword'] = $_POST['loginPassword_'.md5($_POST['loginServer'])];
}
$_reload_browser = true;
}
/* select the theme */
unset($_theme);
if (!isset($conf['theme']))
$conf['theme'] = 'default';
// 1. Check for the theme from a request var
if (isset($_REQUEST['theme']) && is_file("./themes/{$_REQUEST['theme']}/global.css")) {
/* save the selected theme in cookie for a year */
setcookie('ppaTheme', $_REQUEST['theme'], time()+31536000);
$_theme = $_SESSION['ppaTheme'] = $conf['theme'] = $_REQUEST['theme'];
}
// 2. Check for theme session var
if (!isset($_theme) && isset($_SESSION['ppaTheme']) && is_file("./themes/{$_SESSION['ppaTheme']}/global.css")) {
$conf['theme'] = $_SESSION['ppaTheme'];
}
// 3. Check for theme in cookie var
if (!isset($_theme) && isset($_COOKIE['ppaTheme']) && is_file("./themes/{$_COOKIE['ppaTheme']}/global.css")) {
$conf['theme'] = $_COOKIE['ppaTheme'];
}
// 4. Check for theme by server/db/user
$info = $misc->getServerInfo();
if (!is_null($info)) {
$_theme = '';
if ( (isset($info['theme']['default']))
and is_file("./themes/{$info['theme']['default']}/global.css")
)
$_theme = $info['theme']['default'];
if ( isset($_REQUEST['database'])
and isset($info['theme']['db'][$_REQUEST['database']])
and is_file("./themes/{$info['theme']['db'][$_REQUEST['database']]}/global.css")
)
$_theme = $info['theme']['db'][$_REQUEST['database']];
if ( isset($info['username'])
and isset($info['theme']['user'][$info['username']])
and is_file("./themes/{$info['theme']['user'][$info['username']]}/global.css")
)
$_theme = $info['theme']['user'][$info['username']];
if ($_theme !== '') {
setcookie('ppaTheme', $_theme, time()+31536000);
$conf['theme'] = $_theme;
}
}
// Determine language file to import:
unset($_language);
// 1. Check for the language from a request var
if (isset($_REQUEST['language']) && isset($appLangFiles[$_REQUEST['language']])) {
/* save the selected language in cookie for a year */
setcookie('webdbLanguage', $_REQUEST['language'], time()+31536000);
$_language = $_REQUEST['language'];
}
// 2. Check for language session var
if (!isset($_language) && isset($_SESSION['webdbLanguage']) && isset($appLangFiles[$_SESSION['webdbLanguage']])) {
$_language = $_SESSION['webdbLanguage'];
}
// 3. Check for language in cookie var
if (!isset($_language) && isset($_COOKIE['webdbLanguage']) && isset($appLangFiles[$_COOKIE['webdbLanguage']])) {
$_language = $_COOKIE['webdbLanguage'];
}
// 4. Check for acceptable languages in HTTP_ACCEPT_LANGUAGE var
if (!isset($_language) && $conf['default_lang'] == 'auto' && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
// extract acceptable language tags
// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4)
preg_match_all('/\s*([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;q=([01](?:.[0-9]{0,3})?))?\s*(?:,|$)/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']), $_m, PREG_SET_ORDER);
foreach($_m as $_l) { // $_l[1] = language tag, [2] = quality
if (!isset($_l[2])) $_l[2] = 1; // Default quality to 1
if ($_l[2] > 0 && $_l[2] <= 1 && isset($availableLanguages[$_l[1]])) {
// Build up array of (quality => language_file)
$_acceptLang[$_l[2]] = $availableLanguages[$_l[1]];
}
}
unset($_m);
unset($_l);
if (isset($_acceptLang)) {
// Sort acceptable languages by quality
krsort($_acceptLang, SORT_NUMERIC);
$_language = reset($_acceptLang);
unset($_acceptLang);
}
}
// 5. Otherwise resort to the default set in the config file
if (!isset($_language) && $conf['default_lang'] != 'auto' && isset($appLangFiles[$conf['default_lang']])) {
$_language = $conf['default_lang'];
}
// 6. Otherwise, default to english.
if (!isset($_language))
$_language = 'english';
// Import the language file
if (isset($_language)) {
include("./lang/{$_language}.php");
$_SESSION['webdbLanguage'] = $_language;
}
// Check for config file version mismatch
if (!isset($conf['version']) || $conf['base_version'] > $conf['version']) {
echo $lang['strbadconfig'];
exit;
}
// Check php libraries
$php_libraries_requirements = [
// required_function => name_of_the_php_library
'pg_connect' => 'pgsql',
'mb_strlen' => 'mbstring'];
$missing_libraries = [];
foreach($php_libraries_requirements as $funcname => $lib)
if (!function_exists($funcname))
$missing_libraries[] = $lib;
if ($missing_libraries) {
$missing_list = implode(', ', $missing_libraries);
$error_missing_template_string = count($missing_libraries) <= 1 ? $lang['strlibnotfound'] : $lang['strlibnotfound_plural'];
printf($error_missing_template_string, $missing_list);
exit;
}
// Manage the plugins
require_once('./classes/PluginManager.php');
// Create data accessor object, if necessary
if (!isset($_no_db_connection)) {
if (!isset($_REQUEST['server'])) {
echo $lang['strnoserversupplied'];
exit;
}
$_server_info = $misc->getServerInfo();
/* starting with PostgreSQL 9.0, we can set the application name */
if(isset($_server_info['pgVersion']) && version_compare($_server_info['pgVersion'], '9', '>='))
putenv("PGAPPNAME={$appName}_{$appVersion}");
// Redirect to the login form if not logged in
if (!isset($_server_info['username'])) {
include('./login.php');
exit;
}
// Connect to the current database, or if one is not specified
// then connect to the default database.
if (isset($_REQUEST['database']))
$_curr_db = $_REQUEST['database'];
else
$_curr_db = $_server_info['defaultdb'];
include_once('./classes/database/Connection.php');
// Connect to database and set the global $data variable
$data = $misc->getDatabaseAccessor($_curr_db);
// If schema is defined and database supports schemas, then set the
// schema explicitly.
if (isset($_REQUEST['database']) && isset($_REQUEST['schema'])) {
$status = $data->setSchema($_REQUEST['schema']);
if ($status != 0) {
echo $lang['strbadschema'];
exit;
}
}
}
$plugin_manager = new PluginManager($_language);
/**
* Safe unserializer wrapper
*
* It does not unserialize data containing objects
*
* Function from phpMyAdmin version 5.2.1
*
* @param string $data Data to unserialize
*
* @return mixed|null
*/
function safeUnserialize(string $data) {
/* validate serialized data */
$length = strlen($data);
$depth = 0;
for ($i = 0; $i < $length; $i++) {
$value = $data[$i];
switch ($value) {
case '}':
/* end of array */
if ($depth <= 0) {
return null;
}
$depth--;
break;
case 's':
/* string */
// parse sting length
$strlen = intval(substr($data, $i + 2));
// string start
$i = strpos($data, ':', $i + 2);
if ($i === false) {
return null;
}
// skip string, quotes and ;
$i += 2 + $strlen + 1;
if ($data[$i] !== ';') {
return null;
}
break;
case 'b':
case 'i':
case 'd':
/* bool, integer or double */
// skip value to separator
$i = strpos($data, ';', $i);
if ($i === false) {
return null;
}
break;
case 'a':
/* array */
// find array start
$i = strpos($data, '{', $i);
if ($i === false) {
return null;
}
// remember nesting
$depth++;
break;
case 'N':
/* null */
// skip to end
$i = strpos($data, ';', $i);
if ($i === false) {
return null;
}
break;
default:
/* any other elements are not wanted */
return null;
}
}
// check unterminated arrays
if ($depth > 0) {
return null;
}
return unserialize($data);
}
|