2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
2012-10-09 12:54:08 -04:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
2017-08-11 15:54:49 -04:00
|
|
|
class Net
|
2010-12-02 23:34:41 +00:00
|
|
|
{
|
2012-10-09 12:54:08 -04:00
|
|
|
public $hostname;
|
|
|
|
|
public $ip;
|
|
|
|
|
|
|
|
|
|
private $db_user;
|
|
|
|
|
private $db_passwd;
|
|
|
|
|
private $db_sourcename;
|
|
|
|
|
private $db_port;
|
|
|
|
|
private $db_instance;
|
|
|
|
|
|
|
|
|
|
/*errors handle*/
|
|
|
|
|
public $error;
|
|
|
|
|
public $errno;
|
|
|
|
|
public $errstr;
|
|
|
|
|
|
2014-05-16 18:05:34 -04:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$a = func_get_args();
|
2017-08-25 10:57:20 -04:00
|
|
|
$f = "init" . func_num_args();
|
2014-05-16 18:05:34 -04:00
|
|
|
|
|
|
|
|
if (method_exists($this, $f)) {
|
|
|
|
|
call_user_func_array(array($this, $f), $a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-25 10:57:20 -04:00
|
|
|
/**
|
|
|
|
|
* This function is the constructor of the class net
|
|
|
|
|
*
|
|
|
|
|
* return void
|
|
|
|
|
*/
|
|
|
|
|
protected function init0()
|
|
|
|
|
{
|
|
|
|
|
$this->errno = 0;
|
|
|
|
|
$this->error = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function is the constructor of the class net
|
|
|
|
|
*
|
|
|
|
|
* @param string $pHost
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function init1($pHost)
|
|
|
|
|
{
|
|
|
|
|
$this->errno = 0;
|
|
|
|
|
$this->errstr = "";
|
|
|
|
|
$this->db_instance = "";
|
|
|
|
|
|
|
|
|
|
unset($this->db_user);
|
|
|
|
|
unset($this->db_passwd);
|
|
|
|
|
unset($this->db_sourcename);
|
|
|
|
|
|
|
|
|
|
#verifing valid param
|
|
|
|
|
if ($pHost == "") {
|
|
|
|
|
$this->errno = 1000;
|
|
|
|
|
$this->errstr = "NET::You must specify a host";
|
|
|
|
|
//$this->showMsg();
|
|
|
|
|
}
|
|
|
|
|
$this->resolv($pHost);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-09 12:54:08 -04:00
|
|
|
/**
|
|
|
|
|
* This function puts a host
|
|
|
|
|
*
|
|
|
|
|
* @param string $pHost
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function resolv($pHost)
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
2017-08-11 15:54:49 -04:00
|
|
|
$aHost = explode("\\", $pHost);
|
|
|
|
|
if (count($aHost) > 1) {
|
2012-10-09 12:54:08 -04:00
|
|
|
$ipHost = $aHost[0];
|
|
|
|
|
$this->db_instance = $aHost[1];
|
|
|
|
|
} else {
|
|
|
|
|
$ipHost = $pHost;
|
|
|
|
|
}
|
2017-08-11 15:54:49 -04:00
|
|
|
if ($this->is_ipaddress($ipHost)) {
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->ip = $ipHost;
|
2017-12-04 13:25:35 +00:00
|
|
|
if (!$this->hostname = @gethostbyaddr($ipHost)) {
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->errno = 2000;
|
|
|
|
|
$this->errstr = "NET::Host down";
|
2015-09-17 17:08:41 -04:00
|
|
|
$this->error = G::loadTranslation('ID_HOST_UNREACHABLE');
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2017-08-11 15:54:49 -04:00
|
|
|
$ip = @gethostbyname($ipHost);
|
|
|
|
|
$long = ip2long($ip);
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($long == -1 || $long === false) {
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->errno = 2000;
|
|
|
|
|
$this->errstr = "NET::Host down";
|
2015-09-17 17:08:41 -04:00
|
|
|
$this->error = G::loadTranslation('ID_HOST_UNREACHABLE');
|
2012-10-09 12:54:08 -04:00
|
|
|
} else {
|
2017-08-11 15:54:49 -04:00
|
|
|
$this->ip = @gethostbyname($ipHost);
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->hostname = $pHost;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function resolves IP from Hostname returns hostname on failure
|
|
|
|
|
*
|
|
|
|
|
* @param string $pPort
|
|
|
|
|
* @return true
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function scannPort($pPort)
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
2017-08-11 15:54:49 -04:00
|
|
|
define('TIMEOUT', 5);
|
|
|
|
|
$hostip = @gethostbyname($host); // resloves IP from Hostname returns hostname on failure
|
2012-10-09 12:54:08 -04:00
|
|
|
// attempt to connect
|
2017-08-11 15:54:49 -04:00
|
|
|
if (@fsockopen($this->ip, $pPort, $this->errno, $this->errstr, TIMEOUT)) {
|
2012-10-09 12:54:08 -04:00
|
|
|
return true;
|
2017-08-11 15:54:49 -04:00
|
|
|
@fclose($x); //close connection (i dont know if this is needed or not).
|
2012-10-09 12:54:08 -04:00
|
|
|
} else {
|
|
|
|
|
$this->errno = 9999;
|
|
|
|
|
$this->errstr = "NET::Port Host Unreachable";
|
2015-09-17 17:08:41 -04:00
|
|
|
$this->error = G::loadTranslation('ID_PORT_UNREACHABLE');
|
2012-10-09 12:54:08 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function checks if it is a ip address
|
|
|
|
|
*
|
|
|
|
|
* @param string $pHost
|
|
|
|
|
* @return true
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function is_ipaddress($pHost)
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
|
|
|
|
$key = true;
|
|
|
|
|
#verifing if is a ip address
|
2017-08-11 15:54:49 -04:00
|
|
|
$tmp = explode(".", $pHost);
|
2012-10-09 12:54:08 -04:00
|
|
|
#if have a ip address format
|
2017-08-11 15:54:49 -04:00
|
|
|
if (count($tmp) == 4) {
|
2012-10-09 12:54:08 -04:00
|
|
|
#if a correct ip address
|
2017-12-04 13:25:35 +00:00
|
|
|
for ($i = 0; $i < count($tmp); $i++) {
|
|
|
|
|
if (!is_int($tmp[$i])) {
|
2012-10-09 12:54:08 -04:00
|
|
|
$key = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$key = false;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
return $key;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function executes pin -w time IP
|
|
|
|
|
*
|
|
|
|
|
* @param string $pHost
|
|
|
|
|
* @return true
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function ping($pTTL = 3000)
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
|
|
|
|
$cmd = "ping -w $pTTL $this->ip";
|
2017-08-11 15:54:49 -04:00
|
|
|
$output = exec($cmd, $a, $a1);
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->errstr = "";
|
2017-12-04 13:25:35 +00:00
|
|
|
for ($i = 0; $i < count($a); $i++) {
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->errstr += $a[$i];
|
2012-10-22 16:35:54 -04:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->errno = $a1;
|
2011-02-24 21:28:42 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function logins in db
|
|
|
|
|
*
|
|
|
|
|
* @param string $pUser
|
|
|
|
|
* @param string $pPasswd
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function loginDbServer($pUser, $pPasswd)
|
2011-02-24 21:28:42 +00:00
|
|
|
{
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->db_user = $pUser;
|
|
|
|
|
$this->db_passwd = $pPasswd;
|
2011-02-24 21:28:42 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function sets db
|
|
|
|
|
*
|
|
|
|
|
* @param string $pDb
|
|
|
|
|
* @param string $pPort
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function setDataBase($pDb, $pPort = '')
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
|
|
|
|
$this->db_sourcename = $pDb;
|
|
|
|
|
$this->db_port = $pPort;
|
2011-02-24 21:28:42 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function tries to connect to server
|
|
|
|
|
*
|
|
|
|
|
* @param string $pDbDriver
|
2017-12-04 13:25:35 +00:00
|
|
|
* @param array $arrayServerData
|
2014-05-16 18:05:34 -04:00
|
|
|
*
|
2012-10-09 12:54:08 -04:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2015-06-01 13:58:50 -04:00
|
|
|
public function tryConnectServer($pDbDriver, array $arrayServerData = array(), $dbsEncode = "")
|
2011-02-24 21:28:42 +00:00
|
|
|
{
|
2015-03-25 11:25:00 -04:00
|
|
|
$filter = new InputFilter();
|
|
|
|
|
$this->ip = $filter->validateInput($this->ip);
|
2017-08-11 15:54:49 -04:00
|
|
|
$this->db_port = $filter->validateInput($this->db_port, 'int');
|
2015-03-25 11:25:00 -04:00
|
|
|
$this->db_user = $filter->validateInput($this->db_user);
|
|
|
|
|
$this->db_passwd = $filter->validateInput($this->db_passwd);
|
|
|
|
|
$this->db_sourcename = $filter->validateInput($this->db_sourcename);
|
2012-10-09 12:54:08 -04:00
|
|
|
if ($this->errno != 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
$stat = new Stat();
|
|
|
|
|
|
2015-03-05 12:20:19 -04:00
|
|
|
if (array_key_exists("connectionType", $arrayServerData) || array_key_exists("DBS_TYPEORACLE", $arrayServerData)) {
|
|
|
|
|
if ($arrayServerData["connectionType"] == "TNS" || $arrayServerData["DBS_TYPEORACLE"] == "TNS") {
|
2017-12-04 13:25:35 +00:00
|
|
|
$flagTns = 1;
|
2017-08-11 15:54:49 -04:00
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$flagTns = 0;
|
2015-06-01 13:58:50 -04:00
|
|
|
}
|
2017-08-11 15:54:49 -04:00
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$flagTns = 0;
|
2015-03-05 12:20:19 -04:00
|
|
|
}
|
2014-05-16 18:05:34 -04:00
|
|
|
|
|
|
|
|
if (isset($this->db_user) && (isset($this->db_passwd) || $this->db_passwd == "") && (isset($this->db_sourcename) || $flagTns == 1)) {
|
2012-10-09 12:54:08 -04:00
|
|
|
switch ($pDbDriver) {
|
|
|
|
|
case 'mysql':
|
2018-02-01 13:06:32 +00:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
InstallerModule::setNewConnection('NET', $this->ip, $this->db_user, $this->db_passwd, $this->db_sourcename, $this->db_port);
|
|
|
|
|
$stat->status = 'SUCCESS';
|
|
|
|
|
$this->errstr = '';
|
|
|
|
|
$this->errno = 0;
|
|
|
|
|
} catch (Exception $exception) {
|
|
|
|
|
$this->error = 'MySql connection refused!';
|
|
|
|
|
$this->errstr = 'NET::MYSQL->The connection was refused';
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->errno = 10001;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'pgsql':
|
2018-02-01 13:06:32 +00:00
|
|
|
//todo
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->db_port = ($this->db_port == "") ? "5432" : $this->db_port;
|
2017-08-11 15:54:49 -04:00
|
|
|
$link = @pg_connect("host='$this->ip' port='$this->db_port' user='$this->db_user' password='$this->db_passwd' dbname='$this->db_sourcename'");
|
2012-10-09 12:54:08 -04:00
|
|
|
if ($link) {
|
|
|
|
|
$stat->status = 'SUCCESS';
|
|
|
|
|
$this->errstr = "";
|
|
|
|
|
$this->errno = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = "PostgreSql connection refused!";
|
|
|
|
|
$this->errstr = "NET::POSTGRES->The connection was refused";
|
|
|
|
|
$this->errno = 20001;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'mssql':
|
2018-02-01 13:06:32 +00:00
|
|
|
//todo
|
2012-10-09 12:54:08 -04:00
|
|
|
if ($this->db_instance != "") {
|
|
|
|
|
$str_port = "";
|
2017-08-11 15:54:49 -04:00
|
|
|
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
|
2012-10-09 12:54:08 -04:00
|
|
|
} else {
|
|
|
|
|
$str_port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
|
2017-08-11 15:54:49 -04:00
|
|
|
$link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd);
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($link) {
|
|
|
|
|
$stat->status = 'SUCCESS';
|
|
|
|
|
$this->errstr = "";
|
|
|
|
|
$this->errno = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = "MS-SQL Server connection refused";
|
|
|
|
|
$this->errstr = "NET::MSSQL->The connection was refused";
|
|
|
|
|
$this->errno = 30001;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'oracle':
|
2018-02-01 13:06:32 +00:00
|
|
|
//todo
|
2012-10-09 12:54:08 -04:00
|
|
|
try {
|
2014-05-16 18:05:34 -04:00
|
|
|
if ($flagTns == 0) {
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->db_port = ($this->db_port == "" || $this->db_port == 0) ? "1521" : $this->db_port;
|
2014-05-16 18:05:34 -04:00
|
|
|
|
2015-06-01 13:58:50 -04:00
|
|
|
$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);
|
2014-05-16 18:05:34 -04:00
|
|
|
} else {
|
2015-06-01 13:58:50 -04:00
|
|
|
$cnn = @oci_connect($this->db_user, $this->db_passwd, $arrayServerData["tns"], $dbsEncode);
|
2014-05-16 18:05:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($cnn) {
|
|
|
|
|
$stat->status = "SUCCESS";
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->errstr = "";
|
|
|
|
|
$this->errno = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = "Oracle connection refused";
|
|
|
|
|
$this->errstr = "NET::ORACLE->The connection was refused";
|
|
|
|
|
$this->errno = 30001;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
2017-08-11 15:54:49 -04:00
|
|
|
throw new Exception("[erik] Couldn't connect to Oracle Server! - " . $e->getMessage());
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'informix':
|
|
|
|
|
break;
|
|
|
|
|
case 'sqlite':
|
|
|
|
|
break;
|
2011-02-24 21:28:42 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
} else {
|
2017-08-11 15:54:49 -04:00
|
|
|
throw new Exception("CLASS::NET::ERROR: No connections param.");
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $stat;
|
2011-02-24 21:28:42 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function tries to open to the DB
|
|
|
|
|
*
|
|
|
|
|
* @param string $pDbDriver
|
2017-12-04 13:25:35 +00:00
|
|
|
* @param array $arrayServerData
|
2014-05-16 18:05:34 -04:00
|
|
|
*
|
2012-10-09 12:54:08 -04:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2015-06-01 13:58:50 -04:00
|
|
|
public function tryOpenDataBase($pDbDriver, array $arrayServerData = array(), $dbsEncode = "")
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
2015-03-25 11:25:00 -04:00
|
|
|
$filter = new InputFilter();
|
|
|
|
|
$this->ip = $filter->validateInput($this->ip);
|
2017-08-11 15:54:49 -04:00
|
|
|
$this->db_port = $filter->validateInput($this->db_port, 'int');
|
2015-03-25 11:25:00 -04:00
|
|
|
$this->db_user = $filter->validateInput($this->db_user);
|
|
|
|
|
$this->db_passwd = $filter->validateInput($this->db_passwd);
|
|
|
|
|
$this->db_sourcename = $filter->validateInput($this->db_sourcename);
|
2012-10-09 12:54:08 -04:00
|
|
|
if ($this->errno != 0) {
|
|
|
|
|
return 0;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
2017-08-11 15:54:49 -04:00
|
|
|
set_time_limit(0);
|
2012-10-09 12:54:08 -04:00
|
|
|
$stat = new Stat();
|
|
|
|
|
|
2015-03-05 12:20:19 -04:00
|
|
|
if (array_key_exists("connectionType", $arrayServerData) || array_key_exists("DBS_TYPEORACLE", $arrayServerData)) {
|
|
|
|
|
if ($arrayServerData["connectionType"] == "TNS" || $arrayServerData["DBS_TYPEORACLE"] == "TNS") {
|
2017-12-04 13:25:35 +00:00
|
|
|
$flagTns = 1;
|
2017-08-11 15:54:49 -04:00
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$flagTns = 0;
|
2015-06-01 13:58:50 -04:00
|
|
|
}
|
2017-08-11 15:54:49 -04:00
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$flagTns = 0;
|
2015-03-05 12:20:19 -04:00
|
|
|
}
|
2014-05-16 18:05:34 -04:00
|
|
|
|
|
|
|
|
if (isset($this->db_user) && (isset($this->db_passwd) || $this->db_passwd == "") && (isset($this->db_sourcename) || $flagTns == 1)) {
|
2012-10-09 12:54:08 -04:00
|
|
|
switch ($pDbDriver) {
|
|
|
|
|
case 'mysql':
|
2018-02-01 13:06:32 +00:00
|
|
|
try {
|
|
|
|
|
$this->errstr = 'NET::MYSQL->The connection was refused';
|
|
|
|
|
$this->errno = 10001;
|
|
|
|
|
$connection = 'NET_' . $this->db_sourcename;
|
|
|
|
|
InstallerModule::setNewConnection($connection, $this->ip, $this->db_user, $this->db_passwd, $this->db_sourcename, $this->db_port);
|
2017-12-04 13:25:35 +00:00
|
|
|
|
2018-02-01 13:06:32 +00:00
|
|
|
$this->errstr = 'NET::MYSQL->Test query failed';
|
|
|
|
|
$this->errno = 10100;
|
|
|
|
|
|
|
|
|
|
$result = DB::connection($connection)->statement('show tables');
|
|
|
|
|
if ($result) {
|
|
|
|
|
$stat->status = 'SUCCESS';
|
|
|
|
|
$this->errstr = '';
|
|
|
|
|
$this->errno = 0;
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
2018-02-01 13:06:32 +00:00
|
|
|
} catch (Exception $exception) {
|
|
|
|
|
$this->error = $exception->getMessage();
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'pgsql':
|
|
|
|
|
$this->db_port = (($this->db_port == "") || ($this->db_port == 0)) ? "5432" : $this->db_port;
|
2017-08-11 15:54:49 -04:00
|
|
|
$link = @pg_connect("host='$this->ip' port='$this->db_port' user='$this->db_user' password='$this->db_passwd' dbname='$this->db_sourcename'");
|
2012-10-09 12:54:08 -04:00
|
|
|
if ($link) {
|
2017-08-11 15:54:49 -04:00
|
|
|
if (@pg_ping($link)) {
|
2012-10-09 12:54:08 -04:00
|
|
|
$stat->status = 'SUCCESS';
|
|
|
|
|
$this->errstr = "";
|
|
|
|
|
$this->errno = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = "PostgreSql Connection to $this->ip is unreachable!";
|
|
|
|
|
$this->errstr = "NET::POSTGRES->Lost Connection";
|
|
|
|
|
$this->errno = 20010;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = "PostgrSql connection refused";
|
|
|
|
|
$this->errstr = "NET::POSTGRES->The connection was refused";
|
|
|
|
|
$this->errno = 20001;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'mssql':
|
|
|
|
|
if ($this->db_instance != "") {
|
|
|
|
|
$str_port = "";
|
2017-08-11 15:54:49 -04:00
|
|
|
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
|
2012-10-09 12:54:08 -04:00
|
|
|
} else {
|
|
|
|
|
$str_port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
|
2017-08-11 15:54:49 -04:00
|
|
|
$link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd);
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
if ($link) {
|
2017-08-11 15:54:49 -04:00
|
|
|
$db = @mssql_select_db($this->db_sourcename, $link);
|
2012-10-09 12:54:08 -04:00
|
|
|
if ($db) {
|
|
|
|
|
$stat->status = 'SUCCESS';
|
|
|
|
|
$this->errstr = "";
|
|
|
|
|
$this->errno = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = "The $this->db_sourcename data base does'n exist!";
|
|
|
|
|
$this->errstr = "NET::MSSQL->Select data base failed";
|
|
|
|
|
$this->errno = 30010;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = "MS-SQL Server connection refused!";
|
|
|
|
|
$this->errstr = "NET::MSSQL->The connection was refused";
|
|
|
|
|
$this->errno = 30001;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'oracle':
|
2014-05-16 18:05:34 -04:00
|
|
|
if ($flagTns == 0) {
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->db_port = ($this->db_port == "" || $this->db_port == 0) ? "1521" : $this->db_port;
|
2014-05-16 18:05:34 -04:00
|
|
|
|
2015-06-01 13:58:50 -04:00
|
|
|
$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);
|
2014-05-16 18:05:34 -04:00
|
|
|
} else {
|
2015-06-01 13:58:50 -04:00
|
|
|
$cnn = @oci_connect($this->db_user, $this->db_passwd, $arrayServerData["tns"], $dbsEncode);
|
2014-05-16 18:05:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($cnn) {
|
|
|
|
|
$stid = @oci_parse($cnn, 'select AUTHENTICATION_TYPE from v$session_connect_info');
|
2017-08-11 15:54:49 -04:00
|
|
|
$result = @oci_execute($stid, OCI_DEFAULT);
|
2012-10-09 12:54:08 -04:00
|
|
|
if ($result) {
|
|
|
|
|
$stat->status = 'SUCCESS';
|
|
|
|
|
$this->errstr = "";
|
|
|
|
|
$this->errno = 0;
|
2014-05-16 18:05:34 -04:00
|
|
|
@oci_close($cnn);
|
2012-10-09 12:54:08 -04:00
|
|
|
} else {
|
|
|
|
|
$this->error = "the user $this->db_user doesn't have privileges to run queries!";
|
|
|
|
|
$this->errstr = "NET::ORACLE->Couldn't execute any query on this server!";
|
|
|
|
|
$this->errno = 40010;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->error = "Oracle connection refused!";
|
|
|
|
|
$this->errstr = "NET::ORACLE->The connection was refused";
|
|
|
|
|
$this->errno = 40001;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'informix':
|
|
|
|
|
break;
|
|
|
|
|
case 'sqlite':
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-08-11 15:54:49 -04:00
|
|
|
throw new Exception("CLASS::NET::ERROR: No connections param.");
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
return $stat;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function gets DB-s version
|
|
|
|
|
*
|
|
|
|
|
* @param string $driver
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function getDbServerVersion($driver)
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
if (!isset($this->ip)) {
|
2017-08-11 15:54:49 -04:00
|
|
|
$this->ip = getenv('HTTP_CLIENT_IP');
|
2012-10-22 16:35:54 -04:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
2017-08-11 15:54:49 -04:00
|
|
|
if (isset($this->ip) && isset($this->db_user) && isset($this->db_passwd)) {
|
2012-10-09 12:54:08 -04:00
|
|
|
try {
|
2017-12-04 13:25:35 +00:00
|
|
|
if (!isset($this->db_sourcename)) {
|
2012-10-09 12:54:08 -04:00
|
|
|
$this->db_sourcename = DB_NAME;
|
2012-10-22 16:35:54 -04:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
$value = 'none';
|
2017-08-11 15:54:49 -04:00
|
|
|
$sDataBase = 'database_' . strtolower(DB_ADAPTER);
|
|
|
|
|
if (G::LoadSystemExist($sDataBase)) {
|
2012-10-09 12:54:08 -04:00
|
|
|
$oDataBase = new database();
|
2017-08-11 15:54:49 -04:00
|
|
|
$value = $oDataBase->getServerVersion($driver, $this->ip, $this->db_port, $this->db_user, $this->db_passwd, $this->db_sourcename);
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
return $value;
|
|
|
|
|
} catch (Exception $e) {
|
2017-08-11 15:54:49 -04:00
|
|
|
throw new Exception($e->getMessage());
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2017-08-11 15:54:49 -04:00
|
|
|
throw new Exception('NET::Error->No params for Data Base Server!');
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function reurns DB name
|
|
|
|
|
*
|
|
|
|
|
* @param string $pAdapter
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function dbName($pAdapter)
|
2011-02-24 21:28:42 +00:00
|
|
|
{
|
2012-10-09 12:54:08 -04:00
|
|
|
switch ($pAdapter) {
|
|
|
|
|
case 'mysql':
|
|
|
|
|
return 'MySql';
|
|
|
|
|
break;
|
|
|
|
|
case 'pgsql':
|
|
|
|
|
return 'PostgreSQL';
|
|
|
|
|
break;
|
|
|
|
|
case 'mssql':
|
|
|
|
|
return 'Microsoft SQL Server';
|
|
|
|
|
break;
|
|
|
|
|
case 'oracle':
|
|
|
|
|
return 'Oracle';
|
|
|
|
|
break;
|
|
|
|
|
case 'informix':
|
|
|
|
|
return 'Informix';
|
|
|
|
|
break;
|
|
|
|
|
case 'sqlite':
|
|
|
|
|
return 'SQLite';
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-02-24 21:28:42 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If there is an error then it shows
|
|
|
|
|
*
|
|
|
|
|
* @param string $pAdapter
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function showMsg()
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
|
|
|
|
if ($this->errno != 0) {
|
|
|
|
|
$msg = "
|
2010-12-02 23:34:41 +00:00
|
|
|
<center>
|
|
|
|
|
<fieldset style='width:90%'><legend>Class NET</legend>
|
|
|
|
|
<div align=left>
|
|
|
|
|
<font color='red'>
|
|
|
|
|
<b>NET::ERROR NO -> $this->errno<br/>
|
|
|
|
|
NET::ERROR MSG -> $this->errstr</b>
|
|
|
|
|
</font>
|
|
|
|
|
</div>
|
|
|
|
|
</fieldset>
|
|
|
|
|
<center>";
|
2017-12-04 13:25:35 +00:00
|
|
|
print($msg);
|
2012-10-09 12:54:08 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function gets an error
|
|
|
|
|
* param
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function getErrno()
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
|
|
|
|
return $this->errno;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-09 12:54:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function gets an error message
|
|
|
|
|
* param
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2017-08-11 15:54:49 -04:00
|
|
|
public function getErrmsg()
|
2012-10-09 12:54:08 -04:00
|
|
|
{
|
|
|
|
|
return $this->errstr;
|
|
|
|
|
}
|
|
|
|
|
}
|