From 47e4641e04702ad0408374787ab2420405da54ca Mon Sep 17 00:00:00 2001 From: Jellyfrog Date: Sat, 24 Aug 2019 23:52:10 +0200 Subject: [PATCH] Convert About page to Laravel (#10551) * Convert About page to laravel * clean up callback stuff * More translatable strings --- LibreNMS/Util/Version.php | 14 + app/Http/Controllers/AboutController.php | 105 ++++++++ app/Models/Callback.php | 46 ++++ app/Models/DiskIo.php | 11 + app/Models/EntPhysical.php | 11 + app/Models/HrDevice.php | 11 + app/Models/Ipv6Network.php | 41 +++ includes/html/forms/callback-clear.inc.php | 2 +- .../html/forms/callback-statistics.inc.php | 12 +- includes/html/pages/about.inc.php | 248 ------------------ resources/views/about/index.blade.php | 227 ++++++++++++++++ routes/web.php | 1 + 12 files changed, 469 insertions(+), 260 deletions(-) create mode 100644 app/Http/Controllers/AboutController.php create mode 100644 app/Models/Callback.php create mode 100644 app/Models/DiskIo.php create mode 100644 app/Models/EntPhysical.php create mode 100644 app/Models/HrDevice.php create mode 100644 app/Models/Ipv6Network.php delete mode 100644 includes/html/pages/about.inc.php create mode 100644 resources/views/about/index.blade.php diff --git a/LibreNMS/Util/Version.php b/LibreNMS/Util/Version.php index 54463d34bb..9588192c29 100644 --- a/LibreNMS/Util/Version.php +++ b/LibreNMS/Util/Version.php @@ -74,4 +74,18 @@ class Version { return rtrim(shell_exec('git describe --tags 2>/dev/null')); } + + public function gitChangelog() + { + if ($this->is_git_install) { + return shell_exec('git log -10'); + } + } + + public function gitDate() + { + if ($this->is_git_install) { + return shell_exec("git show --pretty='%ct' --no-patch HEAD"); + } + } } diff --git a/app/Http/Controllers/AboutController.php b/app/Http/Controllers/AboutController.php new file mode 100644 index 0000000000..9adbaaa873 --- /dev/null +++ b/app/Http/Controllers/AboutController.php @@ -0,0 +1,105 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Http\Controllers; + +use App\Models\Application; +use App\Models\Callback; +use App\Models\Device; +use App\Models\DiskIo; +use App\Models\EntPhysical; +use App\Models\Eventlog; +use App\Models\HrDevice; +use App\Models\Ipv4Address; +use App\Models\Ipv4Network; +use App\Models\Ipv6Address; +use App\Models\Ipv6Network; +use App\Models\Mempool; +use App\Models\Port; +use App\Models\Processor; +use App\Models\Pseudowire; +use App\Models\Sensor; +use App\Models\Service; +use App\Models\Storage; +use App\Models\Syslog; +use App\Models\Toner; +use App\Models\Vlan; +use App\Models\Vrf; +use App\Models\WirelessSensor; +use DB; +use Illuminate\Http\Request; +use LibreNMS\Config; +use LibreNMS\Util\Version; + +class AboutController extends Controller +{ + public function index(Request $request) + { + $callback_status = Callback::get('enabled') === '1'; + $version = Version::get(); + + return view('about.index', [ + 'callback_status' => $callback_status, + 'callback_uuid' => $callback_status ? Callback::get('uuid') : null, + + 'db_schema' => vsprintf('%s (%s)', $version->database()), + 'git_log' => $version->gitChangelog(), + 'git_date' => $version->gitDate(), + 'project_name' => Config::get('project_name'), + + 'version_local' => $version->local(), + 'version_mysql' => current(DB::selectOne('select version()')), + 'version_php' => phpversion(), + 'version_webserver' => $request->server('SERVER_SOFTWARE'), + 'version_rrdtool' => str_replace('1.7.01.7.0', '1.7.0', implode(' ', array_slice(explode(' ', shell_exec( + Config::get('rrdtool', 'rrdtool') . ' --version | head -n1' + )), 1, 1))), + 'version_netsnmp' => str_replace('version: ', '', rtrim(shell_exec(Config::get('snmpget', 'snmpget') . ' -V 2>&1'))), + + 'stat_apps' => Application::count(), + 'stat_devices' => Device::count(), + 'stat_diskio' => DiskIo::count(), + 'stat_entphys' => EntPhysical::count(), + 'stat_events' => Eventlog::count(), + 'stat_hrdev' => HrDevice::count(), + 'stat_ipv4_addy' => Ipv4Address::count(), + 'stat_ipv4_nets' => Ipv4Network::count(), + 'stat_ipv6_addy' => Ipv6Address::count(), + 'stat_ipv6_nets' => Ipv6Network::count(), + 'stat_memory' => Mempool::count(), + 'stat_ports' => Port::count(), + 'stat_processors' => Processor::count(), + 'stat_pw' => Pseudowire::count(), + 'stat_sensors' => Sensor::count(), + 'stat_services' => Service::count(), + 'stat_storage' => Storage::count(), + 'stat_syslog' => Syslog::count(), + 'stat_toner' => Toner::count(), + 'stat_vlans' => Vlan::count(), + 'stat_vrf' => Vrf::count(), + 'stat_wireless' => WirelessSensor::count(), + ]); + } +} diff --git a/app/Models/Callback.php b/app/Models/Callback.php new file mode 100644 index 0000000000..158d1544bf --- /dev/null +++ b/app/Models/Callback.php @@ -0,0 +1,46 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Models; + +use Illuminate\Database\Eloquent\Model; + +class Callback extends Model +{ + public $timestamps = false; + protected $table = 'callback'; + protected $primaryKey = 'callback_id'; + protected $fillable = ['name', 'value']; + + public static function get($name) + { + return static::query()->where('name', $name)->value('value'); + } + + public static function set($name, $value) + { + return static::query()->updateOrCreate(['name' => $name], ['name' => $name, 'value' => $value]); + } +} diff --git a/app/Models/DiskIo.php b/app/Models/DiskIo.php new file mode 100644 index 0000000000..7d7427f811 --- /dev/null +++ b/app/Models/DiskIo.php @@ -0,0 +1,11 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Models; + +use Illuminate\Database\Eloquent\Model; + +class Ipv6Network extends Model +{ + public $timestamps = false; + protected $primaryKey = 'ipv6_network_id'; + + // ---- Define Relationships ---- + + public function ipv6() + { + return $this->hasMany('App\Models\Ipv6Address', 'ipv6_network_id'); + } +} diff --git a/includes/html/forms/callback-clear.inc.php b/includes/html/forms/callback-clear.inc.php index 6ef29882f1..7d9eea35a5 100644 --- a/includes/html/forms/callback-clear.inc.php +++ b/includes/html/forms/callback-clear.inc.php @@ -18,4 +18,4 @@ if (!Auth::user()->hasGlobalAdmin()) { die('ERROR: You need to be admin'); } -dbUpdate(array('value' => '2'), 'callback', '`name` = "enabled"', array()); +\App\Models\Callback::set('enabled', '2'); diff --git a/includes/html/forms/callback-statistics.inc.php b/includes/html/forms/callback-statistics.inc.php index 38afd412ba..0265bb2f95 100644 --- a/includes/html/forms/callback-statistics.inc.php +++ b/includes/html/forms/callback-statistics.inc.php @@ -18,14 +18,4 @@ if (!Auth::user()->hasGlobalAdmin()) { die('ERROR: You need to be admin'); } -if ($_POST['state'] == 'true') { - $state = 1; -} elseif ($_POST['state'] == 'false') { - $state = 0; -} else { - $state = 0; -} - -if (dbUpdate(array('value' => $state), 'callback', '`name` = "enabled"', array()) == 0) { - dbInsert(array('value' => $state,'name' => 'enabled'), 'callback'); -} +\App\Models\Callback::set('enabled', (int)($_POST['state'] == 'true')); diff --git a/includes/html/pages/about.inc.php b/includes/html/pages/about.inc.php deleted file mode 100644 index 4843a4248d..0000000000 --- a/includes/html/pages/about.inc.php +++ /dev/null @@ -1,248 +0,0 @@ - - -
-
-

License

-
-Copyright (C) 2013- Contributors
-Copyright (C) 2006-2012 Adam Armstrong
-
-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
-along with this program.  If not, see http://www.gnu.org/licenses/.
- -   - - -

Statistics

- - Opt in to send anonymous usage statistics to LibreNMS?
'; -} else { - $callback = "PHP Curl module isn't installed, please install this, restart your web service and refresh this page."; -} - -echo " -
- - "; - -if (Auth::user()->hasGlobalAdmin()) { - echo " - - "; -} - -if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'") != '' && $callback_status != 2) { - echo " - - - - "; -} - -echo " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$callback
- Online stats: stats.librenms.org
Devices$stat_devices Ports$stat_ports
IPv4 Addresses$stat_ipv4_addy IPv4 Networks$stat_ipv4_nets
IPv6 Addresses$stat_ipv6_addy IPv6 Networks$stat_ipv6_nets
Services$stat_services Applications$stat_apps
Processors$stat_processors Memory$stat_memory
Storage$stat_storage Disk I/O$stat_diskio
HR-MIB$stat_hrdev Entity-MIB$stat_entphys
Syslog Entries$stat_syslog Eventlog Entries$stat_events
Sensors$stat_sensors Wireless Sensors$stat_wireless
Toner$stat_toner
-
-"; -?> -
- -
- -

