fixing bug 4851
This commit is contained in:
@@ -1,16 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
/*--------------------------------------------------
|
|
||||||
| net.class.php
|
|
||||||
| By Erik Amaru Ortiz
|
|
||||||
| CopyLeft (f) 2008
|
|
||||||
| Email: erik@colosa.com
|
|
||||||
+--------------------------------------------------
|
|
||||||
| Email bugs/suggestions to erik@colosa.com erik.260mb.com
|
|
||||||
+--------------------------------------------------
|
|
||||||
| This script has been created and released under
|
|
||||||
| the GNU GPL and is free to use and redistribute
|
|
||||||
| only if this copyright statement is not removed
|
|
||||||
+--------------------------------------------------*/
|
|
||||||
/**
|
/**
|
||||||
* LastModification 30/05/2008
|
* LastModification 30/05/2008
|
||||||
*/
|
*/
|
||||||
@@ -71,14 +59,16 @@ class NET
|
|||||||
$this->errstr = "NET::Host down";
|
$this->errstr = "NET::Host down";
|
||||||
$this->error = "Destination Host Unreachable";
|
$this->error = "Destination Host Unreachable";
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$ip = @gethostbyname($pHost);
|
$ip = @gethostbyname($pHost);
|
||||||
$long = ip2long($ip);
|
$long = ip2long($ip);
|
||||||
if ( $long == -1 || $long === FALSE) {
|
if ( $long == -1 || $long === FALSE) {
|
||||||
$this->errno = 2000;
|
$this->errno = 2000;
|
||||||
$this->errstr = "NET::Host down";
|
$this->errstr = "NET::Host down";
|
||||||
$this->error = "Destination Host Unreachable";
|
$this->error = "Destination Host Unreachable";
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->ip = @gethostbyname($pHost);
|
$this->ip = @gethostbyname($pHost);
|
||||||
$this->hostname = $pHost;
|
$this->hostname = $pHost;
|
||||||
}
|
}
|
||||||
@@ -98,13 +88,13 @@ class NET
|
|||||||
if (@fsockopen($this->ip, $pPort, $this->errno, $this->errstr, TIMEOUT)) {
|
if (@fsockopen($this->ip, $pPort, $this->errno, $this->errstr, TIMEOUT)) {
|
||||||
return true;
|
return true;
|
||||||
@fclose($x); //close connection (i dont know if this is needed or not).
|
@fclose($x); //close connection (i dont know if this is needed or not).
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->errno = 9999;
|
$this->errno = 9999;
|
||||||
$this->errstr = "NET::Port Host Unreachable";
|
$this->errstr = "NET::Port Host Unreachable";
|
||||||
$this->error = "Destination Port Unreachable";
|
$this->error = "Destination Port Unreachable";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +116,8 @@ class NET
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$key = false;
|
$key = false;
|
||||||
}
|
}
|
||||||
return $key;
|
return $key;
|
||||||
@@ -190,7 +181,8 @@ class NET
|
|||||||
case 'mysql':
|
case 'mysql':
|
||||||
if ($this->db_passwd == '') {
|
if ($this->db_passwd == '') {
|
||||||
$link = @mysql_connect($this->ip.(($this->db_port != '') && ($this->db_port != 0) ? ':'.$this->db_port : ''), $this->db_user);
|
$link = @mysql_connect($this->ip.(($this->db_port != '') && ($this->db_port != 0) ? ':'.$this->db_port : ''), $this->db_user);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$link = @mysql_connect($this->ip.(($this->db_port != '') && ($this->db_port != 0) ? ':'.$this->db_port : ''), $this->db_user, $this->db_passwd);
|
$link = @mysql_connect($this->ip.(($this->db_port != '') && ($this->db_port != 0) ? ':'.$this->db_port : ''), $this->db_user, $this->db_passwd);
|
||||||
}
|
}
|
||||||
if ($link) {
|
if ($link) {
|
||||||
@@ -198,12 +190,14 @@ class NET
|
|||||||
$stat->status = 'SUCCESS';
|
$stat->status = 'SUCCESS';
|
||||||
$this->errstr = "";
|
$this->errstr = "";
|
||||||
$this->errno = 0;
|
$this->errno = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "Lost MySql Connection";
|
$this->error = "Lost MySql Connection";
|
||||||
$this->errstr = "NET::MYSQL->Lost Connection";
|
$this->errstr = "NET::MYSQL->Lost Connection";
|
||||||
$this->errno = 10010;
|
$this->errno = 10010;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "MySql connection refused!";
|
$this->error = "MySql connection refused!";
|
||||||
$this->errstr = "NET::MYSQL->The connection was refused";
|
$this->errstr = "NET::MYSQL->The connection was refused";
|
||||||
$this->errno = 10001;
|
$this->errno = 10001;
|
||||||
@@ -232,7 +226,8 @@ class NET
|
|||||||
$stat->status = 'SUCCESS';
|
$stat->status = 'SUCCESS';
|
||||||
$this->errstr = "";
|
$this->errstr = "";
|
||||||
$this->errno = 0;
|
$this->errno = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "MS-SQL Server connection refused";
|
$this->error = "MS-SQL Server connection refused";
|
||||||
$this->errstr = "NET::MSSQL->The connection was refused";
|
$this->errstr = "NET::MSSQL->The connection was refused";
|
||||||
$this->errno = 30001;
|
$this->errno = 30001;
|
||||||
@@ -247,12 +242,14 @@ class NET
|
|||||||
$stat->status = 'SUCCESS';
|
$stat->status = 'SUCCESS';
|
||||||
$this->errstr = "";
|
$this->errstr = "";
|
||||||
$this->errno = 0;
|
$this->errno = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "Oracle connection refused";
|
$this->error = "Oracle connection refused";
|
||||||
$this->errstr = "NET::ORACLE->The connection was refused";
|
$this->errstr = "NET::ORACLE->The connection was refused";
|
||||||
$this->errno = 30001;
|
$this->errno = 30001;
|
||||||
}
|
}
|
||||||
} catch (Exception $e){
|
}
|
||||||
|
catch (Exception $e){
|
||||||
throw new Exception("[erik] Couldn't connect to Oracle Server! - ".$e->getMessage());
|
throw new Exception("[erik] Couldn't connect to Oracle Server! - ".$e->getMessage());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -261,9 +258,9 @@ class NET
|
|||||||
break;
|
break;
|
||||||
case 'sqlite':
|
case 'sqlite':
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new Exception("CLASS::NET::ERROR: No connections param.");
|
throw new Exception("CLASS::NET::ERROR: No connections param.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,17 +296,20 @@ class NET
|
|||||||
$this->errstr = "";
|
$this->errstr = "";
|
||||||
$this->errno = 0;
|
$this->errno = 0;
|
||||||
@mysql_free_result($result);
|
@mysql_free_result($result);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "the user $this->db_user doesn't have privileges to run queries!";
|
$this->error = "the user $this->db_user doesn't have privileges to run queries!";
|
||||||
$this->errstr = "NET::MYSQL->Test query failed";
|
$this->errstr = "NET::MYSQL->Test query failed";
|
||||||
$this->errno = 10100;
|
$this->errno = 10100;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "The $this->db_sourcename data base does'n exist!";
|
$this->error = "The $this->db_sourcename data base does'n exist!";
|
||||||
$this->errstr = "NET::MYSQL->Select data base failed";
|
$this->errstr = "NET::MYSQL->Select data base failed";
|
||||||
$this->errno = 10011;
|
$this->errno = 10011;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "MySql connection refused!";
|
$this->error = "MySql connection refused!";
|
||||||
$this->errstr = "NET::MYSQL->The connection was refused";
|
$this->errstr = "NET::MYSQL->The connection was refused";
|
||||||
$this->errno = 10001;
|
$this->errno = 10001;
|
||||||
@@ -324,12 +324,14 @@ class NET
|
|||||||
$stat->status = 'SUCCESS';
|
$stat->status = 'SUCCESS';
|
||||||
$this->errstr = "";
|
$this->errstr = "";
|
||||||
$this->errno = 0;
|
$this->errno = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "PostgreSql Connection to $this->ip is unreachable!";
|
$this->error = "PostgreSql Connection to $this->ip is unreachable!";
|
||||||
$this->errstr = "NET::POSTGRES->Lost Connection";
|
$this->errstr = "NET::POSTGRES->Lost Connection";
|
||||||
$this->errno = 20010;
|
$this->errno = 20010;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "PostgrSql connection refused";
|
$this->error = "PostgrSql connection refused";
|
||||||
$this->errstr = "NET::POSTGRES->The connection was refused";
|
$this->errstr = "NET::POSTGRES->The connection was refused";
|
||||||
$this->errno = 20001;
|
$this->errno = 20001;
|
||||||
@@ -345,12 +347,14 @@ class NET
|
|||||||
$stat->status = 'SUCCESS';
|
$stat->status = 'SUCCESS';
|
||||||
$this->errstr = "";
|
$this->errstr = "";
|
||||||
$this->errno = 0;
|
$this->errno = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "The $this->db_sourcename data base does'n exist!";
|
$this->error = "The $this->db_sourcename data base does'n exist!";
|
||||||
$this->errstr = "NET::MSSQL->Select data base failed";
|
$this->errstr = "NET::MSSQL->Select data base failed";
|
||||||
$this->errno = 30010;
|
$this->errno = 30010;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "MS-SQL Server connection refused!";
|
$this->error = "MS-SQL Server connection refused!";
|
||||||
$this->errstr = "NET::MSSQL->The connection was refused";
|
$this->errstr = "NET::MSSQL->The connection was refused";
|
||||||
$this->errno = 30001;
|
$this->errno = 30001;
|
||||||
@@ -368,24 +372,28 @@ class NET
|
|||||||
$this->errstr = "";
|
$this->errstr = "";
|
||||||
$this->errno = 0;
|
$this->errno = 0;
|
||||||
@oci_close($link);
|
@oci_close($link);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "the user $this->db_user don't has privileges to run queries!";
|
$this->error = "the user $this->db_user don't has privileges to run queries!";
|
||||||
$this->errstr = "NET::ORACLE->Couldn't execute any query on this server!";
|
$this->errstr = "NET::ORACLE->Couldn't execute any query on this server!";
|
||||||
$this->errno = 40010;
|
$this->errno = 40010;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$this->error = "Oracle connection refused!";
|
$this->error = "Oracle connection refused!";
|
||||||
$this->errstr = "NET::ORACLE->The connection was refused";
|
$this->errstr = "NET::ORACLE->The connection was refused";
|
||||||
$this->errno = 40001;
|
$this->errno = 40001;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'informix':
|
case 'informix':
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'sqlite':
|
case 'sqlite':
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new Exception("CLASS::NET::ERROR: No connections param.");
|
throw new Exception("CLASS::NET::ERROR: No connections param.");
|
||||||
}
|
}
|
||||||
return $stat;
|
return $stat;
|
||||||
@@ -403,43 +411,6 @@ class NET
|
|||||||
|
|
||||||
if(isset($this->ip) && isset($this->db_user) && isset($this->db_passwd)) {
|
if(isset($this->ip) && isset($this->db_user) && isset($this->db_passwd)) {
|
||||||
try{
|
try{
|
||||||
/*
|
|
||||||
switch($driver)
|
|
||||||
{
|
|
||||||
case 'mysql':
|
|
||||||
if($link = @mysql_connect($this->ip, $this->db_user, $this->db_passwd)){
|
|
||||||
$v = @mysql_get_server_info();
|
|
||||||
} else {
|
|
||||||
throw new Exception(@mysql_error($link));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'pgsql':
|
|
||||||
$this->db_port = (($this->db_port == "") || ($this->db_port == 0)) ? "5432" : $this->db_port;
|
|
||||||
$link = @pg_connect("host='$this->ip' port='$this->db_port' user='$this->db_user' password='$this->db_passwd' dbname='$this->db_sourcename'");
|
|
||||||
if($link){
|
|
||||||
$v = @pg_version($link);
|
|
||||||
} else {
|
|
||||||
throw new Exception(@pg_last_error($link));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'mssql':
|
|
||||||
if(strlen(trim($this->ip))<=0)
|
|
||||||
$this->ip = DB_HOST;
|
|
||||||
if($link = @mssql_connect($this->ip, $this->db_user, $this->db_passwd)){
|
|
||||||
@mssql_select_db( DB_NAME, $link );
|
|
||||||
$oResult = @mssql_query("select substring(@@version, 21, 6) + ' (' + CAST(SERVERPROPERTY ('productlevel') as varchar(10)) + ') ' + CAST(SERVERPROPERTY('productversion') AS VARCHAR(15)) + ' ' + CAST(SERVERPROPERTY ('edition') AS VARCHAR(25)) as version; ", $link);
|
|
||||||
$aResult = @mssql_fetch_array($oResult);
|
|
||||||
@mssql_free_result($oResult);
|
|
||||||
$v = $aResult[0];
|
|
||||||
} else {
|
|
||||||
throw new Exception(@mssql_error($link));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return (isset($v))?$v:'none';
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(!isset($this->db_sourcename))
|
if(!isset($this->db_sourcename))
|
||||||
$this->db_sourcename = DB_NAME;
|
$this->db_sourcename = DB_NAME;
|
||||||
$value = 'none';
|
$value = 'none';
|
||||||
@@ -450,8 +421,8 @@ class NET
|
|||||||
$value = $oDataBase->getServerVersion($driver, $this->ip, $this->db_port, $this->db_user, $this->db_passwd, $this->db_sourcename);
|
$value = $oDataBase->getServerVersion($driver, $this->ip, $this->db_port, $this->db_user, $this->db_passwd, $this->db_sourcename);
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
|
}
|
||||||
} catch (Exception $e){
|
catch (Exception $e){
|
||||||
throw new Exception($e->getMessage());
|
throw new Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -535,5 +506,3 @@ class NET
|
|||||||
$this->status = false;
|
$this->status = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
Reference in New Issue
Block a user