0) { $ret=$t."y"; $value=$value-$t*(365*24*3600); } $t=floor($value/(30*24*3600)); if($t>0) { $ret=$ret.$t."m"; $value=$value-$t*(30*24*3600); } $t=floor($value/(24*3600)); if($t>0) { $ret=$ret.$t."d"; $value=$value-$t*(24*3600); } $t=floor($value/(3600)); if($t>0) { $ret=$ret.$t."h"; $value=$value-$t*(3600); } $t=floor($value/(60)); if($t>0) { $ret=$ret.$t."m"; $value=$value-$t*(60); } $ret=$ret.$value."s"; return $ret; } $u=""; // Special processing for bits (kilo=1000, not 1024 for bits) if( ($units=="b") || ($units=="bps")) { $abs=abs($value); if($abs<1000) { $u=""; } else if($abs<1000*1000) { $u="K"; $value=$value/1000; } else if($abs<1000*1000*1000) { $u="M"; $value=$value/(1000*1000); } else { $u="G"; $value=$value/(1000*1000*1000); } if(round($value)==$value) { $s=sprintf("%.0f",$value); } else { $s=sprintf("%.2f",$value); } return "$s $u$units"; } if($units=="") { if(round($value)==$value) { return sprintf("%.0f",$value); } else { return sprintf("%.2f",$value); } } $abs=abs($value); if($abs<1024) { $u=""; } else if($abs<1024*1024) { $u="K"; $value=$value/1024; } else if($abs<1024*1024*1024) { $u="M"; $value=$value/(1024*1024); } else { $u="G"; $value=$value/(1024*1024*1024); } if(round($value)==$value) { $s=sprintf("%.0f",$value); } else { $s=sprintf("%.2f",$value); } return "$s $u$units"; } function get_template_permission_str($num) { $str=" "; if(($num&1)==1) $str=$str.S_ADD." "; if(($num&2)==2) $str=$str.S_UPDATE." "; if(($num&4)==4) $str=$str.S_DELETE." "; return $str; } function get_media_count_by_userid($userid) { $sql="select count(*) as cnt from media where userid=$userid"; $result=DBselect($sql); $row=DBfetch($result); return $row["cnt"]; } function get_action_count_by_triggerid($triggerid) { $cnt=0; $sql="select count(*) as cnt from actions where triggerid=$triggerid and scope=0"; $result=DBselect($sql); $row=DBfetch($result); $cnt=$cnt+$row["cnt"]; $sql="select count(*) as cnt from actions where scope=2"; $result=DBselect($sql); $row=DBfetch($result); $cnt=$cnt+$row["cnt"]; $sql="select distinct h.hostid from hosts h,items i,triggers t,functions f where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=$triggerid"; $result=DBselect($sql); while($row=DBfetch($result)) { $sql="select count(*) as cnt from actions a,hosts h,items i,triggers t,functions f where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and a.triggerid=".$row["hostid"]." and a.scope=1"; $result2=DBselect($sql); $row2=DBfetch($result2); $cnt=$cnt+$row2["cnt"]; } return $cnt; } function check_anyright($right,$permission) { global $USER_DETAILS; $sql="select permission from rights where name='Default permission' and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $default_permission="H"; if(DBnum_rows($result)>0) { $default_permission=""; while($row=DBfetch($result)) { $default_permission=$default_permission.$row["permission"]; } } # default_permission $sql="select permission from rights where name='$right' and id!=0 and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $all_permissions=""; if(DBnum_rows($result)>0) { while($row=DBfetch($result)) { $all_permissions=$all_permissions.$row["permission"]; } } # all_permissions // echo "$all_permissions|$default_permission
"; switch ($permission) { case 'A': if(strstr($all_permissions,"A")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"A")) { return 1; } break; case 'R': if(strstr($all_permissions,"R")) { return 1; } else if(strstr($all_permissions,"U")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"R")) { return 1; } else if(strstr($default_permission,"U")) { return 1; } break; case 'U': if(strstr($all_permissions,"U")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"U")) { return 1; } break; default: return 0; } return 0; } function check_right($right,$permission,$id) { global $USER_DETAILS; $sql="select permission from rights where name='Default permission' and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $default_permission="H"; if(DBnum_rows($result)>0) { $default_permission=""; while($row=DBfetch($result)) { $default_permission=$default_permission.$row["permission"]; } } # default_permission $sql="select permission from rights where name='$right' and id=0 and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $group_permission=""; if(DBnum_rows($result)>0) { while($row=DBfetch($result)) { $group_permission=$group_permission.$row["permission"]; } } # group_permission $id_permission=""; if($id!=0) { $sql="select permission from rights where name='$right' and id=$id and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); if(DBnum_rows($result)>0) { while($row=DBfetch($result)) { $id_permission=$id_permission.$row["permission"]; } } } # id_permission // echo "$id_permission|$group_permission|$default_permission
"; switch ($permission) { case 'A': if(strstr($id_permission,"H")) { return 0; } else if(strstr($id_permission,"A")) { return 1; } if(strstr($group_permission,"H")) { return 0; } else if(strstr($group_permission,"A")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"A")) { return 1; } break; case 'R': if(strstr($id_permission,"H")) { return 0; } else if(strstr($id_permission,"R")) { return 1; } else if(strstr($id_permission,"U")) { return 1; } if(strstr($group_permission,"H")) { return 0; } else if(strstr($group_permission,"R")) { return 1; } else if(strstr($group_permission,"U")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"R")) { return 1; } else if(strstr($default_permission,"U")) { return 1; } break; case 'U': if(strstr($id_permission,"H")) { return 0; } else if(strstr($id_permission,"U")) { return 1; } if(strstr($group_permission,"H")) { return 0; } else if(strstr($group_permission,"U")) { return 1; } if(strstr($default_permission,"H")) { return 0; } else if(strstr($default_permission,"U")) { return 1; } break; default: return 0; } return 0; } /* function check_right($right,$permission,$id) { global $USER_DETAILS; if($id!=0) { $sql="select * from rights where name='$right' and permission in ('H') and id=$id and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); if(DBnum_rows($result)>0) { return 0; } } $sql="select permission from rights where name='Default permission' and userid=".$USER_DETAILS["userid"]; $result=DBselect($sql); $default_permission="H"; if(DBnum_rows($result)>0) { $default_permission=""; while($row=DBfetch($result)) { $default_permission=$default_permission.$row["permission"]; } } if($permission=='R') { $cond="'R','U'"; } else { $cond="'".$permission."'"; } $sql="select * from rights where name='$right' and permission in ($cond) and (id=$id or id=0) and userid=".$USER_DETAILS["userid"]; // echo $sql; $result=DBselect($sql); if(DBnum_rows($result)>0) { return 1; } else { if(strstr($default_permission,"A")&&($permission=="A")) { return 1; } if(strstr($default_permission,"R")&&($permission=="R")) { return 1; } if(strstr($default_permission,"U")&&($permission=="R")) { return 1; } if(strstr($default_permission,"U")&&($permission=="U")) { return 1; } return 0; } } */ function check_right_on_trigger($permission,$triggerid) { $sql="select distinct h.hostid from functions f,items i,hosts h where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid"; $result=DBselect($sql); $ok=0; while($row=DBfetch($result)) { if(check_right("Host",$permission,$row["hostid"])) { $ok=1; } } return $ok; } function get_scope_description($scope) { $desc="Unknown"; if($scope==2) { $desc="All"; } elseif($scope==1) { $desc="Host"; } elseif($scope==0) { $desc="Trigger"; } return $desc; } function get_service_status_description($status) { $desc="OK"; if($status==5) { $desc="Disaster"; } elseif($status==4) { $desc="Serious problem"; } elseif($status==3) { $desc="Average problem"; } elseif($status==2) { $desc="Minor problem"; } elseif($status==1) { $desc="OK"; } return $desc; } // The hash has form , function calc_trigger_hash() { $priorities=0; for($i=0;$i<=5;$i++) { $result=DBselect("select count(*) from triggers t,hosts h,items i,functions f where t.value=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status=0 and t.priority=$i"); // $priorities+=(1000^$i)*DBget_field($result,0,0); $priorities+=pow(100,$i)*DBget_field($result,0,0); // echo "$i $priorities ",DBget_field($result,0,0),"
"; // echo pow(100,5)*13; } $triggerids=""; $result=DBselect("select t.triggerid from triggers t,hosts h,items i,functions f where t.value=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status=0"); for($i=0;$i"; // echo ""; echo ""; if($ERROR_MSG=="") { echo "[$msg]"; } else { echo "[$msg. $ERROR_MSG]"; } echo ""; echo "

