mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
committed by
Neil Lathwood
parent
66d9d54f73
commit
b1a414e785
@@ -29,11 +29,20 @@ $dbuser = @$_POST['dbuser'] ?: 'librenms';
|
||||
$dbpass = @$_POST['dbpass'] ?: '';
|
||||
$dbname = @$_POST['dbname'] ?: 'librenms';
|
||||
$dbport = @$_POST['dbport'] ?: 3306;
|
||||
$dbsocket = @$_POST['dbsocket'] ?: '';
|
||||
$config['db_host']=$dbhost;
|
||||
$config['db_user']=$dbuser;
|
||||
$config['db_pass']=$dbpass;
|
||||
$config['db_name']=$dbname;
|
||||
$config['db_port']=$dbport;
|
||||
$config['db_socket']=$dbsocket;
|
||||
|
||||
if (!empty($config['db_socket'])) {
|
||||
$config['db_host'] = '';
|
||||
$config['db_port'] = null;
|
||||
} else {
|
||||
$config['db_socket'] = null;
|
||||
}
|
||||
|
||||
$add_user = @$_POST['add_user'] ?: '';
|
||||
$add_pass = @$_POST['add_pass'] ?: '';
|
||||
@@ -42,18 +51,15 @@ $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, $dbport);
|
||||
dbQuery("SET NAMES 'utf8'");
|
||||
dbQuery("SET CHARACTER SET 'utf8'");
|
||||
dbQuery("SET COLLATION_CONNECTION = 'utf8_unicode_ci'");
|
||||
if (mysqli_connect_error()) {
|
||||
$stage = 1;
|
||||
$msg = "Couldn't connect to the database, please check your details<br /> " . mysqli_connect_error();
|
||||
} elseif ($stage == 2) {
|
||||
if ($_SESSION['build-ok'] == true) {
|
||||
$stage = 3;
|
||||
$msg = "It appears that the database is already setup so have moved onto stage $stage";
|
||||
try {
|
||||
dbConnect();
|
||||
if ($stage == 2 && $_SESSION['build-ok'] == true) {
|
||||
$stage = 3;
|
||||
$msg = "It appears that the database is already setup so have moved onto stage $stage";
|
||||
}
|
||||
} catch (\LibreNMS\Exceptions\DatabaseConnectException $e) {
|
||||
$stage = 1;
|
||||
$msg = "Couldn't connect to the database, please check your details<br /> " . $e->getMessage();
|
||||
}
|
||||
$_SESSION['stage'] = $stage;
|
||||
}
|
||||
@@ -255,13 +261,19 @@ if ($ext_loaded == 'no') {
|
||||
<div class="form-group">
|
||||
<label for="dbhost" class="col-sm-4" control-label">DB Host: </label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" name="dbhost" id="dbhost" value="<?php echo $dbhost; ?>">
|
||||
<input type="text" class="form-control" name="dbhost" id="dbhost" value="<?php echo $dbhost; ?>" placeholder="Leave empty if using Unix-Socket">
|
||||
</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; ?>">
|
||||
<input type="text" class="form-control" name="dbport" id="dbport" value="<?php echo $dbport; ?>" placeholder="Leave empty if using Unix-Socket">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="dbsocket" class="col-sm-4" control-label">DB Unix-Socket: </label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" name="dbsocket" id="dbsocket" value="<?php echo $dbsocket; ?>" placeholder="Leave empty if using Host">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -304,6 +316,7 @@ if ($ext_loaded == 'no') {
|
||||
$config['db_pass'] = $dbpass;
|
||||
$config['db_name'] = $dbname;
|
||||
$config['db_port'] = $dbport;
|
||||
$config['db_socket'] = $dbsocket;
|
||||
$sql_file = '../build.sql';
|
||||
$_SESSION['last'] = time();
|
||||
ob_end_flush();
|
||||
@@ -335,6 +348,7 @@ if ($_SESSION['offset'] < 100 && $_REQUEST['offset'] < 94) {
|
||||
<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; ?>">
|
||||
<input type="hidden" name="dbsocket" value="<?php echo $dbsocket; ?>">
|
||||
<button type="submit" class="btn btn-success">Goto Add User</button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -360,6 +374,7 @@ $config_file = <<<"EOD"
|
||||
\$config\['db_user'\] = '$dbuser';
|
||||
\$config\['db_pass'\] = '$dbpass';
|
||||
\$config\['db_name'\] = '$dbname';
|
||||
\$config\['db_socket'\] = '$dbsocket';
|
||||
\$config\['db'\]\['extension'\] = "mysqli";// mysql or mysqli
|
||||
|
||||
// This is the user LibreNMS will run as
|
||||
@@ -421,6 +436,7 @@ if (!file_exists("../config.php")) {
|
||||
<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="dbsocket" value="<?php echo $dbsocket; ?>">
|
||||
<button type="submit" class="btn btn-success">Finish install</button>
|
||||
</form>
|
||||
<?php
|
||||
@@ -443,6 +459,7 @@ if (!file_exists("../config.php")) {
|
||||
<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="dbsocket" value="<?php echo $dbsocket; ?>">
|
||||
<div class="form-group">
|
||||
<label for="add_user" class="col-sm-4 control-label">Username</label>
|
||||
<div class="col-sm-8">
|
||||
@@ -498,6 +515,7 @@ if (auth_usermanagement()) {
|
||||
<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="dbsocket" value="<?php echo $dbsocket; ?>">
|
||||
<button type="submit" class="btn btn-success" <?php if ($proceed == "1") {
|
||||
echo "disabled='disabled'";
|
||||
} ?>>Generate Config</button>
|
||||
|
||||
Reference in New Issue
Block a user