2020-06-05 14:26:57 -05:00
|
|
|
<?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;
|
2020-06-11 01:06:16 -05:00
|
|
|
use LibreNMS\DB\Eloquent;
|
2020-06-05 14:26:57 -05:00
|
|
|
|
|
|
|
class InstallationController extends Controller
|
|
|
|
{
|
2020-06-11 01:06:16 -05:00
|
|
|
protected $connection = 'setup';
|
|
|
|
protected $steps = [
|
|
|
|
'checks' => \App\Http\Controllers\Install\ChecksController::class,
|
|
|
|
'database' => \App\Http\Controllers\Install\DatabaseController::class,
|
|
|
|
'user' => \App\Http\Controllers\Install\MakeUserController::class,
|
|
|
|
'finish' => \App\Http\Controllers\Install\FinalizeController::class,
|
|
|
|
];
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
if (is_string(config('librenms.install'))) {
|
|
|
|
$this->steps = array_intersect_key($this->steps, array_flip(explode(',', config('librenms.install'))));
|
|
|
|
}
|
|
|
|
$this->configureDatabase();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function baseIndex()
|
|
|
|
{
|
2020-06-11 01:58:42 -05:00
|
|
|
$initial = key($this->steps) ?: 'checks';
|
|
|
|
return redirect()->route("install.$initial");
|
2020-06-11 01:06:16 -05:00
|
|
|
}
|
|
|
|
|
2020-06-06 17:03:32 -05:00
|
|
|
public function invalid()
|
2020-06-05 14:26:57 -05:00
|
|
|
{
|
2020-06-06 17:03:32 -05:00
|
|
|
abort(404);
|
2020-06-05 14:26:57 -05:00
|
|
|
}
|
2020-06-11 01:06:16 -05:00
|
|
|
|
2020-06-11 01:58:42 -05:00
|
|
|
public function stepsCompleted()
|
|
|
|
{
|
2020-06-17 06:59:19 -05:00
|
|
|
return response()->json(array_map(function ($class) {
|
|
|
|
$controller = app()->make($class);
|
2020-06-19 00:17:36 -05:00
|
|
|
return $controller->complete();
|
2020-06-11 01:58:42 -05:00
|
|
|
}, $this->steps));
|
|
|
|
}
|
|
|
|
|
2020-06-15 00:45:40 -05:00
|
|
|
final protected function markStepComplete($step)
|
|
|
|
{
|
|
|
|
session(["install.$step" => true]);
|
2020-06-18 00:41:03 -05:00
|
|
|
session()->save();
|
2020-06-15 00:45:40 -05:00
|
|
|
}
|
|
|
|
|
2020-06-11 01:06:16 -05:00
|
|
|
final protected function formatData($data = [])
|
|
|
|
{
|
2020-06-15 00:45:40 -05:00
|
|
|
$data['steps'] = array_map(function ($class) {
|
|
|
|
return app()->make($class);
|
|
|
|
}, $this->steps);
|
2020-06-11 01:06:16 -05:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function configureDatabase()
|
|
|
|
{
|
|
|
|
$db = session('db');
|
|
|
|
if (!empty($db)) {
|
|
|
|
Eloquent::setConnection(
|
|
|
|
$this->connection,
|
|
|
|
$db['host'] ?? 'localhost',
|
|
|
|
$db['username'] ?? 'librenms',
|
|
|
|
$db['password'] ?? null,
|
|
|
|
$db['database'] ?? 'librenms',
|
|
|
|
$db['port'] ?? 3306,
|
|
|
|
$db['socket'] ?? null,
|
|
|
|
);
|
|
|
|
config(['database.default', $this->connection]);
|
|
|
|
}
|
|
|
|
}
|
2020-06-05 14:26:57 -05:00
|
|
|
}
|