__('Delete', 'thold'), 2 => __('Duplicate', 'thold') ]; $assoc_actions = [ 1 => __('Associate', 'thold'), 2 => __('Disassociate', 'thold') ]; // present a tabbed interface $tabs_thold = [ 'general' => __('General', 'thold'), 'hosts' => __('Devices', 'thold'), 'tholds' => __('Thresholds', 'thold'), 'templates' => __('Templates', 'thold') ]; $tabs_thold = api_plugin_hook_function('notify_list_tabs', $tabs_thold); set_default_action(); switch (get_request_var('action')) { case 'save': form_save(); break; case 'actions': form_actions(); break; case 'edit': top_header(); edit(); bottom_footer(); break; default: top_header(); lists(); bottom_footer(); break; } /* -------------------------- The Save Function -------------------------- */ /** * Validates and saves the notification list edit form's submitted * fields, rejecting the save if the same email address appears in both * the To and BCC lists, then redirects back to the edit form for the * saved (or original) list id. Called from this script's main * request-dispatch switch when action=save. * * @return void */ function form_save() { if (isset_request_var('save_component')) { $save['id'] = get_filter_request_var('id'); $save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3); $save['enabled'] = isset_request_var('enabled') ? 'on' : ''; $save['description'] = form_input_validate(get_nfilter_request_var('description'), 'description', '', false, 3); $save['emails'] = form_input_validate(get_nfilter_request_var('emails'), 'emails', '', true, 3); $save['bcc_emails'] = form_input_validate(get_nfilter_request_var('bcc_emails'), 'bcc_emails', '', true, 3); $save['format_file'] = form_input_validate(get_nfilter_request_var('format_file'), 'format_file', '', true, 3); $bccs = explode(',', $save['bcc_emails']); $emails = explode(',', $save['emails']); $bad = false; foreach ($bccs as $email) { if (array_search(trim($email), $emails, true) !== false) { raise_message( 'duplicate_email', __('ERROR: You can not have your Email in both the To and BCC lines. The Email below is invalid!

%s', $email, 'THOLD'), MESSAGE_LEVEL_WARN ); $_SESSION['sess_error_fields']['bcc_emails'] = 'bcc_emails'; $bad = true; break; } } if (!$bad) { foreach ($emails as $email) { if (array_search(trim($email), $bccs, true) !== false) { raise_message( 'duplicate_email', __('ERROR: You can not have your Email in both the To and BCC lines. The Email below is invalid!

