summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-06-29 10:28:15 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-06-29 10:28:15 +0000
commit96429a66214858603fff8b687dc777ab1e366ef7 (patch)
tree7af2c448a858143247ac384c8a64771aa4a978aa /frontends/php/include
parent65dd1614dba5dc1c81e953480e04e38dfda67f67 (diff)
downloadzabbix-96429a66214858603fff8b687dc777ab1e366ef7.tar.gz
zabbix-96429a66214858603fff8b687dc777ab1e366ef7.tar.xz
zabbix-96429a66214858603fff8b687dc777ab1e366ef7.zip
- improved non standard PostgreSQL & MySQL port using (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@4388 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/config.inc.php3
-rw-r--r--frontends/php/include/db.inc.php43
-rw-r--r--frontends/php/include/setup.inc.php33
3 files changed, 56 insertions, 23 deletions
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 2ed13bff..682dd7ce 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -136,6 +136,9 @@ function TODO($msg) { echo "TODO: ".$msg.BR; } // DEBUG INFO!!!
}
else
{
+ if(file_exists($ZBX_CONFIGURATION_FILE))
+ include $ZBX_CONFIGURATION_FILE;
+
define('ZBX_PAGE_NO_AUTHERIZATION', true);
define('ZBX_DISTRIBUTED', false);
$show_setup = true;
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index 4cfbef5e..16561d65 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -19,16 +19,18 @@
**/
?>
<?php
- global $DB, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
function DBconnect(&$error)
{
$result = true;
- global $DB, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
$DB = null;
+//SDI('type: '.$DB_TYPE.'; server: '.$DB_SERVER.'; port: '.$DB_PORT.'; db: '.$DB_DATABASE.'; usr: '.$DB_USER.'; pass: '.$DB_PASSWORD);
+
if(!isset($DB_TYPE))
{
$error = "Unknown database type.";
@@ -39,28 +41,39 @@
switch($DB_TYPE)
{
case "MYSQL":
- $DB = mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD);
- if(!mysql_select_db($DB_DATABASE))
+ $mysql_server = $DB_SERVER.( !empty($DB_PORT) ? ':'.$DB_PORT : '');
+
+ if ( !($DB = mysql_pconnect($mysql_server,$DB_USER,$DB_PASSWORD)))
{
$error = "Error connecting to database [".mysql_error()."]";
$result = false;
}
else
{
- mysql_select_db($DB_DATABASE);
+ if ( !mysql_select_db($DB_DATABASE) )
+ {
+ $error = 'Error database selection ['.mysql_error().']';
+ $result = false;
+ }
}
break;
case "POSTGRESQL":
- $DB=pg_pconnect("host='$DB_SERVER' dbname='$DB_DATABASE' user='$DB_USER' password='$DB_PASSWORD'");
+ $pg_connection_string =
+ ( !empty($DB_SERVER) ? 'host=\''.$DB_SERVER.'\' ' : '').
+ 'dbname=\''.$DB_DATABASE.'\' '.
+ ( !empty($DB_USER) ? 'user=\''.$DB_USER.'\' ' : '').
+ ( !empty($DB_PASSWORD) ? 'password=\''.$DB_PASSWORD.'\' ' : '').
+ ( !empty($DB_PORT) ? 'port='.$DB_PORT : '');
+SDI($pg_connection_string);
+ $DB=pg_pconnect($pg_connection_string);
if(!$DB)
{
- $error = "Error connecting to database";
+ $error = 'Error connecting to database';
$result = false;
}
break;
case "ORACLE":
$DB = ocilogon($DB_USER, $DB_PASSWORD, $DB_DATABASE);
-// $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)
{
@@ -144,16 +157,19 @@
$result = false;
}
}
+ if( false == $result )
+ $DB = null;
+
return $result;
}
function DBclose()
{
- global $DB, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
$result = false;
- if($DB)
+ if( isset($DB) && !empty($DB) )
{
switch($DB_TYPE)
{
@@ -173,6 +189,7 @@
$GLOBALS['DB'],
$GLOBALS['DB_TYPE'],
$GLOBALS['DB_SERVER'],
+ $GLOBALS['DB_PORT'],
$GLOBALS['DB_DATABASE'],
$GLOBALS['DB_USER'],
$GLOBALS['DB_PASSWORD']
@@ -254,7 +271,7 @@
COpt::savesqlrequest($query);
$result = false;
-
+ if( isset($DB) && !empty($DB) )
switch($DB_TYPE)
{
case "MYSQL":
@@ -342,6 +359,7 @@ COpt::savesqlrequest($query);
$result = false;
+ if( isset($DB) && !empty($DB) )
switch($DB_TYPE)
{
case "MYSQL":
@@ -382,10 +400,11 @@ COpt::savesqlrequest($query);
function DBfetch(&$cursor)
{
- global $DB_TYPE;
+ global $DB, $DB_TYPE;
$result = false;
+ if( isset($DB) && !empty($DB) )
switch($DB_TYPE)
{
case "MYSQL":
diff --git a/frontends/php/include/setup.inc.php b/frontends/php/include/setup.inc.php
index 1fda0289..efd165a7 100644
--- a/frontends/php/include/setup.inc.php
+++ b/frontends/php/include/setup.inc.php
@@ -347,6 +347,7 @@
}
$table->AddRow(array(S_TYPE, $cmbType));
$table->AddRow(array(S_HOST, new CTextBox('server', $this->GetConfig('DB_SERVER', 'localhost'))));
+ $table->AddRow(array(S_PORT, array(new CNumericBox('port', $this->GetConfig('DB_PORT', '0'),5),' 0 - use default port')));
$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', ''))));
@@ -409,11 +410,12 @@
$table = new CTable(null, 'requirements');
$table->SetAlign('center');
- $table->AddRow(array('Database type', $allowed_db[$this->GetConfig('DB_TYPE', 'unknown')]));
- $table->AddRow(array('Database server', $this->GetConfig('DB_SERVER', 'unknown')));
- $table->AddRow(array('Database name', $this->GetConfig('DB_DATABASE', 'unknown')));
- $table->AddRow(array('Database user', $this->GetConfig('DB_USER', 'unknown')));
- $table->AddRow(array('Database password', $this->GetConfig('DB_PASSWORD', 'unknown')));
+ $table->AddRow(array('Database type:', $allowed_db[$this->GetConfig('DB_TYPE', 'unknown')]));
+ $table->AddRow(array('Database server:', $this->GetConfig('DB_SERVER', 'unknown')));
+ $table->AddRow(array('Database port:', $this->GetConfig('DB_PORT', '0')));
+ $table->AddRow(array('Database name:', $this->GetConfig('DB_DATABASE', 'unknown')));
+ $table->AddRow(array('Database user:', $this->GetConfig('DB_USER', 'unknown')));
+ $table->AddRow(array('Database password:', $this->GetConfig('DB_PASSWORD', 'unknown')));
/* $table->AddRow(array('Distributed monitoring', $this->GetConfig('distributed', null) ? 'Enabled' : 'Disabled')); */
if($this->GetConfig('distributed', null))
{
@@ -494,11 +496,12 @@
function CheckConnection()
{
- global $DB, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
$old_DB = $DB;
$old_DB_TYPE = $DB_TYPE;
$old_DB_SERVER = $DB_SERVER;
+ $old_DB_PORT = $DB_PORT;
$old_DB_DATABASE= $DB_DATABASE;
$old_DB_USER = $DB_USER;
$old_DB_PASSWORD= $DB_PASSWORD;
@@ -507,6 +510,7 @@
if(is_null($DB_TYPE)) return false;
$DB_SERVER = $this->GetConfig('DB_SERVER', 'localhost');
+ $DB_PORT = $this->GetConfig('DB_PORT', '0');
$DB_DATABASE = $this->GetConfig('DB_DATABASE', 'zabbix');
$DB_USER = $this->GetConfig('DB_USER', 'root');
$DB_PASSWORD = $this->GetConfig('DB_PASSWORD', '');
@@ -531,11 +535,12 @@
}
/* restore connection */
- global $DB, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
$DB = $old_DB;
$DB_TYPE = $old_DB_TYPE;
$DB_SERVER = $old_DB_SERVER;
+ $DB_PORT = $old_DB_PORT;
$DB_DATABASE = $old_DB_DATABASE;
$DB_USER = $old_DB_USER;
$DB_PASSWORD = $old_DB_PASSWORD;
@@ -633,11 +638,12 @@
function CheckConfigurationFile()
{
- global $DB, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
$old_DB = $DB;
$old_DB_TYPE = $DB_TYPE;
$old_DB_SERVER = $DB_SERVER;
+ $old_DB_PORT = $DB_PORT;
$old_DB_DATABASE= $DB_DATABASE;
$old_DB_USER = $DB_USER;
$old_DB_PASSWORD= $DB_PASSWORD;
@@ -659,9 +665,11 @@
isset($IMAGE_FORMAT_DEFAULT) &&
$DB_TYPE == $this->GetConfig('DB_TYPE', null) &&
$DB_SERVER == $this->GetConfig('DB_SERVER', null) &&
+ $DB_PORT == $this->GetConfig('DB_PORT', null) &&
$DB_DATABASE == $this->GetConfig('DB_DATABASE', null) &&
$DB_USER == $this->GetConfig('DB_USER', null) &&
- $DB_PASSWORD == $this->GetConfig('DB_PASSWORD', null))
+ $DB_PASSWORD == $this->GetConfig('DB_PASSWORD', null)
+ )
{
if(!DBconnect($error_msg))
{
@@ -685,11 +693,12 @@
}
/* restore connection */
- global $DB, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $DB, $DB_TYPE, $DB_PORT, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
$DB = $old_DB;
$DB_TYPE = $old_DB_TYPE;
$DB_SERVER = $old_DB_SERVER;
+ $DB_PORT = $old_DB_PORT;
$DB_DATABASE = $old_DB_DATABASE;
$DB_USER = $old_DB_USER;
$DB_PASSWORD = $old_DB_PASSWORD;
@@ -725,6 +734,7 @@
{
$this->SetConfig('DB_TYPE', get_request('type', $this->GetConfig('DB_TYPE')));
$this->SetConfig('DB_SERVER', get_request('server', $this->GetConfig('DB_SERVER', 'localhost')));
+ $this->SetConfig('DB_PORT', get_request('port', $this->GetConfig('DB_PORT', '0')));
$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', '')));
@@ -828,10 +838,11 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-global $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $IMAGE_FORMAT_DEFAULT;
+global $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $IMAGE_FORMAT_DEFAULT;
$DB_TYPE = "'.$this->GetConfig('DB_TYPE' ,'unknown').'";
$DB_SERVER = "'.$this->GetConfig('DB_SERVER' ,'unknown').'";
+$DB_PORT = "'.$this->GetConfig('DB_PORT' ,'0').'";
$DB_DATABASE = "'.$this->GetConfig('DB_DATABASE' ,'unknown').'";
$DB_USER = "'.$this->GetConfig('DB_USER' ,'unknown').'";
$DB_PASSWORD = "'.$this->GetConfig('DB_PASSWORD' ,'').'";