|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin 6.0.0 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
\defined('BASE_PATH') || \define('BASE_PATH', \dirname(__DIR__)); |
|
8
|
|
|
|
|
9
|
|
|
\defined('THEME_PATH') || \define('THEME_PATH', \dirname(__DIR__) . '/assets/themes'); |
|
10
|
|
|
// Enforce PHP environment |
|
11
|
|
|
\ini_set('arg_separator.output', '&'); |
|
12
|
|
|
|
|
13
|
|
|
if (!\is_writable(\dirname(__DIR__) . '/temp')) { |
|
14
|
|
|
die('Your temp folder must have write permissions (use chmod 777 temp -R on linux)'); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
require_once \dirname(__DIR__) . '/vendor/autoload.php'; |
|
18
|
|
|
|
|
19
|
|
|
$shouldSetSession = (\defined('PHP_SESSION_ACTIVE') ? \PHP_SESSION_ACTIVE !== \session_status() : !\session_id()) |
|
20
|
|
|
&& !\headers_sent() |
|
21
|
|
|
&& !\ini_get('session.auto_start'); |
|
22
|
|
|
|
|
23
|
|
|
if ($shouldSetSession && \PHP_SAPI !== 'cli') { |
|
24
|
|
|
\session_set_cookie_params(0, '/', $_SERVER['HTTP_HOST'], isset($_SERVER['HTTPS'])); |
|
25
|
|
|
\session_name('PPA_ID'); |
|
26
|
|
|
\session_start(); |
|
27
|
|
|
} |
|
28
|
|
|
if (!\defined('ADODB_ERROR_HANDLER_TYPE')) { |
|
29
|
|
|
\define('ADODB_ERROR_HANDLER_TYPE', \E_USER_ERROR); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if (!\defined('ADODB_ERROR_HANDLER')) { |
|
33
|
|
|
\define('ADODB_ERROR_HANDLER', '\PHPPgAdmin\ADOdbException::adodb_throw'); |
|
34
|
|
|
} |
|
35
|
|
|
function getAppInstance() { |
|
|
|
|
|
|
36
|
|
|
$subfolder = ''; |
|
37
|
|
|
// Check to see if the configuration file exists, if not, explain |
|
38
|
|
|
if (!\file_exists(\dirname(__DIR__) . '/config.inc.php')) { |
|
39
|
|
|
die('Configuration error: Copy config.inc.php-dist to config.inc.php and edit appropriately.'); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
$conf = []; |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
include_once \dirname(__DIR__) . '/config.inc.php'; |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
if (isset($conf['subfolder']) && \is_string($conf['subfolder'])) { |
|
46
|
|
|
$subfolder = $conf['subfolder']; |
|
|
|
|
|
|
47
|
|
|
} elseif (\PHP_SAPI === 'cli-server') { |
|
48
|
|
|
$subfolder = '/index.php'; |
|
|
|
|
|
|
49
|
|
|
} elseif (isset($_SERVER['DOCUMENT_ROOT'])) { |
|
50
|
|
|
$subfolder = \str_replace( |
|
|
|
|
|
|
51
|
|
|
$_SERVER['DOCUMENT_ROOT'], |
|
52
|
|
|
'', |
|
53
|
|
|
\dirname(__DIR__) |
|
54
|
|
|
); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$conf['subfolder'] = $subfolder; |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$conf['debugmode'] = (!isset($conf['debugmode'])) ? false : (bool) ($conf['debugmode']); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
if ($conf['debugmode']) { |
|
65
|
|
|
\ini_set('display_errors', 'On'); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
\ini_set('display_startup_errors', 'On'); |
|
|
|
|
|
|
68
|
|
|
\ini_set('opcache.revalidate_freq', '0'); |
|
|
|
|
|
|
69
|
|
|
\error_reporting(\E_ALL); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
if (\array_key_exists('register_debuggers', $conf) && \is_callable($conf['register_debuggers'])) { |
|
72
|
|
|
$conf['register_debuggers'](); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
$conf['BASE_PATH'] = BASE_PATH; |
|
|
|
|
|
|
78
|
|
|
$conf['theme_path'] = BASE_PATH . '/assets/themes'; |
|
|
|
|
|
|
79
|
|
|
\defined('IN_TEST') || \define('IN_TEST', false); |
|
|
|
|
|
|
80
|
|
|
$conf['IN_TEST'] = IN_TEST; |
|
|
|
|
|
|
81
|
|
|
\ini_set('display_errors', strval($conf['debugmode'])); |
|
|
|
|
|
|
82
|
|
|
\defined('ADODB_ASSOC_CASE') || \define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
// Fetch App and DI Container |
|
|
|
|
|
|
85
|
|
|
$app = \PHPPgAdmin\ContainerUtils::getAppInstance($conf); |
|
|
|
|
|
|
86
|
|
|
return $app; |
|
|
|
|
|
|
87
|
|
|
}; |
|
88
|
|
|
|
|
89
|
|
|
function containerInstance(): \PHPPgAdmin\ContainerUtils |
|
90
|
|
|
{ |
|
91
|
|
|
$app=getAppInstance(); |
|
92
|
|
|
$container = $app->getContainer(); |
|
93
|
|
|
if (!$container instanceof \PHPPgAdmin\ContainerUtils) { |
|
94
|
|
|
\trigger_error('App Container must be an instance of \\Slim\\Container', \E_USER_ERROR); |
|
95
|
|
|
} |
|
96
|
|
|
return $container; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
function requestInstance(): \Slim\Http\Request |
|
100
|
|
|
{ |
|
101
|
|
|
return \containerInstance()->request; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
function responseInstance(): \Slim\Http\Response |
|
105
|
|
|
{ |
|
106
|
|
|
return \containerInstance()->response; |
|
107
|
|
|
} |
|
108
|
|
|
$app=getAppInstance(); |
|
109
|
|
|
$container=$app->getContainer(); |
|
110
|
|
|
|
|
111
|
|
|
// This should be deprecated once we're sure no php scripts are required directly |
|
112
|
|
|
$container->offsetSet('server', $_REQUEST['server'] ?? null); |
|
113
|
|
|
$container->offsetSet('database', $_REQUEST['database'] ?? null); |
|
114
|
|
|
$container->offsetSet('schema', $_REQUEST['schema'] ?? null); |
|
115
|
|
|
|
|
116
|
|
|
$container['haltHandler'] = static function (\PHPPgAdmin\ContainerUtils $c) { |
|
117
|
|
|
return static function ($request, $response, $exits, $status = 500) use ($c) { |
|
118
|
|
|
$title = 'PHPPgAdmin Error'; |
|
119
|
|
|
|
|
120
|
|
|
$html = '<p>The application could not run because of the following error:</p>'; |
|
121
|
|
|
|
|
122
|
|
|
$output = \sprintf( |
|
123
|
|
|
"<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" . |
|
124
|
|
|
'<title>%s</title><style>' . |
|
125
|
|
|
'body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}' . |
|
126
|
|
|
'h3{margin:0;font-size:28px;font-weight:normal;line-height:30px;}' . |
|
127
|
|
|
'span{display:inline-block;font-size:16px;}' . |
|
128
|
|
|
'</style></head><body><h3>%s</h3><p>%s</p><span>%s</span></body></html>', |
|
129
|
|
|
$title, |
|
130
|
|
|
$title, |
|
131
|
|
|
$html, |
|
132
|
|
|
\implode('<br>', $exits) |
|
133
|
|
|
); |
|
134
|
|
|
|
|
135
|
|
|
$body = $response->getBody(); //new \Slim\Http\Body(fopen('php://temp', 'r+')); |
|
136
|
|
|
$body->write($output); |
|
137
|
|
|
|
|
138
|
|
|
return $response |
|
139
|
|
|
->withStatus($status) |
|
140
|
|
|
->withHeader('Content-type', 'text/html') |
|
141
|
|
|
->withBody($body); |
|
142
|
|
|
}; |
|
143
|
|
|
}; |
|
144
|
|
|
|
|
145
|
|
|
// Set the requestobj and responseobj properties of the container |
|
146
|
|
|
// as the value of $request and $response, which already contain the route |
|
147
|
|
|
$app->add(new \PHPPgAdmin\Middleware\PopulateRequestResponse($container)); |
|
148
|
|
|
|
|
149
|
|
|
$container['action'] = $_REQUEST['action'] ?? ''; |
|
150
|
|
|
|
|
151
|
|
|
if (!isset($msg)) { |
|
152
|
|
|
$msg = ''; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
$container['msg'] = $msg; |
|
156
|
|
|
//ddd($container->misc); |
|
157
|
|
|
|