__('Duplicate'), AUTOMATION_ACTION_TREE_ENABLE => __('Enable'), AUTOMATION_ACTION_TREE_EXPORT => __('Export'), AUTOMATION_ACTION_TREE_DISABLE => __('Disable'), AUTOMATION_ACTION_TREE_DELETE => __('Delete'), ]; // sanitize the tab gfrv('tab', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^([a-z_A-Z]+)$/']]); // set default action set_default_action(); switch (grv('action')) { case 'save': if (isrv('save_component_import')) { automation_import_process(); } else { form_save(); } break; case 'import': top_header(); automation_import(); bottom_footer(); break; case 'export': automation_export(); break; case 'actions': automation_tree_rules_form_actions(); break; case 'change_leaf': automation_tree_rules_change_leaf(); header('Location: automation_tree_rules.php?action=edit&id=' . grv('id')); break; case 'item_movedown': automation_tree_rules_item_movedown(); header('Location: automation_tree_rules.php?action=edit&id=' . grv('id')); break; case 'item_moveup': automation_tree_rules_item_moveup(); header('Location: automation_tree_rules.php?action=edit&id=' . grv('id')); break; case 'item_remove': automation_tree_rules_item_remove(); header('Location: automation_tree_rules.php?action=edit&id=' . grv('id')); break; case 'item_edit': top_header(); automation_tree_rules_item_edit(); bottom_footer(); break; case 'remove': automation_tree_rules_remove(); header('Location: automation_tree_rules.php'); break; case 'edit': top_header(); automation_tree_rules_edit(); bottom_footer(); break; default: top_header(); automation_tree_rules(); bottom_footer(); break; } function automation_export() : void { draw_tree_rules_filter(true); // if we are to save this form, instead of display it if (isrv('selected_items')) { $selected_items = sanitize_unserialize_selected_items(gnrv('selected_items')); $snmp_option_ids = []; if ($selected_items != false) { if (cacti_sizeof($selected_items) == 1) { $export_data = automation_tree_rule_export($selected_items[0]); } else { foreach ($selected_items as $id) { $snmp_option_ids[] = $id; } $export_data = automation_tree_rule_export($snmp_option_ids); } if (cacti_sizeof($export_data)) { $export_file_name = $export_data['export_name']; header('Content-type: application/json'); header('Content-Disposition: attachment; filename=' . $export_file_name); $output = json_encode($export_data, JSON_PRETTY_PRINT); print $output; } } } else { raise_message(40); header('Location: automation_tree_rules.php'); exit; } } function automation_import() : void { $form_data = [ 'import_file' => [ 'friendly_name' => __('Import Tree Rules from Local File'), 'description' => __('If the JSON file containing the Tree Rules data is located on your local machine, select it here.'), 'method' => 'file', 'accept' => '.json' ], 'import_text' => [ 'method' => 'textarea', 'friendly_name' => __('Import Tree Rules from Text'), 'description' => __('If you have the JSON file containing the Tree Rules data as text, you can paste it into this box to import it.'), 'value' => '', 'default' => '', 'textarea_rows' => '10', 'textarea_cols' => '80', 'class' => 'textAreaNotes' ], 'import_trees_branches' => [ 'friendly_name' => __('Import Device Rules Trees and Branches'), 'description' => __('Automatically Recreate the Trees and Branches if they do not exist upon Import.'), 'method' => 'checkbox', 'value' => '', 'default' => '' ] ]; form_start('automation_tree_rules.php', 'chk', true); if ((isset($_SESSION['import_debug_info'])) && (is_array($_SESSION['import_debug_info']))) { html_start_box(__('Import Results'), '60%', false, 3, 'center', ''); print '' . __('Cacti has Imported the following Tree Rules') . ''; foreach ($_SESSION['import_debug_info'] as $line) { print '' . $line . ''; } html_end_box(); kill_session_var('import_debug_info'); } html_start_box(__('Import Tree Rules'), '60%', false, 3, 'center', ''); draw_edit_form( [ 'config' => ['no_form_tag' => true], 'fields' => $form_data ] ); form_hidden_box('save_component_import', '1', ''); print "