From 792097fb6a6507201ec41f90201ad05ad8c38870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 18 Feb 2014 21:22:34 +0100 Subject: [add] script to make the install more user friendly #466 --- install/index.php | 283 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 install/index.php (limited to 'install') diff --git a/install/index.php b/install/index.php new file mode 100644 index 00000000..d2137172 --- /dev/null +++ b/install/index.php @@ -0,0 +1,283 @@ +download it here manually<∕a> and unzip it in your wallabag folder.'; + } + else { + if (extension_loaded('zip')) { + $zip = new ZipArchive(); + if ($zip->open("cache/vendor.zip") !== TRUE){ + $errors[] = 'Impossible to open cache/vendor.zip. Please unzip it manually in your wallabag folder.'; + } + if ($zip->extractTo(realpath(''))) { + @unlink("cache/vendor.zip"); + $successes[] = 'twig is now installed, you can install wallabag.'; + } + else { + $errors[] = 'Impossible to extract cache/vendor.zip. Please unzip it manually in your wallabag folder.'; + } + $zip->close(); + } + else { + $errors[] = 'zip extension is not enabled in your PHP configuration. Please unzip cache/vendor.zip in your wallabag folder.'; + } + } +} +else if ($_POST['install']) { + if (!is_dir('vendor')) { + $errors[] = 'You must install twig before.'; + } + else { + $continue = true; + // Create config.inc.php + if (!copy('inc/poche/config.inc.php.new', 'inc/poche/config.inc.php')) { + $errors[] = 'Installation aborted, impossible to create inc/poche/config.inc.php file. Maybe you don\'t have write access to create it.'; + $continue = false; + } + else { + function generate_salt() { + mt_srand(microtime(true)*100000 + memory_get_usage(true)); + return md5(uniqid(mt_rand(), true)); + } + + $content = file_get_contents('inc/poche/config.inc.php'); + $salt = generate_salt(); + $content = str_replace("define ('SALT', '');", "define ('SALT', '".$salt."');", $content); + file_put_contents('inc/poche/config.inc.php', $content); + } + + if ($continue) { + + // User informations + $username = trim($_POST['username']); + $password = trim($_POST['password']); + $salted_password = sha1($password . $username . $salt); + + // Database informations + if ($_POST['db_engine'] == 'sqlite') { + if (!copy('install/poche.sqlite', 'db/poche.sqlite')) { + $errors[] = 'Impossible to create inc/poche/config.inc.php file.'; + $continue = false; + } + else { + $db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite'; + $handle = new PDO($db_path); + } + } + else { + $content = file_get_contents('inc/poche/config.inc.php'); + + if ($_POST['db_engine'] == 'mysql') { + $db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database']; + $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['mysql_server']."');", $content); + $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['mysql_database']."');", $content); + $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['mysql_user']."');", $content); + $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['mysql_password']."');", $content); + $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password']); + + $sql_structure = file_get_contents('install/mysql.sql'); + } + else if ($_POST['db_engine'] == 'postgresql') { + $db_path = 'pgsql:host=' . $_POST['pg_server'] . ';dbname=' . $_POST['pg_database']; + $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['pg_server']."');", $content); + $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['pg_database']."');", $content); + $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['pg_user']."');", $content); + $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['pg_password']."');", $content); + $handle = new PDO($db_path, $_POST['pg_user'], $_POST['pg_password']); + + $sql_structure = file_get_contents('install/postgres.sql'); + } + + $content = str_replace("define ('STORAGE', 'sqlite');", "define ('STORAGE', '".$_POST['db_engine']."');", $content); + file_put_contents('inc/poche/config.inc.php', $content); + } + + if ($continue) { + + function executeQuery($handle, $sql, $params) { + try + { + $query = $handle->prepare($sql); + $query->execute($params); + return $query->fetchAll(); + } + catch (Exception $e) + { + return FALSE; + } + } + + // create database structure + $query = executeQuery($handle, $sql_structure, array()); + + // Create user + $handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $sql = 'INSERT INTO users (username, password, name) VALUES (?, ?, ?)'; + $params = array($username, $salted_password, $username); + $query = executeQuery($handle, $sql, $params); + + $id_user = $handle->lastInsertId(); + + $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; + $params = array($id_user, 'pager', '10'); + $query = executeQuery($handle, $sql, $params); + + $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; + $params = array($id_user, 'language', 'en_EN.UTF8'); + $query = executeQuery($handle, $sql, $params); + + $successes[] = 'wallabag is now installed. Don\'t forget to delete install folder.'; + } + } + } +} +?> + + + + + + + wallabag — installation + + + + + + + + + + + + + + +
+

+ logo poche +

+
+
+ + + +
+

Errors during installation:

+

+

    + +
  • + +
+

+

Please reload this page when you think you resolved these problems.

+
+ + +
+

+

    + +
  • + +
+

+
+ +

To install wallabag, you just have to fill the following fields. That's all.

+

Don't forget to check your server compatibility here.

+
+
+ Technical settings + +
wallabag needs twig, a template engine (?). Two ways to install it: +
    +
  • automatically download and extract vendor.zip into your wallabag folder. +

    + + Be careful, zip extension is not enabled in your PHP configuration. You'll have to unzip vendor.zip manually. + + This method is mainly recommended if you don't have a dedicated server.
  • +
  • use Composer :
    curl -s http://getcomposer.org/installer | php
    +php composer.phar install
  • +
+
+ +

+ Database engine: +

    +
  • +
  • + +
      +
    • +
    • +
    • +
    • +
    +
  • +
  • + +
      +
    • +
    • +
    • + id
    • +
    +
  • +
+

+
+ +
+ User settings +

+ + +

+

+ + +

+

+ +

+
+ + +
+
+ + + \ No newline at end of file -- cgit v1.2.3