1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Function library read in upon startup
|
5
|
*
|
6
|
* $Id: lib.inc.php,v 1.105.2.3 2005/11/23 04:31:10 chriskl Exp $
|
7
|
*/
|
8
|
include_once('decorator.inc.php');
|
9
|
include_once('./lang/translations.php');
|
10
|
|
11
|
// Set error reporting level to max
|
12
|
error_reporting(E_ALL);
|
13
|
|
14
|
// Application name
|
15
|
$appName = 'phpPgAdmin';
|
16
|
|
17
|
// Application version
|
18
|
$appVersion = '4.0.1';
|
19
|
|
20
|
// PostgreSQL and PHP minimum version
|
21
|
$postgresqlMinVer = '7.0';
|
22
|
$phpMinVer = '4.1';
|
23
|
|
24
|
// Check the version of PHP
|
25
|
if (version_compare(phpversion(), $phpMinVer, '<'))
|
26
|
exit(sprintf('Version of PHP not supported. Please upgrade to version %s or later.', $phpMinVer));
|
27
|
|
28
|
// Check to see if the configuration file exists, if not, explain
|
29
|
if (file_exists('conf/config.inc.php')) {
|
30
|
$conf = array();
|
31
|
include('./conf/config.inc.php');
|
32
|
}
|
33
|
else {
|
34
|
echo 'Configuration error: Copy conf/config.inc.php-dist to conf/config.inc.php and edit appropriately.';
|
35
|
exit;
|
36
|
}
|
37
|
|
38
|
// Configuration file version. If this is greater than that in config.inc.php, then
|
39
|
// the app will refuse to run. This and $conf['version'] should be incremented whenever
|
40
|
// backwards incompatible changes are made to config.inc.php-dist.
|
41
|
$conf['base_version'] = 15;
|
42
|
|
43
|
// Always include english.php, since it's the master language file
|
44
|
if (!isset($conf['default_lang'])) $conf['default_lang'] = 'english';
|
45
|
$lang = array();
|
46
|
require_once('./lang/recoded/english.php');
|
47
|
|
48
|
// Create Misc class references
|
49
|
require_once('./classes/Misc.php');
|
50
|
$misc = new Misc();
|
51
|
|
52
|
// Start session (if not auto-started)
|
53
|
if (!ini_get('session.auto_start')) {
|
54
|
session_name('PPA_ID');
|
55
|
session_start();
|
56
|
}
|
57
|
|
58
|
// Do basic PHP configuration checks
|
59
|
if (ini_get('magic_quotes_gpc')) {
|
60
|
$misc->stripVar($_GET);
|
61
|
$misc->stripVar($_POST);
|
62
|
$misc->stripVar($_COOKIE);
|
63
|
$misc->stripVar($_REQUEST);
|
64
|
}
|
65
|
|
66
|
// This has to be deferred until after stripVar above
|
67
|
$misc->setHREF();
|
68
|
$misc->setForm();
|
69
|
|
70
|
// Enforce PHP environment
|
71
|
ini_set('magic_quotes_gpc', 0);
|
72
|
ini_set('magic_quotes_runtime', 0);
|
73
|
ini_set('magic_quotes_sybase', 0);
|
74
|
ini_set('arg_separator.output', '&');
|
75
|
|
76
|
// If login action is set, then set session variables
|
77
|
if (isset($_POST['loginServer']) && isset($_POST['loginUsername']) &&
|
78
|
isset($_POST['loginPassword'])) {
|
79
|
|
80
|
$_server_info = $misc->getServerInfo($_POST['loginServer']);
|
81
|
|
82
|
$_server_info['username'] = $_POST['loginUsername'];
|
83
|
$_server_info['password'] = $_POST['loginPassword'];
|
84
|
|
85
|
$misc->setServerInfo(null, $_server_info, $_POST['loginServer']);
|
86
|
|
87
|
// Check for shared credentials
|
88
|
if (isset($_POST['loginShared'])) {
|
89
|
$_SESSION['sharedUsername'] = $_POST['loginUsername'];
|
90
|
$_SESSION['sharedPassword'] = $_POST['loginPassword'];
|
91
|
}
|
92
|
|
93
|
$_reload_browser = true;
|
94
|
}
|
95
|
|
96
|
// Determine language file to import:
|
97
|
// 1. Check for the language from a request var
|
98
|
if (isset($_REQUEST['language']) && isset($appLangFiles[$_REQUEST['language']]))
|
99
|
$_language = $_REQUEST['language'];
|
100
|
|
101
|
// 2. Check for language session var
|
102
|
if (!isset($_language) && isset($_SESSION['webdbLanguage']) && isset($appLangFiles[$_SESSION['webdbLanguage']])) {
|
103
|
$_language = $_SESSION['webdbLanguage'];
|
104
|
}
|
105
|
|
106
|
// 3. Check for acceptable languages in HTTP_ACCEPT_LANGUAGE var
|
107
|
if (!isset($_language) && $conf['default_lang'] == 'auto' && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
108
|
// extract acceptable language tags
|
109
|
// (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4)
|
110
|
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);
|
111
|
foreach($_m as $_l) { // $_l[1] = language tag, [2] = quality
|
112
|
if (!isset($_l[2])) $_l[2] = 1; // Default quality to 1
|
113
|
if ($_l[2] > 0 && $_l[2] <= 1 && isset($availableLanguages[$_l[1]])) {
|
114
|
// Build up array of (quality => language_file)
|
115
|
$_acceptLang[$_l[2]] = $availableLanguages[$_l[1]];
|
116
|
}
|
117
|
}
|
118
|
unset($_m);
|
119
|
unset($_l);
|
120
|
if (isset($_acceptLang)) {
|
121
|
// Sort acceptable languages by quality
|
122
|
krsort($_acceptLang, SORT_NUMERIC);
|
123
|
$_language = reset($_acceptLang);
|
124
|
unset($_acceptLang);
|
125
|
}
|
126
|
}
|
127
|
|
128
|
// 4. Otherwise resort to the default set in the config file
|
129
|
if (!isset($_language) && $conf['default_lang'] != 'auto' && isset($appLangFiles[$conf['default_lang']])) {
|
130
|
$_language = $conf['default_lang'];
|
131
|
}
|
132
|
|
133
|
// Import the language file
|
134
|
if (isset($_language)) {
|
135
|
include("./lang/recoded/{$_language}.php");
|
136
|
$_SESSION['webdbLanguage'] = $_language;
|
137
|
}
|
138
|
|
139
|
// Check for config file version mismatch
|
140
|
if (!isset($conf['version']) || $conf['base_version'] > $conf['version']) {
|
141
|
echo $lang['strbadconfig'];
|
142
|
exit;
|
143
|
}
|
144
|
|
145
|
// Check database support is properly compiled in
|
146
|
if (!function_exists('pg_connect')) {
|
147
|
echo $lang['strnotloaded'];
|
148
|
exit;
|
149
|
}
|
150
|
|
151
|
// Create data accessor object, if necessary
|
152
|
if (!isset($_no_db_connection)) {
|
153
|
if (!isset($_REQUEST['server'])) {
|
154
|
die('No server supplied!');
|
155
|
# TODO: nice error
|
156
|
}
|
157
|
$_server_info = $misc->getServerInfo();
|
158
|
|
159
|
// Redirect to the login form if not logged in
|
160
|
if (!isset($_server_info['username'])) {
|
161
|
include('./login.php');
|
162
|
exit;
|
163
|
}
|
164
|
|
165
|
// Connect to the current database, or if one is not specified
|
166
|
// then connect to the default database.
|
167
|
if (isset($_REQUEST['database']))
|
168
|
$_curr_db = $_REQUEST['database'];
|
169
|
else
|
170
|
$_curr_db = $_server_info['defaultdb'];
|
171
|
|
172
|
include_once('./classes/database/Connection.php');
|
173
|
|
174
|
// Connect to database and set the global $data variable
|
175
|
$data = $misc->getDatabaseAccessor($_curr_db);
|
176
|
|
177
|
// If schema is defined and database supports schemas, then set the
|
178
|
// schema explicitly.
|
179
|
if (isset($_REQUEST['database']) && isset($_REQUEST['schema']) && $data->hasSchemas()) {
|
180
|
$status = $data->setSchema($_REQUEST['schema']);
|
181
|
if ($status != 0) {
|
182
|
echo $lang['strbadschema'];
|
183
|
exit;
|
184
|
}
|
185
|
}
|
186
|
|
187
|
// Get database encoding
|
188
|
$dbEncoding = $data->getDatabaseEncoding();
|
189
|
|
190
|
// Set client encoding to database encoding
|
191
|
if ($dbEncoding != '') {
|
192
|
// Explicitly change client encoding if it's different to server encoding.
|
193
|
if (function_exists('pg_client_encoding'))
|
194
|
$currEncoding = pg_client_encoding($data->conn->_connectionID);
|
195
|
elseif (function_exists('pg_clientencoding'))
|
196
|
$currEncoding = pg_clientencoding($data->conn->_connectionID);
|
197
|
else
|
198
|
$currEncoding = null;
|
199
|
|
200
|
if ($currEncoding != $dbEncoding) {
|
201
|
$status = $data->setClientEncoding($dbEncoding);
|
202
|
if ($status != 0 && $status != -99) {
|
203
|
echo $lang['strbadencoding'];
|
204
|
exit;
|
205
|
}
|
206
|
}
|
207
|
|
208
|
// Override $lang['appcharset']
|
209
|
if (isset($data->codemap[$dbEncoding]))
|
210
|
$lang['appcharset'] = $data->codemap[$dbEncoding];
|
211
|
else
|
212
|
$lang['appcharset'] = $dbEncoding;
|
213
|
}
|
214
|
|
215
|
// Load Slony if required
|
216
|
if ($_server_info['slony_support']) {
|
217
|
include('./classes/plugins/Slony.php');
|
218
|
$slony = new Slony();
|
219
|
}
|
220
|
}
|
221
|
|
222
|
?>
|