feature: support non-standard unix socket (#5724)

* Add support for custom MySQL unix-socket

* NULL must be lowercase!

* Naive edit of html/install.php

* fixup

* Refactor dbConnect
Use it everywhere

* $config needs to be global
Don't need to set $database_link

* small cleanups
This commit is contained in:
Tony Murray
2017-04-06 16:02:37 -05:00
committed by Neil Lathwood
parent 66d9d54f73
commit b1a414e785
15 changed files with 196 additions and 129 deletions

View File

@@ -0,0 +1,31 @@
<?php
/**
* DatabaseConnectException.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\Exceptions;
class DatabaseConnectException extends \Exception
{
}

View File

@@ -20,6 +20,8 @@
namespace LibreNMS;
use LibreNMS\Exceptions\DatabaseConnectException;
class IRCBot
{
@@ -365,7 +367,7 @@ class IRCBot
}//end getUser()
private function connect($try)
private function connect($try = 0)
{
if ($try > $this->max_retry) {
$this->log('Failed too many connection attempts, aborting');
@@ -437,15 +439,21 @@ 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'], null, $this->config['db_port'])) != false && mysqli_select_db($this->sql, $this->config['db_name'])) {
return true;
} else {
$this->log('Cannot connect to MySQL');
try {
$this->sql = dbConnect(
$this->config['db_host'],
$this->config['db_user'],
$this->config['db_pass'],
$this->config['db_name'],
$this->config['db_port'],
$this->config['db_socket']
);
} catch (DatabaseConnectException $e) {
$this->log('Cannot connect to MySQL: ' . $e->getMessage());
return die();
}
} else {
return true;
}
return true;
}//end chkdb()