function testConnection($type, $server, $user, $passwd, $port = 'none', $dbName = "")
{
    if ($port == 'none' || $port == '' || $port == 0) {
        //setting defaults ports
        switch ($type) {
            case 'mysql':
                $port = 3306;
                break;
            case 'pgsql':
                $port = 5432;
                break;
            case 'mssql':
                $port = 1433;
                break;
            case 'oracle':
                $port = 1521;
                break;
        }
    }
    G::LoadClass('net');
    $Server = new NET($server);
    if ($Server->getErrno() == 0) {
        $Server->scannPort($port);
        if ($Server->getErrno() == 0) {
            $Server->loginDbServer($user, $passwd);
            $Server->setDataBase($dbName, $port);
            if ($Server->errno == 0) {
                $response = $Server->tryConnectServer($type);
                if ($response->status == 'SUCCESS') {
                    if ($Server->errno == 0) {
                        $message = "";
                        $response = $Server->tryConnectServer($type);
                        $connDatabase = @mysql_connect($server, $user, $passwd);
                        $dbNameTest = "PROCESSMAKERTESTDC";
                        $db = @mysql_query("CREATE DATABASE " . $dbNameTest, $connDatabase);
                        $success = false;
                        if (!$db) {
                            $message = mysql_error();
                        } else {
                            $usrTest = "wfrbtest";
                            $chkG = "GRANT ALL PRIVILEGES ON `" . $dbNameTest . "`.* TO " . $usrTest . "@'%' IDENTIFIED BY 'sample' WITH GRANT OPTION";
                            $ch = @mysql_query($chkG, $connDatabase);
                            if (!$ch) {
                                $message = mysql_error();
                            } else {
                                $sqlCreateUser = "******" . $user . "_usertest'@'%' IDENTIFIED BY 'sample'";
                                $result = @mysql_query($sqlCreateUser, $connDatabase);
                                if (!$result) {
                                    $message = mysql_error();
                                } else {
                                    $success = true;
                                    $message = G::LoadTranslation('ID_SUCCESSFUL_CONNECTION');
                                }
                                $sqlDropUser = "******" . $user . "_usertest'@'%'";
                                @mysql_query($sqlDropUser, $connDatabase);
                                @mysql_query("DROP USER " . $usrTest . "@'%'", $connDatabase);
                            }
                            @mysql_query("DROP DATABASE " . $dbNameTest, $connDatabase);
                        }
                        return array($success, $message != "" ? $message : $Server->error);
                    } else {
                        return array(false, $Server->error);
                    }
                } else {
                    return array(false, $Server->error);
                }
            } else {
                return array(false, $Server->error);
            }
        } else {
            return array(false, $Server->error);
        }
    } else {
        return array(false, $Server->error);
    }
}
     }
 }
 G::LoadClass('net');
 $Server = new NET($server);
 define("SUCCESSFULL", 'SUCCESSFULL');
 define("FAILED", 'FAILED');
 switch ($step) {
     case 1:
         if ($Server->getErrno() == 0) {
             print SUCCESSFULL . ',';
         } else {
             print FAILED . ',' . $Server->error;
         }
         break;
     case 2:
         $Server->scannPort($port);
         if ($Server->getErrno() == 0) {
             print SUCCESSFULL . ',';
         } else {
             print FAILED . ',' . $Server->error;
         }
         break;
     case 3:
         $Server->loginDbServer($user, $passwd);
         $Server->setDataBase($db_name, $port);
         if ($Server->errno == 0) {
             $response = $Server->tryConnectServer($type);
             if ($response->status == 'SUCCESS') {
                 print SUCCESSFULL . ',';
             } else {
                 print FAILED . ',' . $Server->error;
 /**
  * for Test email configuration
  * @autor Alvaro  <*****@*****.**>
  */
 public function testConnection($params)
 {
     G::LoadClass('net');
     G::LoadThirdParty('phpmailer', 'class.smtp');
     if ($_POST['typeTest'] == 'MAIL') {
         define("SUCCESSFUL", 'SUCCESSFUL');
         define("FAILED", 'FAILED');
         $mail_to = $_POST['mail_to'];
         $send_test_mail = $_POST['send_test_mail'];
         $_POST['FROM_NAME'] = $mail_to;
         $_POST['FROM_EMAIL'] = $mail_to;
         $_POST['MESS_ENGINE'] = 'MAIL';
         $_POST['MESS_SERVER'] = 'localhost';
         $_POST['MESS_PORT'] = 25;
         $_POST['MESS_ACCOUNT'] = $mail_to;
         $_POST['MESS_PASSWORD'] = '';
         $_POST['TO'] = $mail_to;
         $_POST['SMTPAuth'] = true;
         try {
             $resp = $this->sendTestMail();
         } catch (Exception $error) {
             $resp = new stdclass();
             $resp->status = false;
             $resp->msg = $error->getMessage();
         }
         $response = array('success' => $resp->status);
         if ($resp->status == false) {
             $response['msg'] = G::LoadTranslation('ID_SENDMAIL_NOT_INSTALLED');
         }
         echo G::json_encode($response);
         die;
     }
     $step = $_POST['step'];
     $server = $_POST['server'];
     $user = $_POST['user'];
     $passwd = $_POST['passwd'];
     $passwdHide = $_POST['passwdHide'];
     if (trim($passwdHide) != '') {
         $passwd = $passwdHide;
         $passwdHide = '';
     }
     $passwdDec = G::decrypt($passwd, 'EMAILENCRYPT');
     $auxPass = explode('hash:', $passwdDec);
     if (count($auxPass) > 1) {
         if (count($auxPass) == 2) {
             $passwd = $auxPass[1];
         } else {
             array_shift($auxPass);
             $passwd = implode('', $auxPass);
         }
     }
     $_POST['passwd'] = $passwd;
     $port = $_POST['port'];
     $auth_required = $_POST['req_auth'];
     $UseSecureCon = $_POST['UseSecureCon'];
     $SendaTestMail = $_POST['SendaTestMail'];
     $Mailto = $_POST['eMailto'];
     $SMTPSecure = $_POST['UseSecureCon'];
     $Server = new NET($server);
     $smtp = new SMTP();
     $timeout = 10;
     $hostinfo = array();
     $srv = $_POST['server'];
     switch ($step) {
         case 1:
             $this->success = $Server->getErrno() == 0;
             $this->msg = $this->result ? 'success' : $Server->error;
             break;
         case 2:
             $Server->scannPort($port);
             $this->success = $Server->getErrno() == 0;
             //'Successfull'.$smtp->status;
             $this->msg = $this->result ? '' : $Server->error;
             break;
         case 3:
             //try to connect to host
             if (preg_match('/^(.+):([0-9]+)$/', $srv, $hostinfo)) {
                 $server = $hostinfo[1];
                 $port = $hostinfo[2];
             } else {
                 $host = $srv;
             }
             $tls = strtoupper($SMTPSecure) == 'tls';
             $ssl = strtoupper($SMTPSecure) == 'ssl';
             $this->success = $smtp->Connect(($ssl ? 'ssl://' : '') . $server, $port, $timeout);
             $this->msg = $this->result ? '' : $Server->error;
             break;
         case 4:
             //try login to host
             if ($auth_required == 'true') {
                 try {
                     if (preg_match('/^(.+):([0-9]+)$/', $srv, $hostinfo)) {
                         $server = $hostinfo[1];
                         $port = $hostinfo[2];
                     } else {
                         $server = $srv;
                     }
                     if (strtoupper($UseSecureCon) == 'TLS') {
                         $tls = 'tls';
                     }
                     if (strtoupper($UseSecureCon) == 'SSL') {
                         $tls = 'ssl';
                     }
                     $tls = strtoupper($UseSecureCon) == 'tls';
                     $ssl = strtoupper($UseSecureCon) == 'ssl';
                     $server = $_POST['server'];
                     if (strtoupper($UseSecureCon) == 'SSL') {
                         $resp = $smtp->Connect('ssl://' . $server, $port, $timeout);
                     } else {
                         $resp = $smtp->Connect($server, $port, $timeout);
                     }
                     if ($resp) {
                         $hello = $_SERVER['SERVER_NAME'];
                         $smtp->Hello($hello);
                         if (strtoupper($UseSecureCon) == 'TLS') {
                             $smtp->Hello($hello);
                         }
                         if ($smtp->Authenticate($user, $passwd)) {
                             $this->success = true;
                         } else {
                             $this->success = false;
                             $this->msg = $smtp->error['error'];
                         }
                     } else {
                         $this->success = false;
                         $this->msg = $smtp->error['error'];
                     }
                 } catch (Exception $e) {
                     $this->success = false;
                     $this->msg = $e->getMessage();
                 }
             } else {
                 $this->success = true;
                 $this->msg = 'No authentication required!';
             }
             break;
         case 5:
             if ($SendaTestMail == 'true') {
                 try {
                     $_POST['FROM_NAME'] = 'Process Maker O.S. [Test mail]';
                     $_POST['FROM_EMAIL'] = $user;
                     $_POST['MESS_ENGINE'] = 'PHPMAILER';
                     $_POST['MESS_SERVER'] = $server;
                     $_POST['MESS_PORT'] = $port;
                     $_POST['MESS_ACCOUNT'] = $user;
                     $_POST['MESS_PASSWORD'] = $passwd;
                     $_POST['TO'] = $Mailto;
                     if ($auth_required == 'true') {
                         $_POST['SMTPAuth'] = true;
                     } else {
                         $_POST['SMTPAuth'] = false;
                     }
                     if (strtolower($_POST["UseSecureCon"]) != "no") {
                         $_POST["SMTPSecure"] = $_POST["UseSecureCon"];
                     }
                     if ($_POST['UseSecureCon'] == 'ssl') {
                         $_POST['MESS_SERVER'] = 'ssl://' . $_POST['MESS_SERVER'];
                     }
                     $resp = $this->sendTestMail();
                     if ($resp->status == '1') {
                         $this->success = true;
                     } else {
                         $this->success = false;
                         $this->msg = $smtp->error['error'];
                     }
                 } catch (Exception $e) {
                     $this->success = false;
                     $this->msg = $e->getMessage();
                 }
             } else {
                 $this->success = true;
                 $this->msg = 'jump this step';
             }
             break;
     }
 }
 /**
  * Test DataBase Connection
  * @var string $dataCon. Data for DataBase Connection
  * @var string $returnArray. Flag for url
  *
  * @author Brayan Pereyra (Cochalo) <*****@*****.**>
  * @copyright Colosa - Bolivia
  *
  * @return void
  */
 public function testConnection($dataCon, $returnArray = false)
 {
     $resp = array();
     $respTest = array();
     $resp['resp'] = false;
     $dataCon = array_change_key_case($dataCon, CASE_UPPER);
     $flagTns = $dataCon["DBS_TYPE"] == "oracle" && $dataCon["DBS_CONNECTION_TYPE"] == "TNS" ? 1 : 0;
     G::LoadClass('net');
     if ($flagTns == 0) {
         $Server = new \NET($dataCon['DBS_SERVER']);
         // STEP 1 : Resolving Host Name
         $respTest['0'] = array();
         $respTest['0']['test'] = G::loadTranslation('RESOLVING_NAME') . ' ' . $dataCon['DBS_SERVER'];
         if ($Server->getErrno() != 0) {
             if ($returnArray) {
                 $respTest['0']['error'] = G::loadTranslation('ID_ERROR_HOST_NAME_FAILED') . ' : ' . $Server->error;
             } else {
                 $resp['message'] = G::loadTranslation('ID_ERROR_HOST_NAME_FAILED') . ' : ' . $Server->error;
                 return $resp;
             }
         }
         // STEP 2 : Checking port
         $respTest['1'] = array();
         $respTest['1']['test'] = G::loadTranslation('ID_CHECK_PORT') . ' ' . $dataCon['DBS_PORT'];
         $Server->scannPort($dataCon['DBS_PORT']);
         if ($Server->getErrno() != 0) {
             if ($returnArray) {
                 $respTest['1']['error'] = G::loadTranslation('ID_CHECK_PORT_FAILED') . ' : ' . $Server->error;
             } else {
                 $resp['message'] = G::loadTranslation('ID_CHECK_PORT_FAILED') . ' : ' . $Server->error;
                 return $resp;
             }
         }
         // STEP 3 : Trying to connect to host
         $respTest['2'] = array();
         $respTest['2']['test'] = G::loadTranslation('ID_CONNECTING_TO_HOST') . ' ' . $dataCon['DBS_SERVER'] . ($dataCon['DBS_PORT'] != '' ? ':' . $dataCon['DBS_PORT'] : '');
         $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
         $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
         if ($Server->errno == 0) {
             $response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
             if ($response->status != 'SUCCESS') {
                 if ($returnArray) {
                     $respTest['2']['error'] = G::loadTranslation('ID_CONNECTING_TO_HOST_FAILED') . ' : ' . $Server->error;
                 } else {
                     $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_HOST_FAILED') . ' : ' . $Server->error;
                     return $resp;
                 }
             }
         } else {
             if ($returnArray) {
                 $respTest['2']['error'] = G::loadTranslation('ID_CONNECTING_TO_HOST_FAILED') . ' : ' . $Server->error;
             } else {
                 $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_HOST_FAILED') . ' : ' . $Server->error;
                 return $resp;
             }
         }
         // STEP 4 : Trying to open database
         $respTest['3'] = array();
         $respTest['3']['test'] = G::loadTranslation('ID_OPEN_DATABASE') . ' [' . $dataCon['DBS_DATABASE_NAME'] . ']';
         $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
         $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
         if ($Server->errno == 0) {
             $response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
             if ($response->status == 'SUCCESS') {
                 $response = $Server->tryOpenDataBase($dataCon['DBS_TYPE']);
                 if ($response->status != 'SUCCESS') {
                     if ($returnArray) {
                         $respTest['3']['error'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error;
                     } else {
                         $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error;
                         return $resp;
                     }
                 }
             } else {
                 if ($returnArray) {
                     $respTest['3']['error'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error;
                 } else {
                     $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error;
                     return $resp;
                 }
             }
         } else {
             if ($returnArray) {
                 $respTest['3']['error'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error;
             } else {
                 $resp['message'] = G::loadTranslation('ID_CONNECTING_TO_DATABASE_FAILED') . ' : ' . $Server->error;
                 return $resp;
             }
         }
     } else {
         $net = new \NET();
         //STEP 0: Trying to open database type TNS
         $respTest["0"] = array();
         $respTest["0"]["test"] = G::loadTranslation('ID_TEST_DATABASE_ORACLE_TNS') . ' ' . $dataCon["DBS_TNS"];
         $net->loginDbServer($dataCon["DBS_USERNAME"], $dataCon["DBS_PASSWORD"]);
         if ($net->errno == 0) {
             $arrayServerData = array("connectionType" => $dataCon["DBS_CONNECTION_TYPE"], "tns" => $dataCon["DBS_TNS"]);
             $response = $net->tryConnectServer($dataCon["DBS_TYPE"], $arrayServerData);
             if ($response->status == "SUCCESS") {
                 $response = $net->tryOpenDataBase($dataCon["DBS_TYPE"], $arrayServerData);
                 if ($response->status != "SUCCESS") {
                     if ($returnArray) {
                         $respTest["0"]["error"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error;
                     } else {
                         $resp["message"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error;
                         //Return
                         return $resp;
                     }
                 }
             } else {
                 if ($returnArray) {
                     $respTest["0"]["error"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error;
                 } else {
                     $resp["message"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error;
                     //Return
                     return $resp;
                 }
             }
         } else {
             if ($returnArray) {
                 $respTest["0"]["error"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error;
             } else {
                 $resp["message"] = G::loadTranslation('ID_TEST_ERROR_ORACLE_TNS') . ', ' . $net->error;
                 //Return
                 return $resp;
             }
         }
     }
     if ($returnArray) {
         return $respTest;
     } else {
         // CORRECT CONNECTION
         $resp['resp'] = true;
         return $resp;
     }
 }
    /**
     * Test DataBase Connection
     * @var string $dataCon. Data for DataBase Connection
     * @var string $returnArray. Flag for url
     *
     * @author Brayan Pereyra (Cochalo) <*****@*****.**>
     * @copyright Colosa - Bolivia
     *
     * @return void
     */
    public function testConnection($dataCon, $returnArray = false)
    {
        $resp = array();
        $respTest = array();
        $resp['resp'] = false;

        $dataCon = array_change_key_case($dataCon, CASE_UPPER);

        $flagTns = ($dataCon["DBS_TYPE"] == "oracle" && $dataCon["DBS_CONNECTION_TYPE"] == "TNS")? 1 : 0;

        G::LoadClass( 'net' );

        if ($flagTns == 0) {
            $Server = new \NET($dataCon['DBS_SERVER']);

            // STEP 1 : Resolving Host Name
            $respTest['0'] = array();
            $respTest['0']['test'] = 'Resolving Host Name ' . $dataCon['DBS_SERVER'];
            if ($Server->getErrno() != 0) {
                if ($returnArray) {
                    $respTest['0']['error'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error;
                } else {
                    $resp['message'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error;
                    return $resp;
                }
            }

            // STEP 2 : Checking port
            $respTest['1'] = array();
            $respTest['1']['test'] = 'Checking port ' . $dataCon['DBS_PORT'];
            $Server->scannPort($dataCon['DBS_PORT']);
            if ($Server->getErrno() != 0) {
                if ($returnArray) {
                    $respTest['1']['error'] = "Error Testing Connection: Checking port FAILED : " . $Server->error;
                } else {
                    $resp['message'] = "Error Testing Connection: Checking port FAILED : " . $Server->error;
                    return $resp;
                }
            }

            // STEP 3 : Trying to connect to host
            $respTest['2'] = array();
            $respTest['2']['test'] = 'Connecting to host ' . $dataCon['DBS_SERVER'] . (($dataCon['DBS_PORT'] != '') ? ':'.$dataCon['DBS_PORT'] : '');
            $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
            $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
            if ($Server->errno == 0) {
                $response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
                if ($response->status != 'SUCCESS') {
                    if ($returnArray) {
                        $respTest['2']['error'] = "Error Testing Connection: Connecting to host FAILED : " . $Server->error;
                    } else {
                        $resp['message'] = "Error Testing Connection: Connecting to host FAILED : " . $Server->error;
                        return $resp;
                    }
                }
            } else {
                if ($returnArray) {
                    $respTest['2']['error'] = "Error Testing Connection: Connecting to host FAILED : " . $Server->error;
                } else {
                    $resp['message'] = "Error Testing Connection: Connecting to host FAILED : " . $Server->error;
                    return $resp;
                }
            }

            // STEP 4 : Trying to open database
            $respTest['3'] = array();
            $respTest['3']['test'] = 'Opening database [' . $dataCon['DBS_DATABASE_NAME'] . ']';
            $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
            $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
            if ($Server->errno == 0) {
                $response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
                if ($response->status == 'SUCCESS') {
                    $response = $Server->tryOpenDataBase($dataCon['DBS_TYPE']);
                    if ($response->status != 'SUCCESS') {
                        if ($returnArray) {
                            $respTest['3']['error'] = "Error Testing Connection: Opening database FAILED : " . $Server->error;
                        } else {
                            $resp['message'] = "Error Testing Connection: Opening database FAILED : " . $Server->error;
                            return $resp;
                        }
                    }
                } else {
                    if ($returnArray) {
                        $respTest['3']['error'] = "Error Testing Connection: Opening database FAILED : " . $Server->error;
                    } else {
                        $resp['message'] = "Error Testing Connection: Opening database FAILED : " . $Server->error;
                        return $resp;
                    }
                }
            } else {
                if ($returnArray) {
                    $respTest['3']['error'] = "Error Testing Connection: Opening database FAILED : " . $Server->error;
                } else {
                    $resp['message'] = "Error Testing Connection: Opening database FAILED : " . $Server->error;
                    return $resp;
                }
            }
        } else {
            $net = new \NET();

            //STEP 0: Trying to open database type TNS
            $respTest["0"] = array();
            $respTest["0"]["test"] = "Test TNS: " . $dataCon["DBS_TNS"];

            $net->loginDbServer($dataCon["DBS_USERNAME"], $dataCon["DBS_PASSWORD"]);

            if ($net->errno == 0) {
                $arrayServerData = array("connectionType" => $dataCon["DBS_CONNECTION_TYPE"], "tns" => $dataCon["DBS_TNS"]);

                $response = $net->tryConnectServer($dataCon["DBS_TYPE"], $arrayServerData);

                if ($response->status == "SUCCESS") {
                    $response = $net->tryOpenDataBase($dataCon["DBS_TYPE"], $arrayServerData);

                    if ($response->status != "SUCCESS") {
                        if ($returnArray) {
                            $respTest["0"]["error"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error;
                        } else {
                            $resp["message"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error;

                            //Return
                            return $resp;
                        }
                    }
                } else {
                    if ($returnArray) {
                        $respTest["0"]["error"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error;
                    } else {
                        $resp["message"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error;

                        //Return
                        return $resp;
                    }
                }
            } else {
                if ($returnArray) {
                    $respTest["0"]["error"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error;
                } else {
                    $resp["message"] = "Error Testing Connection: Opening database type TNS FAILED, " . $net->error;

                    //Return
                    return $resp;
                }
            }
        }

        if ($returnArray) {
            return $respTest;
        } else {
            // CORRECT CONNECTION
            $resp['resp'] = true;
            return $resp;
        }
    }
Beispiel #6
0
 /**
  * Test connection by step
  *
  * @param array $arrayData Data
  * @param int   $step      Step
  *
  * return array Return array with result of test connection by step
  */
 public function testConnectionByStep(array $arrayData, $step = 0)
 {
     try {
         \G::LoadClass("net");
         \G::LoadThirdParty("phpmailer", "class.smtp");
         //MAIL
         if ($arrayData["MESS_ENGINE"] == "MAIL") {
             $arrayDataMail = array();
             $eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\\.[0-9a-zA-Z]{2,3}\$/";
             $arrayDataMail["FROM_EMAIL"] = $arrayData["MESS_FROM_MAIL"] != "" && preg_match($eregMail, $arrayData["MESS_FROM_MAIL"]) ? $arrayData["MESS_FROM_MAIL"] : "";
             $arrayDataMail["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : \G::LoadTranslation("ID_MESS_TEST_BODY");
             $arrayDataMail["MESS_ENGINE"] = "MAIL";
             $arrayDataMail["MESS_SERVER"] = "localhost";
             $arrayDataMail["MESS_PORT"] = 25;
             $arrayDataMail["MESS_ACCOUNT"] = $arrayData["MAIL_TO"];
             $arrayDataMail["MESS_PASSWORD"] = "";
             $arrayDataMail["TO"] = $arrayData["MAIL_TO"];
             $arrayDataMail["MESS_RAUTH"] = true;
             $arrayTestMailResult = array();
             try {
                 $arrayTestMailResult = $this->sendTestMail($arrayDataMail);
             } catch (Exception $e) {
                 $arrayTestMailResult["status"] = false;
                 $arrayTestMailResult["message"] = $e->getMessage();
             }
             $arrayResult = array("result" => $arrayTestMailResult["status"], "message" => "");
             if ($arrayTestMailResult["status"] == false) {
                 $arrayResult["message"] = \G::LoadTranslation("ID_SENDMAIL_NOT_INSTALLED");
             }
             //Return
             return $arrayResult;
         }
         //PHPMAILER
         $server = $arrayData["MESS_SERVER"];
         $user = $arrayData["MESS_ACCOUNT"];
         $passwd = $arrayData["MESS_PASSWORD"];
         $fromMail = $arrayData["MESS_FROM_MAIL"];
         $passwdHide = $arrayData["MESS_PASSWORD"];
         if (trim($passwdHide) != "") {
             $passwd = $passwdHide;
             $passwdHide = "";
         }
         $passwdDec = \G::decrypt($passwd, "EMAILENCRYPT");
         $auxPass = explode("hash:", $passwdDec);
         if (count($auxPass) > 1) {
             if (count($auxPass) == 2) {
                 $passwd = $auxPass[1];
             } else {
                 array_shift($auxPass);
                 $passwd = implode("", $auxPass);
             }
         }
         $arrayData["MESS_PASSWORD"] = $passwd;
         $port = (int) $arrayData["MESS_PORT"];
         $auth_required = (int) $arrayData["MESS_RAUTH"];
         $useSecureCon = $arrayData["SMTPSECURE"];
         $sendTestMail = (int) $arrayData["MESS_TRY_SEND_INMEDIATLY"];
         $mailTo = $arrayData["MAIL_TO"];
         $smtpSecure = $arrayData["SMTPSECURE"];
         $serverNet = new \NET($server);
         $smtp = new \SMTP();
         $timeout = 10;
         $hostinfo = array();
         $srv = $arrayData["MESS_SERVER"];
         $arrayResult = array();
         switch ($step) {
             case 1:
                 $arrayResult["result"] = $serverNet->getErrno() == 0;
                 $arrayResult["message"] = $serverNet->error;
                 break;
             case 2:
                 $serverNet->scannPort($port);
                 $arrayResult["result"] = $serverNet->getErrno() == 0;
                 $arrayResult["message"] = $serverNet->error;
                 break;
             case 3:
                 //Try to connect to host
                 if (preg_match("/^(.+):([0-9]+)\$/", $srv, $hostinfo)) {
                     $server = $hostinfo[1];
                     $port = $hostinfo[2];
                 } else {
                     $host = $srv;
                 }
                 $tls = strtoupper($smtpSecure) == "tls";
                 $ssl = strtoupper($smtpSecure) == "ssl";
                 $arrayResult["result"] = $smtp->Connect(($ssl ? "ssl://" : "") . $server, $port, $timeout);
                 $arrayResult["message"] = $serverNet->error;
                 break;
             case 4:
                 //Try login to host
                 if ($auth_required == 1) {
                     try {
                         if (preg_match("/^(.+):([0-9]+)\$/", $srv, $hostinfo)) {
                             $server = $hostinfo[1];
                             $port = $hostinfo[2];
                         } else {
                             $server = $srv;
                         }
                         if (strtoupper($useSecureCon) == "TLS") {
                             $tls = "tls";
                         }
                         if (strtoupper($useSecureCon) == "SSL") {
                             $tls = "ssl";
                         }
                         $tls = strtoupper($useSecureCon) == "tls";
                         $ssl = strtoupper($useSecureCon) == "ssl";
                         $server = $arrayData["MESS_SERVER"];
                         if (strtoupper($useSecureCon) == "SSL") {
                             $resp = $smtp->Connect("ssl://" . $server, $port, $timeout);
                         } else {
                             $resp = $smtp->Connect($server, $port, $timeout);
                         }
                         if ($resp) {
                             $hello = $_SERVER["SERVER_NAME"];
                             $smtp->Hello($hello);
                             if (strtoupper($useSecureCon) == "TLS") {
                                 $smtp->Hello($hello);
                             }
                             if ($smtp->Authenticate($user, $passwd)) {
                                 $arrayResult["result"] = true;
                             } else {
                                 if (strtoupper($useSecureCon) == "TLS") {
                                     $arrayResult["result"] = true;
                                 } else {
                                     $arrayResult["result"] = false;
                                     $smtpError = $smtp->getError();
                                     $arrayResult["message"] = $smtpError["error"];
                                 }
                             }
                         } else {
                             $arrayResult["result"] = false;
                             $smtpError = $smtp->getError();
                             $arrayResult["message"] = $smtpError["error"];
                         }
                     } catch (Exception $e) {
                         $arrayResult["result"] = false;
                         $arrayResult["message"] = $e->getMessage();
                     }
                 } else {
                     $arrayResult["result"] = true;
                     $arrayResult["message"] = "No authentication required!";
                 }
                 break;
             case 5:
                 if ($sendTestMail == 1) {
                     try {
                         $arrayDataPhpMailer = array();
                         $eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\\.[0-9a-zA-Z]{2,3}\$/";
                         $arrayDataPhpMailer["FROM_EMAIL"] = $fromMail != "" && preg_match($eregMail, $fromMail) ? $fromMail : "";
                         $arrayDataPhpMailer["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : \G::LoadTranslation("ID_MESS_TEST_BODY");
                         $arrayDataPhpMailer["MESS_ENGINE"] = "PHPMAILER";
                         $arrayDataPhpMailer["MESS_SERVER"] = $server;
                         $arrayDataPhpMailer["MESS_PORT"] = $port;
                         $arrayDataPhpMailer["MESS_ACCOUNT"] = $user;
                         $arrayDataPhpMailer["MESS_PASSWORD"] = $passwd;
                         $arrayDataPhpMailer["TO"] = $mailTo;
                         if ($auth_required == 1) {
                             $arrayDataPhpMailer["MESS_RAUTH"] = true;
                         } else {
                             $arrayDataPhpMailer["MESS_RAUTH"] = false;
                         }
                         if (strtolower($arrayData["SMTPSECURE"]) != "no") {
                             $arrayDataPhpMailer["SMTPSecure"] = $arrayData["SMTPSECURE"];
                         }
                         $arrayTestMailResult = $this->sendTestMail($arrayDataPhpMailer);
                         if ($arrayTestMailResult["status"] . "" == "1") {
                             $arrayResult["result"] = true;
                         } else {
                             $arrayResult["result"] = false;
                             $smtpError = $smtp->getError();
                             $arrayResult["message"] = $smtpError["error"];
                         }
                     } catch (Exception $e) {
                         $arrayResult["result"] = false;
                         $arrayResult["message"] = $e->getMessage();
                     }
                 } else {
                     $arrayResult["result"] = true;
                     $arrayResult["message"] = "Jump this step";
                 }
                 break;
         }
         if (!isset($arrayResult["message"])) {
             $arrayResult["message"] = "";
         }
         //Return
         return $arrayResult;
     } catch (\Exception $e) {
         $arrayResult = array();
         $arrayResult["result"] = false;
         $arrayResult["message"] = $e->getMessage();
         //Return
         return $arrayResult;
     }
 }
    /**
     * Test DataBase Connection
     * @var string $dataCon. Data for DataBase Connection
     * @var string $returnArray. Flag for url
     *
     * @author Brayan Pereyra (Cochalo) <*****@*****.**>
     * @copyright Colosa - Bolivia
     *
     * @return void
     */
    public function testConnection($dataCon, $returnArray = false)
    {
        $resp = array();
        $respTest = array();
        $resp['resp'] = false;

        $dataCon = array_change_key_case($dataCon, CASE_UPPER);

        G::LoadClass( 'net' );
        $Server = new \NET($dataCon['DBS_SERVER']);

        // STEP 1 : Resolving Host Name
        $respTest['0'] = array();
        $respTest['0']['test'] = 'Resolving Host Name ' . $dataCon['DBS_SERVER'];
        if ($Server->getErrno() != 0) {
            if ($returnArray) {
                $respTest['0']['error'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error;
            } else {
                $resp['message'] = "Error Testing Connection: Resolving Host Name FAILED : " . $Server->error;
                return $resp;
            }
        }

        // STEP 2 : Checking port
        $respTest['1'] = array();
        $respTest['1']['test'] = 'Checking port ' . $dataCon['DBS_PORT'];
        $Server->scannPort($dataCon['DBS_PORT']);
        if ($Server->getErrno() != 0) {
            if ($returnArray) {
                $respTest['1']['error'] = "Error Testing Connection: Checking port FAILED : " . $Server->error;
            } else {
                $resp['message'] = "Error Testing Connection: Checking port FAILED : " . $Server->error;
                return $resp;
            }
        }

        // STEP 3 : Trying to connect to host
        $respTest['2'] = array();
        $respTest['2']['test'] = 'Trying to connect to host ' . $dataCon['DBS_SERVER'] . (($dataCon['DBS_PORT'] != '') ? ':'.$dataCon['DBS_PORT'] : '');
        $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
        $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
        if ($Server->errno == 0) {
            $response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
            if ($response->status != 'SUCCESS') {
                if ($returnArray) {
                    $respTest['2']['error'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error;
                } else {
                    $resp['message'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error;
                    return $resp;
                }
            }
        } else {
            if ($returnArray) {
                $respTest['2']['error'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error;
            } else {
                $resp['message'] = "Error Testing Connection: Trying to connect to host FAILED : " . $Server->error;
                return $resp;
            }
        }

        // STEP 4 : Trying to open database
        $respTest['3'] = array();
        $respTest['3']['test'] = 'Trying to open database [' . $dataCon['DBS_DATABASE_NAME'] . ']';
        $Server->loginDbServer($dataCon['DBS_USERNAME'], $dataCon['DBS_PASSWORD']);
        $Server->setDataBase($dataCon['DBS_DATABASE_NAME'], $dataCon['DBS_PORT']);
        if ($Server->errno == 0) {
            $response = $Server->tryConnectServer($dataCon['DBS_TYPE']);
            if ($response->status == 'SUCCESS') {
                $response = $Server->tryOpenDataBase($dataCon['DBS_TYPE']);
                if ($response->status != 'SUCCESS') {
                    if ($returnArray) {
                        $respTest['3']['error'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
                    } else {
                        $resp['message'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
                        return $resp;
                    }
                }
            } else {
                if ($returnArray) {
                    $respTest['3']['error'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
                } else {
                    $resp['message'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
                    return $resp;
                }
            }
        } else {
            if ($returnArray) {
                $respTest['3']['error'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
            } else {
                $resp['message'] = "Error Testing Connection: Trying to open database FAILED : " . $Server->error;
                return $resp;
            }
        }

        if ($returnArray) {
            return $respTest;
        } else {
            // CORRECT CONNECTION
            $resp['resp'] = true;
            return $resp;
        }
    }