"; } function show_message($msg) { show_messages(TRUE,$msg,''); } function show_error_message($msg) { show_messages(FALSE,'',$msg); } function validate_float($str) { // echo "Validating float:$str
"; if (eregi('^([0-9]+)((\.)?)([0-9]*[KMG]{0,1})$', $str, &$arr)) { return 0; } else { return -1; } } // Does expression match server:key.function(param) ? function validate_simple_expression($expression) { global $ERROR_MSG; // echo "Validating simple:$expression
"; // Before str() // if (eregi('^\{([0-9a-zA-Z[.-.]\_\.]+)\:([]\[0-9a-zA-Z\_\/\.\,]+)\.((diff)|(min)|(max)|(last)|(prev))\(([0-9\.]+)\)\}$', $expression, &$arr)) // if (eregi('^\{([0-9a-zA-Z[.-.]\_\.]+)\:([]\[0-9a-zA-Z\_\/\.\,]+)\.((diff)|(min)|(max)|(last)|(prev)|(str))\(([0-9a-zA-Z\.\_\/\,]+)\)\}$', $expression, &$arr)) if (eregi('^\{([0-9a-zA-Z\_\.-]+)\:([]\[0-9a-zA-Z\_\/\.\,\:\(\) -]+)\.([a-z]{3,9})\(([0-9a-zA-Z\_\/\.\,]+)\)\}$', $expression, &$arr)) { $host=$arr[1]; $key=$arr[2]; $function=$arr[3]; $parameter=$arr[4]; // echo $host,"
"; // echo $key,"
"; // echo $function,"
"; // echo $parameter,"
"; $sql="select count(*) from hosts h,items i where h.host='$host' and i.key_='$key' and h.hostid=i.hostid"; $result=DBselect($sql); if(DBget_field($result,0,0)!=1) { $ERROR_MSG="No such host ($host) or monitored parameter ($key)"; return -1; } if( ($function!="last")&& ($function!="diff")&& ($function!="min") && ($function!="max") && ($function!="avg") && ($function!="sum") && ($function!="count") && ($function!="prev")&& ($function!="delta")&& ($function!="change")&& ($function!="abschange")&& ($function!="nodata")&& ($function!="time")&& ($function!="dayofweek")&& ($function!="date")&& ($function!="now")&& ($function!="str")) { $ERROR_MSG="Unknown function [$function]"; return -1; } if(( $function!="str") && (validate_float($parameter)!=0) ) { $ERROR_MSG="[$parameter] is not a float"; return -1; } } else { $ERROR_MSG="Expression [$expression] does not match to [server:key.func(param)]"; return -1; } return 0; } function validate_expression($expression) { global $ERROR_MSG; // echo "Validating expression: $expression
"; $ok=0; // Replace all {server:key.function(param)} with 0 while($ok==0) { // echo "Expression:$expression
"; $arr=""; if (eregi('^((.)*)(\{((.)*)\})((.)*)$', $expression, &$arr)) { // for($i=0;$i<20;$i++) // { // if($arr[$i]) // echo " $i: ",$arr[$i],"
"; // } if(validate_simple_expression($arr[3])!=0) { return -1; } $expression=$arr[1]."0".$arr[6]; } else { $ok=1; } } // echo "Result:$expression

"; $ok=0; while($ok==0) { // Replace all with 0 // echo "Expression:$expression
"; $arr=""; if (eregi('^((.)*)([0-9\.]+[A-Z]{0,1})([\&\|\>\<\=\+\-\*\/\#]{1})([0-9\.]+[A-Z]{0,1})((.)*)$', $expression, &$arr)) { // echo "OK
"; // for($i=0;$i<50;$i++) // { // if($arr[$i]!="") // echo " $i: ",$arr[$i],"
"; // } if(validate_float($arr[3])!=0) { $ERROR_MSG="[".$arr[3]."] is not a float"; return -1; } if(validate_float($arr[5])!=0) { $ERROR_MSG="[".$arr[5]."] is not a float"; return -1; } $expression=$arr[1]."(0)".$arr[6]; } else { $ok=1; } // Replace all (float) with 0 // echo "Expression2:[$expression]
"; $arr=""; if (eregi('^((.)*)(\(([0-9\.]+)\))((.)*)$', $expression, &$arr)) { // echo "OK
"; // for($i=0;$i<30;$i++) // { // if($arr[$i]!="") // echo " $i: ",$arr[$i],"
"; // } if(validate_float($arr[4])!=0) { $ERROR_MSG="[".$arr[4]."] is not a float"; return -1; } $expression=$arr[1]."0".$arr[5]; $ok=0; } else { $ok=1; } } // echo "Result:$expression

