HOR-4527
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
parent
abe71a6ffe
commit
0d533e19d9
@@ -79,7 +79,7 @@ class Net
|
||||
}
|
||||
if ($this->is_ipaddress($ipHost)) {
|
||||
$this->ip = $ipHost;
|
||||
if (! $this->hostname = @gethostbyaddr($ipHost)) {
|
||||
if (!$this->hostname = @gethostbyaddr($ipHost)) {
|
||||
$this->errno = 2000;
|
||||
$this->errstr = "NET::Host down";
|
||||
$this->error = G::loadTranslation('ID_HOST_UNREACHABLE');
|
||||
@@ -87,7 +87,7 @@ class Net
|
||||
} else {
|
||||
$ip = @gethostbyname($ipHost);
|
||||
$long = ip2long($ip);
|
||||
if ($long == - 1 || $long === false) {
|
||||
if ($long == -1 || $long === false) {
|
||||
$this->errno = 2000;
|
||||
$this->errstr = "NET::Host down";
|
||||
$this->error = G::loadTranslation('ID_HOST_UNREACHABLE');
|
||||
@@ -134,8 +134,8 @@ class Net
|
||||
#if have a ip address format
|
||||
if (count($tmp) == 4) {
|
||||
#if a correct ip address
|
||||
for ($i = 0; $i < count($tmp); $i ++) {
|
||||
if (! is_int($tmp[$i])) {
|
||||
for ($i = 0; $i < count($tmp); $i++) {
|
||||
if (!is_int($tmp[$i])) {
|
||||
$key = false;
|
||||
break;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ class Net
|
||||
$cmd = "ping -w $pTTL $this->ip";
|
||||
$output = exec($cmd, $a, $a1);
|
||||
$this->errstr = "";
|
||||
for ($i = 0; $i < count($a); $i ++) {
|
||||
for ($i = 0; $i < count($a); $i++) {
|
||||
$this->errstr += $a[$i];
|
||||
}
|
||||
$this->errno = $a1;
|
||||
@@ -193,7 +193,7 @@ class Net
|
||||
* This function tries to connect to server
|
||||
*
|
||||
* @param string $pDbDriver
|
||||
* @param array $arrayServerData
|
||||
* @param array $arrayServerData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -212,24 +212,26 @@ class Net
|
||||
|
||||
if (array_key_exists("connectionType", $arrayServerData) || array_key_exists("DBS_TYPEORACLE", $arrayServerData)) {
|
||||
if ($arrayServerData["connectionType"] == "TNS" || $arrayServerData["DBS_TYPEORACLE"] == "TNS") {
|
||||
$flagTns=1;
|
||||
$flagTns = 1;
|
||||
} else {
|
||||
$flagTns=0;
|
||||
$flagTns = 0;
|
||||
}
|
||||
} else {
|
||||
$flagTns=0;
|
||||
$flagTns = 0;
|
||||
}
|
||||
|
||||
if (isset($this->db_user) && (isset($this->db_passwd) || $this->db_passwd == "") && (isset($this->db_sourcename) || $flagTns == 1)) {
|
||||
switch ($pDbDriver) {
|
||||
case 'mysql':
|
||||
// Note, we suppress warnings on the connection calls because we want to avoid displaying warning
|
||||
// When utilizing this code in an API call. Otherwise it will return invalid JSON overall.
|
||||
if ($this->db_passwd == '') {
|
||||
$link = @mysql_connect($this->ip . (($this->db_port != '') && ($this->db_port != 0) ? ':' . $this->db_port : ''), $this->db_user);
|
||||
$link = @mysqli_connect($this->ip . (($this->db_port != '') && ($this->db_port != 0) ? ':' . $this->db_port : ''), $this->db_user, $this->db_sourcename);
|
||||
} else {
|
||||
$link = @mysql_connect($this->ip . (($this->db_port != '') && ($this->db_port != 0) ? ':' . $this->db_port : ''), $this->db_user, $this->db_passwd);
|
||||
$link = @mysqli_connect($this->ip . (($this->db_port != '') && ($this->db_port != 0) ? ':' . $this->db_port : ''), $this->db_user, $this->db_passwd, $this->db_sourcename);
|
||||
}
|
||||
if ($link) {
|
||||
if (@mysql_ping($link)) {
|
||||
if (mysqli_ping($link)) {
|
||||
$stat->status = 'SUCCESS';
|
||||
$this->errstr = "";
|
||||
$this->errno = 0;
|
||||
@@ -279,7 +281,7 @@ class Net
|
||||
case 'oracle':
|
||||
try {
|
||||
if ($flagTns == 0) {
|
||||
$this->db_port = ($this->db_port == "" || $this->db_port == 0)? "1521" : $this->db_port;
|
||||
$this->db_port = ($this->db_port == "" || $this->db_port == 0) ? "1521" : $this->db_port;
|
||||
|
||||
$cnn = @oci_connect($this->db_user, $this->db_passwd, "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) (HOST=$this->ip) (PORT=$this->db_port) )) (CONNECT_DATA=(SERVICE_NAME=$this->db_sourcename)))", $dbsEncode);
|
||||
} else {
|
||||
@@ -315,7 +317,7 @@ class Net
|
||||
* This function tries to open to the DB
|
||||
*
|
||||
* @param string $pDbDriver
|
||||
* @param array $arrayServerData
|
||||
* @param array $arrayServerData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -336,41 +338,39 @@ class Net
|
||||
|
||||
if (array_key_exists("connectionType", $arrayServerData) || array_key_exists("DBS_TYPEORACLE", $arrayServerData)) {
|
||||
if ($arrayServerData["connectionType"] == "TNS" || $arrayServerData["DBS_TYPEORACLE"] == "TNS") {
|
||||
$flagTns=1;
|
||||
$flagTns = 1;
|
||||
} else {
|
||||
$flagTns=0;
|
||||
$flagTns = 0;
|
||||
}
|
||||
} else {
|
||||
$flagTns=0;
|
||||
$flagTns = 0;
|
||||
}
|
||||
|
||||
if (isset($this->db_user) && (isset($this->db_passwd) || $this->db_passwd == "") && (isset($this->db_sourcename) || $flagTns == 1)) {
|
||||
switch ($pDbDriver) {
|
||||
case 'mysql':
|
||||
$link = @mysql_connect($this->ip . (($this->db_port != '') && ($this->db_port != 0) ? ':' . $this->db_port : ''), $this->db_user, $this->db_passwd);
|
||||
$db = @mysql_select_db($this->db_sourcename);
|
||||
$link = mysqli_connect($this->ip . (($this->db_port !== '') && ($this->db_port !== 0) ? ':' . $this->db_port : ''), $this->db_user, $this->db_passwd, $this->db_sourcename);
|
||||
$db = mysqli_select_db($link, $this->db_sourcename);
|
||||
$this->error = 'MySql connection refused!';
|
||||
$this->errstr = 'NET::MYSQL->The connection was refused';
|
||||
$this->errno = 10001;
|
||||
|
||||
if ($link) {
|
||||
$this->error = 'The $this->db_sourcename data base does\'n exist!';
|
||||
$this->errstr = 'NET::MYSQL->Select data base failed';
|
||||
$this->errno = 10011;
|
||||
if ($db) {
|
||||
$result = @mysql_query("show tables;");
|
||||
$result = mysqli_query($link, 'show tables;');
|
||||
$this->error = 'the user $this->db_user doesn\'t have privileges to run queries!';
|
||||
$this->errstr = 'NET::MYSQL->Test query failed';
|
||||
$this->errno = 10100;
|
||||
if ($result) {
|
||||
$stat->status = 'SUCCESS';
|
||||
$this->errstr = "";
|
||||
$this->errstr = '';
|
||||
$this->errno = 0;
|
||||
@mysql_free_result($result);
|
||||
} else {
|
||||
$this->error = "the user $this->db_user doesn't have privileges to run queries!";
|
||||
$this->errstr = "NET::MYSQL->Test query failed";
|
||||
$this->errno = 10100;
|
||||
mysqli_free_result($result);
|
||||
}
|
||||
} else {
|
||||
$this->error = "The $this->db_sourcename data base does'n exist!";
|
||||
$this->errstr = "NET::MYSQL->Select data base failed";
|
||||
$this->errno = 10011;
|
||||
}
|
||||
} else {
|
||||
$this->error = "MySql connection refused!";
|
||||
$this->errstr = "NET::MYSQL->The connection was refused";
|
||||
$this->errno = 10001;
|
||||
}
|
||||
break;
|
||||
case 'pgsql':
|
||||
@@ -393,8 +393,6 @@ class Net
|
||||
}
|
||||
break;
|
||||
case 'mssql':
|
||||
// $str_port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":".$this->db_port;
|
||||
// $link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd);
|
||||
if ($this->db_instance != "") {
|
||||
$str_port = "";
|
||||
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
|
||||
@@ -421,7 +419,7 @@ class Net
|
||||
break;
|
||||
case 'oracle':
|
||||
if ($flagTns == 0) {
|
||||
$this->db_port = ($this->db_port == "" || $this->db_port == 0)? "1521" : $this->db_port;
|
||||
$this->db_port = ($this->db_port == "" || $this->db_port == 0) ? "1521" : $this->db_port;
|
||||
|
||||
$cnn = @oci_connect($this->db_user, $this->db_passwd, "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) (HOST=$this->ip) (PORT=$this->db_port) )) (CONNECT_DATA=(SERVICE_NAME=$this->db_sourcename)))", $dbsEncode);
|
||||
} else {
|
||||
@@ -466,13 +464,13 @@ class Net
|
||||
*/
|
||||
public function getDbServerVersion($driver)
|
||||
{
|
||||
if (! isset($this->ip)) {
|
||||
if (!isset($this->ip)) {
|
||||
$this->ip = getenv('HTTP_CLIENT_IP');
|
||||
}
|
||||
|
||||
if (isset($this->ip) && isset($this->db_user) && isset($this->db_passwd)) {
|
||||
try {
|
||||
if (! isset($this->db_sourcename)) {
|
||||
if (!isset($this->db_sourcename)) {
|
||||
$this->db_sourcename = DB_NAME;
|
||||
}
|
||||
$value = 'none';
|
||||
@@ -540,7 +538,7 @@ class Net
|
||||
</div>
|
||||
</fieldset>
|
||||
<center>";
|
||||
print($msg) ;
|
||||
print($msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user