' . html_escape(__('Review the recorded observations below. Acknowledgments are personal to this session, expire when observations change, and never suppress alerts or change health.', 'pfs')) . '
'; + print '' . html_escape(__('Monitoring view', 'pfs')) . '
'; + OperatorPage::render($rows, $session, $user, $now, $actions); + bottom_footer(); +} catch (Throwable $error) { + cacti_log('Operator page failed (' . get_class($error) . ')', false, 'PFS'); + http_response_code(503); + top_header(); + print '' . html_escape(__('Observations could not be read. Ask an administrator to check the plugin log.', 'pfs')) . '
'; + bottom_footer(); +} diff --git a/phpstan.neon b/phpstan.neon index d107c26..ad4da47 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -23,6 +23,7 @@ parameters: paths: - lib - setup.php + - include/operator.php - include/unbooted-uninstall.php - scripts scanDirectories: diff --git a/setup.php b/setup.php index 75aaa9f..0f11081 100644 --- a/setup.php +++ b/setup.php @@ -100,13 +100,18 @@ function plugin_pfs_check_config(): bool { } /** - * Common start of every page script, after include/auth.php has authorized - * the realm. Refuses on an unsupported runtime or a disabled plugin, because - * Cacti keeps plugin realms registered while a plugin is disabled. + * Common start after include/auth.php establishes the user. Recheck the + * realm here because cookie and Basic login restore the user after the + * alternate-realms hook. Disabled plugins and unsupported runtimes refuse. */ function pfs_page_start(): bool { if (pfs_boot() && api_plugin_is_enabled('pfs')) { - return true; + if (pfs_page_allowed()) { + return true; + } + http_response_code(403); + + return false; } top_header(); @@ -252,12 +257,14 @@ function pfs_setup_hooks(bool $grant = false): void { include_once($config['library_path'] . '/poller.php'); } + $enabled = (new \Somethingwithproof\Pfs\Schema(false))->pluginEnabled(); + foreach (\Somethingwithproof\Pfs\Schema::HOOKS as $hook => $function) { - api_plugin_register_hook('pfs', $hook, $function, 'setup.php'); + api_plugin_register_hook('pfs', $hook, $function, 'setup.php', $enabled); } foreach (\Somethingwithproof\Pfs\Pages::realms() as $realm) { - api_plugin_register_realm('pfs', implode(',', $realm['files']), $realm['name'], $grant); + api_plugin_register_realm('pfs', implode(',', $realm['files']), $realm['name'], $grant && $realm['files'] !== \Somethingwithproof\Pfs\Pages::OPERATOR); } } @@ -380,6 +387,10 @@ function pfs_config_arrays(): void { function pfs_config_settings(): void { global $tabs, $settings; + if (PHP_SAPI !== 'cli' && !api_plugin_user_realm_auth('pfs_admin.php')) { + return; + } + if (!pfs_boot()) { return; } @@ -393,10 +404,17 @@ function pfs_config_settings(): void { * @return array