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