From c3f882960c350310054244fa3acd0db0a159ee92 Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Fri, 8 Jun 2018 18:58:48 +0000 Subject: [PATCH] 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). --- source/config.ini | 31 ++++++++++++ source/config.php | 51 -------------------- source/dbtools/Application.php | 41 ++++------------ source/dbtools/ApplicationApiTools.php | 7 +-- source/defs/Virtualmin/Virtualmin.php | 6 +-- source/helpers/ConfigHelper/class.Config.php | 5 +- 6 files changed, 46 insertions(+), 95 deletions(-) create mode 100644 source/config.ini delete mode 100644 source/config.php diff --git a/source/config.ini b/source/config.ini new file mode 100644 index 0000000..78a12bb --- /dev/null +++ b/source/config.ini @@ -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" \ No newline at end of file diff --git a/source/config.php b/source/config.php deleted file mode 100644 index f9de827..0000000 --- a/source/config.php +++ /dev/null @@ -1,51 +0,0 @@ - - [ - "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 - - - ] - ] - - ]; \ No newline at end of file diff --git a/source/dbtools/Application.php b/source/dbtools/Application.php index 5c454b2..5d3925f 100644 --- a/source/dbtools/Application.php +++ b/source/dbtools/Application.php @@ -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->instDB(); - } - - private function isHostAlive($domain) - { - $starttime = microtime(true); - $file = fsockopen ($domain, 80, $errno, $errstr, 10); - $stoptime = microtime(true); - $status = 0; + $this->database['username'] = $cConfigArray['database']['username']; + $this->database['password'] = $cConfigArray['database']['password']; + $this->database['hostname'] = $cConfigArray['database']['hostname']; + $this->database['dbname'] = $cConfigArray['database']['dbname']; - 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']; - - $Conn = \ParagonIE\EasyDB\Factory::create($dsn, $username, $password); + $this->db = \ParagonIE\EasyDB\Factory::create($dsn, $username, $password); - $this->db = $Conn; + } + public function Exists($Table, $IDRowColumnName, $SearchValue) { $exists = $db->cell( diff --git a/source/dbtools/ApplicationApiTools.php b/source/dbtools/ApplicationApiTools.php index e946fec..a758891 100644 --- a/source/dbtools/ApplicationApiTools.php +++ b/source/dbtools/ApplicationApiTools.php @@ -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 ); diff --git a/source/defs/Virtualmin/Virtualmin.php b/source/defs/Virtualmin/Virtualmin.php index b328ec2..d8738ab 100644 --- a/source/defs/Virtualmin/Virtualmin.php +++ b/source/defs/Virtualmin/Virtualmin.php @@ -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); } diff --git a/source/helpers/ConfigHelper/class.Config.php b/source/helpers/ConfigHelper/class.Config.php index 7506f8b..16d6998 100644 --- a/source/helpers/ConfigHelper/class.Config.php +++ b/source/helpers/ConfigHelper/class.Config.php @@ -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);