. * * @link https://www.librenms.org * * @copyright 2022 Tony Murray * @author Tony Murray */ namespace LibreNMS\Validations; use Illuminate\Support\Str; use LibreNMS\Config; use LibreNMS\Validator; class WebServer extends BaseValidation { /** * @inheritDoc */ public function validate(Validator $validator): void { if (! app()->runningInConsole()) { $url = request()->url(); $expected = Str::finish(Config::get('base_url'), '/') . 'validate/results'; if ($url !== $expected) { preg_match('#://([^/]+)/#', $url, $actual_host_match); preg_match('#://([^/]+)/#', $expected, $expected_host_match); $actual_host = $actual_host_match[1]; if ($actual_host != $expected_host_match[1]) { $nginx = Str::startsWith(request()->server->get('SERVER_SOFTWARE'), 'nginx'); $server_name = $nginx ? 'server_name' : 'ServerName'; $fix = $nginx ? "server_name $actual_host;" : "ServerName $actual_host"; $validator->fail("$server_name is set incorrectly for your webserver, update your webserver config.", $fix); } else { $correct_base = str_replace('validate/results', '', $url); $validator->fail('base_url is not set correctly', "lnms config:set base_url $correct_base"); } } } } public function isDefault(): bool { return ! app()->runningInConsole(); } }