diff --git a/.github/.phpstan.neon b/.github/.phpstan.neon
index 5d363fa..ca8061f 100644
--- a/.github/.phpstan.neon
+++ b/.github/.phpstan.neon
@@ -1,7 +1,9 @@
parameters:
level: 6
paths:
- - .
+ - %currentWorkingDirectory%/setup.php
+ - %currentWorkingDirectory%/functions.php
+ - %currentWorkingDirectory%/maint.php
excludePaths:
- vendor
- locales
diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml
index 9f50492..ffd8e94 100644
--- a/.github/workflows/plugin-ci-workflow.yml
+++ b/.github/workflows/plugin-ci-workflow.yml
@@ -124,7 +124,7 @@ jobs:
composer validate --strict || true
fi
- - name: Install Composer Dependencies
+ - name: Install Composer Dependencies for Cacti
run: |
cd ${{ github.workspace }}/cacti
if [ -f composer.json ]; then
@@ -181,22 +181,10 @@ jobs:
exit 1
fi
- - name: Verify Maint Plugin Composer Setup
- run: |
- ls -la ${{ github.workspace }}/cacti/plugins/maint
- cat ${{ github.workspace }}/cacti/plugins/maint/composer.json
-
- - name: Install Maint Plugin Composer Dependencies
- run: composer install --prefer-dist --no-progress --no-interaction
+ - name: Install Plugin Composer Dependencies
+ run: composer install --prefer-dist --no-progress
working-directory: ${{ github.workspace }}/cacti/plugins/maint
- env:
- COMPOSER_NO_DEV: 0
- - name: Verify Maint Plugin Vendor Binaries
- run: |
- ls -la ${{ github.workspace }}/cacti/plugins/maint/vendor
- ls -la ${{ github.workspace }}/cacti/plugins/maint/vendor/bin
-
- name: Run Linter on base code
run: composer run-script lint
working-directory: ${{ github.workspace }}/cacti/plugins/maint
diff --git a/composer.json b/composer.json
index 98444da..deedd1a 100644
--- a/composer.json
+++ b/composer.json
@@ -3,15 +3,14 @@
"description": "Cacti maintenance window plugin.",
"type": "project",
"license": "GPL-2.0-or-later",
- "require": {},
"require-dev": {
- "friendsofphp/php-cs-fixer": "^3.60",
+ "friendsofphp/php-cs-fixer": "^3.93",
"phpstan/phpstan": "^1.11",
"overtrue/phplint": "^9.2"
},
"scripts": {
- "lint": "./vendor/bin/phplint -c .github/.phplint.yml",
- "phpcsfixer": "./vendor/bin/php-cs-fixer fix --dry-run --diff --config .github/.php-cs-fixer.php",
- "phpstan": "./vendor/bin/phpstan analyse -c .github/.phpstan.neon"
+ "lint": "bash -c 'cd ../../ && plugins/maint/vendor/bin/phplint plugins/maint --exclude=vendor'",
+ "phpcsfixer": "bash -c 'cd ../../ && plugins/maint/vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.php plugins/maint'",
+ "phpstan": "bash -c 'cd ../../ && plugins/maint/vendor/bin/phpstan analyse --level=6 plugins/maint'"
}
}
diff --git a/functions.php b/functions.php
index 48f8430..44a91a9 100644
--- a/functions.php
+++ b/functions.php
@@ -24,92 +24,134 @@
+-------------------------------------------------------------------------+
*/
-function plugin_maint_check_cacti_host($host)
-{
- return plugin_maint_check_host(1, $host);
+/**
+ * Check if a Cacti host is in maintenance
+ *
+ * This is called via the 'is_device_in_maintenance' hook.
+ *
+ * @param int $host Host ID to check
+ *
+ * @return bool True if host is in active maintenance, false otherwise
+ */
+function plugin_maint_check_cacti_host(int $host): bool {
+ return plugin_maint_check_host(1, $host);
}
-function plugin_maint_check_webseer_url($host)
-{
- return plugin_maint_check_host(2, $host);
+/**
+ * Check if a WebSeer URL is in maintenance
+ *
+ * @param int $host WebSeer URL ID to check
+ *
+ * @return bool True if URL is in active maintenance, false otherwise
+ */
+function plugin_maint_check_webseer_url(int $host): bool {
+ return plugin_maint_check_host(2, $host);
}
-function plugin_maint_check_servcheck_test($host)
-{
- return plugin_maint_check_host(3, $host);
+/**
+ * Check if a Servcheck test is in maintenance
+ *
+ * @param int $host Servcheck test ID to check
+ *
+ * @return bool True if test is in active maintenance, false otherwise
+ */
+function plugin_maint_check_servcheck_test(int $host): bool {
+ return plugin_maint_check_host(3, $host);
}
-
-function plugin_maint_check_host($type, $host)
-{
- $schedules = db_fetch_assoc_prepared(
- 'SELECT *
+/**
+ * Check if a host is in maintenance based on type
+ *
+ * @param int $type Host type (1=Cacti host, 2=WebSeer URL, 3=Servcheck test)
+ * @param int $host Host/URL/Test ID to check
+ *
+ * @return bool True if host is in active maintenance schedule, false otherwise
+ */
+function plugin_maint_check_host(int $type, int $host): bool {
+ $schedules = db_fetch_assoc_prepared(
+ 'SELECT *
FROM plugin_maint_hosts
WHERE TYPE = ?
AND (host = ? OR host = 0)',
- [$type, $host],
- );
-
- if (!empty($schedules)) {
- foreach ($schedules as $s) {
- if (plugin_maint_check_schedule($s['schedule'])) {
- return true;
- }
- }
- }
- return false;
+ [$type, $host],
+ );
+
+ if (!empty($schedules)) {
+ foreach ($schedules as $s) {
+ if (plugin_maint_check_schedule($s['schedule'])) {
+ return true;
+ }
+ }
+ }
+
+ return false;
}
-function plugin_maint_check_schedule($schedule)
-{
- $sc = db_fetch_row_prepared(
- 'SELECT *
+/**
+ * Check if a maintenance schedule is currently active
+ *
+ * Handles both one-time and recurring schedules.
+ * For recurring schedules that have passed, automatically calculates
+ * and updates the next occurrence.
+ *
+ * @param int $schedule Schedule ID to check
+ *
+ * @return bool True if schedule is active now, false otherwise
+ */
+function plugin_maint_check_schedule(int $schedule): bool {
+ $sc = db_fetch_row_prepared(
+ 'SELECT *
FROM plugin_maint_schedules
WHERE enabled = \'on\' AND id = ?',
- [$schedule],
- );
-
- if (!empty($sc)) {
- $t = time();
- switch ($sc['mtype']) {
- case 1:
- if ($t > $sc['stime'] && $t < $sc['etime']) {
- return true;
- }
- break;
-
- case 2: // Recurring
- /* past, calculate next */
- if ($sc['etime'] < $t) {
- /* convert start and end to local so that hour stays same for add days across daylight saving time change */
- $starttimelocal = (new DateTime('@' . strval($sc['stime'])))->setTimezone(new DateTimeZone(date_default_timezone_get()));
- $endtimelocal = (new DateTime('@' . strval($sc['etime'])))->setTimezone(new DateTimeZone(date_default_timezone_get()));
- $nowtime = new DateTime();
- /* add interval days */
- $addday = new DateInterval('P' . strval($sc['minterval'] / 86400) . 'D');
- while ($endtimelocal < $nowtime) {
- $starttimelocal = $starttimelocal->add($addday);
- $endtimelocal = $endtimelocal->add($addday);
- }
-
- $sc['stime'] = $starttimelocal->getTimestamp();
- $sc['etime'] = $endtimelocal->getTimestamp();
- /* save next interval so not need to recalculate */
- db_execute_prepared(
- 'UPDATE plugin_maint_schedules
+ [$schedule],
+ );
+
+ if (!empty($sc)) {
+ $t = time();
+
+ switch ($sc['mtype']) {
+ case 1:
+ if ($t > $sc['stime'] && $t < $sc['etime']) {
+ return true;
+ }
+
+ break;
+ case 2: // Recurring
+ // past, calculate next
+ if ($sc['etime'] < $t) {
+ // convert start and end to local so that hour stays same for add days across daylight saving time change
+ $starttimelocal = (new DateTime('@' . strval($sc['stime'])))->setTimezone(new DateTimeZone(date_default_timezone_get()));
+ $endtimelocal = (new DateTime('@' . strval($sc['etime'])))->setTimezone(new DateTimeZone(date_default_timezone_get()));
+ $nowtime = new DateTime();
+ // add interval days
+ $addday = new DateInterval('P' . strval($sc['minterval'] / 86400) . 'D');
+
+ while ($endtimelocal < $nowtime) {
+ $starttimelocal = $starttimelocal->add($addday);
+ $endtimelocal = $endtimelocal->add($addday);
+ }
+
+ $sc['stime'] = $starttimelocal->getTimestamp();
+ $sc['etime'] = $endtimelocal->getTimestamp();
+ // save next interval so not need to recalculate
+ db_execute_prepared(
+ 'UPDATE plugin_maint_schedules
SET stime = ?, etime = ?
WHERE id = ?',
- [$sc['stime'], $sc['etime'], $schedule],
- );
- /* format yyyy-mm-dd hh:mm */
- cacti_log('INFO: Maintenance schedule "' . $sc['name'] . '" Next start ' . $starttimelocal->format('Y-m-d H:i')
- . ' End ' . $endtimelocal->format('Y-m-d H:i'), false, 'MAINT');
- }
- if ($t > $sc['stime'] && $t < $sc['etime']) {
- return true;
- }
- break;
- }
- }
- return false;
+ [$sc['stime'], $sc['etime'], $schedule],
+ );
+ // format yyyy-mm-dd hh:mm
+ cacti_log('INFO: Maintenance schedule "' . $sc['name'] . '" Next start ' . $starttimelocal->format('Y-m-d H:i')
+ . ' End ' . $endtimelocal->format('Y-m-d H:i'), false, 'MAINT');
+ }
+
+ if ($t > $sc['stime'] && $t < $sc['etime']) {
+ return true;
+ }
+
+ break;
+ }
+ }
+
+ return false;
}
diff --git a/maint.php b/maint.php
index 6a7428a..29d839b 100644
--- a/maint.php
+++ b/maint.php
@@ -34,53 +34,53 @@
// Maint Schedule Actions
$actions = [
- 1 => __('Update Time (Now + 1 Hour)', 'maint'),
- 2 => __('Delete', 'maint'),
+ 1 => __('Update Time (Now + 1 Hour)', 'maint'),
+ 2 => __('Delete', 'maint'),
];
// Host Maint Schedule Actions
$assoc_actions = [
- 1 => __('Associate', 'maint'),
- 2 => __('Disassociate', 'maint'),
+ 1 => __('Associate', 'maint'),
+ 2 => __('Disassociate', 'maint'),
];
$maint_types = [
- 1 => __('One Time', 'maint'),
- 2 => __('Recurring', 'maint'),
+ 1 => __('One Time', 'maint'),
+ 2 => __('Recurring', 'maint'),
];
$maint_intervals = [
- 0 => __('Not Defined', 'maint'),
- 86400 => __('Every Day', 'maint'),
- 604800 => __('Every Week', 'maint'),
+ 0 => __('Not Defined', 'maint'),
+ 86400 => __('Every Day', 'maint'),
+ 604800 => __('Every Week', 'maint'),
];
$yesno = [
- '' => __('No', 'maint'), // table value
- 0 => __('No', 'maint'),
- 1 => __('Yes', 'maint'),
- 'on' => __('Yes', 'maint'),
- 'off' => __('No', 'maint'),
+ '' => __('No', 'maint'), // table value
+ 0 => __('No', 'maint'),
+ 1 => __('Yes', 'maint'),
+ 'on' => __('Yes', 'maint'),
+ 'off' => __('No', 'maint'),
];
// Present a tabbed interface
$tabs = [
- 'general' => __('General', 'maint'),
+ 'general' => __('General', 'maint'),
];
if (api_plugin_is_enabled('thold')) {
- $tabs['hosts'] = __('Thold Devices', 'maint');
- define('MAINT_HOST_TYPE_HOSTS', '1');
+ $tabs['hosts'] = __('Thold Devices', 'maint');
+ define('MAINT_HOST_TYPE_HOSTS', '1');
}
if (api_plugin_is_enabled('webseer')) {
- $tabs['webseer'] = __('WebSeer', 'maint');
- define('MAINT_HOST_TYPE_WEBSEER', '2');
+ $tabs['webseer'] = __('WebSeer', 'maint');
+ define('MAINT_HOST_TYPE_WEBSEER', '2');
}
if (api_plugin_is_enabled('servcheck')) {
- $tabs['servcheck'] = __('Servcheck', 'maint');
- define('MAINT_HOST_TYPE_SERVCHECK', '3');
+ $tabs['servcheck'] = __('Servcheck', 'maint');
+ define('MAINT_HOST_TYPE_SERVCHECK', '3');
}
$tabs = api_plugin_hook_function('maint_tabs', $tabs);
@@ -88,294 +88,340 @@
set_default_action();
switch (get_request_var('action')) {
- case 'save':
- form_save();
- break;
- case 'actions':
- form_actions();
- break;
- case 'edit':
- top_header();
- schedule_edit();
- bottom_footer();
- break;
- default:
- top_header();
- schedules();
- bottom_footer();
- break;
+ case 'save':
+ form_save();
+
+ break;
+ case 'actions':
+ form_actions();
+
+ break;
+ case 'edit':
+ top_header();
+ schedule_edit();
+ bottom_footer();
+
+ break;
+ default:
+ top_header();
+ schedules();
+ bottom_footer();
+
+ break;
}
-function schedule_delete()
-{
- $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
+/**
+ * Delete selected maintenance schedules
+ *
+ * Deletes schedules and all associated host mappings.
+ * Redirects to main page after deletion.
+ *
+ * @return void This function exits after redirect
+ */
+function schedule_delete(): void {
+ $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
- if ($selected_items != false) {
- foreach ($selected_items as $id) {
- db_execute_prepared('DELETE FROM plugin_maint_schedules WHERE id=? LIMIT 1', [$id]);
- db_execute_prepared('DELETE FROM plugin_maint_hosts WHERE schedule = ?', [$id]);
- }
- }
+ if ($selected_items != false) {
+ foreach ($selected_items as $id) {
+ db_execute_prepared('DELETE FROM plugin_maint_schedules WHERE id=? LIMIT 1', [$id]);
+ db_execute_prepared('DELETE FROM plugin_maint_hosts WHERE schedule = ?', [$id]);
+ }
+ }
- header('Location: maint.php?header=false');
+ header('Location: maint.php?header=false');
- exit;
+ exit;
}
-function schedule_update()
-{
- $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
- if ($selected_items != false) {
- foreach ($selected_items as $id) {
- $stime = intval(time() / 60) * 60;
- $etime = $stime + 3600;
- db_execute_prepared(
- 'UPDATE plugin_maint_schedules
+/**
+ * Update selected schedules to start now and end in 1 hour
+ *
+ * Sets the start time to current time (rounded to nearest minute)
+ * and end time to 1 hour later. Redirects to main page after update.
+ *
+ * @return void This function exits after redirect
+ */
+function schedule_update(): void {
+ $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
+
+ if ($selected_items != false) {
+ foreach ($selected_items as $id) {
+ $stime = intval(time() / 60) * 60;
+ $etime = $stime + 3600;
+ db_execute_prepared(
+ 'UPDATE plugin_maint_schedules
SET stime = ?, etime = ?
WHERE id = ?
LIMIT 1',
- [$stime, $etime, $id],
- );
- }
- }
+ [$stime, $etime, $id],
+ );
+ }
+ }
- header('Location: maint.php?header=false');
+ header('Location: maint.php?header=false');
- exit;
+ exit;
}
+/**
+ * Save a maintenance schedule from edit form
+ *
+ * Validates and saves schedule data including:
+ * - Name, type (one-time or recurring), enabled status
+ * - Start/end times, interval for recurring schedules
+ * Redirects to edit page after save.
+ *
+ * @return void This function exits after redirect
+ */
+function form_save(): void {
+ global $plugins;
+
+ if (isset_request_var('save_component')) {
+ // ================= input validation =================
+ get_filter_request_var('id');
+ get_filter_request_var('mtype');
+ get_filter_request_var('minterval');
+
+ if (isset_request_var('name')) {
+ // Remove HTML <>
+ set_request_var('name', trim(str_replace(['\\', "'", '"', '<', '>'], '', get_nfilter_request_var('name'))));
+ }
+
+ if (isset_request_var('stime')) {
+ set_request_var('stime', trim(str_replace(['\\', "'", '"'], '', get_nfilter_request_var('stime'))));
+ }
+
+ if (isset_request_var('etime')) {
+ set_request_var('etime', trim(str_replace(['\\', "'", '"'], '', get_nfilter_request_var('etime'))));
+ }
+ // ====================================================
+
+ $save['id'] = get_nfilter_request_var('id');
+ $save['name'] = get_nfilter_request_var('name');
+ $save['mtype'] = get_nfilter_request_var('mtype');
+ $save['stime'] = strtotime(get_nfilter_request_var('stime'));
+ $save['etime'] = strtotime(get_nfilter_request_var('etime'));
+ $save['minterval'] = get_nfilter_request_var('minterval');
+
+ if (isset_request_var('enabled')) {
+ $save['enabled'] = 'on';
+ } else {
+ $save['enabled'] = '';
+ }
-function form_save()
-{
- global $plugins;
-
- if (isset_request_var('save_component')) {
- /* ================= input validation ================= */
- get_filter_request_var('id');
- get_filter_request_var('mtype');
- get_filter_request_var('minterval');
-
- if (isset_request_var('name')) {
- /* Remove HTML <> */
- set_request_var('name', trim(str_replace(["\\", "'", '"', '<', '>'], '', get_nfilter_request_var('name'))));
- }
- if (isset_request_var('stime')) {
- set_request_var('stime', trim(str_replace(["\\", "'", '"'], '', get_nfilter_request_var('stime'))));
- }
- if (isset_request_var('etime')) {
- set_request_var('etime', trim(str_replace(["\\", "'", '"'], '', get_nfilter_request_var('etime'))));
- }
- /* ==================================================== */
-
- $save['id'] = get_nfilter_request_var('id');
- $save['name'] = get_nfilter_request_var('name');
- $save['mtype'] = get_nfilter_request_var('mtype');
- $save['stime'] = strtotime(get_nfilter_request_var('stime'));
- $save['etime'] = strtotime(get_nfilter_request_var('etime'));
- $save['minterval'] = get_nfilter_request_var('minterval');
-
- if (isset_request_var('enabled')) {
- $save['enabled'] = 'on';
- } else {
- $save['enabled'] = '';
- }
-
- if ($save['mtype'] == 1) {
- $save['minterval'] = 0;
- }
-
- if ($save['stime'] >= $save['etime']) {
- raise_message(2);
- }
-
- if (!is_error_message()) {
- $id = sql_save($save, 'plugin_maint_schedules');
- if ($id) {
- raise_message(1);
- } else {
- raise_message(2);
- }
- }
-
- header('Location: maint.php?tab=general&action=edit&header=false&id=' . (empty($id) ? $save['id'] : $id));
-
- exit;
- }
+ if ($save['mtype'] == 1) {
+ $save['minterval'] = 0;
+ }
+
+ if ($save['stime'] >= $save['etime']) {
+ raise_message(2);
+ }
+
+ if (!is_error_message()) {
+ $id = sql_save($save, 'plugin_maint_schedules');
+
+ if ($id) {
+ raise_message(1);
+ } else {
+ raise_message(2);
+ }
+ }
+
+ header('Location: maint.php?tab=general&action=edit&header=false&id=' . (empty($id) ? $save['id'] : $id));
+
+ exit;
+ }
}
-function form_actions()
-{
- global $actions, $assoc_actions;
-
- /* ================= input validation ================= */
- get_filter_request_var('id');
- get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^([a-zA-Z0-9_]+)$/']]);
- /* ================= input validation ================= */
-
- /* if we are to save this form, instead of display it */
- if (isset_request_var('selected_items')) {
- if (isset_request_var('save_list')) {
- if (get_request_var('drp_action') == '2') { /* delete */
- schedule_delete();
- } elseif (get_request_var('drp_action') == '1') { /* update */
- schedule_update();
- }
-
- header('Location: maint.php?header=false');
-
- exit;
- } elseif (isset_request_var('save_hosts')) {
- $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
-
- if ($selected_items != false) {
- if (get_request_var('drp_action') == '1') { /* associate */
- for ($i = 0; ($i < count($selected_items)); $i++) {
- db_execute_prepared(
- 'REPLACE INTO plugin_maint_hosts (type, host, schedule)
+/**
+ * Handle form actions for schedules and host associations
+ *
+ * Processes:
+ * - Schedule actions (delete, update time)
+ * - Host association actions (associate, disassociate)
+ * - WebSeer URL associations
+ * - Servcheck test associations
+ *
+ * @return void This function may exit after processing
+ */
+function form_actions(): void {
+ global $actions, $assoc_actions;
+
+ // ================= input validation =================
+ get_filter_request_var('id');
+ get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^([a-zA-Z0-9_]+)$/']]);
+
+ // ================= input validation ================= // if we are to save this form, instead of display it
+ if (isset_request_var('selected_items')) {
+ if (isset_request_var('save_list')) {
+ if (get_request_var('drp_action') == '2') { // delete
+ schedule_delete();
+ } elseif (get_request_var('drp_action') == '1') { // update
+ schedule_update();
+ }
+
+ header('Location: maint.php?header=false');
+
+ exit;
+ }
+
+ if (isset_request_var('save_hosts')) {
+ $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
+
+ if ($selected_items != false) {
+ if (get_request_var('drp_action') == '1') { // associate
+ for ($i = 0; ($i < count($selected_items)); $i++) {
+ db_execute_prepared(
+ 'REPLACE INTO plugin_maint_hosts (type, host, schedule)
VALUES (?, ?, ?)',
- [MAINT_HOST_TYPE_HOSTS, $selected_items[$i], get_request_var('id')],
- );
- }
- } elseif (get_request_var('drp_action') == '2') { /* disassociate */
- for ($i = 0; ($i < count($selected_items)); $i++) {
- db_execute_prepared(
- 'DELETE FROM plugin_maint_hosts
+ [MAINT_HOST_TYPE_HOSTS, $selected_items[$i], get_request_var('id')],
+ );
+ }
+ } elseif (get_request_var('drp_action') == '2') { // disassociate
+ for ($i = 0; ($i < count($selected_items)); $i++) {
+ db_execute_prepared(
+ 'DELETE FROM plugin_maint_hosts
WHERE type = ? AND host = ? AND schedule = ?',
- [MAINT_HOST_TYPE_HOSTS, $selected_items[$i], get_request_var('id')],
- );
- }
- }
- }
-
- header('Location: maint.php?action=edit&tab=hosts&header=false&id=' . get_request_var('id'));
-
- exit;
- } elseif (isset_request_var('save_webseer')) {
- $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
-
- if ($selected_items != false) {
- if (get_request_var('drp_action') == '1') { /* associate */
- for ($i = 0; ($i < count($selected_items)); $i++) {
- db_execute_prepared(
- 'REPLACE INTO plugin_maint_hosts (type, host, schedule)
+ [MAINT_HOST_TYPE_HOSTS, $selected_items[$i], get_request_var('id')],
+ );
+ }
+ }
+ }
+
+ header('Location: maint.php?action=edit&tab=hosts&header=false&id=' . get_request_var('id'));
+
+ exit;
+ }
+
+ if (isset_request_var('save_webseer')) {
+ $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
+
+ if ($selected_items != false) {
+ if (get_request_var('drp_action') == '1') { // associate
+ for ($i = 0; ($i < count($selected_items)); $i++) {
+ db_execute_prepared(
+ 'REPLACE INTO plugin_maint_hosts (type, host, schedule)
VALUES (?, ?, ?)',
- [MAINT_HOST_TYPE_WEBSEER, $selected_items[$i], get_request_var('id')],
- );
- }
- } elseif (get_request_var('drp_action') == '2') { /* disassociate */
- for ($i = 0; ($i < count($selected_items)); $i++) {
- db_execute_prepared(
- 'DELETE FROM plugin_maint_hosts
+ [MAINT_HOST_TYPE_WEBSEER, $selected_items[$i], get_request_var('id')],
+ );
+ }
+ } elseif (get_request_var('drp_action') == '2') { // disassociate
+ for ($i = 0; ($i < count($selected_items)); $i++) {
+ db_execute_prepared(
+ 'DELETE FROM plugin_maint_hosts
WHERE type = ? AND host = ? AND schedule = ?',
- [MAINT_HOST_TYPE_WEBSEER, $selected_items[$i], get_request_var('id')],
- );
- }
- }
- }
-
- header('Location: maint.php?action=edit&tab=webseer&header=false&id=' . get_request_var('id'));
-
- exit;
- } elseif (isset_request_var('save_servcheck')) {
- $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
-
- if ($selected_items != false) {
- if (get_request_var('drp_action') == '1') { /* associate */
- for ($i = 0; ($i < count($selected_items)); $i++) {
- db_execute_prepared(
- 'REPLACE INTO plugin_maint_hosts (type, host, schedule)
+ [MAINT_HOST_TYPE_WEBSEER, $selected_items[$i], get_request_var('id')],
+ );
+ }
+ }
+ }
+
+ header('Location: maint.php?action=edit&tab=webseer&header=false&id=' . get_request_var('id'));
+
+ exit;
+ }
+
+ if (isset_request_var('save_servcheck')) {
+ $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
+
+ if ($selected_items != false) {
+ if (get_request_var('drp_action') == '1') { // associate
+ for ($i = 0; ($i < count($selected_items)); $i++) {
+ db_execute_prepared(
+ 'REPLACE INTO plugin_maint_hosts (type, host, schedule)
VALUES (?, ?, ?)',
- [MAINT_HOST_TYPE_SERVCHECK, $selected_items[$i], get_request_var('id')],
- );
- }
- } elseif (get_request_var('drp_action') == '2') { /* disassociate */
- for ($i = 0; ($i < count($selected_items)); $i++) {
- db_execute_prepared(
- 'DELETE FROM plugin_maint_hosts
+ [MAINT_HOST_TYPE_SERVCHECK, $selected_items[$i], get_request_var('id')],
+ );
+ }
+ } elseif (get_request_var('drp_action') == '2') { // disassociate
+ for ($i = 0; ($i < count($selected_items)); $i++) {
+ db_execute_prepared(
+ 'DELETE FROM plugin_maint_hosts
WHERE type = ? AND host = ? AND schedule = ?',
- [MAINT_HOST_TYPE_SERVCHECK, $selected_items[$i], get_request_var('id')],
- );
- }
- }
- }
-
- header('Location: maint.php?action=edit&tab=servcheck&header=false&id=' . get_request_var('id'));
-
- exit;
- } else {
- api_plugin_hook_function('maint_actions_execute');
- }
- }
-
- /* setup some variables */
- $list = '';
- $array = [];
- $list_name = '';
- if (isset_request_var('id')) {
- $list_name = html_escape(
- db_fetch_cell_prepared(
- 'SELECT name
+ [MAINT_HOST_TYPE_SERVCHECK, $selected_items[$i], get_request_var('id')],
+ );
+ }
+ }
+ }
+
+ header('Location: maint.php?action=edit&tab=servcheck&header=false&id=' . get_request_var('id'));
+
+ exit;
+ } else {
+ api_plugin_hook_function('maint_actions_execute');
+ }
+ }
+
+ // setup some variables
+ $list = '';
+ $array = [];
+ $list_name = '';
+
+ if (isset_request_var('id')) {
+ $list_name = html_escape(
+ db_fetch_cell_prepared(
+ 'SELECT name
FROM plugin_maint_schedules
WHERE id = ?',
- [get_request_var('id')],
- ),
- );
- }
-
- if (isset_request_var('save_list')) {
- /* loop through each of the notification lists selected on the previous page and get more info about them */
- foreach ($_POST as $var => $val) {
- if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
- /* ================= input validation ================= */
- input_validate_input_number($matches[1]);
- /* ==================================================== */
-
- $list .= '
' . html_escape(
- db_fetch_cell_prepared(
- 'SELECT name
+ [get_request_var('id')],
+ ),
+ );
+ }
+
+ if (isset_request_var('save_list')) {
+ // loop through each of the notification lists selected on the previous page and get more info about them
+ foreach ($_POST as $var => $val) {
+ if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
+ // ================= input validation =================
+ input_validate_input_number($matches[1]);
+ // ====================================================
+
+ $list .= '
' . html_escape(
+ db_fetch_cell_prepared(
+ 'SELECT name
FROM plugin_maint_schedules
WHERE id=?',
- [$matches[1]],
- ),
- )
- . '
" . __('Click \'Continue\' to Delete the following Maintenance Schedule(s). Any Devices(s) Associated with this Schedule will be Disassociated.', 'maint') . "
$list
";
- $save_html = " ";
- }
- } else {
- print "
" . __('You must select at least one Maintenance Schedule.', 'maint') . "
";
- $save_html = " ";
+ }
+ } else {
+ print "
" . __('You must select at least one Maintenance Schedule.', 'maint') . '
';
+ $save_html = "
+ print "
@@ -386,65 +432,65 @@ function form_actions()
";
- html_end_box();
+ html_end_box();
- form_end();
+ form_end();
- bottom_footer();
- } elseif (isset_request_var('save_hosts')) {
- /* loop through each of the notification lists selected on the previous page and get more info about them */
- foreach ($_POST as $var => $val) {
- if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
- /* ================= input validation ================= */
- input_validate_input_number($matches[1]);
- /* ==================================================== */
+ bottom_footer();
+ } elseif (isset_request_var('save_hosts')) {
+ // loop through each of the notification lists selected on the previous page and get more info about them
+ foreach ($_POST as $var => $val) {
+ if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
+ // ================= input validation =================
+ input_validate_input_number($matches[1]);
+ // ====================================================
- $description = db_fetch_cell_prepared(
- 'SELECT description
+ $description = db_fetch_cell_prepared(
+ 'SELECT description
FROM host
WHERE id = ?',
- [$matches[1]],
- );
+ [$matches[1]],
+ );
- $list .= '
" . __('You must select at least one Device.', 'maint') . '
';
+ $save_html = "';
+ }
- print "
+ print "
@@ -455,65 +501,65 @@ function form_actions()
";
- html_end_box();
+ html_end_box();
- form_end();
+ form_end();
- bottom_footer();
- } elseif (isset_request_var('save_webseer')) {
- /* loop through each of the notification lists selected on the previous page and get more info about them */
- foreach ($_POST as $var => $val) {
- if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
- /* ================= input validation ================= */
- input_validate_input_number($matches[1]);
- /* ==================================================== */
+ bottom_footer();
+ } elseif (isset_request_var('save_webseer')) {
+ // loop through each of the notification lists selected on the previous page and get more info about them
+ foreach ($_POST as $var => $val) {
+ if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
+ // ================= input validation =================
+ input_validate_input_number($matches[1]);
+ // ====================================================
- $description = db_fetch_cell_prepared(
- 'SELECT display_name
+ $description = db_fetch_cell_prepared(
+ 'SELECT display_name
FROM plugin_webseer_urls
WHERE id = ?',
- [$matches[1]],
- );
+ [$matches[1]],
+ );
- $list .= '
" . __('You must select at least one Webseer.', 'maint') . '
';
+ $save_html = "';
+ }
- print "
+ print "
@@ -524,65 +570,65 @@ function form_actions()
";
- html_end_box();
+ html_end_box();
- form_end();
+ form_end();
- bottom_footer();
- } elseif (isset_request_var('save_servcheck')) {
- /* loop through each of the notification lists selected on the previous page and get more info about them */
- foreach ($_POST as $var => $val) {
- if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
- /* ================= input validation ================= */
- input_validate_input_number($matches[1]);
- /* ==================================================== */
+ bottom_footer();
+ } elseif (isset_request_var('save_servcheck')) {
+ // loop through each of the notification lists selected on the previous page and get more info about them
+ foreach ($_POST as $var => $val) {
+ if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
+ // ================= input validation =================
+ input_validate_input_number($matches[1]);
+ // ====================================================
- $description = db_fetch_cell_prepared(
- 'SELECT display_name
+ $description = db_fetch_cell_prepared(
+ 'SELECT display_name
FROM plugin_servcheck_test
WHERE id = ?',
- [$matches[1]],
- );
+ [$matches[1]],
+ );
- $list .= '