Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LoginController.php « controllers « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 770be03007bc38fa67f5e01870de0172f3fcbf5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php

/**
 * PHPPgAdmin 6.0.0
 */

namespace PHPPgAdmin\Controller;

/**
 * Login controller class.
 */
class LoginController extends BaseController
{
    public $appLangFiles = [];

    public $appThemes = [];

    public $appName = '';

    public $appVersion = '';

    public $form = '';

    public $href = '';

    public $lang = [];

    public $controller_title = 'strlogin';

    protected $container;

    protected $_connection;

    protected $app;

    protected $data;

    protected $database;

    protected $server_id;

    protected $no_db_connection = true;

    /**
     * Default method to render the controller according to the action parameter.
     */
    public function render()
    {
        if (null === \requestInstance()->getAttribute('route')) {
            echo $this->doLoginForm();
        } else {
            $body = \responseInstance()->getBody();
            $body->write($this->doLoginForm());

            return \responseInstance();
        }
    }

    public function doLoginForm($msg = '')
    {
        $this->misc->setNoDBConnection(true);

        $server_id = \requestInstance()->getQueryParam('server');

        if (null === $server_id) {
            $this->prtrace('invalid server param');

            return $this->lang['strinvalidserverparam'];
        }

        $login_html = $this->printHeader($this->headerTitle(), $this->scripts, false);
        $login_html .= $this->printBody(false);
        $login_html .= $this->printTrail('root', false);

        if (!empty($_POST)) {
            $vars = &$_POST;
        } else {
            $vars = &$_GET;
        }

        foreach ($_REQUEST as $key => $val) {
            if (false !== \mb_strpos($key, '?')) {
                $namexploded = \explode('?', $key);
                $_REQUEST[$namexploded[1]] = \htmlspecialchars($val);
            }
        }

        $server_info = $this->misc->getServerInfo($server_id);
        $title = \sprintf($this->lang['strlogintitle'], $server_info['desc']);

        $printTitle = $this->printTitle($title, null, false);

        $login_html .= $printTitle;

        if (isset($msg)) {
            $login_html .= $this->printMsg($msg, false);
        }

        $login_html .= '<form id="login_form"    method="post" name="login_form" action="' . \containerInstance()->subFolder . '/redirect/server?server=' . \htmlspecialchars($server_id) . '">';

        $md5_server = \md5($server_id);
        // Pass request vars through form (is this a security risk???)
        foreach ($vars as $key => $val) {
            if ('login' === \mb_substr($key, 0, 5)) {
                continue;
            }

            if (false !== \mb_strpos($key, '?')) {
                $key = \explode('?', $key)[1];
            }

            $login_html .= '<input type="hidden" name="' . \htmlspecialchars($key) . '" value="' . \htmlspecialchars($val) . '" />' . \PHP_EOL;
        }

        $login_html .= '<input type="hidden" name="loginServer" value="' . \htmlspecialchars($server_id) . '" />';
        $login_html .= '<table class="navbar" border="0" cellpadding="5" cellspacing="3">';
        $login_html .= '<tr>';
        $login_html .= '<td>' . $this->lang['strusername'] . '</td>';
        $loginusername = isset($_POST['loginUsername']) ? \htmlspecialchars($_POST['loginUsername']) : '';

        $login_html .= '<td><input type="text" name="loginUsername" value="' . $loginusername . '" size="24" /></td>';
        $login_html .= '</tr>';
        $login_html .= '<tr>';
        $login_html .= '<td>' . $this->lang['strpassword'] . '</td>';
        $login_html .= '<td><input id="loginPassword" type="password" name="loginPassword_' . $md5_server . '" size="24" /></td>';
        $login_html .= '</tr>';
        $login_html .= '</table>';

        if (1 < \count($this->conf['servers'])) {
            $checked = isset($_POST['loginShared']) ? 'checked="checked"' : '';
            $login_html .= '<p><input type="checkbox" id="loginShared" name="loginShared" ' . $checked . ' />';
            $login_html .= '<label for="loginShared">' . $this->lang['strtrycred'] . '</label></p>';
        }
        $login_html .= '<p><input type="submit" name="loginSubmit" value="' . $this->lang['strlogin'] . '" /></p>';
        $login_html .= '</form>';

        $login_html .= '<script type="text/javascript">';
        $login_html .= '	var uname = document.login_form.loginUsername;';
        $login_html .= '	var pword = document.login_form.loginPassword_' . $md5_server . ';';
        $login_html .= '	if (uname.value == "") {';
        $login_html .= '		uname.focus();';
        $login_html .= '	} else {';
        $login_html .= '		pword.focus();';
        $login_html .= '	}';
        $login_html .= '</script>';

        // Output footer
        $login_html .= $this->printFooter(false);

        return $login_html;
    }
}