|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin 6.1.3 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
foreach (['logs', 'sessions', 'twigcache'] as $tempFolder) { |
|
8
|
|
|
if (!\is_writable(\sprintf('%s/temp/%s', \dirname(__DIR__), $tempFolder))) { |
|
9
|
|
|
die(\sprintf('The folder temp/%s must be writable', $tempFolder)); |
|
10
|
|
|
} |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
require_once \dirname(__DIR__) . '/vendor/autoload.php'; |
|
14
|
|
|
|
|
15
|
|
|
\defined('BASE_PATH') || \define('BASE_PATH', \dirname(__DIR__)); |
|
16
|
|
|
|
|
17
|
|
|
\defined('THEME_PATH') || \define('THEME_PATH', \dirname(__DIR__) . '/assets/themes'); |
|
18
|
|
|
// Enforce PHP environment |
|
19
|
|
|
\ini_set('arg_separator.output', '&'); |
|
20
|
|
|
\defined('ADODB_ERROR_HANDLER_TYPE') || \define('ADODB_ERROR_HANDLER_TYPE', \E_USER_ERROR); |
|
21
|
|
|
\defined('ADODB_ERROR_HANDLER') || \define('ADODB_ERROR_HANDLER', '\PHPPgAdmin\ADOdbException::adodb_throw'); |
|
22
|
|
|
|
|
23
|
|
|
$shouldSetSession = (\defined('PHP_SESSION_ACTIVE') ? \PHP_SESSION_ACTIVE !== \session_status() : !\session_id()) |
|
24
|
|
|
&& !\headers_sent() |
|
25
|
|
|
&& !\ini_get('session.auto_start'); |
|
26
|
|
|
|
|
27
|
|
|
if ($shouldSetSession && \PHP_SAPI !== 'cli') { |
|
28
|
|
|
\session_set_cookie_params(0, '/', $_SERVER['HTTP_HOST'], isset($_SERVER['HTTPS'])); |
|
29
|
|
|
\session_name('PPA_ID'); |
|
30
|
|
|
\session_start(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
\defined('ADODB_ASSOC_CASE') || \define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE); |
|
34
|
|
|
|
|
35
|
|
|
$app = getAppInstance(); |
|
36
|
|
|
$container = $app->getContainer(); |
|
37
|
|
|
|
|
38
|
|
|
// If no dump function has been globally declared at this point |
|
39
|
|
|
// we fill the gap with an empty one to avoid errors |
|
40
|
|
|
if(!function_exists('dump')) { |
|
41
|
|
|
function dump(...$args):void { |
|
|
|
|
|
|
42
|
|
|
// do nothing |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// Set the requestobj and responseobj properties of the container |
|
47
|
|
|
// as the value of $request and $response, which already contain the route |
|
48
|
|
|
$app->add(new \PHPPgAdmin\Middleware\PopulateRequestResponse($container)); |
|
49
|
|
|
|
|
50
|
|
|
if (!isset($msg)) { |
|
51
|
|
|
$msg = ''; |
|
52
|
|
|
} |
|
53
|
|
|
$container['msg'] = $msg; |
|
54
|
|
|
//ddd($container->misc); |
|
55
|
|
|
|
|
56
|
|
|
$app->get('/status', function ( |
|
57
|
|
|
\Slim\Http\Request $request, |
|
58
|
|
|
\Slim\Http\Response $response, |
|
59
|
|
|
array $args |
|
|
|
|
|
|
60
|
|
|
) { |
|
61
|
|
|
return $response |
|
62
|
|
|
->withHeader('Content-type', 'application/json') |
|
63
|
|
|
->withJson( |
|
64
|
|
|
$this->get('settings')['debug'] ? $this->get('settings')->all() : ['version' => $this->version] |
|
|
|
|
|
|
65
|
|
|
); |
|
66
|
|
|
}); |
|
67
|
|
|
|
|
68
|
|
|
$app->post('/redirect/server', function ( |
|
69
|
|
|
\Slim\Http\Request $request, |
|
70
|
|
|
\Slim\Http\Response $response, |
|
71
|
|
|
array $args |
|
|
|
|
|
|
72
|
|
|
) { |
|
73
|
|
|
$body = $response->getBody(); |
|
74
|
|
|
$misc = $this->misc; |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$loginShared = $request->getParsedBodyParam('loginShared'); |
|
77
|
|
|
$loginServer = $request->getParsedBodyParam('loginServer'); |
|
78
|
|
|
$loginUsername = $request->getParsedBodyParam('loginUsername'); |
|
79
|
|
|
$loginPassword = $request->getParsedBodyParam('loginPassword_' . \md5($loginServer)); |
|
80
|
|
|
|
|
81
|
|
|
// If login action is set, then set session variables |
|
82
|
|
|
if ((bool) $loginServer && (bool) $loginUsername && null !== $loginPassword) { |
|
83
|
|
|
$_server_info = $this->misc->getServerInfo($loginServer); |
|
84
|
|
|
|
|
85
|
|
|
$_server_info['username'] = $loginUsername; |
|
86
|
|
|
$_server_info['password'] = $loginPassword; |
|
87
|
|
|
|
|
88
|
|
|
$this->misc->setServerInfo(null, $_server_info, $loginServer); |
|
89
|
|
|
|
|
90
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
91
|
|
|
|
|
92
|
|
|
if (null === $data) { |
|
93
|
|
|
//ddd($misc->getErrorMsg()); |
|
94
|
|
|
$login_controller = new \PHPPgAdmin\Controller\LoginController($this, true); |
|
|
|
|
|
|
95
|
|
|
$body->write($login_controller->doLoginForm($misc->getErrorMsg())); |
|
96
|
|
|
|
|
97
|
|
|
return $response; |
|
98
|
|
|
} |
|
99
|
|
|
// Check for shared credentials |
|
100
|
|
|
if (null !== $loginShared) { |
|
101
|
|
|
$_SESSION['sharedUsername'] = $loginUsername; |
|
102
|
|
|
$_SESSION['sharedPassword'] = $loginPassword; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$this->view->setReloadBrowser(true); |
|
106
|
|
|
$this->addFlash(true, 'reload_browser'); |
|
107
|
|
|
|
|
108
|
|
|
$destinationurl = $this->getDestinationWithLastTab('alldb'); |
|
109
|
|
|
|
|
110
|
|
|
return $response->withStatus(302)->withHeader('Location', $destinationurl); |
|
111
|
|
|
} |
|
112
|
|
|
$_server_info = $this->misc->getServerInfo(); |
|
113
|
|
|
|
|
114
|
|
|
if (!isset($_server_info['username'])) { |
|
115
|
|
|
$destinationurl = $this->getDestinationWithLastTab('server'); |
|
116
|
|
|
|
|
117
|
|
|
return $response->withStatus(302)->withHeader('Location', $destinationurl); |
|
118
|
|
|
} |
|
119
|
|
|
}); |
|
120
|
|
|
|
|
121
|
|
|
$app->get('/redirect[/{subject}]', function ( |
|
122
|
|
|
\Slim\Http\Request $request, |
|
123
|
|
|
\Slim\Http\Response $response, |
|
124
|
|
|
array $args |
|
125
|
|
|
) { |
|
126
|
|
|
$subject = (isset($args['subject'])) ? $args['subject'] : 'root'; |
|
127
|
|
|
$destinationurl = $this->getDestinationWithLastTab($subject); |
|
|
|
|
|
|
128
|
|
|
$cleanDestination=($this->subFolder.'/'. $destinationurl); |
|
129
|
|
|
|
|
130
|
|
|
return $response->withStatus(302)->withHeader('Location',$cleanDestination); |
|
131
|
|
|
}); |
|
132
|
|
|
|
|
133
|
|
|
ini_set('display_errors','on'); |
|
134
|
|
|
$app->get('/{subject:servers|intro|browser}[/{server_id}]', function ( |
|
135
|
|
|
\Slim\Http\Request $request, |
|
136
|
|
|
\Slim\Http\Response $response, |
|
137
|
|
|
array $args |
|
138
|
|
|
) { |
|
139
|
|
|
$subject = $args['subject'] ?? 'intro'; |
|
140
|
|
|
$this->view->offsetSet('includeJsTree',true); |
|
|
|
|
|
|
141
|
|
|
$className = '\PHPPgAdmin\Controller\\' . \ucfirst($subject) . 'Controller'; |
|
142
|
|
|
$controller = new $className($this); |
|
143
|
|
|
return $controller->render(); |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
}); |
|
147
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
$app->map(['GET', 'POST'], '/src/views/{subject}', function ( |
|
150
|
|
|
\Slim\Http\Request $request, |
|
151
|
|
|
\Slim\Http\Response $response, |
|
152
|
|
|
array $args |
|
153
|
|
|
) { |
|
154
|
|
|
$subject = $args['subject']; |
|
155
|
|
|
$nextPath=$this->subFolder.'/'. $subject; |
|
|
|
|
|
|
156
|
|
|
$query_string = $request->getUri()->getQuery(); |
|
157
|
|
|
return $response->withStatus(302)->withHeader('Location',$nextPath.($query_string? '?'.$query_string:'')); |
|
158
|
|
|
}); |
|
159
|
|
|
|
|
160
|
|
|
$app->get('/{subject:\w+}[/{server_id}]', function ( |
|
161
|
|
|
\Slim\Http\Request $request, |
|
162
|
|
|
\Slim\Http\Response $response, |
|
163
|
|
|
array $args |
|
164
|
|
|
) { |
|
165
|
|
|
$subject = $args['subject'] ?? 'intro'; |
|
166
|
|
|
$server_id = $args['server_id'] ?? $request->getQueryParam('server'); |
|
167
|
|
|
$_server_info = $this->misc->getServerInfo(); |
|
|
|
|
|
|
168
|
|
|
if (!isset($_server_info['username'])) { |
|
169
|
|
|
$subject = 'login'; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
if ('login' === $subject && null === $server_id) { |
|
173
|
|
|
$subject = 'servers'; |
|
174
|
|
|
} |
|
175
|
|
|
$query_string = $request->getUri()->getQuery(); |
|
|
|
|
|
|
176
|
|
|
$this->view->offsetSet('includeJsTree',true); |
|
177
|
|
|
$className = $this->view->getControllerClassName($subject); |
|
178
|
|
|
$controller = new $className($this); |
|
179
|
|
|
return $controller->render(); |
|
180
|
|
|
|
|
181
|
|
|
}); |
|
182
|
|
|
|
|
183
|
|
|
$app->get('/', function ( |
|
184
|
|
|
\Slim\Http\Request $request, |
|
185
|
|
|
\Slim\Http\Response $response, |
|
186
|
|
|
array $args |
|
|
|
|
|
|
187
|
|
|
) { |
|
188
|
|
|
$subject = 'intro'; |
|
|
|
|
|
|
189
|
|
|
$query_string = $request->getUri()->getQuery(); |
|
|
|
|
|
|
190
|
|
|
return $response->withStatus(302)->withHeader('Location',$nextPath); |
|
|
|
|
|
|
191
|
|
|
|
|
192
|
|
|
return $this->view->maybeRenderIframes($response, $subject, $query_string); |
|
|
|
|
|
|
193
|
|
|
}); |
|
194
|
|
|
|
|
195
|
|
|
$app->get('[/{path:.*}]', function ( |
|
196
|
|
|
\Slim\Http\Request $request, |
|
197
|
|
|
\Slim\Http\Response $response, |
|
198
|
|
|
array $args |
|
199
|
|
|
) { |
|
200
|
|
|
return $response->write(sprintf("We couldn't find a route matching %s", $args['path'] ? $args['path'] : 'index')); |
|
201
|
|
|
}); |
|
202
|
|
|
|
|
203
|
|
|
// Run app |
|
204
|
|
|
$app->run(); |
|
205
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.