mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Remove DB credentials from config.php
Better validation when config.php does not exist Update docs and quote password only populate legacy vars in config_to_json drop .travis.yml config copy remove credentials from config.php.default Check for existance of .env instead of config.php in python scripts legacy credential cleanup tiny cleanups consistent env for artisan server and artisan dusk
This commit is contained in:
@@ -450,6 +450,9 @@ class Config
|
||||
}
|
||||
|
||||
self::populateTime();
|
||||
|
||||
// populate legacy DB credentials, just in case something external uses them. Maybe remove this later
|
||||
self::populateLegacyDbCredentials();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,42 +491,6 @@ class Config
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get just the database connection settings from config.php
|
||||
*
|
||||
* @return array (keys: db_host, db_port, db_name, db_user, db_pass, db_socket)
|
||||
*/
|
||||
public static function getDatabaseSettings()
|
||||
{
|
||||
// Do not access global $config in this function!
|
||||
|
||||
$keys = $config = [
|
||||
'db_host' => '',
|
||||
'db_port' => '',
|
||||
'db_name' => '',
|
||||
'db_user' => '',
|
||||
'db_pass' => '',
|
||||
'db_socket' => '',
|
||||
];
|
||||
|
||||
if (is_file(__DIR__ . '/../config.php')) {
|
||||
include __DIR__ . '/../config.php';
|
||||
}
|
||||
|
||||
// Check for testing database
|
||||
if (isset($config['test_db_name'])) {
|
||||
putenv('DB_TEST_DATABASE=' . $config['test_db_name']);
|
||||
}
|
||||
if (isset($config['test_db_user'])) {
|
||||
putenv('DB_TEST_USERNAME=' . $config['test_db_user']);
|
||||
}
|
||||
if (isset($config['test_db_pass'])) {
|
||||
putenv('DB_TEST_PASSWORD=' . $config['test_db_pass']);
|
||||
}
|
||||
|
||||
return array_intersect_key($config, $keys); // return only the db settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate the actual path of a binary
|
||||
*
|
||||
@@ -565,4 +532,16 @@ class Config
|
||||
self::set('time.year', $now - 31536000); // time() - (365 * 24 * 60 * 60);
|
||||
self::set('time.twoyear', $now - 63072000); // time() - (2 * 365 * 24 * 60 * 60);
|
||||
}
|
||||
|
||||
public static function populateLegacyDbCredentials()
|
||||
{
|
||||
$db = config('database.default');
|
||||
|
||||
self::set('db_host', config("database.connections.$db.host", 'localhost'));
|
||||
self::set('db_name', config("database.connections.$db.database", 'librenms'));
|
||||
self::set('db_user', config("database.connections.$db.username", 'librenms'));
|
||||
self::set('db_pass', config("database.connections.$db.password"));
|
||||
self::set('db_port', config("database.connections.$db.port", 3306));
|
||||
self::set('db_socket', config("database.connections.$db.unix_socket"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user