'Device sysContact', 'contact_method' => 'syscontact', 'contact_endpoint' => '{"syscontact":"device"}', //'contact_disabled' => '0', //'contact_disabled_until' => NULL, //'contact_message_custom' => 0, //'contact_message_template' => NULL ]; dbInsert($syscontact, 'alert_contacts'); } if (!$readonly && isset($vars['action']) && request_token_valid($vars['requesttoken'])) { switch ($vars['action']) { case 'edit_syslog_rule': $update_array = array('la_name' => $vars['la_name'], 'la_descr' => $vars['la_descr'], 'la_rule' => $vars['la_rule'], 'la_disable' => (isset($vars['la_disable']) ? 1 : 0)); $rows_updated = dbUpdate($update_array, 'syslog_rules', '`la_id` = ?', array($vars['la_id'])); if ($rows_updated) { set_obs_attrib('syslog_rules_changed', time()); // Trigger reload syslog script print_message('Syslog Rule updated ('.$vars['la_id'].')'); } unset($vars['la_id']); break; case 'delete_syslog_rule': if (get_var_true($vars['confirm'], 'confirm')) { $rows_deleted = dbDelete('syslog_rules_assoc', '`la_id` = ?', array($vars['la_id'])); $rows_deleted += dbDelete('syslog_rules', '`la_id` = ?', array($vars['la_id'])); $rows_deleted += dbDelete('syslog_alerts', '`la_id` = ?', array($vars['la_id'])); $rows_deleted += dbDelete('alert_contacts_assoc', '`aca_type` = ? AND `alert_checker_id` = ?', array('syslog', $vars['la_id'])); if ($rows_deleted) { set_obs_attrib('syslog_rules_changed', time()); // Trigger reload syslog script print_message('Deleted all traces of Syslog Rule ('.$vars['la_id'].')'); } } unset($vars['la_id']); break; } } // End Actions print_syslog_rules_table($vars); function print_syslog_rules_table($vars) { if (isset($vars['la_id'])) { $las = dbFetchRows("SELECT * FROM `syslog_rules` WHERE `la_id` = ?", array($vars['la_id'])); } else { $las = dbFetchRows("SELECT * FROM `syslog_rules` ORDER BY `la_name`"); } if (is_array($las) && count($las)) { $modals = ''; $string = generate_box_open(); $string .= '' . PHP_EOL; $cols = array( array(NULL, 'class="state-marker"'), 'name' => array('Name', 'style="width: 160px;"'), 'descr' => array('Description', 'style="width: 400px;"'), 'rule' => 'Rule', 'severity' => array('Severity', 'style="width: 60px;"'), 'disabled' => array('Status', 'style="width: 60px;"'), 'controls' => array('', 'style="width: 60px;"'), ); $string .= get_table_header($cols, $vars); foreach($las as $la) { if ($la['disable'] == 0) { $la['html_row_class'] = "up"; } else { $la['html_row_class'] = "disabled"; } $string .= ''; $string .= ''; $string .= ' ' . PHP_EOL; $string .= ' ' . PHP_EOL; $string .= ' ' . PHP_EOL; $string .= ' ' . PHP_EOL; $string .= ' ' . PHP_EOL; $string .= ' '; $string .= ' ' . PHP_EOL; // Delete Rule Modal $modal_args = array( 'id' => 'modal-delete_syslog_rule_' . $la['la_id'], 'title' => 'Delete Syslog Rule "'.escape_html($la['la_descr']).'"', //'hide' => TRUE, //'fade' => TRUE, //'role' => 'dialog', //'class' => 'modal-md', ); $form = array('type' => 'horizontal', 'id' => 'delete_syslog_rule_' . $la['la_id'], 'userlevel' => 10, // Minimum user level for display form 'modal_args' => $modal_args, // !!! This generate modal specific form //'help' => 'This will completely delete the rule and all associations and history.', 'class' => '', // Clean default box class! 'url' => generate_url(array('page' => 'syslog_rules')) ); $form['fieldset']['body'] = array('class' => 'modal-body'); // Required this class for modal body! $form['fieldset']['footer'] = array('class' => 'modal-footer'); // Required this class for modal footer! $form['row'][0]['la_id'] = array( 'type' => 'hidden', 'fieldset' => 'body', 'value' => $la['la_id']); $form['row'][0]['action'] = array( 'type' => 'hidden', 'fieldset' => 'body', 'value' => 'delete_syslog_rule'); $form['row'][5]['confirm'] = array( 'type' => 'checkbox', 'fieldset' => 'body', 'name' => 'Confirm', 'placeholder' => 'Yes, please delete this rule.', 'onchange' => "javascript: toggleAttrib('disabled', 'delete_button_".$la['la_id']."'); showDiv(!this.checked, 'warning_".$la['la_id']."_div');", 'value' => 'confirm'); $form['row'][6]['warning_'.$la['la_id']] = array( 'type' => 'html', 'fieldset' => 'body', 'html' => '

