示例#1
0
function script_field_edit() {
	$_script_id = get_get_var_number("script_id");
	$_script_field_id = get_get_var_number("id");
	$_field_type = get_get_var_number("field_type");

	if (empty($_script_field_id)) {
		$header_label = "[new]";
	}else{
		$script_field = api_script_field_get($_script_field_id);

		$header_label = "[edit: " . $script_field["data_name"] . "]";
	}

	$script = api_script_get($_script_id);

	if (($_field_type == SCRIPT_FIELD_TYPE_INPUT) || ($_field_type == SCRIPT_FIELD_TYPE_OUTPUT)) {
		$current_field_type = $_field_type;
	}else{
		$current_field_type = ($script_field["input_output"] == "in" ? SCRIPT_FIELD_TYPE_INPUT : "out");
	}

	if ($current_field_type == SCRIPT_FIELD_TYPE_INPUT) {
		$current_field_type_friendly = _("Input");
	}elseif ($current_field_type == SCRIPT_FIELD_TYPE_OUTPUT) {
		$current_field_type_friendly = _("Output");
	}

	form_start("scripts_fields.php", "form_script_field");

	html_start_box("<strong>$current_field_type_friendly Field</strong> $header_label");

	if ($current_field_type == SCRIPT_FIELD_TYPE_INPUT) {
		field_row_header("Input Options");

		_script_field_field__field_input_type("field_input_type", (isset($script_field["field_input_type"]) ? $script_field["field_input_type"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
		_script_field_field__field_input_value_custom("field_input_value_custom", (isset($script_field["field_input_value"]) ? $script_field["field_input_value"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
		_script_field_field__field_input_value_device("field_input_value_device", (isset($script_field["field_input_value"]) ? $script_field["field_input_value"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}

	field_row_header("Field Options");

	if ($current_field_type == SCRIPT_FIELD_TYPE_INPUT) {
		_script_field_field__data_name_input("data_name", $_script_id, (isset($script_field["data_name"]) ? $script_field["data_name"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}else if ($current_field_type == SCRIPT_FIELD_TYPE_OUTPUT) {
		_script_field_field__data_name_output("data_name", (isset($script_field["data_name"]) ? $script_field["data_name"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}

	_script_field_field__name("name", (isset($script_field["name"]) ? $script_field["name"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));

	if ($current_field_type == SCRIPT_FIELD_TYPE_INPUT) {
		_script_field_field__regexp_match("regexp_match", (isset($script_field["regexp_match"]) ? $script_field["regexp_match"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
		_script_field_field__allow_empty("allow_empty", (isset($script_field["allow_empty"]) ? $script_field["allow_empty"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}else if ($current_field_type == SCRIPT_FIELD_TYPE_OUTPUT) {
		_script_field_field__update_rrd("update_rrd", (isset($script_field["update_rrd"]) ? $script_field["update_rrd"] : ""), (isset($script_field["id"]) ? $script_field["id"] : "0"));
	}

	_script_field_field__field_input_type_js_update((isset($script_field["field_input_type"]) ? $script_field["field_input_type"] : SCRIPT_FIELD_INPUT_CUSTOM), (empty($_script_field_id) ? 0 : $_script_field_id));

	html_end_box();

	form_hidden_box("id", $_script_field_id, "0");
	form_hidden_box("script_id", $_script_id, "0");
	form_hidden_box("field_type", $current_field_type, "0");
	form_hidden_box("action_post", "script_field_edit");

	form_save_button("scripts.php?action=edit&id=" . $_script_id);
}
示例#2
0
function script_edit() {
	$menu_items = array(
		"remove" => "Remove"
		);

	$_script_id = get_get_var_number("id");

	if (empty($_script_id)) {
		$header_label = "[new]";
	}else{
		$script = api_script_get($_script_id);

		$header_label = "[edit: " . $script["name"] . "]";
	}

	form_start("scripts.php", "form_script");

	html_start_box("<strong>" . _("Scripts") . "</strong> $header_label");

	_script_field__name("name", (isset($script["name"]) ? $script["name"] : ""), (isset($script["id"]) ? $script["id"] : "0"));
	_script_field__type_id("type_id", (isset($script["type_id"]) ? $script["type_id"] : ""), (isset($script["id"]) ? $script["id"] : "0"));
	_script_field__input_string("input_string", (isset($script["input_string"]) ? $script["input_string"] : ""), (isset($script["id"]) ? $script["id"] : "0"));

	html_end_box();

	form_hidden_box("id", $_script_id);
	form_hidden_box("action_post", "script_edit");

	form_save_button("scripts.php");

	if (!empty($_script_id)) {
		echo "<br />\n";

		form_start("scripts_fields.php", "form_script_item");

		$box_id = "1";
		html_start_box("<strong>" . _("Script Fields") . "</strong>");

		?>
		<tr class="heading">
			<td colspan="2">
				Input Fields
			</td>
			<td align="right">
				<a href="scripts_fields.php?action=edit&field_type=<?php echo SCRIPT_FIELD_TYPE_INPUT;?>&script_id=<?php echo $_script_id;?>">Add</a>
			</td>
		</tr>
		<?php
		$input_fields = api_script_field_list($_script_id, SCRIPT_FIELD_TYPE_INPUT);

		if ((is_array($input_fields) > 0) && (sizeof($input_fields) > 0)) {
			foreach ($input_fields as $field) {
				?>
				<tr class="item" id="box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>" onClick="display_row_select('<?php echo $box_id;?>',document.forms[1],'box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>', 'box-<?php echo $box_id;?>-chk-<?php echo $field["id"];?>')" onMouseOver="display_row_hover('box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>')" onMouseOut="display_row_clear('box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>')">
					<td class="item">
						<a onClick="display_row_block('box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>')" href="scripts_fields.php?action=edit&script_id=<?php echo $_script_id;?>&id=<?php echo $field["id"];?>"><span id="box-<?php echo $box_id;?>-text-<?php echo $field["id"];?>"><?php echo $field["data_name"];?></span></a>
					</td>
					<td>
						<?php echo $field["name"];?>
					</td>
					<td class="checkbox"align="center">
						<input type='checkbox' name='box-<?php echo $box_id;?>-chk-<?php echo $field["id"];?>' id='box-<?php echo $box_id;?>-chk-<?php echo $field["id"];?>' title="<?php echo $field["data_name"];?>">
					</td>
				</tr>
				<?php
			}
		}else{
			?>
			<tr class="empty">
				<td colspan="2">
					No input fields found. This means that no input parameters will be passed to the script.
				</td>
			</tr>
			<?php
		}

		?>
		<tr class="heading">
			<td colspan="2">
				Output Fields
			</td>
			<td align="right">
				<a href="scripts_fields.php?action=edit&field_type=<?php echo SCRIPT_FIELD_TYPE_OUTPUT;?>&script_id=<?php echo $_script_id;?>">Add</a>
			</td>
		</tr>
		<?php
		$output_fields = api_script_field_list($_script_id, SCRIPT_FIELD_TYPE_OUTPUT);

		if ((is_array($output_fields) > 0) && (sizeof($output_fields) > 0)) {
			foreach ($output_fields as $field) {
				?>
				<tr class="item" id="box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>" onClick="display_row_select('<?php echo $box_id;?>',document.forms[1],'box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>', 'box-<?php echo $box_id;?>-chk-<?php echo $field["id"];?>')" onMouseOver="display_row_hover('box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>')" onMouseOut="display_row_clear('box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>')">
					<td class="title">
						<a onClick="display_row_block('box-<?php echo $box_id;?>-row-<?php echo $field["id"];?>')" href="scripts_fields.php?action=edit&script_id=<?php echo $_script_id;?>&id=<?php echo $field["id"];?>"><span id="box-<?php echo $box_id;?>-text-<?php echo $field["id"];?>"><?php echo $field["data_name"];?></span></a>
					</td>
					<td>
						<?php echo $field["name"];?>
					</td>
					<td class="checkbox" align="center">
						<input type='checkbox' name='box-<?php echo $box_id;?>-chk-<?php echo $field["id"];?>' id='box-<?php echo $box_id;?>-chk-<?php echo $field["id"];?>' title="<?php echo $field["data_name"];?>">
					</td>
				</tr>
				<?php
			}
		}else{
			?>
			<tr class="empty">
				<td colspan="2">
					No output fields found. Remember that <strong>at least one output field</strong> must be defined!
				</td>
			</tr>
			<?php
		}

		html_box_toolbar_draw($box_id, "1", "2", HTML_BOX_SEARCH_NONE);
		html_end_box(false);

		html_box_actions_menu_draw($box_id, "1", $menu_items);

		form_hidden_box("script_id", $_script_id);
		form_hidden_box("action", "save");
		form_hidden_box("action_post", "script_field_list");

		form_end();

		?>
		<script language="JavaScript">
		<!--
		function action_area_handle_type(box_id, type, parent_div, parent_form) {
			if (type == 'remove') {
				parent_div.appendChild(document.createTextNode('Are you sure you want to remove these script fields?'));
				parent_div.appendChild(action_area_generate_selected_rows(box_id));

				action_area_update_header_caption(box_id, 'Remove Script Field');
				action_area_update_submit_caption(box_id, 'Remove');
				action_area_update_selected_rows(box_id, parent_form);
			}
		}
		-->
		</script>
		<?php
	}
}
示例#3
0
function _script_field_field__data_name_input($field_name, $script_id, $field_value = "", $field_id = 0) {
	require_once(CACTI_BASE_PATH . "/lib/sys/html_form.php");
	require_once(CACTI_BASE_PATH . "/lib/script/script_info.php");

	$script = api_script_get($script_id);

	/* parse out all field names listed in the input string */
	$array_field_names = array();
	if (preg_match_all("/<([_a-zA-Z0-9]+)>/", $script["input_string"], $matches)) {
		for ($i=0; ($i < count($matches[1])); $i++) {
			$array_field_names{$matches[1][$i]} = $matches[1][$i];
		}
	}

	?>
	<tr class="<?php echo field_get_row_style();?>">
		<td class="field-row" width="50%">
			<span class="textEditTitle"><?php echo _("Field Name");?></span><br>
			<?php echo _("The name that Cacti uses to refer to a field when sending data to the script.");?>
		</td>
		<td class="field-row" colspan="2">
			<?php form_dropdown($field_name, $array_field_names, "", "", $field_value, "", "hostname");?>
		</td>
	</tr>
	<?php
}
示例#4
0
function &package_script_export($script_id, $indent = 3) {
	require_once(CACTI_BASE_PATH . "/lib/script/script_info.php");

	$xml = "";

	/*
	 * XML Tag: <script>
	 */

	/* obtain a list of all script specific fields */
	$script_fields = api_script_form_list();
	/* obtain a copy of this specfic script */
	$script = api_script_get($script_id);

	$_xml = "";
	foreach (array_keys($script_fields) as $field_name) {
		/* create an XML key for each script field */
		$_xml .= package_xml_tag_get($field_name, xml_character_encode($script[$field_name]), $indent + 2);
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("script", $_xml, $indent + 1, true);

	/*
	 * XML Tag: <fields>
	 */

	/* obtain a list of all script field specific fields */
	$script_field_fields = api_script_field_form_list();
	/* obtain a list of all script fields associated with this script */
	$script_fields = api_script_field_list($script_id);

	$_xml = "";
	if (sizeof($script_fields) > 0) {
		$i = 0;
		foreach ($script_fields as $script_field) {
			$__xml = "";
			foreach (array_keys($script_field_fields) as $field_name) {
				/* create an XML key for each script field field */
				$__xml .= package_xml_tag_get($field_name, xml_character_encode($script_field[$field_name]), $indent + 3);
			}

			/* append the result onto a temporary XML string */
			$_xml .= package_xml_tag_get("item_" . str_pad($i, 5, "0", STR_PAD_LEFT), $__xml, $indent + 2, true);

			$i++;
		}
	}

	/* append the result onto the final XML string */
	$xml .= package_xml_tag_get("fields", $_xml, $indent + 1, true);

	/* wrap the whole XML string into a 'script' tag and return it */
	$xml = package_xml_tag_get(package_hash_get($script_id, "script"), $xml, $indent, true);

	return $xml;
}