LibreNMS is an autodiscovering PHP/MySQL-based network monitoring system.

- - - - - - - - -
Version$version - $version_date
DB Schema$schema_version
Web Server$webserv_version
PHP$php_version
MySQL$mysql_version
RRDtool$rrdtool_version
-
-"; - - -?> - -
LibreNMS is a community-based project. Please feel free to join us and contribute code, documentation, and bug reports:
- -

- Web site | - Docs | - GitHub | - Bug tracker | - Community Forum | - Twitter | - Changelog | - Git log -

- -
-
- -

Contributors

- -

See the list of contributors on GitHub.

- -

Acknowledgements

- - Bruno Pramont Collectd code.
- Dennis de Houx Application monitors for PowerDNS, Shoutcast, NTPD (Client, Server).
- Erik Bosrup Overlib Library.
- Jonathan De Graeve SNMP code improvements.
- Mark James Silk Iconset.
- Observium Codebase for fork.
- -
- - - diff --git a/resources/views/about/index.blade.php b/resources/views/about/index.blade.php new file mode 100644 index 0000000000..ee6fdbd676 --- /dev/null +++ b/resources/views/about/index.blade.php @@ -0,0 +1,227 @@ +@extends('layouts.librenmsv1') + +@section('title', __('About')) + +@section('content') + + +
+
+
+ +

