Change wrong DSN name for db wrapper and update config class
This commit changes how the config class gets it's values to a more solid way. Additonally, the DSN was updated to use a correct format, allowing PDO to connect (With a wrong DSN, it tries to connect to something that doesn't exist).
This commit is contained in:
parent
9c9c10467d
commit
c3f882960c
|
@ -0,0 +1,31 @@
|
|||
[mainconfig]
|
||||
|
||||
appname = "SG-Gateway"
|
||||
appversion = "alpha 1.1"
|
||||
operationmode = "development"
|
||||
|
||||
|
||||
[database]
|
||||
|
||||
username = "sjbilling"
|
||||
password = "zwNUECRSy1DVZneq"
|
||||
hostname = "db4free.net"
|
||||
port = "3306"
|
||||
dbname = "spacejewelbillin"
|
||||
|
||||
[virtualmin]
|
||||
|
||||
vmin-url = ""
|
||||
password = ""
|
||||
username = ""
|
||||
|
||||
[templates]
|
||||
|
||||
templateDirectory = "/source/emailTemplates"
|
||||
|
||||
[mailer]
|
||||
|
||||
username = "0bffccb77f9228"
|
||||
password = "bbd994d1500dab"
|
||||
hostname = "smtp.mailtrap.io"
|
||||
port = "2525"
|
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Keep things simple for simplicity's sake. We can't waste too much time.
|
||||
// Wrap this around an helper class
|
||||
return [
|
||||
|
||||
"mainconfig" =>
|
||||
[
|
||||
"appname" => "SG-Gateway",
|
||||
"appversion" => "alpha 1.0",
|
||||
"operationmode" => "development"
|
||||
|
||||
],
|
||||
|
||||
"core" =>
|
||||
[
|
||||
"database" =>
|
||||
[
|
||||
"username" => "spacejewel",
|
||||
"password" => "zwNUECRSy1DVZneq",
|
||||
"hostname" => "spacejewel.ga",
|
||||
"port" => "3306",
|
||||
"dbname" => "billing"
|
||||
],
|
||||
"virtualmin" =>
|
||||
[
|
||||
"vmin-url" => "",
|
||||
"password" => "",
|
||||
"username" => ""
|
||||
],
|
||||
|
||||
"templates" =>
|
||||
[
|
||||
|
||||
"templateDirectory" => $_SERVER['DOCUMENT_ROOT'] . '/source/emailTemplates'
|
||||
|
||||
],
|
||||
|
||||
"mailer" =>
|
||||
[
|
||||
|
||||
"username" => "0bffccb77f9228",
|
||||
"password" => "bbd994d1500dab",
|
||||
"hostname" => " smtp.mailtrap.io",
|
||||
"port" => 2525
|
||||
|
||||
|
||||
]
|
||||
]
|
||||
|
||||
];
|
|
@ -12,46 +12,23 @@ class Application
|
|||
|
||||
|
||||
|
||||
$this->database['username'] = $cConfigArray['core']['database']['username'];
|
||||
$this->database['password'] = $cConfigArray['core']['database']['password'];
|
||||
$this->database['hostname'] = $cConfigArray['core']['database']['hostname'];
|
||||
$this->database['dbname'] = $cConfigArray['core']['database']['dbname'];
|
||||
$this->database['username'] = $cConfigArray['database']['username'];
|
||||
$this->database['password'] = $cConfigArray['database']['password'];
|
||||
$this->database['hostname'] = $cConfigArray['database']['hostname'];
|
||||
$this->database['dbname'] = $cConfigArray['database']['dbname'];
|
||||
|
||||
$this->instDB();
|
||||
}
|
||||
|
||||
private function isHostAlive($domain)
|
||||
{
|
||||
$starttime = microtime(true);
|
||||
$file = fsockopen ($domain, 80, $errno, $errstr, 10);
|
||||
$stoptime = microtime(true);
|
||||
$status = 0;
|
||||
|
||||
if (!$file) $status = -1; // Site is down
|
||||
else
|
||||
{
|
||||
fclose($file);
|
||||
$status = ($stoptime - $starttime) * 1000;
|
||||
$status = floor($status);
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
protected function instDB()
|
||||
{
|
||||
|
||||
$dsn = "mysql:host=" . $this->database['hostname'] . "dbname=" . $this->database['dbname'];
|
||||
$dsn = 'mysql:dbname=' . $this->database['dbname'] . ';host=' . $this->database['hostname'];
|
||||
$username = $this->database['username'];
|
||||
$password = $this->database['password'];
|
||||
|
||||
echo $this->database['hostname'];
|
||||
$this->db = \ParagonIE\EasyDB\Factory::create($dsn, $username, $password);
|
||||
|
||||
$Conn = \ParagonIE\EasyDB\Factory::create($dsn, $username, $password);
|
||||
|
||||
$this->db = $Conn;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function Exists($Table, $IDRowColumnName, $SearchValue)
|
||||
{
|
||||
$exists = $db->cell(
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
class ApplicationAPI extends Application
|
||||
{
|
||||
|
||||
private $gDatabase;
|
||||
|
||||
|
||||
private $AdminID;
|
||||
|
||||
|
||||
|
@ -22,8 +19,6 @@ class ApplicationAPI extends Application
|
|||
|
||||
$this->AdminID = $AdminID;
|
||||
|
||||
$this->gDatabase = parent::instDB();
|
||||
|
||||
|
||||
if (!$this->ApiKeyExists($AdminID))
|
||||
{
|
||||
|
@ -35,7 +30,7 @@ class ApplicationAPI extends Application
|
|||
{
|
||||
$AdminID = $this->AdminID;
|
||||
|
||||
$record = $this->gDatabase->row(
|
||||
$record = $this->db->row(
|
||||
"SELECT * FROM APIKeys WHERE AdminID = ?",
|
||||
$AdminID
|
||||
);
|
||||
|
|
|
@ -13,9 +13,9 @@ class VirtualminHandler
|
|||
$Config = new Config();
|
||||
$cConfigArray = $Config->getConfig();
|
||||
|
||||
$url = $cConfigArray['vmin-url'];
|
||||
$username = $cConfigArray['username'];
|
||||
$password = $cConfigArray['password'];
|
||||
$url = $cConfigArray['virtualmin']['vmin-url'];
|
||||
$username = $cConfigArray['virtualmin']['username'];
|
||||
$password = $cConfigArray['virtualmin']['password'];
|
||||
|
||||
$this->virtualmin = new Virtualmin\VirtualServersClient($url, $username, $password);
|
||||
}
|
||||
|
|
|
@ -8,10 +8,9 @@ class Config
|
|||
public function __construct()
|
||||
{
|
||||
$ROOT = $_SERVER['DOCUMENT_ROOT'];
|
||||
$config = $ROOT . "/source/config.php";
|
||||
$config = $ROOT . "/source/config.ini";
|
||||
|
||||
$c = include($config);
|
||||
$this->config = $c;
|
||||
$this->config = parse_ini_file($config, true);
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue