5 /* Function taken from at http://php.net/manual/en/function.rmdir.php#110489
6 * Idea : nbari at dalmp dot com
8 * Here in case of .gitignore files
10 function delTree($dir) {
11 $files = array_diff(scandir($dir), array('.','..'));
12 foreach ($files as $file) {
13 (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
18 if (isset($_GET['clean'])) {
19 if (is_dir('install')){
21 header('Location: index.php');
25 if (isset($_POST['download'])) {
26 if (!file_put_contents("cache
/vendor
.zip
", fopen("http
://static.wallabag.org/files/vendor.zip", 'r'))) {
27 $errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually</a> and unzip it in your wallabag folder.';
30 if (extension_loaded('zip')) {
31 $zip = new ZipArchive();
32 if ($zip->open("cache/vendor.zip") !== TRUE){
33 $errors[] = 'Impossible to open cache/vendor.zip. Please unzip it manually in your wallabag folder.';
35 if ($zip->extractTo(realpath(''))) {
36 @unlink("cache/vendor.zip");
37 $successes[] = 'twig is now installed, you can install wallabag.';
40 $errors[] = 'Impossible to extract cache/vendor.zip. Please unzip it manually in your wallabag folder.';
45 $errors[] = 'zip extension is not enabled in your PHP configuration. Please unzip cache/vendor.zip in your wallabag folder.';
49 else if (isset($_POST['install'])) {
50 if (!is_dir('vendor')) {
51 $errors[] = 'You must install twig before.';
55 // Create config.inc.php
56 if (!copy('inc/poche/config.inc.default.php', 'inc/poche/config.inc.php')) {
57 $errors[] = 'Installation aborted, impossible to create inc/poche/config.inc.php file. Maybe you don\'t have write access to create it.';
61 function generate_salt() {
62 mt_srand(microtime(true)*100000 +
memory_get_usage(true));
63 return md5(uniqid(mt_rand(), true));
66 $content = file_get_contents('inc/poche/config.inc.php');
67 $salt = generate_salt();
68 $content = str_replace("define ('SALT', '');", "define ('SALT', '".$salt."');", $content);
69 file_put_contents('inc/poche/config.inc.php', $content);
75 $username = trim($_POST['username']);
76 $password = trim($_POST['password']);
77 $salted_password = sha1($password . $username . $salt);
79 // Database informations
80 if ($_POST['db_engine'] == 'sqlite') {
81 if (!copy('install/poche.sqlite', 'db/poche.sqlite')) {
82 $errors[] = 'Impossible to create inc/poche/config.inc.php file.';
86 $db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite';
87 $handle = new PDO($db_path);
92 $content = file_get_contents('inc/poche/config.inc.php');
94 if ($_POST['db_engine'] == 'mysql') {
95 $db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database'];
96 $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['mysql_server']."');", $content);
97 $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['mysql_database']."');", $content);
98 $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['mysql_user']."');", $content);
99 $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['mysql_password']."');", $content);
100 $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password']);
102 $sql_structure = file_get_contents('install/mysql.sql');
104 else if ($_POST['db_engine'] == 'postgres') {
105 $db_path = 'pgsql:host=' . $_POST['pg_server'] . ';dbname=' . $_POST['pg_database'];
106 $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['pg_server']."');", $content);
107 $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['pg_database']."');", $content);
108 $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['pg_user']."');", $content);
109 $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['pg_password']."');", $content);
110 $handle = new PDO($db_path, $_POST['pg_user'], $_POST['pg_password']);
112 $sql_structure = file_get_contents('install/postgres.sql');
115 $content = str_replace("define ('STORAGE', 'sqlite');", "define ('STORAGE', '".$_POST['db_engine']."');", $content);
116 file_put_contents('inc/poche/config.inc.php', $content);
121 function executeQuery($handle, $sql, $params) {
124 $query = $handle->prepare($sql);
125 $query->execute($params);
126 return $query->fetchAll();
134 // create database structure
135 $query = executeQuery($handle, $sql_structure, array());
138 $handle->setAttribute(PDO
::ATTR_ERRMODE
, PDO
::ERRMODE_EXCEPTION
);
140 $sql = 'INSERT INTO users (username, password, name) VALUES (?, ?, ?)';
141 $params = array($username, $salted_password, $username);
142 $query = executeQuery($handle, $sql, $params);
144 $id_user = $handle->lastInsertId();
146 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
147 $params = array($id_user, 'pager', '10');
148 $query = executeQuery($handle, $sql, $params);
150 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
151 $params = array($id_user, 'language', 'en_EN.UTF8');
152 $query = executeQuery($handle, $sql, $params);
154 $successes[] = 'wallabag is now installed. You can now <a href="index.php?clean=0">access it !</a>';
163 <meta name
="viewport" content
="initial-scale=1.0">
164 <meta charset
="utf-8">
166 <meta http
-equiv
="X-UA-Compatible" content
="IE=10">
168 <title
>wallabag
- installation
</title
>
169 <link rel
="shortcut icon" type
="image/x-icon" href
="themes/baggy/img/favicon.ico" />
170 <link rel
="apple-touch-icon-precomposed" sizes
="144x144" href
="themes/baggy/img/apple-touch-icon-144x144-precomposed.png">
171 <link rel
="apple-touch-icon-precomposed" sizes
="72x72" href
="themes/baggy/img/apple-touch-icon-72x72-precomposed.png">
172 <link rel
="apple-touch-icon-precomposed" href
="themes/baggy/img/apple-touch-icon-precomposed.png">
173 <link href
='//fonts.googleapis.com/css?family=PT+Sans:700' rel
='stylesheet' type
='text/css'>
174 <link rel
="stylesheet" href
="themes/baggy/css/ratatouille.css" media
="all">
175 <link rel
="stylesheet" href
="themes/baggy/css/font.css" media
="all">
176 <link rel
="stylesheet" href
="themes/baggy/css/main.css" media
="all">
177 <link rel
="stylesheet" href
="themes/baggy/css/messages.css" media
="all">
178 <link rel
="stylesheet" href
="themes/baggy/css/print.css" media
="print">
179 <script src
="themes/default/js/jquery-2.0.3.min.js"></script
>
180 <script src
="themes/baggy/js/init.js"></script
>
183 <header
class="w600p center mbm">
185 <img width
="100" height
="100" src
="themes/baggy/img/logo-w.png" alt
="logo poche" />
189 <button id
="menu" class="icon icon-menu desktopHide"><span
>Menu
</span
></button
>
190 <ul id
="links" class="links">
191 <li
><a href
="http://www.wallabag.org/frequently-asked-questions/">FAQ
</a
></li
>
192 <li
><a href
="http://doc.wallabag.org/">doc
</a
></li
>
193 <li
><a href
="http://www.wallabag.org/help/">help
</a
></li
>
194 <li
><a href
="http://www.wallabag.org/">wallabag
.org
</a
></li
>
196 <?php
if (!empty($errors)) : ?>
197 <div
class='messages error install'>
198 <p
>Errors during installation
:</p
>
201 <?php
foreach($errors as $error) :?>
202 <li
><?php
echo $error; ?></li
>
206 <p
><a href
="index.php">Please reload
</a
> this page when you think you resolved these problems
.</p
>
209 <?php
if (!empty($successes)) : ?>
210 <div
class='messages success install'>
213 <?php
foreach($successes as $success) :?>
214 <li
><?php
echo $success; ?></li
>
220 <?php
if (file_exists('inc/poche/config.inc.php') && is_dir('vendor')) : ?>
221 <div
class='messages success install'>
223 wallabag seems already installed
. If you want to update it
, you only have to delete install folder
, then
<a href
="index.php">reload this page
</a
>.
228 <p
>To install wallabag
, you just have to fill the following fields
. That
's all.</p>
229 <p>Don't forget to check your server compatibility
<a href
="wallabag_compatibility_test.php?from=install">here
</a
>.</p
>
232 <legend
><strong
>Technical settings
</strong
></legend
>
233 <?php
if (!is_dir('vendor')) : ?>
234 <div
class='messages notice install'>wallabag needs twig
, a template
engine (<a href
="http://twig.sensiolabs.org/">?</a
>). Two ways to install it
:<br
/>
236 <li
>automatically download
and extract vendor
.zip into your wallabag folder
.
237 <p
><input type
="submit" name
="download" value
="Download vendor.zip" /></p
>
238 <?php
if (!extension_loaded('zip')) : ?>
239 <b
>Be careful
, zip extension is not enabled in your PHP configuration
. You
'll have to unzip vendor.zip manually.</b>
241 <em>This method is mainly recommended if you don't have a dedicated server
.</em
></li
>
242 <li
>use <a href
="http://getcomposer.org/">Composer
</a
> :<pre
><code
>curl
-s http
://getcomposer.org/installer | php
243 php composer
.phar install
</code
></pre
></li
>
250 <li
><label
for="sqlite">SQLite
</label
> <input name
="db_engine" type
="radio" checked
="" id
="sqlite" value
="sqlite" />
251 <div id
="pdo_sqlite" class='messages error install'>
252 <p
>You have to enable
<a href
="http://php.net/manual/ref.pdo-sqlite.php">pdo_sqlite extension
</a
>.</p
>
256 <label
for="mysql">MySQL
</label
> <input name
="db_engine" type
="radio" id
="mysql" value
="mysql" />
257 <ul id
="mysql_infos">
258 <li
><label
for="mysql_server">Server
</label
> <input type
="text" placeholder
="localhost" id
="mysql_server" name
="mysql_server" /></li
>
259 <li
><label
for="mysql_database">Database
</label
> <input type
="text" placeholder
="wallabag" id
="mysql_database" name
="mysql_database" /></li
>
260 <li
><label
for="mysql_user">User
</label
> <input type
="text" placeholder
="user" id
="mysql_user" name
="mysql_user" /></li
>
261 <li
><label
for="mysql_password">Password
</label
> <input type
="text" placeholder
="p4ssw0rd" id
="mysql_password" name
="mysql_password" /></li
>
265 <label
for="postgres">PostgreSQL
</label
> <input name
="db_engine" type
="radio" id
="postgres" value
="postgres" />
267 <li
><label
for="pg_server">Server
</label
> <input type
="text" placeholder
="localhost" id
="pg_server" name
="pg_server" /></li
>
268 <li
><label
for="pg_database">Database
</label
> <input type
="text" placeholder
="wallabag" id
="pg_database" name
="pg_database" /></li
>
269 <li
><label
for="pg_user">User
</label
> <input type
="text" placeholder
="user" id
="pg_user" name
="pg_user" /></li
>
270 <li
><label
for="pg_password">Password
</label
> <input type
="text" placeholder
="p4ssw0rd" id
="pg_password" name
="pg_password" /></li
>
278 <legend
><strong
>User settings
</strong
></legend
>
280 <label
for="username">Username
</label
>
281 <input type
="text" required id
="username" name
="username" value
="wallabag" />
284 <label
for="password">Password
</label
>
285 <input type
="password" required id
="password" name
="password" value
="wallabag" />
288 <label
for="show">Show password
:</label
> <input name
="show" id
="show" type
="checkbox" onchange
="document.getElementById('password').type = this.checked ? 'text' : 'password'">
292 <input type
="submit" id
="install_button" value
="Install wallabag" name
="install" />
296 $
("#mysql_infos").hide();
297 $
("#pg_infos").hide();
300 if (!extension_loaded('pdo_sqlite')) : ?>
301 $
("#install_button").hide();
305 $
("#pdo_sqlite").hide();
310 $
("input[name=db_engine]").click(function()
312 if ( $
("#mysql").prop('checked')) {
313 $
("#mysql_infos").show();
314 $
("#pg_infos").hide();
315 $
("#pdo_sqlite").hide();
316 $
("#install_button").show();
319 if ( $
("#postgres").prop('checked')) {
320 $
("#mysql_infos").hide();
321 $
("#pg_infos").show();
322 $
("#pdo_sqlite").hide();
323 $
("#install_button").show();
326 $
("#mysql_infos").hide();
327 $
("#pg_infos").hide();
329 if (!extension_loaded('pdo_sqlite')) : ?>
330 $
("#pdo_sqlite").show();
331 $
("#install_button").hide();