3 * wallabag, self hostable application allowing you to not miss any content anymore
6 * @author Nicolas LÅ“uillet <nicolas@loeuillet.org>
8 * @license http://opensource.org/licenses/MIT see COPYING file
14 /* Function taken from at http://php.net/manual/en/function.rmdir.php#110489
15 * Idea : nbari at dalmp dot com
17 * Here in case of .gitignore files
19 function delTree($dir) {
20 $files = array_diff(scandir($dir), array('.','..'));
21 foreach ($files as $file) {
22 (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
27 if (isset($_GET['clean'])) {
28 if (is_dir('install')){
30 header('Location: index.php');
34 if (isset($_POST['download'])) {
35 if (!file_put_contents("cache
/vendor
.zip
", fopen("http
://static.wallabag.org/files/vendor.zip", 'r'))) {
36 $errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually</a> and unzip it in your wallabag folder.';
39 if (extension_loaded('zip')) {
40 $zip = new ZipArchive();
41 if ($zip->open("cache/vendor.zip") !== TRUE){
42 $errors[] = 'Impossible to open cache/vendor.zip. Please unzip it manually in your wallabag folder.';
44 if ($zip->extractTo(realpath(''))) {
45 @unlink("cache/vendor.zip");
46 $successes[] = 'twig is now installed, you can install wallabag.';
49 $errors[] = 'Impossible to extract cache/vendor.zip. Please unzip it manually in your wallabag folder.';
54 $errors[] = 'zip extension is not enabled in your PHP configuration. Please unzip cache/vendor.zip in your wallabag folder.';
58 else if (isset($_POST['install'])) {
59 if (!is_dir('vendor')) {
60 $errors[] = 'You must install twig before.';
64 // Create config.inc.php
65 if (!copy('inc/poche/config.inc.default.php', 'inc/poche/config.inc.php')) {
66 $errors[] = 'Installation aborted, impossible to create inc/poche/config.inc.php file. Maybe you don\'t have write access to create it.';
70 function generate_salt() {
71 mt_srand(microtime(true)*100000 +
memory_get_usage(true));
72 return md5(uniqid(mt_rand(), true));
75 $content = file_get_contents('inc/poche/config.inc.php');
76 $salt = generate_salt();
77 $content = str_replace("define ('SALT', '');", "define ('SALT', '".$salt."');", $content);
78 file_put_contents('inc/poche/config.inc.php', $content);
84 $username = trim($_POST['username']);
85 $password = trim($_POST['password']);
86 $salted_password = sha1($password . $username . $salt);
88 // Database informations
89 if ($_POST['db_engine'] == 'sqlite') {
90 if (!copy('install/poche.sqlite', 'db/poche.sqlite')) {
91 $errors[] = 'Impossible to create inc/poche/config.inc.php file.';
95 $db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite';
96 $handle = new PDO($db_path);
101 $content = file_get_contents('inc/poche/config.inc.php');
103 if ($_POST['db_engine'] == 'mysql') {
104 $db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database'] . ';charset=utf8mb4';
105 $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['mysql_server']."');", $content);
106 $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['mysql_database']."');", $content);
107 $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['mysql_user']."');", $content);
108 $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['mysql_password']."');", $content);
109 $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password'], array(
110 PDO
::MYSQL_ATTR_INIT_COMMAND
=> 'SET NAMES utf8mb4',
113 $sql_structure = file_get_contents('install/mysql.sql');
115 else if ($_POST['db_engine'] == 'postgres') {
116 $db_path = 'pgsql:host=' . $_POST['pg_server'] . ';dbname=' . $_POST['pg_database'];
117 $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['pg_server']."');", $content);
118 $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['pg_database']."');", $content);
119 $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['pg_user']."');", $content);
120 $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['pg_password']."');", $content);
121 $handle = new PDO($db_path, $_POST['pg_user'], $_POST['pg_password']);
123 $sql_structure = file_get_contents('install/postgres.sql');
126 $content = str_replace("define ('STORAGE', 'sqlite');", "define ('STORAGE', '".$_POST['db_engine']."');", $content);
127 file_put_contents('inc/poche/config.inc.php', $content);
132 function executeQuery($handle, $sql, $params) {
135 $query = $handle->prepare($sql);
136 $query->execute($params);
137 return $query->fetchAll();
145 // create database structure
146 $query = executeQuery($handle, $sql_structure, array());
149 $handle->setAttribute(PDO
::ATTR_ERRMODE
, PDO
::ERRMODE_EXCEPTION
);
151 $sql = 'INSERT INTO users (username, password, name) VALUES (?, ?, ?)';
152 $params = array($username, $salted_password, $username);
153 $query = executeQuery($handle, $sql, $params);
155 $id_user = $handle->lastInsertId();
157 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
158 $params = array($id_user, 'pager', '10');
159 $query = executeQuery($handle, $sql, $params);
161 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
162 $params = array($id_user, 'language', 'en_EN.UTF8');
163 $query = executeQuery($handle, $sql, $params);
165 $successes[] = 'wallabag is now installed. You can now <a href="index.php?clean=0">access it !</a>';
174 <meta name
="viewport" content
="initial-scale=1.0">
175 <meta charset
="utf-8">
177 <meta http
-equiv
="X-UA-Compatible" content
="IE=10">
179 <title
>wallabag
- installation
</title
>
180 <link rel
="shortcut icon" type
="image/x-icon" href
="themes/baggy/img/favicon.ico" />
181 <link rel
="apple-touch-icon-precomposed" sizes
="144x144" href
="themes/baggy/img/apple-touch-icon-144x144-precomposed.png">
182 <link rel
="apple-touch-icon-precomposed" sizes
="72x72" href
="themes/baggy/img/apple-touch-icon-72x72-precomposed.png">
183 <link rel
="apple-touch-icon-precomposed" href
="themes/baggy/img/apple-touch-icon-precomposed.png">
184 <link href
='//fonts.googleapis.com/css?family=PT+Sans:700' rel
='stylesheet' type
='text/css'>
185 <link rel
="stylesheet" href
="themes/baggy/css/ratatouille.css" media
="all">
186 <link rel
="stylesheet" href
="themes/baggy/css/font.css" media
="all">
187 <link rel
="stylesheet" href
="themes/baggy/css/main.css" media
="all">
188 <link rel
="stylesheet" href
="themes/baggy/css/messages.css" media
="all">
189 <link rel
="stylesheet" href
="themes/baggy/css/print.css" media
="print">
190 <script src
="themes/default/js/jquery-2.0.3.min.js"></script
>
191 <script src
="themes/baggy/js/init.js"></script
>
194 <header
class="w600p center mbm">
196 <img width
="100" height
="100" src
="themes/baggy/img/logo-w.png" alt
="logo poche" />
200 <button id
="menu" class="icon icon-menu desktopHide"><span
>Menu
</span
></button
>
201 <ul id
="links" class="links">
202 <li
><a href
="http://www.wallabag.org/frequently-asked-questions/">FAQ
</a
></li
>
203 <li
><a href
="http://doc.wallabag.org/">doc
</a
></li
>
204 <li
><a href
="http://www.wallabag.org/help/">help
</a
></li
>
205 <li
><a href
="http://www.wallabag.org/">wallabag
.org
</a
></li
>
207 <?php
if (!empty($errors)) : ?>
208 <div
class='messages error install'>
209 <p
>Errors during installation
:</p
>
212 <?php
foreach($errors as $error) :?>
213 <li
><?php
echo $error; ?></li
>
217 <p
><a href
="index.php">Please reload
</a
> this page when you think you resolved these problems
.</p
>
220 <?php
if (!empty($successes)) : ?>
221 <div
class='messages success install'>
224 <?php
foreach($successes as $success) :?>
225 <li
><?php
echo $success; ?></li
>
231 <?php
if (file_exists('inc/poche/config.inc.php') && is_dir('vendor')) : ?>
232 <div
class='messages success install'>
234 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
>.
239 <p
>To install wallabag
, you just have to fill the following fields
. That
's all.</p>
240 <p>Don't forget to check your server compatibility
<a href
="wallabag_compatibility_test.php?from=install">here
</a
>.</p
>
243 <legend
><strong
>Technical settings
</strong
></legend
>
244 <?php
if (!is_dir('vendor')) : ?>
245 <div
class='messages notice install'>wallabag needs twig
, a template
engine (<a href
="http://twig.sensiolabs.org/">?</a
>). Two ways to install it
:<br
/>
247 <li
>automatically download
and extract vendor
.zip into your wallabag folder
.
248 <p
><input type
="submit" name
="download" value
="Download vendor.zip" /></p
>
249 <?php
if (!extension_loaded('zip')) : ?>
250 <b
>Be careful
, zip extension is not enabled in your PHP configuration
. You
'll have to unzip vendor.zip manually.</b>
252 <em>This method is mainly recommended if you don't have a dedicated server
.</em
></li
>
253 <li
>use <a href
="http://getcomposer.org/">Composer
</a
> :<pre
><code
>curl
-s http
://getcomposer.org/installer | php
254 php composer
.phar install
</code
></pre
></li
>
261 <li
><label
for="sqlite">SQLite
</label
> <input name
="db_engine" type
="radio" checked
="" id
="sqlite" value
="sqlite" />
262 <div id
="pdo_sqlite" class='messages error install'>
263 <p
>You have to enable
<a href
="http://php.net/manual/ref.pdo-sqlite.php">pdo_sqlite extension
</a
>.</p
>
267 <label
for="mysql">MySQL
</label
> <input name
="db_engine" type
="radio" id
="mysql" value
="mysql" />
268 <ul id
="mysql_infos">
269 <li
><label
for="mysql_server">Server
</label
> <input type
="text" placeholder
="localhost" id
="mysql_server" name
="mysql_server" /></li
>
270 <li
><label
for="mysql_database">Database
</label
> <input type
="text" placeholder
="wallabag" id
="mysql_database" name
="mysql_database" /></li
>
271 <li
><label
for="mysql_user">User
</label
> <input type
="text" placeholder
="user" id
="mysql_user" name
="mysql_user" /></li
>
272 <li
><label
for="mysql_password">Password
</label
> <input type
="text" placeholder
="p4ssw0rd" id
="mysql_password" name
="mysql_password" /></li
>
276 <label
for="postgres">PostgreSQL
</label
> <input name
="db_engine" type
="radio" id
="postgres" value
="postgres" />
278 <li
><label
for="pg_server">Server
</label
> <input type
="text" placeholder
="localhost" id
="pg_server" name
="pg_server" /></li
>
279 <li
><label
for="pg_database">Database
</label
> <input type
="text" placeholder
="wallabag" id
="pg_database" name
="pg_database" /></li
>
280 <li
><label
for="pg_user">User
</label
> <input type
="text" placeholder
="user" id
="pg_user" name
="pg_user" /></li
>
281 <li
><label
for="pg_password">Password
</label
> <input type
="text" placeholder
="p4ssw0rd" id
="pg_password" name
="pg_password" /></li
>
289 <legend
><strong
>User settings
</strong
></legend
>
291 <label
for="username">Username
</label
>
292 <input type
="text" required id
="username" name
="username" value
="wallabag" />
295 <label
for="password">Password
</label
>
296 <input type
="password" required id
="password" name
="password" value
="wallabag" />
299 <label
for="show">Show password
:</label
> <input name
="show" id
="show" type
="checkbox" onchange
="document.getElementById('password').type = this.checked ? 'text' : 'password'">
303 <input type
="submit" id
="install_button" value
="Install wallabag" name
="install" />
307 $
("#mysql_infos").hide();
308 $
("#pg_infos").hide();
311 if (!extension_loaded('pdo_sqlite')) : ?>
312 $
("#install_button").hide();
316 $
("#pdo_sqlite").hide();
321 $
("input[name=db_engine]").click(function()
323 if ( $
("#mysql").prop('checked')) {
324 $
("#mysql_infos").show();
325 $
("#pg_infos").hide();
326 $
("#pdo_sqlite").hide();
327 $
("#install_button").show();
330 if ( $
("#postgres").prop('checked')) {
331 $
("#mysql_infos").hide();
332 $
("#pg_infos").show();
333 $
("#pdo_sqlite").hide();
334 $
("#install_button").show();
337 $
("#mysql_infos").hide();
338 $
("#pg_infos").hide();
340 if (!extension_loaded('pdo_sqlite')) : ?>
341 $
("#pdo_sqlite").show();
342 $
("#install_button").hide();