summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-11-07 08:56:18 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-11-07 08:56:18 +0000
commit23bdb608fe93cf4a98683dae0a09fcca30aa9d1d (patch)
treefa3b2460d754189c42780f7da474fb6599240856 /frontends/php/include
parentdda9501aff9b7293055eee1a8c769068d3701ad7 (diff)
- developed frontend installation wizard (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3434 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/classes/cform.inc.php7
-rw-r--r--frontends/php/include/classes/clist.inc.php13
-rw-r--r--frontends/php/include/classes/ctable.inc.php3
-rw-r--r--frontends/php/include/classes/ctag.inc.php20
-rw-r--r--frontends/php/include/config.inc.php191
-rw-r--r--frontends/php/include/copt.lib.php12
-rw-r--r--frontends/php/include/db.inc.php134
-rw-r--r--frontends/php/include/defines.inc.php4
-rw-r--r--frontends/php/include/forms.inc.php27
-rw-r--r--frontends/php/include/locales/en_gb.inc.php12
-rw-r--r--frontends/php/include/page_header.php40
-rw-r--r--frontends/php/include/perm.inc.php2
-rw-r--r--frontends/php/include/setup.inc.php739
-rw-r--r--frontends/php/include/validate.inc.php5
14 files changed, 1070 insertions, 139 deletions
diff --git a/frontends/php/include/classes/cform.inc.php b/frontends/php/include/classes/cform.inc.php
index 9767a7f3..7af98ee8 100644
--- a/frontends/php/include/classes/cform.inc.php
+++ b/frontends/php/include/classes/cform.inc.php
@@ -41,9 +41,12 @@
{
if(isset($page['file']))
{
- return $this->options['action'] = $page['file'];
+ $value = $page['file'];
+ }
+ else
+ {
+ $value = "#";
}
- return 1;
}
return $this->options['action'] = $value;
}
diff --git a/frontends/php/include/classes/clist.inc.php b/frontends/php/include/classes/clist.inc.php
index c5eb9b57..cf5a5502 100644
--- a/frontends/php/include/classes/clist.inc.php
+++ b/frontends/php/include/classes/clist.inc.php
@@ -22,10 +22,11 @@
class CListItem extends CTag
{
/* public */
- function CListItem($value)
+ function CListItem($value,$class=null)
{
parent::CTag('li','yes');
+ $this->SetClass($class);
$this->AddItem($value);
}
}
@@ -40,25 +41,25 @@
$this->AddItem($value);
$this->SetClass($class);
}
- function PrepareItem($value=NULL)
+ function PrepareItem($value=NULL,$class=null)
{
if(!is_null($value))
{
- $value = new CListItem($value);
+ $value = new CListItem($value,$class);
}
return $value;
}
- function AddItem($value)
+ function AddItem($value,$class=null)
{
if(is_array($value))
{
foreach($value as $el)
- parent::AddItem($this->PrepareItem($el));
+ parent::AddItem($this->PrepareItem($el,$class));
}
else
{
- parent::AddItem($this->PrepareItem($value));
+ parent::AddItem($this->PrepareItem($value,$class));
}
}
}
diff --git a/frontends/php/include/classes/ctable.inc.php b/frontends/php/include/classes/ctable.inc.php
index 10bb4d87..79ffc1d4 100644
--- a/frontends/php/include/classes/ctable.inc.php
+++ b/frontends/php/include/classes/ctable.inc.php
@@ -145,7 +145,8 @@
}
elseif(is_a($item,'crow'))
{
- $item->SetClass($rowClass);
+ if(isset($rowClass))
+ $item->SetClass($rowClass);
}
else
{
diff --git a/frontends/php/include/classes/ctag.inc.php b/frontends/php/include/classes/ctag.inc.php
index 00f81eda..80020309 100644
--- a/frontends/php/include/classes/ctag.inc.php
+++ b/frontends/php/include/classes/ctag.inc.php
@@ -67,7 +67,7 @@
var $tag_end;
/* public */
- function CTag($tagname=NULL, $paired='no', $body=NULL)
+ function CTag($tagname=NULL, $paired='no', $body=NULL, $class=null)
{
if(!is_string($tagname))
{
@@ -87,6 +87,8 @@
CTag::AddItem($body);
}
+ $this->SetClass($class);
+
}
function ShowStart() { echo $this->StartToString(); }
function ShowBody() { echo $this->BodyToString(); }
@@ -145,6 +147,9 @@
{
if(isset($value))
$this->options['class'] = $value;
+ else
+ unset($this->options['class']);
+
return $value;
}
function DelOption($name)
@@ -161,21 +166,18 @@
function SetHint($text, $width='', $class='')
{
+ $text = addslashes(htmlspecialchars($text));
if($width != '' || $class!= '')
{
- $this->AddOption(
- 'onMouseOver',
- "show_hint_ext(this,'".$text."','".$width."','".$class."');"
- );
+ $code = "show_hint_ext(this,event,'".$text."','".$width."','".$class."');";
}
else
{
- $this->AddOption(
- 'onMouseOver',
- "show_hint(this,'".$text."');"
- );
+ $code = "show_hint(this,event,'".$text."');";
}
+ $this->AddOption('onMouseOver', $code);
+ $this->AddOption('onMouseMove', $code);
}
function OnClick($handle_code)
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index b8db1617..3231d63f 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -18,7 +18,8 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-function SDI($msg="SDI") { echo "DEBUG INFO: "; if(is_array($msg)) print_r($msg); else echo($msg); echo BR; } // DEBUG INFO!!!
+function SDI($msg="SDI") { echo "DEBUG INFO: "; var_export($msg); echo BR; } // DEBUG INFO!!!
+function VDP($var, $msg=null) { echo "DEBUG DUMP: "; if(isset($msg)) echo '"'.$msg.'"'.SPACE; var_dump($var); echo BR; } // DEBUG INFO!!!
?>
@@ -41,16 +42,6 @@ function SDI($msg="SDI") { echo "DEBUG INFO: "; if(is_array($msg)) print_r($msg)
$_REQUEST= zbx_stripslashes($_REQUEST);
}
- require_once "include/defines.inc.php";
- require_once "include/db.inc.php";
- require_once "include/locales.inc.php";
- require_once "include/perm.inc.php";
- require_once "include/audit.inc.php";
-
-// Include Validation
-
- require_once "include/validate.inc.php";
-
// Include Classes
require_once("include/classes/ctag.inc.php");
require_once("include/classes/cvar.inc.php");
@@ -77,11 +68,42 @@ function SDI($msg="SDI") { echo "DEBUG INFO: "; if(is_array($msg)) print_r($msg)
// Include Tactical Overview modules
+ require_once "include/defines.inc.php";
+ require_once "include/locales.inc.php";
+
include_once("include/classes/chostsinfo.mod.php");
include_once("include/classes/ctriggerinfo.mod.php");
include_once("include/classes/cserverinfo.mod.php");
include_once("include/classes/cflashclock.mod.php");
+ require_once "include/db.inc.php";
+ require_once "include/perm.inc.php";
+ require_once "include/audit.inc.php";
+
+// Include Validation
+
+ require_once "include/validate.inc.php";
+
+ function zbx_err_handler($errno, $errstr, $errfile, $errline)
+ {
+ error($errstr.'['.$errfile.':'.$errline.']');
+ }
+
+ set_error_handler('zbx_err_handler');
+
+ read_configuration_file();
+
+ $error = '';
+ if(!DBconnect($error))
+ {
+ error($error);
+ define('ZBX_DISTRIBUTED', false);
+ include_once "setup.php";
+ }
+ unset($error);
+
+ global $ZBX_LOCALNODEID;
+
/* Init LOCAL NODE ID */
if($local_node_data = DBfetch(DBselect('select nodeid from nodes where nodetype=1 order by nodeid')))
{
@@ -95,6 +117,25 @@ function SDI($msg="SDI") { echo "DEBUG INFO: "; if(is_array($msg)) print_r($msg)
}
unset($local_node_data);
+ function read_configuration_file($file='conf/zabbix.conf.php')
+ {
+ global $ZBX_CONFIGURATION_FILE;
+
+ global $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+
+ $ZBX_CONFIGURATION_FILE = $file;
+
+ if(!file_exists($file) || isset($_COOKIE['ZBX_CONFIG']))
+ {
+ define('ZBX_DISTRIBUTED', false);
+ include_once "setup.php";
+ }
+ else
+ {
+ include $ZBX_CONFIGURATION_FILE;
+ }
+ }
+
function access_deny()
{
include_once "include/page_header.php";
@@ -152,9 +193,36 @@ function SDI($msg="SDI") { echo "DEBUG INFO: "; if(is_array($msg)) print_r($msg)
function fatal_error($msg)
{
+ include_once "include/page_header.php";
error($msg);
include_once "include/page_footer.php";
}
+
+ function str2mem($val)
+ {
+ $val = trim($val);
+ $last = strtolower($val{strlen($val)-1});
+ switch($last)
+ {
+ // The 'G' modifier is available since PHP 5.1.0
+ case 'g':
+ $val *= 1024;
+ case 'm':
+ $val *= 1024;
+ case 'k':
+ $val *= 1024;
+ }
+
+ return $val;
+ }
+
+ function mem2str($size)
+ {
+ $prefix = 'B';
+ if($size > 1048576) { $size = $size/1048576; $prefix = 'M'; }
+ elseif($size > 1024) { $size = $size/1024; $prefix = 'K'; }
+ return round($size, 6).$prefix;
+ }
function getmicrotime()
{
@@ -171,34 +239,34 @@ function SDI($msg="SDI") { echo "DEBUG INFO: "; if(is_array($msg)) print_r($msg)
return $ret;
}
//Special processing of uptime
- if($units=="uptime")
- {
- $ret="";
- $days=floor($value/(24*3600));
- if($days>0)
- {
- $value=$value-$days*(24*3600);
- }
- $hours=floor($value/(3600));
- if($hours>0)
- {
- $value=$value-$hours*3600;
- }
- $min=floor($value/(60));
- if($min>0)
+ if($units=="uptime")
{
- $value=$value-$min*(60);
- }
- if($days==0)
- {
- $ret = sprintf("%02d:%02d:%02d", $hours, $min, $value);
- }
- else
- {
- $ret = sprintf("%d days, %02d:%02d:%02d", $days, $hours, $min, $value);
+ $ret="";
+ $days=floor($value/(24*3600));
+ if($days>0)
+ {
+ $value=$value-$days*(24*3600);
+ }
+ $hours=floor($value/(3600));
+ if($hours>0)
+ {
+ $value=$value-$hours*3600;
+ }
+ $min=floor($value/(60));
+ if($min>0)
+ {
+ $value=$value-$min*(60);
+ }
+ if($days==0)
+ {
+ $ret = sprintf("%02d:%02d:%02d", $hours, $min, $value);
+ }
+ else
+ {
+ $ret = sprintf("%d days, %02d:%02d:%02d", $days, $hours, $min, $value);
+ }
+ return $ret;
}
- return $ret;
- }
// Special processing for seconds
if($units=="s")
{
@@ -1254,27 +1322,47 @@ function GetPos(obj)
var hint_box = null;
+function get_cursor_position(e)
+{
+ e = e || window.event;
+ var cursor = {x:0, y:0};
+ if (e.pageX || e.pageY) {
+ cursor.x = e.pageX;
+ cursor.y = e.pageY;
+ }
+ else {
+ var de = document.documentElement;
+ var b = document.body;
+ cursor.x = e.clientX +
+ (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
+ cursor.y = e.clientY +
+ (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
+ }
+ return cursor;
+}
+
function hide_hint()
{
if(!hint_box) return;
hint_box.style.visibility="hidden"
- //hint_box.style.width = "0px"
- hint_box.style.left = "-" + hint_box.style.width;
+ hint_box.style.left = "-" + ((hint_box.style.width) ? hint_box.style.width : 100) + "px";
}
-function show_hint(obj, hint_text)
+function show_hint(obj, e, hint_text)
{
- show_hint_ext(obj, hint_text, "", "");
+ show_hint_ext(obj, e, hint_text, "", "");
}
-function show_hint_ext(obj, hint_text, width, class)
+function show_hint_ext(obj, e, hint_text, width, class_name)
{
if(!hint_box) return;
+
+ var cursor = get_cursor_position(e);
- if(class != "")
+ if(class_name != "")
{
- hint_text = "<span class=" + class + ">" + hint_text + "</span>";
+ hint_text = "<span class=" + class_name + ">" + hint_text + "</"+"span>";
}
hint_box.innerHTML = hint_text;
@@ -1285,7 +1373,8 @@ function show_hint_ext(obj, hint_text, width, class)
hint_box.x = pos[0];
hint_box.y = pos[1];
- hint_box.style.left = hint_box.x + obj.offsetWidth + 10 + "px";
+ hint_box.style.left = cursor.x + 10 + "px";
+ //hint_box.style.left = hint_box.x + obj.offsetWidth + 10 + "px";
hint_box.style.top = hint_box.y + obj.offsetHeight + "px";
hint_box.style.visibility = "visible";
@@ -1672,16 +1761,24 @@ else if (document.getElementById)
return true;
}
- function set_image_header($format=IMAGE_FORMAT_DEFAULT)
+ function set_image_header($format=null)
{
+ global $IMAGE_FORMAT_DEFAULT;
+
+ if(is_null($format)) $format = $IMAGE_FORMAT_DEFAULT;
+
if(IMAGE_FORMAT_JPEG == $format) Header( "Content-type: image/jpeg");
if(IMAGE_FORMAT_TEXT == $format) Header( "Content-type: text/html");
else Header( "Content-type: image/png");
Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT");
}
- function ImageOut($image,$format=IMAGE_FORMAT_DEFAULT)
+ function ImageOut($image,$format=NULL)
{
+ global $IMAGE_FORMAT_DEFAULT;
+
+ if(is_null($format)) $format = $IMAGE_FORMAT_DEFAULT;
+
if(IMAGE_FORMAT_JPEG == $format)
ImageJPEG($image);
else
diff --git a/frontends/php/include/copt.lib.php b/frontends/php/include/copt.lib.php
index ba67f4f1..76991054 100644
--- a/frontends/php/include/copt.lib.php
+++ b/frontends/php/include/copt.lib.php
@@ -136,14 +136,6 @@ if(defined('USE_MEM_PROF')) {
}
}
- /* protected static */ function mem2str($size)
- {
- $prefix = 'B';
- if($size > 1048576) { $size = $size/1048576; $prefix = 'M'; }
- elseif($size > 1024) { $size = $size/1024; $prefix = 'K'; }
- return round($size, 6).$prefix;
- }
-
/* public static */ function counter_up($type=NULL)
{
if(defined('USE_COUNTER_PROF'))
@@ -224,8 +216,8 @@ if(defined('USE_TIME_PROF'))
if(defined('USE_MEM_PROF'))
{
echo "(".$type.") Memory limit : ".ini_get('memory_limit')."<br/>\n";
- echo "(".$type.") Memory usage : ".COpt::mem2str($memorystamp[$type])." - ".COpt::mem2str($memory)."\n<br/>\n";
- echo "(".$type.") Memory leak : ".COpt::mem2str($memory - $memorystamp[$type])."\n<br/>\n";
+ echo "(".$type.") Memory usage : ".mem2str($memorystamp[$type])." - ".mem2str($memory)."\n<br/>\n";
+ echo "(".$type.") Memory leak : ".mem2str($memory - $memorystamp[$type])."\n<br/>\n";
}
if(defined('USE_VAR_MON'))
{
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index 000c14fb..8be2f932 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -19,52 +19,113 @@
**/
?>
<?php
+ function DBconnect(&$error)
+ {
+ $result = true;
+
+ global $DB, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
-// DATABASE CONFIGURATION
-
-// $DB_TYPE ="ORACLE";
-// $DB_TYPE ="POSTGRESQL";
- $DB_TYPE ="MYSQL";
- $DB_SERVER ="localhost";
- $DB_DATABASE ="osmiy1";
- $DB_USER ="root";
- $DB_PASSWORD ="";
-// END OF DATABASE CONFIGURATION
+ if(!isset($DB_TYPE))
+ {
+ $error = "Uncnown database type.";
+ $result = false;
+ }
+ else
+ {
+ if($DB_TYPE == "MYSQL")
+ {
+ $DB = mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD);
+ if(!mysql_select_db($DB_DATABASE))
+ {
+ $error = "Error connecting to database [".mysql_error()."]";
+ $result = false;
+ }
+ else
+ {
+ 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)
+ {
+ $error = "Error connecting to database";
+ $result = false;
+ }
+ }
- global $USER_DETAILS;
+ if($DB_TYPE == "ORACLE")
+ {
+ $DB = ocilogon($DB_USER, $DB_PASSWORD, "");
+ // $DB = ocilogon($DB_USER, $DB_PASSWORD, "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$DB_SERVER)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=$DB_DATABASE)))");
+ if(!$DB)
+ {
+ $error = "Error connecting to database";
+ $result = false;
+ }
+ }
+ }
+ return $result;
+ }
- if($DB_TYPE == "MYSQL")
+ function DBclose()
{
- $DB=mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD);
- if(!mysql_select_db($DB_DATABASE))
+ global $DB, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+
+ $result = false;
+
+ if($DB)
{
- echo "Error connecting to database [".mysql_error()."]";
- exit;
+ if($DB_TYPE == "MYSQL") $result = mysql_close($DB);
+ elseif($DB_TYPE == "POSTGRESQL") $result = pg_close($DB);
+ elseif($DB_TYPE == "ORACLE") $result = ociclose($DB);
}
- mysql_select_db($DB_DATABASE);
+ unset(
+ $GLOBALS['DB'],
+ $GLOBALS['DB_TYPE'],
+ $GLOBALS['DB_SERVER'],
+ $GLOBALS['DB_DATABASE'],
+ $GLOBALS['DB_USER'],
+ $GLOBALS['DB_PASSWORD']
+ );
+
+
+ return $result;
}
- if($DB_TYPE == "POSTGRESQL")
+
+ function DBloadfile($file, &$error)
{
- $DB=pg_pconnect("host='$DB_SERVER' dbname='$DB_DATABASE' user='$DB_USER' password='$DB_PASSWORD'");
- if(!$DB)
+ global $DB_TYPE;
+
+ if(!file_exists($file))
{
- echo "Error connecting to database";
- exit;
+ $error = 'DBloadfile. Missing file['.$file.']';
+ return false;
}
- }
+
+ $fl = file($file);
+
+ foreach($fl as $n => $l) if(substr($l,0,2)=='--') unset($fl[$n]);
+
+ $fl = explode(";\n", implode("\n",$fl));
+ unset($fl[count($fl)-1]);
+
+ $result = true;
- if($DB_TYPE == "ORACLE")
- {
- $DB = ocilogon($DB_USER, $DB_PASSWORD, "");
-// $DB = ocilogon($DB_USER, $DB_PASSWORD, "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$DB_SERVER)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=$DB_DATABASE)))");
- if(!$DB)
+ foreach($fl as $sql)
{
- echo "Error connecting to database";
- exit;
+ if(empty($sql)) continue;
+
+ if(!DBexecute($sql,0))
+ {
+ $error = '';
+ return false;
+ }
}
+ return true;
}
-
function DBstart()
{
/* TODO *//* start transaction */
@@ -103,7 +164,6 @@
{
global $DB,$DB_TYPE;
-// echo $query,"<br>";
COpt::savesqlrequest($query);
if($DB_TYPE == "MYSQL")
@@ -115,7 +175,7 @@ COpt::savesqlrequest($query);
$result=mysql_query($query,$DB);
if(!$result)
{
- echo "Error in query [$query] [".mysql_error()."]";
+ error("Error in query [$query] [".mysql_error()."]");
}
return $result;
}
@@ -155,7 +215,6 @@ COpt::savesqlrequest($query);
{
global $DB,$DB_TYPE;
-// echo $query,"<br>";
COpt::savesqlrequest($query);
$result = FALSE;
@@ -201,7 +260,6 @@ COpt::savesqlrequest($query);
}
if($DB_TYPE == "ORACLE")
{
-// echo "DBfetch<br>";
if(!ocifetchinto($cursor, $row, OCI_ASSOC+OCI_NUM+OCI_RETURN_NULLS))
{
return FALSE;
@@ -235,8 +293,7 @@ COpt::savesqlrequest($query);
$row=pg_fetch_row($result,$rownum);
if(!$row)
{
- echo "Error getting row";
- exit;
+ fatal_error("Error getting row");
}
return $row[$fieldnum];
}
@@ -258,7 +315,6 @@ COpt::savesqlrequest($query);
if($DB_TYPE == "POSTGRESQL")
{
$oid=pg_getlastoid($result);
-// echo "OID:$oid<br>";
$sql="select $field from $table where oid=$oid";
$result=DBselect($sql);
return get_field($result,0,0);
@@ -279,7 +335,7 @@ COpt::savesqlrequest($query);
}
/* string value prepearing */
-if($DB_TYPE == "ORACLE") {
+if(isset($DB_TYPE) && $DB_TYPE == "ORACLE") {
function zbx_dbstr($var) {
return "'".ereg_replace('\'','\'\'',$var)."'";
}
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index b882785f..2d282396 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -43,10 +43,6 @@
define("IMAGE_FORMAT_PNG", "PNG");
define("IMAGE_FORMAT_JPEG", "JPEG");
define("IMAGE_FORMAT_TEXT", "JPEG");
-// define("IMAGE_FORMAT_DEFAULT", IMAGE_FORMAT_TEXT);
- define("IMAGE_FORMAT_DEFAULT", IMAGE_FORMAT_PNG);
- define("MAP_OUTPUT_FORMAT", IMAGE_FORMAT_PNG);
-// define("MAP_OUTPUT_FORMAT", IMAGE_FORMAT_JPEG);
// END OF MISC PARAMETERS
define("AUDIT_ACTION_ADD", 0);
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index 0077bbad..339a89a1 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -26,6 +26,33 @@
require_once "include/users.inc.php";
require_once "include/db.inc.php";
+ function insert_configuration_form($file)
+ {
+ $type = get_request('type', 'MYSQL');
+ $server = get_request('server', 'localhost');
+ $database = get_request('database', 'zabbix');
+ $user = get_request('user', 'root');
+ $password = get_request('password', '');
+
+ $form = new CFormTable(S_CONFIGURATION_OF_ZABBIX_DATABASE, null, 'post');
+
+ $form->SetHelp("install_source_web.php");
+ $cmbType = new CComboBox('type', $type);
+ $cmbType->AddItem('MYSQL', S_MYSQL);
+ $cmbType->AddItem('POSTGRESQL', S_POSTGRESQL);
+ $cmbType->AddItem('ORACLE', S_ORACLE);
+ $form->AddRow(S_TYPE, $cmbType);
+
+ $form->AddRow(S_HOST, new CTextBox('server', $server));
+ $form->AddRow(S_NAME, new CTextBox('database', $database));
+ $form->AddRow(S_USER, new CTextBox('user', $user));
+ $form->AddRow(S_PASSWORD, new CPassBox('password', $password));
+
+ $form->AddItemToBottomRow(new CButton('save',S_SAVE));
+
+ $form->Show();
+ }
+
function insert_node_form()
{
global $ZBX_CURNODEID;
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index 50c00a38..8b1ff8e7 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -27,6 +27,18 @@
"S_DATE_FORMAT_YMD"=> "d M Y",
"S_HTML_CHARSET"=> "iso-8859-1",
+// admin.php
+ "S_PREVIOUS"=> "<< Previous",
+ "S_NEXT"=> "Next >>",
+ "S_RETRY"=> "Retry",
+ "S_FINISH"=> "Finish",
+ "S_FAIL"=> "Fail",
+ "S_UPDATE_BIG"=> "UPDATE",
+ "S_INSTALLATION"=> "Installation",
+ "S_NEW_INSTALLATION"=> "New installation",
+ "S_NEW_INSTALLATION_BIG"=> "NEW INSTALLATION",
+ "S_INSTALLATION_UPDATE"=> "Installation/Update",
+
// node.php
"S_TIME_ZONE"=> "Time zone",
"S_DO_NOT_KEEP_HISTORY_OLDER_THAN"=> "Do not keep history older than (in days)",
diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php
index 72f85541..43693086 100644
--- a/frontends/php/include/page_header.php
+++ b/frontends/php/include/page_header.php
@@ -20,6 +20,7 @@
?>
<?php
require_once("include/config.inc.php");
+ require_once("include/perm.inc.php");
global $USER_DETAILS;
global $ZBX_CURNODEID;
@@ -81,30 +82,32 @@ COpt::profiling_start("page");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=<?php echo S_HTML_CHARSET; ?>">
-<meta name="Author" content="ZABBIX SIA (Alexei Vladishev, Eugene Grigorjev)">
-<link rel="stylesheet" href="css.css">
+ <head>
<?php
if(isset($page['title']) && defined($page['title'])) $page['title'] = constant($page['title']);
- if(defined('ZBX_PAGE_DO_REFRESH') && $USER_DETAILS["refresh"])
- {
- echo " <meta http-equiv=\"refresh\" content=\"".$USER_DETAILS["refresh"]."\">\n";
-
- if(isset($page['title']))
- $page['title'] .= ' [refreshed every '.$USER_DETAILS['refresh'].' sec]';
- }
-
- if(isset($page['title']))
+ if(!isset($page['title'])) $page['title'] = 'ZABBIX';
+
+ if(defined('ZBX_DISTRIBUTED'))
{
if($curr_node_data = DBfetch(DBselect('select * from nodes where nodeid='.$ZBX_CURNODEID)))
$page['title'] = '('.$curr_node_data['name'].') '.$page['title'];
-
- echo " <title>".$page['title']."</title>\n";
}
+
+ if(defined('ZBX_PAGE_DO_REFRESH') && $USER_DETAILS["refresh"])
+ {
+?>
+ <meta http-equiv=\"refresh\" content="<?php echo $USER_DETAILS["refresh"] ?>">
+<?php
+ $page['title'] .= ' [refreshed every '.$USER_DETAILS['refresh'].' sec]';
+ }
+
?>
-</head>
+ <title><?php echo $page['title'] ?></title>
+ <link rel="stylesheet" href="css.css">
+ <meta http-equiv="Content-Type" content="text/html; charset=<?php echo S_HTML_CHARSET ?>">
+ <meta name="Author" content="ZABBIX SIA (Alexei Vladishev, Eugene Grigorjev)">
+ </head>
<body>
<?php
break; /* case PAGE_TYPE_HTML */
@@ -197,7 +200,6 @@ COpt::profiling_start("page");
"label" => S_ADMINISTRATION,
"default_page_id" => 0,
"pages"=>array(
- array("url"=>"admin.php" ,"label"=>S_ADMINISTRATION ),
ZBX_DISTRIBUTED ? array("url"=>"nodes.php" ,"label"=>S_NODES) : null ,
array("url"=>"users.php" ,"label"=>S_USERS ,
"sub_pages"=>array("popup_media.php",
@@ -205,7 +207,9 @@ COpt::profiling_start("page");
),
array("url"=>"media_types.php" ,"label"=>S_MEDIA_TYPES ),
array("url"=>"audit.php" ,"label"=>S_AUDIT ),
- array("url"=>"report4.php" ,"label"=>S_NOTIFICATIONS )
+ array("url"=>"report4.php" ,"label"=>S_NOTIFICATIONS ),
+ array("url"=>"instal.php" ,"label"=>S_INSTALLATION ,
+ "sub_pages"=>array("setup.php"))
)
),
"login"=>array(
diff --git a/frontends/php/include/perm.inc.php b/frontends/php/include/perm.inc.php
index 27a1ed3e..493ec095 100644
--- a/frontends/php/include/perm.inc.php
+++ b/frontends/php/include/perm.inc.php
@@ -19,7 +19,7 @@
**/
?>
<?php
- require_once "db.inc.php";
+ require_once "include/db.inc.php";
function permission2str($group_permission)
{
diff --git a/frontends/php/include/setup.inc.php b/frontends/php/include/setup.inc.php
new file mode 100644
index 00000000..2146b6af
--- /dev/null
+++ b/frontends/php/include/setup.inc.php
@@ -0,0 +1,739 @@
+<?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.
+**/
+?>
+<?php
+ function zbx_is_callable($var)
+ {
+ foreach($var as $e)
+ if(!is_callable($e)) return false;
+
+ return true;
+ }
+
+ class CSetupWizard extends CForm
+ {
+/* protected */
+ var $ZBX_CONFIG;
+ var $DISABLE_NEXT_BUTTON;
+ var $stage = array(
+ 0 => array('title' => '1. Intoduction' , 'fnc' => 'Stage0' ),
+ 1 => array('title' => '2. License Agreement' , 'fnc' => 'Stage1' ),
+ 2 => array('title' => '3. Checking of requirements' , 'fnc' => 'Stage2' ),
+ 3 => array('title' => '4. Configure of DB connection' , 'fnc' => 'Stage3' ),
+ 4 => array('title' => '5. Distributed monitoring' , 'fnc' => 'Stage4' ),
+ 5 => array('title' => '6. Pre-Installation Summery' , 'fnc' => 'Stage5' ),
+ 6 => array('title' => '7. Installing...' , 'fnc' => 'Stage6' ),
+ 7 => array('title' => '8. Finishing...' , 'fnc' => 'Stage7' )
+ );
+
+/* public */
+ function CSetupWizard(&$ZBX_CONFIG)
+ {
+ $this->DISABLE_NEXT_BUTTON = false;
+
+ $this->ZBX_CONFIG = &$ZBX_CONFIG;
+
+ $this->EventHandler();
+
+ parent::CForm(null, 'post');
+ }
+
+ function GetConfig($name, $default)
+ {
+ return isset($this->ZBX_CONFIG[$name]) ? $this->ZBX_CONFIG[$name] : $default;
+ }
+ function SetConfig($name, $value)
+ {
+ return ($this->ZBX_CONFIG[$name] = $value);
+ }
+
+ function GetStep()
+ {
+ return $this->GetConfig('step', 0);
+ }
+ function DoNext()
+ {
+ if(isset($this->stage[$this->GetStep() + 1]))
+ {
+ $this->ZBX_CONFIG['step']++;
+ return true;
+ }
+ return false;
+ }
+ function DoBack()
+ {
+ if(isset($this->stage[$this->GetStep() - 1]))
+ {
+ $this->ZBX_CONFIG['step']--;
+ return true;
+ }
+ return false;
+ }
+
+ function BodyToString($destroy=true)
+ {
+ $table = new CTable(null, 'setup_wizard');
+ $table->SetAlign('center');
+ $table->SetHeader(array(
+ new CCol(S_ZABBIX_VER, 'left'),
+ SPACE
+ ),'header');
+ $table->AddRow(array(SPACE, new CCol($this->stage[$this->GetStep()]['title'], 'right')),'title');
+ $table->AddRow(array(
+ new CCol($this->GetList(), 'left'),
+ new CCol($this->GetState(), 'right')
+ ), 'center');
+
+ $next = new CButton('next['.$this->GetStep().']', S_NEXT);
+ if($this->DISABLE_NEXT_BUTTON) $next->SetEnabled(false);
+
+ $table->SetFooter(array(
+ new CCol(new CButton('cancel',S_CANCEL),'left'),
+ new CCol(array(
+ isset($this->stage[$this->GetStep()-1]) ? new CButton('back['.$this->GetStep().']', S_PREVIOUS) : null,
+ isset($this->stage[$this->GetStep()+1]) ? $next: new CButton('finish', S_FINISH)
+ ) , 'right')
+ ),'footer');
+
+ return parent::BodyToString($destroy).$table->ToString();
+ }
+
+ function GetList()
+ {
+ $list = new CList();
+ foreach($this->stage as $id => $data)
+ {
+ if($id < $this->GetStep()) $style = 'completed';
+ elseif($id == $this->GetStep()) $style = 'current';
+ else $style = null;
+
+ $list->AddItem($data['title'], $style);
+ }
+ return $list->ToString();
+ }
+
+ function GetState()
+ {
+ $fnc = $this->stage[$this->GetStep()]['fnc'];
+ return $this->$fnc();
+ }
+
+ function Stage0()
+ {
+
+ return new CTag('div', 'yes', 'Welcom to the ZABBIX frontend installation guide.'.BR.BR.
+ 'This installation guide will guide you through the installation of ZABBIX fromtend'.BR.BR.
+ 'Click to "Next" button to proceed to the next screen. If you want to change somethong '.
+ 'on previos screen, click "Previous" button'.BR.BR.
+ 'You may cancel installation at any time by clicking "Cancel" button', 'text');
+ }
+
+ function Stage1()
+ {
+ $LICENCE_FILE = 'conf/COPYING';
+
+ $this->DISABLE_NEXT_BUTTON = !$this->GetConfig('agree', false);
+
+ return array(
+ new CTag('div', 'yes', (file_exists($LICENCE_FILE) ?
+ nl2br(nbsp(htmlspecialchars(file_get_contents($LICENCE_FILE)))) :
+ 'Missing licence file. See GPL licence.')
+ , 'licence'),
+ BR,
+ new CTag('div', 'yes',
+ array(
+ new CCheckBox(
+ 'agree',
+ $this->GetConfig('agree', false),
+ 'submit();'),
+ 'I\'m agree'),
+ 'center')
+ );
+ }
+
+ function Stage2()
+ {
+ function get_test_result(&$result, $test_name, $test_value, $condition, $fail_message)
+ {
+ $result &= $condition;
+
+ $row = new CRow(array(
+ $test_name,
+ $test_value,
+ $condition ? new CSpan(S_OK,'ok') : new CSpan(S_FAIL,'fail')
+ ),
+ !$condition ? 'fail' : null);
+
+ if(!$condition && isset($fail_message))
+ $row->SetHint($fail_message);
+
+ return $row;
+ }
+
+ $final_result = true;
+
+ $table = new CTable(null, 'requirements');
+ $table->SetAlign('center');
+
+ /* Check PHP version */
+ $table->AddRow(get_test_result(
+ $final_result,
+ 'PHP version: ',
+ phpversion(),
+ version_compare(phpversion(), '4.3.0', '>='),
+ 'Minimal version of PHP is 4.3.0'));
+
+ $memory_limit = str2mem(ini_get('memory_limit'));
+ $table->AddRow(get_test_result(
+ $final_result,
+ 'PHP Memory limit:',
+ function_exists('memory_get_usage') ? mem2str($memory_limit) : 'unlimited',
+ $memory_limit >= 8*1024*1024 || !function_exists('memory_get_usage'),
+ '8M is a minimal PHP memory limitation'));
+
+ $memory_limit = str2mem(ini_get('post_max_size'));
+ $table->AddRow(
+ get_test_result(
+ $final_result,
+ 'PHP post max size:',
+ mem2str($memory_limit),
+ $memory_limit >= 8*1024*1024,
+ '8M is minimum size of PHP post'));
+
+ $table->AddRow(
+ get_test_result(
+ $final_result,
+ 'PHP max execution time:',
+ ini_get('max_execution_time').' sec',
+ ini_get('max_execution_time') >= 300,
+ '300 sec is a maximal limitation on execution of PHP scripts'));
+
+ /* Check supporteds databases */
+ global $ZBX_CONFIG;
+
+ $table->AddRow(
+ get_test_result(
+ $final_result,
+ 'PHP Databases support: ',
+ implode(BR, $ZBX_CONFIG['allowed_db']),
+ !isset($ZBX_CONFIG['allowed_db']['no']),
+ 'Required any databases support [MySQL or PostgreSQL or Oracle]'));
+
+ /* Check GD existence */
+ $gd_version = S_NO;
+ if(is_callable('gd_info'))
+ {
+ $gd_info = gd_info();
+ $gd_version = $gd_info['GD Version'];
+ }
+ $table->AddRow(
+ get_test_result(
+ $final_result,
+ 'GD Version:',
+ $gd_version,
+ $gd_version != S_NO,
+ 'The GD extension isn\'t loaded.'));
+
+ /* Check supported image formats */
+ $img_formats = array();
+ if(isset($gd_info))
+ {
+ //if($gd_info['JPG Support']) array_push($img_formats, 'JPEG');
+ if($gd_info['PNG Support']) array_push($img_formats, 'PNG');
+ }
+ if(count($img_formats) == 0)
+ {
+ $img_formats = array(S_NO);
+ $no_img_formats = true;
+ }
+ $table->AddRow(
+ get_test_result(
+ $final_result,
+ 'Image formats:',
+ implode(BR, $img_formats),
+ !isset($no_img_formats),
+ 'Required images genetarion support [PNG]'));
+
+ if(!$final_result)
+ {
+ $this->DISABLE_NEXT_BUTTON = true;
+
+ $this->AddVar('trouble',true);
+
+ $final_result = array(
+ new CSpan(S_FAIL,'fail'),
+ BR, BR,
+ 'Please correct all issuse and press "Retry" button',
+ BR, BR,
+ new CButton('retry', S_RETRY)
+ );
+ }
+ else
+ {
+ $this->DISABLE_NEXT_BUTTON = false;
+ $final_result = new CSpan(S_OK,'ok');
+ }
+
+ return array($table, BR, $final_result);
+ }
+
+ function Stage3()
+ {
+ global $ZBX_CONFIG, $_REQUEST;
+
+ $table = new CTable();
+ $table->SetAlign('center');
+
+ $cmbType = new CComboBox('type', $this->GetConfig('DB_TYPE', 'MYSQL'));
+ foreach($ZBX_CONFIG['allowed_db'] as $id => $name)
+ {
+ $cmbType->AddItem($id, $name);
+ }
+ $table->AddRow(array(S_TYPE, $cmbType));
+ $table->AddRow(array(S_HOST, new CTextBox('server', $this->GetConfig('DB_SERVER', 'localhost'))));
+ $table->AddRow(array(S_NAME, new CTextBox('database', $this->GetConfig('DB_DATABASE', 'zabbix'))));
+ $table->AddRow(array(S_USER, new CTextBox('user', $this->GetConfig('DB_USER', 'root'))));
+ $table->AddRow(array(S_PASSWORD, new CPassBox('password', $this->GetConfig('DB_PASSWORD', ''))));
+
+ return array(
+ 'Please create database manually.', BR,
+ 'And set the configuration parameters of connection to this database.',
+ BR,BR,
+ 'And press "Test connection" button.',
+ BR,BR,
+ $table,
+ BR,
+ !$this->DISABLE_NEXT_BUTTON ? new CSpan(S_OK,'ok') : new CSpan(S_FAIL, 'fail'),
+ BR,
+ new CButton('retry', 'Test connection')
+ );
+ }
+
+ function Stage4()
+ {
+ global $_SERVER;
+
+ if($this->GetConfig('distributed', null))
+ {
+ $table = new CTable();
+ $table->SetAlign('center');
+ $table->AddRow(array(
+ 'Node name',
+ new CTextBox('nodename', $this->GetConfig('nodename', $_SERVER["SERVER_NAME"]), 40)
+ ));
+ $table->AddRow(array(
+ 'Node GUID',
+ new CNumericBox('nodeid', $this->GetConfig('nodeid', 0), 10)
+ ));
+
+ }
+ else
+ {
+ $table = null;
+ }
+
+ return new CTag('div', 'yes', array(
+ 'The goal in the distributed monitoring environment is a service checks from a "central" server '.
+ 'onto one or more "distributed" servers. Most small to medium sized systems '.
+ 'will not have a real need for setting up such an environment.',BR,BR,
+ 'Please check the "Use distributed monitoring" to enabling this functionality',BR,BR,
+ new CTag('div', 'yes', array(
+ new CCheckBox('distributed', $this->GetConfig('distributed', null), 'submit();'),
+ 'Use distributed monitoring'),
+ 'center'),
+ BR,BR,
+ $table
+ ), 'text');
+ }
+
+ function Stage5()
+ {
+ $allowed_db = $this->GetConfig('allowed_db', array());
+
+ $table = new CTable(null, 'requirements');
+ $table->SetAlign('center');
+ $table->AddRow(array('Database type', $allowed_db[$this->GetConfig('DB_TYPE', 'uncnown')]));
+ $table->AddRow(array('Database server', $this->GetConfig('DB_SERVER', 'uncnown')));
+ $table->AddRow(array('Database name', $this->GetConfig('DB_DATABASE', 'uncnown')));
+ $table->AddRow(array('Database user', $this->GetConfig('DB_USER', 'uncnown')));
+ $table->AddRow(array('Database password', $this->GetConfig('DB_PASSWORD', 'uncnown')));
+ $table->AddRow(array('Distributed monitoring', $this->GetConfig('distributed', null) ? 'Enabled' : 'Disabled'));
+ if($this->GetConfig('distributed', null))
+ {
+ $table->AddRow(array('Node name', $this->GetConfig('nodename', 'uncnown')));
+ $table->AddRow(array('Node GUID', $this->GetConfig('nodeid', 'uncnown')));
+ }
+ return array(
+ 'Please check configuration parameters.', BR,
+ 'If all correct press "Next" button, or "Previous" button to change configuration parameters.', BR, BR,
+ $table
+ );
+ }
+
+ function Stage6()
+ {
+ global $_SERVER, $ZBX_CONFIGURATION_FILE;
+
+ if(is_writable($ZBX_CONFIGURATION_FILE))
+ {
+ /* Write the new contents */
+ if($f = fopen($ZBX_CONFIGURATION_FILE, 'w'))
+ {
+ if(fwrite($f, addslashes($config_content)))
+ {
+ if(fclose($f))
+ {
+ $config_saved = true;
+ }
+ }
+ }
+ }
+
+ $table = new CTable(null, 'requirements');
+ $table->SetAlign('center');
+
+ $table->AddRow(array('Configuration file:', $this->GetConfig('ZBX_CONFIG_FILE_CORRECT', false) ?
+ new CSpan(S_OK,'ok') :
+ new CSpan(S_FAIL,'fail')
+ ));
+
+ $table->AddRow(array('Table creation:', $this->GetConfig('ZBX_TABLES_CREATED', false) ?
+ new CSpan(S_OK,'ok') :
+ new CSpan(S_FAIL,'fail')
+ ));
+
+ $table->AddRow(array('Data loading:', $this->GetConfig('ZBX_DATA_LOADED', false) ?
+ new CSpan(S_OK,'ok') :
+ new CSpan(S_FAIL,'fail')
+ ));
+
+ return array(
+ $table, BR,
+ $this->DISABLE_NEXT_BUTTON ? array(new CButton('retry', S_RETRY), BR,BR) : null,
+ !$this->GetConfig('ZBX_CONFIG_FILE_CORRECT', false) ?
+ array('Please install configuration file manualy.',BR,BR,
+ 'By pressing "Save configuration file" button download configuration file ',
+ 'and place them into the ',BR,
+ '"'.(dirname($_SERVER['SCRIPT_FILENAME']).'/'.$ZBX_CONFIGURATION_FILE).'"',BR,BR,
+ new CButton('save_config',"Save configuration file"),
+ BR,BR
+ )
+ : null,
+ 'Press the '.($this->DISABLE_NEXT_BUTTON ? '"Retry"' : '"Next"').' button'
+ );
+ }
+
+ function Stage7()
+ {
+ return array(
+ 'Congratulation with succesfull instalation of ZABBIX frontend.',BR,BR,
+ 'Press "Finish" button to complete installation'
+ );
+ }
+
+ function CheckConnection()
+ {
+ global $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+
+ $DB_TYPE = $this->GetConfig('DB_TYPE', 'MYSQL');
+ $DB_SERVER = $this->GetConfig('DB_SERVER', 'localhost');
+ $DB_DATABASE = $this->GetConfig('DB_DATABASE', 'zabbix');
+ $DB_USER = $this->GetConfig('DB_USER', 'root');
+ $DB_PASSWORD = $this->GetConfig('DB_PASSWORD', '');
+
+ $error = '';
+ if(!($result = DBconnect($error)))
+ {
+ error($error);
+ }
+ else
+ {
+ $result = DBexecute('create table zabbix_installation_test ( test_row integer )');
+ $result |= DBexecute('drop table zabbix_installation_test');
+ }
+
+ DBclose();
+
+ return $result;
+ }
+
+ function CreateTables()
+ {
+ global $ZBX_CONFIGURATION_FILE;
+
+ $error = null;
+ if(file_exists($ZBX_CONFIGURATION_FILE))
+ {
+ include $ZBX_CONFIGURATION_FILE;
+
+ switch($DB_TYPE)
+ {
+ case 'MYSQL': $ZBX_SCHEMA_FILE = 'mysql.sql'; break;
+ case 'POSTGRESQL': $ZBX_SCHEMA_FILE = 'postgresql.sql'; break;
+ case 'ORACLE': $ZBX_SCHEMA_FILE = 'oracle.sql'; break;
+ }
+
+ if(isset($ZBX_SCHEMA_FILE))
+ {
+ $ZBX_SCHEMA_FILE = 'create/'.$ZBX_SCHEMA_FILE;
+ if(DBconnect($error))
+ {
+ DBloadfile($ZBX_SCHEMA_FILE, $error);
+ }
+ }
+ else
+ {
+ $error = 'Table creation. Incorrect configuration file ['.$ZBX_CONFIGURATION_FILE.']';
+ }
+ DBclose();
+ }
+ else
+ {
+ $error = 'Table creation. Missing configuration file['.$ZBX_CONFIGURATION_FILE.']';
+ }
+ if(isset($error))
+ {
+ error($error);
+ }
+
+ return !isset($error);
+ }
+
+ function LoadData()
+ {
+ global $ZBX_CONFIGURATION_FILE;
+
+ $error = null;
+ if(file_exists($ZBX_CONFIGURATION_FILE))
+ {
+ include $ZBX_CONFIGURATION_FILE;
+
+ $ZBX_DATA_FILE = 'create/data.sql';
+ if(DBconnect($error))
+ {
+ if(DBloadfile($ZBX_DATA_FILE, $error))
+ {
+ if($this->GetConfig('distributed', null))
+ {
+ if(!DBexecute('insert into nodes (nodeid, name, nodetype) values('.
+ $this->GetConfig('nodeid', 0).','.
+ zbx_dbstr($this->GetConfig('nodename', 'local')).','.
+ '1)'))
+ {
+ $error = '';
+ }
+ }
+ }
+ }
+ DBclose();
+ }
+ else
+ {
+ $error = 'Table creation. Missing configuration file['.$ZBX_CONFIGURATION_FILE.']';
+ }
+ if(isset($error))
+ {
+ error($error);
+ }
+
+ return !isset($error);
+ }
+
+ function CheckConfigurationFile()
+ {
+ global $ZBX_CONFIGURATION_FILE;
+
+ $error = null;
+
+ if(file_exists($ZBX_CONFIGURATION_FILE))
+ {
+ include $ZBX_CONFIGURATION_FILE;
+
+ if( isset($DB_TYPE) &&
+ isset($DB_SERVER) &&
+ isset($DB_DATABASE) &&
+ isset($DB_USER) &&
+ isset($DB_PASSWORD) &&
+ isset($IMAGE_FORMAT_DEFAULT) &&
+ $DB_TYPE == $this->GetConfig('DB_TYPE', null) &&
+ $DB_SERVER == $this->GetConfig('DB_SERVER', null) &&
+ $DB_DATABASE == $this->GetConfig('DB_DATABASE', null) &&
+ $DB_USER == $this->GetConfig('DB_USER', null) &&
+ $DB_PASSWORD == $this->GetConfig('DB_PASSWORD', null))
+ {
+ if(!DBconnect($error))
+ {
+ $error = 'Can not connect to database';
+ }
+ }
+ else
+ {
+ $error = 'Incorrect configuration file['.$ZBX_CONFIGURATION_FILE.']';
+ }
+ DBclose();
+ }
+ else
+ {
+ $error = 'Missing configuration file['.$ZBX_CONFIGURATION_FILE.']';
+ }
+
+ if(isset($error))
+ {
+ error($error);
+ }
+
+ return !isset($error);
+
+ }
+
+ function EventHandler()
+ {
+ global $_REQUEST;
+
+ if(isset($_REQUEST['back'][$this->GetStep()])) $this->DoBack();
+
+ if($this->GetStep() == 1)
+ {
+ if(!isset($_REQUEST['next'][0]) && !isset($_REQUEST['back'][2]))
+ {
+ $this->SetConfig('agree', isset($_REQUEST['agree']));
+ }
+
+ if(isset($_REQUEST['next'][$this->GetStep()]) && $this->GetConfig('agree', false))
+ {
+ $this->DoNext();
+ }
+ }
+ if($this->GetStep() == 2 && isset($_REQUEST['next'][$this->GetStep()]) && !isset($_REQUEST['trouble']))
+ {
+ $this->DoNext();
+ }
+ if($this->GetStep() == 3)
+ {
+ $this->SetConfig('DB_TYPE', get_request('type', $this->GetConfig('DB_TYPE', 'MYSQL')));
+ $this->SetConfig('DB_SERVER', get_request('server', $this->GetConfig('DB_SERVER', 'localhost')));
+ $this->SetConfig('DB_DATABASE', get_request('database', $this->GetConfig('DB_DATABASE', 'zabbix')));
+ $this->SetConfig('DB_USER', get_request('user', $this->GetConfig('DB_USER', 'root')));
+ $this->SetConfig('DB_PASSWORD', get_request('password', $this->GetConfig('DB_PASSWORD', '')));
+
+ if(!$this->CheckConnection())
+ {
+ $this->DISABLE_NEXT_BUTTON = true;
+ unset($_REQUEST['next']);
+ }
+ if(isset($_REQUEST['next'][$this->GetStep()])) $this->DoNext();
+ }
+
+ if($this->GetStep() == 4)
+ {
+ if(!isset($_REQUEST['next'][3]) && !isset($_REQUEST['back'][5]))
+ {
+ $this->SetConfig('distributed',
+ get_request('distributed', null));
+ }
+
+ if($this->GetConfig('distributed', null))
+ {
+ $this->SetConfig('nodename',
+ get_request('nodename',
+ $this->GetConfig('nodename', $_SERVER["SERVER_NAME"])));
+ $this->SetConfig('nodeid',
+ get_request('nodeid',
+ $this->GetConfig('nodeid', 0)));
+ }
+ else
+ {
+ $this->SetConfig('nodename', null);
+ $this->SetConfig('nodeid', null);
+ }
+ }
+
+ if($this->GetStep() == 5 && isset($_REQUEST['next'][$this->GetStep()]))
+ {
+ $this->DoNext();
+ }
+
+ if($this->GetStep() == 6)
+ {
+ $this->SetConfig('ZBX_CONFIG_FILE_CORRECT', $this->CheckConfigurationFile());
+
+ if($this->GetConfig('ZBX_CONFIG_FILE_CORRECT', false) && !$this->GetConfig('ZBX_TABLES_CREATED', false))
+ {
+ $this->SetConfig('ZBX_TABLES_CREATED', $this->CreateTables());
+ }
+
+ if($this->GetConfig('ZBX_TABLES_CREATED', false) && !$this->GetConfig('ZBX_DATA_LOADED', false))
+ {
+ $this->SetConfig('ZBX_DATA_LOADED', $this->LoadData());
+ }
+
+ if(!$this->GetConfig('ZBX_TABLES_CREATED', false) ||
+ !$this->GetConfig('ZBX_DATA_LOADED', false) ||
+ !$this->GetConfig('ZBX_CONFIG_FILE_CORRECT', false))
+ {
+ $this->DISABLE_NEXT_BUTTON = true;
+ }
+
+ if(isset($_REQUEST['save_config']))
+ {
+ global $ZBX_CONFIGURATION_FILE;
+
+ /* Make zabbix.conf.php downloadable */
+ header('Content-Type: application/x-httpd-php');
+ header('Content-Disposition: attachment; filename="'.$ZBX_CONFIGURATION_FILE.'"');
+ die(
+'<?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.
+**/
+
+global $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $IMAGE_FORMAT_DEFAULT;
+
+$DB_TYPE = "'.$this->GetConfig('DB_TYPE' ,'uncnown').'";
+$DB_SERVER = "'.$this->GetConfig('DB_SERVER' ,'uncnown').'";
+$DB_DATABASE = "'.$this->GetConfig('DB_DATABASE' ,'uncnown').'";
+$DB_USER = "'.$this->GetConfig('DB_USER' ,'uncnown').'";
+$DB_PASSWORD = "'.$this->GetConfig('DB_PASSWORD' ,'').'";
+
+$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
+?>'
+ );
+ }
+ }
+
+ if(isset($_REQUEST['next'][$this->GetStep()])) $this->DoNext();
+ }
+ }
+?>
diff --git a/frontends/php/include/validate.inc.php b/frontends/php/include/validate.inc.php
index b91b300f..95ba33d9 100644
--- a/frontends/php/include/validate.inc.php
+++ b/frontends/php/include/validate.inc.php
@@ -331,12 +331,13 @@
function invalid_url()
{
+ include_once "include/page_header.php";
unset_all();
show_error_message(S_INVALID_URL);
include_once "include/page_footer.php";
}
- function check_fields(&$fields)
+ function check_fields(&$fields, $show_messages=true)
{
global $_REQUEST;
@@ -370,7 +371,7 @@
invalid_url();
}
- show_messages();
+ if($show_messages) show_messages();
return ($err==ZBX_VALID_OK ? 1 : 0);
}