"; if($expression=="0") { return 0; } return 1; } function cr() { echo "\n"; } function check_authorisation() { global $page; global $PHP_AUTH_USER,$PHP_AUTH_PW; global $USER_DETAILS; global $_COOKIE; global $_GET; // global $sessionid; if(isset($_COOKIE["sessionid"])) { $sessionid=$_COOKIE["sessionid"]; } else { unset($sessionid); } if(isset($sessionid)) { $sql="select u.userid,u.alias,u.name,u.surname from sessions s,users u where s.sessionid='$sessionid' and s.userid=u.userid and s.lastaccess+900>".time(); $result=DBselect($sql); if(DBnum_rows($result)==1) { // setcookie("sessionid",$sessionid,time()+3600); setcookie("sessionid",$sessionid); $sql="update sessions set lastaccess=".time()." where sessionid='$sessionid'"; DBexecute($sql); $USER_DETAILS["userid"]=DBget_field($result,0,0); $USER_DETAILS["alias"]=DBget_field($result,0,1); $USER_DETAILS["name"]=DBget_field($result,0,2); $USER_DETAILS["surname"]=DBget_field($result,0,3); return; } else { setcookie("sessionid",$sessionid,time()-3600); unset($sessionid); } } $sql="select u.userid,u.alias,u.name,u.surname from users u where u.alias='guest'"; $result=DBselect($sql); if(DBnum_rows($result)==1) { $USER_DETAILS["userid"]=DBget_field($result,0,0); $USER_DETAILS["alias"]=DBget_field($result,0,1); $USER_DETAILS["name"]=DBget_field($result,0,2); $USER_DETAILS["surname"]=DBget_field($result,0,3); return; } if($page["file"]!="index.php") { echo ""; } show_special_header("Login",0,1,1); show_error_message("Login name or password is incorrect"); insert_login_form(); show_footer(); exit; } # Header for HTML pages function show_header($title,$refresh,$nomenu) { show_special_header($title,$refresh,$nomenu,0); } function show_special_header($title,$refresh,$nomenu,$noauth) { global $page; global $USER_DETAILS; if($noauth!=1) { check_authorisation(); } ?> \n"; echo "$title [refreshed every $refresh sec]\n"; } else { echo "$title\n"; } echo ""; ?> array( "label"=>"View", "pages"=>array("overview.php","latest.php","tr_status.php","queue.php","latestalarms.php","alerts.php","maps.php","charts.php","screens.php","srv_status.php","alarms.php","history.php","tr_comments.php","report3.php"), "level2"=>array( array("label"=>"Overview","url"=>"overview.php"), array("label"=>"Latest data","url"=>"latest.php"), array("label"=>"Triggers","url"=>"tr_status.php?onlytrue=true&noactions=true&compact=true"), array("label"=>"Queue","url"=>"queue.php"), array("label"=>"Events","url"=>"latestalarms.php"), array("label"=>"Actions","url"=>"alerts.php"), array("label"=>"Maps","url"=>"maps.php"), array("label"=>"Graphs","url"=>"charts.php"), array("label"=>"Screens","url"=>"screens.php"), array("label"=>"IT Services","url"=>"srv_status.php") ) ), "reports"=>array( "label"=>"Reports", "pages"=>array("report1.php","report2.php"), "level2"=>array( array("label"=>"Status of ZABBIX","url"=>"report1.php"), array("label"=>"Availability report","url"=>"report2.php") ) ), "configuration"=>array( "label"=>"Configuration", "pages"=>array("config.php","users.php","audit.php","hosts.php","items.php","triggers.php","sysmaps.php","graphs.php","screenconf.php","services.php","sysmap.php","media.php","screenedit.php","actions.php","graph.php"), "level2"=>array( array("label"=>"General","url"=>"config.php"), array("label"=>"Users","url"=>"users.php"), array("label"=>"Audit","url"=>"audit.php"), array("label"=>"Hosts","url"=>"hosts.php"), array("label"=>"Items","url"=>"items.php"), array("label"=>"Triggers","url"=>"triggers.php"), array("label"=>"Maps","url"=>"sysmaps.php"), array("label"=>"Graphs","url"=>"graphs.php"), array("label"=>"Screens","url"=>"screenconf.php"), array("label"=>"IT Services","url"=>"services.php") ) ), "login"=>array( "label"=>"Login", "pages"=>array("index.php"), "level2"=>array( array("label"=>"Login","url"=>"index.php"), ) ), ); ?>
ZABBIX |Help|
$sub) { // Check permissions if($label=="configuration") { if( !check_anyright("Configuration of Zabbix","U") &&!check_anyright("User","U") &&!check_anyright("Host","U") &&!check_anyright("Graph","U") &&!check_anyright("Screen","U") &&!check_anyright("Network map","U") &&!check_anyright("Service","U") ) { continue; } if( !check_anyright("Default permission","R") &&!check_anyright("Host","R") ) { continue; } } // End of check permissions $active=0; foreach($sub["pages"] as $label2) { if($page["file"]==$label2) { $active=1; $active_level1=$label; } } if($active==1) echo ""; else echo ""; $i++; } ?>

$from and clock<$till order by clock"; } else { $sql="select clock,value from history_str where itemid=$itemid and clock>$from and clock<$till order by clock"; } $result=DBselect($sql); echo "

\n";
		for($i=0;$i10 to something like localhost:procload.last(0)>10

	function	explode_exp ($expression, $html)
	{
#		echo "EXPRESSION:",$expression,"
"; $functionid=''; $exp=''; $state=''; for($i=0;$i".DBget_field($res1,0,0).":".DBget_field($res1,0,1).".".DBget_field($res1,0,2)."(".DBget_field($res1,0,3).")}"; } else { $exp=$exp."{".DBget_field($res1,0,0).":".DBget_field($res1,0,1).".".DBget_field($res1,0,2)."(".DBget_field($res1,0,3).")}"; } } continue; } if($state == "FUNCTIONID") { $functionid=$functionid.$expression[$i]; continue; } $exp=$exp.$expression[$i]; } # echo "EXP:",$exp,"
"; return $exp; } # Translate localhost:procload.last(0)>10 to {12}>10 function implode_exp ($expression, $triggerid) { // echo "Expression:$expression
"; $exp=''; $state=""; for($i=0;$i"; // echo "KEY:$key
"; // echo "FUNCTION:$function
"; // echo "PARAMETER:$parameter
"; $state=''; $sql="select i.itemid from items i,hosts h where i.key_='$key' and h.host='$host' and h.hostid=i.hostid"; # echo $sql,"
"; $res=DBselect($sql); $itemid=DBget_field($res,0,0); # echo "ITEMID:$itemid
"; # $sql="select functionid,count(*) from functions where function='$function' and parameter=$parameter group by 1"; # echo $sql,"
"; # $res=DBselect($sql); # # if(DBget_field($res,0,1)>0) # { # $functionid=DBget_field($res,0,0); # } # else # { $sql="insert into functions (itemid,triggerid,function,parameter) values ($itemid,$triggerid,'$function','$parameter')"; # echo $sql,"
"; $res=DBexecute($sql); if(!$res) { # echo "ERROR
"; return $res; } $functionid=DBinsert_id($res,"functions","functionid"); # } # echo "FUNCTIONID:$functionid
"; $exp=$exp.'{'.$functionid.'}'; continue; } if($expression[$i] == '(') { if($state == "FUNCTION") { $state='PARAMETER'; continue; } } if($expression[$i] == ')') { if($state == "PARAMETER") { $state=''; continue; } } if(($expression[$i] == ':') && ($state == "HOST")) { $state="KEY"; continue; } if($expression[$i] == '.') { if($state == "KEY") { $state="FUNCTION"; continue; } // Support for '.' in KEY if($state == "FUNCTION") { $state="FUNCTION"; $key=$key.".".$function; $function=""; continue; } } if($state == "HOST") { $host=$host.$expression[$i]; continue; } if($state == "KEY") { $key=$key.$expression[$i]; continue; } if($state == "FUNCTION") { $function=$function.$expression[$i]; continue; } if($state == "PARAMETER") { $parameter=$parameter.$expression[$i]; continue; } $exp=$exp.$expression[$i]; } return $exp; } function update_trigger_comments($triggerid,$comments) { global $ERROR_MSG; if(!check_right("Trigger comment","U",$triggerid)) { $ERROR_MSG="Insufficient permissions"; return 0; } $comments=addslashes($comments); $sql="update triggers set comments='$comments' where triggerid=$triggerid"; return DBexecute($sql); } # Update Trigger status function update_trigger_status($triggerid,$status) { global $ERROR_MSG; if(!check_right_on_trigger("U",$triggerid)) { $ERROR_MSG="Insufficient permissions"; return 0; } add_alarm($triggerid,2); $sql="update triggers set status=$status where triggerid=$triggerid"; return DBexecute($sql); } # Update Item status function update_item_status($itemid,$status) { global $ERROR_MSG; if(!check_right("Item","U",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } $sql="update items set status=$status where itemid=$itemid"; return DBexecute($sql); } # "Processor load on %s is 5" to "Processor load on www.sf.net is 5" function expand_trigger_description_simple($triggerid) { $sql="select distinct t.description,h.host from triggers t,functions f,items i,hosts h where t.triggerid=$triggerid and f.triggerid=t.triggerid and f.itemid=i.itemid and i.hostid=h.hostid"; // echo $sql; $result=DBselect($sql); $row=DBfetch($result); // $description=str_replace("%s",$row["host"],$row["description"]); $search=array("{HOSTNAME}"); $replace=array($row["host"]); // $description = str_replace($search, $replace,$row["description"]); $description = str_replace("{HOSTNAME}", $row["host"],$row["description"]); return $description; } # "Processor load on %s is 5" to "Processor load on www.sf.net is 5" function expand_trigger_description($triggerid) { $description=expand_trigger_description_simple($triggerid); $description=stripslashes(htmlspecialchars($description)); return $description; } function update_trigger_value_to_unknown_by_hostid($hostid) { $sql="select distinct t.triggerid from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.hostid=$hostid"; $result=DBselect($sql); while($row=DBfetch($result)) { $sql="update triggers set value=2 where triggerid=".$row["triggerid"]; DBexecute($sql); } } # Update Host status function update_host_status($hostid,$status) { global $ERROR_MSG; if(!check_right("Host","U",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } $sql="select status from hosts where hostid=$hostid"; $result=DBselect($sql); $old_status=DBget_field($result,0,0); if($status != $old_status) { update_trigger_value_to_unknown_by_hostid($hostid); $sql="update hosts set status=$status where hostid=$hostid and status!=".HOST_STATUS_DELETED; return DBexecute($sql); } else { return 1; } } # Update Item definition function update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends) { global $ERROR_MSG; if(!check_right("Item","U",$itemid)) { $ERROR_MSG="Insufficient permissions"; return 0; } if($delay<1) { $ERROR_MSG="Delay cannot be less than 1 second"; return 0; } if( ($snmp_port<1)||($snmp_port>65535)) { $ERROR_MSG="Invalid SNMP port"; return 0; } if($value_type == ITEM_VALUE_TYPE_STR) { $delta=0; } $key=addslashes($key); $description=addslashes($description); $snmpv3_securityname=addslashes($snmpv3_securityname); $snmpv3_authpassphrase=addslashes($snmpv3_authpassphrase); $snmpv3_privpassphrase=addslashes($snmpv3_privpassphrase); $sql="update items set description='$description',key_='$key',hostid=$hostid,delay=$delay,history=$history,nextcheck=0,status=$status,type=$type,snmp_community='$snmp_community',snmp_oid='$snmp_oid',value_type=$value_type,trapper_hosts='$trapper_hosts',snmp_port=$snmp_port,units='$units',multiplier=$multiplier,delta=$delta,snmpv3_securityname='$snmpv3_securityname',snmpv3_securitylevel=$snmpv3_securitylevel,snmpv3_authpassphrase='$snmpv3_authpassphrase',snmpv3_privpassphrase='$snmpv3_privpassphrase',formula='$formula',trends=$trends where itemid=$itemid"; return DBexecute($sql); } # Add Action function add_action( $triggerid, $userid, $good, $delay, $subject, $message, $scope, $severity, $recipient, $usrgrpid) { global $ERROR_MSG; if(!check_right_on_trigger("A",$triggerid)) { $ERROR_MSG="Insufficient permissions"; return 0; } if($recipient == RECIPIENT_TYPE_USER) { $id = $userid; } else { $id = $usrgrpid; } if($scope==2) { $sql="insert into actions (triggerid,userid,good,delay,nextcheck,subject,message,scope,severity,recipient) values (0,$id,$good,$delay,0,'*Automatically generated*','*Automatically generated*',$scope,$severity,$recipient)"; return DBexecute($sql); } elseif($scope==1) { $sql="select h.hostid from triggers t,hosts h,functions f,items i where f.triggerid=t.triggerid and h.hostid=i.hostid and i.itemid=f.itemid and t.triggerid=$triggerid"; // echo "$sql
"; $result=DBselect($sql); while($row=DBfetch($result)) { $sql="insert into actions (triggerid,userid,good,delay,nextcheck,subject,message,scope,severity,recipient) values (".$row["hostid"].",$id,$good,$delay,0,'*Automatically generated*','*Automatically generated*',$scope,$severity,$recipient)"; // echo "$sql
"; DBexecute($sql); } return TRUE; } else { $sql="insert into actions (triggerid,userid,good,delay,nextcheck,subject,message,scope,severity,recipient) values ($triggerid,$id,$good,$delay,0,'$subject','$message',$scope,$severity,$recipient)"; return DBexecute($sql); } } # Return TRUE if triggerid is a reason why the service is not OK # Warning: recursive function function does_service_depend_on_the_service($serviceid,$serviceid2) { # echo "Serviceid:$serviceid Triggerid:$serviceid2
"; $service=get_service_by_serviceid($serviceid); # echo "Service status:".$service["status"]."
"; if($service["status"]==0) { return FALSE; } if($serviceid==$serviceid2) { if($service["status"]>0) { return TRUE; } } $sql="select serviceupid from services_links where servicedownid=$serviceid2 and soft=0"; # echo $sql."
"; $result=DBselect($sql); while($row=DBfetch($result)) { if(does_service_depend_on_the_service($serviceid,$row["serviceupid"]) == TRUE) { return TRUE; } } return FALSE; } function service_has_parent($serviceid) { $sql="select count(*) from services_links where servicedownid=$serviceid"; $result=DBselect($sql); if(DBget_field($result,0,0)>0) { return TRUE; } return FALSE; } function service_has_no_this_parent($parentid,$serviceid) { $sql="select count(*) from services_links where serviceupid=$parentid and servicedownid=$serviceid"; $result=DBselect($sql); if(DBget_field($result,0,0)>0) { return FALSE; } return TRUE; } function delete_service_link($linkid) { $sql="delete from services_links where linkid=$linkid"; return DBexecute($sql); } function delete_service($serviceid) { $sql="delete from services_links where servicedownid=$serviceid or serviceupid=$serviceid"; $result=DBexecute($sql); if(!$result) { return $result; } $sql="delete from services where serviceid=$serviceid"; return DBexecute($sql); } function update_service($serviceid,$name,$triggerid,$linktrigger,$algorithm,$showsla,$goodsla,$sortorder) { if( isset($linktrigger)&&($linktrigger=="on") ) { // No mistake here $triggerid=$triggerid; } else { $triggerid='NULL'; } if( isset($showsla)&&($showsla=="on") ) { $showsla=1; } else { $showsla=0; } $sql="update services set name='$name',triggerid=$triggerid,status=0,algorithm=$algorithm,showsla=$showsla,goodsla=$goodsla,sortorder=$sortorder where serviceid=$serviceid"; return DBexecute($sql); } function add_service($serviceid,$name,$triggerid,$linktrigger,$algorithm,$showsla,$goodsla,$sortorder) { if( isset($showsla)&&($showsla=="on") ) { $showsla=1; } else { $showsla=0; } if( isset($linktrigger)&&($linktrigger=="on") ) { // $trigger=get_trigger_by_triggerid($triggerid); // $description=$trigger["description"]; // if( strstr($description,"%s")) // { $description=expand_trigger_description($triggerid); // } $description=addslashes($description); $sql="insert into services (name,triggerid,status,algorithm,showsla,goodsla,sortorder) values ('$description',$triggerid,0,$algorithm,$showsla,$goodsla,$sortorder)"; } else { $sql="insert into services (name,status,algorithm,showsla,goodsla,sortorder) values ('$name',0,$algorithm,$showsla,$goodsla,$sortorder)"; } $result=DBexecute($sql); if(!$result) { return FALSE; } $id=DBinsert_id($result,"services","serviceid"); if(isset($serviceid)) { add_service_link($id,$serviceid,0); } return $id; } function add_host_to_services($hostid,$serviceid) { $sql="select distinct t.triggerid,t.description from triggers t,hosts h,items i,functions f where h.hostid=$hostid and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid"; $result=DBselect($sql); while($row=DBfetch($result)) { $serviceid2=add_service($serviceid,$row["description"],$row["triggerid"],"on",0,"off",99,0); // add_service_link($serviceid2,$serviceid,0); } return 1; } function is_service_hardlinked($serviceid) { $sql="select count(*) from services_links where servicedownid=$serviceid and soft=0"; $result=DBselect($sql); if(DBget_field($result,0,0)>0) { return TRUE; } return FALSE; } function add_image($name,$imagetype,$files) { global $ERROR_MSG; if(isset($files)) { if($files["image"]["error"]==0) if($files["image"]["size"]<1024*1024) { $image=addslashes(fread(fopen($files["image"]["tmp_name"],"r"),filesize($files["image"]["tmp_name"]))); $sql="insert into images (name,imagetype,image) values ('$name',$imagetype,'$image')"; return DBexecute($sql); } else { $ERROR_MSG="Image size must be less than 1Mb"; return FALSE; } } else { $ERROR_MSG="Select image to download"; return FALSE; } } function delete_image($imageid) { $sql="delete from images where imageid=$imageid"; return DBexecute($sql); } function add_service_link($servicedownid,$serviceupid,$softlink) { global $ERROR_MSG; if( ($softlink==0) && (is_service_hardlinked($servicedownid)==TRUE) ) { return FALSE; } if($servicedownid==$serviceupid) { $ERROR_MSG="Cannot link service to itself."; return FALSE; } $sql="insert into services_links (servicedownid,serviceupid,soft) values ($servicedownid,$serviceupid,$softlink)"; return DBexecute($sql); } # Update Action function update_action( $actionid, $triggerid, $userid, $good, $delay, $subject, $message, $scope, $severity, $recipient, $usrgrpid) { delete_action($actionid); return add_action( $triggerid, $userid, $good, $delay, $subject, $message, $scope, $severity, $recipient, $usrgrpid); } function delete_graphs_item($gitemid) { $sql="delete from graphs_items where gitemid=$gitemid"; return DBexecute($sql); } # Delete Graph function delete_graph($graphid) { $sql="delete from graphs_items where graphid=$graphid"; $result=DBexecute($sql); if(!$result) { return $result; } $sql="delete from graphs where graphid=$graphid"; return DBexecute($sql); } # Delete System Map function delete_sysmap( $sysmapid ) { $sql="delete from sysmaps where sysmapid=$sysmapid"; $result=DBexecute($sql); if(!$result) { return $result; } $sql="delete from sysmaps_hosts where sysmapid=$sysmapid"; $result=DBexecute($sql); if(!$result) { return $result; } $sql="delete from sysmaps_links where sysmapid=$sysmapid"; return DBexecute($sql); } # Delete Alert by actionid function delete_alert_by_actionid( $actionid ) { $sql="delete from alerts where actionid=$actionid"; return DBexecute($sql); } function delete_rights_by_userid($userid ) { $sql="delete from rights where userid=$userid"; return DBexecute($sql); } # Delete Action by userid function delete_actions_by_userid( $userid ) { $sql="select actionid from actions where userid=$userid"; $result=DBexecute($sql); for($i=0;$i0) // { // return FALSE; // } // It was wrong - was deleting all dependencies // $sql="select triggerid_down,triggerid_up from trigger_depends where triggerid_up=$triggerid_up or triggerid_down=$triggerid_down"; // $result=DBexecute($sql); // for($i=0;$i3 function add_additional_dependencies($triggerid_down,$triggerid_up) { $sql="select triggerid_down from trigger_depends where triggerid_up=$triggerid_down"; $result=DBselect($sql); for($i=0;$i0) { $ERROR_MSG="An item with the same Key already exists for this host. The key must be unique."; return 0; } if($delay<1) { $ERROR_MSG="Delay cannot be less than 1 second"; return 0; } if( ($snmp_port<1)||($snmp_port>65535)) { $ERROR_MSG="Invalid SNMP port"; return 0; } if($value_type == ITEM_VALUE_TYPE_STR) { $delta=0; } $key=addslashes($key); $description=addslashes($description); $snmpv3_securityname=addslashes($snmpv3_securityname); $snmpv3_authpassphrase=addslashes($snmpv3_authpassphrase); $snmpv3_privpassphrase=addslashes($snmpv3_privpassphrase); $sql="insert into items (description,key_,hostid,delay,history,nextcheck,status,type,snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase,formula,trends) values ('$description','$key',$hostid,$delay,$history,0,$status,$type,'$snmp_community','$snmp_oid',$value_type,'$trapper_hosts',$snmp_port,'$units',$multiplier,$delta,'$snmpv3_securityname',$snmpv3_securitylevel,'$snmpv3_authpassphrase','$snmpv3_privpassphrase','$formula',$trends)"; $result=DBexecute($sql); return DBinsert_id($result,"items","itemid"); } # Delete Function definition function delete_function_by_triggerid($triggerid) { $sql="delete from functions where triggerid=$triggerid"; return DBexecute($sql); } function delete_actions_by_triggerid($triggerid) { $sql="delete from actions where triggerid=$triggerid and scope=0"; return DBexecute($sql); } function delete_alarms_by_triggerid($triggerid) { $sql="delete from alarms where triggerid=$triggerid"; return DBexecute($sql); } # Delete Function and Trigger definitions by itemid function delete_triggers_by_itemid($itemid) { $sql="select triggerid from functions where itemid=$itemid"; $result=DBselect($sql); for($i=0;$i"; $result=DBexecute($sql); if(!$result) { return $result; } $triggerid=DBinsert_id($result,"triggers","triggerid"); # echo $triggerid,"
"; add_alarm($triggerid,2); $expression=implode_exp($expression,$triggerid); $sql="update triggers set expression='$expression' where triggerid=$triggerid"; # echo $sql,"
"; $triggerid=DBexecute($sql); reset_items_nextcheck($triggerid); return $triggerid; } # Delete Trigger definition function delete_trigger($triggerid) { global $ERROR_MSG; $sql="select count(*) from trigger_depends where triggerid_down=$triggerid or triggerid_up=$triggerid"; $result=DBexecute($sql); if(DBget_field($result,0,0)>0) { $ERROR_MSG="Delete dependencies first"; return FALSE; } $result=delete_function_by_triggerid($triggerid); if(!$result) { return $result; } $result=delete_alarms_by_triggerid($triggerid); if(!$result) { return $result; } $result=delete_actions_by_triggerid($triggerid); if(!$result) { return $result; } $result=delete_services_by_triggerid($triggerid); if(!$result) { return $result; } $sql="update sysmaps_links set triggerid=NULL where triggerid=$triggerid"; DBexecute($sql); $sql="delete from triggers where triggerid=$triggerid"; return DBexecute($sql); } # Update Trigger definition function update_trigger($triggerid,$expression,$description,$priority,$status,$comments,$url) { global $ERROR_MSG; if(!check_right_on_trigger("U",$triggerid)) { $ERROR_MSG="Insufficient permissions"; return 0; } $result=delete_function_by_triggerid($triggerid); if(!$result) { return $result; } $expression=implode_exp($expression,$triggerid); add_alarm($triggerid,2); // $sql="update triggers set expression='$expression',description='$description',priority=$priority,status=$status,comments='$comments',url='$url' where triggerid=$triggerid"; reset_items_nextcheck($triggerid); $sql="update triggers set expression='$expression',description='$description',priority=$priority,status=$status,comments='$comments',url='$url',value=2 where triggerid=$triggerid"; return DBexecute($sql); } # Update User definition function update_user($userid,$name,$surname,$alias,$passwd, $url) { global $ERROR_MSG; if(!check_right("User","U",$userid)) { $ERROR_MSG="Insufficient permissions"; return 0; } if($passwd=="") { $sql="update users set name='$name',surname='$surname',alias='$alias',url='$url' where userid=$userid"; } else { $passwd=md5($passwd); $sql="update users set name='$name',surname='$surname',alias='$alias',passwd='$passwd',url='$url' where userid=$userid"; } return DBexecute($sql); } # Add permission function add_permission($userid,$right,$permission,$id) { $sql="insert into rights (userid,name,permission,id) values ($userid,'$right','$permission',$id)"; return DBexecute($sql); } # Add User definition function add_user($name,$surname,$alias,$passwd,$url) { global $ERROR_MSG; if(!check_right("User","A",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } $passwd=md5($passwd); $sql="insert into users (name,surname,alias,passwd,url) values ('$name','$surname','$alias','$passwd','$url')"; return DBexecute($sql); } # Update Graph function update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax) { global $ERROR_MSG; if(!check_right("Graph","U",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } $sql="update graphs set name='$name',width=$width,height=$height,yaxistype=$yaxistype,yaxismin=$yaxismin,yaxismax=$yaxismax where graphid=$graphid"; return DBexecute($sql); } # Update System Map function update_sysmap($sysmapid,$name,$width,$height,$background,$label_type) { global $ERROR_MSG; if(!check_right("Network map","U",$sysmapid)) { $ERROR_MSG="Insufficient permissions"; return 0; } $sql="update sysmaps set name='$name',width=$width,height=$height,background='$background',label_type=$label_type where sysmapid=$sysmapid"; return DBexecute($sql); } # Add Graph function add_graph($name,$width,$height,$yaxistype,$yaxismin,$yaxismax) { global $ERROR_MSG; if(!check_right("Graph","A",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } $sql="insert into graphs (name,width,height,yaxistype,yaxismin,yaxismax) values ('$name',$width,$height,$yaxistype,$yaxismin,$yaxismax)"; $result=DBexecute($sql); return DBinsert_id($result,"graphs","graphid"); } function update_graph_item($gitemid,$itemid,$color,$drawtype,$sortorder) { $sql="update graphs_items set itemid=$itemid,color='$color',drawtype=$drawtype,sortorder=$sortorder where gitemid=$gitemid"; return DBexecute($sql); } function add_item_to_graph($graphid,$itemid,$color,$drawtype,$sortorder) { $sql="insert into graphs_items (graphid,itemid,color,drawtype,sortorder) values ($graphid,$itemid,'$color',$drawtype,$sortorder)"; return DBexecute($sql); } # Add System Map function add_sysmap($name,$width,$height,$background,$label_type) { global $ERROR_MSG; if(!check_right("Network map","A",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } $sql="insert into sysmaps (name,width,height,background,label_type) values ('$name',$width,$height,'$background',$label_type)"; return DBexecute($sql); } function add_link($sysmapid,$shostid1,$shostid2,$triggerid,$drawtype_off,$color_off,$drawtype_on,$color_on) { if($triggerid == 0) { $sql="insert into sysmaps_links (sysmapid,shostid1,shostid2,triggerid,drawtype_off,color_off,drawtype_on,color_on) values ($sysmapid,$shostid1,$shostid2,NULL,$drawtype_off,'$color_off',$drawtype_on,'$color_on')"; } else { $sql="insert into sysmaps_links (sysmapid,shostid1,shostid2,triggerid,drawtype_off,color_off,drawtype_on,color_on) values ($sysmapid,$shostid1,$shostid2,$triggerid,$drawtype_off,'$color_off',$drawtype_on,'$color_on')"; } return DBexecute($sql); } function delete_link($linkid) { $sql="delete from sysmaps_links where linkid=$linkid"; return DBexecute($sql); } # Add host-template linkage function add_template_linkage($hostid,$templateid,$items,$triggers,$actions,$graphs,$screens) { $sql="insert into hosts_templates (hostid,templateid,items,triggers,actions,graphs,screens) values ($hostid,$templateid,$items,$triggers,$actions,$graphs,$screens)"; return DBexecute($sql); } # Update host-template linkage function update_template_linkage($hosttemplateid,$hostid,$templateid,$items,$triggers,$actions,$graphs,$screens) { $sql="update hosts_templates set hostid=$hostid,templateid=$templateid,items=$items,triggers=$triggers,actions=$actions,graphs=$graphs,screens=$screens where hosttemplateid=$hosttemplateid"; return DBexecute($sql); } # Delete host-template linkage function delete_template_linkage($hosttemplateid) { $sql="delete from hosts_templates where hosttemplateid=$hosttemplateid"; return DBexecute($sql); } # Add Host to system map function add_host_to_sysmap($sysmapid,$hostid,$label,$x,$y,$icon,$url,$icon_on) { $sql="insert into sysmaps_hosts (sysmapid,hostid,label,x,y,icon,url,icon_on) values ($sysmapid,$hostid,'$label',$x,$y,'$icon','$url','$icon_on')"; return DBexecute($sql); } function update_sysmap_host($shostid,$sysmapid,$hostid,$label,$x,$y,$icon,$url,$icon_on) { $sql="update sysmaps_hosts set hostid=$hostid,label='$label',x=$x,y=$y,icon='$icon',url='$url',icon_on='$icon_on' where shostid=$shostid"; return DBexecute($sql); } # Add everything based on host_templateid function add_using_host_template($hostid,$host_templateid) { global $ERROR_MSG; if(!isset($host_templateid)||($host_templateid==0)) { $ERROR_MSG="Select template first"; return 0; } $host=get_host_by_hostid($hostid); $sql="select itemid from items where hostid=$host_templateid"; $result=DBselect($sql); while($row=DBfetch($result)) { $item=get_item_by_itemid($row["itemid"]); $itemid=add_item($item["description"],$item["key_"],$hostid,$item["delay"],$item["history"],$item["status"],$item["type"],$item["snmp_community"],$item["snmp_oid"],$item["value_type"],"",$item["snmp_port"],$item["units"],$item["multiplier"],$item["delta"],$item["snmpv3_securityname"],$item["snmpv3_securitylevel"],$item["snmpv3_authpassphrase"],$item["snmpv3_privpassphrase"],$item["formula"],$item["trends"]); $sql="select distinct t.triggerid from triggers t,functions f where f.itemid=".$row["itemid"]." and f.triggerid=t.triggerid"; $result2=DBselect($sql); while($row2=DBfetch($result2)) { $trigger=get_trigger_by_triggerid($row2["triggerid"]); // Cannot use add_trigger here $description=$trigger["description"]; # $description=str_replace("%s",$host["host"],$description); $sql="insert into triggers (description,priority,status,comments,url,value) values ('".addslashes($description)."',".$trigger["priority"].",".$trigger["status"].",'".addslashes($trigger["comments"])."','".addslashes($trigger["url"])."',2)"; $result4=DBexecute($sql); $triggerid=DBinsert_id($result4,"triggers","triggerid"); $sql="select functionid from functions where triggerid=".$row2["triggerid"]." and itemid=".$row["itemid"]; $result3=DBselect($sql); while($row3=DBfetch($result3)) { $function=get_function_by_functionid($row3["functionid"]); $sql="insert into functions (itemid,triggerid,function,parameter) values ($itemid,$triggerid,'".$function["function"]."','".$function["parameter"]."')"; $result4=DBexecute($sql); $functionid=DBinsert_id($result4,"functions","functionid"); $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$triggerid"; DBexecute($sql); $trigger["expression"]=str_replace("{".$row3["functionid"]."}","{".$functionid."}",$trigger["expression"]); $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$triggerid"; DBexecute($sql); } # Add actions $sql="select actionid from actions where scope=0 and triggerid=".$row2["triggerid"]; $result3=DBselect($sql); while($row3=DBfetch($result3)) { $action=get_action_by_actionid($row3["actionid"]); $userid=$action["userid"]; $scope=$action["scope"]; $severity=$action["severity"]; $good=$action["good"]; $delay=$action["delay"]; $subject=addslashes($action["subject"]); $message=addslashes($action["message"]); $recipient=$action["recipient"]; $sql="insert into actions (triggerid, userid, scope, severity, good, delay, subject, message,recipient) values ($triggerid,$userid,$scope,$severity,$good,$delay,'$subject','$message',$recipient)"; // echo "$sql
"; $result4=DBexecute($sql); $actionid=DBinsert_id($result4,"actions","actionid"); } } } return TRUE; } function add_group_to_host($hostid,$newgroup) { $sql="insert into groups (groupid,name) values (NULL,'$newgroup')"; $result=DBexecute($sql); if(!$result) { return $result; } $groupid=DBinsert_id($result,"groupd","groupid"); $sql="insert into hosts_groups (hostid,groupid) values ($hostid,$groupid)"; $result=DBexecute($sql); return $result; } function update_user_groups($usrgrpid,$users) { $count=count($users); $sql="delete from users_groups where usrgrpid=$usrgrpid"; DBexecute($sql); for($i=0;$i<$count;$i++) { $sql="insert into users_groups (usrgrpid,userid) values ($usrgrpid,".$users[$i].")"; DBexecute($sql); } } function update_host_groups_by_groupid($groupid,$hosts) { $count=count($hosts); $sql="delete from hosts_groups where groupid=$groupid"; DBexecute($sql); for($i=0;$i<$count;$i++) { $sql="insert into hosts_groups (hostid,groupid) values (".$hosts[$i].",$groupid)"; DBexecute($sql); } } function update_host_groups($hostid,$groups) { $count=count($groups); $sql="delete from hosts_groups where hostid=$hostid"; DBexecute($sql); for($i=0;$i<$count;$i++) { $sql="insert into hosts_groups (hostid,groupid) values ($hostid,".$groups[$i].")"; DBexecute($sql); } } function add_host_group($name,$hosts) { global $ERROR_MSG; // if(!check_right("Host","A",0)) // { // $ERROR_MSG="Insufficient permissions"; // return 0; // } $sql="select * from groups where name='$name'"; $result=DBexecute($sql); if(DBnum_rows($result)>0) { $ERROR_MSG="Group '$name' already exists"; return 0; } $sql="insert into groups (name) values ('$name')"; $result=DBexecute($sql); if(!$result) { return $result; } $groupid=DBinsert_id($result,"groups","groupid"); update_host_groups_by_groupid($groupid,$hosts); return $result; } function add_user_group($name,$users) { global $ERROR_MSG; if(!check_right("Host","A",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } $sql="select * from usrgrp where name='$name'"; $result=DBexecute($sql); if(DBnum_rows($result)>0) { $ERROR_MSG="Group '$name' already exists"; return 0; } $sql="insert into usrgrp (name) values ('$name')"; $result=DBexecute($sql); if(!$result) { return $result; } $usrgrpid=DBinsert_id($result,"usrgrp","usrgrpid"); update_user_groups($usrgrpid,$users); return $result; } function update_host_group($groupid,$name,$users) { global $ERROR_MSG; // if(!check_right("Host","U",0)) // { // $ERROR_MSG="Insufficient permissions"; // return 0; // } $sql="select * from groups where name='$name' and groupid<>$groupid"; $result=DBexecute($sql); if(DBnum_rows($result)>0) { $ERROR_MSG="Group '$name' already exists"; return 0; } $sql="update groups set name='$name' where groupid=$groupid"; $result=DBexecute($sql); if(!$result) { return $result; } update_host_groups_by_groupid($groupid,$users); return $result; } function update_user_group($usrgrpid,$name,$users) { global $ERROR_MSG; if(!check_right("Host","U",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } $sql="select * from usrgrp where name='$name' and usrgrpid<>$usrgrpid"; $result=DBexecute($sql); if(DBnum_rows($result)>0) { $ERROR_MSG="Group '$name' already exists"; return 0; } $sql="update usrgrp set name='$name' where usrgrpid=$usrgrpid"; $result=DBexecute($sql); if(!$result) { return $result; } update_user_groups($usrgrpid,$users); return $result; } # Add Host definition function add_host($host,$port,$status,$useip,$ip,$host_templateid,$newgroup,$groups) { global $ERROR_MSG; if(!check_right("Host","A",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } if (!eregi('^([0-9a-zA-Z\_\.-]+)$', $host, &$arr)) { $ERROR_MSG="Hostname should contain 0-9a-zA-Z_.- characters only"; return 0; } $sql="select * from hosts where host='$host'"; $result=DBexecute($sql); if(DBnum_rows($result)>0) { $ERROR_MSG="Host '$host' already exists"; return 0; } if( isset($useip) && ($useip=="on") ) { $useip=1; } else { $useip=0; } $sql="insert into hosts (host,port,status,useip,ip,disable_until,available) values ('$host',$port,$status,$useip,'$ip',0,".HOST_AVAILABLE_UNKNOWN.")"; $result=DBexecute($sql); if(!$result) { return $result; } $hostid=DBinsert_id($result,"hosts","hostid"); if($host_templateid != 0) { add_templates_to_host($hostid,$host_templateid); // $result=add_using_host_template($hostid,$host_templateid); sync_host_with_templates($hostid); } update_host_groups($hostid,$groups); if($newgroup != "") { add_group_to_host($hostid,$newgroup); } update_profile("HOST_PORT",$port); return $result; } function update_host($hostid,$host,$port,$status,$useip,$ip,$newgroup,$groups) { global $ERROR_MSG; if(!check_right("Host","U",$hostid)) { $ERROR_MSG="Insufficient permissions"; return 0; } if (!eregi('^([0-9a-zA-Z\_\.-]+)$', $host, &$arr)) { $ERROR_MSG="Hostname should contain 0-9a-zA-Z_.- characters only"; return 0; } $sql="select * from hosts where host='$host' and hostid<>$hostid"; $result=DBexecute($sql); if(DBnum_rows($result)>0) { $ERROR_MSG="Host '$host' already exists"; return 0; } if($useip=="on") { $useip=1; } else { $useip=0; } $sql="update hosts set host='$host',port=$port,useip=$useip,ip='$ip' where hostid=$hostid"; $result=DBexecute($sql); update_host_status($hostid, $status); update_host_groups($hostid,$groups); if($newgroup != "") { add_group_to_host($hostid,$newgroup); } return $result; } # Add templates linked to template host to the host function add_templates_to_host($hostid,$host_templateid) { $sql="select * from hosts_templates where hostid=$host_templateid"; $result=DBselect($sql); while($row=DBfetch($result)) { add_template_linkage($hostid,$row["templateid"],$row["items"],$row["triggers"],$row["actions"], $row["graphs"],$row["screens"]); } } # Sync host with hard-linked templates function sync_host_with_templates($hostid) { $sql="select * from hosts_templates where hostid=$hostid"; $result=DBselect($sql); while($row=DBfetch($result)) { sync_host_with_template($hostid,$row["templateid"],$row["items"],$row["triggers"],$row["actions"], $row["graphs"],$row["screens"]); } } # Sync host with hard-linked template function sync_host_with_template($hostid,$templateid,$items,$triggers,$actions,$graphs,$screens) { global $ERROR_MSG; if(!isset($templateid)||($templateid==0)) { $ERROR_MSG="Select template first"; return 0; } $host=get_host_by_hostid($hostid); $sql="select itemid from items where hostid=$templateid"; $result=DBselect($sql); while($row=DBfetch($result)) { $item=get_item_by_itemid($row["itemid"]); $itemid=add_item($item["description"],$item["key_"],$hostid,$item["delay"],$item["history"],$item["status"],$item["type"],$item["snmp_community"],$item["snmp_oid"],$item["value_type"],"",$item["snmp_port"],$item["units"],$item["multiplier"],$item["delta"],$item["snmpv3_securityname"],$item["snmpv3_securitylevel"],$item["snmpv3_authpassphrase"],$item["snmpv3_privpassphrase"],$item["formula"],$item["trends"]); $sql="select distinct t.triggerid from triggers t,functions f where f.itemid=".$row["itemid"]." and f.triggerid=t.triggerid"; $result2=DBselect($sql); while($row2=DBfetch($result2)) { $trigger=get_trigger_by_triggerid($row2["triggerid"]); // Cannot use add_trigger here $description=$trigger["description"]; # $description=str_replace("%s",$host["host"],$description); $sql="insert into triggers (description,priority,status,comments,url,value) values ('".addslashes($description)."',".$trigger["priority"].",".$trigger["status"].",'".addslashes($trigger["comments"])."','".addslashes($trigger["url"])."',2)"; $result4=DBexecute($sql); $triggerid=DBinsert_id($result4,"triggers","triggerid"); $sql="select functionid from functions where triggerid=".$row2["triggerid"]." and itemid=".$row["itemid"]; $result3=DBselect($sql); while($row3=DBfetch($result3)) { $function=get_function_by_functionid($row3["functionid"]); $sql="insert into functions (itemid,triggerid,function,parameter) values ($itemid,$triggerid,'".$function["function"]."','".$function["parameter"]."')"; $result4=DBexecute($sql); $functionid=DBinsert_id($result4,"functions","functionid"); $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$triggerid"; DBexecute($sql); $trigger["expression"]=str_replace("{".$row3["functionid"]."}","{".$functionid."}",$trigger["expression"]); $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$triggerid"; DBexecute($sql); } # Add actions $sql="select actionid from actions where scope=0 and triggerid=".$row2["triggerid"]; $result3=DBselect($sql); while($row3=DBfetch($result3)) { $action=get_action_by_actionid($row3["actionid"]); $userid=$action["userid"]; $scope=$action["scope"]; $severity=$action["severity"]; $good=$action["good"]; $delay=$action["delay"]; $subject=addslashes($action["subject"]); $message=addslashes($action["message"]); $recipient=$action["recipient"]; $sql="insert into actions (triggerid, userid, scope, severity, good, delay, subject, message,recipient) values ($triggerid,$userid,$scope,$severity,$good,$delay,'$subject','$message',$recipient)"; // echo "$sql
"; $result4=DBexecute($sql); $actionid=DBinsert_id($result4,"actions","actionid"); } } } # Add graphs $sql="select distinct g.graphid from graphs g,items i, hosts h,graphs_items gi where h.hostid=$templateid and i.hostid=h.hostid and gi.itemid=i.itemid and g.graphid=gi.graphid"; $result=DBselect($sql); while($row=DBfetch($result)) { $graph=get_graph_by_graphid($row["graphid"]); $graphid=add_graph($graph["name"],$graph["width"],$graph["height"],$graph["yaxistype"],$graph["yaxismin"],$graph["yaxismax"]); $sql="select distinct gi.gitemid from graphs_items gi,graphs g,items i,hosts h where gi.itemid=i.itemid and h.hostid=$templateid and i.hostid=h.hostid and g.graphid=gi.graphid and gi.itemid=i.itemid and g.graphid=".$graph["graphid"]; $result2=DBselect($sql); while($row=DBfetch($result2)) { $gitem=get_graphitem_by_gitemid($row["gitemid"]); $item=get_item_by_itemid($gitem["itemid"]); $sql="select * from items where key_='".$item["key_"]."' and hostid=$hostid"; $result3=DBselect($sql); if(DBnum_rows($result3)==1) { $row2=DBfetch($result3); add_item_to_graph($graphid,$row2["itemid"],$gitem["color"],$gitem["drawtype"],$gitem["sortorder"]); } } } return TRUE; } # Delete Media definition by mediatypeid function delete_media_by_mediatypeid($mediatypeid) { $sql="delete from media where mediatypeid=$mediatypeid"; return DBexecute($sql); } # Delete alrtes by mediatypeid function delete_alerts_by_mediatypeid($mediatypeid) { $sql="delete from alerts where mediatypeid=$mediatypeid"; return DBexecute($sql); } function get_mediatype_by_mediatypeid($mediatypeid) { global $ERROR_MSG; $sql="select * from media_type where mediatypeid=$mediatypeid"; $result=DBselect($sql); if(DBnum_rows($result) == 1) { return DBfetch($result); } else { $ERROR_MSG="No media type with with mediatypeid=[$mediatypeid]"; } return $item; } # Delete media type function delete_mediatype($mediatypeid) { delete_media_by_mediatypeid($mediatypeid); delete_alerts_by_mediatypeid($mediatypeid); $sql="delete from media_type where mediatypeid=$mediatypeid"; return DBexecute($sql); } # Update media type function update_mediatype($mediatypeid,$type,$description,$smtp_server,$smtp_helo,$smtp_email,$exec_path) { $description=addslashes($description); $sql="update media_type set type=$type,description='$description',smtp_server='$smtp_server',smtp_helo='$smtp_helo',smtp_email='$smtp_email',exec_path='$exec_path' where mediatypeid=$mediatypeid"; return DBexecute($sql); } # Add Media type function add_mediatype($type,$description,$smtp_server,$smtp_helo,$smtp_email,$exec_path) { $description=addslashes($description); $sql="insert into media_type (type,description,smtp_server,smtp_helo,smtp_email,exec_path) values ($type,'$description','$smtp_server','$smtp_helo','$smtp_email','$exec_path')"; return DBexecute($sql); } # Add Media definition function add_media( $userid, $mediatypeid, $sendto, $severity, $active) { $c=count($severity); $s=0; for($i=0;$i<$c;$i++) { $s=$s|pow(2,(int)$severity[$i]); } $sql="insert into media (userid,mediatypeid,sendto,active,severity) values ($userid,'$mediatypeid','$sendto',$active,$s)"; return DBexecute($sql); } # Update Media definition function update_media($mediaid, $userid, $mediatypeid, $sendto, $severity, $active) { $c=count($severity); $s=0; for($i=0;$i<$c;$i++) { $s=$s|pow(2,(int)$severity[$i]); } $sql="update media set userid=$userid, mediatypeid=$mediatypeid, sendto='$sendto', active=$active,severity=$s where mediaid=$mediaid"; return DBexecute($sql); } # Delete Media definition function delete_media($mediaid) { $sql="delete from media where mediaid=$mediaid"; return DBexecute($sql); } # Delete Media definition by userid function delete_media_by_userid($userid) { $sql="delete from media where userid=$userid"; return DBexecute($sql); } function delete_profiles_by_userid($userid) { $sql="delete from profiles where userid=$userid"; return DBexecute($sql); } # Update configuration // function update_config($smtp_server,$smtp_helo,$smtp_email,$alarm_history,$alert_history) function update_config($alarm_history,$alert_history) { global $ERROR_MSG; if(!check_right("Configuration of Zabbix","U",0)) { $ERROR_MSG="Insufficient permissions"; return 0; } // $sql="update config set smtp_server='$smtp_server',smtp_helo='$smtp_helo',smtp_email='$smtp_email',alarm_history=$alarm_history,alert_history=$alert_history"; $sql="update config set alarm_history=$alarm_history,alert_history=$alert_history"; return DBexecute($sql); } # Activate Media function activate_media($mediaid) { $sql="update media set active=0 where mediaid=$mediaid"; return DBexecute($sql); } # Disactivate Media function disactivate_media($mediaid) { $sql="update media set active=1 where mediaid=$mediaid"; return DBexecute($sql); } function delete_sysmaps_host_by_hostid($hostid) { $sql="select shostid from sysmaps_hosts where hostid=$hostid"; $result=DBselect($sql); while($row=DBfetch($result)) { $sql="delete from sysmaps_links where shostid1=".$row["shostid"]." or shostid2".$row["shostid"]; DBexecute($sql); } $sql="delete from sysmaps_hosts where hostid=$hostid"; return DBexecute($sql); } # Delete Host from sysmap definition function delete_sysmaps_host($shostid) { $sql="delete from sysmaps_links where shostid1=$shostid or shostid2=$shostid"; $result=DBexecute($sql); if(!$result) { return $result; } $sql="delete from sysmaps_hosts where shostid=$shostid"; return DBexecute($sql); } function delete_groups_by_hostid($hostid) { $sql="select groupid from hosts_groups where hostid=$hostid"; $result=DBselect($sql); while($row=DBfetch($result)) { $sql="delete from hosts_groups where hostid=$hostid and groupid=".$row["groupid"]; DBexecute($sql); $sql="select count(*) as count from hosts_groups where groupid=".$row["groupid"]; $result2=DBselect($sql); $row2=DBfetch($result2); if($row2["count"]==0) { $sql="delete from groups where groupid=".$row["groupid"]; DBexecute($sql); } } } # Delete Host function delete_host($hostid) { global $DB_TYPE; if($DB_TYPE=="MYSQL") { $sql="update hosts set status=".HOST_STATUS_DELETED.",host=concat(host,\" [DELETED]\") where hostid=$hostid"; } else { $sql="update hosts set status=".HOST_STATUS_DELETED.",host=host||' [DELETED]' where hostid=$hostid"; } return DBexecute($sql); // $sql="select itemid from items where hostid=$hostid"; // $result=DBselect($sql); // if(!$result) // { // return $result; // } // for($i=0;$i"; cr(); echo ""; cr(); echo ""; cr(); // echo " "; cr(); } function show_table2_h_delimiter() { // echo ""; cr(); echo ""; cr(); // echo ""; echo ""; cr(); // echo " "; cr(); } function show_table3_h_delimiter($width=10) { ?> "; cr(); echo ""; cr(); cr(); */ } function show_table_v_delimiter($colspan=1) { // echo ""; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); // echo ""; cr(); } function show_table2_v_delimiter($rownum=0) { // echo ""; cr(); echo ""; cr(); echo ""; cr(); if($rownum%2 == 1) { echo ""; } else { echo ""; } cr(); // echo ""; echo ""; cr(); // echo ""; cr(); } function show_table3_v_delimiter() { ?> "; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); cr();*/ } function show_table2_v_delimiter2() { // echo ""; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); // echo ""; echo ""; cr(); // echo ""; cr(); } // function show_table2_header_begin() function show_form_begin($help="") { ?>

