refactor: Added config option for database port (#5517)

This commit is contained in:
David Bell
2017-01-27 23:16:04 +00:00
committed by Neil Lathwood
parent 46003a39b6
commit 5dd030f438
10 changed files with 23 additions and 17 deletions

View File

@@ -437,7 +437,7 @@ class IRCBot
private function chkdb()
{
if (!is_resource($this->sql)) {
if (($this->sql = mysqli_connect($this->config['db_host'], $this->config['db_user'], $this->config['db_pass'])) != false && mysqli_select_db($this->sql, $this->config['db_name'])) {
if (($this->sql = mysqli_connect($this->config['db_host'], $this->config['db_user'], $this->config['db_pass'], null, $this->config['db_port'])) != false && mysqli_select_db($this->sql, $this->config['db_name'])) {
return true;
} else {
$this->log('Cannot connect to MySQL');

View File

@@ -15,7 +15,7 @@ if ($sql_fh === false) {
exit(1);
}
$database_link = mysqli_connect('p:'.$config['db_host'], $config['db_user'], $config['db_pass']);
$database_link = mysqli_connect('p:'.$config['db_host'], $config['db_user'], $config['db_pass'], null, $config['db_port']);
if ($database_link === false) {
echo 'ERROR: Cannot connect to database: '.mysqli_error($database_link)."\n";
exit(1);

View File

@@ -87,16 +87,13 @@ except:
discovery_path = config['install_dir'] + '/discovery.php'
db_username = config['db_user']
db_password = config['db_pass']
db_port = int(config['db_port'])
if config['db_host'][:5].lower() == 'unix:':
db_server = config['db_host']
db_port = 0
elif ':' in config['db_host']:
db_server = config['db_host'].rsplit(':')[0]
db_port = int(config['db_host'].rsplit(':')[1])
else:
db_server = config['db_host']
db_port = 0
db_dbname = config['db_name']

View File

@@ -26,6 +26,7 @@ These are the configuration options you will need to use to specify to get start
```php
$config['db_host'] = '127.0.0.1';
$config['db_port'] = 3306;
$config['db_user'] = '';
$config['db_pass'] = '';
$config['db_name'] = '';

View File

@@ -28,10 +28,12 @@ $dbhost = @$_POST['dbhost'] ?: 'localhost';
$dbuser = @$_POST['dbuser'] ?: 'librenms';
$dbpass = @$_POST['dbpass'] ?: '';
$dbname = @$_POST['dbname'] ?: 'librenms';
$dbport = @$_POST['dbport'] ?: 3306;
$config['db_host']=$dbhost;
$config['db_user']=$dbuser;
$config['db_pass']=$dbpass;
$config['db_name']=$dbname;
$config['db_port']=$dbport;
$add_user = @$_POST['add_user'] ?: '';
$add_pass = @$_POST['add_pass'] ?: '';
@@ -40,7 +42,7 @@ $add_email = @$_POST['add_email'] ?: '';
// Check we can connect to MySQL DB, if not, back to stage 1 :)
if ($stage > 1) {
$database_link = mysqli_connect('p:'.$dbhost, $dbuser, $dbpass, $dbname);
$database_link = mysqli_connect('p:'.$dbhost, $dbuser, $dbpass, $dbname, $dbport);
if (mysqli_connect_error()) {
$stage = 1;
$msg = "Couldn't connect to the database, please check your details<br /> " . mysqli_connect_error();
@@ -253,6 +255,12 @@ if ($ext_loaded == 'no') {
<input type="text" class="form-control" name="dbhost" id="dbhost" value="<?php echo $dbhost; ?>">
</div>
</div>
<div class="form-group">
<label for="dbport" class="col-sm-4" control-label">DB Port: </label>
<div class="col-sm-8">
<input type="text" class="form-control" name="dbport" id="dbport" value="<?php echo $dbport; ?>">
</div>
</div>
<div class="form-group">
<label for="dbuser" class="col-sm-4" control-label">DB User: </label>
<div class="col-sm-8">
@@ -292,6 +300,7 @@ if ($ext_loaded == 'no') {
$config['db_user'] = $dbuser;
$config['db_pass'] = $dbpass;
$config['db_name'] = $dbname;
$config['db_port'] = $dbport;
$sql_file = '../build.sql';
$_SESSION['last'] = time();
ob_end_flush();
@@ -322,6 +331,7 @@ if ($_SESSION['offset'] < 100 && $_REQUEST['offset'] < 94) {
<input type="hidden" name="dbuser" value="<?php echo $dbuser; ?>">
<input type="hidden" name="dbpass" value="<?php echo $dbpass; ?>">
<input type="hidden" name="dbname" value="<?php echo $dbname; ?>">
<input type="hidden" name="dbport" value="<?php echo $dbport; ?>">
<button type="submit" class="btn btn-success">Goto Add User</button>
</form>
</div>
@@ -343,6 +353,7 @@ $config_file = <<<"EOD"
### Database config
\$config\['db_host'\] = '$dbhost';
\$config\['db_port'\] = '$dbport';
\$config\['db_user'\] = '$dbuser';
\$config\['db_pass'\] = '$dbpass';
\$config\['db_name'\] = '$dbname';

View File

@@ -34,6 +34,9 @@ $config['db']['extension'] = 'mysqli';//mysql and mysqli available
// MySQL Debug level
$config['mysql_log_level'] = 'ERROR';
//MySQL port
$config['db_port'] = 3306;
// What is my own hostname (used to identify this host in its own database)
$config['own_hostname'] = 'localhost';

View File

@@ -97,7 +97,7 @@ if ($config['memcached']['enable'] === true) {
if (!module_selected('nodb', $init_modules)) {
// Connect to database
$database_link = mysqli_connect('p:' . $config['db_host'], $config['db_user'], $config['db_pass']);
$database_link = mysqli_connect('p:' . $config['db_host'], $config['db_user'], $config['db_pass'], null, $config['db_port']);
if (!$database_link) {
echo '<h2>MySQL Error</h2>';
echo mysqli_connect_error();

View File

@@ -136,16 +136,13 @@ poller_path = config['install_dir'] + '/poller.php'
discover_path = config['install_dir'] + '/discovery.php'
db_username = config['db_user']
db_password = config['db_pass']
db_port = int(config['db_port'])
if config['db_host'][:5].lower() == 'unix:':
db_server = config['db_host']
db_port = 0
elif ':' in config['db_host']:
db_server = config['db_host'].rsplit(':')[0]
db_port = int(config['db_host'].rsplit(':')[1])
else:
db_server = config['db_host']
db_port = 0
db_dbname = config['db_name']

View File

@@ -77,16 +77,13 @@ except:
poller_path = config['install_dir'] + '/poller.php'
db_username = config['db_user']
db_password = config['db_pass']
db_port = int(config['db_port'])
if config['db_host'][:5].lower() == 'unix:':
db_server = config['db_host']
db_port = 0
elif ':' in config['db_host']:
db_server = config['db_host'].rsplit(':')[0]
db_port = int(config['db_host'].rsplit(':')[1])
else:
db_server = config['db_host']
db_port = 0
db_dbname = config['db_name']

View File

@@ -154,7 +154,7 @@ if (isset($config['user'])) {
}
// Run test on MySQL
$test_db = @mysqli_connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']);
$test_db = @mysqli_connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name'], $config['db_port']);
if (mysqli_connect_error()) {
print_fail('Error connecting to your database '.mysqli_connect_error());
} else {