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