2018-05-09 08:05:17 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Menu.php
|
|
|
|
*
|
2018-09-11 07:51:35 -05:00
|
|
|
* Builds data for LibreNMS menu
|
2018-05-09 08:05:17 -05:00
|
|
|
*
|
|
|
|
* 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
|
2021-02-09 00:29:04 +01:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-05-09 08:05:17 -05:00
|
|
|
*
|
2021-02-09 00:29:04 +01:00
|
|
|
* @link https://www.librenms.org
|
2021-09-10 20:09:53 +02:00
|
|
|
*
|
2018-05-09 08:05:17 -05:00
|
|
|
* @copyright 2018 Tony Murray
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\ViewComposers;
|
|
|
|
|
|
|
|
use App\Models\AlertRule;
|
|
|
|
use App\Models\BgpPeer;
|
2024-01-31 22:56:59 +08:00
|
|
|
use App\Models\CustomMap;
|
2020-04-10 14:34:44 +02:00
|
|
|
use App\Models\Dashboard;
|
2018-05-09 08:05:17 -05:00
|
|
|
use App\Models\Device;
|
|
|
|
use App\Models\DeviceGroup;
|
2024-04-25 09:19:21 -05:00
|
|
|
use App\Models\Link;
|
Refactored and update Location Geocoding (#9359)
- Fix location so it is a regular database relation (this allows multiple devices to be accurately linked to one location and saves api calls)
- Parse coordinates from the location more consistently
- Add settings to webui
- ~~Used [PHP Geocoder](http://geocoder-php.org/), which has lots of backends and is well tested. (also includes reverse and geoip)~~
- Google Maps, Bing, Mapquest, and OpenStreetMap supported initially.
- Default to OpenStreetMap, which doesn't require a key. They will liberally hand out bans if you exceed 1 query per second though.
- All other Geocoding APIs require an API key. (Google requires a credit card on file, but seems to be the most accurate)
- Update all (I think) sql queries to handle the new structure
- Remove final vestiges of override_sysLocation as a device attribute
- Update existing device groups and rules in DB
- Tested all APIs with good/bad location, no/bad/good key, and no connection.
- Cannot fix advanced queries that use location
This blocks #8868
DO NOT DELETE THIS TEXT
#### Please note
> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.
- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)
#### Testers
If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`. If there are schema changes, you can ask on discord how to revert.
2018-11-28 16:49:18 -06:00
|
|
|
use App\Models\Location;
|
2018-05-09 08:05:17 -05:00
|
|
|
use App\Models\Notification;
|
|
|
|
use App\Models\Package;
|
2022-08-07 14:49:57 -05:00
|
|
|
use App\Models\PortGroup;
|
2023-09-01 03:25:24 +02:00
|
|
|
use App\Models\PortsNac;
|
2018-05-09 08:05:17 -05:00
|
|
|
use App\Models\User;
|
2019-11-14 19:40:38 +01:00
|
|
|
use App\Models\UserPref;
|
2019-06-03 19:15:13 -05:00
|
|
|
use App\Models\Vminfo;
|
2018-05-09 08:05:17 -05:00
|
|
|
use App\Models\WirelessSensor;
|
2022-11-05 10:04:36 +01:00
|
|
|
use Illuminate\Support\Collection;
|
2021-03-31 21:30:04 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2018-05-09 08:05:17 -05:00
|
|
|
use Illuminate\View\View;
|
|
|
|
use LibreNMS\Config;
|
2024-08-15 15:26:47 -05:00
|
|
|
use LibreNMS\Interfaces\Plugins\Hooks\MenuEntryHook;
|
2021-10-19 13:53:28 +02:00
|
|
|
use LibreNMS\Plugins;
|
2019-05-10 11:02:39 -05:00
|
|
|
use LibreNMS\Util\ObjectCache;
|
2021-10-19 13:53:28 +02:00
|
|
|
use PluginManager;
|
2018-05-09 08:05:17 -05:00
|
|
|
|
|
|
|
class MenuComposer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bind data to the view.
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param View $view
|
2018-05-09 08:05:17 -05:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function compose(View $view)
|
|
|
|
{
|
|
|
|
$vars = [];
|
|
|
|
/** @var User $user */
|
|
|
|
$user = Auth::user();
|
2019-11-17 05:13:48 +00:00
|
|
|
$site_style = Config::get('applied_site_style');
|
2018-05-09 08:05:17 -05:00
|
|
|
|
2020-04-10 14:34:44 +02:00
|
|
|
//global Settings
|
|
|
|
$vars['hide_dashboard_editor'] = UserPref::getPref($user, 'hide_dashboard_editor');
|
|
|
|
// end global Settings
|
|
|
|
|
2019-11-14 19:40:38 +01:00
|
|
|
//TODO: should be handled via CSS Themes
|
2020-05-21 21:04:54 -03:00
|
|
|
$vars['navbar'] = in_array($site_style, ['mono']) ? 'navbar-inverse' : '';
|
2018-05-09 08:05:17 -05:00
|
|
|
|
|
|
|
$vars['project_name'] = Config::get('project_name', 'LibreNMS');
|
2019-05-10 11:02:39 -05:00
|
|
|
$vars['title_image'] = Config::get('title_image', "images/librenms_logo_$site_style.svg");
|
2018-05-09 08:05:17 -05:00
|
|
|
|
2020-04-10 14:34:44 +02:00
|
|
|
//Dashboards
|
|
|
|
$vars['dashboards'] = Dashboard::select('dashboard_id', 'dashboard_name')->allAvailable($user)->orderBy('dashboard_name')->get();
|
|
|
|
|
2018-05-09 08:05:17 -05:00
|
|
|
// Device menu
|
2019-05-13 14:26:52 -05:00
|
|
|
$vars['device_groups'] = DeviceGroup::hasAccess($user)->orderBy('name')->get(['device_groups.id', 'name', 'desc']);
|
2018-05-09 08:05:17 -05:00
|
|
|
$vars['package_count'] = Package::hasAccess($user)->count();
|
|
|
|
|
2019-05-13 14:26:52 -05:00
|
|
|
$vars['device_types'] = Device::hasAccess($user)->select('type')->distinct()->where('type', '!=', '')->orderBy('type')->pluck('type');
|
2018-05-09 08:05:17 -05:00
|
|
|
|
2019-05-13 14:26:52 -05:00
|
|
|
$vars['locations'] = (Config::get('show_locations') && Config::get('show_locations_dropdown')) ?
|
|
|
|
Location::hasAccess($user)->where('location', '!=', '')->orderBy('location')->get(['location', 'id']) :
|
2022-11-05 10:04:36 +01:00
|
|
|
new Collection();
|
2019-06-03 19:15:13 -05:00
|
|
|
$vars['show_vmwinfo'] = Vminfo::hasAccess($user)->exists();
|
2018-05-09 08:05:17 -05:00
|
|
|
|
2024-04-25 15:32:33 -05:00
|
|
|
//Maps
|
|
|
|
$vars['links'] = Link::exists();
|
|
|
|
$vars['device_dependencies'] = \DB::table('device_relationships')->exists();
|
|
|
|
$vars['device_group_dependencies'] = $vars['device_groups']->isNotEmpty() && \DB::table('device_group_device')->exists();
|
|
|
|
$vars['custommaps'] = CustomMap::select(['custom_map_id', 'name', 'menu_group'])->hasAccess($user)->orderBy('name')->get()->groupBy('menu_group')->sortKeys();
|
|
|
|
|
2018-05-09 08:05:17 -05:00
|
|
|
// Service menu
|
|
|
|
if (Config::get('show_services')) {
|
2019-05-10 11:02:39 -05:00
|
|
|
$vars['service_counts'] = ObjectCache::serviceCounts(['warning', 'critical']);
|
2018-05-09 08:05:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Port menu
|
2019-05-10 11:02:39 -05:00
|
|
|
$vars['port_counts'] = ObjectCache::portCounts(['errored', 'ignored', 'deleted', 'shutdown', 'down']);
|
|
|
|
$vars['port_counts']['pseudowire'] = Config::get('enable_pseudowires') ? ObjectCache::portCounts(['pseudowire'])['pseudowire'] : 0;
|
|
|
|
|
|
|
|
$vars['port_counts']['alerted'] = 0; // not actually supported on old...
|
2020-11-21 03:59:54 +01:00
|
|
|
|
|
|
|
$custom_descr = [];
|
|
|
|
foreach ((array) Config::get('custom_descr', []) as $descr) {
|
|
|
|
$custom_descr_name = is_array($descr) ? $descr[0] : $descr;
|
|
|
|
if (empty($custom_descr_name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$custom_descr[] = ['name' => $custom_descr_name,
|
|
|
|
'icon' => is_array($descr) ? $descr[1] : 'fa-connectdevelop',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$vars['custom_port_descr'] = collect($custom_descr)->filter();
|
2019-05-10 11:02:39 -05:00
|
|
|
$vars['port_groups_exist'] = Config::get('int_customers') ||
|
|
|
|
Config::get('int_transit') ||
|
|
|
|
Config::get('int_peering') ||
|
|
|
|
Config::get('int_core') ||
|
|
|
|
Config::get('int_l2tp') ||
|
|
|
|
$vars['custom_port_descr']->isNotEmpty();
|
2018-05-09 08:05:17 -05:00
|
|
|
|
2022-08-07 14:49:57 -05:00
|
|
|
$vars['port_groups'] = PortGroup::hasAccess($user)->orderBy('name')->get(['port_groups.id', 'name', 'desc']);
|
|
|
|
|
2023-09-01 03:25:24 +02:00
|
|
|
$vars['port_nac'] = PortsNac::hasAccess($user)->exists();
|
|
|
|
|
2018-05-09 08:05:17 -05:00
|
|
|
// Sensor menu
|
2019-05-10 11:02:39 -05:00
|
|
|
$vars['sensor_menu'] = ObjectCache::sensors();
|
2018-05-09 08:05:17 -05:00
|
|
|
|
|
|
|
// Wireless menu
|
|
|
|
$wireless_menu_order = array_keys(\LibreNMS\Device\WirelessSensor::getTypes());
|
2019-05-13 14:26:52 -05:00
|
|
|
$vars['wireless_menu'] = WirelessSensor::hasAccess($user)
|
2018-05-09 08:05:17 -05:00
|
|
|
->groupBy('sensor_class')
|
2019-05-13 14:26:52 -05:00
|
|
|
->get(['sensor_class'])
|
2018-05-09 08:05:17 -05:00
|
|
|
->sortBy(function ($wireless_sensor) use ($wireless_menu_order) {
|
|
|
|
$pos = array_search($wireless_sensor->sensor_class, $wireless_menu_order);
|
2020-09-21 14:54:51 +02:00
|
|
|
|
2018-05-09 08:05:17 -05:00
|
|
|
return $pos === false ? 100 : $pos; // unknown at bottom
|
|
|
|
});
|
|
|
|
|
|
|
|
// Application menu
|
2019-05-10 11:02:39 -05:00
|
|
|
$vars['app_menu'] = ObjectCache::applications();
|
2018-05-09 08:05:17 -05:00
|
|
|
|
|
|
|
// Routing menu
|
|
|
|
// FIXME queries use relationships to user
|
|
|
|
$routing_menu = [];
|
|
|
|
if ($user->hasGlobalRead()) {
|
2019-05-10 11:02:39 -05:00
|
|
|
$routing_count = ObjectCache::routing();
|
|
|
|
|
|
|
|
if ($routing_count['vrf']) {
|
2018-05-09 08:05:17 -05:00
|
|
|
$routing_menu[] = [
|
|
|
|
[
|
|
|
|
'url' => 'vrf',
|
|
|
|
'icon' => 'arrows',
|
|
|
|
'text' => 'VRFs',
|
2019-06-06 23:12:13 +02:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($routing_count['mpls']) {
|
|
|
|
$routing_menu[] = [
|
|
|
|
[
|
|
|
|
'url' => 'mpls',
|
|
|
|
'icon' => 'tag',
|
|
|
|
'text' => 'MPLS',
|
2018-05-09 08:05:17 -05:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:02:39 -05:00
|
|
|
if ($routing_count['ospf']) {
|
2018-05-09 08:05:17 -05:00
|
|
|
$routing_menu[] = [
|
|
|
|
[
|
|
|
|
'url' => 'ospf',
|
|
|
|
'icon' => 'circle-o-notch fa-rotate-180',
|
|
|
|
'text' => 'OSPF Devices',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-06-11 03:42:34 +03:00
|
|
|
if ($routing_count['isis']) {
|
|
|
|
$routing_menu[] = [
|
|
|
|
[
|
|
|
|
'url' => 'isis',
|
|
|
|
'icon' => 'arrows-alt',
|
|
|
|
'text' => 'ISIS Adjacencies',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:02:39 -05:00
|
|
|
if ($routing_count['cisco-otv']) {
|
2018-05-09 08:05:17 -05:00
|
|
|
$routing_menu[] = [
|
|
|
|
[
|
|
|
|
'url' => 'cisco-otv',
|
|
|
|
'icon' => 'exchange',
|
|
|
|
'text' => 'Cisco OTV',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:02:39 -05:00
|
|
|
if ($routing_count['bgp']) {
|
2018-05-09 08:05:17 -05:00
|
|
|
$vars['show_peeringdb'] = Config::get('peeringdb.enabled', false);
|
|
|
|
$vars['bgp_alerts'] = BgpPeer::hasAccess($user)->inAlarm()->count();
|
|
|
|
$routing_menu[] = [
|
|
|
|
[
|
|
|
|
'url' => 'bgp/type=all/graph=NULL',
|
|
|
|
'icon' => 'circle-o',
|
|
|
|
'text' => 'BGP All Sessions',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'url' => 'bgp/type=external/graph=NULL',
|
|
|
|
'icon' => 'external-link',
|
|
|
|
'text' => 'BGP External',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'url' => 'bgp/type=internal/graph=NULL',
|
|
|
|
'icon' => 'external-link fa-rotate-180',
|
|
|
|
'text' => 'BGP Internal',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$vars['show_peeringdb'] = false;
|
|
|
|
$vars['bgp_alerts'] = [];
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:02:39 -05:00
|
|
|
if ($routing_count['cef']) {
|
2018-05-09 08:05:17 -05:00
|
|
|
$routing_menu[] = [
|
|
|
|
[
|
|
|
|
'url' => 'cef',
|
|
|
|
'icon' => 'exchange',
|
|
|
|
'text' => 'Cisco CEF',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$vars['routing_menu'] = $routing_menu;
|
|
|
|
|
|
|
|
// Alert menu
|
|
|
|
$alert_status = AlertRule::select('severity')
|
|
|
|
->isActive()
|
|
|
|
->hasAccess($user)
|
2019-03-14 03:01:30 +01:00
|
|
|
->leftJoin('devices', 'alerts.device_id', '=', 'devices.device_id')
|
|
|
|
->where('devices.disabled', '=', '0')
|
|
|
|
->where('devices.ignore', '=', '0')
|
2018-05-09 08:05:17 -05:00
|
|
|
->groupBy('severity')
|
|
|
|
->pluck('severity');
|
|
|
|
|
|
|
|
if ($alert_status->contains('critical')) {
|
|
|
|
$vars['alert_menu_class'] = 'danger';
|
|
|
|
} elseif ($alert_status->contains('warning')) {
|
|
|
|
$vars['alert_menu_class'] = 'warning';
|
|
|
|
} else {
|
|
|
|
$vars['alert_menu_class'] = 'success';
|
|
|
|
}
|
|
|
|
|
|
|
|
// User menu
|
|
|
|
$vars['notification_count'] = Notification::isSticky()
|
|
|
|
->orWhere(function ($query) use ($user) {
|
|
|
|
$query->isUnread($user);
|
|
|
|
})->count();
|
|
|
|
|
2020-07-03 00:37:37 -05:00
|
|
|
// Poller Settings
|
|
|
|
$vars['poller_clusters'] = \App\Models\PollerCluster::exists();
|
|
|
|
|
2018-05-09 08:05:17 -05:00
|
|
|
// Search bar
|
2019-06-23 00:29:12 -05:00
|
|
|
$vars['typeahead_limit'] = Config::get('webui.global_search_result_limit');
|
2023-05-15 03:34:37 +02:00
|
|
|
$vars['global_search_ctrlf_focus'] = UserPref::getPref(Auth::user(), 'global_search_ctrlf_focus');
|
2018-05-09 08:05:17 -05:00
|
|
|
|
2021-10-19 13:53:28 +02:00
|
|
|
// Plugins
|
|
|
|
$vars['has_v1_plugins'] = Plugins::count() != 0;
|
|
|
|
$vars['v1_plugin_menu'] = Plugins::call('menu');
|
|
|
|
$vars['has_v2_plugins'] = PluginManager::hasHooks(MenuEntryHook::class);
|
|
|
|
$vars['menu_hooks'] = PluginManager::call(MenuEntryHook::class);
|
|
|
|
|
2021-10-06 07:29:47 -05:00
|
|
|
$vars['browser_push'] = $user->hasBrowserPushTransport();
|
|
|
|
|
2018-05-09 08:05:17 -05:00
|
|
|
$view->with($vars);
|
|
|
|
}
|
|
|
|
}
|