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