mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
db wip
This commit is contained in:
@@ -25,10 +25,49 @@
|
||||
|
||||
namespace App\Http\Controllers\Install;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use LibreNMS\DB\Eloquent;
|
||||
|
||||
class DatabaseController extends \App\Http\Controllers\Controller
|
||||
{
|
||||
public function __invoke()
|
||||
const KEYS = ['host', 'username', 'password', 'database', 'port', 'unix_socket'];
|
||||
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
// TODO: Implement __invoke() method.
|
||||
$data = Arr::only(session()->get('db') ?: [], self::KEYS);
|
||||
$data['stage'] = 2;
|
||||
|
||||
return view('install.database', $data);
|
||||
}
|
||||
|
||||
public function test(Request $request)
|
||||
{
|
||||
Eloquent::setConnection(
|
||||
'setup',
|
||||
$request->get('host', 'localhost'),
|
||||
$request->get('username', 'librenms'),
|
||||
$request->get('password', ''),
|
||||
$request->get('database', 'librenms'),
|
||||
$request->get('port', 3306),
|
||||
$request->get('unix_socket')
|
||||
);
|
||||
|
||||
session()->put('db', Arr::only(config('database.connections.setup', []), self::KEYS));
|
||||
|
||||
$ok = false;
|
||||
$message = '';
|
||||
try {
|
||||
$ok = Eloquent::isConnected('setup');
|
||||
} catch (\Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
session(['install.database' => $ok]);
|
||||
|
||||
return response()->json([
|
||||
'result' => $ok ? 'ok' : 'fail',
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
return [
|
||||
'title' => 'LibreNMS Install',
|
||||
'install' => 'Install',
|
||||
'welcome' => 'Welcome to the LibreNMS installer',
|
||||
'stage' => 'Stage :stage of :stages complete',
|
||||
'checks' => [
|
||||
'title' => 'Pre-Install Checks',
|
||||
@@ -10,5 +9,15 @@ return [
|
||||
'item' => 'Item',
|
||||
'status' => 'Status',
|
||||
'comment' => 'Comment',
|
||||
],
|
||||
'database' => [
|
||||
'host' => 'Host',
|
||||
'port' => 'Port',
|
||||
'socket' => 'Unix-Socket',
|
||||
'user' => 'User',
|
||||
'password' => 'Password',
|
||||
'name' => 'Name',
|
||||
'socket_empty' => 'Leave empty if using Unix-Socket',
|
||||
'ip_empty' => 'Leave empty if using Host',
|
||||
]
|
||||
];
|
||||
|
66
resources/views/install/database.blade.php
Normal file
66
resources/views/install/database.blade.php
Normal file
@@ -0,0 +1,66 @@
|
||||
@extends('layouts.install')
|
||||
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<form id="database-form" class="form-horizontal" role="form" method="post" action="{{ route('install.test-database') }}">
|
||||
@csrf
|
||||
<div class="form-group">
|
||||
<label for="host" class="col-sm-4 control-label">@lang('install.database.host')</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" name="host" id="host" value="{{ $host ?? 'localhost' }}" placeholder="@lang('install.database.socket_empty')">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="port" class="col-sm-4 control-label">@lang('install.database.port')</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" name="port" id="port" value="{{ $port ?? 3306 }}" placeholder="@lang('install.database.socket_empty')">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="unix_socket" class="col-sm-4 control-label">@lang('install.database.socket')</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" name="unix_socket" id="unix_socket" value="{{ $unix_socket }}" placeholder="@lang('install.database.ip_empty')">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="username" class="col-sm-4 control-label">@lang('install.database.username')</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" name="username" id="username" value="{{ $username ?? 'librenms' }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password" class="col-sm-4 control-label">@lang('install.database.password')</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="password" class="form-control" name="password" id="password" value="{{ $password }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="database" class="col-sm-4 control-label">@lang('install.database.name')</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" name="database" id="database" value="{{ $database ?? 'librenms' }}">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success pull-right">Test</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
<script>
|
||||
$('#database-form').submit(function (event) {
|
||||
event.preventDefault();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: $('#database-form').attr('action'),
|
||||
data: $('#database-form').serialize(),
|
||||
success: function (response) {
|
||||
alert(response.message)
|
||||
},
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
@@ -33,9 +33,9 @@
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div id="install-progress" class="progress progress-striped">
|
||||
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="{{ !empty($stage) ? (($stages ?? 6) / $stage) : 0 }}"
|
||||
aria-valuemin="0" aria-valuemax="100" style="width: {{ !empty($stage) ? (($stages ?? 6) / $stage) : 0 }}%">
|
||||
<span class="sr-only">{{ !empty($stage) ? (($stages ?? 6) / $stage) : 0 }}% Complete</span>
|
||||
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="{{ ($stage ?? 0) / ($stages ?? 6) * 100 }}"
|
||||
aria-valuemin="0" aria-valuemax="100" style="width: {{ ($stage ?? 0) / ($stages ?? 6) * 100 }}%">
|
||||
<span class="sr-only">{{ ($stage ?? 0) / ($stages ?? 6) * 100 }}% Complete</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -51,5 +51,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@yield('scripts')
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -150,12 +150,13 @@ Route::group(['middleware' => ['auth'], 'guard' => 'auth'], function () {
|
||||
|
||||
// installation routes
|
||||
Route::group(['prefix' => 'install', 'namespace' => 'Install'], function () {
|
||||
Route::get('/', 'InstallationController')->name('install');
|
||||
Route::redirect('/', '/install/checks')->name('install');
|
||||
Route::get('/checks', 'ChecksController')->name('install.checks');
|
||||
Route::get('/database', 'DatabaseController')->name('install.database');
|
||||
Route::get('/user', 'MakeUserController')->name('install.user');
|
||||
Route::get('/finish', 'FinalizeController')->name('install.finish');
|
||||
Route::any('/migrate-database', 'DatabaseMigrationController')->name('install.migrate-database');
|
||||
Route::post('/database/test', 'DatabaseController@test')->name('install.test-database');
|
||||
Route::any('/database/migrate', 'DatabaseMigrationController')->name('install.migrate-database');
|
||||
});
|
||||
|
||||
// Legacy routes
|
||||
|
Reference in New Issue
Block a user