"; echo ""; echo "
\"?\""; } } function show_table_header_begin() { echo ""; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); echo "
"; cr(); echo ""; cr(); echo ""; cr(); // echo ""; cr(); echo ""; cr(); echo "
"; echo ""; cr(); // echo " "; cr(); } function show_header2($h1, $h2, $h2_form1, $h2_form2) { ?> "; } function show_table2_header_end() { // echo " "; cr(); echo ""; cr(); echo ""; cr(); echo ""; cr(); echo "
"; echo "

"; cr(); } function show_table_header_end() { /* cr(); echo "
"; cr();*/ echo "
"; } function show_table_header($title) { ?> "; echo ""; echo ""; echo "Year"; echo ""; echo "Month"; echo ""; echo "Day"; echo ""; echo "Hour"; echo ""; echo "Period:"; echo ""; echo ""; echo ""; } # Show History Graph function show_history($itemid,$from,$period,$diff) { if (!isset($from)) { $from=0; $till="NOW"; } else { $till=time(NULL)-$from*3600; $till=date("d M - H:i:s",$till); } if (!isset($period)) { $period=3600; show_table_header("TILL $till (LAST HOUR)"); } else { $tmp=$period/3600; show_table_header("TILL $till ($tmp HOURs)"); } // echo("


"); echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
"; if($diff==0) { echo ""; } else { echo ""; } echo "
"; echo "
"; echo("
"); insert_time_navigator($itemid,$period,$from); echo("
"); } # Show history function show_freehist($itemid,$period) { show_form_begin("history.period"); echo "Choose period"; show_table2_v_delimiter(); echo "
"; echo ""; echo "Period in seconds"; show_table2_h_delimiter(); echo ""; show_table2_v_delimiter(); echo "From (in hours)"; show_table2_h_delimiter(); echo ""; show_table2_v_delimiter2(); echo "Press "; echo " to see values in plain text"; show_table2_header_end(); show_footer(); } # Show in plain text function show_plaintxt($itemid,$period) { show_form_begin("history.plaim"); echo "Data in plain text format"; show_table2_v_delimiter(); echo ""; echo ""; echo ""; echo "From: (yyyy/mm/dd - HH:MM)"; show_table2_h_delimiter(); echo "/"; echo "/"; echo " - "; echo ":"; echo ""; show_table2_v_delimiter(); echo "Till: (yyyy/mm/dd - HH:MM)"; show_table2_h_delimiter(); echo "/"; echo "/"; echo " - "; echo ":"; echo ""; show_table2_v_delimiter2(); echo "Press to see data in "; echo ""; show_table2_header_end(); show_footer(); } function show_footer() { global $USER_DETAILS; ?>

