port setting is not respected in master-client setup when host and database names are identical leading to client database being accessed instead of master database

Summary

On one client I have migrated the database to docker. Connection to master database runs through stunnel. Connection settings are:

$conf['db_type'] = 'mysql'; $conf['db_host'] = '127.0.0.1'; $conf['db_port'] = '3306'; $conf['db_database'] = 'dbispconfig';

$conf['dbmaster_type'] = 'mysql'; $conf['dbmaster_host'] = '127.0.0.1'; $conf['dbmaster_port'] = '3309'; $conf['dbmaster_database'] = 'dbispconfig';

So the only difference is the port.

Jobs and log updates did not work and it took me quite some while to figure out that it was not (only) my broken database that I had fixed by replacing it with docker but a missing respect for the port in ispconfig.

I found that in server/lib/app.inc.php function __construct()

if($conf['dbmaster_host'] != '' && ($conf['dbmaster_host'] != $conf['db_host'] || ($conf['dbmaster_host'] == $conf['db_host'] && $conf['dbmaster_database'] != $conf['db_database']))) {
				try {
					$this->dbmaster = new db($conf['dbmaster_host'], $conf['dbmaster_user'], $conf['dbmaster_password'], $conf['dbmaster_database'], $conf['dbmaster_port'], $conf['dbmaster_client_flags']);
				} catch (Exception $e) {
					$this->dbmaster = false;
				}
			} else {
				$this->dbmaster = $this->db;
			}

$this->dbmaster = $this->db when host and dbname of master and client are identical. So the client does not connect to master db in this setting and it does not report that it does not do so.

In the master web interface this leads to jobs not being processed and client logs not being updated.

Steps to reproduce

  1. set up client with hostname and dbname identical to dbmaster, only port differing

Correct behaviour

Connect to master db on client. In the webinterface: process jobs, show uptodate server log info.

In case this behaviour happens I would expect some kind of message that client db is being used instead of master db.

Environment

Proposed fix

$conf['dbmaster_host'] == $conf['db_host'] && $conf['dbmaster_database'] == $conf['db_database'] && $conf['dbmaster_port'] != $conf['db_port'] needs to be added to respect this setting as far as I understand the issue at hand.

I have not validated this proposed fix.

A workaround could be to rename client db to dbispconfig_client.

I have applied the workaround. System now seems to work as usual (jobs get processed, uptodate client logs can be seen on web interface)

Edited by christoph Holtermann