|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin 6.1.3 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
require_once __DIR__ . '/lib.inc.php'; |
|
8
|
|
|
$app = getAppInstance(); |
|
9
|
|
|
$container = containerInstance(); |
|
10
|
|
|
|
|
11
|
|
|
// Set the requestobj and responseobj properties of the container |
|
12
|
|
|
// as the value of $request and $response, which already contain the route |
|
13
|
|
|
$app->add(new \PHPPgAdmin\Middleware\PopulateRequestResponse($container)); |
|
14
|
|
|
|
|
15
|
|
|
if (!isset($msg)) { |
|
16
|
|
|
$msg = ''; |
|
17
|
|
|
} |
|
18
|
|
|
$container['msg'] = $msg; |
|
19
|
|
|
//ddd($container->misc); |
|
20
|
|
|
|
|
21
|
|
|
$app->get('/status', function ( |
|
22
|
|
|
\Slim\Http\Request $request, |
|
23
|
|
|
\Slim\Http\Response $response, |
|
24
|
|
|
array $args |
|
|
|
|
|
|
25
|
|
|
) { |
|
26
|
|
|
return $response |
|
27
|
|
|
->withHeader('Content-type', 'application/json') |
|
28
|
|
|
->withJson( |
|
29
|
|
|
$this->get('settings')['debug'] ? $this->get('settings')->all() : ['version' => $this->version] |
|
|
|
|
|
|
30
|
|
|
); |
|
31
|
|
|
}); |
|
32
|
|
|
|
|
33
|
|
|
$app->post('/redirect/server', function ( |
|
34
|
|
|
\Slim\Http\Request $request, |
|
35
|
|
|
\Slim\Http\Response $response, |
|
36
|
|
|
array $args |
|
|
|
|
|
|
37
|
|
|
) { |
|
38
|
|
|
$body = $response->getBody(); |
|
39
|
|
|
$misc = $this->misc; |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$loginShared = $request->getParsedBodyParam('loginShared'); |
|
42
|
|
|
$loginServer = $request->getParsedBodyParam('loginServer'); |
|
43
|
|
|
$loginUsername = $request->getParsedBodyParam('loginUsername'); |
|
44
|
|
|
$loginPassword = $request->getParsedBodyParam('loginPassword_' . \md5($loginServer)); |
|
45
|
|
|
|
|
46
|
|
|
// If login action is set, then set session variables |
|
47
|
|
|
if ((bool) $loginServer && (bool) $loginUsername && null !== $loginPassword) { |
|
48
|
|
|
$_server_info = $this->misc->getServerInfo($loginServer); |
|
49
|
|
|
|
|
50
|
|
|
$_server_info['username'] = $loginUsername; |
|
51
|
|
|
$_server_info['password'] = $loginPassword; |
|
52
|
|
|
|
|
53
|
|
|
$this->misc->setServerInfo(null, $_server_info, $loginServer); |
|
54
|
|
|
|
|
55
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
56
|
|
|
|
|
57
|
|
|
if (null === $data) { |
|
58
|
|
|
//ddd($misc->getErrorMsg()); |
|
59
|
|
|
$login_controller = new \PHPPgAdmin\Controller\LoginController($this, true); |
|
|
|
|
|
|
60
|
|
|
$body->write($login_controller->doLoginForm($misc->getErrorMsg())); |
|
61
|
|
|
|
|
62
|
|
|
return $response; |
|
63
|
|
|
} |
|
64
|
|
|
// Check for shared credentials |
|
65
|
|
|
if (null !== $loginShared) { |
|
66
|
|
|
$_SESSION['sharedUsername'] = $loginUsername; |
|
67
|
|
|
$_SESSION['sharedPassword'] = $loginPassword; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$this->view->setReloadBrowser(true); |
|
71
|
|
|
$this->addFlash(true, 'reload_browser'); |
|
72
|
|
|
|
|
73
|
|
|
$destinationurl = $this->getDestinationWithLastTab('alldb'); |
|
74
|
|
|
|
|
75
|
|
|
return $response->withStatus(302)->withHeader('Location', $destinationurl); |
|
76
|
|
|
} |
|
77
|
|
|
$_server_info = $this->misc->getServerInfo(); |
|
78
|
|
|
|
|
79
|
|
|
if (!isset($_server_info['username'])) { |
|
80
|
|
|
$destinationurl = $this->getDestinationWithLastTab('server'); |
|
81
|
|
|
|
|
82
|
|
|
return $response->withStatus(302)->withHeader('Location', $destinationurl); |
|
83
|
|
|
} |
|
84
|
|
|
}); |
|
85
|
|
|
|
|
86
|
|
|
$app->get('/redirect[/{subject}]', function ( |
|
87
|
|
|
\Slim\Http\Request $request, |
|
88
|
|
|
\Slim\Http\Response $response, |
|
89
|
|
|
array $args |
|
90
|
|
|
) { |
|
91
|
|
|
$subject = (isset($args['subject'])) ? $args['subject'] : 'root'; |
|
92
|
|
|
$destinationurl = $this->getDestinationWithLastTab($subject); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
return $response->withStatus(302)->withHeader('Location', $destinationurl); |
|
95
|
|
|
}); |
|
96
|
|
|
|
|
97
|
|
|
$app->map(['GET', 'POST'], '/src/views/{subject}', function ( |
|
98
|
|
|
\Slim\Http\Request $request, |
|
99
|
|
|
\Slim\Http\Response $response, |
|
100
|
|
|
array $args |
|
101
|
|
|
) { |
|
102
|
|
|
$subject = $args['subject']; |
|
103
|
|
|
|
|
104
|
|
|
if ('server' === $subject) { |
|
105
|
|
|
$subject = 'servers'; |
|
106
|
|
|
} |
|
107
|
|
|
$_server_info = $this->misc->getServerInfo(); |
|
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
$safe_subjects = ('servers' === $subject || 'intro' === $subject || 'browser' === $subject); |
|
110
|
|
|
|
|
111
|
|
|
if (null === $this->misc->getServerId() && !$safe_subjects) { |
|
112
|
|
|
return $response->withStatus(302)->withHeader('Location', $this->subFolder . '/src/views/servers'); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
if (!isset($_server_info['username']) && 'login' !== $subject && !$safe_subjects) { |
|
116
|
|
|
$destinationurl = $this->subFolder . '/src/views/login?server=' . $this->misc->getServerId(); |
|
117
|
|
|
|
|
118
|
|
|
return $response->withStatus(302)->withHeader('Location', $destinationurl); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
$className = '\PHPPgAdmin\Controller\\' . \ucfirst($subject) . 'Controller'; |
|
122
|
|
|
$controller = new $className($this); |
|
123
|
|
|
|
|
124
|
|
|
return $controller->render(); |
|
125
|
|
|
}); |
|
126
|
|
|
|
|
127
|
|
|
$app->get('/{subject:\w+}[/{server_id}]', function ( |
|
128
|
|
|
\Slim\Http\Request $request, |
|
129
|
|
|
\Slim\Http\Response $response, |
|
130
|
|
|
array $args |
|
131
|
|
|
) { |
|
132
|
|
|
$subject = $args['subject'] ?? 'intro'; |
|
133
|
|
|
$server_id = $args['server_id'] ?? $request->getQueryParam('server'); |
|
134
|
|
|
//ddd($subject, $server_id); |
|
135
|
|
|
$_server_info = $this->misc->getServerInfo(); |
|
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
//$this->utils->prtrace($_server_info); |
|
138
|
|
|
|
|
139
|
|
|
if (!isset($_server_info['username'])) { |
|
140
|
|
|
$subject = 'login'; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
if ('login' === $subject && null === $server_id) { |
|
144
|
|
|
$subject = 'servers'; |
|
145
|
|
|
} |
|
146
|
|
|
$query_string = $request->getUri()->getQuery(); |
|
147
|
|
|
|
|
148
|
|
|
return $this->view->maybeRenderIframes($response, $subject, $query_string); |
|
149
|
|
|
}); |
|
150
|
|
|
|
|
151
|
|
|
$app->get('/', function ( |
|
152
|
|
|
\Slim\Http\Request $request, |
|
153
|
|
|
\Slim\Http\Response $response, |
|
154
|
|
|
array $args |
|
|
|
|
|
|
155
|
|
|
) { |
|
156
|
|
|
$subject = 'intro'; |
|
157
|
|
|
|
|
158
|
|
|
$query_string = $request->getUri()->getQuery(); |
|
159
|
|
|
|
|
160
|
|
|
return $this->view->maybeRenderIframes($response, $subject, $query_string); |
|
|
|
|
|
|
161
|
|
|
}); |
|
162
|
|
|
|
|
163
|
|
|
$app->get('[/{path:.*}]', function ( |
|
164
|
|
|
\Slim\Http\Request $request, |
|
165
|
|
|
\Slim\Http\Response $response, |
|
166
|
|
|
array $args |
|
167
|
|
|
) { |
|
168
|
|
|
$filepath = \dirname(__DIR__) . '/' . $args['path']; |
|
|
|
|
|
|
169
|
|
|
$query_string = $request->getUri()->getQuery(); |
|
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
//d($this->subfolder, $args, $query_string, $filepath); |
|
172
|
|
|
|
|
173
|
|
|
$this->prtrace($request->getAttribute('route')); |
|
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
return $response->write($args['path'] ? $args['path'] : 'index'); |
|
176
|
|
|
}); |
|
177
|
|
|
|
|
178
|
|
|
// Run app |
|
179
|
|
|
$app->run(); |
|
180
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.