]> git.immae.eu Git - github/wallabag/wallabag.git/blame - install/index.php
better wallabag in wallabag button (see #685)
[github/wallabag/wallabag.git] / install / index.php
CommitLineData
792097fb
NL
1<?php
2$errors = array();
3$successes = array();
1be13ba1
NL
4
5/* Function taken from at http://php.net/manual/en/function.rmdir.php#110489
6 * Idea : nbari at dalmp dot com
7 * Rights unknown
8 * Here in case of .gitignore files
9 */
10function 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");
14 }
15 return rmdir($dir);
16 }
17
18if (isset($_GET['clean'])) {
19 if (is_dir('install')){
20 delTree('install');
21 header('Location: index.php');
22 }
23}
24
fecb62a3 25if (isset($_POST['download'])) {
fb5a9666 26 if (!file_put_contents("cache/vendor.zip", fopen("http://static.wallabag.org/files/vendor.zip", 'r'))) {
d967a1fa 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.';
792097fb
NL
28 }
29 else {
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.';
34 }
35 if ($zip->extractTo(realpath(''))) {
36 @unlink("cache/vendor.zip");
37 $successes[] = 'twig is now installed, you can install wallabag.';
38 }
39 else {
40 $errors[] = 'Impossible to extract cache/vendor.zip. Please unzip it manually in your wallabag folder.';
41 }
42 $zip->close();
43 }
44 else {
45 $errors[] = 'zip extension is not enabled in your PHP configuration. Please unzip cache/vendor.zip in your wallabag folder.';
46 }
47 }
48}
fecb62a3 49else if (isset($_POST['install'])) {
792097fb
NL
50 if (!is_dir('vendor')) {
51 $errors[] = 'You must install twig before.';
52 }
53 else {
54 $continue = true;
55 // Create config.inc.php
43c7b978 56 if (!copy('inc/poche/config.inc.default.php', 'inc/poche/config.inc.php')) {
792097fb
NL
57 $errors[] = 'Installation aborted, impossible to create inc/poche/config.inc.php file. Maybe you don\'t have write access to create it.';
58 $continue = false;
59 }
60 else {
61 function generate_salt() {
62 mt_srand(microtime(true)*100000 + memory_get_usage(true));
63 return md5(uniqid(mt_rand(), true));
64 }
65
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);
70 }
71
72 if ($continue) {
73
74 // User informations
75 $username = trim($_POST['username']);
76 $password = trim($_POST['password']);
77 $salted_password = sha1($password . $username . $salt);
78
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.';
83 $continue = false;
84 }
85 else {
86 $db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite';
87 $handle = new PDO($db_path);
1be13ba1 88 $sql_structure = "";
792097fb
NL
89 }
90 }
91 else {
92 $content = file_get_contents('inc/poche/config.inc.php');
93
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']);
101
102 $sql_structure = file_get_contents('install/mysql.sql');
103 }
feecea28 104 else if ($_POST['db_engine'] == 'postgres') {
792097fb
NL
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']);
111
112 $sql_structure = file_get_contents('install/postgres.sql');
113 }
114
115 $content = str_replace("define ('STORAGE', 'sqlite');", "define ('STORAGE', '".$_POST['db_engine']."');", $content);
116 file_put_contents('inc/poche/config.inc.php', $content);
117 }
118
119 if ($continue) {
120
121 function executeQuery($handle, $sql, $params) {
122 try
123 {
124 $query = $handle->prepare($sql);
125 $query->execute($params);
126 return $query->fetchAll();
127 }
128 catch (Exception $e)
129 {
130 return FALSE;
131 }
132 }
133
134 // create database structure
135 $query = executeQuery($handle, $sql_structure, array());
136
137 // Create user
138 $handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
139
140 $sql = 'INSERT INTO users (username, password, name) VALUES (?, ?, ?)';
141 $params = array($username, $salted_password, $username);
142 $query = executeQuery($handle, $sql, $params);
143
144 $id_user = $handle->lastInsertId();
145
146 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
147 $params = array($id_user, 'pager', '10');
148 $query = executeQuery($handle, $sql, $params);
149
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);
153
1be13ba1 154 $successes[] = 'wallabag is now installed. You can now <a href="index.php?clean=0">access it !</a>';
792097fb
NL
155 }
156 }
157 }
158}
159?>
160<!DOCTYPE html>
161<html>
162 <head>
163 <meta name="viewport" content="initial-scale=1.0">
164 <meta charset="utf-8">
165 <!--[if IE]>
166 <meta http-equiv="X-UA-Compatible" content="IE=10">
167 <![endif]-->
d967a1fa 168 <title>wallabag - installation</title>
792097fb
NL
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">
d967a1fa 179 <script src="themes/default/js/jquery-2.0.3.min.js"></script>
792097fb
NL
180 <script src="themes/baggy/js/init.js"></script>
181 </head>
182 <body>
183 <header class="w600p center mbm">
184 <h1 class="logo">
185 <img width="100" height="100" src="themes/baggy/img/logo-w.png" alt="logo poche" />
186 </h1>
187 </header>
188 <div id="main">
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>
195 </ul>
196 <?php if (!empty($errors)) : ?>
d09a5674 197 <div class='messages error install'>
792097fb
NL
198 <p>Errors during installation:</p>
199 <p>
200 <ul>
201 <?php foreach($errors as $error) :?>
202 <li><?php echo $error; ?></li>
203 <?php endforeach; ?>
204 </ul>
205 </p>
206 <p><a href="index.php">Please reload</a> this page when you think you resolved these problems.</p>
207 </div>
208 <?php endif; ?>
209 <?php if (!empty($successes)) : ?>
d09a5674 210 <div class='messages success install'>
792097fb
NL
211 <p>
212 <ul>
213 <?php foreach($successes as $success) :?>
214 <li><?php echo $success; ?></li>
215 <?php endforeach; ?>
216 </ul>
217 </p>
218 </div>
d09a5674
NL
219 <?php else : ?>
220 <?php if (file_exists('inc/poche/config.inc.php') && is_dir('vendor')) : ?>
221 <div class='messages success install'>
222 <p>
1be13ba1 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>.
d09a5674
NL
224 </p>
225 </div>
226 <?php endif; ?>
792097fb
NL
227 <?php endif; ?>
228 <p>To install wallabag, you just have to fill the following fields. That's all.</p>
1be13ba1 229 <p>Don't forget to check your server compatibility <a href="wallabag_compatibility_test.php?from=install">here</a>.</p>
792097fb
NL
230 <form method="post">
231 <fieldset>
232 <legend><strong>Technical settings</strong></legend>
233 <?php if (!is_dir('vendor')) : ?>
1be13ba1 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 />
792097fb
NL
235 <ul>
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>
240 <?php endif; ?>
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
243php composer.phar install</code></pre></li>
244 </ul>
245 </div>
246 <?php endif; ?>
247 <p>
248 Database engine:
249 <ul>
1be13ba1
NL
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>
253 </div>
254 </li>
792097fb
NL
255 <li>
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>
262 </ul>
263 </li>
264 <li>
feecea28 265 <label for="postgres">PostgreSQL</label> <input name="db_engine" type="radio" id="postgres" value="postgres" />
792097fb
NL
266 <ul id="pg_infos">
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>
1be13ba1 270 <li><label for="pg_password">Password</label> <input type="text" placeholder="p4ssw0rd" id="pg_password" name="pg_password" /></li>
792097fb
NL
271 </ul>
272 </li>
273 </ul>
274 </p>
275 </fieldset>
276
277 <fieldset>
278 <legend><strong>User settings</strong></legend>
279 <p>
280 <label for="username">Username</label>
281 <input type="text" required id="username" name="username" value="wallabag" />
282 </p>
283 <p>
284 <label for="password">Password</label>
285 <input type="password" required id="password" name="password" value="wallabag" />
286 </p>
287 <p>
288 <label for="show">Show password:</label> <input name="show" id="show" type="checkbox" onchange="document.getElementById('password').type = this.checked ? 'text' : 'password'">
289 </p>
290 </fieldset>
291
1be13ba1 292 <input type="submit" id="install_button" value="Install wallabag" name="install" />
792097fb
NL
293 </form>
294 </div>
295 <script>
296 $("#mysql_infos").hide();
297 $("#pg_infos").hide();
1be13ba1
NL
298
299 <?php
300 if (!extension_loaded('pdo_sqlite')) : ?>
301 $("#install_button").hide();
302 <?php
303 else :
304 ?>
305 $("#pdo_sqlite").hide();
306 <?php
307 endif;
308 ?>
309
792097fb
NL
310 $("input[name=db_engine]").click(function()
311 {
312 if ( $("#mysql").prop('checked')) {
313 $("#mysql_infos").show();
314 $("#pg_infos").hide();
1be13ba1
NL
315 $("#pdo_sqlite").hide();
316 $("#install_button").show();
792097fb
NL
317 }
318 else {
feecea28 319 if ( $("#postgres").prop('checked')) {
792097fb
NL
320 $("#mysql_infos").hide();
321 $("#pg_infos").show();
1be13ba1
NL
322 $("#pdo_sqlite").hide();
323 $("#install_button").show();
792097fb
NL
324 }
325 else {
326 $("#mysql_infos").hide();
327 $("#pg_infos").hide();
1be13ba1
NL
328 <?php
329 if (!extension_loaded('pdo_sqlite')) : ?>
330 $("#pdo_sqlite").show();
331 $("#install_button").hide();
332 <?php
333 endif;
334 ?>
792097fb
NL
335 }
336 }
337 });
338 </script>
339 </body>
340</html>