From 826fe3df0bacbb75d3f75a234b16b0ee475f54d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Garrido=20Labrador?= Date: Wed, 16 May 2018 16:00:03 +0200 Subject: [PATCH] Composer updated and 503 error added --- Source/composer.lock | 40 ++++++++++++++++++++-------------------- Source/src/Config.php | 2 +- Source/src/app.php | 22 ++++++++++++++++------ 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/Source/composer.lock b/Source/composer.lock index 6ab50f1..e873566 100644 --- a/Source/composer.lock +++ b/Source/composer.lock @@ -1,23 +1,23 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], "content-hash": "c34d26c2711c26f871ff9ca8a4401104", "packages": [ { "name": "jkanetwork/dbwrapper", - "version": "1.4.1", + "version": "1.5.0", "source": { "type": "git", "url": "https://gitlab.com/CodeSolutionsProject/DBWrapper.git", - "reference": "d10246e5bd55950280f3f7802d885341f1477874" + "reference": "d366ae0f1f25d6a89c8c5a379118bf92aca45bdd" }, "dist": { "type": "zip", - "url": "https://gitlab.com/api/v4/projects/CodeSolutionsProject%2FDBWrapper/repository/archive.zip?sha=d10246e5bd55950280f3f7802d885341f1477874", - "reference": "d10246e5bd55950280f3f7802d885341f1477874", + "url": "https://gitlab.com/api/v4/projects/CodeSolutionsProject%2FDBWrapper/repository/archive.zip?sha=d366ae0f1f25d6a89c8c5a379118bf92aca45bdd", + "reference": "d366ae0f1f25d6a89c8c5a379118bf92aca45bdd", "shasum": "" }, "require": { @@ -31,7 +31,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "APACHE" + "Apache-2.0" ], "authors": [ { @@ -46,20 +46,20 @@ "sqlite", "wrapper" ], - "time": "2017-09-22T01:18:27+00:00" + "time": "2018-05-16T13:37:18+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.5.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803" + "reference": "3296adf6a6454a050679cde90f95350ad604b171" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7c8fae0ac1d216eb54349e6a8baa57d515fe8803", - "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", + "reference": "3296adf6a6454a050679cde90f95350ad604b171", "shasum": "" }, "require": { @@ -71,7 +71,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -105,20 +105,20 @@ "portable", "shim" ], - "time": "2017-06-14T15:44:48+00:00" + "time": "2018-04-26T10:06:28+00:00" }, { "name": "twig/twig", - "version": "v2.4.4", + "version": "v2.4.8", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "eddb97148ad779f27e670e1e3f19fb323aedafeb" + "reference": "7b604c89da162034bdf4bb66310f358d313dd16d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/eddb97148ad779f27e670e1e3f19fb323aedafeb", - "reference": "eddb97148ad779f27e670e1e3f19fb323aedafeb", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/7b604c89da162034bdf4bb66310f358d313dd16d", + "reference": "7b604c89da162034bdf4bb66310f358d313dd16d", "shasum": "" }, "require": { @@ -127,8 +127,8 @@ }, "require-dev": { "psr/container": "^1.0", - "symfony/debug": "~2.7", - "symfony/phpunit-bridge": "~3.3@dev" + "symfony/debug": "^2.7", + "symfony/phpunit-bridge": "^3.3" }, "type": "library", "extra": { @@ -171,7 +171,7 @@ "keywords": [ "templating" ], - "time": "2017-09-27T18:10:31+00:00" + "time": "2018-04-02T09:24:19+00:00" } ], "packages-dev": [], diff --git a/Source/src/Config.php b/Source/src/Config.php index 9c1ebcc..042d054 100644 --- a/Source/src/Config.php +++ b/Source/src/Config.php @@ -84,7 +84,7 @@ class Config if(!Config::initialized()) Config::init(); $DB = Config::$config["database"]; - return dbw_connect($DB["SGBD"],$DB["path"],$DB["db"],$DB["user"],$DB["password"]); + return dbw_connect($DB["SGBD"], $DB["path"], $DB["db"], $DB["user"], $DB["password"]); } /** diff --git a/Source/src/app.php b/Source/src/app.php index d3ae070..8f42418 100644 --- a/Source/src/app.php +++ b/Source/src/app.php @@ -20,18 +20,23 @@ $supported = ksonParse('data/supported.kson'); $loader = new Twig_Loader_Filesystem($path['html']); $twig = new Twig_Environment($loader); $user = array(); +$db=null; +try { + $db = new DB(); +}catch (Exception $ex){ + sendHTTPError(503); + exit(); +} function run(){ global $user; if(isset($_SESSION['sessionID'])){ - $db = new DB(); + global $db; if($db->checkCookie($_SESSION['sessionID'],$_SESSION['token'])){ $user = $db->loadProfile($_SESSION['sessionID']); } } if (isset($_POST["search"])){ - //echo $_POST["search"]; - //die(); firstPage(false,true); } else if ($_GET) { @@ -66,6 +71,8 @@ function run(){ case "user": user(); break; + case "error": + sendHTTPError($_GET['error']); /*case "del": deleteSource();*/ break; @@ -96,6 +103,9 @@ function sendHTTPError($code){ case 404: $text = "Page not found"; break; + case 503: + $text = "Database unavailable"; + break; case 500: $text = "Internal server error"; break; @@ -117,7 +127,7 @@ function sendHTTPError($code){ */ function firstPage($filter=false,$globalSearch=false){ global $supported,$twig,$path,$user; - $db = new DB(); + global $db; if(!$filter and !$globalSearch) //Common index if(isset($_GET["p"])) //If page (not 0) $query = $db->loadLast($_GET["p"]); @@ -185,7 +195,7 @@ function add(){ function codeViewer(){ global $supported,$twig,$path,$user; - $db = new DB(); + global $db; if(isset($_POST['lang'])){ $db->addSource($_GET['id'],$_POST['lang'],htmlentities($_POST['code']),$user["IDU"]); @@ -331,7 +341,7 @@ function user(){ $passact = $_POST["passact"]; $newpass = $_POST["newpass"]; //echo "EEEEEOOO"; - $db = new DB(); + global $db; if($db->checkPass($user['email'],$passact)){ $status=1; $db->updatePass($user['IDU'],$newpass);