1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Single entrypoint of the app |
||
5 | */ |
||
6 | require_once './src/lib.inc.php'; |
||
7 | |||
8 | $app->get('/status', function ($request, $response, $args) { |
||
0 ignored issues
–
show
|
|||
9 | |||
10 | return $response |
||
11 | ->withHeader('Content-type', 'application/json') |
||
12 | ->withJson(['version' => $this->version]); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
13 | |||
14 | }); |
||
15 | |||
16 | $app->post('/redirect[/{subject}]', function ($request, $response, $args) { |
||
17 | $body = $response->getBody(); |
||
18 | $query_string = $request->getUri()->getQuery(); |
||
19 | $misc = $this->misc; |
||
20 | |||
21 | $loginShared = $request->getParsedBodyParam('loginShared'); |
||
22 | $loginServer = $request->getParsedBodyParam('loginServer'); |
||
23 | $loginUsername = $request->getParsedBodyParam('loginUsername'); |
||
24 | $loginPassword = $request->getParsedBodyParam('loginPassword_' . md5($loginServer)); |
||
25 | |||
26 | // If login action is set, then set session variables |
||
27 | if (boolval($loginServer) && boolval($loginUsername) && $loginPassword !== null) { |
||
28 | $_server_info = $this->misc->getServerInfo($loginServer); |
||
29 | |||
30 | $_server_info['username'] = $loginUsername; |
||
31 | $_server_info['password'] = $loginPassword; |
||
32 | |||
33 | $this->misc->setServerInfo(null, $_server_info, $loginServer); |
||
34 | |||
35 | $data = $misc->getDatabaseAccessor(); |
||
36 | |||
37 | if ($data === null) { |
||
38 | $login_controller = new \PHPPgAdmin\Controller\LoginController($this, true); |
||
39 | $body->write($login_controller->doLoginForm($misc->getErrorMsg())); |
||
40 | return $response; |
||
41 | } |
||
42 | // Check for shared credentials |
||
43 | if ($loginShared !== null) { |
||
44 | $_SESSION['sharedUsername'] = $loginUsername; |
||
45 | $_SESSION['sharedPassword'] = $loginPassword; |
||
46 | } |
||
47 | |||
48 | $misc->setReloadBrowser(true); |
||
49 | $all_db_controller = new \PHPPgAdmin\Controller\AlldbController($this); |
||
50 | return $all_db_controller->render(); |
||
51 | } else { |
||
52 | $_server_info = $this->misc->getServerInfo(); |
||
53 | |||
54 | if (!isset($_server_info['username'])) { |
||
55 | $destinationurl = $this->utils->getDestinationWithLastTab($subject); |
||
56 | return $response->withStatus(302)->withHeader('Location', $destinationurl); |
||
57 | } |
||
58 | } |
||
59 | }); |
||
60 | |||
61 | $app->get('/redirect[/{subject}]', function ($request, $response, $args) { |
||
62 | $subject = (isset($args['subject'])) ? $args['subject'] : 'root'; |
||
63 | $destinationurl = $this->utils->getDestinationWithLastTab($subject); |
||
64 | return $response->withStatus(302)->withHeader('Location', $destinationurl); |
||
65 | }); |
||
66 | |||
67 | $app->get('/src/views/browser', function ($request, $response, $args) { |
||
68 | $controller = new \PHPPgAdmin\Controller\BrowserController($this, true); |
||
69 | return $controller->render(); |
||
70 | }); |
||
71 | |||
72 | $app->get('/src/views/login', function ($request, $response, $args) { |
||
73 | $controller = new \PHPPgAdmin\Controller\LoginController($this, true); |
||
74 | return $controller->render(); |
||
75 | }); |
||
76 | |||
77 | $app->get('/src/views/servers', function ($request, $response, $args) { |
||
78 | $controller = new \PHPPgAdmin\Controller\ServersController($this, true); |
||
79 | return $controller->render(); |
||
80 | }); |
||
81 | |||
82 | $app->get('/src/views/intro', function ($request, $response, $args) { |
||
83 | $controller = new \PHPPgAdmin\Controller\IntroController($this, true); |
||
84 | return $controller->render(); |
||
85 | }); |
||
86 | |||
87 | $app->map(['GET', 'POST'], '/src/views/{subject}', function ($request, $response, $args) { |
||
88 | if ($this->misc->getServerId() === null) { |
||
89 | return $response->withStatus(302)->withHeader('Location', SUBFOLDER . '/src/views/servers'); |
||
90 | } |
||
91 | $_server_info = $this->misc->getServerInfo(); |
||
92 | |||
93 | if (!isset($_server_info['username'])) { |
||
94 | $destinationurl = SUBFOLDER . '/src/views/login?server=' . $this->misc->getServerId(); |
||
95 | return $response->withStatus(302)->withHeader('Location', $destinationurl); |
||
96 | } |
||
97 | |||
98 | $subject = $args['subject']; |
||
99 | |||
100 | $className = '\PHPPgAdmin\Controller\\' . ucfirst($subject) . 'Controller'; |
||
101 | $controller = new $className($this); |
||
102 | return $controller->render(); |
||
103 | }); |
||
104 | |||
105 | $app->get('/[{subject}]', function ($request, $response, $args) { |
||
106 | $subject = (isset($args['subject'])) ? $args['subject'] : 'intro'; |
||
107 | $_server_info = $this->misc->getServerInfo(); |
||
108 | $query_string = $request->getUri()->getQuery(); |
||
109 | $server_id = $request->getQueryParam('server'); |
||
110 | |||
111 | if (!isset($_server_info['username']) && ($subject === 'server' || $subject === 'root')) { |
||
112 | $subject = 'login'; |
||
113 | } |
||
114 | |||
115 | if ($subject === 'login' && $server_id === null) { |
||
116 | $subject = 'servers'; |
||
117 | } |
||
118 | |||
119 | $viewVars = [ |
||
120 | 'url' => '/src/views/' . $subject . ($query_string ? '?' . $query_string : ''), |
||
121 | 'headertemplate' => 'header.twig', |
||
122 | ]; |
||
123 | |||
124 | return $this->view->render($response, 'iframe_view.twig', $viewVars); |
||
125 | }); |
||
126 | |||
127 | // Run app |
||
128 | $app->run(); |
||
129 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.