"; $result=DBselect($sql); if(DBget_field($result,0,0)>0) { $sql="select value from service_alarms where serviceid=$serviceid and clock=".DBget_field($result,0,1); $result2=DBselect($sql); // Assuring that we get very latest service value. There could be several with the same timestamp // $value=DBget_field($result2,0,0); for($i=0;$i1 PROBLEMS if($state<=1) { $ok_time+=$diff; $state=$value; } else { $problem_time+=$diff; $state=$value; } } // echo $problem_time,"-",$ok_time,"
"; if(DBnum_rows($result)==0) { if(get_last_service_value($serviceid,$period_start)<=1) { $ok_time=$period_end-$period_start; } else { $problem_time=$period_end-$period_start; } } else { if($state<=1) { $ok_time=$ok_time+$period_end-$time; } else { $problem_time=$problem_time+$period_end-$time; } } // echo $problem_time,"-",$ok_time,"
"; $total_time=$problem_time+$ok_time; if($total_time==0) { $ret["problem_time"]=0; $ret["ok_time"]=0; $ret["problem"]=0; $ret["ok"]=0; } else { $ret["problem_time"]=$problem_time; $ret["ok_time"]=$ok_time; $ret["problem"]=(100*$problem_time)/$total_time; $ret["ok"]=(100*$ok_time)/$total_time; } return $ret; } // If $period_start=$period_end=0, then take maximum period function calculate_availability($triggerid,$period_start,$period_end) { if(($period_start==0)&&($period_end==0)) { $sql="select count(*),min(clock),max(clock) from alarms where triggerid=$triggerid"; } else { $sql="select count(*),min(clock),max(clock) from alarms where triggerid=$triggerid and clock>=$period_start and clock<=$period_end"; } // echo $sql,"
"; $result=DBselect($sql); if(DBget_field($result,0,0)>0) { $min=DBget_field($result,0,1); $max=DBget_field($result,0,2); } else { if(($period_start==0)&&($period_end==0)) { $max=time(); $min=$max-24*3600; } else { $ret["true_time"]=0; $ret["false_time"]=0; $ret["unknown_time"]=0; $ret["true"]=0; $ret["false"]=0; $ret["unknown"]=100; return $ret; } } $sql="select clock,value from alarms where triggerid=$triggerid and clock>=$min and clock<=$max"; // echo " $sql
"; $result=DBselect($sql); // echo $sql,"
"; // -1,0,1 $state=-1; $true_time=0; $false_time=0; $unknown_time=0; $time=$min; if(($period_start==0)&&($period_end==0)) { $max=time(); } for($i=0;$i"; echo "function Confirm(msg)"; echo "{"; echo " if(confirm( msg))"; echo " {"; echo " return true;"; echo " }"; echo " else"; echo " {"; echo " return false;"; echo " }"; echo "}"; echo ""; } function get_map_imagemap($sysmapid) { $map="\n"; $result=DBselect("select h.host,sh.shostid,sh.sysmapid,sh.hostid,sh.label,sh.x,sh.y,h.status,sh.icon,sh.url from sysmaps_hosts sh,hosts h where sh.sysmapid=$sysmapid and h.hostid=sh.hostid"); for($i=0;$i"; } /* if(function_exists("imagecreatetruecolor")&&@imagecreatetruecolor(1,1)) { $map=$map."\n\"$host\""; } else { $map=$map."\n\"$host\""; }*/ } } $map=$map."\n"; return $map; } /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ if(function_exists("imagesetstyle")) { function DashedLine($image,$x1,$y1,$x2,$y2,$color) { // Style for dashed lines // $style = array($color, $color, $color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); $style = array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); ImageSetStyle($image, $style); ImageLine($image,$x1,$y1,$x2,$y2,IMG_COLOR_STYLED); } } else { function DashedLine($image,$x1,$y1,$x2,$y2,$color) { ImageDashedLine($image,$x1,$y1,$x2,$y2,$color); } } function time_navigator($resource="graphid",$id) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
"; echo "
"; echo "".S_PERIOD.": "; $hour=3600; $a=array(S_1H=>3600,S_2H=>2*3600,S_4H=>4*3600,S_8H=>8*3600,S_12H=>12*3600, S_24H=>24*3600,S_WEEK_SMALL=>7*24*3600,S_MONTH_SMALL=>31*24*3600,S_YEAR_SMALL=>365*24*3600); foreach($a as $label=>$sec) { echo "["; if($_GET["period"]>$sec) { $tmp=$_GET["period"]-$sec; echo("-"); } else { echo "-"; } echo(""); echo($label.""); $tmp=$_GET["period"]+$sec; echo("+"); echo "] "; } echo("
"); echo "
"; echo "".nbsp(S_KEEP_PERIOD).": "; if($_GET["keep"] == 1) { echo("[".S_ON_C."]"); } else { echo("[".S_OFF_C."]"); } echo "
"; if(isset($_GET["stime"])) { echo "
" ; echo "".S_MOVE.": " ; $day=24; // $a already defined // $a=array("1h"=>1,"2h"=>2,"4h"=>4,"8h"=>8,"12h"=>12, // "24h"=>24,"week"=>7*24,"month"=>31*24,"year"=>365*24); foreach($a as $label=>$hours) { echo "["; $stime=$_GET["stime"]; $tmp=mktime(substr($stime,8,2),substr($stime,10,2),0,substr($stime,4,2),substr($stime,6,2),substr($stime,0,4)); $tmp=$tmp-3600*$hours; $tmp=date("YmdHi",$tmp); echo("-"); echo($label); $stime=$_GET["stime"]; $tmp=mktime(substr($stime,8,2),substr($stime,10,2),0,substr($stime,4,2),substr($stime,6,2),substr($stime,0,4)); $tmp=$tmp+3600*$hours; $tmp=date("YmdHi",$tmp); echo("+"); echo "] "; } echo("
"); } else { echo "
"; echo "".S_MOVE.": "; $day=24; // $a already defined // $a=array("1h"=>1,"2h"=>2,"4h"=>4,"8h"=>8,"12h"=>12, // "24h"=>24,"week"=>7*24,"month"=>31*24,"year"=>365*24); foreach($a as $label=>$hours) { echo "["; $tmp=$_GET["from"]+$hours; echo("-"); echo($label); if($_GET["from"]>=$hours) { $tmp=$_GET["from"]-$hours; echo("+"); } else { echo "+"; } echo "] "; } echo("
"); } echo "
"; // echo("
"); echo ""; echo ""; echo ""; if(isset($_GET["stime"])) { echo ""; } else { echo ""; } echo " "; echo ""; echo ""; // echo("
"); echo "
"; } function ImageOut($image) { // ImageJPEG($image); ImagePNG($image); } function add_audit($action,$resource,$details) { global $USER_DETAILS; $details=addslashes($details); $userid=$USER_DETAILS["userid"]; $clock=time(); $sql="insert into audit (userid,clock,action,resource,details) values ($userid,$clock,$action,$resource,'$details')"; return DBexecute($sql); } ?>