@lang('LibreNMS is an autodiscovering PHP/MySQL-based network monitoring system')

+ + + + + + + + + + + + + + + + + + + + + + + + + +
@lang('Version'){{ $version_local }} - {{ $git_date }}
@lang('Database Schema'){{ $db_schema }}
@lang('Web Server'){{ $version_webserver }}
@lang('PHP'){{ $version_php }}
@lang('MySQL'){{ $version_mysql }}
@lang('RRDtool'){{ $version_rrdtool }}
+ +

+

@lang('LibreNMS is a community-based project')

+ @lang('Please feel free to join us and contribute code, documentation, and bug reports:') +
+ @lang('Web site') | + @lang('Docs') | + @lang('GitHub') | + @lang('Bug tracker') | + @lang('Community Forum') | + @lang('Twitter') | + @lang('Changelog') | + @lang('Local git log') +

+ +

@lang('Contributors')

+ +

@lang('See the list of contributors on GitHub.', ['url' => 'https://github.com/librenms/librenms/blob/master/AUTHORS.md'])

+ +

@lang('Acknowledgements')

+ + Bruno Pramont Collectd code.
+ Dennis de Houx Application monitors for PowerDNS, Shoutcast, NTPD (Client, Server).
+ Erik Bosrup Overlib Library.
+ Jonathan De Graeve SNMP code improvements.
+ Mark James Silk Iconset.
+ Observium Codebase for fork.
+ +
+
+ +

@lang('Statistics')

+ + + + @admin + + + + + @isset($callback_uuid) + + + + @endisset + @endadmin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +

+ @lang('Online stats:') stats.librenms.org +
+ +
@lang('Devices'){{ $stat_devices }} @lang('Ports'){{ $stat_ports }}
@lang('IPv4 Addresses'){{ $stat_ipv4_addy }} @lang('IPv4 Networks'){{ $stat_ipv4_nets }}
@lang('IPv6 Addresses'){{ $stat_ipv6_addy }} @lang('IPv6 Networks'){{ $stat_ipv6_nets }}
@lang('Services'){{ $stat_services }} @lang('Applications'){{ $stat_apps }}
@lang('Processors'){{ $stat_processors }} @lang('Memory'){{ $stat_memory }}
@lang('Storage'){{ $stat_storage }} @lang('Disk I/O'){{ $stat_diskio }}
@lang('HR-MIB'){{ $stat_hrdev }} @lang('Entity-MIB'){{ $stat_entphys }}
@lang('Syslog Entries'){{ $stat_syslog }} @lang('Eventlog Entries'){{ $stat_events }}
@lang('Sensors'){{ $stat_sensors }} @lang('Wireless Sensors'){{ $stat_wireless }}
@lang('Toner'){{ $stat_toner }}
+ +

@lang('License')

+
+Copyright (C) 2013-{{ date('Y') }} {{ $project_name }} Contributors
+Copyright (C) 2006-2012 Adam Armstrong
+
+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
+along with this program.  If not, see http://www.gnu.org/licenses/.
+ +
+
+
+@endsection + +@section('scripts') + +@endsection diff --git a/routes/web.php b/routes/web.php index 4d7a7ce387..82cff1bee5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -26,6 +26,7 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () { Route::get('locations', 'LocationController@index'); Route::resource('preferences', 'UserPreferencesController', ['only' => ['index', 'store']]); Route::resource('users', 'UserController'); + Route::get('about', 'AboutController@index'); // old route redirects Route::permanentRedirect('poll-log', 'pollers/tab=log/');