mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refined finish
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
namespace App\Http\Controllers\Install;
|
||||
|
||||
use Exception;
|
||||
use LibreNMS\Exceptions\FileWriteFailedException;
|
||||
use LibreNMS\Interfaces\InstallerStep;
|
||||
use LibreNMS\Util\EnvHelper;
|
||||
|
||||
@@ -40,58 +41,68 @@ class FinalizeController extends InstallationController implements InstallerStep
|
||||
}
|
||||
|
||||
$env = '';
|
||||
$config = '';
|
||||
$config_file = base_path('config.php');
|
||||
$config = $this->getConfigFileContents();
|
||||
$messages = [];
|
||||
$success = true;
|
||||
$success = false;
|
||||
$config_message = file_exists($config_file) ? trans('install.finish.config_exists') : trans('install.finish.config_written');
|
||||
$env_message = trans('install.finish.env_written');
|
||||
|
||||
try {
|
||||
$this->writeConfigFile();
|
||||
} catch (Exception $e) {
|
||||
$messages[] = $e->getMessage();
|
||||
$config = $this->getConfigFileContents();
|
||||
$config_message = trans('install.finish.config_not_written');
|
||||
}
|
||||
|
||||
try {
|
||||
$this->writeEnvFile();
|
||||
$success = true;
|
||||
}
|
||||
|
||||
// write env last only if everything else succeeded
|
||||
if ($success) {
|
||||
try {
|
||||
$env = $this->writeEnvFile();
|
||||
} catch (Exception $e) {
|
||||
$messages[] = $e->getMessage();
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
session()->flush();
|
||||
} catch (Exception $e) {
|
||||
$env = $this->getEnvFileContents();
|
||||
$messages[] = $e->getMessage();
|
||||
$env_message = trans('install.finish.env_not_written');
|
||||
}
|
||||
|
||||
return view('install.finish', $this->formatData([
|
||||
'success' => $success,
|
||||
'env' => $env,
|
||||
'config' => $config,
|
||||
'messages' => $messages,
|
||||
'success' => $success,
|
||||
'env_message' => $env_message,
|
||||
'config_message' => $config_message,
|
||||
]));
|
||||
}
|
||||
|
||||
private function writeEnvFile()
|
||||
{
|
||||
return EnvHelper::writeEnv(
|
||||
$this->envVars(),
|
||||
['INSTALL'],
|
||||
base_path('.env')
|
||||
);
|
||||
}
|
||||
|
||||
private function envVars()
|
||||
{
|
||||
$this->configureDatabase();
|
||||
$connection = config('database.default', $this->connection);
|
||||
return EnvHelper::writeEnv([
|
||||
$port = config("database.connections.$connection.port");
|
||||
return [
|
||||
'NODE_ID' => uniqid(),
|
||||
'DB_HOST' => config("database.connections.$connection.host"),
|
||||
'DB_PORT' => config("database.connections.$connection.port"),
|
||||
'DB_PORT' => $port == 3306 ? null : $port, // don't set default port
|
||||
'DB_USERNAME' => config("database.connections.$connection.username"),
|
||||
'DB_PASSWORD' => config("database.connections.$connection.password"),
|
||||
'DB_DATABASE' => config("database.connections.$connection.database"),
|
||||
'DB_SOCKET' => config("database.connections.$connection.unix_socket"),
|
||||
], ['INSTALL'], base_path('.env'));
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \LibreNMS\Exceptions\FileWriteFailedException
|
||||
*/
|
||||
private function writeConfigFile()
|
||||
{
|
||||
$config_file = base_path('config.php');
|
||||
@@ -100,7 +111,7 @@ class FinalizeController extends InstallationController implements InstallerStep
|
||||
}
|
||||
|
||||
if (!copy(base_path('config.php.default'), $config_file)) {
|
||||
throw new Exception("We couldn't create the config.php file, please create this manually before continuing by copying the below into a config.php in the root directory of your install (typically /opt/librenms/)");
|
||||
throw new FileWriteFailedException($config_file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +120,15 @@ class FinalizeController extends InstallationController implements InstallerStep
|
||||
return file_get_contents(base_path('config.php.default'));
|
||||
}
|
||||
|
||||
private function getEnvFileContents()
|
||||
{
|
||||
return EnvHelper::setEnv(
|
||||
file_get_contents(base_path('.env')),
|
||||
$this->envVars(),
|
||||
['INSTALL']
|
||||
);
|
||||
}
|
||||
|
||||
public function enabled(): bool
|
||||
{
|
||||
foreach ($this->steps as $step => $controller) {
|
||||
|
@@ -49,6 +49,7 @@ class InstallationController extends Controller
|
||||
public function redirectToIncomplete()
|
||||
{
|
||||
foreach ($this->filterActiveSteps() as $step => $controller) {
|
||||
/** @var InstallerStep $controller */
|
||||
if (!$controller->complete()) {
|
||||
return redirect()->route("install.$step");
|
||||
}
|
||||
@@ -77,12 +78,12 @@ class InstallationController extends Controller
|
||||
$this->filterActiveSteps();
|
||||
$this->configureDatabase();
|
||||
|
||||
foreach ($this->stepStatus() as $step => $complete) {
|
||||
foreach ($this->stepStatus() as $step => $status) {
|
||||
if ($step == $this->step) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$complete) {
|
||||
if (!$status['complete']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -121,7 +122,7 @@ class InstallationController extends Controller
|
||||
$db['password'] ?? null,
|
||||
$db['database'] ?? 'librenms',
|
||||
$db['port'] ?? 3306,
|
||||
$db['socket'] ?? null,
|
||||
$db['socket'] ?? null
|
||||
);
|
||||
config(['database.default', $this->connection]);
|
||||
}
|
||||
|
@@ -50,8 +50,11 @@ return [
|
||||
'finish' => [
|
||||
'title' => 'Finish Install',
|
||||
'env_written' => '.env file written',
|
||||
'env_not_written' => 'Could not write .env file',
|
||||
'env_manual' => 'Manually update :file with the following content',
|
||||
'config_exists' => 'config.php file exists',
|
||||
'config_written' => 'config.php file written',
|
||||
'config_not_required' => 'This file is not required. Here is the default.',
|
||||
'config_not_written' => 'Could not write config.php',
|
||||
'not_finished' => 'You have not quite finished yet!',
|
||||
'validate' => 'First, you need to :validate and fix any issues.',
|
||||
@@ -59,5 +62,6 @@ return [
|
||||
'thanks' => 'Thank you for setting up LibreNMS.',
|
||||
'statistics' => 'It would be great if you would consider contributing to our statistics, you can do this on the :about and check the box under Statistics.',
|
||||
'statistics_link' => 'About LibreNMS Page',
|
||||
'retry' => 'Retry'
|
||||
]
|
||||
];
|
||||
|
@@ -2,23 +2,41 @@
|
||||
|
||||
@section('content')
|
||||
<div class="card mb-2">
|
||||
<div class="card-header" data-toggle="collapse" data-target="#env-file-text" aria-expanded="false">
|
||||
@lang('install.finish.env_written')
|
||||
<i class="fa fa-chevron-up rotate-if-collapsed pull-right"></i>
|
||||
</div>
|
||||
<div id="env-file-text" class="card-body collapse">
|
||||
<pre class="card bg-light p-3">{{ $env }}</pre>
|
||||
<div class="card-header" data-toggle="collapse" data-target="#env-file-text" aria-expanded="{{ $success ? 'false' : 'true' }}">
|
||||
@if($success)
|
||||
<i class="fa fa-lg fa-check-circle text-success"></i>
|
||||
@else
|
||||
<i class="fa fa-lg fa-times-circle text-danger"></i>
|
||||
@endif
|
||||
{{ $env_message }}
|
||||
@if($env)<i class="fa fa-lg fa-chevron-down rotate-if-collapsed pull-right"></i>@endif($env)
|
||||
</div>
|
||||
@if($env)
|
||||
<div id="env-file-text" class="card-body collapse @if(!$success) show @endif">
|
||||
<button class="btn btn-primary float-right" onclick="location.reload()">@lang('install.finish.retry')</button>
|
||||
<strong>
|
||||
@lang('install.finish.env_manual', ['file' => base_path('.env')])
|
||||
</strong>
|
||||
<pre class="card bg-light p-3 mt-3">{{ $env }}</pre>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="card mb-2">
|
||||
<div class="card-header" data-toggle="collapse" data-target="#config-file-text" aria-expanded="false">
|
||||
<i class="fa fa-lg fa-check-circle text-success"></i>
|
||||
{{ $config_message }}
|
||||
<i class="fa fa-chevron-up rotate-if-collapsed pull-right"></i>
|
||||
@if($config)<i class="fa fa-lg fa-chevron-down rotate-if-collapsed pull-right"></i>@endif
|
||||
</div>
|
||||
@if($config)
|
||||
<div id="config-file-text" class="card-body collapse">
|
||||
<pre class="card bg-light p-3">{{ $config }}</pre>
|
||||
<strong>
|
||||
@lang('install.finish.config_not_required')
|
||||
</strong>
|
||||
<pre class="card bg-light p-3 mt-3">{{ $config }}</pre>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@if($success)
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="alert alert-warning">
|
||||
@@ -35,4 +53,5 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@endsection
|
||||
|
Reference in New Issue
Block a user