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
|
<?php
/**
* PHPPgAdmin 6.1.2
*/
require_once __DIR__ . '/lib.inc.php';
$app = getAppInstance();
$container = containerInstance();
// Set the requestobj and responseobj properties of the container
// as the value of $request and $response, which already contain the route
$app->add(new \PHPPgAdmin\Middleware\PopulateRequestResponse($container));
if (!isset($msg)) {
$msg = '';
}
$container['msg'] = $msg;
//ddd($container->misc);
$app->get('/status', function (
\Slim\Http\Request $request,
\Slim\Http\Response $response,
array $args
) {
return $response
->withHeader('Content-type', 'application/json')
->withJson(
$this->get('settings')['debug'] ? $this->get('settings')->all() : ['version' => $this->version]
);
});
$app->post('/redirect/server', function (
\Slim\Http\Request $request,
\Slim\Http\Response $response,
array $args
) {
$body = $response->getBody();
$misc = $this->misc;
$loginShared = $request->getParsedBodyParam('loginShared');
$loginServer = $request->getParsedBodyParam('loginServer');
$loginUsername = $request->getParsedBodyParam('loginUsername');
$loginPassword = $request->getParsedBodyParam('loginPassword_' . \md5($loginServer));
// If login action is set, then set session variables
if ((bool) $loginServer && (bool) $loginUsername && null !== $loginPassword) {
$_server_info = $this->misc->getServerInfo($loginServer);
$_server_info['username'] = $loginUsername;
$_server_info['password'] = $loginPassword;
$this->misc->setServerInfo(null, $_server_info, $loginServer);
$data = $misc->getDatabaseAccessor();
if (null === $data) {
//ddd($misc->getErrorMsg());
$login_controller = new \PHPPgAdmin\Controller\LoginController($this, true);
$body->write($login_controller->doLoginForm($misc->getErrorMsg()));
return $response;
}
// Check for shared credentials
if (null !== $loginShared) {
$_SESSION['sharedUsername'] = $loginUsername;
$_SESSION['sharedPassword'] = $loginPassword;
}
$this->view->setReloadBrowser(true);
$this->addFlash(true, 'reload_browser');
$destinationurl = $this->getDestinationWithLastTab('alldb');
return $response->withStatus(302)->withHeader('Location', $destinationurl);
}
$_server_info = $this->misc->getServerInfo();
if (!isset($_server_info['username'])) {
$destinationurl = $this->getDestinationWithLastTab('server');
return $response->withStatus(302)->withHeader('Location', $destinationurl);
}
});
$app->get('/redirect[/{subject}]', function (
\Slim\Http\Request $request,
\Slim\Http\Response $response,
array $args
) {
$subject = (isset($args['subject'])) ? $args['subject'] : 'root';
$destinationurl = $this->getDestinationWithLastTab($subject);
return $response->withStatus(302)->withHeader('Location', $destinationurl);
});
$app->map(['GET', 'POST'], '/src/views/{subject}', function (
\Slim\Http\Request $request,
\Slim\Http\Response $response,
array $args
) {
$subject = $args['subject'];
if ('server' === $subject) {
$subject = 'servers';
}
$_server_info = $this->misc->getServerInfo();
$safe_subjects = ('servers' === $subject || 'intro' === $subject || 'browser' === $subject);
if (null === $this->misc->getServerId() && !$safe_subjects) {
return $response->withStatus(302)->withHeader('Location', $this->subFolder . '/src/views/servers');
}
if (!isset($_server_info['username']) && 'login' !== $subject && !$safe_subjects) {
$destinationurl = $this->subFolder . '/src/views/login?server=' . $this->misc->getServerId();
return $response->withStatus(302)->withHeader('Location', $destinationurl);
}
$className = '\PHPPgAdmin\Controller\\' . \ucfirst($subject) . 'Controller';
$controller = new $className($this);
return $controller->render();
});
$app->get('/{subject:\w+}[/{server_id}]', function (
\Slim\Http\Request $request,
\Slim\Http\Response $response,
array $args
) {
$subject = $args['subject'] ?? 'intro';
$server_id = $args['server_id'] ?? $request->getQueryParam('server');
//ddd($subject, $server_id);
$_server_info = $this->misc->getServerInfo();
//$this->utils->prtrace($_server_info);
if (!isset($_server_info['username'])) {
$subject = 'login';
}
if ('login' === $subject && null === $server_id) {
$subject = 'servers';
}
$query_string = $request->getUri()->getQuery();
return $this->view->maybeRenderIframes($response, $subject, $query_string);
});
$app->get('/', function (
\Slim\Http\Request $request,
\Slim\Http\Response $response,
array $args
) {
$subject = 'intro';
$query_string = $request->getUri()->getQuery();
return $this->view->maybeRenderIframes($response, $subject, $query_string);
});
$app->get('[/{path:.*}]', function (
\Slim\Http\Request $request,
\Slim\Http\Response $response,
array $args
) {
$filepath = \dirname(__DIR__) . '/' . $args['path'];
$query_string = $request->getUri()->getQuery();
//d($this->subfolder, $args, $query_string, $filepath);
$this->prtrace($request->getAttribute('route'));
return $response->write($args['path'] ? $args['path'] : 'index');
});
// Run app
$app->run();
|