X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=install%2Findex.php;h=654d21cab8575157e309d6e36d1e06ecea4b76f3;hb=refs%2Ftags%2F1.9.1beta2;hp=7a6eaf3aac9224dbf7db5e80454afde8cc4a637a;hpb=7f8f8271e49a2834a87012ea838099c8b46cf63f;p=github%2Fwallabag%2Fwallabag.git diff --git a/install/index.php b/install/index.php index 7a6eaf3a..654d21ca 100755 --- a/install/index.php +++ b/install/index.php @@ -16,6 +16,29 @@ $email = ""; require_once('install_functions.php'); +// Start by destroying session to avoid wrong logins from previous installations +// cookie part +$cookiedir = ''; +if (dirname($_SERVER['SCRIPT_NAME'])!='/') { + $cookiedir = dirname($_SERVER["SCRIPT_NAME"]).'/'; +} + +if (isset($_SERVER['HTTP_COOKIE'])) { + $cookies = explode(';', $_SERVER['HTTP_COOKIE']); + foreach($cookies as $cookie) { + $parts = explode('=', $cookie); + $name = trim($parts[0]); + setcookie($name, '', time()-1000); + setcookie($name, '', time()-1000, $cookiedir); + } +} +// session part +if (isset($_SESSION['poche_user'])) { + unset($_SESSION['poche_user']); +} +session_destroy(); + + if (isset($_GET['clean'])) { if (is_dir('install')){ delTree('install', true); @@ -92,6 +115,8 @@ else if (isset($_POST['install'])) { if ($_POST['mysql_server'] != "") {$server = $_POST['mysql_server'];} // if server and database are filled if ($_POST['mysql_database'] != "") {$database = $_POST['mysql_database'];} + $sql_structure = file_get_contents('install/mysql.sql'); + if (isset($_POST['mysql_utf8_mb4'])) { //with UTF8-MB4 $db_path = 'mysql:host=' . $server . ';dbname=' . $database . ';charset=utf8mb4'; @@ -100,7 +125,7 @@ else if (isset($_POST['install'])) { )); $content = str_replace("define ('MYSQL_USE_UTF8MB4', FALSE);", "define ('MYSQL_USE_UTF8MB4', TRUE);", $content); } else { // regular UTF8 - $content = str_replace(" DEFAULT CHARSET=utf8mb4", "", $content); // replace the UTF8-MB4 occurences inside the mysql.sql file + $sql_structure = str_replace(" DEFAULT CHARSET=utf8mb4", "", $sql_structure); // replace the UTF8-MB4 occurences inside the mysql.sql file $db_path = 'mysql:host=' . $server . ';dbname=' . $database; $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password']); } @@ -142,16 +167,43 @@ else if (isset($_POST['install'])) { $sql_structure = file_get_contents('install/postgres.sql'); } // create database structure - $query = $handle->exec($sql_structure); - - $usertest = executeQuery($handle,"SELECT * from users WHERE username = ?", array($username)); - if (!empty($usertest)) { - $continue = false; - $errors[] = "An user already exists with this username in database."; - } + if (!$handle) { + $continue = false; + $errors[] = "Couldn't connect to your database server. Please check credentials."; + } else { + $query = $handle->exec($sql_structure); + + $usertest = executeQuery($handle,"SELECT * from users WHERE username = ?", array($username)); + if (!empty($usertest)) { + $continue = false; + $errors[] = "An user already exists with this username in database."; + } + } } catch (PDOException $e) { - $errors[] = $e->getMessage(); + /* Error codes : + / 7 : PostgreSQL issues + / 1045 : Access denied to the user : user doesn't exists + / 1044 : Access denied to the user : user doesn't have the rights to connect to this database + / 2005 : Unknown database server + */ + switch ($e->getCode()) { + case 7: + $errors[] = "PostgreSQL has encountered an issue : " . $e->getMessage(); + break; + case 1045: + $errors[] = "The password for this user is incorrect, or this user doesn't exist."; + break; + case 1044: + $errors[] = "The user isn't allowed to use this database."; + break; + case 2005: + $errors[] = "The server can't be reached."; + break; + default: + $errors[] = "A error happened while connecting to your database : " . $e->getMessage(); + break; + } $continue = false; } }