mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
structure and better middleware
This commit is contained in:
34
app/Http/Controllers/Install/ChecksController.php
Normal file
34
app/Http/Controllers/Install/ChecksController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* InstallationChecksController.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 2020 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Install;
|
||||
|
||||
class ChecksController extends \App\Http\Controllers\Controller
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
return view('install.checks');
|
||||
}
|
||||
}
|
34
app/Http/Controllers/Install/DatabaseController.php
Normal file
34
app/Http/Controllers/Install/DatabaseController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* DatabaseController.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 2020 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Install;
|
||||
|
||||
class DatabaseController extends \App\Http\Controllers\Controller
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
// TODO: Implement __invoke() method.
|
||||
}
|
||||
}
|
66
app/Http/Controllers/Install/DatabaseMigrationController.php
Normal file
66
app/Http/Controllers/Install/DatabaseMigrationController.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* DatabaseMigrationController.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 2020 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Install;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\StreamedOutput;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class DatabaseMigrationController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
\LibreNMS\DB\Eloquent::setConnection(
|
||||
'setup',
|
||||
session('dbhost', 'localhost'),
|
||||
session('dbuser', 'librenms'),
|
||||
session('dbpass', 'farts'),
|
||||
session('dbname', 'phpunit_tests_librenms_234324'),
|
||||
session('dbport', 3306)
|
||||
);
|
||||
var_dump(session()->all()); exit;
|
||||
|
||||
$response = new StreamedResponse(function () {
|
||||
try {
|
||||
$output = new StreamedOutput(fopen('php://stdout', 'w'));
|
||||
echo "Starting Update...\n";
|
||||
$ret = \Artisan::call('migrate', ['--seed' => true, '--force' => true, '--database' => 'setup'], $output);
|
||||
if ($ret !== 0) {
|
||||
throw new \RuntimeException('Migration failed');
|
||||
}
|
||||
echo "\n\nSuccess!";
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage() . "\n\nError!";
|
||||
}
|
||||
});
|
||||
|
||||
$response->headers->set('Content-Type', 'text/plain');
|
||||
$response->headers->set('X-Accel-Buffering', 'no');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
34
app/Http/Controllers/Install/FinalizeController.php
Normal file
34
app/Http/Controllers/Install/FinalizeController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* FinalizeController.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 2020 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Install;
|
||||
|
||||
class FinalizeController extends \App\Http\Controllers\Controller
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
// TODO: Implement __invoke() method.
|
||||
}
|
||||
}
|
36
app/Http/Controllers/Install/InstallationController.php
Normal file
36
app/Http/Controllers/Install/InstallationController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* InstallationController.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 2020 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Install;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class InstallationController extends Controller
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
return 'install';
|
||||
}
|
||||
}
|
34
app/Http/Controllers/Install/MakeUserController.php
Normal file
34
app/Http/Controllers/Install/MakeUserController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* MakeUserController.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 2020 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Install;
|
||||
|
||||
class MakeUserController extends \App\Http\Controllers\Controller
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
// TODO: Implement __invoke() method.
|
||||
}
|
||||
}
|
@@ -29,7 +29,7 @@ class Kernel extends HttpKernel
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
'check-installed',
|
||||
\App\Http\Middleware\CheckInstalled::class,
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
@@ -71,8 +71,6 @@ class Kernel extends HttpKernel
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'check-installed' => \App\Http\Middleware\CheckInstalled::class,
|
||||
'check-not-installed' => \App\Http\Middleware\CheckNotInstalled::class,
|
||||
'deny-demo' => \App\Http\Middleware\DenyDemoUser::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
|
@@ -26,6 +26,7 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
|
||||
class CheckInstalled
|
||||
{
|
||||
@@ -38,9 +39,14 @@ class CheckInstalled
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (!file_exists(base_path('config.php')) && !$request->is(['install', 'ajax/db-update'])) {
|
||||
$installed = file_exists(base_path('config.php'));
|
||||
$is_install_route = $request->is('install*');
|
||||
|
||||
if (!$installed && !$is_install_route) {
|
||||
// no config.php does so let's redirect to the install
|
||||
return redirect(url('/install'));
|
||||
return redirect(route('install'));
|
||||
} elseif ($installed && $is_install_route) {
|
||||
throw new AuthorizationException('This should only be called during install');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
4
resources/lang/en/install.php
Normal file
4
resources/lang/en/install.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'title' => 'LibreNMS Install'
|
||||
];
|
5
resources/views/install/checks.blade.php
Normal file
5
resources/views/install/checks.blade.php
Normal file
@@ -0,0 +1,5 @@
|
||||
@extends('layouts.install')
|
||||
|
||||
@section('content')
|
||||
Checks
|
||||
@endsection
|
20
resources/views/layouts/install.blade.php
Normal file
20
resources/views/layouts/install.blade.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>@lang('install.title')</title>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet" type="text/css"/>
|
||||
<link href="{{ asset(Config::get('stylesheet')) }}" rel="stylesheet" type="text/css"/>
|
||||
<script src="{{ asset('js/jquery.min.js') }}"></script>
|
||||
<script src="{{ asset('js/bootstrap.min.js') }}"></script>
|
||||
<script src="{{ asset('js/bootstrap-hover-dropdown.min.js') }}"></script>
|
||||
<script src="{{ asset('js/hogan-2.0.0.js') }}"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
@yield('content')
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@@ -149,9 +149,13 @@ Route::group(['middleware' => ['auth'], 'guard' => 'auth'], function () {
|
||||
});
|
||||
|
||||
// installation routes
|
||||
Route::group(['middleware' => ['check-not-installed']], function () {
|
||||
Route::get('/install', 'Install\InstallationController');
|
||||
Route::any('/ajax/db-update', 'Ajax\DatabaseUpdateController');
|
||||
Route::group(['prefix' => 'install', 'namespace' => 'Install'], function () {
|
||||
Route::get('/', 'InstallationController')->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');
|
||||
});
|
||||
|
||||
// Legacy routes
|
||||
|
Reference in New Issue
Block a user