summaryrefslogtreecommitdiffstats
path: root/frontends/php
diff options
context:
space:
mode:
Diffstat (limited to 'frontends/php')
-rw-r--r--frontends/php/history.php16
-rw-r--r--frontends/php/include/classes/ccombobox.inc.php2
-rw-r--r--frontends/php/include/classes/ctable.inc.php7
-rw-r--r--frontends/php/include/classes/ctag.inc.php20
-rw-r--r--frontends/php/include/classes/ctextarea.inc.php2
-rw-r--r--frontends/php/include/classes/ctextbox.inc.php2
-rw-r--r--frontends/php/include/config.inc.php175
-rw-r--r--frontends/php/include/copt.lib.php124
-rw-r--r--frontends/php/include/db.inc.php1
-rw-r--r--frontends/php/include/html.inc.php9
-rw-r--r--frontends/php/include/items.inc.php12
-rw-r--r--frontends/php/include/triggers.inc.php61
-rw-r--r--frontends/php/include/validate.inc.php6
13 files changed, 225 insertions, 212 deletions
diff --git a/frontends/php/history.php b/frontends/php/history.php
index 150a8a6c..f118b7e6 100644
--- a/frontends/php/history.php
+++ b/frontends/php/history.php
@@ -74,7 +74,7 @@
if(!isset($_REQUEST["plaintext"]))
insert_confirm_javascript();
else
- print($main_header.BR);
+ echo $main_header.BR;
if(is_array($_REQUEST["itemid"]))
{
@@ -282,7 +282,7 @@
}
else
{
- print $l_header."\n";
+ echo $l_header."\n";
}
$cond_clock = "";
@@ -340,7 +340,7 @@
}
else
{
- print("<PRE>\n");
+ echo "<PRE>\n";
}
while($row=DBfetch($result))
@@ -427,14 +427,14 @@
}
else
{
- print(date("Y-m-d H:i:s",$row["clock"]));
- print("\t".$row["clock"]."\t".$row["value"]."\n");
+ echo date("Y-m-d H:i:s",$row["clock"]);
+ echo "\t".$row["clock"]."\t".$row["value"]."\n";
}
}
if(!isset($_REQUEST["plaintext"]))
$table->ShowTagEnd(); // to solve memory leak we call 'Show' method by steps
else
- print("</PRE>");
+ echo "</PRE>";
}
else
{
@@ -462,7 +462,7 @@
}
else
{
- print("<PRE>\n");
+ echo "<PRE>\n";
}
$i=0;
@@ -498,7 +498,7 @@
if(!isset($_REQUEST["plaintext"]))
$table->ShowTagEnd(); // to solve memory leak we call 'Show' method by steps
else
- print("</PRE>");
+ echo "</PRE>";
}
}
diff --git a/frontends/php/include/classes/ccombobox.inc.php b/frontends/php/include/classes/ccombobox.inc.php
index 69a17636..ea579803 100644
--- a/frontends/php/include/classes/ccombobox.inc.php
+++ b/frontends/php/include/classes/ccombobox.inc.php
@@ -141,7 +141,7 @@
function Show()
{
if(isset($this->caption))
- print ($this->caption." ");
+ echo $this->caption." ";
parent::Show();
}
}
diff --git a/frontends/php/include/classes/ctable.inc.php b/frontends/php/include/classes/ctable.inc.php
index e82e5429..b0d5485a 100644
--- a/frontends/php/include/classes/ctable.inc.php
+++ b/frontends/php/include/classes/ctable.inc.php
@@ -242,5 +242,12 @@
return parent::AddItem($value);
}
+/* function Show()
+ {
+ ob_start();
+ parent::Show();
+ ob_end_flush();
+ }
+*/
}
?>
diff --git a/frontends/php/include/classes/ctag.inc.php b/frontends/php/include/classes/ctag.inc.php
index 9ddc0b20..82caa5b8 100644
--- a/frontends/php/include/classes/ctag.inc.php
+++ b/frontends/php/include/classes/ctag.inc.php
@@ -176,25 +176,25 @@
/* protected */
function ShowTagStart()
{
- print ($this->tag_start);
- print("<".$this->name);
+ echo $this->tag_start;
+ echo "<".$this->name;
foreach($this->options as $key => $value)
{
- print (" $key=\"$value\"");
+ echo " $key=\"$value\"";
}
if($this->paired=='yes')
- print (">");
+ echo ">";
else
- print ("/>");
+ echo "/>";
- print ($this->tag_body_start);
+ echo $this->tag_body_start;
}
function ShowTagItem(&$item)
{
if(is_null($item)) return;
elseif(is_object($item))$item->Show();
- else print (strval($item));
+ else echo strval($item);
}
function ShowTagBody()
{
@@ -203,12 +203,12 @@
}
function ShowTagEnd()
{
- print ($this->tag_body_end);
+ echo $this->tag_body_end;
if($this->paired=='yes')
{
- print ("</".$this->name.">");
- print ($this->tag_end);
+ echo "</".$this->name.">";
+ echo $this->tag_end;
}
}
function SetEnabled($value='yes')
diff --git a/frontends/php/include/classes/ctextarea.inc.php b/frontends/php/include/classes/ctextarea.inc.php
index e9e75530..5ea51f70 100644
--- a/frontends/php/include/classes/ctextarea.inc.php
+++ b/frontends/php/include/classes/ctextarea.inc.php
@@ -39,7 +39,7 @@
function Show()
{
if(isset($this->caption))
- print ($this->caption." ");
+ echo $this->caption." ";
parent::Show();
}
function SetName($value='textarea')
diff --git a/frontends/php/include/classes/ctextbox.inc.php b/frontends/php/include/classes/ctextbox.inc.php
index 5629f2b6..6345b342 100644
--- a/frontends/php/include/classes/ctextbox.inc.php
+++ b/frontends/php/include/classes/ctextbox.inc.php
@@ -37,7 +37,7 @@
function Show()
{
if(isset($this->caption))
- print ($this->caption." ");
+ echo $this->caption." ";
parent::Show();
}
function SetReadonly($value='yes')
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 3c8924f0..ac694a90 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -22,6 +22,8 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
?>
<?php
+ include_once("include/copt.lib.php");
+
// GLOBALS
$USER_DETAILS ="";
$USER_RIGHTS ="";
@@ -93,6 +95,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
include_once("include/classes/cserverinfo.mod.php");
include_once("include/classes/cflashclock.mod.php");
+
function zbx_stripslashes($value){
if(is_array($value)){
$value = array_map('zbx_stripslashes',$value);
@@ -976,6 +979,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
{
global $page;
global $USER_DETAILS;
+COpt::profiling_start("page");
if($noauth==0)
{
@@ -1225,174 +1229,6 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
return $table;
}
- # Translate {10}>10 to something like localhost:procload.last(0)>10
-
- function explode_exp ($expression, $html)
- {
-# echo "EXPRESSION:",$expression,"<Br>";
-
- $functionid='';
- $exp='';
- $state='';
- for($i=0;$i<strlen($expression);$i++)
- {
- if($expression[$i] == '{')
- {
- $functionid='';
- $state='FUNCTIONID';
- continue;
- }
- if($expression[$i] == '}')
- {
- $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=DBselect($sql);
- $row1=DBfetch($res1);
- if($html == 0)
- {
- $exp=$exp."{".$row1["host"].":".$row1["key_"].".".$row1["function"]."(".$row1["parameter"].")}";
- }
- else
- {
- $item=get_item_by_itemid($row1["itemid"]);
- if($item["value_type"] ==0)
- {
- $exp=$exp."{<A HREF=\"history.php?action=showgraph&itemid=".$row1["itemid"]."\">".$row1["host"].":".$row1["key_"]."</A>.<B>".$row1["function"]."(</B>".$row1["parameter"]."<B>)</B>}";
- }
- else
- {
- $exp=$exp."{<A HREF=\"history.php?action=showvalues&period=3600&itemid=".$row1["itemid"]."\">".$row1["host"].":".$row1["key_"]."</A>.<B>".$row1["function"]."(</B>".$row1["parameter"]."<B>)</B>}";
- }
- }
- continue;
- }
- if($state == "FUNCTIONID")
- {
- $functionid=$functionid.$expression[$i];
- continue;
- }
- $exp=$exp.$expression[$i];
- }
-# echo "EXP:",$exp,"<Br>";
- return $exp;
- }
-
- # Translate localhost:procload.last(0)>10 to {12}>10
-
- /*function implode_exp ($expression, $triggerid)
- {
-// echo "Expression:$expression<br>";
- $exp='';
- $state="";
- for($i=0;$i<strlen($expression);$i++)
- {
- if($expression[$i] == '{')
- {
- if($state=="")
- {
- $host='';
- $key='';
- $function='';
- $parameter='';
- $state='HOST';
- continue;
- }
- }
- if( ($expression[$i] == '}')&&($state=="") )
- {
-// echo "HOST:$host<BR>";
-// echo "KEY:$key<BR>";
-// echo "FUNCTION:$function<BR>";
-// echo "PARAMETER:$parameter<BR>";
- $state='';
-
- $sql="select i.itemid from items i,hosts h where i.key_=".zbx_dbstr($key).
- " and h.host=".zbx_dbstr($host)." and h.hostid=i.hostid";
-# echo $sql,"<Br>";
- $res=DBselect($sql);
- $row=DBfetch($res);
-
- $itemid=$row["itemid"];
-# echo "ITEMID:$itemid<BR>";
-
- $sql="insert into functions (itemid,triggerid,function,parameter)".
- " values ($itemid,$triggerid,".zbx_dbstr($function).",".
- zbx_dbstr($parameter).")";
-# echo $sql,"<Br>";
- $res=DBexecute($sql);
- if(!$res)
- {
-# echo "ERROR<br>";
- return $res;
- }
- $functionid=DBinsert_id($res,"functions","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 add_image($name,$imagetype,$file)
{
if(!is_null($file))
@@ -1975,6 +1811,9 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
"page_footer_r")
));
$table->Show();
+
+ COpt::profiling_stop("page");
+
echo "</body>\n";
echo "</html>\n";
}
diff --git a/frontends/php/include/copt.lib.php b/frontends/php/include/copt.lib.php
new file mode 100644
index 00000000..aaebaab5
--- /dev/null
+++ b/frontends/php/include/copt.lib.php
@@ -0,0 +1,124 @@
+<?php
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+ /* SPEED Measurement
+ -= slow =-
+ vs
+ -= fast =-
+ 1)strlen
+ if (strlen($foo) < 5) { echo "Foo is too short"; }
+ vs
+ if (!isset($foo{5})) { echo "Foo is too short"; }
+
+ 2)++
+ $i++
+ vs
+ ++$i
+
+ 3)print
+ print
+ vs
+ echo
+
+ 4)regexps
+ preg_match("![0-9]+!", $foo);
+ vs
+ ctype_digit($foo);
+
+ 5)in_array
+ $keys = array("apples", "oranges", "mangoes", "tomatoes", "pickles");
+ if (in_array('mangoes', $keys)) { ... }
+ vs
+ $keys = array("apples" => 1, "oranges" => 1, "mangoes" => 1, "tomatoes" => 1, "pickles" => 1);
+ if (isset($keys['mangoes'])) { ... }
+
+ 6)key_exist
+ if(array_key_exists('mangoes', $keys))
+ vs
+ if (isset($keys['mangoes'])) { ... }
+
+ 7)regexps
+ POSIX-regexps
+ vs
+ Perl-regexps
+
+ 8)constants
+ UPPER case constans (TRUE, FALSE)
+ vs
+ lower case constans (true, false)
+
+ 9)for
+ for ($i = 0; $i < FUNCTION($j); $i++) {...}
+ vs
+ for ($i = 0, $k = FUNCTION($j); $i < $k; $i = $i + 1) {...}
+
+ 10)strings
+ "var=$var"
+ vs
+ 'var='.$var
+
+ */
+
+
+ /*
+ ** Description:
+ ** Optimization class. Provide functions for
+ ** PHP code optimization.
+ **
+ ** Author:
+ ** Eugene Grigorjev (eugene.grigorjev@zabbix.com)
+ **/
+
+ //define("USE_PROFILING",1);
+
+ $starttime[]=array();
+
+ class COpt
+ {
+ /* protected static $starttime[]=array(); */
+
+ /* protected static */ function getmicrotime()
+ {
+ list($usec, $sec) = explode(" ",microtime());
+ return ((float)$usec + (float)$sec);
+ }
+ /* public static */ function profiling_start($type=NULL)
+ {
+ if(!defined('USE_PROFILING')) return;
+
+ global $starttime;
+ if(is_null($type)) $type="global";
+
+ $starttime[$type] = COpt::getmicrotime();
+ }
+ /* public static */ function profiling_stop($type=NULL)
+ {
+ if(!defined('USE_PROFILING')) return;
+
+ global $starttime;
+
+ $endtime = COpt::getmicrotime();
+
+ if(is_null($type)) $type="global";
+ echo "<br/>\nTime to execute (".$type."): ". bcsub($endtime,$starttime[$type],6)." seconds!\n<br/>";
+ }
+ }
+
+?>
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index 6b6df889..ae1a5c42 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -27,6 +27,7 @@
$DB_SERVER ="localhost";
// $DB_DATABASE ="zabbix";
$DB_DATABASE ="osmiy";
+// $DB_DATABASE ="demo";
$DB_USER ="root";
$DB_PASSWORD ="";
// END OF DATABASE CONFIGURATION
diff --git a/frontends/php/include/html.inc.php b/frontends/php/include/html.inc.php
index 277668b7..61ec6dca 100644
--- a/frontends/php/include/html.inc.php
+++ b/frontends/php/include/html.inc.php
@@ -23,13 +23,6 @@
define("SPACE","&nbsp;");
define("RARR","&rArr;");
- function do_vertival_text($str)
- {
- for($i=0,$out = ""; $i<strlen($str); $i++) $out .= $str[$i].BR;
- $str = $out;
- return $str;
- }
-
function bold($str)
{
if(is_array($str)){
@@ -45,7 +38,7 @@
function bfirst($str) // mark first symbol of string as bold
{
$res = bold($str[0]);
- for($i=1; $i<strlen($str); $i++) $res .= $str[$i];
+ for($i=1,$max=strlen($str); $i<$max; $i++) $res .= $str[$i];
$str = $res;
return $str;
}
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php
index 4f6e074b..45213f30 100644
--- a/frontends/php/include/items.inc.php
+++ b/frontends/php/include/items.inc.php
@@ -469,26 +469,25 @@
$header=array(new CCol(S_ITEMS,"center"));
$hosts=array();
- $result=DBselect("select h.hostid,h.host from hosts h,items i $group_where".
+ $result=DBselect("select distinct h.hostid,h.host from hosts h,items i $group_where".
" h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and i.status=".ITEM_STATUS_ACTIVE.
" group by h.host,h.hostid order by h.host");
while($row=DBfetch($result))
{
- if(!check_right("Host","R",$row["hostid"])) continue; //TODO optimize duplication check !!!! see buttom
+ if(!check_right("Host","R",$row["hostid"])) continue;
array_push($header,new CImg("vtext.php?text=".$row["host"]));
array_push($hosts,$row["hostid"]);
}
$table->SetHeader($header,"vertical_header");
- $db_items = DBselect("select distinct i.description,h.hostid from hosts h,items i $group_where".
+ $db_items = DBselect("select distinct i.description from hosts h,items i $group_where".
" h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and i.status=".ITEM_STATUS_ACTIVE.
" order by 1");
while($item = DBfetch($db_items))
{
- if(!check_right("Host","R",$row["hostid"])) continue; //TODO optimize duplication check !!!! see top
-
$table_row = array(nbsp($item["description"]));
+ $host_added = 0;
foreach($hosts as $hostid)
{
$db_host_items = DBselect("select itemid,value_type,lastvalue,units from items where".
@@ -502,6 +501,7 @@
if(!check_right("Item","R",$host_item["itemid"])) continue;
+ ++$host_added; // added corect host item;
if(!isset($host_item["lastvalue"]))
{
array_push($table_row,"-");
@@ -521,7 +521,7 @@
array_push($table_row,new CCol(nbsp($value),$style));
}
- $table->AddRow($table_row);
+ if($host_added > 0) $table->AddRow($table_row);
}
return $table;
}
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index 393fc77e..ec7e7873 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -97,7 +97,7 @@
$state="";
$host="";
$hosts=array();
- for($i=0;$i<strlen($expression);$i++)
+ for($i=0,$max=strlen($expression); $i<$max; $i++)
{
if($expression[$i] == '{' && $state=="")
{
@@ -435,13 +435,65 @@
return $newtriggerid;
}
+ # Translate {10}>10 to something like localhost:procload.last(0)>10
+
+ function explode_exp ($expression, $html)
+ {
+# echo "EXPRESSION:",$expression,"<Br>";
+
+ $functionid='';
+ $exp='';
+ $state='';
+ for($i=0,$max=strlen($expression); $i<$max; $i++)
+ {
+ if($expression[$i] == '{')
+ {
+ $functionid='';
+ $state='FUNCTIONID';
+ continue;
+ }
+ if($expression[$i] == '}')
+ {
+ $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=DBselect($sql);
+ $row1=DBfetch($res1);
+ if($html == 0)
+ {
+ $exp=$exp."{".$row1["host"].":".$row1["key_"].".".$row1["function"]."(".$row1["parameter"].")}";
+ }
+ else
+ {
+ $item=get_item_by_itemid($row1["itemid"]);
+ if($item["value_type"] ==0)
+ {
+ $exp=$exp."{<A HREF=\"history.php?action=showgraph&itemid=".$row1["itemid"]."\">".$row1["host"].":".$row1["key_"]."</A>.<B>".$row1["function"]."(</B>".$row1["parameter"]."<B>)</B>}";
+ }
+ else
+ {
+ $exp=$exp."{<A HREF=\"history.php?action=showvalues&period=3600&itemid=".$row1["itemid"]."\">".$row1["host"].":".$row1["key_"]."</A>.<B>".$row1["function"]."(</B>".$row1["parameter"]."<B>)</B>}";
+ }
+ }
+ continue;
+ }
+ if($state == "FUNCTIONID")
+ {
+ $functionid=$functionid.$expression[$i];
+ continue;
+ }
+ $exp=$exp.$expression[$i];
+ }
+# echo "EXP:",$exp,"<Br>";
+ return $exp;
+ }
+
function implode_exp ($expression, $triggerid)
# Translate localhost:procload.last(0)>10 to {12}>10
{
// echo "Expression:$expression<br>";
$exp='';
$state="";
- for($i=0;$i<strlen($expression);$i++)
+ for($i=0,$max=strlen($expression); $i<$max; $i++)
{
if($expression[$i] == '{')
{
@@ -972,20 +1024,19 @@
" group by h.host,h.hostid order by h.host");
while($row=DBfetch($result))
{
- if(!check_right("Host","R",$row["hostid"])) continue; //TODO optimize duplication check !!!! see top
+ if(!check_right("Host","R",$row["hostid"])) continue;
$header=array_merge($header,array(new CImg("vtext.php?text=".$row["host"])));
$hosts=array_merge($hosts,array($row["hostid"]));
}
$table->SetHeader($header,"vertical_header");
- $db_triggers = DBselect("select distinct t.description,h.hostid from hosts h,items i,triggers t,functions f $group_where".
+ $db_triggers = DBselect("select distinct t.description from hosts h,items i,triggers t,functions f $group_where".
" h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid".
" and t.status=".TRIGGER_STATUS_ENABLED.
" group by 1");
while($triggers = DBfetch($db_triggers))
{
- if(!check_right("Host","R",$row["hostid"])) continue; //TODO optimize duplication check !!!! see top
$table_row = array(nbsp($triggers["description"]));
foreach($hosts as $hostid)
{
diff --git a/frontends/php/include/validate.inc.php b/frontends/php/include/validate.inc.php
index 0e8ba889..4517c221 100644
--- a/frontends/php/include/validate.inc.php
+++ b/frontends/php/include/validate.inc.php
@@ -67,9 +67,7 @@
$expression = str_replace('{'.$f.'}','$_REQUEST["'.$f.'"]',$expression);
//$debug .= $f." = ".$_REQUEST[$f].BR;
}
- $expression=rtrim($expression,"&");
- if($expression[strlen($expression)-1]=='&') $expression[strlen($expression)-1]=0;
- if($expression[strlen($expression)-1]=='&') $expression[strlen($expression)-1]=0;
+ $expression = trim($expression,"& ");
$exec = "return (".$expression.") ? 1 : 0;";
$ret = eval($exec);
@@ -269,7 +267,7 @@
{
if($flags&P_SYS)
{
- info("Critical error. Incorrect value for [".$field."]");
+ info("Critical error. Incorrect value for [".$field."] = '".$_REQUEST[$field]."'");
return ZBX_VALID_ERROR;
}
else