Warning!

' . ' This rule and all history will be completely deleted!', 'div_class' => 'alert alert-warning', 'div_style' => 'display:none;'); $form['row'][8]['close'] = array( 'type' => 'submit', 'fieldset' => 'footer', 'div_class' => '', // Clean default form-action class! 'name' => 'Close', 'icon' => '', 'attribs' => array('data-dismiss' => 'modal', 'aria-hidden' => 'true')); $form['row'][9]['delete_button_'.$la['la_id']] = array( 'type' => 'submit', 'fieldset' => 'footer', 'div_class' => '', // Clean default form-action class! 'name' => 'Delete Rule', 'icon' => 'icon-trash icon-white', //'right' => TRUE, 'class' => 'btn-danger', 'disabled' => TRUE, 'value' => 'delete_syslog_rule'); $modals .= generate_form_modal($form); unset($form); // Edit Rule Modal $modal_args = array( 'id' => 'modal-edit_syslog_rule_' . $la['la_id'], 'title' => 'Edit Syslog Rule "'.escape_html($la['la_descr']).'"', //'hide' => TRUE, //'fade' => TRUE, //'role' => 'dialog', 'class' => 'modal-lg', ); $form = array('type' => 'horizontal', 'id' => 'edit_syslog_rule_' . $la['la_id'], 'userlevel' => 10, // Minimum user level for display form 'modal_args' => $modal_args, // !!! This generate modal specific form //'help' => 'This will completely delete the rule and all associations and history.', 'class' => '', // Clean default box class! 'url' => generate_url(array('page' => 'syslog_rules')) ); $form['fieldset']['body'] = array('class' => 'modal-body'); // Required this class for modal body! $form['fieldset']['footer'] = array('class' => 'modal-footer'); // Required this class for modal footer! $form['row'][0]['la_id'] = array( 'type' => 'hidden', 'fieldset' => 'body', 'value' => $la['la_id']); $form['row'][3]['la_name'] = array( 'type' => 'text', 'fieldset' => 'body', 'name' => 'Rule Name', 'class' => 'input-xlarge', 'value' => escape_html($la['la_name'])); $form['row'][4]['la_descr'] = array( 'type' => 'textarea', 'fieldset' => 'body', 'name' => 'Description', 'class' => 'input-xxlarge', //'style' => 'margin-bottom: 10px;', 'value' => escape_html($la['la_descr'])); $form['row'][5]['la_rule'] = array( 'type' => 'textarea', 'fieldset' => 'body', 'name' => 'Regular Expression', 'class' => 'input-xxlarge', 'value' => escape_html($la['la_rule'])); $form['row'][6]['la_disable'] = array( 'type' => 'switch-ng', 'fieldset' => 'body', 'name' => 'Status', 'on-text' => 'Disabled', 'on-color' => 'danger', 'off-text' => 'Enabled', 'off-color' => 'success', 'size' => 'small', 'value' => $la['la_disable']); $form['row'][8]['close'] = array( 'type' => 'submit', 'fieldset' => 'footer', 'div_class' => '', // Clean default form-action class! 'name' => 'Close', 'icon' => '', 'attribs' => array('data-dismiss' => 'modal', 'aria-hidden' => 'true')); $form['row'][9]['action'] = array( 'type' => 'submit', 'fieldset' => 'footer', 'div_class' => '', // Clean default form-action class! 'name' => 'Save Changes', 'icon' => 'icon-ok icon-white', //'right' => TRUE, 'class' => 'btn-primary', 'value' => 'edit_syslog_rule'); $modals .= generate_form_modal($form); unset($form); } $string .= '
' . escape_html($la['la_name']) . '' . escape_html($la['la_descr']) . '' . escape_html($la['la_rule']) . '' . escape_html($la['la_severity']) . '' . ($la['la_disable'] ? 'disabled' : 'enabled') . ''; if ($_SESSION['userlevel'] >= 10) { $string .= '
'; } $string .= '
'; $string .= generate_box_close(); echo $string; } else { print_warning("There are currently no Syslog alerting filters defined."); } echo $modals; } if (isset($vars['la_id'])) { // Pagination $vars['pagination'] = TRUE; print_logalert_log($vars); } register_html_title('Syslog Rules'); // EOF