1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
<?
/* This file is part of JFFNMS
* Copyright (C) <2002-2005> Javier Szyszlican <javier@szysz.com>
* This program is licensed under the GNU GPL, full terms in the LICENSE file
*/
class jffnms_tools extends internal_base_standard {
var $jffnms_class = "tools";
var $jffnms_insert = array("description"=>"New Tool","name"=>"none");
var $jffnms_filter_record = 0;
var $jffnms_order_type = "asc";
function get_all() { $params = func_get_args(); return call_user_func_array("tools_list",$params); }
function info() { $params = func_get_args(); return call_user_func_array("tools_info",$params); }
function get_value() { $params = func_get_args(); return call_user_func_array("tools_get",$params); } //Remote/Local GUI
function set_value() { $params = func_get_args(); return call_user_func_array("tools_set",$params); } //Remote/Local GUI
function get_value_real() { $params = func_get_args(); return call_user_func_array("tools_get_real",$params); } //Remote API
function set_value_real() { $params = func_get_args(); return call_user_func_array("tools_set_real",$params); } //Remote API
}
function tools_list ($ids = NULL, $filters = array()) {
$where = array();
foreach ($filters as $field=>$value)
switch ($field) {
case "itype" : if (!empty($value)) $where[]=array("tools.itype","=",$value); break;
case "name" : if (!empty($value)) $where[]=array("tools.name","=","'$value'"); break;
}
return get_db_list(
array("tools","interface_types"), $ids,
array("tools.*",
"itype_description"=>"interface_types.description"
) ,
array_merge(
array(
array("tools.itype","=","interface_types.id"),
array("tools.id",">",1)),
$where
),
array(
array("tools.itype","asc"),
array("tools.pos","asc"),
array("tools.description","desc"),
array("tools.id","desc")
));
}
function tools_info($tool_name) {
$data = tools_list(NULL,array("name"=>$tool_name));
//if (is_array($data) and (count($data)==1)) { // For Separators
$data = current($data);
$file = (!empty($data["file_group"])?$data["file_group"]:$data["name"]);
$real_function = "tool_".$data["name"]."_info";
$function_file = get_config_option("jffnms_real_path")."/engine/tools/$file.inc.php";
if (in_array($function_file,get_included_files()) || (file_exists($function_file) && (include_once($function_file)))) {
if (function_exists($real_function)) {
$result = call_user_func_array($real_function,array());
return $result;
} else
logger("ERROR: Calling Function '$real_function' doesn't exists.<br>\n");
} else
logger ("ERROR Loading file $function_file.<br>\n");
//} else
// logger("ERROR: Bad Tool Name\n");
return false;
}
function tools_get($tool_name,$id) {
$data = tools_list(NULL,array("name"=>$tool_name));
$interface_data = ((is_numeric($id))?interfaces_list($id,array("host_fields"=>1)):$id);
if (is_array($data) and (count($data)==1) && is_array($interface_data) && (count($interface_data)==1)) {
$data = current($data);
$interface_data = current($interface_data);
if ($interface_data["host_satellite"]==satellite_my_id()) //Local Call
$result = tools_get_real ($data,$interface_data);
else //Remote Call
$result = satellite_call($interface_data["host_satellite"],"tools","get_value_real",array($data,$interface_data));
} else
logger("ERROR: Bad Tool Name or Interface\n");
if (isset($result))
return $result;
else
return false;
}
function tools_set($tool_name,$id,$value,$username = "unknown",$reget = true) {
$data = tools_list(NULL,array("name"=>$tool_name));
if (is_array($data) and (count($data)==1)) {
$data = current($data);
if ($data["allow_set"]==1) {
$interface_data = ((is_numeric($id))?interfaces_list($id,array("host_fields"=>1)):$id);
if (is_array($interface_data) && (count($interface_data)==1)) {
$interface_data = current($interface_data);
if ($interface_data["host_satellite"]==satellite_my_id()) //Local Call
$result = tools_set_real ($data,$interface_data,$value);
else //Remote Call
$result = satellite_call($interface_data["host_satellite"],"tools","set_value_real",array($data,$interface_data,$value));
} else
logger("ERROR: Bad Interface\n");
} else
logger ("ERROR: Tool does not allow Setting.\n");
} else
logger("ERROR: Bad Tool Name\n");
if (isset($result)) {
//Event Creation
$tool_event_type = 42; //FIXME Hard-Coded
//Get a meaningful value to show in the event
$tool_info = tools_info($data["name"]);
switch ($tool_info["type"]) {
case "select":
$value_info = $tool_info["param"][$value];
break;
default:
$value_info = $value;
}
$description= (isset($tool_info["description_label"])?$tool_info["description_label"]:$data["description"]);
$value_info = (isset($tool_info["state_label"]) ?$tool_info["state_label"]:$value_info);
$value_info .= (isset($tool_info["param"]["label"]) ?$tool_info["param"]["label"]:""); // add label to event value
insert_event(date("Y-m-d H:i:s",time()),$tool_event_type,
$interface_data["host"],$interface_data["interface"],$value_info,$username,$description,"",0);
//Return data to the caller
return array($result,($reget==true)?tools_get($data["name"],array($interface_data)):NULL);
} else
return false;
}
function tools_get_real ($tool_data,$interface_data) {
$file = (!empty($tool_data["file_group"])?$tool_data["file_group"]:$tool_data["name"]);
$real_function = "tool_".$tool_data["name"]."_get";
$function_file = get_config_option("jffnms_real_path")."/engine/tools/$file.inc.php";
if (in_array($function_file,get_included_files()) || (file_exists($function_file) && (include_once($function_file)))) {
if (function_exists($real_function))
$result = call_user_func_array($real_function,array($interface_data));
else
logger("ERROR: Calling Function '$real_function' doesn't exists.<br>\n");
} else
logger ("ERROR Loading file $function_file.<br>\n");
return $result;
}
function tools_set_real ($tool_data,$interface_data,$value) {
$file = (!empty($tool_data["file_group"])?$tool_data["file_group"]:$tool_data["name"]);
$real_function = "tool_".$tool_data["name"]."_set";
$function_file = get_config_option("jffnms_real_path")."/engine/tools/$file.inc.php";
if (in_array($function_file,get_included_files()) || (file_exists($function_file) && (include_once($function_file)))) {
if (function_exists($real_function))
$result = call_user_func_array($real_function,array($interface_data,$value));
else
logger("ERROR: Calling Function '$real_function' doesn't exists.<br>\n");
} else
logger ("ERROR Loading file $function_file.<br>\n");
return $result;
}
?>
|