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()){ - +Benvenuto in Allerta. Prima di iniziare abbiamo bisogno di alcune informazioni sul database. Devi conoscere i seguenti dati prima di procedere.
Hai quasi terminato l'installazione di Allerta, devi solo inserire alcune informazioni.
@@ -218,7 +235,7 @@ if(!is_cli()){