From bb309f27c4758569abe2466b0c535d470ff6010f Mon Sep 17 00:00:00 2001
From: Matteo Gheza
Date: Fri, 5 Jun 2020 17:56:22 +0200
Subject: [PATCH] Hotfix
---
.dockerignore | 5 +++
server/core.php | 7 ++++
server/install/install.php | 71 ++++++++++++++++++++------------
server/install/installHelper.php | 34 +++++++++------
4 files changed, 77 insertions(+), 40 deletions(-)
create mode 100644 .dockerignore
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..daaf0dd
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,5 @@
+*/vendor
+*.md
+.git
+config.php
+config.old.php
\ No newline at end of file
diff --git a/server/core.php b/server/core.php
index a518b0e..d8656c0 100644
--- a/server/core.php
+++ b/server/core.php
@@ -161,11 +161,18 @@ class database{
}
}
+ public function isOptionsEmpty(){
+ return empty($this->database->exec("SELECT * FROM `%PREFIX%_options`;", true));
+ }
+
public function __construct(){
if(!defined("DATABASE")){
define("DATABASE", "OK");
}
$this->connect();
+ if($this->isOptionsEmpty){
+ header('Location: install/install.php');
+ }
}
public function close(){
diff --git a/server/install/install.php b/server/install/install.php
index a2a911f..0d81013 100644
--- a/server/install/install.php
+++ b/server/install/install.php
@@ -12,6 +12,43 @@ if (file_exists("installHelper.php")) {
if (!file_exists("runInstall.php")) {
die("Already installed");
}
+
+$populated = false;
+if (file_exists("../config.php")) {
+ try {
+ require('../config.php');
+ $dbnameValue = DB_NAME;
+ $unameValue = DB_USER;
+ $pwdValue = DB_PASSWORD;
+ $dbhostValue = DB_HOST;
+ $prefixValue = DB_PREFIX;
+ if(checkConnection($dbhostValue,$unameValue,$pwdValue,$dbnameValue,true)){
+ $configExist = true;
+ try{
+ $connection = new PDO("mysql:host=$dbhostValue;dbname=$dbnameValue", $unameValue, $pwdValue,[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
+ $populated = !empty($connection->prepare(str_replace("%PREFIX%", DB_PREFIX, "SELECT * FROM `%PREFIX%_dbversion`;"))->execute());
+ $userPopulated = !empty($connection->prepare(str_replace("%PREFIX%", DB_PREFIX, "SELECT * FROM `%PREFIX%_users`;"))->execute());
+ } catch (PDOException $e){
+ $populated = false;
+ }
+ }
+ } catch (Exception $e) {
+ $dbnameValue = "allerta";
+ $unameValue = "user";
+ $pwdValue = "password";
+ $dbhostValue = "localhost";
+ $prefixValue = "allerta01";
+ $configExist = false;
+ }
+} else {
+ $dbnameValue = "allerta";
+ $unameValue = "user";
+ $pwdValue = "password";
+ $dbhostValue = "localhost";
+ $prefixValue = "allerta01";
+ $configExist = false;
+}
+
if(!is_cli()){
?>
@@ -27,7 +64,7 @@ if(!is_cli()){
Allerta
-
+
Prima di iniziare
Benvenuto in Allerta. Prima di iniziare abbiamo bisogno di alcune informazioni sul database. Devi conoscere i seguenti dati prima di procedere.
@@ -49,29 +86,7 @@ if(!is_cli()){
Configura la connection al database
@@ -124,8 +139,10 @@ if(!is_cli()){
Evviva!
Hai quasi terminato l'installazione di Allerta, devi solo inserire alcune informazioni.
@@ -218,7 +235,7 @@ if(!is_cli()){
Installazione terminata con successo.
diff --git a/server/install/installHelper.php b/server/install/installHelper.php
index 9f4e6ef..993a7ec 100644
--- a/server/install/installHelper.php
+++ b/server/install/installHelper.php
@@ -38,16 +38,19 @@ if (file_exists('../vendor/autoload.php')) {
define('NAME', 'AllertaVVF');
define('VERSION', '0.1-alpha');
-function checkConnection($host, $user, $password, $database){
+function checkConnection($host, $user, $password, $database, $return=false){
try{
$connection = new PDO("mysql:host=$host", $user, $password,[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$connectionOk = true;
} catch (PDOException $e){
- if(is_cli()){
- echo($e);
- exit(8);
- }
- $connectionOk = false;
+ if($return){
+ return false;
+ } else {
+ if(is_cli()){
+ echo($e);
+ exit(8);
+ }
+ $connectionOk = false;
?>
Errore nello stabilire una connection al database
Questo potrebbe voler dire che name user e password nel file config.php
sono sbagliate o che non possiamo contattare il database
. Potrebbe voler dire che il tuo database รจ irraddbile.
@@ -64,7 +67,8 @@ function checkConnection($host, $user, $password, $database){
Riprova
exec("use " . preg_replace('/[^a-zA-Z0-9]/', '', trim($database)));
} catch (PDOException $e){
- if(is_cli()){
- echo($e);
- exit(7);
- }
+ if($return){
+ return false;
+ } else {
+ if(is_cli()){
+ echo($e);
+ exit(7);
+ }
?>
Impossibile selezionare il database
Siamo riusciti a connetterci al server del database (il che significa che il tuo name user e password sono ok), ma non siamo riusciti a selezionare il database
.
@@ -95,8 +102,10 @@ function checkConnection($host, $user, $password, $database){
Riprova
' );
function initDB(){
try{
- require "../config.php";
$connection = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME, DB_USER, DB_PASSWORD,[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$prefix = DB_PREFIX;
$connection->exec("