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
|
<?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');
// Set error reporting level to max
error_reporting(E_ALL);
// Application name
$appName = 'phpPgAdmin';
// Application version
$appVersion = '4.2.3';
// PostgreSQL and PHP minimum version
$postgresqlMinVer = '7.0';
$phpMinVer = '4.1';
// 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/recoded/english.php');
// Create Misc class references
require_once('./classes/Misc.php');
$misc = new Misc();
// Start session (if not auto-started)
if (!ini_get('session.auto_start')) {
session_name('PPA_ID');
session_start();
}
// Do basic PHP configuration checks
if (ini_get('magic_quotes_gpc')) {
$misc->stripVar($_GET);
$misc->stripVar($_POST);
$misc->stripVar($_COOKIE);
$misc->stripVar($_REQUEST);
}
// This has to be deferred until after stripVar above
$misc->setHREF();
$misc->setForm();
// Enforce PHP environment
ini_set('magic_quotes_gpc', 0);
ini_set('magic_quotes_runtime', 0);
ini_set('magic_quotes_sybase', 0);
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;
}
// Determine language file to import:
unset($_language);
// 1. Check for the language from a request var
if (isset($_REQUEST['language']) && isset($appLangFiles[$_REQUEST['language']]))
$_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 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);
}
}
// 4. 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'];
}
// Import the language file
if (isset($_language)) {
include("./lang/recoded/{$_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 database support is properly compiled in
if (!function_exists('pg_connect')) {
echo $lang['strnotloaded'];
exit;
}
// Create data accessor object, if necessary
if (!isset($_no_db_connection)) {
if (!isset($_REQUEST['server'])) {
echo $lang['strnoserversupplied'];
exit;
}
$_server_info = $misc->getServerInfo();
// 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']) && $data->hasSchemas()) {
$status = $data->setSchema($_REQUEST['schema']);
if ($status != 0) {
echo $lang['strbadschema'];
exit;
}
}
// Get database encoding
$dbEncoding = $data->getDatabaseEncoding();
// Set client encoding to database encoding
if ($dbEncoding != '') {
// Explicitly change client encoding if it's different to server encoding.
if (function_exists('pg_client_encoding'))
$currEncoding = pg_client_encoding($data->conn->_connectionID);
elseif (function_exists('pg_clientencoding'))
$currEncoding = pg_clientencoding($data->conn->_connectionID);
else
$currEncoding = null;
if ($currEncoding != $dbEncoding) {
$status = $data->setClientEncoding($dbEncoding);
if ($status != 0 && $status != -99) {
echo $lang['strbadencoding'];
exit;
}
}
// Override $lang['appcharset']
if (isset($data->codemap[$dbEncoding]))
$lang['appcharset'] = $data->codemap[$dbEncoding];
else
$lang['appcharset'] = $dbEncoding;
}
// Load Slony if required
if ($_server_info['slony_support']) {
include('./classes/plugins/Slony.php');
$slony = new Slony();
}
}
if (!function_exists("htmlspecialchars_decode")) {
function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) {
return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
}
}
?>
|