diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cae51a7e27..30077972c1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -76,8 +76,8 @@ jobs: - name: Run PHPStan (Deprecated functions) - run: ./vendor/bin/phpstan analyze --no-interaction --no-progress --error-format=github --memory-limit=4G --configuration=phpstan-deprecated.neon + run: ./vendor/bin/phpstan analyze --no-interaction --no-progress --memory-limit=4G --configuration=phpstan-deprecated.neon - name: Run PHPStan - run: ./vendor/bin/phpstan analyze --no-interaction --no-progress --error-format=github --memory-limit=4G + run: ./vendor/bin/phpstan analyze --no-interaction --no-progress --memory-limit=4G diff --git a/LibreNMS/Alert/Transport/Elasticsearch.php b/LibreNMS/Alert/Transport/Elasticsearch.php index 3e3a9a5ab6..0aab6aaafa 100644 --- a/LibreNMS/Alert/Transport/Elasticsearch.php +++ b/LibreNMS/Alert/Transport/Elasticsearch.php @@ -39,7 +39,7 @@ class Elasticsearch extends Transport { $es_host = '127.0.0.1'; $es_port = 9200; - $index = strftime('librenms-%Y.%m.%d'); + $index = date("\l\i\b\\r\\e\\n\m\s\-Y.m.d"); $type = 'alert'; $severity = $obj['severity']; @@ -61,7 +61,7 @@ class Elasticsearch extends Transport } if (! empty($opts['es_index'])) { - $index = strftime($opts['es_index']); + $index = date($opts['es_index']); } $host = $es_host . ':' . $es_port . '/' . $index . '/' . $type; @@ -222,7 +222,7 @@ class Elasticsearch extends Transport [ 'title' => 'Index Pattern', 'name' => 'es-pattern', - 'descr' => 'Elasticsearch Index Pattern', + 'descr' => 'Elasticsearch Index Pattern | Default: \l\i\b\\r\\e\\n\m\s\-Y.m.d | Format: https://www.php.net/manual/en/function.date.php', 'type' => 'text', ], [ diff --git a/LibreNMS/Alert/Transport/Linenotify.php b/LibreNMS/Alert/Transport/Linenotify.php index 2014104ae3..46b3348e68 100644 --- a/LibreNMS/Alert/Transport/Linenotify.php +++ b/LibreNMS/Alert/Transport/Linenotify.php @@ -16,7 +16,7 @@ class Linenotify extends Transport { $opts['line-notify-access-token'] = $this->config['line-notify-access-token']; - return $this->contactLineNotify($obj, $opts); + return $this->contactLinenotify($obj, $opts); } private function contactLinenotify($obj, $opts) diff --git a/LibreNMS/Alert/Transport/Twilio.php b/LibreNMS/Alert/Transport/Twilio.php index 23aa7b2d6c..7f88783305 100644 --- a/LibreNMS/Alert/Transport/Twilio.php +++ b/LibreNMS/Alert/Transport/Twilio.php @@ -27,7 +27,7 @@ class Twilio extends Transport $twilio_opts['sender'] = $this->config['twilio-sender']; $twilio_opts['to'] = $this->config['twilio-to']; - return $this->contacttwilio($obj, $twilio_opts); + return $this->contactTwilio($obj, $twilio_opts); } public static function contactTwilio($obj, $opts) diff --git a/LibreNMS/Authentication/SSOAuthorizer.php b/LibreNMS/Authentication/SSOAuthorizer.php index e5384c165e..22b92cb415 100644 --- a/LibreNMS/Authentication/SSOAuthorizer.php +++ b/LibreNMS/Authentication/SSOAuthorizer.php @@ -124,10 +124,10 @@ class SSOAuthorizer extends MysqlAuthorizer foreach ($proxies as $value) { $proxy = IP::parse($value); if ($proxies == '8.8.8.0/25') { - dd($source->innetwork((string) $proxy)); + dd($source->inNetwork((string) $proxy)); } - if ($source->innetwork((string) $proxy)) { + if ($source->inNetwork((string) $proxy)) { // Proxy matches trusted subnet return true; } diff --git a/LibreNMS/Data/Store/Rrd.php b/LibreNMS/Data/Store/Rrd.php index 92dae88252..5ce88c6d64 100644 --- a/LibreNMS/Data/Store/Rrd.php +++ b/LibreNMS/Data/Store/Rrd.php @@ -460,7 +460,7 @@ class Rrd extends BaseDatastore public function getRrdFiles($device) { if ($this->rrdcached) { - $filename = sprintf('/%s', self::safename($device['hostname'])); + $filename = sprintf('/%s', self::safeName($device['hostname'])); $rrd_files = $this->command('list', $filename, ''); // Command output is an array, create new array with each filename as a item in array. $rrd_files_array = explode("\n", trim($rrd_files[0])); diff --git a/LibreNMS/Device/Processor.php b/LibreNMS/Device/Processor.php index 429c3276c7..37189b620f 100644 --- a/LibreNMS/Device/Processor.php +++ b/LibreNMS/Device/Processor.php @@ -28,7 +28,6 @@ namespace LibreNMS\Device; use Illuminate\Support\Str; use LibreNMS\Interfaces\Discovery\DiscoveryItem; use LibreNMS\Interfaces\Discovery\DiscoveryModule; -use LibreNMS\Interfaces\Discovery\ProcessorDiscovery; use LibreNMS\Interfaces\Polling\PollerModule; use LibreNMS\Interfaces\Polling\ProcessorPolling; use LibreNMS\Model; @@ -142,7 +141,7 @@ class Processor extends Model implements DiscoveryModule, PollerModule, Discover $processors = self::processYaml($os); // if no processors found, check OS discovery (which will fall back to HR and UCD if not implemented - if (empty($processors) && $os instanceof ProcessorDiscovery) { + if (empty($processors)) { $processors = $os->discoverProcessors(); } diff --git a/LibreNMS/Modules/Isis.php b/LibreNMS/Modules/Isis.php index 1081a6418c..a5cb70ed5b 100644 --- a/LibreNMS/Modules/Isis.php +++ b/LibreNMS/Modules/Isis.php @@ -144,7 +144,7 @@ class Isis implements Module 'isisISAdjLastUpTime' => $this->parseAdjacencyTime($adjacency_data), 'isisISAdjAreaAddress' => str_replace(' ', '.', trim($adjacency_data['isisISAdjAreaAddress'] ?? '')), 'isisISAdjIPAddrType' => $adjacency_data['isisISAdjIPAddrType'] ?? '', - 'isisISAdjIPAddrAddress' => (string) IP::fromHexstring($adjacency_data['isisISAdjIPAddrAddress'] ?? null, true), + 'isisISAdjIPAddrAddress' => (string) IP::fromHexString($adjacency_data['isisISAdjIPAddrAddress'] ?? null, true), ]); } diff --git a/LibreNMS/Modules/Mempools.php b/LibreNMS/Modules/Mempools.php index b5e394ec69..697427174f 100644 --- a/LibreNMS/Modules/Mempools.php +++ b/LibreNMS/Modules/Mempools.php @@ -30,7 +30,6 @@ use App\Models\Mempool; use App\Observers\MempoolObserver; use Illuminate\Support\Collection; use LibreNMS\DB\SyncsModels; -use LibreNMS\Interfaces\Discovery\MempoolsDiscovery; use LibreNMS\Interfaces\Module; use LibreNMS\Interfaces\Polling\MempoolsPolling; use LibreNMS\OS; @@ -52,25 +51,23 @@ class Mempools implements Module public function discover(OS $os): void { - if ($os instanceof MempoolsDiscovery) { - $mempools = $os->discoverMempools()->filter(function (Mempool $mempool) { - if ($mempool->isValid()) { - return true; - } - Log::debug("Rejecting Mempool $mempool->mempool_index $mempool->mempool_descr: Invalid total value"); + $mempools = $os->discoverMempools()->filter(function (Mempool $mempool) { + if ($mempool->isValid()) { + return true; + } + Log::debug("Rejecting Mempool $mempool->mempool_index $mempool->mempool_descr: Invalid total value"); - return false; - }); - $this->calculateAvailable($mempools); + return false; + }); + $this->calculateAvailable($mempools); - MempoolObserver::observe('\App\Models\Mempool'); - $this->syncModels($os->getDevice(), 'mempools', $mempools); + MempoolObserver::observe('\App\Models\Mempool'); + $this->syncModels($os->getDevice(), 'mempools', $mempools); - echo PHP_EOL; - $mempools->each(function ($mempool) { - $this->printMempool($mempool); - }); - } + echo PHP_EOL; + $mempools->each(function ($mempool) { + $this->printMempool($mempool); + }); } public function poll(OS $os): void diff --git a/LibreNMS/Modules/Stp.php b/LibreNMS/Modules/Stp.php index e31f0cadb3..3e373db567 100644 --- a/LibreNMS/Modules/Stp.php +++ b/LibreNMS/Modules/Stp.php @@ -29,11 +29,7 @@ use App\Models\Device; use App\Models\PortStp; use App\Observers\ModuleModelObserver; use LibreNMS\DB\SyncsModels; -use LibreNMS\Interfaces\Discovery\StpInstanceDiscovery; -use LibreNMS\Interfaces\Discovery\StpPortDiscovery; use LibreNMS\Interfaces\Module; -use LibreNMS\Interfaces\Polling\StpInstancePolling; -use LibreNMS\Interfaces\Polling\StpPortPolling; use LibreNMS\OS; class Stp implements Module @@ -52,40 +48,33 @@ class Stp implements Module { $device = $os->getDevice(); - if ($os instanceof StpInstanceDiscovery) { - echo 'Instances: '; - $instances = $os->discoverStpInstances(); - ModuleModelObserver::observe(\App\Models\Stp::class); - $this->syncModels($device, 'stpInstances', $instances); + echo 'Instances: '; + $instances = $os->discoverStpInstances(); + ModuleModelObserver::observe(\App\Models\Stp::class); + $this->syncModels($device, 'stpInstances', $instances); - if ($os instanceof StpPortDiscovery) { - echo "\nPorts: "; - $ports = $os->discoverStpPorts($instances); - ModuleModelObserver::observe(PortStp::class); - $this->syncModels($device, 'stpPorts', $ports); - } - echo PHP_EOL; - } + echo "\nPorts: "; + $ports = $os->discoverStpPorts($instances); + ModuleModelObserver::observe(PortStp::class); + $this->syncModels($device, 'stpPorts', $ports); + + echo PHP_EOL; } public function poll(OS $os): void { $device = $os->getDevice(); - if ($os instanceof StpInstancePolling) { - echo 'Instances: '; - $instances = $device->stpInstances; - $instances = $os->pollStpInstances($instances); - ModuleModelObserver::observe(\App\Models\Stp::class); - $this->syncModels($device, 'stpInstances', $instances); - } + echo 'Instances: '; + $instances = $device->stpInstances; + $instances = $os->pollStpInstances($instances); + ModuleModelObserver::observe(\App\Models\Stp::class); + $this->syncModels($device, 'stpInstances', $instances); - if ($os instanceof StpPortPolling) { - echo "\nPorts: "; - $ports = $device->stpPorts; - ModuleModelObserver::observe(PortStp::class); - $this->syncModels($device, 'stpPorts', $ports); - } + echo "\nPorts: "; + $ports = $device->stpPorts; + ModuleModelObserver::observe(PortStp::class); + $this->syncModels($device, 'stpPorts', $ports); } public function cleanup(Device $device): void diff --git a/LibreNMS/OS/Ciscowlc.php b/LibreNMS/OS/Ciscowlc.php index 5b5279258a..d679a21fa5 100644 --- a/LibreNMS/OS/Ciscowlc.php +++ b/LibreNMS/OS/Ciscowlc.php @@ -92,7 +92,7 @@ class Ciscowlc extends Cisco implements d_echo($ap->toArray()); // if there is a numeric channel, assume the rest of the data is valid, I guess - if (! is_numeric($ap->channel)) { + if (! is_numeric($channel)) { continue; } diff --git a/LibreNMS/OS/Ifotec.php b/LibreNMS/OS/Ifotec.php index fd903a310d..7529854c28 100644 --- a/LibreNMS/OS/Ifotec.php +++ b/LibreNMS/OS/Ifotec.php @@ -37,7 +37,7 @@ class Ifotec extends OS implements OSDiscovery if (Str::startsWith($device->sysObjectID, '.1.3.6.1.4.1.21362.100.')) { $ifoSysProductIndex = snmp_get($this->getDeviceArray(), 'ifoSysProductIndex.0', '-Oqv', 'IFOTEC-SMI'); - if ($ifoSysProductIndex !== null) { + if ($ifoSysProductIndex !== false) { $oids = [ 'ifoSysSerialNumber.' . $ifoSysProductIndex, 'ifoSysFirmware.' . $ifoSysProductIndex, diff --git a/LibreNMS/OS/Iosxe.php b/LibreNMS/OS/Iosxe.php index fdce1e97fc..7725847a27 100644 --- a/LibreNMS/OS/Iosxe.php +++ b/LibreNMS/OS/Iosxe.php @@ -107,7 +107,7 @@ class Iosxe extends Ciscowlc implements 'isisISAdjAreaAddress' => implode(',', array_map([$this, 'formatIsIsId'], $adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjAreaAddress'] ?? [])), 'isisISAdjIPAddrType' => implode(',', $adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjIPAddrType'] ?? []), 'isisISAdjIPAddrAddress' => implode(',', array_map(function ($ip) { - return (string) IP::fromHexstring($ip, true); + return (string) IP::fromHexString($ip, true); }, $adjacency_data['CISCO-IETF-ISIS-MIB::ciiISAdjIPAddrAddress'] ?? [])), ])); } diff --git a/LibreNMS/OS/Shared/Cisco.php b/LibreNMS/OS/Shared/Cisco.php index 20bf37c7fc..d86fa5e46c 100755 --- a/LibreNMS/OS/Shared/Cisco.php +++ b/LibreNMS/OS/Shared/Cisco.php @@ -431,7 +431,7 @@ class Cisco extends OS implements // Lets process each SLA $unixtime = intval(($data[$sla_nr]['rttMonLatestRttOperTime'] / 100 + $time_offset)); - $time = strftime('%Y-%m-%d %H:%M:%S', $unixtime); + $time = date('Y-m-d H:i:s', $unixtime); // Save data $sla->rtt = $data[$sla_nr]['rttMonLatestRttOperCompletionTime']; diff --git a/LibreNMS/OS/Traits/FrogfootResources.php b/LibreNMS/OS/Traits/FrogfootResources.php index 2c8f183689..487f88d96e 100644 --- a/LibreNMS/OS/Traits/FrogfootResources.php +++ b/LibreNMS/OS/Traits/FrogfootResources.php @@ -40,7 +40,7 @@ trait FrogfootResources return [ Processor::discover( $this->getName(), - $this->getDeviceID(), + $this->getDeviceId(), '1.3.6.1.4.1.10002.1.1.1.4.2.1.3.2', 0 ), diff --git a/LibreNMS/Proc.php b/LibreNMS/Proc.php index c5c5a32cd3..867f4abe99 100644 --- a/LibreNMS/Proc.php +++ b/LibreNMS/Proc.php @@ -260,6 +260,7 @@ class Proc */ public function isRunning() { + /* @phpstan-ignore-next-line */ if (! is_resource($this->_process)) { return false; } diff --git a/LibreNMS/Util/Clean.php b/LibreNMS/Util/Clean.php index 0b8dc675de..e421b56390 100644 --- a/LibreNMS/Util/Clean.php +++ b/LibreNMS/Util/Clean.php @@ -75,7 +75,6 @@ class Clean */ public static function html($value, $purifier_config = []) { - /** @var HTMLPurifier $purifier */ static $purifier; // If $purifier_config is non-empty then we don't want diff --git a/app/Http/Controllers/AboutController.php b/app/Http/Controllers/AboutController.php index 9059720aac..3591fd4cbd 100644 --- a/app/Http/Controllers/AboutController.php +++ b/app/Http/Controllers/AboutController.php @@ -74,7 +74,7 @@ class AboutController extends Controller 'version_local' => $version->local(), 'version_database' => $version->databaseServer(), 'version_php' => phpversion(), - 'version_laravel' => App::VERSION(), + 'version_laravel' => App::version(), 'version_python' => $version->python(), 'version_webserver' => $request->server('SERVER_SOFTWARE'), 'version_rrdtool' => Rrd::version(), diff --git a/app/Http/Controllers/Device/Tabs/VmInfoController.php b/app/Http/Controllers/Device/Tabs/VmInfoController.php index 6974cb7386..3bfb8ec833 100644 --- a/app/Http/Controllers/Device/Tabs/VmInfoController.php +++ b/app/Http/Controllers/Device/Tabs/VmInfoController.php @@ -59,7 +59,7 @@ class VmInfoController implements DeviceTab private static function getVms(Device $device) { - return $device->vmInfo() + return $device->vminfo() ->select('vmwVmDisplayName', 'vmwVmState', 'vmwVmGuestOS', 'vmwVmMemSize', 'vmwVmCpus') ->with('parentDevice') ->orderBy('vmwVmDisplayName') diff --git a/app/Models/DeviceGroup.php b/app/Models/DeviceGroup.php index e932dffb51..b9c64dc7aa 100644 --- a/app/Models/DeviceGroup.php +++ b/app/Models/DeviceGroup.php @@ -65,7 +65,7 @@ class DeviceGroup extends BaseModel public function updateDevices() { if ($this->type == 'dynamic') { - $this->devices()->sync(QueryBuilderFluentParser::fromJSON($this->rules)->toQuery() + $this->devices()->sync(QueryBuilderFluentParser::fromJson($this->rules)->toQuery() ->distinct()->pluck('devices.device_id')); } } diff --git a/app/Models/ServiceTemplate.php b/app/Models/ServiceTemplate.php index 236e65dcf3..e3e7327da3 100644 --- a/app/Models/ServiceTemplate.php +++ b/app/Models/ServiceTemplate.php @@ -91,7 +91,7 @@ class ServiceTemplate extends BaseModel public function updateDevices() { if ($this->type == 'dynamic') { - $this->devices()->sync(QueryBuilderFluentParser::fromJSON($this->rules)->toQuery() + $this->devices()->sync(QueryBuilderFluentParser::fromJson($this->rules)->toQuery() ->distinct()->pluck('devices.device_id')); } } diff --git a/app/Models/UserPref.php b/app/Models/UserPref.php index 4903fea217..17f23d94bd 100644 --- a/app/Models/UserPref.php +++ b/app/Models/UserPref.php @@ -99,9 +99,6 @@ class UserPref extends BaseModel { /** @var array */ $keys = $this->getKeyName(); - if (! is_array($keys)) { - return parent::setKeysForSaveQuery($query); - } foreach ($keys as $keyName) { $query->where($keyName, '=', $this->getKeyForSaveQuery($keyName)); diff --git a/app/Providers/ErrorReportingProvider.php b/app/Providers/ErrorReportingProvider.php index ff5ce6418a..10b383c68d 100644 --- a/app/Providers/ErrorReportingProvider.php +++ b/app/Providers/ErrorReportingProvider.php @@ -46,6 +46,7 @@ class ErrorReportingProvider extends \Facade\Ignition\IgnitionServiceProvider public function boot(): void { + /* @phpstan-ignore-next-line */ if (! method_exists(\Facade\FlareClient\Flare::class, 'filterReportsUsing')) { Log::debug("Flare client too old, disabling Ignition to avoid bug.\n"); diff --git a/includes/billing.php b/includes/billing.php index 36c32e98cf..aebfa8c57f 100644 --- a/includes/billing.php +++ b/includes/billing.php @@ -353,8 +353,8 @@ function getHistoricTransferGraphData($bill_id) $allowed_val = null; foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12', [$bill_id]) as $data) { - $datefrom = strftime('%Y-%m-%d', strtotime($data['bill_datefrom'])); - $dateto = strftime('%Y-%m-%d', strtotime($data['bill_dateto'])); + $datefrom = date('Y-m-d', strtotime($data['bill_datefrom'])); + $dateto = date('Y-m-d', strtotime($data['bill_dateto'])); $datelabel = $datefrom . ' - ' . $dateto; array_push($ticklabels, $datelabel); @@ -421,7 +421,7 @@ function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgt $average = 0; if ($imgtype == 'day') { foreach (dbFetch('SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC', [$bill_id, $from, $to]) as $data) { - array_push($ticklabels, strftime('%Y-%m-%d', $data['timestamp'])); + array_push($ticklabels, date('Y-m-d', $data['timestamp'])); array_push($in_data, isset($data['traf_in']) ? $data['traf_in'] : 0); array_push($out_data, isset($data['traf_out']) ? $data['traf_out'] : 0); array_push($tot_data, isset($data['traf_total']) ? $data['traf_total'] : 0); @@ -431,7 +431,7 @@ function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgt $ave_count = count($tot_data); // Add empty items for the days not yet passed - $days = (strftime('%e', date($to - $from)) - $ave_count - 1); + $days = (date('j', date($to - $from)) - $ave_count - 1); for ($x = 0; $x < $days; $x++) { array_push($ticklabels, ''); array_push($in_data, 0); diff --git a/includes/html/collectd/functions.php b/includes/html/collectd/functions.php index f2859eee25..2402ae0db0 100644 --- a/includes/html/collectd/functions.php +++ b/includes/html/collectd/functions.php @@ -38,18 +38,7 @@ function read_var($name, &$array, $default = null) { if (isset($array[$name])) { if (is_array($array[$name])) { - if (get_magic_quotes_gpc()) { - $ret = []; - foreach ($array[$name] as $k => $v) { - $ret[stripslashes($k)] = stripslashes($v); - } - - return $ret; - } else { - return $array[$name]; - } - } elseif (is_string($array[$name]) && get_magic_quotes_gpc()) { - return stripslashes($array[$name]); + return $array[$name]; } else { return $array[$name]; } diff --git a/includes/html/graphs/bill/historicmonthly.inc.php b/includes/html/graphs/bill/historicmonthly.inc.php index 371df16e08..71891fea91 100644 --- a/includes/html/graphs/bill/historicmonthly.inc.php +++ b/includes/html/graphs/bill/historicmonthly.inc.php @@ -17,9 +17,9 @@ for ($i = 0; $i < count($graph_data['ticklabels']); $i++) { if (date('m', $start) == date('m', $end) && date('d', $start == 1)) { // Calendar months, omit the date and the end! - $graph_data['ticklabels'][$i] = strftime('%b %Y', $start); + $graph_data['ticklabels'][$i] = date('M Y', $start); } else { - $graph_data['ticklabels'][$i] = strftime('%e %b %Y', $start) . "\n" . strftime('%e %b %Y', $end); + $graph_data['ticklabels'][$i] = date('j M Y', $start) . "\n" . date('j M Y', $end); } } } diff --git a/includes/html/graphs/bill/historictransfer.inc.php b/includes/html/graphs/bill/historictransfer.inc.php index f56a4cf01c..750cd89635 100644 --- a/includes/html/graphs/bill/historictransfer.inc.php +++ b/includes/html/graphs/bill/historictransfer.inc.php @@ -21,7 +21,7 @@ for ($i = 0; $i < count($graph_data['ticklabels']); $i++) { $date = strtotime($graph_data['ticklabels'][$i]); if ($vars['imgtype'] === 'day') { - $graph_data['ticklabels'][$i] = strftime("%e\n%b", $date); + $graph_data['ticklabels'][$i] = date("j\nM", $date); } } } diff --git a/includes/html/pages/bill/history.inc.php b/includes/html/pages/bill/history.inc.php index 2d0c7ef694..4283d92feb 100644 --- a/includes/html/pages/bill/history.inc.php +++ b/includes/html/pages/bill/history.inc.php @@ -104,7 +104,7 @@ foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY echo '