| [ PHPXref.com ] | [ Generated: Sun Jul 20 18:21:30 2008 ] | [ JFFNMS 0.8.2 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <? 2 /* This file is part of JFFNMS 3 * Copyright (C) <2002-2005> Javier Szyszlican <javier@szysz.com> 4 * This program is licensed under the GNU GPL, full terms in the LICENSE file 5 */ 6 class jffnms_access_api { 7 var $session; 8 9 function jffnms_access_api ($init_type = NULL) { 10 if (isset($init_type)) $this->init_type = $init_type; 11 } 12 13 function get($class_name) { 14 $new_class_name = "jffnms_remote_$class_name"; 15 $obj = NULL; 16 17 if (!class_exists($new_class_name)) { 18 19 $methods = $this->_call($class_name,"get_methods",NULL); 20 21 $class_code.=" class $new_class_name extends jffnms_access_api {\n"; 22 if (is_array($methods)) { 23 foreach ($methods as $meth) 24 if (!(($class_name=="jffnms") and ($meth=="get"))) { //don't overwrite the jffnms->get method 25 $class_code.=" function $meth() {\n"; 26 $class_code.=" \$params = func_get_args();\n"; 27 $class_code.=" return parent::_call('$class_name','$meth',\$params);\n"; 28 $class_code.=" }\n"; 29 } 30 $class_code.=" }\n"; 31 32 eval ($class_code); 33 } 34 } 35 36 if (class_exists($new_class_name)) { //class created 37 $obj = new $new_class_name; 38 $obj->session = &$this->session; 39 40 if ($class_name=="jffnms") { //special mail class 41 $jffnms_classes = $obj->jffnms ($this->init_type); 42 43 if ($this->init_type==1) //init all classes 44 foreach ($jffnms_classes as $aux) 45 if ($aux!="access_api") 46 $obj->$aux = $this->get($aux); 47 } 48 } 49 50 return $obj; 51 } 52 53 function _call ($class,$method,$params) { 54 $server = get_config_option("jffnms_satellite_server_uri"); 55 56 if (empty($this->session)) $this->session = "get"; 57 58 $message = array( 59 "sat_id"=>1, 60 "class"=>$class, 61 "method"=>$method, 62 "params"=>$params, 63 "session"=>$this->session 64 ); 65 66 $ret = satellite_query ($server,$message,"GUIClient",0); 67 //debug (array(request=>$message,response=>$ret)); 68 69 if (is_array($ret) && (isset($ret["session"]))) { 70 $this->session = $ret["session"]; 71 unset ($ret["session"]); 72 } 73 74 return $ret; 75 } 76 } 77 78 function clean_url_array (&$list, $key,$value,$deep = 0) { 79 if (is_array($value)) 80 foreach ($value as $k=>$v) { 81 //debug ("DEEP $deep - $key - $k - $v"); 82 $key_aux = (is_array($value)&&!empty($key))?"[$k]":$k; 83 84 clean_url_array($list,$key.$key_aux,$v,$deep+1); 85 } 86 else { 87 //debug ("VALUE $deep - $key - $value"); 88 $list[] = urlencode($key)."=".urlencode($value); 89 } 90 } 91 92 function clean_url($extra_vars = array(),$no_vars = array()) { 93 if ($GLOBALS["_GET"]) 94 $REQUEST_URI_VARS = array_merge($GLOBALS["_GET"],$GLOBALS["_POST"],$extra_vars); //suport for PHP 4.1.0 and older 95 else 96 $REQUEST_URI_VARS = array_merge($GLOBALS["HTTP_GET_VARS"],$GLOBALS["HTTP_POST_VARS"],$extra_vars); 97 98 foreach ($no_vars as $delete) 99 unset($REQUEST_URI_VARS[$delete]); 100 101 $url_aux=array(); 102 clean_url_array($url_aux,"",$REQUEST_URI_VARS); 103 104 $REQUEST_URI_CLEAN = $GLOBALS["SCRIPT_NAME"]."?".join("&",$url_aux); 105 106 $GLOBALS["REQUEST_URI"]=$REQUEST_URI_CLEAN; //cleaning up the URL 107 } 108 109 function http_authenticate() { 110 global $jffnms_version,$jffnms_real_path,$jffnms_rel_path; 111 header( "WWW-Authenticate: Basic realm=\"JFFNMS $jffnms_version\""); 112 header( "HTTP/1.0 401 Unauthorized"); 113 include("$jffnms_real_path/htdocs/logout.php"); 114 exit; 115 } 116 117 function show_license($title) { 118 119 return 120 "<!-- 121 /* $title\n 122 * Copyright (C) <2002-2005> Javier Szyszlican <javier@szysz.com> 123 * 124 * This file is part of JFFNMS. 125 * 126 * JFFNMS is free software; you can redistribute it and/or modify 127 * it under the terms of the GNU General Public License as published by 128 * the Free Software Foundation; either version 2 of the License, or 129 * (at your option) any later version. 130 * 131 * JFFNMS is distributed in the hope that it will be useful, 132 * but WITHOUT ANY WARRANTY; without even the implied warranty of 133 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 134 * GNU General Public License for more details. 135 * 136 * You should have received a copy of the GNU General Public License 137 * along with JFFNMS; if not, write to the Free Software 138 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 139 */ 140 -->\n"; 141 142 } 143 144 function adm_header($title = "", $bgcolor = "", $body_others="", $just_head = false) { 145 global $refresh,$REQUEST_URI; 146 147 echo 148 ((!$just_head)?tag("!DOCTYPE", "", "","HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"", false):""). 149 show_license($title). 150 tag("html","","","",false). 151 tag("head"). 152 html("title", (!empty($title)?$title." - ":"")."JFFNMS"). 153 tag("meta","","","HTTP-EQUIV='Pragma' CONTENT='no-cache'", false). 154 tag("meta","","","HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1'", false). 155 tag("meta","","","HTTP-EQUIV='Content-language' CONTENT='en'", false). 156 tag("meta","","","HTTP-EQUIV='Content-Style-Type' CONTENT='text/css'", false). 157 tag("meta","","","HTTP-EQUIV='Content-Script-Type' CONTENT='text/javascript'", false). 158 159 (($refresh) 160 ?tag("meta","","","HTTP-EQUIV='Refresh' CONTENT='".$refresh.";".$REQUEST_URI."'", false) 161 :""). 162 163 tag("link","","","rel='shortcut icon' type='image/x-icon' href='".$GLOBALS["jffnms_rel_path"]."/images/jffnms.ico'", false). 164 tag("link","","","rel='icon' type='image/x-icon' href='".$GLOBALS["jffnms_rel_path"]."/images/jffnms.ico'", false). 165 tag("link","","","rel='stylesheet' href='".$GLOBALS["jffnms_rel_path"]."/default.css'", false). 166 (!empty($GLOBALS["jffnms_custom_css"])?tag("link","","","rel='stylesheet' href='".$GLOBALS["jffnms_custom_css"]."'", false):""). 167 tag("link","","","rel='alternate' type='application/rss+xml' title='".$GLOBALS["jffnms_site"]." Events Feed' href='".$GLOBALS["jffnms_rel_path"]."/events.php?view_type=rss'", false). 168 tag_close("head"). 169 ((!$just_head) 170 ?tag ("body","","", 171 (!empty($bgcolor)?" style='background-color: #$bgcolor;'":""). 172 (!empty($body_others)?" ".$body_others:"") 173 ,false) 174 :""); 175 } 176 177 function adm_footer () { 178 echo 179 tag_close("body"). 180 tag_close("html"); 181 } 182 183 function news_get ($news_url) { 184 $news = http_post_message($news_url,news_parse()); 185 if (!empty($news)) 186 return @explode("\n",$news); 187 else 188 return false; 189 } 190 191 function control_button ($text, $frame = "", $url = "" ,$image = "", $control_name = "", $onclick = "") { 192 193 if (empty($image)) $image = "bullet3.png"; // So people call it with an empty value 194 195 $result = 196 linktext ("\n". 197 (($image!="none")?image($image)." ":"") 198 .$text."\n" 199 ,$url, $frame, "controlbutton", $onclick, $control_name); 200 201 return $result; 202 } 203 204 function javascript_refresh($url,$time) { 205 $time_usec = $time*1000; 206 if (($url) && ($time > 1)) 207 $value = script("refresh_timeout = window.setTimeout ('$url',$time_usec);"); 208 209 return $value; 210 } 211 212 function play_sound($file) { 213 $file = $GLOBALS["jffnms_rel_path"]."/sounds/".$file; 214 215 return 216 html("embed", "", "", "", "src='".$file."' autostart='true' hidden='true' loop='false'"). // MOZ 217 218 html ("object", tag("param", "", "", "name='Filename' value='".$file."'") 219 ,"", "", "hidden='true' classid='clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95' style='display: none;'"); // IE 220 221 } 222 223 function show_event ($event,$color, $map_id,$filter_id) { 224 global $REQUEST_URI, $express_filter, $jffnms_rel_path, $view_type, $journal_id; 225 226 $image_ack = (($event["ack"]>0)?"ok.png":"alert2.gif"); 227 228 $filter_url = $_SERVER["SCRIPT_NAME"]."?filter_id=$filter_id"; 229 230 $date_unix = strtotime($event["date"]); 231 $day = date ("j M",$date_unix); 232 $hour = date ("H:i:s",$date_unix); 233 $event_text = $event["text"]; 234 235 switch ($view_type) { 236 237 case "html": 238 $day_filter = date ("Y-m-d",$date_unix-(60*60*24)); 239 $fgcolor = $event["fgcolor"]; 240 $bgcolor = $event["bgcolor"]; 241 $id = $event["id"]; 242 $ack_image = image($image_ack); 243 244 $summary_ids = (is_array($event["summary_ids"])?join(",",$event["summary_ids"]):$event["id"]); 245 246 $output = 247 tr_open("event$id", (($event["ack"]!=0)?"ack":"event"), $bgcolor, "", "color: ".$fgcolor). 248 249 //Date + Hour 250 td(linktext($day, $filter_url."&express_filter=date,$day_filter,=")." ".html("a",$hour), "date"). 251 252 // Checkbox + Detail 253 td( checkbox_value("checkedid[]", $summary_ids, 254 ((($event["ack"]!=0) && ($journal_id > 1) &&($journal_id==$event["ack"]))?1:0)). //check 255 linktext($ack_image,$REQUEST_URI."&journal_id=".(($event["ack"]==0)?1:0)."&journal_button=Ack&checkedid[]=".$summary_ids), 256 "ack_check"). 257 258 // Type 259 td (linktext($event["type_description"], $filter_url."&express_filter=".$express_filter."^type,".$event["type_id"].",=&map_id=".$map_id), 260 "type", "", (($event["show_host"]==0)?3:"")); 261 262 if ($event["show_host"] == 1) //Host + Zone 263 $output .= 264 td( 265 linktext(" ".substr($event["host_name"],0,20)." ".$event["zone"]." ", 266 $filter_url."&express_filter=".$express_filter."^host,".$event["host_id"].",=&map_id=".$map_id), 267 "host", "", (empty($event["zone_image"])?2:"")). 268 269 (!empty($event["zone_image"]) 270 ?td(linktext(image($event["zone_image"]), 271 $filter_url."&express_filter=".$express_filter."^zone,".$event["zone_id"].",=&map_id=".$map_id), 272 "zone"):""); 273 274 // Event Text 275 $output .= td($event_text, "detail"); 276 277 //closing 278 $output .= 279 tag_close("tr"); 280 281 break; 282 283 case "csv": 284 $day_only = date ("Y-m-d",$date_unix); 285 286 $fields = array($day_only,$hour,$event["host_name"],$event["zone_name"],$event["user"],$event["interface"], 287 $event["type_description"],$event["state"],$event["info"],$event["severity"]); 288 289 foreach ($fields as $key=>$aux) 290 $fields[$key] = "\"".$aux."\""; 291 292 $output = join(",",$fields)."\n"; 293 break; 294 295 case "rss": 296 case "rdf": 297 $output .= 298 html("item", 299 html("title", $event["severity"]." - ".$event["host_name"]." ".$event["zone"].": ".$event_text, "", "", "", false, true). 300 html("pubDate", $event["date"], "", "", "",false, true). 301 html("link", 302 htmlspecialchars(current_host().$REQUEST_URI."&view_type=html"), "", "", "",false, true) 303 ); 304 break; 305 } 306 307 echo $output; 308 } //function show_event 309 310 function interface_shortname_and_card ($interface,$type_description,$break_by_card) { 311 312 $interface_len = strlen($interface); 313 314 for ($pos = 0; ($pos < $interface_len) && (!is_numeric($interface[$pos])); $pos++); 315 316 $space_pos = strpos($interface," "); 317 318 if ($interface_len > 9) { 319 if ($pos <= 0) $pos = 1; 320 if ($pos == $interface_len) $pos = 1; //if there was no numbers in the interface name 321 322 if ($space_pos!==FALSE) { //if the interface has a space in it 323 $int = substr($interface,0,$space_pos)." ".$interface[$space_pos+1]; // from Real Memory take Real M 324 $pos = $space_pos; 325 } else 326 $int = $interface[0].substr($interface,$pos,$interface_len); //from Serial9/3/4 take S9/3/4 327 } else $int = $interface; 328 329 if (strpos($interface,"/")===FALSE) $pos--; //if the interface is not part of a card Serial3/4 | Tunnel0 then pos-- because card will not include the number 330 331 332 if ($break_by_card==1) { 333 if (is_numeric($interface[$pos])) //Card Number Numeric Serial9 interface[pos]="9" 334 $card = substr(substr($interface,0,$pos),0,8).$interface[$pos]; //use Serial9 335 else 336 $card = substr(substr($interface,0,$pos+1),0,9); //interface[pos] not numeric, use all 9 chars from interface name 337 } else 338 $card = substr($type_description,0,9); 339 340 $int = trim($int); 341 $card = trim ($card); 342 343 //debug ("inter: $interface -- int: $int -- card: $card -- len: $interface_len -- pos: $pos -- pos1: $pos1");// continue; 344 return Array ($int, $card); 345 } 346 347 //Get the Graph File from object and store it in a local (public) place 348 function performance_graph ($interface_object, $id, $graph_filename, $graph_function, $sizex, $sizey, $title, $graph_time_start, $graph_time_stop, $other_data = "") { 349 350 list ($value, $graph_data, $other_data) = $interface_object->graph($id, $graph_function, $sizex,$sizey, $title,$graph_time_start,$graph_time_stop, $other_data); 351 352 $graph_data = base64_decode ($graph_data); 353 $fp = fopen ($graph_filename, "wb+"); 354 fputs($fp,$graph_data); 355 fclose ($fp); 356 357 return $value; 358 } 359 360 function news_parse () { 361 return array("site"=>$GLOBALS["jffnms_site"],"version"=>$GLOBALS["jffnms_version"],"h"=>$GLOBALS["info"]["hosts"]["data"],"i"=>$GLOBALS["info"]["interfaces"]["data"],"f"=>$_SERVER["REMOTE_ADDR"],"php"=>phpversion(),"apache"=>$_SERVER["SERVER_SOFTWARE"]); 362 } 363 364 function alarms_get_status ($alarms) { 365 $lower_alarm=256; 366 $lower_alarm_id = 2; 367 368 if (is_array($alarms)) 369 foreach ($alarms as $alarm_name=>$data) 370 if ($data["alarm_level"] < $lower_alarm) { 371 $lower_alarm = $data["alarm_level"]; 372 $lower_alarm_name = $alarm_name; 373 $bgcolor = $data["bgcolor"]; 374 $fgcolor = $data["fgcolor"]; 375 } 376 377 $alarms_parsed = array(); 378 $alarms_long = array(); 379 380 if (is_array($alarms)) 381 foreach($alarms as $key=>$alarm) { 382 if ($key=="total") $alarms_parsed[$key]="T=".$alarm[qty]; 383 else $alarms_parsed[$key]=strtoupper($key[0]).$alarm[qty]; 384 385 $alarms_long[$key]=$alarm["qty"]; 386 } 387 $status = join("/",$alarms_parsed); 388 389 return array($status,$bgcolor,$fgcolor,$alarms_long,$lower_alarm_name); 390 } 391 392 function profile ($tag, $set_value = NULL) { 393 394 $profile = $GLOBALS["jffnms"]->get("profiles"); 395 396 if ($set_value !== NULL) 397 $profile->update($GLOBALS["auth_user_id"], $tag, $set_value); 398 399 $value = $profile->get_value($tag,$GLOBALS["auth_user_id"]); 400 401 return $value; 402 } 403 404 function cookie ($tag, $set_value = NULL) { 405 406 session_start(); 407 408 if ($set_value !== NULL) 409 $_SESSION[$tag] = $set_value; 410 411 $value = $_SESSION[$tag]; 412 413 session_write_close(); 414 415 return $value; 416 } 417 418 function ImageStringCenter($im,$color,$y,$text,$big = 0) { 419 420 if (!is_array($text)) $text = array($text); 421 422 if ($big==0) { 423 $size = 2; 424 $charsize = 6; 425 $line_span = 9; 426 } 427 428 if ($big==1) { 429 $size = 4; 430 $charsize = 8; 431 $line_span = 13; 432 } 433 434 $len = (strlen($text)*$charsize); 435 $sizex = imagesx($im); 436 $sizey = imagesy($im); 437 438 $cant_lines = count($text); 439 $lines_space = ($cant_lines * $line_span); 440 $space_left = ($sizey - $lines_space); 441 $y_span = floor(($space_left/($cant_lines*2))); 442 443 //echo "$sizey $lines_space $space_left $cant_lines $y_span ----"; 444 445 $line_number = 0; 446 foreach ($text as $align=>$aux) { 447 $aux = substr($aux,0,($sizex/$charsize)); 448 $len = (strlen($aux)*$charsize); 449 450 if (is_numeric($align)) $align = "center"; 451 452 switch ($align) { 453 case "center" : $x=($sizex/2)-($len/2); break; 454 case "left" : $x=($sizex-$len); break; 455 case "right" : $x=0; break; 456 } 457 458 ImageString ($im, $size, $x, $y+$y_span+($line_number*($line_span+$y_span)), $aux,$color); 459 $line_number++; 460 } 461 } 462 463 function current_host() { 464 return "http".(isset($_SERVER["HTTPS"])?"s":"")."://".$_SERVER["HTTP_HOST"]; 465 } 466 467 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |