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