%s', $email, 'THOLD'), MESSAGE_LEVEL_WARN ); $_SESSION['sess_error_fields']['bcc_emails'] = 'bcc_emails'; $bad = true; break; } } } if (!is_error_message()) { $id = sql_save($save, 'plugin_notification_lists'); if ($id) { raise_message(1); } else { raise_message(2); } } } header('Location: notify_lists.php?header=false&action=edit&id=' . (empty($id) ? get_request_var('id') : $id)); } /* ------------------------ The 'actions' function ------------------------ */ /** * Handles the bulk-action confirmation page/submission for the * notification lists view and its host/threshold/template association * sub-views, validating the requested action against the combined set * of list-level and association-level allowed actions before * dispatching. Called from this script's main request-dispatch switch * when action=actions. * * @return void * * @global array $actions Map of drp_action value => action label * for list-level bulk actions. * @global array $assoc_actions Map of drp_action value => action label * for host/threshold/template association * bulk actions. */ function form_actions() { global $actions, $assoc_actions; // ================= input validation ================= /* * get_filter_request_var() stores the value as an int, so the comparison * has to be made on strings for the strict check to mean anything. */ get_filter_request_var('drp_action'); $valid_actions = array_map('strval', array_keys($actions + $assoc_actions)); if (!in_array((string) get_request_var('drp_action'), $valid_actions, true)) { raise_message(40); header('Location: notify_lists.php?header=false'); exit; } // ==================================================== // if we are to save this form, instead of display it if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); if (isset_request_var('save_list')) { if ($selected_items != false) { if (get_request_var('drp_action') == '1') { // delete /* * Bind positionally on the values: sanitize_unserialize_selected_items() * preserves the submitted array's keys, and a string key would be read * as a named parameter. */ $ids = array_map('intval', array_values($selected_items)); $placeholders = implode(', ', array_fill(0, cacti_sizeof($ids), '?')); /* * Issued as SQL rather than through db_begin_transaction() and * friends: Cacti's db_commit_transaction() gates the commit on * SELECT @@in_transaction, which only MariaDB defines. On MySQL that * query fails, the commit is skipped, and every write here is * discarded when the connection closes. */ db_execute('START TRANSACTION'); /* * The host reset deliberately omits the deleted = "" predicate its * siblings carry: a soft-deleted device that is later restored must * not come back pointing at a list that no longer exists. */ $statements = [ 'DELETE FROM plugin_notification_lists WHERE id IN (' . $placeholders . ')', 'UPDATE host SET thold_send_email = 0 WHERE thold_send_email = 2 AND deleted = "" AND thold_host_email IN (' . $placeholders . ')', 'UPDATE host SET thold_send_email = 1 WHERE thold_send_email = 3 AND deleted = "" AND thold_host_email IN (' . $placeholders . ')', 'UPDATE host SET thold_host_email = 0 WHERE thold_host_email IN (' . $placeholders . ')', 'UPDATE thold_data SET notify_warning = 0 WHERE notify_warning IN (' . $placeholders . ')', 'UPDATE thold_data SET notify_alert = 0 WHERE notify_alert IN (' . $placeholders . ')', 'UPDATE thold_template SET notify_warning = 0 WHERE notify_warning IN (' . $placeholders . ')', 'UPDATE thold_template SET notify_alert = 0 WHERE notify_alert IN (' . $placeholders . ')' ]; $ok = true; foreach ($statements as $sql) { if (!db_execute_prepared($sql, $ids)) { $ok = false; break; } } if ($ok) { db_execute('COMMIT'); } else { db_execute('ROLLBACK'); } } elseif (get_request_var('drp_action') == '2') { // duplicate $i = 1; foreach ($selected_items as $item) { // get list to be duplicated $list = db_fetch_row_prepared('SELECT * FROM plugin_notification_lists WHERE id = ?', [$item]); // see if there is already a list with the new name $exists = db_fetch_cell_prepared('SELECT COUNT(*) FROM plugin_notification_lists WHERE name = ?', [get_nfilter_request_var('name')]); if ($exists > 0) { $name = get_nfilter_request_var('name') . ' (' . $i . ')'; $i ++; } else { $name = get_nfilter_request_var('name'); } $save['id'] = 0; $save['name'] = $name; $save['description'] = $list['description']; $save['emails'] = $list['emails']; $save['bcc_emails'] = $list['bcc_emails']; $id = sql_save($save, 'plugin_notification_lists'); if ($id) { raise_message(1); } else { raise_message(2); } } } } header('Location: notify_lists.php?header=false'); exit; } if (isset_request_var('save_associate')) { if ($selected_items != false) { get_filter_request_var('id'); get_filter_request_var('notification_action'); get_filter_request_var('notification_warning_action'); get_filter_request_var('notification_alert_action'); db_execute('START TRANSACTION'); $ok = true; if (get_request_var('drp_action') == '1') { // associate for ($i = 0; ($i < cacti_sizeof($selected_items)); $i++) { // set the notification list $ok = db_execute_prepared('UPDATE host SET thold_host_email = ? WHERE id = ? AND deleted = ""', [get_request_var('id'), $selected_items[$i]]) && $ok; // set the global/list election $ok = db_execute_prepared('UPDATE host SET thold_send_email = ? WHERE id = ? AND deleted = ""', [get_request_var('notification_action'), $selected_items[$i]]) && $ok; if (get_request_var('notification_warning_action') > 0) { // clear other settings if (get_request_var('notification_warning_action') == 1) { // set the notification list $ok = db_execute_prepared('UPDATE thold_data AS td LEFT JOIN thold_template AS tt ON td.thold_template_id = tt.id SET td.notify_warning = ? WHERE td.host_id = ? AND (tt.notify_templated = "" OR tt.notify_templated IS NULL)', [get_request_var('id'), $selected_items[$i]]) && $ok; // clear other items $ok = db_execute_prepared('UPDATE thold_data AS td LEFT JOIN thold_template AS tt ON td.thold_template_id = tt.id SET td.notify_warning_extra = \'\' WHERE td.host_id = ? AND (tt.notify_templated = "" OR tt.notify_templated IS NULL)', [$selected_items[$i]]) && $ok; } else { // set the notification list $ok = db_execute_prepared('UPDATE thold_data AS td LEFT JOIN thold_template AS tt ON td.thold_template_id = tt.id SET td.notify_warning = ? WHERE td.host_id = ? AND (tt.notify_templated = "" OR tt.notify_templated IS NULL)', [get_request_var('id'), $selected_items[$i]]) && $ok; } } if (get_request_var('notification_alert_action') > 0) { // clear other settings if (get_request_var('notification_alert_action') == 1) { // set the notification list $ok = db_execute_prepared('UPDATE thold_data AS td LEFT JOIN thold_template AS tt ON td.thold_template_id = tt.id SET td.notify_alert = ? WHERE td.host_id = ? AND (tt.notify_templated = "" OR tt.notify_templated IS NULL)', [get_request_var('id'), $selected_items[$i]]) && $ok; // clear other items $ok = db_execute_prepared('UPDATE thold_data AS td LEFT JOIN thold_template AS tt ON td.thold_template_id = tt.id SET td.notify_extra = \'\' WHERE host_id = ? AND (tt.notify_templated = "" OR tt.notify_templated IS NULL)', [$selected_items[$i]]) && $ok; // remove legacy contacts $ok = db_execute_prepared('DELETE pttc FROM plugin_thold_threshold_contact AS pttc INNER JOIN thold_data AS td ON pttc.thold_id = td.id LEFT JOIN thold_template AS tt ON td.thold_template_id = tt.id WHERE td.host_id = ? AND (tt.notify_templated = "" OR tt.notify_templated IS NULL)', [$selected_items[$i]]) && $ok; } else { // set the notification list $ok = db_execute_prepared('UPDATE thold_data AS td LEFT JOIN thold_template AS tt ON td.thold_template_id = tt.id SET td.notify_alert = ? WHERE td.host_id = ? AND (tt.notify_templated = "" OR tt.notify_templated IS NULL)', [get_request_var('id'), $selected_items[$i]]) && $ok; } } if (!$ok) { break; } } } elseif (get_request_var('drp_action') == '2') { // disassociate for ($i = 0; ($i < cacti_sizeof($selected_items)); $i++) { // set the notification list $ok = db_execute_prepared('UPDATE host SET thold_host_email = 0 WHERE id = ? AND deleted = ""', [$selected_items[$i]]) && $ok; // set the global/list election $ok = db_execute_prepared('UPDATE host SET thold_send_email = ? WHERE id = ? AND deleted = ""', [get_request_var('notification_action'), $selected_items[$i]]) && $ok; if (get_request_var('notification_warning_action') > 0) { // set the notification list $ok = db_execute_prepared('UPDATE thold_data AS td LEFT JOIN thold_template AS tt ON td.thold_template_id = tt.id SET td.notify_warning = 0 WHERE td.host_id = ? AND (tt.notify_templated = "" OR tt.notify_templated IS NULL) AND td.notify_warning = ?', [$selected_items[$i], get_request_var('id')]) && $ok; } if (get_request_var('notification_alert_action') > 0) { // set the notification list $ok = db_execute_prepared('UPDATE thold_data AS td LEFT JOIN thold_template AS tt ON td.thold_template_id = tt.id SET td.notify_alert = 0 WHERE td.host_id = ? AND (tt.notify_templated = "" OR tt.notify_templated IS NULL) AND td.notify_alert = ?', [$selected_items[$i], get_request_var('id')]) && $ok; } if (!$ok) { break; } } } if ($ok) { db_execute('COMMIT'); } else { db_execute('ROLLBACK'); } } header('Location: notify_lists.php?header=false&action=edit&tab=hosts&id=' . get_request_var('id')); exit; } if (isset_request_var('save_templates')) { if ($selected_items != false) { get_filter_request_var('id'); get_filter_request_var('notification_action'); get_filter_request_var('notification_warning_action'); get_filter_request_var('notification_alert_action'); db_execute('START TRANSACTION'); $ok = true; $update_template = []; if (get_request_var('drp_action') == '1') { // associate for ($i = 0; ($i < cacti_sizeof($selected_items)); $i++) { if (get_request_var('notification_warning_action') > 0) { // clear other settings if (get_request_var('notification_warning_action') == 1) { // set the notification list $ok = db_execute_prepared('UPDATE thold_template SET notify_warning = ? WHERE id = ?', [get_request_var('id'), $selected_items[$i]]) && $ok; // clear other items $ok = db_execute_prepared("UPDATE thold_template SET notify_warning_extra = '' WHERE id = ?", [$selected_items[$i]]) && $ok; } else { // set the notification list $ok = db_execute_prepared('UPDATE thold_template SET notify_warning = ? WHERE id = ?', [get_request_var('id'), $selected_items[$i]]) && $ok; } } if (get_request_var('notification_alert_action') > 0) { // clear other settings if (get_request_var('notification_alert_action') == 1) { // set the notification list $ok = db_execute_prepared('UPDATE thold_template SET notify_alert = ? WHERE id = ?', [get_request_var('id'), $selected_items[$i]]) && $ok; // clear other items $ok = db_execute_prepared("UPDATE thold_template SET notify_extra = '' WHERE id = ?", [$selected_items[$i]]) && $ok; $ok = db_execute_prepared('DELETE FROM plugin_thold_template_contact WHERE template_id = ?', [$selected_items[$i]]) && $ok; } else { // set the notification list $ok = db_execute_prepared('UPDATE thold_template SET notify_alert = ? WHERE id = ?', [get_request_var('id'), $selected_items[$i]]) && $ok; } } $update_template[] = $selected_items[$i]; if (!$ok) { break; } } } elseif (get_request_var('drp_action') == '2') { // disassociate for ($i = 0; ($i < cacti_sizeof($selected_items)); $i++) { if (get_request_var('notification_warning_action') > 0) { // set the notification list $ok = db_execute_prepared('UPDATE thold_template SET notify_warning = 0 WHERE id = ? AND notify_warning = ?', [$selected_items[$i], get_request_var('id')]) && $ok; } if (get_request_var('notification_alert_action') > 0) { // set the notification list $ok = db_execute_prepared('UPDATE thold_template SET notify_alert = 0 WHERE id = ? AND notify_alert = ?', [$selected_items[$i], get_request_var('id')]) && $ok; } $update_template[] = $selected_items[$i]; if (!$ok) { break; } } } if ($ok) { db_execute('COMMIT'); // Propagate template changes to threshold instances after the // notification assignment is committed so this cascade does not // participate in the transaction boundary. foreach ($update_template as $template_id) { thold_template_update_thresholds($template_id); } } else { db_execute('ROLLBACK'); } } header('Location: notify_lists.php?header=false&action=edit&tab=templates&id=' . get_request_var('id')); exit; } if (isset_request_var('save_tholds')) { if ($selected_items != false) { get_filter_request_var('id'); get_filter_request_var('notification_action'); get_filter_request_var('notification_warning_action'); get_filter_request_var('notification_alert_action'); db_execute('START TRANSACTION'); $ok = true; if (get_request_var('drp_action') == '1') { // associate for ($i = 0; ($i < cacti_sizeof($selected_items)); $i++) { if (get_request_var('notification_warning_action') > 0) { // clear other settings if (get_request_var('notification_warning_action') == 1) { // set the notification list $ok = db_execute_prepared('UPDATE thold_data SET notify_warning = ? WHERE id = ?', [get_request_var('id'), $selected_items[$i]]) && $ok; // clear other items $ok = db_execute_prepared("UPDATE thold_data SET notify_warning_extra = '' WHERE id = ?", [$selected_items[$i]]) && $ok; } else { // set the notification list $ok = db_execute_prepared('UPDATE thold_data SET notify_warning = ? WHERE id = ?', [get_request_var('id'), $selected_items[$i]]) && $ok; } } if (get_request_var('notification_alert_action') > 0) { // clear other settings if (get_request_var('notification_alert_action') == 1) { // set the notification list $ok = db_execute_prepared('UPDATE thold_data SET notify_alert = ? WHERE id = ?', [get_request_var('id'), $selected_items[$i]]) && $ok; // clear other items $ok = db_execute_prepared("UPDATE thold_data SET notify_extra = '' WHERE id = ?", [$selected_items[$i]]) && $ok; $ok = db_execute_prepared('DELETE FROM plugin_thold_threshold_contact WHERE thold_id = ?', [$selected_items[$i]]) && $ok; } else { // set the notification list $ok = db_execute_prepared('UPDATE thold_data SET notify_alert = ? WHERE id = ?', [get_request_var('id'), $selected_items[$i]]) && $ok; } } if (!$ok) { break; } } } elseif (get_request_var('drp_action') == '2') { // disassociate for ($i = 0; ($i < cacti_sizeof($selected_items)); $i++) { if (get_request_var('notification_warning_action') > 0) { // set the notification list $ok = db_execute_prepared('UPDATE thold_data SET notify_warning = 0 WHERE id = ? AND notify_warning = ?', [$selected_items[$i], get_request_var('id')]) && $ok; } if (get_request_var('notification_alert_action') > 0) { // set the notification list $ok = db_execute_prepared('UPDATE thold_data SET notify_alert = 0 WHERE id = ? AND notify_alert = ?', [$selected_items[$i], get_request_var('id')]) && $ok; } if (!$ok) { break; } } } if ($ok) { db_execute('COMMIT'); } else { db_execute('ROLLBACK'); } } header('Location: notify_lists.php?header=false&action=edit&tab=tholds&id=' . get_request_var('id')); exit; } else { api_plugin_hook_function('notify_list_save', $_POST); header('Location: notify_lists.php?header=false&action=edit&tab=tholds&id=' . get_request_var('id')); exit; } } // setup some variables $list = ''; $array = []; $list_name = ''; if (isset_request_var('id')) { $list_name = db_fetch_cell_prepared('SELECT name FROM plugin_notification_lists WHERE id = ?', [get_filter_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]); // ==================================================== $name = db_fetch_cell_prepared('SELECT name FROM plugin_notification_lists WHERE id = ?', [$matches[1]]); $list .= '
  • ' . html_escape($name) . '
  • '; $array[] = $matches[1]; } } top_header(); form_start('notify_lists.php'); html_start_box($actions[get_request_var('drp_action')] . ' ' . html_escape($list_name) , '80%', false, '3', 'center', ''); if (cacti_sizeof($array)) { if (get_request_var('drp_action') == '1') { // delete print "

    " . __('Click \'Continue\' to Delete Notification Lists(s). Any Device(s) or Threshold(s) associated with the List(s) will be reverted to the default.', 'thold') . "

    "; $save_html = " "; } elseif (get_request_var('drp_action') == '2') { // duplicate print "

    " . __('Click \'Continue\' to Duplicate the following Notification List(s).', 'thold') . "

    " . __('New List Name') . '
    '; form_text_box('name', __('New Notification List'), '', '255', '40', 'text'); print '

    '; $save_html = " "; } } else { raise_message(40); header('Location: notify_lists.php?action=edit&header=false&id=' . get_request_var('id') . '&tab=' . get_request_var('tab')); exit; } print " $save_html "; html_end_box(); form_end(); bottom_footer(); } elseif (isset_request_var('save_templates')) { // 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]); // ==================================================== $name = db_fetch_cell_prepared('SELECT name FROM thold_template WHERE id = ?', [$matches[1]]); $list .= '
  • ' . html_escape($name) . '
  • '; $array[] = $matches[1]; } } top_header(); form_start('notify_lists.php'); html_start_box(__('%s Threshold Template(s)', $assoc_actions[get_request_var('drp_action')], 'thold'), '80%', false, '3', 'center', ''); if (cacti_sizeof($array)) { if (get_request_var('drp_action') == '1') { // associate print "

    " . __esc('Click \'Continue\' to Association the Notification List \'%s\' with the Threshold Template(s) below.', $list_name, 'thold') . "

    " . __('Warning Membership:', 'thold') . '
    '; form_dropdown('notification_warning_action', [0 => __('No Change', 'thold'), 1 => __('Notification List Only', 'thold'), 2 => __('Notification List, Retain Other Settings', 'thold')], '', '', 1, '', ''); print '

    ' . __('Alert Membership:', 'thold') . '
    '; form_dropdown('notification_alert_action', [0 => __('No Change', 'thold'), 1 => __('Notification List Only', 'thold'), 2 => __('Notification List, Retain Other Settings', 'thold')], '', '', 1, '', ''); print '

    '; $save_html = " "; } elseif (get_request_var('drp_action') == '2') { // disassociate print "

    " . __esc('Click \'Continue\' to Disassociate the Notification List \'%s\' from the Thresholds Template(s) below.', $list_name, 'thold') . "

    " . __('Warning Membership:', 'thold') . '
    '; form_dropdown('notification_warning_action', [0 => __('No Change', 'thold'), 1 => __('Remove List', 'thold')], '', '', 1, '', ''); print '

    ' . __('Alert Membership:', 'thold') . '
    '; form_dropdown('notification_alert_action', [0 => __('No Change', 'thold'), 1 => __('Remove List', 'thold')], '', '', 1, '', ''); print '

    '; $save_html = " "; } } else { raise_message(40); header('Location: notify_lists.php?action=edit&header=false&id=' . get_request_var('id') . '&tab=' . get_request_var('tab')); exit; } print " $save_html "; html_end_box(); form_end(); bottom_footer(); } elseif (isset_request_var('save_tholds')) { // 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]); // ==================================================== $name = db_fetch_cell_prepared('SELECT name_cache FROM thold_data WHERE id = ?', [$matches[1]]); $list .= '
  • ' . html_escape($name) . '
  • '; $array[] = $matches[1]; } } top_header(); form_start('notify_lists.php'); html_start_box(__('%s Threshold(s)', $assoc_actions[get_request_var('drp_action')], 'thold'), '80%', false, '3', 'center', ''); if (cacti_sizeof($array)) { if (get_request_var('drp_action') == '1') { // associate print "

    " . __esc('Click \'Continue\' to Associate the Notification List \'%s\' with the Threshold(s) below.', $list_name, 'thold') . "

    " . __('Warning Membership:', 'thold') . '
    '; form_dropdown('notification_warning_action', [0 => __('No Change', 'thold'), 1 => __('Notification List Only', 'thold'), 2 => __('Notification List, Retain Other Settings', 'thold')], '', '', 1, '', ''); print '

    ' . __('Alert Membership:', 'thold') . '
    '; form_dropdown('notification_alert_action', [0 => __('No Change', 'thold'), 1 => __('Notification List Only', 'thold'), 2 => __('Notification List, Retain Other Settings', 'thold')], '', '', 1, '', ''); print '

    '; $save_html = " "; } elseif (get_request_var('drp_action') == '2') { // disassociate print "

    " . __esc('Click \'Continue\' to Disassociate the Notification List \'%s\' from the Thresholds(s) below.', $list_name, 'thold') . "

    " . __('Warning Membership:', 'thold') . '
    '; form_dropdown('notification_warning_action', [0 => __('No Change', 'thold'), 1 => __('Remove List', 'thold')], '', '', 1, '', ''); print '

    ' . __('Alert Membership:', 'thold') . '
    '; form_dropdown('notification_alert_action', [0 => __('No Change', 'thold'), 1 => __('Remove List', 'thold')], '', '', 1, '', ''); print '

    '; $save_html = " "; } } else { raise_message(40); header('Location: notify_lists.php?action=edit&header=false&id=' . get_request_var('id') . '&tab=' . get_request_var('tab')); exit; } print " $save_html "; html_end_box(); form_end(); bottom_footer(); } elseif (isset_request_var('save_associate')) { // 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]); // ==================================================== $name = db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', [$matches[1]]); $list .= '
  • ' . html_escape($name) . '
  • '; $array[] = $matches[1]; } } top_header(); form_start('notify_lists.php'); html_start_box($assoc_actions[get_request_var('drp_action')] . ' Device(s)', '80%', false, '3', 'center', ''); if (cacti_sizeof($array)) { if (get_request_var('drp_action') == '1') { // associate print "

    " . __esc('Click \'Continue\' to Associate the Notification List \'%s\' with the Device(s) below.', $list_name, 'thold') . '

    ' . __('You may also Associate the Devices Thresholds as well. However, these Device Thresholds will allow the Threshold Notification List to be overwritten.', 'thold') . "

    " . __('Resulting Membership:', 'thold') . '
    '; form_dropdown('notification_action', [2 => __('Notification List Only', 'thold'), 3 => __('Notification and Global Lists', 'thold')], '', '', 2, '', ''); print '

    ' . __('Device Threshold Warning Membership:', 'thold') . '
    '; form_dropdown('notification_warning_action', [0 => __('No Change', 'thold'), 1 => __('Notification List Only', 'thold'), 2 => __('Notification List, Retain Other Settings', 'thold')], '', '', 1, '', ''); print '

    ' . __('Device Threshold Alert Membership:', 'thold') . '
    '; form_dropdown('notification_alert_action', [0 => __('No Change', 'thold'), 1 => __('Notification List Only', 'thold'), 2 => __('Notification List, Retain Other Settings', 'thold')], '', '', 1, '', ''); print '

    '; $save_html = " "; } elseif (get_request_var('drp_action') == '2') { // disassociate print "

    " . __esc('Click \'Continue\' to Disassociate the Notification List \'%s\' from the Device(s) below.', $list_name, 'thold') . '

    ' . __('You may also Disassociate the Devices Thresholds as well. However, these Device Thresholds will allow the Threshold Notification List to be overwritten.', 'thold') . "

    " . __('Resulting Membership:', 'thold') . '
    '; form_dropdown('notification_action', [1 => __('Global List', 'thold'), 0 => __('Disabled', 'thold')], '', '', 1, '', ''); print '

    ' . __('Device Threshold Warning Membership:', 'thold') . '
    '; form_dropdown('notification_warning_action', [0 => __('No Change', 'thold'), 1 => __('Remove List', 'thold')], '', '', 1, '', ''); print '

    ' . __('Device Threshold Alert Membership:', 'thold') . '
    '; form_dropdown('notification_alert_action', [0 => __('No Change', 'thold'), 1 => __('Remove List', 'thold')], '', '', 1, '', ''); print '

    '; $save_html = " "; } } else { raise_message(40); header('Location: notify_lists.php?action=edit&header=false&id=' . get_request_var('id') . '&tab=' . get_request_var('tab')); exit; } print " $save_html "; html_end_box(); form_end(); bottom_footer(); } else { $save = ['post' => $_POST, 'selected_items' => isset($selected_items) ? $selected_items : '']; api_plugin_hook_function('notify_list_form_confirm', $save); } } /* ---------------------------- Notification List Edit ---------------------------- */ /** * Builds the "[edit: name]" or "[new]" header suffix label for the * notification list edit page, based on whether an existing list id * request variable is present. * * @return string The escaped header label suffix. */ function get_notification_header_label() { if (!isempty_request_var('id')) { $list = db_fetch_row_prepared('SELECT * FROM plugin_notification_lists WHERE id = ?', [get_filter_request_var('id')]); $header_label = __esc('[edit: %s]', $list['name'], 'thold'); } else { $header_label = __('[new]', 'thold'); } return $header_label; } /** * Renders the tabbed add/edit page for a notification list: displays * the tab bar (General, Devices, Thresholds, Templates) when editing * an existing list, then renders the currently selected tab's content * (the general settings form on the 'general' tab, or delegates to * hosts()/tholds()/templates() for the association tabs). Called from * this script's main request-dispatch switch when action=edit. * * @return void * * @global array $tabs_thold Map of tab short-name => display label, * used to render the tab bar. * @global array $config Cacti global configuration array; used to * build tab URLs. */ function edit() { global $tabs_thold, $config; // ================= input validation ================= get_filter_request_var('id'); get_filter_request_var('tab', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^([a-zA-Z]+)$/']]); // ==================================================== // set the default tab load_current_session_value('tab', 'sess_thold_notify_tab', 'general'); $current_tab = get_request_var('tab'); if (cacti_sizeof($tabs_thold) && isset_request_var('id')) { print "
    '; } $header_label = get_notification_header_label(); $formats = reports_get_format_files(); if (isset_request_var('id')) { $list = db_fetch_row_prepared('SELECT * FROM plugin_notification_lists WHERE id = ?', [get_request_var('id')]); } else { $list = []; $current_tab = 'general'; } if ($current_tab == 'general') { form_start('notify_lists.php'); html_start_box(__('List General Settings', 'thold') . ' ' . html_escape($header_label), '100%', false, '3', 'center', ''); $fields_notification = [ 'name' => [ 'method' => 'textbox', 'friendly_name' => __('Name', 'thold'), 'description' => __('Enter a name for this Notification List.', 'thold'), 'value' => '|arg1:name|', 'max_length' => '80' ], 'description' => [ 'method' => 'textarea', 'friendly_name' => __('Description', 'thold'), 'description' => __('Enter a description for this Notification List.', 'thold'), 'value' => '|arg1:description|', 'class' => 'textAreaNotes', 'textarea_rows' => '2', 'textarea_cols' => '80' ], 'enabled' => [ 'method' => 'checkbox', 'friendly_name' => __('Enabled'), 'description' => __('To disable all notifications from this Notification List, you can simply disable it here.', 'thold'), 'default' => '', 'value' => '|arg1:enabled|' ], 'emails' => [ 'method' => 'textarea', 'friendly_name' => __('To Email Addresses', 'thold'), 'description' => __('Enter a comma separated list of Email addresses for this Notification List.', 'thold'), 'value' => '|arg1:emails|', 'class' => 'textAreaNotes', 'textarea_rows' => '4', 'textarea_cols' => '80' ], 'bcc_emails' => [ 'method' => 'textarea', 'friendly_name' => __('BCC Email Addresses', 'thold'), 'description' => __('Enter a comma separated list of Email addresses for this Notification List to be blind copied.', 'thold'), 'value' => '|arg1:bcc_emails|', 'class' => 'textAreaNotes', 'textarea_rows' => '4', 'textarea_cols' => '80' ], 'format_file' => [ 'friendly_name' => __('Email Style/Format File', 'thold'), 'method' => 'drop_array', 'default' => 'default.format', 'description' => __('Choose the custom html wrapper and CSS file to use. This file contains both html and CSS to wrap around your report. If it contains more than simply CSS, you need to place a special tag inside of the file. This format tag will be replaced by the report content. These files are located in the \'formats\' directory.', 'thold'), 'value' => '|arg1:format_file|', 'array' => $formats ], 'id' => [ 'method' => 'hidden_zero', 'value' => '|arg1:id|' ], 'save_component' => [ 'method' => 'hidden', 'value' => '1' ] ]; draw_edit_form( [ 'config' => [], 'fields' => inject_form_variables($fields_notification, (isset($list) ? $list : [])) ] ); html_end_box(); form_save_button('notify_lists.php', 'return'); } elseif ($current_tab == 'hosts') { hosts($header_label); } elseif ($current_tab == 'tholds') { tholds($header_label); } elseif ($current_tab == 'templates') { templates($header_label); } else { $save = [ 'current_tab' => $current_tab, 'header_label' => $header_label ]; api_plugin_hook_function('notify_list_display', $save); } } /** * Renders the notification list's \"Devices\" tab: validates/stores this * tab's filter request variables, displays the device filter form, then * displays a filtered, sorted, paginated table of devices with their * association status to this list and a bulk-actions dropdown to * associate/disassociate them. * * @param string $header_label The \"[edit: name]\"/\"[new]\" header label * suffix to display in the box title. * * @return void * * @global array $assoc_actions Map of drp_action value => action label, * used for the bulk-actions dropdown. * @global array $item_rows Default number of rows per page from * Cacti settings. * @global array $config Cacti global configuration array. */ function hosts($header_label) { global $assoc_actions, $item_rows, $config; // ================= input validation and session storage ================= $filters = [ 'rows' => [ 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ], 'page' => [ 'filter' => FILTER_VALIDATE_INT, 'default' => '1' ], 'site_id' => [ 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ], 'rfilter' => [ 'filter' => FILTER_VALIDATE_IS_REGEX, 'pageset' => true, 'default' => '' ], 'sort_column' => [ 'filter' => FILTER_CALLBACK, 'default' => 'description', 'options' => ['options' => 'sanitize_search_string'] ], 'sort_direction' => [ 'filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => ['options' => 'sanitize_search_string'] ], 'associated' => [ 'filter' => FILTER_CALLBACK, 'default' => 'true', 'options' => ['options' => 'sanitize_search_string'] ], 'host_template_id' => [ 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ] ]; validate_store_request_vars($filters, 'sess_nlh'); // ================= input validation ================= // if the number of rows is -1, set it to the default if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } html_start_box(__('Associated Devices', 'thold') . ' ' . html_escape($header_label), '100%', false, '3', 'center', ''); ?>
    '> > ' title=''> ' title=''>
    1 AND h.thold_host_email = ?)'; $sql_params[] = get_request_var('id'); } $sql_limit = 'LIMIT ' . ($rows * (intval(get_request_var('page')) - 1)) . ',' . $rows; $sql_order = get_order_string(); $total_rows = db_fetch_cell_prepared("SELECT COUNT(h.id) FROM host AS h $sql_where", $sql_params); $host_graphs = array_rekey( db_fetch_assoc('SELECT host_id, COUNT(*) AS graphs FROM graph_local GROUP BY host_id'), 'host_id', 'graphs' ); $host_data_sources = array_rekey( db_fetch_assoc('SELECT host_id, COUNT(*) AS data_sources FROM data_local GROUP BY host_id'), 'host_id', 'data_sources' ); $sql_query = "SELECT h.*, s.name AS site_name FROM host AS h LEFT JOIN sites AS s ON h.site_id = s.id $sql_where $sql_order $sql_limit"; $hosts = db_fetch_assoc_prepared($sql_query, $sql_params); $nav = html_nav_bar('notify_lists.php?action=edit&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Devices', 'thold'), 'page', 'main'); form_start('notify_lists.php', 'chk'); print $nav; html_start_box('', '100%', false, '3', 'center', ''); $display_text = [ 'description' => [ 'display' => __('Description', 'thold'), 'align' => 'left', 'sort' => 'ASC', ], 'site_name' => [ 'display' => __('Site', 'thold'), 'align' => 'left', 'sort' => 'ASC', ], 'h.id' => [ 'display' => __('ID', 'thold'), 'align' => 'left', 'sort' => 'ASC', ], 'h.status' => [ 'display' => __('Status', 'thold'), 'align' => 'left', 'sort' => 'ASC', ], 'nosort0' => [ 'display' => __('Associated Lists', 'thold'), 'align' => 'left', 'sort' => 'ASC', ], 'nosort1' => [ 'display' => __('Graphs', 'thold'), 'align' => 'right', 'sort' => 'DESC', ], 'nosort2' => [ 'display' => __('Data Sources', 'thold'), 'align' => 'right', 'sort' => 'DESC', ], 'h.hostname' => [ 'display' => __('Hostname', 'thold'), 'align' => 'right', 'sort' => 'ASC', ] ]; html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'notify_lists.php?action=edit&id=' . get_filter_request_var('id')); if (cacti_sizeof($hosts)) { foreach ($hosts as $host) { form_alternate_row('line' . $host['id'], true); form_selectable_cell(filter_value($host['description'], get_request_var('rfilter'), $config['url_path'] . 'host.php?action=edit&id=' . $host['id']), $host['id'],250); form_selectable_ecell($host['site_name'] != '' ? $host['site_name'] : __('None', 'thold'), $host['id']); form_selectable_cell($host['id'], $host['id']); form_selectable_cell(get_colored_device_status(($host['disabled'] == 'on' ? true : false), $host['status']), $host['id']); if ($host['thold_send_email'] == 0) { form_selectable_cell('' . __('Disabled', 'thold') . '', $host['id']); } elseif ($host['thold_send_email'] == 1) { form_selectable_cell('' . __('Global List', 'thold') . '', $host['id']); } elseif ($host['thold_host_email'] == get_request_var('id')) { if ($host['thold_send_email'] == 2) { form_selectable_cell('' . __('Current List Only', 'thold') . '', $host['id']); } else { form_selectable_cell('' . __('Current and Global List(s)', 'thold') . '', $host['id']); } } elseif ($host['thold_host_email'] == '0') { form_selectable_cell('' . __('None', 'thold') . '', $host['id']); } else { $name = db_fetch_cell_prepared('SELECT name FROM plugin_notification_lists WHERE id = ?', [get_request_var('id')]); form_selectable_cell('' . html_escape($name) . '', $host['id']); } form_selectable_cell((isset($host_graphs[$host['id']]) ? $host_graphs[$host['id']] : 0), $host['id'], '', 'right'); form_selectable_cell((isset($host_data_sources[$host['id']]) ? $host_data_sources[$host['id']] : 0), $host['id'], '', 'right'); form_selectable_cell(filter_value($host['hostname'], get_request_var('rfilter')), $host['id'], '', 'right'); form_checkbox_cell($host['description'], $host['id']); form_end_row(); } } else { print '' . __('No Associated Devices Found', 'thold') . ''; } html_end_box(); if (cacti_sizeof($hosts)) { print $nav; } form_hidden_box('tab', 'hosts', ''); form_hidden_box('id', get_request_var('id'), ''); form_hidden_box('save_associate', '1', ''); draw_actions_dropdown($assoc_actions); form_end(); } /** * Renders the notification list's \"Thresholds\" tab: validates/stores * this tab's filter request variables, displays the threshold filter * form, then displays a filtered, sorted, paginated table of * thresholds with their association status to this list and a * bulk-actions dropdown to associate/disassociate them. * * @param string $header_label The \"[edit: name]\"/\"[new]\" header label * suffix to display in the box title. * * @return void */ function tholds($header_label) { global $item_rows, $assoc_actions, $config; include($config['base_path'] . '/plugins/thold/includes/arrays.php'); thold_request_validation(); $statefilter = ''; if (isset_request_var('state')) { if (get_request_var('state') == '-1') { $statefilter = ''; } elseif (get_request_var('state') == '0') { $statefilter = "td.thold_enabled = 'off'"; } elseif (get_request_var('state') == '2') { $statefilter = "td.thold_enabled = 'on'"; } elseif (get_request_var('state') == '1') { $statefilter = '(td.thold_alert != 0 OR td.bl_alert > 0)'; } elseif (get_request_var('state') == '3') { $statefilter = '(td.thold_alert != 0 AND td.thold_fail_count >= td.thold_fail_trigger) OR (td.bl_alert > 0 AND td.bl_fail_count >= td.bl_fail_trigger)'; } } // if the number of rows is -1, set it to the default if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } $sql_where = ''; $sort = get_request_var('sort_column') . ' ' . get_request_var('sort_direction'); $limit = ($rows * (intval(get_request_var('page')) - 1)) . ", $rows"; if (!isempty_request_var('template') && get_request_var('template') != '-1') { $sql_where .= ($sql_where == '' ? '' : ' AND ') . 'td.data_template_id = ' . get_request_var('template'); } if (get_request_var('site_id') == '-1') { // Show all items } elseif (get_request_var('site_id') == '0') { $sql_where .= ($sql_where == '' ? '' : ' AND ') . ' h.site_id=0'; } elseif (!isempty_request_var('site_id')) { $sql_where .= ($sql_where == '' ? '' : ' AND ') . ' h.site_id=' . get_request_var('site_id'); } if (strlen(get_request_var('rfilter'))) { // rfilter is pre-validated as a legal PHP regex by FILTER_VALIDATE_IS_REGEX in the // request validation array; db_qstr() SQL-escapes the already-validated value. $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . 'td.name_cache ' . thold_rlike_clause(get_request_var('rfilter')); } if ($statefilter != '') { $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . $statefilter; } if (get_request_var('associated') == 'true') { $sql_where .= (!strlen($sql_where) ? '' : ' AND ') . '(td.notify_warning=' . get_request_var('id') . ' OR td.notify_alert=' . get_request_var('id') . ')'; } $result = get_allowed_thresholds($sql_where, $sort, $limit, $total_rows); $data_templates = db_fetch_assoc('SELECT DISTINCT dt.id, dt.name FROM data_template AS dt INNER JOIN thold_data AS td ON td.data_template_id = dt.id ORDER BY dt.name'); html_start_box(__('Associated Thresholds', 'thold') . ' ' . html_escape($header_label) , '100%', false, '3', 'center', ''); ?>
    '> > ' title=''> ' title=''>
    [ 'display' => __('Name', 'thold'), 'sort' => 'ASC' ], 'id' => [ 'display' => __('ID', 'thold'), 'sort' => 'ASC' ], 'nosort1' => [ 'display' => __('Warning Lists', 'thold'), 'sort' => 'ASC' ], 'nosort2' => [ 'display' => __('Alert Lists', 'thold'), 'sort' => 'ASC' ], 'thold_type' => [ 'display' => __('Type', 'thold'), 'sort' => 'ASC' ], 'thold_alert' => [ 'display' => __('Triggered', 'thold'), 'sort' => 'ASC' ], 'nosort3' => [ 'display' => __('Templated', 'thold'), 'sort' => 'ASC' ], 'thold_enabled' => [ 'display' => __('Enabled', 'thold'), 'sort' => 'ASC' ] ]; html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'notify_lists.php?action=edit&tab=tholds&id=' . get_filter_request_var('id')); $c = 0; if (cacti_sizeof($result)) { foreach ($result as $row) { $c++; $alertstat = __('No', 'thold'); if ($row['thold_type'] != 1) { if ($row['thold_alert'] != 0) { $alertstat = __('Yes', 'thold'); } } else { if ($row['bl_alert'] == 1) { $alertstat = __('baseline-LOW', 'thold'); } elseif ($row['bl_alert'] == 2) { $alertstat = __('baseline-HIGH', 'thold'); } } // show alert stats first $alert_stat = ''; $list = db_fetch_cell_prepared('SELECT count(*) FROM plugin_thold_threshold_contact WHERE thold_id = ?', [$row['id']]); if ($list > 0) { $alert_stat = "" . __('Select Users', 'thold') . ''; } if (strlen($row['notify_extra'])) { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "" . __('Specific Emails', 'thold') . ''; } if (!empty($row['notify_alert'])) { if (get_request_var('id') == $row['notify_alert']) { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "" . __('Current List', 'thold') . ''; } else { $alert_info = db_fetch_cell_prepared('SELECT name FROM plugin_notification_lists WHERE id = ?', [$row['notify_alert']]); if ($alert_info != '') { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "" . html_escape($alert_info) . ''; } else { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "" . __('Unknown Threshold', 'thold') . ''; } } } if (!strlen($alert_stat)) { $alert_stat = "" . __('Log Only', 'thold') . ''; } // show warning stats first $warn_stat = ''; if (strlen($row['notify_warning_extra'])) { $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "" . __('Specific Emails', 'thold') . ''; } if (!empty($row['notify_warning'])) { if (get_request_var('id') == $row['notify_warning']) { $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "" . __('Current List', 'thold') . ''; } else { $warn_list = db_fetch_cell_prepared('SELECT name FROM plugin_notification_lists WHERE id = ?', [$row['notify_warning']]); $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "" . html_escape($warn_list) . ''; } } if ((!strlen($warn_stat)) && (($row['thold_type'] == 0 && $row['thold_warning_hi'] == '' && $row['thold_warning_low'] == '') || ($row['thold_type'] == 2 && $row['time_warning_hi'] == '' && $row['time_warning_low'] == ''))) { $warn_stat = "" . __('None', 'thold') . ''; } elseif (!strlen($warn_stat)) { $warn_stat = "" . __('Log Only', 'thold') . ''; } if ($row['template_enabled'] == 'on') { $templated = db_fetch_cell_prepared('SELECT notify_templated FROM thold_template WHERE id = ?', [$row['thold_template_id']]); if ($templated == 'on') { $disabled = true; } else { $disabled = false; } } else { $disabled = false; } form_alternate_row('line' . $row['id'], true, $disabled); form_selectable_cell(filter_value($row['name_cache'], get_request_var('rfilter')), $row['id']); form_selectable_cell($row['id'], $row['id']); form_selectable_cell($warn_stat, $row['id']); form_selectable_cell($alert_stat, $row['id']); form_selectable_cell($thold_types[$row['thold_type']], $row['id']); form_selectable_cell($alertstat, $row['id']); form_selectable_cell($disabled ? __('Read Only', 'thold') : __('Editable', 'thold'), $row['id']); form_selectable_cell((($row['thold_enabled'] == 'off') ? __('Disabled', 'thold') : __('Enabled', 'thold')), $row['id']); form_checkbox_cell($row['name'], $row['id'], $disabled); form_end_row(); } } else { print "" . __('No Thresholds Found', 'thold') . ''; } html_end_box(false); if (cacti_sizeof($result)) { print $nav; } form_hidden_box('tab', 'tholds', ''); form_hidden_box('id', get_request_var('id'), ''); form_hidden_box('save_tholds', '1', ''); draw_actions_dropdown($assoc_actions); form_end(); } /** * Renders the notification list's \"Templates\" tab: validates/stores * this tab's filter request variables, displays the template filter * form, then displays a filtered, sorted, paginated table of threshold * templates with their association status to this list and a * bulk-actions dropdown to associate/disassociate them. * * @param string $header_label The \"[edit: name]\"/\"[new]\" header label * suffix to display in the box title. * * @return void */ function templates($header_label) { global $config, $item_rows, $assoc_actions; include($config['base_path'] . '/plugins/thold/includes/arrays.php'); thold_template_request_validation(); // if the number of rows is -1, set it to the default if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } $sql_where = ''; $sql_order = get_order_string(); $sql_limit = ' LIMIT ' . ($rows * (intval(get_request_var('page')) - 1)) . ',' . $rows; if (get_request_var('associated') == 'true') { $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . '(notify_warning=' . get_request_var('id') . ' OR notify_alert=' . get_request_var('id') . ')'; } if (strlen(get_request_var('rfilter'))) { // rfilter is pre-validated as a legal PHP regex by FILTER_VALIDATE_IS_REGEX in the // request validation array; db_qstr() SQL-escapes the already-validated value. $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . 'thold_template.name ' . thold_rlike_clause(get_request_var('rfilter')); } $sql = "SELECT * FROM thold_template $sql_where $sql_order $sql_limit"; $result = db_fetch_assoc($sql); html_start_box(__('Associated Templates', 'thold') . ' ' . html_escape($header_label), '100%', false, '3', 'center', ''); ?>
    '> > ' title=''> ' title=''>
    [__('Name', 'thold'), 'ASC'], 'id' => [__('ID', 'thold'), 'ASC'], 'nosort1' => [__('Warning Lists', 'thold'), 'ASC'], 'nosort2' => [__('Alert Lists', 'thold'), 'ASC'], 'thold_type' => [__('Type', 'thold'), 'ASC']]; html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'notify_lists.php?action=edit&tab=templates&id=' . get_filter_request_var('id')); $c = 0; if (cacti_sizeof($result)) { foreach ($result as $row) { $c++; // show alert stats first $alert_stat = ''; $list = db_fetch_cell_prepared('SELECT COUNT(*) FROM plugin_thold_template_contact WHERE template_id = ?', [$row['id']]); if ($list > 0) { $alert_stat = "" . __('Select Users', 'thold') . ''; } if (strlen($row['notify_extra'])) { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "" . __('Specific Emails', 'thold') . ''; } if (!empty($row['notify_alert'])) { if (get_request_var('id') == $row['notify_alert']) { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "" . __('Current List', 'thold') . ''; } else { $alert_info = db_fetch_cell_prepared('SELECT name FROM plugin_notification_lists WHERE id = ?', [$row['notify_alert']]); if ($alert_info != '') { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "" . html_escape($alert_info) . ''; } else { $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "" . __('Unknown Template', 'thold') . ''; } } } if (!strlen($alert_stat)) { $alert_stat = "" . __('Log Only', 'thold') . ''; } // show warning stats first $warn_stat = ''; if (strlen($row['notify_warning_extra'])) { $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "" . __('Specific Emails', 'thold') . ''; } if (!empty($row['notify_warning'])) { if (get_request_var('id') == $row['notify_warning']) { $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "" . __('Current List', 'thold') . ''; } else { $warn_list = db_fetch_cell_prepared('SELECT name FROM plugin_notification_lists WHERE id = ?', [$row['notify_warning']]); $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "" . html_escape($warn_list) . ''; } } if ((!strlen($warn_stat)) && (($row['thold_type'] == 0 && $row['thold_warning_hi'] == '' && $row['thold_warning_low'] == '') || ($row['thold_type'] == 2 && $row['time_warning_hi'] == '' && $row['time_warning_low'] == ''))) { $warn_stat = "" . __('None', 'thold') . ''; } elseif (!strlen($warn_stat)) { $warn_stat = "" . __('Log Only', 'thold') . ''; } form_alternate_row('line' . $row['id'], true); form_selectable_cell(filter_value($row['name'], get_request_var('rfilter')), $row['id']); form_selectable_cell($row['id'], $row['id']); form_selectable_cell($warn_stat, $row['id']); form_selectable_cell($alert_stat, $row['id']); form_selectable_cell($thold_types[$row['thold_type']], $row['id']); form_checkbox_cell($row['name'], $row['id']); form_end_row(); } } else { print "" . __('No Threshold Templates', 'thold') . ''; } html_end_box(false); if (cacti_sizeof($result)) { print $nav; } form_hidden_box('tab', 'templates', ''); form_hidden_box('id', get_request_var('id'), ''); form_hidden_box('save_templates', '1', ''); draw_actions_dropdown($assoc_actions); form_end(); } /** * Validates and stores the threshold-templates-tab filter request * variables (rows, page, filter text, sort column/direction, * associated flag) into the session for the notification list's * Templates tab. * * @return void */ function thold_template_request_validation() { // ================= input validation and session storage ================= $filters = [ 'rows' => [ 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ], 'page' => [ 'filter' => FILTER_VALIDATE_INT, 'default' => '1' ], 'rfilter' => [ 'filter' => FILTER_VALIDATE_IS_REGEX, 'pageset' => true, 'default' => '' ], 'sort_column' => [ 'filter' => FILTER_CALLBACK, 'default' => 'name', 'options' => ['options' => 'sanitize_search_string'] ], 'sort_direction' => [ 'filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => ['options' => 'sanitize_search_string'] ], 'associated' => [ 'filter' => FILTER_CALLBACK, 'default' => 'true', 'options' => ['options' => 'sanitize_search_string'] ] ]; validate_store_request_vars($filters, 'sess_nltt'); // ================= input validation ================= } /** * Validates and stores the thresholds-tab filter request variables * (rows, page, filter text, sort column/direction, associated flag) * into the session for the notification list's Thresholds tab. * * @return void */ function thold_request_validation() { // ================= input validation and session storage ================= $filters = [ 'rows' => [ 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ], 'page' => [ 'filter' => FILTER_VALIDATE_INT, 'default' => '1' ], 'site_id' => [ 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ], 'rfilter' => [ 'filter' => FILTER_VALIDATE_IS_REGEX, 'pageset' => true, 'default' => '' ], 'sort_column' => [ 'filter' => FILTER_CALLBACK, 'default' => 'thold_alert', 'options' => ['options' => 'sanitize_search_string'] ], 'sort_direction' => [ 'filter' => FILTER_CALLBACK, 'default' => 'DESC', 'options' => ['options' => 'sanitize_search_string'] ], 'state' => [ 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1', ], 'template' => [ 'filter' => FILTER_VALIDATE_INT, 'default' => '', ], 'associated' => [ 'filter' => FILTER_CALLBACK, 'default' => 'true', 'options' => ['options' => 'sanitize_search_string'] ] ]; validate_store_request_vars($filters, 'sess_nlt'); // ================= input validation ================= } /** * Renders the main notification lists list page: validates/stores this * view's filter request variables, then displays a filtered, sorted, * paginated table of notification lists with a bulk-actions dropdown. * Called from this script's main request-dispatch switch as the * default view. * * @return void * * @global array $actions Map of drp_action value => action label, * used for the bulk-actions dropdown. * @global array $item_rows Default number of rows per page from Cacti * settings. */ function lists() { global $actions, $item_rows; // ================= input validation and session storage ================= $filters = [ 'rows' => [ 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ], 'page' => [ 'filter' => FILTER_VALIDATE_INT, 'default' => '1' ], 'rfilter' => [ 'filter' => FILTER_VALIDATE_IS_REGEX, 'pageset' => true, 'default' => '' ], 'sort_column' => [ 'filter' => FILTER_CALLBACK, 'default' => 'description', 'options' => ['options' => 'sanitize_search_string'] ], 'sort_direction' => [ 'filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => ['options' => 'sanitize_search_string'] ] ]; validate_store_request_vars($filters, 'sess_lists'); // ================= input validation ================= // if the number of rows is -1, set it to the default if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } html_start_box(__('Notification Lists', 'thold'), '100%', false, '3', 'center', 'notify_lists.php?action=edit'); ?>
    '> ' title=''> ' title=''>
    [__('List Name', 'thold'), 'ASC'], 'enabled' => [__('Enabled', 'thold'), 'ASC'], 'nosort1' => [__('Devices', 'thold'), ''], 'nosort2' => [__('Thresholds', 'thold'), ''], 'nosort3' => [__('Templates', 'thold'), ''], 'description' => [__('Description', 'thold'), 'ASC'], 'emails' => [__('Emails', 'thold'), 'ASC']]; html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); if (cacti_sizeof($lists)) { foreach ($lists as $item) { // Add wrappable characters to emails $item['emails'] = implode(', ', explode(',', $item['emails'])); form_alternate_row('line' . $item['id'], true); form_selectable_cell(filter_value($item['name'], get_request_var('rfilter'), 'notify_lists.php?action=edit&id=' . $item['id']), $item['id']); form_selectable_cell($item['enabled'] == 'on' ? __('Yes', 'thold') : __('No', 'thold'), $item['id'], '', 'white-space:pre-wrap'); form_selectable_cell(filter_value($item['hosts'], get_request_var('rfilter'), 'notify_lists.php?tab=hosts&action=edit&id=' . $item['id']), $item['id']); form_selectable_cell(filter_value('Warn: ' . $item['thold_warnings'] . ', Alert: ' . $item['thold_alerts'] , get_request_var('rfilter'), 'notify_lists.php?tab=tholds&action=edit&id=' . $item['id']), $item['id']); form_selectable_cell(filter_value('Warn: ' . $item['template_warnings'] . ', Alert: ' . $item['template_alerts'] , get_request_var('rfilter'), 'notify_lists.php?tab=templates&action=edit&id=' . $item['id']), $item['id']); form_selectable_cell(filter_value($item['description'], get_request_var('rfilter')), $item['id'], '', 'wrap'); form_selectable_cell(filter_value($item['emails'], get_request_var('rfilter')), $item['id'], '', 'white-space:pre-wrap'); form_checkbox_cell($item['name'], $item['id']); form_end_row(); } } else { print '' . __('No Notification Lists', 'thold') . ''; } html_end_box(false); if (cacti_sizeof($lists)) { print $nav; } form_hidden_box('save_list', '1', ''); // draw the dropdown containing a list of available actions for this form draw_actions_dropdown($actions); form_end(); }