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
This commit is contained in:
Tony Murray
2018-10-02 07:56:13 -05:00
committed by GitHub
parent 9a17307f3f
commit 421bcb030d
8 changed files with 72 additions and 54 deletions

View File

@@ -32,6 +32,8 @@ class AppServiceProvider extends ServiceProvider
Log::getMonolog()->popHandler(); // remove existing errorlog logger Log::getMonolog()->popHandler(); // remove existing errorlog logger
Log::useFiles(Config::get('log_file', base_path('logs/librenms.log')), 'error'); 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 directives (Yucky because of < L5.5)
Blade::directive('config', function ($key) { Blade::directive('config', function ($key) {

View File

@@ -51,7 +51,7 @@ return [
| |
*/ */
'url' => env('APP_URL', 'http://localhost'), 'url' => env('APP_URL'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@@ -19,6 +19,7 @@ DB_SOCKET=
## Trusted Reverse Proxies ## Trusted Reverse Proxies
A comma separated list of trusted reverse proxy IPs or CIDR. A comma separated list of trusted reverse proxy IPs or CIDR.
For legacy reasons the default is `'*'`, which means any proxy is allowed. For legacy reasons the default is `'*'`, which means any proxy is allowed.
`'**'` means trust any proxy up the chain. `'**'` 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 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 ## User / Group
The user and group that LibreNMS should operate as. The user and group that LibreNMS should operate as.

View File

@@ -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) 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']`.
### <a name='my-alerts-aren't-being-delivered-on-time'>My alerts aren't being delivered on time</a> ### <a name='my-alerts-aren't-being-delivered-on-time'>My alerts aren't being delivered on time</a>
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. 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.

View File

@@ -1,7 +1,7 @@
@extends('layouts.librenmsv1') @extends('layouts.librenmsv1')
@section('javascript') @section('javascript')
<script src="js/jquery.qrcode.min.js"></script> <script src="{{ asset('js/jquery.qrcode.min.js') }}"></script>
@endsection @endsection
@section('content') @section('content')

View File

@@ -25,7 +25,7 @@
@foreach($devices as $device) @foreach($devices as $device)
<tr> <tr>
<td><span class="alert-status {{ $device->status ? 'label-success' : 'label-danger' }}"></span></td> <td><span class="alert-status {{ $device->status ? 'label-success' : 'label-danger' }}"></span></td>
<td><img src="{{ $device->icon }}" width="32px" height="32px"></td> <td><img src="{{ asset($device->icon) }}" width="32px" height="32px"></td>
<td class="device-name">{{ $device->displayName() }}</td> <td class="device-name">{{ $device->displayName() }}</td>
<td>{{ $device->hardware }} {{ $device->features }}</td> <td>{{ $device->hardware }} {{ $device->features }}</td>
<td>{{ $device->formatUptime(true) }}<br>{{ substr($device->location, 0, 32) }}</td> <td>{{ $device->formatUptime(true) }}<br>{{ substr($device->location, 0, 32) }}</td>

View File

@@ -8,12 +8,12 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@if(!LibreNMS\Config::get('favicon', false)) @if(!LibreNMS\Config::get('favicon', false))
<link rel="apple-touch-icon" sizes="180x180" href="images/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="180x180" href="{{ asset('images/apple-touch-icon.png') }}">
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32"> <link rel="icon" type="image/png" href="{{ asset('images/favicon-32x32.png') }}" sizes="32x32">
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16"> <link rel="icon" type="image/png" href="{{ asset('images/favicon-16x16.png') }}" sizes="16x16">
<link rel="manifest" href="images/manifest.json"> <link rel="manifest" href="{{ asset('images/manifest.json') }}">
<link rel="mask-icon" href="images/safari-pinned-tab.svg" color="#5bbad5"> <link rel="mask-icon" href="{{ asset('images/safari-pinned-tab.svg') }}" color="#5bbad5">
<link rel="shortcut icon" href="images/favicon.ico"> <link rel="shortcut icon" href="{{ asset('images/favicon.ico') }}">
<meta name="csrf-token" content="{{ csrf_token() }}"> <meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="msapplication-config" content="images/browserconfig.xml"> <meta name="msapplication-config" content="images/browserconfig.xml">
<meta name="theme-color" content="#ffffff"> <meta name="theme-color" content="#ffffff">
@@ -21,53 +21,53 @@
<link rel="shortcut icon" href="{{ LibreNMS\Config::get('favicon') }}" /> <link rel="shortcut icon" href="{{ LibreNMS\Config::get('favicon') }}" />
@endif @endif
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/bootstrap-datetimepicker.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/bootstrap-switch.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/toastr.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/toastr.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/jquery-ui.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/jquery-ui.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/jquery.bootgrid.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/jquery.bootgrid.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/tagmanager.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/tagmanager.css') }}" rel="stylesheet" type="text/css" />
<link href="css/mktree.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/mktree.css') }}" rel="stylesheet" type="text/css" />
<link href="css/vis.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/vis.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/font-awesome.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/jquery.gridster.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/jquery.gridster.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/leaflet.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/leaflet.css') }}" rel="stylesheet" type="text/css" />
<link href="css/MarkerCluster.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/MarkerCluster.css') }}" rel="stylesheet" type="text/css" />
<link href="css/MarkerCluster.Default.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/MarkerCluster.Default.css') }}" rel="stylesheet" type="text/css" />
<link href="css/leaflet.awesome-markers.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/leaflet.awesome-markers.css') }}" rel="stylesheet" type="text/css" />
<link href="css/select2.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/select2.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/select2-bootstrap.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/select2-bootstrap.min.css') }}" rel="stylesheet" type="text/css" />
<link href="css/query-builder.default.min.css" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/query-builder.default.min.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ LibreNMS\Config::get('stylesheet', 'css/styles.css') }}?ver=20180512" rel="stylesheet" type="text/css" /> <link href="{{ asset(LibreNMS\Config::get('stylesheet', 'css/styles.css')) }}?ver=20180512" rel="stylesheet" type="text/css" />
<link href="css/{{ LibreNMS\Config::get('site_style', 'light') }}.css?ver=632417642" rel="stylesheet" type="text/css" /> <link href="{{ asset('css/' . LibreNMS\Config::get('site_style', 'light') . '.css?ver=632417642') }}" rel="stylesheet" type="text/css" />
@foreach(LibreNMS\Config::get('webui.custom_css', []) as $custom_css) @foreach(LibreNMS\Config::get('webui.custom_css', []) as $custom_css)
<link href="{{ $custom_css }}" rel="stylesheet" type="text/css" /> <link href="{{ asset($custom_css) }}" rel="stylesheet" type="text/css" />
@endforeach @endforeach
@yield('css') @yield('css')
<script src="js/jquery.min.js"></script> <script src="{{ asset('js/jquery.min.js') }}"></script>
<script src="js/bootstrap.min.js"></script> <script src="{{ asset('js/bootstrap.min.js') }}"></script>
<script src="js/bootstrap-hover-dropdown.min.js"></script> <script src="{{ asset('js/bootstrap-hover-dropdown.min.js') }}"></script>
<script src="js/bootstrap-switch.min.js"></script> <script src="{{ asset('js/bootstrap-switch.min.js') }}"></script>
<script src="js/hogan-2.0.0.js"></script> <script src="{{ asset('js/hogan-2.0.0.js') }}"></script>
<script src="js/jquery.cycle2.min.js"></script> <script src="{{ asset('js/jquery.cycle2.min.js') }}"></script>
<script src="js/moment.min.js"></script> <script src="{{ asset('js/moment.min.js') }}"></script>
<script src="js/bootstrap-datetimepicker.min.js"></script> <script src="{{ asset('js/bootstrap-datetimepicker.min.js') }}"></script>
<script src="js/typeahead.bundle.min.js"></script> <script src="{{ asset('js/typeahead.bundle.min.js') }}"></script>
<script src="js/jquery-ui.min.js"></script> <script src="{{ asset('js/jquery-ui.min.js') }}"></script>
<script src="js/tagmanager.js"></script> <script src="{{ asset('js/tagmanager.js') }}"></script>
<script src="js/mktree.js"></script> <script src="{{ asset('js/mktree.js') }}"></script>
<script src="js/jquery.bootgrid.min.js"></script> <script src="{{ asset('js/jquery.bootgrid.min.js') }}"></script>
<script src="js/handlebars.min.js"></script> <script src="{{ asset('js/handlebars.min.js') }}"></script>
<script src="js/pace.min.js"></script> <script src="{{ asset('js/pace.min.js') }}"></script>
<script src="js/qrcode.min.js"></script> <script src="{{ asset('js/qrcode.min.js') }}"></script>
@if(LibreNMS\Config::get('enable_lazy_load', true)) @if(LibreNMS\Config::get('enable_lazy_load', true))
<script src="js/jquery.lazyload.min.js"></script> <script src="{{ asset('js/jquery.lazyload.min.js') }}"></script>
<script src="js/lazyload.js"></script> <script src="{{ asset('js/lazyload.js') }}"></script>
@endif @endif
<script src="js/select2.min.js"></script> <script src="{{ asset('js/select2.min.js') }}"></script>
<script src="js/librenms.js?ver=20180512"></script> <script src="{{ asset('js/librenms.js?ver=20180512') }}"></script>
<script type="text/javascript"> <script type="text/javascript">
<!-- Begin <!-- Begin
@@ -79,9 +79,9 @@
} }
// End --> // End -->
</script> </script>
<script type="text/javascript" src="js/overlib_mini.js"></script> <script type="text/javascript" src="{{ asset('js/overlib_mini.js') }}"></script>
<script type="text/javascript" src="js/toastr.min.js"></script> <script type="text/javascript" src="{{ asset('js/toastr.min.js') }}"></script>
<script type="text/javascript" src="js/boot.js"></script> <script type="text/javascript" src="{{ asset('js/boot.js') }}"></script>
@yield('javascript') @yield('javascript')
</head> </head>
<body> <body>

View File

@@ -45,7 +45,7 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () {
}); });
// Debugbar routes need to be here because of catch-all // 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', [ Route::get('/_debugbar/assets/stylesheets', [
'as' => 'debugbar-css', 'as' => 'debugbar-css',
'uses' => '\Barryvdh\Debugbar\Controllers\AssetController@css' 'uses' => '\Barryvdh\Debugbar\Controllers\AssetController@css'