diff --git a/catalog/includes/OSC/OM/Db.php b/catalog/includes/OSC/OM/Db.php index cdb82f106..f75bee84c 100644 --- a/catalog/includes/OSC/OM/Db.php +++ b/catalog/includes/OSC/OM/Db.php @@ -21,6 +21,7 @@ class Db extends \PDO protected $table_prefix; protected $port; protected $driver_options = []; + protected $options = []; public static function initialize( $server = null, @@ -28,7 +29,8 @@ public static function initialize( $password = null, $database = null, $port = null, - array $driver_options = [] + array $driver_options = null, + array $options = null ) { if (!isset($server)) { $server = OSCOM::getConfig('db_server'); @@ -46,6 +48,10 @@ public static function initialize( $database = OSCOM::getConfig('db_database'); } + if (!is_array($driver_options)) { + $driver_options = []; + } + if (!isset($driver_options[\PDO::ATTR_ERRMODE])) { $driver_options[\PDO::ATTR_ERRMODE] = \PDO::ERRMODE_EXCEPTION; } @@ -58,8 +64,25 @@ public static function initialize( $driver_options[\PDO::ATTR_STATEMENT_CLASS] = array('OSC\OM\DbStatement'); } - $class = 'OSC\OM\Db\MySQL'; - $object = new $class($server, $username, $password, $database, $port, $driver_options); + if (!is_array($options)) { + $options = []; + } + + $object = false; + + try { + $class = 'OSC\OM\Db\MySQL'; + $object = new $class($server, $username, $password, $database, $port, $driver_options, $options); + } catch (\Exception $e) { + $message = $e->getMessage(); + // $message .= "\n" . $e->getTraceAsString(); // the trace will contain the password in plain text + + if (!isset($options['log_errors']) || ($options['log_errors'] === true)) { + error_log('OSC\OM\Db::initialize(): ' . $message); + } + + throw new \Exception($message, $e->getCode()); + } return $object; } diff --git a/catalog/includes/OSC/OM/Db/MySQL.php b/catalog/includes/OSC/OM/Db/MySQL.php index 341dc8d1a..1d84bf392 100644 --- a/catalog/includes/OSC/OM/Db/MySQL.php +++ b/catalog/includes/OSC/OM/Db/MySQL.php @@ -10,7 +10,7 @@ class MySQL extends \OSC\OM\Db { - public function __construct($server, $username, $password, $database, $port, $driver_options) + public function __construct($server, $username, $password, $database, $port, $driver_options, $options) { $this->server = $server; $this->username = $username; @@ -18,6 +18,7 @@ public function __construct($server, $username, $password, $database, $port, $dr $this->database = $database; $this->port = $port; $this->driver_options = $driver_options; + $this->options = $options; if (!isset($this->driver_options[\PDO::MYSQL_ATTR_INIT_COMMAND])) { // STRICT_ALL_TABLES 5.0.2 diff --git a/catalog/includes/OSC/OM/OSCOM.php b/catalog/includes/OSC/OM/OSCOM.php index b7e12b24f..126a6123b 100644 --- a/catalog/includes/OSC/OM/OSCOM.php +++ b/catalog/includes/OSC/OM/OSCOM.php @@ -121,8 +121,6 @@ public static function isRPC() public static function link($page, $parameters = null, $add_session_id = true, $search_engine_safe = true) { - $OSCOM_Session = Registry::get('Session'); - $page = HTML::sanitize($page); $site = $req_site = static::$site; @@ -170,9 +168,13 @@ public static function link($page, $parameters = null, $add_session_id = true, $ } // Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined - if (($add_session_id == true) && $OSCOM_Session->hasStarted() && ($OSCOM_Session->isForceCookies() === false)) { - if ((strlen(SID) > 0) || (((HTTP::getRequestType() == 'NONSSL') && (parse_url(static::getConfig('http_server', $req_site), PHP_URL_SCHEME) == 'https')) || ((HTTP::getRequestType() == 'SSL') && (parse_url(static::getConfig('http_server', $req_site), PHP_URL_SCHEME) == 'http')))) { - $link .= $separator . HTML::sanitize(session_name() . '=' . session_id()); + if (($add_session_id == true) && Registry::exists('Session')) { + $OSCOM_Session = Registry::get('Session'); + + if ($OSCOM_Session->hasStarted() && ($OSCOM_Session->isForceCookies() === false)) { + if ((strlen(SID) > 0) || (((HTTP::getRequestType() == 'NONSSL') && (parse_url(static::getConfig('http_server', $req_site), PHP_URL_SCHEME) == 'https')) || ((HTTP::getRequestType() == 'SSL') && (parse_url(static::getConfig('http_server', $req_site), PHP_URL_SCHEME) == 'http')))) { + $link .= $separator . HTML::sanitize(session_name() . '=' . session_id()); + } } } @@ -180,7 +182,7 @@ public static function link($page, $parameters = null, $add_session_id = true, $ $link = str_replace('&&', '&', $link); } - if ((SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true)) { + if (($search_engine_safe == true) && defined('SEARCH_ENGINE_FRIENDLY_URLS') && (SEARCH_ENGINE_FRIENDLY_URLS == 'true')) { $link = str_replace(['?', '&', '='], '/', $link); } diff --git a/catalog/includes/OSC/Sites/Admin/Admin.php b/catalog/includes/OSC/Sites/Admin/Admin.php index ff9175bbf..bf4a22e1a 100644 --- a/catalog/includes/OSC/Sites/Admin/Admin.php +++ b/catalog/includes/OSC/Sites/Admin/Admin.php @@ -29,8 +29,13 @@ protected function init() $OSCOM_Cookies = new Cookies(); Registry::set('Cookies', $OSCOM_Cookies); - $OSCOM_Db = Db::initialize(); - Registry::set('Db', $OSCOM_Db); + try { + $OSCOM_Db = Db::initialize(); + Registry::set('Db', $OSCOM_Db); + } catch (\Exception $e) { + include(OSCOM::getConfig('dir_root', 'Shop') . 'includes/error_documents/maintenance.php'); + exit; + } Registry::set('Hooks', new Hooks()); diff --git a/catalog/includes/OSC/Sites/Shop/Shop.php b/catalog/includes/OSC/Sites/Shop/Shop.php index 656922e77..f92bff8bf 100644 --- a/catalog/includes/OSC/Sites/Shop/Shop.php +++ b/catalog/includes/OSC/Sites/Shop/Shop.php @@ -27,8 +27,13 @@ protected function init() $OSCOM_Cookies = new Cookies(); Registry::set('Cookies', $OSCOM_Cookies); - $OSCOM_Db = Db::initialize(); - Registry::set('Db', $OSCOM_Db); + try { + $OSCOM_Db = Db::initialize(); + Registry::set('Db', $OSCOM_Db); + } catch (\Exception $e) { + include(OSCOM::getConfig('dir_root') . 'includes/error_documents/maintenance.php'); + exit; + } Registry::set('Hooks', new Hooks()); diff --git a/catalog/includes/error_documents/404.php b/catalog/includes/error_documents/404.php index c5de72da4..6f00aff1d 100644 --- a/catalog/includes/error_documents/404.php +++ b/catalog/includes/error_documents/404.php @@ -12,8 +12,26 @@ http_response_code(404); ?> -

Error - Page Not Found (404)

+ + + + + +Error - Page Not Found + + + + + +
+
+

This Page is Missing

-
- +

It looks like this page is missing. Please continue back to our website and try again.

+ +

+
+ + + diff --git a/catalog/includes/error_documents/maintenance.php b/catalog/includes/error_documents/maintenance.php new file mode 100644 index 000000000..cc157369c --- /dev/null +++ b/catalog/includes/error_documents/maintenance.php @@ -0,0 +1,38 @@ + + + + + + + +Maintenance + + + + + +
+
+

We'll be back soon!

+ +

We're currently working on and improving our website. We'll be back in a few moments..

+ +

+
+
+ + + diff --git a/catalog/install/rpc.php b/catalog/install/rpc.php index 62c1a6011..b0d603f3e 100644 --- a/catalog/install/rpc.php +++ b/catalog/install/rpc.php @@ -61,7 +61,7 @@ case 'dbCheck': try { - $OSCOM_Db = Db::initialize(isset($_POST['server']) ? $_POST['server'] : '', isset($_POST['username']) ? $_POST['username'] : '', isset($_POST['password']) ? $_POST['password'] : '', isset($_POST['name']) ? $_POST['name'] : ''); + $OSCOM_Db = Db::initialize(isset($_POST['server']) ? $_POST['server'] : '', isset($_POST['username']) ? $_POST['username'] : '', isset($_POST['password']) ? $_POST['password'] : '', isset($_POST['name']) ? $_POST['name'] : '', null, null, ['log_errors' => false]); $result['status'] = '1'; $result['message'] = 'success'; @@ -71,7 +71,7 @@ if (($e->getCode() == '1049') && isset($_GET['createDb']) && ($_GET['createDb'] == 'true')) { try { - $OSCOM_Db = Db::initialize($_POST['server'], $_POST['username'], $_POST['password'], ''); + $OSCOM_Db = Db::initialize($_POST['server'], $_POST['username'], $_POST['password'], '', null, null, ['log_errors' => false]); $OSCOM_Db->exec('create database ' . Db::prepareIdentifier($_POST['name']) . ' character set utf8 collate utf8_unicode_ci');