mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Automatic fixes for validations * webui * lint fixes * Fix an install issue with ConfigSeeder requesting cli input in web page. * Do not use c_echo in validate.php print_fail()
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use LibreNMS\Interfaces\ValidationFixer;
|
|
use LibreNMS\Validator;
|
|
|
|
class ValidateController extends Controller
|
|
{
|
|
public function index(): View
|
|
{
|
|
return view('validate.index');
|
|
}
|
|
|
|
public function runValidation(): JsonResponse
|
|
{
|
|
$validator = new Validator();
|
|
$validator->validate();
|
|
|
|
return response()->json($validator->toArray());
|
|
}
|
|
|
|
public function runFixer(Request $request): JsonResponse
|
|
{
|
|
$this->validate($request, [
|
|
'fixer' => [
|
|
'starts_with:LibreNMS\Validations',
|
|
function ($attribute, $value, $fail) {
|
|
if (! class_exists($value) || ! in_array(ValidationFixer::class, class_implements($value))) {
|
|
$fail(trans('validation.results.invalid_fixer'));
|
|
}
|
|
},
|
|
],
|
|
]);
|
|
$fixer = $request->get('fixer');
|
|
|
|
return response()->json([
|
|
'result' => (new $fixer)->fix(),
|
|
]);
|
|
}
|
|
}
|