Пример #1
0
         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;
         }
     } else {
         print FAILED . ',' . $Server->error;
     }
     break;
 case 4:
     $Server->loginDbServer($user, $passwd);
     $Server->setDataBase($db_name, $port);
     if ($Server->errno == 0) {
         $response = $Server->tryConnectServer($type);
         if ($response->status == 'SUCCESS') {
Пример #2
0
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);
    }
}
Пример #3
0
             }
             break;
         default:
             echo "finished";
             break;
     }
 } else {
     $connectionType = $_POST["connectionType"];
     $tns = $_POST["tns"];
     $net = new NET();
     switch ($step) {
         case 1:
             $net->loginDbServer($user, $passwd);
             if ($net->errno == 0) {
                 $arrayServerData = array("connectionType" => $connectionType, "tns" => $tns);
                 $response = $net->tryConnectServer($type, $arrayServerData);
                 if ($response->status == "SUCCESS") {
                     $response = $net->tryOpenDataBase($type, $arrayServerData);
                     if ($response->status == "SUCCESS") {
                         echo SUCCESSFULL . "," . $net->error;
                     } else {
                         echo FAILED . "," . $net->error;
                     }
                 } else {
                     echo FAILED . "," . $net->error;
                 }
             } else {
                 echo FAILED . "," . $net->error;
             }
             break;
         default:
Пример #4
0
 /**
  * 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;
     }
 }
Пример #5
0
    /**
     * 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;
        }
    }
Пример #6
0
    /**
     * 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;
        }
    }