librenms/routes/console.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

212 lines
7.6 KiB
PHP
Raw Normal View History

Add Laravel to LibreNMS (#8318) * Add Laravel to LibreNMS. * Try to set permissions during initial install and first composer update to Laravel. * Fix composer.lock Fix missing db config keys * Start building v1 layout Port ajax_setresolution, inject csrf into jquery ajax calls Layout works, building menu Partially done. * Fix device group list remove stupid count relationships * Print messages for common boot errors. Don't log to laravel.log file. Log to error_log until booted, then librenms.log * Fix up some issues with Config loading Start of custom directives * Custom blade directives: config, notconfig, admin * Preflight checks Only load config files once. * Update the composer.lock for php 5.6 * Menu through routing * Start of alert menu * Better alert scopes * reduce cruft in models * Alerting menu more or less working :D * Fix style * Improved preflight * Fix chicken-eggs! * Remove examples * Better alert_rule status queries Debugbar * fix app.env check * User Menu * Settings bar (dropped refresh) Search JS * Toastr messages * Rename preflight * Use hasAccess(User) on most models. Add port counts * Missed a Preflight -> Checks rename * Fix some formatting * Boot Eloquent outside of Laravel Use Eloquent for Config and Plugins so we don't have to connect with dbFacile inside Laravel. Move locate_binary() into Config class * Config WIP * Try to fix a lot of config loading issues. * Improve menu for non-admins removing unneeded menus url() for all in menu * Only use eloquent if it exists * Include APP_URL in initial .env settings * Implement Legacy User Provider * Helper class for using Eloquent outside of Laravel. Allows access to DB style queries too and checking the connection status. * Fix up tests * Fix device groups query * Checking Travis * copy config.test.php earlier * dbFacile check config before connecting Don't use exception to check if eloquent is connected, it gets grabbed by the exception handler. Ignore missing config.php error. * Fix config load with database is not migrated yet. * Remove Config::load() from early boot. * Use laravel config settings to init db (this prefers .env settings) Fix bgp vars not set in menu add _ide_helper.php to .gitignore * Restrict dependencies to versions that support php 5.6 * Update ConfigTest * Fix a couple of installation issues * Add unique NODE_ID to .env * Correct handling of title image * Fix database config not loading. Thanks @laf * Don't prepend / * add class_exists checks for development service providers * Fix config value casting * Don't use functions that may not exist * Update dbFacile.php * d_echo may not be defined when Config used called. * Add SELinux configuration steps More detailed permissions check. Check all and give complete corrective commands in one step. * Ignore node_modules directory * Re-add accidetal removal
2018-05-09 13:05:17 +00:00
<?php
Update dependencies (#13310) * Bump composer dependencies - Upgrading brick/math (0.9.2 => 0.9.3) - Upgrading composer/ca-bundle (1.2.10 => 1.2.11) - Upgrading composer/composer (2.1.3 => 2.1.8) - Upgrading composer/xdebug-handler (2.0.1 => 2.0.2) - Upgrading dapphp/radius (2.5.5 => 2.5.6) - Upgrading doctrine/annotations (1.13.1 => 1.13.2) - Upgrading doctrine/cache (2.0.3 => 2.1.1) - Upgrading doctrine/dbal (2.13.2 => 2.13.3) - Upgrading facade/flare-client-php (1.8.1 => 1.9.1) - Upgrading facade/ignition (2.11.0 => 2.14.0) - Upgrading fakerphp/faker (v1.15.0 => v1.16.0) - Upgrading filp/whoops (2.13.0 => 2.14.3) - Upgrading friendsofphp/php-cs-fixer (v2.19.0 => v2.19.2) - Upgrading graham-campbell/result-type (v1.0.1 => v1.0.2) - Upgrading laravel/dusk (v6.15.1 => v6.18.1) - Upgrading laravel/framework (v8.49.2 => v8.62.0) - Locking laravel/serializable-closure (v1.0.2) - Upgrading laravel/tinker (v2.6.1 => v2.6.2) - Upgrading league/commonmark (1.6.5 => 1.6.6) - Upgrading league/flysystem (1.1.4 => 1.1.5) - Upgrading league/mime-type-detection (1.7.0 => 1.8.0) - Upgrading maximebf/debugbar (v1.16.5 => v1.17.1) - Upgrading mockery/mockery (1.4.3 => 1.4.4) - Upgrading monolog/monolog (2.3.0 => 2.3.4) - Upgrading nesbot/carbon (2.50.0 => 2.53.1) - Upgrading nikic/php-parser (v4.11.0 => v4.13.0) - Upgrading nunomaduro/collision (v5.5.0 => v5.10.0) - Upgrading phar-io/manifest (2.0.1 => 2.0.3) - Upgrading php-parallel-lint/php-parallel-lint (v1.3.0 => v1.3.1) - Upgrading phpdocumentor/type-resolver (1.4.0 => 1.5.0) - Upgrading phpmailer/phpmailer (v6.5.0 => v6.5.1) - Upgrading phpoption/phpoption (1.7.5 => 1.8.0) - Upgrading phpseclib/phpseclib (3.0.9 => 3.0.10) - Upgrading phpspec/prophecy (1.13.0 => 1.14.0) - Upgrading phpstan/phpstan (0.12.92 => 0.12.99) - Upgrading phpunit/php-code-coverage (9.2.6 => 9.2.7) - Upgrading phpunit/phpunit (9.5.6 => 9.5.10) - Upgrading predis/predis (v1.1.7 => v1.1.8) - Upgrading ramsey/collection (1.1.3 => 1.2.1) - Upgrading ramsey/uuid (4.1.1 => 4.2.3) - Upgrading seld/phar-utils (1.1.1 => 1.1.2) - Upgrading symfony/console (v5.3.2 => v5.3.7) - Upgrading symfony/css-selector (v5.3.0 => v5.3.4) - Upgrading symfony/debug (v4.4.25 => v4.4.31) - Upgrading symfony/error-handler (v5.3.3 => v5.3.7) - Upgrading symfony/event-dispatcher (v5.3.0 => v5.3.7) - Upgrading symfony/filesystem (v5.3.3 => v5.3.4) - Upgrading symfony/finder (v5.3.0 => v5.3.7) - Upgrading symfony/http-foundation (v5.3.3 => v5.3.7) - Upgrading symfony/http-kernel (v5.3.3 => v5.3.9) - Upgrading symfony/mime (v5.3.2 => v5.3.8) - Upgrading symfony/options-resolver (v5.3.0 => v5.3.7) - Upgrading symfony/polyfill-intl-grapheme (v1.23.0 => v1.23.1) - Upgrading symfony/polyfill-mbstring (v1.23.0 => v1.23.1) - Upgrading symfony/polyfill-php80 (v1.23.0 => v1.23.1) - Locking symfony/polyfill-php81 (v1.23.0) - Upgrading symfony/process (v5.3.2 => v5.3.7) - Upgrading symfony/routing (v5.3.0 => v5.3.7) - Upgrading symfony/stopwatch (v5.3.0 => v5.3.4) - Upgrading symfony/string (v5.3.3 => v5.3.7) - Upgrading symfony/translation (v5.3.3 => v5.3.9) - Upgrading symfony/var-dumper (v5.3.3 => v5.3.8) - Upgrading symfony/yaml (v4.4.26 => v4.4.29) - Upgrading tecnickcom/tcpdf (6.4.1 => 6.4.2) - Upgrading theseer/tokenizer (1.2.0 => 1.2.1) * Update npm dependecies * Update phpstan ignores after laravel upgrades * Merge laravel/laravel repo changes
2021-10-02 23:04:59 +00:00
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Process\Process;
Add Laravel to LibreNMS (#8318) * Add Laravel to LibreNMS. * Try to set permissions during initial install and first composer update to Laravel. * Fix composer.lock Fix missing db config keys * Start building v1 layout Port ajax_setresolution, inject csrf into jquery ajax calls Layout works, building menu Partially done. * Fix device group list remove stupid count relationships * Print messages for common boot errors. Don't log to laravel.log file. Log to error_log until booted, then librenms.log * Fix up some issues with Config loading Start of custom directives * Custom blade directives: config, notconfig, admin * Preflight checks Only load config files once. * Update the composer.lock for php 5.6 * Menu through routing * Start of alert menu * Better alert scopes * reduce cruft in models * Alerting menu more or less working :D * Fix style * Improved preflight * Fix chicken-eggs! * Remove examples * Better alert_rule status queries Debugbar * fix app.env check * User Menu * Settings bar (dropped refresh) Search JS * Toastr messages * Rename preflight * Use hasAccess(User) on most models. Add port counts * Missed a Preflight -> Checks rename * Fix some formatting * Boot Eloquent outside of Laravel Use Eloquent for Config and Plugins so we don't have to connect with dbFacile inside Laravel. Move locate_binary() into Config class * Config WIP * Try to fix a lot of config loading issues. * Improve menu for non-admins removing unneeded menus url() for all in menu * Only use eloquent if it exists * Include APP_URL in initial .env settings * Implement Legacy User Provider * Helper class for using Eloquent outside of Laravel. Allows access to DB style queries too and checking the connection status. * Fix up tests * Fix device groups query * Checking Travis * copy config.test.php earlier * dbFacile check config before connecting Don't use exception to check if eloquent is connected, it gets grabbed by the exception handler. Ignore missing config.php error. * Fix config load with database is not migrated yet. * Remove Config::load() from early boot. * Use laravel config settings to init db (this prefers .env settings) Fix bgp vars not set in menu add _ide_helper.php to .gitignore * Restrict dependencies to versions that support php 5.6 * Update ConfigTest * Fix a couple of installation issues * Add unique NODE_ID to .env * Correct handling of title image * Fix database config not loading. Thanks @laf * Don't prepend / * add class_exists checks for development service providers * Fix config value casting * Don't use functions that may not exist * Update dbFacile.php * d_echo may not be defined when Config used called. * Add SELinux configuration steps More detailed permissions check. Check all and give complete corrective commands in one step. * Ignore node_modules directory * Re-add accidetal removal
2018-05-09 13:05:17 +00:00
/*
|--------------------------------------------------------------------------
| Console Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of your Closure based console
| commands. Each Closure is bound to a command instance allowing a
| simple approach to interacting with each command's IO methods.
|
*/
Artisan::command('device:rename
{old hostname : ' . __('The existing hostname, IP, or device id') . '}
{new hostname : ' . __('The new hostname or IP') . '}
', function () {
/** @var \Illuminate\Console\Command $this */
(new Process([
base_path('renamehost.php'),
$this->argument('old hostname'),
$this->argument('new hostname'),
]))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
})->purpose(__('Rename a device, this can be used to change the hostname or IP of a device'));
Artisan::command('device:remove
{device spec : ' . __('Hostname, IP, or device id to remove') . '}
', function () {
/** @var \Illuminate\Console\Command $this */
(new Process([
base_path('delhost.php'),
$this->argument('device spec'),
]))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
})->purpose('Remove a device');
Artisan::command('update', function () {
(new Process([base_path('daily.sh')]))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
})->purpose(__('Update LibreNMS and run maintenance routines'));
Artisan::command('poller:ping
{groups?* : ' . __('Optional List of distributed poller groups to poll') . '}
', function () {
// PingCheck::dispatch(new PingCheck($this->argument('groups')));
$command = [base_path('ping.php')];
if ($this->argument('groups')) {
$command[] = '-g';
$command[] = implode(',', $this->argument('groups'));
}
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
$command[] = '-d';
if ($verbosity >= 256) {
$command[] = '-v';
}
}
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
})->purpose(__('Check if devices are up or down via icmp'));
Artisan::command('poller:discovery
{device spec : ' . __('Device spec to discover: device_id, hostname, wildcard, odd, even, all, new') . '}
{--o|os= : ' . __('Only devices with the specified operating system') . '}
{--t|type= : ' . __('Only devices with the specified type') . '}
{--m|modules= : ' . __('Specify single module to be run. Comma separate modules, submodules may be added with /') . '}
', function () {
$command = [base_path('discovery.php'), '-h', $this->argument('device spec')];
if ($this->option('os')) {
$command[] = '-o';
$command[] = $this->option('os');
}
if ($this->option('type')) {
$command[] = '-t';
$command[] = $this->option('type');
}
if ($this->option('modules')) {
$command[] = '-m';
$command[] = $this->option('modules');
}
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
$command[] = '-d';
if ($verbosity >= 256) {
$command[] = '-v';
}
}
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
})->purpose(__('Discover information about existing devices, defines what will be polled'));
Artisan::command('poller:alerts', function () {
$command = [base_path('alerts.php')];
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
$command[] = '-d';
if ($verbosity >= 256) {
$command[] = '-v';
}
}
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
})->purpose(__('Check for any pending alerts and deliver them via defined transports'));
Artisan::command('poller:billing
{bill id? : ' . __('The bill id to poll') . '}
', function () {
/** @var \Illuminate\Console\Command $this */
$command = [base_path('poll-billing.php')];
if ($this->argument('bill id')) {
$command[] = '-b';
$command[] = $this->argument('bill id');
}
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
$command[] = '-d';
if ($verbosity >= 256) {
$command[] = '-v';
}
}
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
})->purpose(__('Collect billing data'));
Artisan::command('poller:services
{device spec : ' . __('Device spec to poll: device_id, hostname, wildcard, all') . '}
{--x|no-data : ' . __('Do not update datastores (RRD, InfluxDB, etc)') . '}
', function () {
/** @var \Illuminate\Console\Command $this */
$command = [base_path('check-services.php')];
if ($this->option('no-data')) {
array_push($command, '-r', '-f', '-p');
}
if ($this->argument('device spec') !== 'all') {
$command[] = '-h';
$command[] = $this->argument('device spec');
}
if (($verbosity = $this->getOutput()->getVerbosity()) >= 128) {
$command[] = '-d';
if ($verbosity >= 256) {
$command[] = '-v';
}
}
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
})->purpose(__('Update LibreNMS and run maintenance routines'));
Artisan::command('poller:billing-calculate
{--c|clear-history : ' . __('Delete all billing history') . '}
', function () {
/** @var \Illuminate\Console\Command $this */
$command = [base_path('billing-calculate.php')];
if ($this->option('clear-history')) {
$command[] = '-r';
}
(new Process($command))->setTimeout(null)->setIdleTimeout(null)->setTty(true)->run();
})->purpose(__('Run billing calculations'));
Artisan::command('scan
{network?* : ' . __('CIDR notation network(s) to scan, can be ommited if \'nets\' config is set') . '}
{--P|ping-only : ' . __('Add the device as a ping only device if it replies to ping but not SNMP') . '}
{--o|dns-only : ' . __('Only DNS resolved Devices') . '}
{--t|threads=32 : ' . __('How many IPs to scan at a time, more will increase the scan speed, but could overload your system') . '}
{--l|legend : ' . __('Print the legend') . '}
', function () {
/** @var \Illuminate\Console\Command $this */
$command = [base_path('snmp-scan.py')];
if (empty($this->argument('network')) && ! \LibreNMS\Config::has('nets')) {
$this->error(__('Network is required if \'nets\' is not set in the config'));
return 1;
}
if ($this->option('dns-only')) {
$command[] = '-o';
}
if ($this->option('ping-only')) {
$command[] = '-P';
}
$command[] = '-t';
$command[] = $this->option('threads');
if ($this->option('legend')) {
$command[] = '-l';
}
$verbosity = $this->getOutput()->getVerbosity();
if ($verbosity >= 64) {
$command[] = '-v';
if ($verbosity >= 128) {
$command[] = '-v';
if ($verbosity >= 256) {
$command[] = '-v';
}
}
}
$command = array_merge($command, $this->argument('network'));
$scan_process = (new Process($command))
->setTimeout(null)
->setIdleTimeout(null)
->setTty(Process::isTtySupported() && ! $this->option('quiet'));
$scan_process->run();
if (! Process::isTtySupported() && ! $this->option('quiet')) {
// just dump the output after we are done if we couldn't use tty
$this->line($scan_process->getOutput());
}
return $scan_process->getExitCode();
})->purpose(__('Scan the network for hosts and try to add them to LibreNMS'));