diff options
| author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2001-04-16 17:45:23 +0000 |
|---|---|---|
| committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2001-04-16 17:45:23 +0000 |
| commit | a2f46eff39e547e40d042ce97851805b9f9efea4 (patch) | |
| tree | 674ce1bfe3af9dd6ca058b44d5d0fdf9e7b4ba29 /frontends/php | |
| parent | a23282b7b988f6bbe5e7f98170c88e0dfe24fc3b (diff) | |
Added PostgreSQL support for PHP frontend. Added database abstraction layer in frontend/php/include/db.inc.
git-svn-id: svn://svn.zabbix.com/trunk@42 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
| -rw-r--r-- | frontends/php/actions.html | 49 | ||||
| -rw-r--r-- | frontends/php/alarms.html | 17 | ||||
| -rw-r--r-- | frontends/php/alerts.html | 16 | ||||
| -rw-r--r-- | frontends/php/chart.html | 8 | ||||
| -rw-r--r-- | frontends/php/config.html | 11 | ||||
| -rw-r--r-- | frontends/php/history.html | 23 | ||||
| -rw-r--r-- | frontends/php/hosts.html | 22 | ||||
| -rw-r--r-- | frontends/php/include/config.inc | 325 | ||||
| -rw-r--r-- | frontends/php/include/db.inc | 119 | ||||
| -rw-r--r-- | frontends/php/items.html | 49 | ||||
| -rw-r--r-- | frontends/php/latest.html | 30 | ||||
| -rw-r--r-- | frontends/php/latestalarms.html | 12 | ||||
| -rw-r--r-- | frontends/php/media.html | 10 | ||||
| -rw-r--r-- | frontends/php/queue.html | 18 | ||||
| -rw-r--r-- | frontends/php/tr_status.html | 47 | ||||
| -rw-r--r-- | frontends/php/triggers.html | 29 | ||||
| -rw-r--r-- | frontends/php/users.html | 14 |
17 files changed, 415 insertions, 384 deletions
diff --git a/frontends/php/actions.html b/frontends/php/actions.html index d21bac62..36f9c618 100644 --- a/frontends/php/actions.html +++ b/frontends/php/actions.html @@ -25,10 +25,9 @@ if(!isset($description)) { $sql="select description, expression from triggers where triggerid=$triggerid"; - $result=mysql_query($sql,$mysql); - $row=mysql_fetch_row($result); - $description=$row[0]; - $expression=$row[1]; + $result=DBselect($sql); + $description=DBget_field($result,0,0); + $expression=DBget_field($result,0,1); } ?> @@ -42,7 +41,7 @@ <? $sql="select a.actionid,a.triggerid,u.alias,a.good,a.delay,a.subject,a.message from actions a,users u where a.userid=u.userid and a.triggerid=$triggerid order by u.alias, a.good desc"; - $result=mysql_query($sql,$mysql); + $result=DBselect($sql); echo "<CENTER>"; echo "<TABLE BORDER=0 WIDTH=100% BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; @@ -54,18 +53,18 @@ echo "<TD><b>Message</b></TD>"; echo "<TD><b>Actions</b></TD>"; echo "</TR>"; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $actid=$row[0]; + $actid=DBget_field($result,$i,0); $good="OFF"; - if($row[3]) + if(DBget_field($result,$i,3)) { $good="ON"; } - $to=$row[2]; - $delay=$row[4]; - $subject=$row[5]; - $msg=$row[6]; + $to=DBget_field($result,$i,2); + $delay=DBget_field($result,$i,4); + $subject=DBget_field($result,$i,5); + $msg=DBget_field($result,$i,6); if($actionid==$actid) { @@ -112,16 +111,14 @@ if(isset($actionid)) { $sql="select a.actionid,a.triggerid,a.good,a.delay,a.subject,a.message from actions a where a.actionid=$actionid"; - $result=mysql_query($sql,$mysql); - - $row=mysql_fetch_row($result); - - $actionid=$row[0]; - $triggerid=$row[1]; - $good=$row[2]; - $delay=$row[3]; - $subject=$row[4]; - $message=$row[5]; + $result=DBselect($sql); + + $actionid=DBget_field($result,0,0); + $triggerid=DBget_field($rsult,0,1); + $good=DBget_field($result,0,2); + $delay=DBget_field($result,0,3); + $subject=DBget_field($result,0,4); + $message=DBget_field($result,0,5); } echo "<br>"; show_table2_header_begin(); @@ -136,11 +133,11 @@ echo "<SELECT NAME=\"userid\" SIZE=\"1\">"; $sql="select userid,alias from users order by alias"; - $result=mysql_query($sql,$mysql); - while($row=mysql_fetch_row($result)) + $result=DBselect($sql); + for($i=0;$i<DBnum_rows($result);$i++) { - $id=$row[0]; - $name=$row[1]; + $id=DBget_field($result,$i,0); + $name=DBget_field($result,$i,1); if($name==$sto) { echo "<option value=\"$id\" SELECTED>$name"; diff --git a/frontends/php/alarms.html b/frontends/php/alarms.html index da7e63a5..08f26515 100644 --- a/frontends/php/alarms.html +++ b/frontends/php/alarms.html @@ -22,12 +22,11 @@ { if((!$Expression)||(!$Description)||(!$Priority)) { - $result=mysql_query("select expression,description,priority from triggers where triggerid=$triggerid",$mysql); - $row=mysql_fetch_row($result); + $result=DBselect("select expression,description,priority from triggers where triggerid=$triggerid"); - if(!isset($Expression)) $Expression=$row[0]; - if(!isset($Description)) $Description=$row[1]; - if(!isset($Priority)) $Priority=$row[2]; + if(!isset($Expression)) $Expression=DBget_field($result,0,0); + if(!isset($Description)) $Description=DBget_field($result,0,1); + if(!isset($Priority)) $Priority=DBget_field($result,0,2); } } ?> @@ -59,7 +58,7 @@ <FONT COLOR="#000000"> <? $sql="select clock,istrue from alarms where triggerid=$triggerid order by clock desc $limit"; - $result=mysql_query($sql,$mysql); + $result=DBselect($sql); echo "<CENTER>"; echo "<TABLE WIDTH=100% BORDER=0 BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; @@ -74,12 +73,12 @@ $falsesum=0; $dissum=0; $clock=mktime(); - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { $lclock=$clock; - $clock=$row[0]; + $clock=DBget_field($result,$i,0); $leng=$lclock-$clock; - $status=$row[1]; + $status=DBget_field($result,$i,1); if($status==0) { echo "<TR BGCOLOR=#EEFFEE>"; } elseif($status==2) { echo "<TR BGCOLOR=#DDDDDD>"; } elseif($status==3) { echo "<TR BGCOLOR=#EEEEEE>"; } diff --git a/frontends/php/alerts.html b/frontends/php/alerts.html index 5f11ced6..23897c17 100644 --- a/frontends/php/alerts.html +++ b/frontends/php/alerts.html @@ -34,7 +34,7 @@ <FONT COLOR="#000000"> <? $sql="select a.alertid,a.clock,a.type,a.sendto,a.subject,a.message,ac.triggerid from alerts a,actions ac where a.actionid=ac.actionid order by a.clock desc $limit"; - $result=mysql_query($sql,$mysql); + $result=DBselect($sql); echo "<CENTER>"; echo "<TABLE WIDTH=100% BORDER=0 BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; @@ -45,7 +45,7 @@ echo "<TD><FONT SIZE=+1>Subject</FONT></TD>"; echo "<TD><FONT SIZE=+1>Message</FONT></TD>"; echo "</TR>"; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { if($col==1) { @@ -57,16 +57,16 @@ echo "<tr bgcolor=#EEEEEE>"; $col=1; } - $clock=$row[1]; - $type=$row[2]; + $clock=DBget_field($result,$i,1); + $type=DBget_field($result,$i,2); if($type=="EMAIL") { $type="E-mail"; } - $sendto=$row[3]; - $subject=$row[4]; - $message=$row[5]; - $triggerid=$row[6]; + $sendto=DBget_field($result,$i,3); + $subject=DBget_field($result,$i,4); + $message=DBget_field($result,$i,5); + $triggerid=DBget_field($result,$i,6); echo "<TD><a href=\"alarms.html?triggerid=$triggerid\">".date("Y.M.d H:i:s",$clock)."</a></TD>"; echo "<TD>$type</TD>"; diff --git a/frontends/php/chart.html b/frontends/php/chart.html index e4e20602..c322b4d6 100644 --- a/frontends/php/chart.html +++ b/frontends/php/chart.html @@ -46,7 +46,7 @@ $from_time = time(NULL)-$period-3600*$from; $to_time = time(NULL)-3600*$from; - $result=mysql_query("select clock,value from history where itemid=$itemid and clock>$from_time and clock<$to_time order by clock",$mysql); + $result=DBselect("select clock,value from history where itemid=$itemid and clock>$from_time and clock<$to_time order by clock"); $len=0; $maxX=-1000000000; $maxY=-1000000000; @@ -54,11 +54,11 @@ $minY=1000000000; $x=array(); $y=array(); - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { $nodata=0; - $x[$len]=$row[0]; - $y[$len]=$row[1]; + $x[$len]=DBget_field($result,$i,0); + $y[$len]=DBget_field($result,$i,1);; // echo $row[0]," - ",$y[$len],"<Br>"; if($x[$len]>$maxX) { $maxX=$x[$len]; } if($x[$len]<$minX) { $minX=$x[$len]; } diff --git a/frontends/php/config.html b/frontends/php/config.html index 5fae9542..0340e3e5 100644 --- a/frontends/php/config.html +++ b/frontends/php/config.html @@ -27,12 +27,11 @@ ?> <? - $result=mysql_query("select smtp_server,smtp_helo,smtp_email,password_required from config",$mysql); - $row=mysql_fetch_row($result); - $smtp_server=$row[0]; - $smtp_helo=$row[1]; - $smtp_email=$row[2]; - $password_required=$row[3]; + $result=DBselect("select smtp_server,smtp_helo,smtp_email,password_required from config"); + $smtp_server=DBget_field($result,0,0); + $smtp_helo=DBget_field($result,0,1); + $smtp_email=DBget_field($result,0,2); + $password_required=DBget_field($result,0,3); ?> <? diff --git a/frontends/php/history.html b/frontends/php/history.html index b45e4640..55d05363 100644 --- a/frontends/php/history.html +++ b/frontends/php/history.html @@ -9,14 +9,17 @@ exit; } - $result=mysql_query("select h.host,i.description,i.nextcheck-unix_timestamp(now()),h.hostid from items i,hosts h where i.itemid=$itemid and h.hostid=i.hostid"); - while($row=mysql_fetch_row($result)) + $now=time(); + + $result=DBselect("select h.host,i.description,i.nextcheck-$now,h.hostid from items i,hosts h where i.itemid=$itemid and h.hostid=i.hostid"); + $host=DBget_field($result,0,0); + $description=DBget_field($result,0,1); + $beforenextcheck=DBget_field($result,0,2)+5; + if($beforenextcheck<=0) { - $host=$row[0]; - $description=$row[1]; - $beforenextcheck=$row[2]+10; - $hostid=$row[3]; + $beforenextcheck=5; } + $hostid=DBget_field($result,0,3); if($action=="showhistory") { @@ -131,8 +134,8 @@ echo "</TR>"; - $result=mysql_query("select clock,value from history where itemid=$itemid and clock>$time and clock<$till order by clock desc"); - while($row=mysql_fetch_row($result)) + $result=DBselect("select clock,value from history where itemid=$itemid and clock>$time and clock<$till order by clock desc"); + for($i=0;$i<DBnum_rows($result);$i++) { if($col==1) { @@ -143,8 +146,8 @@ echo "<TR BGCOLOR=#EEEEEE>"; $col=1; } - $clock=$row[0]; - $value=$row[1]; + $clock=DBget_field($result,$i,0); + $value=DBget_field($result,$i,1); $clock=date("d M - H:i:s",$clock); echo "<TD>$clock</TD>"; echo "<TD>$value</TD>"; diff --git a/frontends/php/hosts.html b/frontends/php/hosts.html index e90c3a1e..90488bbf 100644 --- a/frontends/php/hosts.html +++ b/frontends/php/hosts.html @@ -35,9 +35,9 @@ echo "<TD WIDTH=\"10%\" NOSAVE><B>Actions</B></TD>"; echo "</TR>"; - $result=mysql_query("select h.hostid,p.platform,h.host,h.port,h.status from hosts h,platforms p where p.platformid=h.platformid order by p.platform,h.host",$mysql); + $result=DBselect("select h.hostid,p.platform,h.host,h.port,h.status from hosts h,platforms p where p.platformid=h.platformid order by p.platform,h.host"); echo "<CENTER>"; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { if($col==1) { @@ -49,11 +49,11 @@ $col=1; } - $hostid=$row[0]; - $platform=$row[1]; - $host=$row[2]; - $port=$row[3]; - $status=$row[4]; + $hostid=DBget_field($result,$i,0); + $platform=DBget_field($result,$i,1); + $host=DBget_field($result,$i,2); + $port=DBget_field($result,$i,3); + $status=DBget_field($result,$i,4); echo "<TD>$platform</TD>"; echo "<TD><a href=\"items.html?hostid=$hostid\">$host</a></TD>"; echo "<TD>$port</TD>"; @@ -81,11 +81,11 @@ echo "Platform"; show_table2_h_delimiter(); echo "<select name=\"platformid\">"; - $result=mysql_query("select platformid,platform from platforms order by platform",$mysql); - while($row=mysql_fetch_row($result)) + $result=DBselect("select platformid,platform from platforms order by platform"); + for($i=0;$i<DBnum_rows($result);$i++) { - $platformid=$row[0]; - $platform=$row[1]; + $platformid=DBget_field($result,$i,0); + $platform=DBget_field($result,$i,1); echo "<option value=\"$platformid\">$platform"; } echo "</select>"; diff --git a/frontends/php/include/config.inc b/frontends/php/include/config.inc index e22d3a73..4473d043 100644 --- a/frontends/php/include/config.inc +++ b/frontends/php/include/config.inc @@ -1,14 +1,8 @@ <? - $DB_SERVER ="localhost"; - $DB_DATABASE ="zabbix"; - $DB_USER ="root"; - $DB_PASSWORD =""; + include "include/db.inc"; $USER_DETAILS =""; - $mysql=mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD); - mysql_select_db($DB_DATABASE); - function validate_float($str) { if (eregi('^([0-9]+)((\.)?)([0-9]*)$', $str, &$arr)) @@ -24,8 +18,6 @@ // Does expression match server:key.function(param) ? function validate_simple_expression($expression) { - global $mysql; - // echo "Validating:$expression<br>"; if (eregi('^\{([0-9a-zA-Z\_\.]+)\:([0-9a-zA-Z\_]+)\.((diff)|(min)|(max)|(last)|(nodata))\(([0-9\.]+)\)\}$', $expression, &$arr)) { @@ -35,9 +27,8 @@ $parameter=$arr[9]; $sql="select count(*) from hosts h,items i where h.host='$host' and i.key_='$key' and h.hostid=i.hostid"; - $result=mysql_query($sql,$mysql); - $row=mysql_fetch_row($result); - if($row[0]!=1) + $result=DBselect($sql); + if($DBget_field($result,0,0)!=1) { return -1; } @@ -153,21 +144,19 @@ function check_authorisation() { - global $mysql; global $page; global $PHP_AUTH_USER,$PHP_AUTH_PW; global $USER_DETAILS; $sql="select g.groupid,u.userid,u.alias,u.name,u.surname from users u,groups g where u.alias='$PHP_AUTH_USER' and u.passwd='$PHP_AUTH_PW' and u.groupid=g.groupid"; - $result=mysql_query($sql,$mysql); - $row=mysql_fetch_row($result); - if($row) + $result=DBselect($sql); + if(DBnum_rows($result)==1) { - $USER_DETAILS["groupid"]=$row[0]; - $USER_DETAILS["userid"]=$row[1]; - $USER_DETAILS["alias"]=$row[2]; - $USER_DETAILS["name"]=$row[3]; - $USER_DETAILS["surname"]=$row[4]; + $USER_DETAILS["groupid"]=DBget_field($result,0,0); + $USER_DETAILS["userid"]=DBget_field($result,0,1); + $USER_DETAILS["alias"]=DBget_field($result,0,2); + $USER_DETAILS["name"]=DBget_field($result,0,3); + $USER_DETAILS["surname"]=DBget_field($result,0,4); } @@ -180,10 +169,9 @@ ($page["file"]=="index.html")) { $sql="select password_required from config"; - $result=mysql_query($sql,$mysql); - $row=mysql_fetch_row($result); + $result=DBselect($sql); - if($row[0]==0) + if(DBget_field($result,0,0)==0) { return; } @@ -194,10 +182,11 @@ { $sql="select count(*) from users u,groups g where u.alias='$PHP_AUTH_USER' and u.passwd='$PHP_AUTH_PW' and u.groupid=g.groupid and g.groupid=1"; } - $result=mysql_query($sql,$mysql); - $row=mysql_fetch_row($result); + $result=DBselect($sql); + +// echo "==",DBget_field($result,0,0),"=="; - if($row[0]!=1) + if(DBget_field($result,0,0)!=1) { Header("WWW-authenticate: basic realm=\"Zabbix\""); Header("HTTP/1.0 401 Unauthorized"); @@ -406,15 +395,13 @@ function show_plaintext($itemid, $from, $till) { - global $mysql; - - $result=mysql_query("select clock,value from history where itemid=$itemid and clock>$from and clock<$till order by clock",$mysql); + $result=DBselect("select clock,value from history where itemid=$itemid and clock>$from and clock<$till order by clock"); echo "<PRE>"; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $clock=$row[0]; - $value=$row[1]; + $clock=DBget_field($result,$i,0); + $value=DBget_field($result,$i,1); echo date("Y-m-d H:i:s",$clock); echo "\t$clock\t$value\n"; } @@ -425,8 +412,6 @@ function explode_exp ($expression, $html) { - global $mysql; - # echo "EXPRESSION:",$expression,"<Br>"; $functionid=''; @@ -443,15 +428,14 @@ { $state=''; $sql="select h.host,i.key_,f.function,f.parameter,i.itemid from items i,functions f,hosts h where functionid=$functionid and i.itemid=f.itemid and h.hostid=i.hostid"; - $res1=mysql_query($sql,$mysql); - $row1=mysql_fetch_row($res1); + $res1=DBselect($sql); if($html == 0) { - $exp=$exp."{".$row1[0].":".$row1[1].".".$row1[2]."(".$row1[3].")}"; + $exp=$exp."{".DBget_field($res1,0,0).":".DBget_field($res1,0,1).".".DBget_field($res1,0,2)."(".DBget_field($res1,0,3).")}"; } else { - $exp=$exp."{<A HREF=\"history.html?action=showhistory&itemid=$row1[4]\">".$row1[0].":".$row1[1]."</A>.<B>".$row1[2]."(</B>".$row1[3]."<B>)</B>}"; + $exp=$exp."{<A HREF=\"history.html?action=showhistory&itemid=$row1[4]\">".DBget_field($res1,0,0).":".DBget_field($res1,0,1)."</A>.<B>".DBget_field($res1,0,2)."(</B>".DBget_field($res1,0,3)."<B>)</B>}"; } continue; } @@ -470,8 +454,6 @@ function implode_exp ($expression, $triggerid) { - global $mysql; - $exp=''; for($i=0;$i<strlen($expression);$i++) { @@ -497,10 +479,9 @@ $sql="select i.itemid from items i,hosts h where i.key_='$key' and h.host='$host' and h.hostid=i.hostid"; # echo $sql,"<Br>"; - $res=mysql_query($sql,$mysql); - $row=mysql_fetch_row($res); + $res=DBselect($sql); - $itemid=$row[0]; + $itemid=DBget_field($res,0,0); # echo "ITEMID:$itemid<BR>"; # $sql="select functionid from functions where function='$function' and parameter=$parameter"; @@ -514,10 +495,10 @@ # } # else # { - $sql="insert into functions (functionid,itemid,triggerid,function,parameter) values (NULL,$itemid,$triggerid,'$function',$parameter)"; + $sql="insert into functions (itemid,triggerid,function,parameter) values ($itemid,$triggerid,'$function',$parameter)"; # echo $sql,"<Br>"; - $res=mysql_query($sql,$mysql); - $functionid=mysql_insert_id($mysql); + $res=DBexecute($sql); + $functionid=DBinsert_id($res,"functions","functionid"); # } # echo "FUNCTIONID:$functionid<BR>"; @@ -583,181 +564,149 @@ function update_trigger_status($triggerid,$status) { - global $mysql; - $sql="update triggers set istrue=$status where triggerid=$triggerid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Update Item status function update_item_status($itemid,$status) { - global $mysql; - $sql="update items set status=$status where itemid=$itemid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Update Host status function update_host_status($hostid,$status) { - global $mysql; - $sql="update hosts set status=$status where hostid=$hostid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Update Item definition function update_item($itemid,$description,$key,$hostid,$delay,$history,$status) { - global $mysql; - $sql="update items set description='$description',key_='$key',hostid=$hostid,delay=$delay,history=$history,lastdelete=0,nextcheck=0,status=$status where itemid=$itemid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Add Action function add_action( $triggerid, $userid, $good, $delay, $subject, $message ) { - global $mysql; - - $sql="insert into actions (actionid,triggerid,userid,good,delay,nextcheck,subject,message) values (NULL,$triggerid,$userid,$good,$delay,0,'$subject','$message')"; - $result=mysql_query($sql,$mysql); + $sql="insert into actions (triggerid,userid,good,delay,nextcheck,subject,message) values ($triggerid,$userid,$good,$delay,0,'$subject','$message')"; + $result=DBexecute($sql); } # Update Action function update_action( $actionid, $userid, $good, $delay, $subject, $message ) { - global $mysql; - $sql="update actions set userid=$userid,good=$good,delay=$delay,nextcheck=0,subject='$subject',message='$message' where actionid=$actionid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Delete Action by userid function delete_actions_by_userid( $userid ) { - global $mysql; - $sql="delete from actions where userid=$userid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Delete Action function delete_action( $actionid ) { - global $mysql; - $sql="delete from actions where actionid=$actionid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Delete from History function delete_history_by_itemid( $itemid ) { - global $mysql; - $sql="delete from history where itemid=$itemid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Add Item definition function add_item($description,$key,$hostid,$delay,$history,$status) { - global $mysql; - - $sql="insert into items (itemid,description,key_,hostid,delay,history,lastdelete,nextcheck,status) values (NULL,'$description','$key',$hostid,$delay,$history,0,0,$status)"; - $result=mysql_query($sql,$mysql); - return mysql_insert_id($mysql); + $sql="insert into items (description,key_,hostid,delay,history,lastdelete,nextcheck,status) values ('$description','$key',$hostid,$delay,$history,0,0,$status)"; + $result=DBexecute($sql); + return DBinsert_id($result,"items","itemid"); } # Delete Function definition function delete_function_by_triggerid($triggerid) { - global $mysql; - $sql="delete from functions where triggerid=$triggerid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Delete Function and Trigger definitions by itemid function delete_triggers_functions_by_itemid($itemid) { - global $mysql; - $sql="select triggerid from functions where itemid=$itemid"; - $result=mysql_query($sql,$mysql); - while($row=mysql_fetch_row($result)) + $result=DBselect($sql); + for($i=0;$i<DBnum_rows($result);$i++) { - delete_function_by_triggerid($row[0]); + delete_function_by_triggerid(DBget_field($result,$i,0)); } $sql="delete from functions where itemid=$itemid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Delete Item definition function delete_item($itemid) { - global $mysql; - - $sql="delete from items where itemid=$itemid"; - $result=mysql_query($sql,$mysql); delete_triggers_functions_by_itemid($itemid); delete_history_by_itemid($itemid); + $sql="delete from items where itemid=$itemid"; + $result=DBexecute($sql); } # Add alarm function add_alarm($triggerid,$istrue) { - global $mysql; - - $now=mktime(); + $now=time(); $sql="insert into alarms(triggerid,clock,istrue) values($triggerid,$now,$istrue)"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Add Trigger definition function add_trigger($expression,$description,$priority,$istrue,$comments) { - global $mysql; - - $sql="insert into triggers (triggerid,description,priority,istrue,comments) values (NULL,'$description',$priority,$istrue,'$comments')"; + $sql="insert into triggers (description,priority,istrue,comments) values ('$description',$priority,$istrue,'$comments')"; # echo $sql,"<Br>"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); - $triggerid=mysql_insert_id($mysql); + $triggerid=DBinsert_id($result,"triggers","triggerid"); $expression=implode_exp($expression,$triggerid); $sql="update triggers set expression='$expression' where triggerid=$triggerid"; # echo $sql,"<Br>"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Delete Trigger definition function delete_trigger($triggerid) { - global $mysql; - $sql="delete from triggers where triggerid=$triggerid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); delete_function_by_triggerid($triggerid); } @@ -766,8 +715,6 @@ function update_trigger($triggerid,$expression,$description,$priority,$istrue,$comments) { - global $mysql; - delete_trigger($triggerid); $triggerid=add_trigger($expression,$description,$priority,$istrue,$comments); @@ -777,10 +724,8 @@ function update_user($userid,$groupid,$name,$surname,$alias,$password) { - global $mysql; - $sql="update users set groupid=$groupid,name='$name',surname='$surname',alias='$alias',passwd='$password' where userid=$userid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); return $result; } @@ -789,10 +734,8 @@ function add_user($groupid,$name,$surname,$alias,$passwd) { - global $mysql; - - $sql="insert into users (userid,groupid,name,surname,alias,passwd) values (NULL,$groupid,'$name','$surname','$alias','$passwd')"; - $result=mysql_query($sql,$mysql); + $sql="insert into users (groupid,name,surname,alias,passwd) values ($groupid,'$name','$surname','$alias','$passwd')"; + $result=DBexecute($sql); return $result; } @@ -801,30 +744,28 @@ function add_from_templates($hostid,$platformid,$host) { - global $mysql; - - $result=mysql_query("select itemtemplateid,description,key_,delay from items_template where platformid=$platformid",$mysql); - while($row=mysql_fetch_row($result)) + $result=DBselect("select itemtemplateid,description,key_,delay from items_template where platformid=$platformid"); + for($i=0;$i<DBnum_rows($result);$i++) { - $itemtemplateid=$row[0]; - $description=$row[1]; - $key=$row[2]; - $delay=$row[3]; + $itemtemplateid=DBget_field($result,$i,0); + $description=DBget_field($result,$i,1); + $key=DBget_field($result,$i,2); + $delay=DBget_field($result,$i,3); $itemid=add_item($description,$key,$hostid,$delay,24*3600,0); - $result2=mysql_query("select triggertemplateid,description,expression from triggers_template where itemtemplateid=$itemtemplateid",$mysql); - while($row2=mysql_fetch_row($result2)) + $result2=DBselect("select triggertemplateid,description,expression from triggers_template where itemtemplateid=$itemtemplateid"); + for($j=0;$j<DBnum_rows($result2);$j++) { - $itemtemplateid=$row2[0]; - $description=$row2[1]; - $expression=$row2[2]; + $itemtemplateid=DBget_field($result2,$j,0); + $description=DBget_field($result2,$j,1); + $expression=DBget_field($result2,$j,2); - for($i=0;$i<strlen($expression);$i++) + for($z=0;$z<strlen($expression);$z++) { - if($expression[$i] == ':') + if($expression[$z] == ':') { - $expression=substr($expression,0,$i)."$host:$key".substr($expression,$i); + $expression=substr($expression,0,$z)."$host:$key".substr($expression,$z); break; } @@ -839,11 +780,9 @@ function add_host($platformid,$host,$port,$status) { - global $mysql; - - $sql="insert into hosts (hostid,platformid,host,port,status) values (NULL,$platformid,'$host',$port,$status)"; - $result=mysql_query($sql,$mysql); - $hostid=mysql_insert_id($mysql); + $sql="insert into hosts (platformid,host,port,status) values ($platformid,'$host',$port,$status)"; + $result=DBexecute($sql); + $hostid=DBinsert_id($result,"hosts","hostid"); add_from_templates($hostid,$platformid,$host); @@ -853,40 +792,32 @@ function add_media( $userid, $type, $sendto) { - global $mysql; - - $sql="insert into media (userid,mediaid,type,sendto,active) values ($userid,NULL,'$type','$sendto',0)"; - $result=mysql_query($sql,$mysql); + $sql="insert into media (userid,type,sendto,active) values ($userid,'$type','$sendto',0)"; + $result=DBexecute($sql); } # Delete Media definition function delete_media($mediaid) { - global $mysql; - $sql="delete from media where mediaid=$mediaid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Delete Media definition by userid function delete_media_by_userid($userid) { - global $mysql; - $sql="delete from media where userid=$userid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Update configuration function update_config($smtp_server,$smtp_helo,$smtp_email,$password_required) { - global $mysql; - - $sql="update config set smtp_server=\"$smtp_server\",smtp_helo=\"$smtp_helo\",smtp_email=\"$smtp_email\",password_required=$password_required"; - $result=mysql_query($sql,$mysql); + $sql="update config set smtp_server='$smtp_server',smtp_helo='$smtp_helo',smtp_email='$smtp_email',password_required=$password_required"; + $result=DBexecute($sql); } @@ -894,50 +825,42 @@ function activate_media($mediaid) { - global $mysql; - $sql="update media set active=0 where mediaid=$mediaid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Disactivate Media function disactivate_media($mediaid) { - global $mysql; - $sql="update media set active=1 where mediaid=$mediaid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Delete Host function delete_host($hostid) { - global $mysql; - $sql="select itemid from items where hostid=$hostid"; - $result=mysql_query($sql,$mysql); - while($row=mysql_fetch_row($result)) + $result=DBselect($sql); + for($i=0;$i<DBnum_rows($result);$i++) { - delete_item($row[0]); + delete_item(DBget_field($result,$i,0)); } $sql="delete from hosts where hostid=$hostid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } # Delete User definition function delete_user($userid) { - global $mysql; - delete_media_by_userid($userid); delete_actions_by_userid($userid); $sql="delete from users where userid=$userid"; - $result=mysql_query($sql,$mysql); + $result=DBexecute($sql); } function show_table_h_delimiter() @@ -1270,21 +1193,17 @@ # Insert form for Item information function insert_item_form($itemid) { - global $mysql; - if(isset($itemid)) { - mysql_select_db("monitor"); - $result=mysql_query("select i.description, i.key_, h.host, h.port, i.delay, i.history, i.status from items i,hosts h where i.itemid=$itemid and h.hostid=i.hostid",$mysql); - $row=mysql_fetch_row($result); + $result=DBselect("select i.description, i.key_, h.host, h.port, i.delay, i.history, i.status from items i,hosts h where i.itemid=$itemid and h.hostid=i.hostid"); - $description=$row[0]; - $key=$row[1]; - $host=$row[2]; - $port=$row[3]; - $delay=$row[4]; - $history=$row[5]; - $status=$row[6]; + $description=DBget_field($result,0,0); + $key=DBget_field($result,0,1); + $host=DBget_field($result,0,2); + $port=DBget_field($result,0,3); + $delay=DBget_field($result,0,4); + $history=DBget_field($result,0,5); + $status=DBget_field($result,0,6); } if( !isset($port) ) { @@ -1319,11 +1238,11 @@ echo "Host"; show_table2_h_delimiter(); echo "<select name=\"hostid\" value=\"3\">"; - $result=mysql_query("select hostid,host from hosts order by host",$mysql); - while($row=mysql_fetch_row($result)) + $result=DBselect("select hostid,host from hosts order by host"); + for($i=0;$i<DBnum_rows($result);$i++) { - $hostid_=$row[0]; - $host_=$row[1]; + $hostid_=DBget_field($result,$i,0); + $host_=DBget_field($result,$i,1); if($host==$host_) { echo "<option value=\"$hostid_\" selected>$host_"; @@ -1394,18 +1313,16 @@ # Insert form for User function insert_user_form($userid) { - global $mysql; - if(isset($userid)) { - $result=mysql_query("select u.alias,u.name,u.surname,u.passwd,g.groupid from users u,groups g where u.groupid=g.groupid and u.userid=$userid",$mysql); - $row=mysql_fetch_row($result); + echo $userid,"<br>"; + $result=DBselect("select u.alias,u.name,u.surname,u.passwd,g.groupid from users u,groups g where u.groupid=g.groupid and u.userid=$userid"); - $alias=$row[0]; - $name=$row[1]; - $surname=$row[2]; - $password=$row[3]; - $groupid_=$row[4]; + $alias=DBget_field($result,0,0); + $name=DBget_field($result,0,1); + $surname=DBget_field($result,0,2); + $password=DBget_field($result,0,3); + $groupid_=DBget_field($result,0,4); } show_table2_header_begin(); @@ -1413,7 +1330,10 @@ show_table2_v_delimiter(); echo "<form method=\"post\" action=\"users.html\">"; - echo "<input name=\"userid\" type=\"hidden\" value=$userid size=8>"; + if(isset($userid)) + { + echo "<input name=\"userid\" type=\"hidden\" value=\"$userid\" size=8>"; + } echo "Alias"; show_table2_h_delimiter(); echo "<input name=\"alias\" value=\"$alias\" size=20>"; @@ -1432,11 +1352,11 @@ echo "User group"; show_table2_h_delimiter(); echo "<select name=\"groupid\">"; - $result=mysql_query("select groupid,name from groups order by name",$mysql); - while($row=mysql_fetch_row($result)) + $result=DBselect("select groupid,name from groups order by name"); + for($i=0;$i<DBnum_rows($result);$i++) { - $groupid=$row[0]; - $name=$row[1]; + $groupid=DBget_field($result,$i,0); + $name=DBget_field($result,$i,1); if($groupid_==$groupid) { echo "<option value=\"$groupid\" selected>$name"; @@ -1472,20 +1392,17 @@ # Insert form for Trigger function insert_trigger_form($triggerid) { - global $mysql; - if(isset($triggerid)) { - $result=mysql_query("select expression,description,priority,istrue,comments from triggers where triggerid=$triggerid",$mysql); - $row=mysql_fetch_row($result); + $result=DBselect("select expression,description,priority,istrue,comments from triggers where triggerid=$triggerid"); - $expression=$row[0]; + $expression=DBget_field($result,0,0); $expression=explode_exp($expression,0); - $description=$row[1]; - $priority=$row[2]; - $istrue=$row[3]; - $comments=$row[6]; + $description=DBget_field($result,0,1); + $priority=DBget_field($result,0,2); + $istrue=DBget_field($result,0,3); + $comments=DBget_field($result,0,6); } echo "<br>"; diff --git a/frontends/php/include/db.inc b/frontends/php/include/db.inc new file mode 100644 index 00000000..b954e648 --- /dev/null +++ b/frontends/php/include/db.inc @@ -0,0 +1,119 @@ +<? + + $DB_TYPE ="POSTGRESQL"; +// $DB_TYPE ="MYSQL"; + $DB_SERVER ="localhost"; + $DB_DATABASE ="zabbix"; + $DB_USER ="zabbix"; +// $DB_USER ="root"; + $DB_PASSWORD =""; + + $USER_DETAILS =""; + + if($DB_TYPE == "MYSQL") + { + $DB=mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD); + mysql_select_db($DB_DATABASE); + } + if($DB_TYPE == "POSTGRESQL") + { + $DB=pg_pconnect("host=$DB_SERVER dbname=$DB_DATABASE user=$DB_USER password=$DB_PASSWORD"); + if(!$DB) + { + echo "Error connecting to database"; + exit; + } + } + + function DBselect($query) + { + global $DB,$DB_TYPE; + +// echo $query,"<br>"; + + if($DB_TYPE == "MYSQL") + { + $result=mysql_query($query,$DB); + return $result; + } + if($DB_TYPE == "POSTGRESQL") + { + $result=pg_exec($DB,$query); + return $result; + } + } + + function DBexecute($query) + { + global $DB,$DB_TYPE; + +// echo $query,"<br>"; + + if($DB_TYPE == "MYSQL") + { + $result=mysql_query($query,$DB); + return $result; + } + if($DB_TYPE == "POSTGRESQL") + { + $result=pg_exec($DB,$query); + return $result; + } + } + + function DBget_field($result,$rownum,$fieldnum) + { + global $DB_TYPE; + + if($DB_TYPE == "MYSQL") + { + mysql_data_seek($result,$rownum); + $row=mysql_fetch_row($result); + return $row[$fieldnum]; + } + if($DB_TYPE == "POSTGRESQL") + { + $row=pg_fetch_row($result,$rownum); + if(!$row) + { + echo "Error getting row"; + exit; + } + return $row[$fieldnum]; + } + } + + function DBnum_rows($result) + { + global $DB_TYPE; + + if($DB_TYPE == "MYSQL") + { + return mysql_num_rows($result); + } + if($DB_TYPE == "POSTGRESQL") + { + return pg_numrows($result); + } + } + + function DBinsert_id($result,$table,$field) + { + global $DB,$DB_TYPE; + + if($DB_TYPE == "MYSQL") + { + return mysql_insert_id($DB); + } + + if($DB_TYPE == "POSTGRESQL") + { + $oid=pg_getlastoid($result); +// echo "OID:$oid<br>"; + $sql="select $field from $table where oid=$oid"; + $result=DBselect($sql); + return DBget_field($result,0,0); + } + } + +?> diff --git a/frontends/php/items.html b/frontends/php/items.html index 0b218114..dd4c33ee 100644 --- a/frontends/php/items.html +++ b/frontends/php/items.html @@ -33,7 +33,7 @@ ?> <? - $result=mysql_query("select hostid,host from hosts order by host",$mysql); + $result=DBselect("select hostid,host from hosts order by host"); if(isset($hostid)) { echo "<A HREF=\"items.html\">all</A> "; @@ -42,10 +42,10 @@ { echo "<b>[<A HREF=\"items.html\">all</A>]</b> "; } - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $hid=$row[0]; - $host=$row[1]; + $hid=DBget_field($result,$i,0); + $host=DBget_field($result,$i,1); if($hostid == $hid) { echo "<b>["; @@ -69,13 +69,13 @@ { $whereonly="where h.hostid=i.hostid"; } - $result=mysql_query("select h.host,i.key_,i.itemid,i.description,h.port,i.delay,i.history,i.lastvalue,i.lastclock,i.status,i.lastdelete,i.nextcheck,h.hostid from hosts h,items i $whereonly order by h.host,i.key_,i.description",$mysql); + $result=DBselect("select h.host,i.key_,i.itemid,i.description,h.port,i.delay,i.history,i.lastvalue,i.lastclock,i.status,i.lastdelete,i.nextcheck,h.hostid from hosts h,items i $whereonly order by h.host,i.key_,i.description"); echo "<CENTER>"; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $host=$row[0]; - $itemid_=$row[2]; - $hostid_=$row[12]; + $host=DBget_field($result,$i,0); + $itemid_=DBget_field($result,$i,2); + $hostid_=DBget_field($result,$i,12); // echo "\n<br><hr><b>=$host= =$lasthost=</b>\n"; if($lasthost!=$host) { @@ -122,19 +122,19 @@ echo "<TR BGCOLOR=#EEEEEE>"; $col=1; } - $host=$row[0]; - $port=$row[4]; - $delay=$row[5]; - $history=$row[6]; - $shortname=$row[0].':'.$row[1]; - $key=$row[1]; - $description=$row[3]; - $lastvalue=$row[7]; - $lastclock=date("y/m/d H:i:s",$row[9]); - $itemid_=$row[2]; - $status=$row[9]; - $lastdelete=date("y/m/d H:i:s",$row[10]); - $nextcheck=date("y/m/d H:i:s",$row[11]); + $host=DBget_field($result,$i,0); + $port=DBget_field($result,$i,4); + $delay=DBget_field($result,$i,5); + $history=DBget_field($result,$i,6); + $key=DBget_field($result,$i,1); + $shortname=$host.':'.$key; + $description=DBget_field($result,$i,3); + $lastvalue=DBget_field($result,$i,7); + $lastclock=date("y/m/d H:i:s",DBget_field($result,$i,9)); + $itemid_=DBget_field($result,$i,2); + $status=DBget_field($result,$i,9); + $lastdelete=date("y/m/d H:i:s",DBget_field($result,$i,10)); + $nextcheck=date("y/m/d H:i:s",DBget_field($result,$i,11)); echo "<TD>$host</TD>"; echo "<TD>$key</TD>"; echo "<TD>$description</TD>"; @@ -169,9 +169,8 @@ ?> <? - $result=mysql_query("select count(*) from hosts",$mysql); - $row=mysql_fetch_row($result); - if($row[0]>0) + $result=DBselect("select count(*) from hosts"); + if(DBget_field($result,0,0)>0) { echo "<a name=\"form\"></a>"; insert_item_form($itemid); diff --git a/frontends/php/latest.html b/frontends/php/latest.html index 29ffe2cf..5c0d75e5 100644 --- a/frontends/php/latest.html +++ b/frontends/php/latest.html @@ -14,7 +14,7 @@ echo "<font size=2>"; $lasthost=""; - $result=mysql_query("select h.hostid,h.host from hosts h,items i where h.status=0 and h.hostid=i.hostid group by h.hostid,h.host order by h.host",$mysql); + $result=DBselect("select h.hostid,h.host from hosts h,items i where h.status=0 and h.hostid=i.hostid group by h.hostid,h.host order by h.host"); if(isset($hostid)) { @@ -24,10 +24,10 @@ { echo "<b>[<a href='latest.html'>all</a>]</b> "; } - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $hostid_=$row[0]; - $host=$row[1]; + $hostid_=DBget_field($result,$i,0); + $host=DBget_field($result,$i,1); if($hostid == $hostid_) { echo "<b>["; @@ -53,12 +53,12 @@ $where="where h.hostid=i.hostid and h.status=0"; } - $result=mysql_query("select h.host,i.itemid,i.description,i.lastvalue,i.prevvalue,i.lastclock,i.status,h.hostid from items i,hosts h $where order by h.host,i.description",$mysql); - while($row=mysql_fetch_row($result)) + $result=DBselect("select h.host,i.itemid,i.description,i.lastvalue,i.prevvalue,i.lastclock,i.status,h.hostid from items i,hosts h $where order by h.host,i.description"); + for($i=0;$i<DBnum_rows($result);$i++) { - $host=$row[0]; - $itemid=$row[1]; - $hostid=$row[7]; + $host=DBget_field($result,$i,0); + $itemid=DBget_field($result,$i,1); + $hostid=DBget_field($result,$i,7); if($lasthost!=$host) { if($lasthost!="") @@ -94,10 +94,10 @@ echo "<tr bgcolor=#EEEEEE>"; $col=1; } - $prevvalue=$row[4]; - $description=$row[2]; - $lastvalue=$row[3]; - $lastclock=$row[5]; + $prevvalue=DBget_field($result,$i,4); + $description=DBget_field($result,$i,2); + $lastvalue=DBget_field($result,$i,3); + $lastclock=DBget_field($result,$i,5); if($lastclock==NULL) { $lastclock="<center>-</center>"; @@ -106,8 +106,8 @@ { $lastclock=date("H:i:s",$lastclock); } - $itemid=$row[1]; - $status=$row[6]; + $itemid=DBget_field($result,$i,1); + $status=DBget_field($result,$i,6); $dif=$lastvalue-$prevvalue; echo "<td>$description</td>"; echo "<td>"; diff --git a/frontends/php/latestalarms.html b/frontends/php/latestalarms.html index 5c02ad8c..39ef312f 100644 --- a/frontends/php/latestalarms.html +++ b/frontends/php/latestalarms.html @@ -41,7 +41,7 @@ { $sql="select t.description,a.clock,a.istrue,t.triggerid from alarms a,triggers t where t.triggerid=a.triggerid order by clock desc limit $limit 50"; } - $result=mysql_query($sql,$mysql); + $result=DBselect($sql); echo "<CENTER>"; echo "<TABLE WIDTH=100% BORDER=0 BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; @@ -50,12 +50,12 @@ echo "<TD><b>Description</b></TD>"; echo "<TD width=\"10%\"><b>Status</b></TD>"; echo "</TR>"; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $description=$row[0]; - $clock=$row[1]; - $istrue=$row[2]; - $triggerid_=$row[3]; + $description=DBget_field($result,$i,0); + $clock=DBget_field($result,$i,1); + $istrue=DBget_field($result,$i,2); + $triggerid_=DBget_field($result,$i,3); if($col==1) { diff --git a/frontends/php/media.html b/frontends/php/media.html index 994a1c16..5cf73068 100644 --- a/frontends/php/media.html +++ b/frontends/php/media.html @@ -41,7 +41,7 @@ <FONT COLOR="#000000"> <? $sql="select mediaid,type,sendto,active from media where userid=$userid order by type,sendto"; - $result=mysql_query($sql,$mysql); + $result=DBselect($sql); echo "<CENTER>"; echo "<TABLE BORDER=0 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>"; @@ -52,7 +52,7 @@ echo "<TD><FONT SIZE=+1>Actions</FONT></TD>"; echo "</TR>"; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { if($col==1) { @@ -63,8 +63,8 @@ echo "<TR BGCOLOR=#EEEEEE>"; $col=1; } - $mediaid=$row[0]; - $type_=$row[1]; + $mediaid=DBget_field($result,$i,0); + $type_=DBget_field($result,$i,1); echo "<TD>"; if($type_=="EMAIL") { @@ -75,7 +75,7 @@ echo $type_; } echo "</TD>"; - echo "<TD>",$row[2],"</TD>"; + echo "<TD>",DBget_field($result,$i,2),"</TD>"; echo "<TD>"; if($row[3]==0) { diff --git a/frontends/php/queue.html b/frontends/php/queue.html index e2e5d4d3..f50c0c39 100644 --- a/frontends/php/queue.html +++ b/frontends/php/queue.html @@ -14,19 +14,20 @@ show_table_header("QUEUE"); ?> <? - $result=mysql_query("select i.itemid, from_unixtime(i.nextcheck), i.description, h.host from items i,hosts h where i.status=0 and h.status=0 and i.hostid=h.hostid and i.nextcheck<UNIX_TIMESTAMP() order by i.nextcheck;",$mysql); - $i=0; + $now=time(); + $result=DBselect("select i.itemid, i.nextcheck, i.description, h.host from items i,hosts h where i.status=0 and h.status=0 and i.hostid=h.hostid and i.nextcheck<$now order by i.nextcheck"); echo "<table border=0 width=100% bgcolor='#CCCCCC' cellspacing=1 cellpadding=3>"; echo "\n"; echo "<tr><td><b>Next time to check</b></td><td><b>Host</b></td><td><b>Description</b></td></tr>"; echo "\n"; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $i++; - $itemid=$row[0]; - $time=$row[1]; - $description=$row[2]; - $host=$row[3]; + $itemid=DBget_field($result,$i,0); + $time=DBget_field($result,$i,1); + $description=DBget_field($result,$i,2); + $host=DBget_field($result,$i,3); + + $time=date("m.d.Y H:i:s",$time); if($col==1) { @@ -46,6 +47,7 @@ echo "</table>"; ?> <? + $i=DBnum_rows($result); show_table_header("Total:$i"); ?> diff --git a/frontends/php/tr_status.html b/frontends/php/tr_status.html index 0489ac25..8d5fc6c3 100644 --- a/frontends/php/tr_status.html +++ b/frontends/php/tr_status.html @@ -15,7 +15,7 @@ ?> <? - $result=mysql_query("select hostid,host from hosts order by host",$mysql); + $result=DBselect("select hostid,host from hosts order by host"); if(isset($hostid)) { echo "<A HREF=\"tr_status.html\">all</A> "; @@ -24,10 +24,10 @@ { echo "<b>[<A HREF=\"tr_status.html\">all</A>]</b> "; } - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $hid=$row[0]; - $host=$row[1]; + $hid=DBget_field($result,$i,0); + $host=DBget_field($result,$i,1); if($hid == $hostid) { echo "<b>[<A HREF=\"tr_status.html?hostid=$hid\">$host</A>]</b> "; @@ -116,17 +116,14 @@ if($onlytrue=='true') { - $result=mysql_query("select t.triggerid,t.istrue,t.description,t.lastcheck,t.expression,t.priority,t.lastchange,t.comments from triggers t,hosts h,items i,functions f where t.istrue=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid $cond order by t.priority desc, t.description",$mysql); + $result=DBselect("select t.triggerid,t.istrue,t.description,t.lastcheck,t.expression,t.priority,t.lastchange,t.comments from triggers t,hosts h,items i,functions f where t.istrue=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid $cond order by t.priority desc, t.description"); } else { - $result=mysql_query("select t.triggerid,t.istrue,t.description,t.lastcheck,t.expression,t.priority,t.lastchange,t.comments from triggers t,hosts h,items i,functions f where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid $cond order by t.priority desc, t.description",$mysql); + $result=DBselect("select t.triggerid,t.istrue,t.description,t.lastcheck,t.expression,t.priority,t.lastchange,t.comments from triggers t,hosts h,items i,functions f where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid $cond order by t.priority desc, t.description"); } - $trigcount=0; - $i=0; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $trigcount++; if($col==1) { echo "\n<TR BGCOLOR=#EEEEEE>"; @@ -136,14 +133,14 @@ echo "\n<TR BGCOLOR=#DDDDDD>"; $col=1; } - $expression=$row[4]; - $description=$row[2]; - $triggerid=$row[0]; - $istrue=$row[1]; - $lastcheck=$row[3]; - $priority=$row[5]; - $lastchange=$row[6]; - $comments=$row[7]; + $expression=DBget_field($result,$i,4); + $description=DBget_field($result,$i,2); + $triggerid=DBget_field($result,$i,0); + $istrue=DBget_field($result,$i,1); + $lastcheck=DBget_field($result,$i,3); + $priority=DBget_field($result,$i,5); + $lastchange=DBget_field($result,$i,6); + $comments=DBget_field($result,$i,7); $lastchange=date("d M H:i:s",$lastchange); @@ -193,20 +190,20 @@ echo "</TD>"; } if($istrue==0) echo "</TR>\n"; - $i++; } echo "</TABLE>\n"; + $i=DBnum_rows($result); + show_table_header("Total:$i"); - $result=mysql_query(" select min(lastcheck) from triggers where istrue<2;",$mysql); - $row=mysql_fetch_row($result); - $lastcheck=$row[0]; + $result=DBselect("select min(lastcheck) from triggers where istrue<2"); + $lastcheck=DBget_field($result,0,0); $diff=mktime()-$lastcheck; - $result=mysql_query("select count(*) from items i,hosts h where i.status=0 and h.status=0 and h.hostid=i.hostid and i.nextcheck<UNIX_TIMESTAMP()-60;",$mysql); - $row=mysql_fetch_row($result); - $answ=$row[0]; + $now=time(); + $result=DBselect("select count(*) from items i,hosts h where i.status=0 and h.status=0 and h.hostid=i.hostid and i.nextcheck<$now-60"); + $answ=DBget_field($result,0,0); if ($answ>0) { echo "<br>"; diff --git a/frontends/php/triggers.html b/frontends/php/triggers.html index 1c3c6e52..6b0334e2 100644 --- a/frontends/php/triggers.html +++ b/frontends/php/triggers.html @@ -45,7 +45,7 @@ ?> <? - $result=mysql_query("select hostid,host from hosts order by host",$mysql); + $result=DBselect("select hostid,host from hosts order by host"); if(isset($hostid)) { echo "<A HREF=\"triggers.html\">all</A> "; @@ -54,10 +54,10 @@ { echo "<b>[<A HREF=\"triggers.html\">all</A>]</b> "; } - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $hid=$row[0]; - $host=$row[1]; + $hid=DBget_field($result,$i,0); + $host=DBget_field($result,$i,1); if($hid == $hostid) { echo "<b>[<A HREF=\"triggers.html?hostid=$hid\">$host</A>]</b> "; @@ -83,12 +83,12 @@ $cond=""; } - $result=mysql_query("select h.hostid,h.host,t.triggerid,t.expression,t.description,t.istrue from triggers t,hosts h,items i,functions f where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid $cond order by h.host,t.description",$mysql); + $result=DBselect("select h.hostid,h.host,t.triggerid,t.expression,t.description,t.istrue from triggers t,hosts h,items i,functions f where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid $cond order by h.host,t.description"); $ss="."; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { - $hostid_=$row[0]; - $host=$row[1]; + $hostid_=DBget_field($result,$i,0); + $host=DBget_field($result,$i,1); if($lasthost!=$host) { if($lasthost!="") @@ -115,10 +115,10 @@ echo "<TR BGCOLOR=#EEEEEE>"; $col=1; } - $description=$row[4]; - $triggerid_=$row[2]; - $expression=$row[3]; - $istrue=$row[5]; + $description=DBget_field($result,$i,4); + $triggerid_=DBget_field($result,$i,2); + $expression=DBget_field($result,$i,3); + $istrue=DBget_field($result,$i,5); echo "<TD>$description</TD>"; $description=rawurlencode($description); @@ -151,9 +151,8 @@ ?> <? - $result=mysql_query("select count(*) from hosts",$mysql); - $row=mysql_fetch_row($result); - if($row[0]>0) + $result=DBselect("select count(*) from hosts"); + if(DBget_field($result,0,0)>0) { echo "<a name=\"form\"></a>"; insert_trigger_form($triggerid); diff --git a/frontends/php/users.html b/frontends/php/users.html index 167906d7..65015232 100644 --- a/frontends/php/users.html +++ b/frontends/php/users.html @@ -42,9 +42,9 @@ echo "<TD WIDTH=\"10%\" NOSAVE><B>Actions</B></TD>"; echo "</TR>"; - $result=mysql_query("select u.userid,u.alias,u.name,u.surname,g.name from users u,groups g where u.groupid=g.groupid order by g.name,u.alias",$mysql); + $result=DBselect("select u.userid,u.alias,u.name,u.surname,g.name from users u,groups g where u.groupid=g.groupid order by g.name,u.alias"); echo "<CENTER>"; - while($row=mysql_fetch_row($result)) + for($i=0;$i<DBnum_rows($result);$i++) { if($col==1) { @@ -56,11 +56,11 @@ $col=1; } - $alias=$row[1]; - $name=$row[2]; - $surname=$row[3]; - $group=$row[4]; - $userid_=$row[0]; + $alias=DBget_field($result,$i,1); + $name=DBget_field($result,$i,2); + $surname=DBget_field($result,$i,3); + $group=DBget_field($result,$i,4); + $userid_=DBget_field($result,$i,0); echo "<TD>$group</TD>"; echo "<TD>$alias</TD>"; echo "<TD>$name</TD>"; |
