Skip to content

Auto-Login doesn't work #28

@danielmarschall

Description

@danielmarschall

I am trying to have a phpPgAdmin instance that automatically logs in with no credentials. (The phpPgAdmin installation is placed in a folder that is secured via .htaccess).

The automatic login feature does not seem to work.

I have set the following values in my conf/config.php:

    $conf['servers'][0]['desc'] = 'PostgreSQL';
    $conf['servers'][0]['host'] = ''; // Unix socket
    $conf['servers'][0]['port'] = 5432;
    $conf['servers'][0]['username'] = 'my_username_here';
    $conf['servers'][0]['password'] = '';
    $conf['servers'][0]['sslmode'] = 'allow';
    $conf['servers'][0]['defaultdb'] = 'template1';
    $conf['servers'][0]['pg_dump_path'] = '/usr/bin/pg_dump';
    $conf['servers'][0]['pg_dumpall_path'] = '/usr/bin/pg_dumpall';
    $conf['extra_login_security'] = false;
    $conf['owned_only'] = true;

When I try to open phpPgAdmin, the tree on the left side loads correctly. When I refresh the tree, then it just says "Tree Item" (the default tree text). When I click it, I get the PHP error message:

Warning: Undefined array key "desc" in /.../phpPgAdmin/login.php on line 23

It turns out that the method $misc->getServerInfo($_REQUEST['server']) returns an array with just two items:

Array ( [platform] => PostgreSQL 15.10 (Debian 15.10-0+deb12u1) [pgVersion] => 15.10 (Debian 15.10-0+deb12u1) )

But there should be other stuff, such like "username", "host", "port", etc!!

Inspecting classes/Misc.php at method getServerInfo shows the weird array with just 2 items is retrieved from here:

                    // Check for the server in the logged-in list
                    if (isset($_SESSION['webdbLogin'][$server_id]))
                            return $_SESSION['webdbLogin'][$server_id];

The session variable webdbLogin is set at setServerInfo, which is called at getDatabaseAccessor():

                    $this->setServerInfo('platform', $platform, $server_id);
                    $this->setServerInfo('pgVersion', $_connection->conn->ServerInfo()['version'], $server_id);

Here is the problem: If I understand correctly, then these two lines should only be called if the login has been already done (i.e. the session variable already exists and contains the server data), and these two variables are supposed to be just added on top of it.

But here, the session variable was not initialized (because there was never a "real" login), and therefore the session variable was initialized by these two commands and hence the session just contained these two variables "platform" and "pgVersion" and the other stuff like "host" and "port" are not set. This is why getServerInfo will return invalid data until the session cookie is deleted.

I am not 100% sure how to correctly fix it. For now, I could fix the issue by placing the two lines in an "if" statement, but I am not sure if that is correct, since the two lines seem to never be executed now.


if (isset($_SESSION['webdbLogin'][$server_id])) { # <-- HOTFIX
                        $this->setServerInfo('platform', $platform, $server_id);
                        $this->setServerInfo('pgVersion', $_connection->conn->ServerInfo()['version'], $server_id);
} # <-- HOTFIX

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions