From 421bcb030d9f0343effd94aab98ccc69f50bf56e Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 2 Oct 2018 07:56:13 -0500 Subject: [PATCH] Force root url if set by user (#9266) * Force root url if set by user If user sets APP_URL, force the root url to that. Empty strings result in default behavior. Fix some of the urls in the laravel templates. * Docs update * Add base_url --- app/Providers/AppServiceProvider.php | 2 + config/app.php | 2 +- doc/Support/Environment-Variables.md | 13 +++ doc/Support/FAQ.md | 3 + resources/views/auth/2fa.blade.php | 2 +- resources/views/auth/public-status.blade.php | 2 +- resources/views/layouts/librenmsv1.blade.php | 100 +++++++++---------- routes/web.php | 2 +- 8 files changed, 72 insertions(+), 54 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3c5fcff984..b7c2def78a 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -32,6 +32,8 @@ class AppServiceProvider extends ServiceProvider Log::getMonolog()->popHandler(); // remove existing errorlog logger Log::useFiles(Config::get('log_file', base_path('logs/librenms.log')), 'error'); + // Set root url according to user's settings + \URL::forceRootUrl(\Config::get('app.url')); // Blade directives (Yucky because of < L5.5) Blade::directive('config', function ($key) { diff --git a/config/app.php b/config/app.php index 6c82768534..ae84631dbb 100644 --- a/config/app.php +++ b/config/app.php @@ -51,7 +51,7 @@ return [ | */ - 'url' => env('APP_URL', 'http://localhost'), + 'url' => env('APP_URL'), /* |-------------------------------------------------------------------------- diff --git a/doc/Support/Environment-Variables.md b/doc/Support/Environment-Variables.md index 854acd796d..d3f241f4ba 100644 --- a/doc/Support/Environment-Variables.md +++ b/doc/Support/Environment-Variables.md @@ -19,6 +19,7 @@ DB_SOCKET= ## Trusted Reverse Proxies A comma separated list of trusted reverse proxy IPs or CIDR. + For legacy reasons the default is `'*'`, which means any proxy is allowed. `'**'` means trust any proxy up the chain. @@ -26,6 +27,18 @@ For legacy reasons the default is `'*'`, which means any proxy is allowed. APP_TRUSTED_PROXIES=192.168.1.0/24,192.167.8.20 ``` +## Base url + +Set the base url for generated urls. Do not set this if it is not needed. + +You may need to set this when using reverse proxies combined with a subdirectory. + +Generally, LibreNMS will make correct URLs (especially if you have set up your proxy variables correctly) + +```dotenv +APP_URL=http://librenms/ +``` + ## User / Group The user and group that LibreNMS should operate as. diff --git a/doc/Support/FAQ.md b/doc/Support/FAQ.md index 9e0801961e..8f78579527 100644 --- a/doc/Support/FAQ.md +++ b/doc/Support/FAQ.md @@ -388,5 +388,8 @@ At a minimum: X-Forwarded-For and X-Forwarded-Proto (X-Forwarded-Port if needed) You also need to [Set the proxy or proxies as trusted](../Support/Environment-Variables.md#trusted-reverse-proxies) +If you are using a subdirectory on the reverse proxy and not on the actual web server, +you may need to set [APP_URL](../Support/Environment-Variables.md#base-url) and `$config['base_url']`. + ### My alerts aren't being delivered on time If you're running MySQL/MariaDB on a separate machine or container make sure the timezone is set properly on both the LibreNMS **and** MySQL/MariaDB instance. Alerts will be delivered according to MySQL/MariaDB's time, so a mismatch between the two can cause alerts to be delivered late if LibreNMS is on a timezone later than MySQL/MariaDB. diff --git a/resources/views/auth/2fa.blade.php b/resources/views/auth/2fa.blade.php index 649077db5b..e31ebc0e4c 100644 --- a/resources/views/auth/2fa.blade.php +++ b/resources/views/auth/2fa.blade.php @@ -1,7 +1,7 @@ @extends('layouts.librenmsv1') @section('javascript') - + @endsection @section('content') diff --git a/resources/views/auth/public-status.blade.php b/resources/views/auth/public-status.blade.php index 1e69579462..fb21670d45 100644 --- a/resources/views/auth/public-status.blade.php +++ b/resources/views/auth/public-status.blade.php @@ -25,7 +25,7 @@ @foreach($devices as $device) - + {{ $device->displayName() }} {{ $device->hardware }} {{ $device->features }} {{ $device->formatUptime(true) }}
{{ substr($device->location, 0, 32) }} diff --git a/resources/views/layouts/librenmsv1.blade.php b/resources/views/layouts/librenmsv1.blade.php index 4dea6ef8d0..5a058df6af 100644 --- a/resources/views/layouts/librenmsv1.blade.php +++ b/resources/views/layouts/librenmsv1.blade.php @@ -8,12 +8,12 @@ @if(!LibreNMS\Config::get('favicon', false)) - - - - - - + + + + + + @@ -21,53 +21,53 @@ @endif - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + @foreach(LibreNMS\Config::get('webui.custom_css', []) as $custom_css) - + @endforeach @yield('css') - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @if(LibreNMS\Config::get('enable_lazy_load', true)) - - + + @endif - - + + - - - + + + @yield('javascript') diff --git a/routes/web.php b/routes/web.php index a581245ee7..3553d3a881 100644 --- a/routes/web.php +++ b/routes/web.php @@ -45,7 +45,7 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () { }); // Debugbar routes need to be here because of catch-all - if (config('app.env') !== 'production' && config('app.debug')) { + if (config('app.env') !== 'production' && config('app.debug') && config('debugbar.enabled') !== false) { Route::get('/_debugbar/assets/stylesheets', [ 'as' => 'debugbar-css', 'uses' => '\Barryvdh\Debugbar\Controllers\AssetController@css'