]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | /** | |
3 | * wallabag, self hostable application allowing you to not miss any content anymore | |
4 | * | |
5 | * @category wallabag | |
6 | * @author Nicolas LÅ“uillet <nicolas@loeuillet.org> | |
7 | * @copyright 2013 | |
8 | * @license http://opensource.org/licenses/MIT see COPYING file | |
9 | */ | |
10 | ||
11 | $errors = array(); | |
12 | $successes = array(); | |
13 | ||
14 | /* Function taken from at http://php.net/manual/en/function.rmdir.php#110489 | |
15 | * Idea : nbari at dalmp dot com | |
16 | * Rights unknown | |
17 | * Here in case of .gitignore files | |
18 | */ | |
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"); | |
23 | } | |
24 | return rmdir($dir); | |
25 | } | |
26 | ||
27 | if (isset($_GET['clean'])) { | |
28 | if (is_dir('install')){ | |
29 | delTree('install'); | |
30 | header('Location: index.php'); | |
31 | } | |
32 | } | |
33 | ||
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.'; | |
37 | } | |
38 | else { | |
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.'; | |
43 | } | |
44 | if ($zip->extractTo(realpath(''))) { | |
45 | @unlink("cache/vendor.zip"); | |
46 | $successes[] = 'twig is now installed, you can install wallabag.'; | |
47 | } | |
48 | else { | |
49 | $errors[] = 'Impossible to extract cache/vendor.zip. Please unzip it manually in your wallabag folder.'; | |
50 | } | |
51 | $zip->close(); | |
52 | } | |
53 | else { | |
54 | $errors[] = 'zip extension is not enabled in your PHP configuration. Please unzip cache/vendor.zip in your wallabag folder.'; | |
55 | } | |
56 | } | |
57 | } | |
58 | else if (isset($_POST['install'])) { | |
59 | if (!is_dir('vendor')) { | |
60 | $errors[] = 'You must install twig before.'; | |
61 | } | |
62 | else { | |
63 | $continue = true; | |
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.'; | |
67 | $continue = false; | |
68 | } | |
69 | else { | |
70 | function generate_salt() { | |
71 | mt_srand(microtime(true)*100000 + memory_get_usage(true)); | |
72 | return md5(uniqid(mt_rand(), true)); | |
73 | } | |
74 | ||
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); | |
79 | } | |
80 | ||
81 | if ($continue) { | |
82 | ||
83 | // User informations | |
84 | $username = trim($_POST['username']); | |
85 | $password = trim($_POST['password']); | |
86 | $salted_password = sha1($password . $username . $salt); | |
87 | ||
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.'; | |
92 | $continue = false; | |
93 | } | |
94 | else { | |
95 | $db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite'; | |
96 | $handle = new PDO($db_path); | |
97 | $sql_structure = ""; | |
98 | } | |
99 | } | |
100 | else { | |
101 | $content = file_get_contents('inc/poche/config.inc.php'); | |
102 | ||
103 | if ($_POST['db_engine'] == 'mysql') { | |
104 | $db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database']; | |
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']); | |
110 | ||
111 | $sql_structure = file_get_contents('install/mysql.sql'); | |
112 | } | |
113 | else if ($_POST['db_engine'] == 'postgres') { | |
114 | $db_path = 'pgsql:host=' . $_POST['pg_server'] . ';dbname=' . $_POST['pg_database']; | |
115 | $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['pg_server']."');", $content); | |
116 | $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['pg_database']."');", $content); | |
117 | $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['pg_user']."');", $content); | |
118 | $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['pg_password']."');", $content); | |
119 | $handle = new PDO($db_path, $_POST['pg_user'], $_POST['pg_password']); | |
120 | ||
121 | $sql_structure = file_get_contents('install/postgres.sql'); | |
122 | } | |
123 | ||
124 | $content = str_replace("define ('STORAGE', 'sqlite');", "define ('STORAGE', '".$_POST['db_engine']."');", $content); | |
125 | file_put_contents('inc/poche/config.inc.php', $content); | |
126 | } | |
127 | ||
128 | if ($continue) { | |
129 | ||
130 | function executeQuery($handle, $sql, $params) { | |
131 | try | |
132 | { | |
133 | $query = $handle->prepare($sql); | |
134 | $query->execute($params); | |
135 | return $query->fetchAll(); | |
136 | } | |
137 | catch (Exception $e) | |
138 | { | |
139 | return FALSE; | |
140 | } | |
141 | } | |
142 | ||
143 | // create database structure | |
144 | $query = $handle->exec($sql_structure); | |
145 | ||
146 | // Create user | |
147 | $handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
148 | ||
149 | $sql = "INSERT INTO users (username, password, name, email) VALUES (?, ?, ?, '')"; | |
150 | $params = array($username, $salted_password, $username); | |
151 | $query = executeQuery($handle, $sql, $params); | |
152 | ||
153 | $id_user = (int)$handle->lastInsertId('users_id_seq'); | |
154 | ||
155 | $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; | |
156 | $params = array($id_user, 'pager', '10'); | |
157 | $query = executeQuery($handle, $sql, $params); | |
158 | ||
159 | $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; | |
160 | $params = array($id_user, 'language', 'en_EN.UTF8'); | |
161 | $query = executeQuery($handle, $sql, $params); | |
162 | ||
163 | $successes[] = 'wallabag is now installed. You can now <a href="index.php?clean=0">access it !</a>'; | |
164 | } | |
165 | } | |
166 | } | |
167 | } | |
168 | ?> | |
169 | <!DOCTYPE html> | |
170 | <html> | |
171 | <head> | |
172 | <meta name="viewport" content="initial-scale=1.0"> | |
173 | <meta charset="utf-8"> | |
174 | <!--[if IE]> | |
175 | <meta http-equiv="X-UA-Compatible" content="IE=10"> | |
176 | <![endif]--> | |
177 | <title>wallabag - installation</title> | |
178 | <link rel="shortcut icon" type="image/x-icon" href="themes/baggy/img/favicon.ico" /> | |
179 | <link rel="apple-touch-icon-precomposed" sizes="144x144" href="themes/baggy/img/apple-touch-icon-144x144-precomposed.png"> | |
180 | <link rel="apple-touch-icon-precomposed" sizes="72x72" href="themes/baggy/img/apple-touch-icon-72x72-precomposed.png"> | |
181 | <link rel="apple-touch-icon-precomposed" href="themes/baggy/img/apple-touch-icon-precomposed.png"> | |
182 | <link href='//fonts.googleapis.com/css?family=PT+Sans:700' rel='stylesheet' type='text/css'> | |
183 | <link rel="stylesheet" href="themes/baggy/css/ratatouille.css" media="all"> | |
184 | <link rel="stylesheet" href="themes/baggy/css/font.css" media="all"> | |
185 | <link rel="stylesheet" href="themes/baggy/css/main.css" media="all"> | |
186 | <link rel="stylesheet" href="themes/baggy/css/messages.css" media="all"> | |
187 | <link rel="stylesheet" href="themes/baggy/css/print.css" media="print"> | |
188 | <script src="themes/default/js/jquery-2.0.3.min.js"></script> | |
189 | <script src="themes/baggy/js/init.js"></script> | |
190 | </head> | |
191 | <body> | |
192 | <header class="w600p center mbm"> | |
193 | <h1 class="logo"> | |
194 | <img width="100" height="100" src="themes/baggy/img/logo-w.png" alt="logo poche" /> | |
195 | </h1> | |
196 | </header> | |
197 | <div id="main"> | |
198 | <button id="menu" class="icon icon-menu desktopHide"><span>Menu</span></button> | |
199 | <ul id="links" class="links"> | |
200 | <li><a href="http://www.wallabag.org/frequently-asked-questions/">FAQ</a></li> | |
201 | <li><a href="http://doc.wallabag.org/">doc</a></li> | |
202 | <li><a href="http://www.wallabag.org/help/">help</a></li> | |
203 | <li><a href="http://www.wallabag.org/">wallabag.org</a></li> | |
204 | </ul> | |
205 | <?php if (!empty($errors)) : ?> | |
206 | <div class='messages error install'> | |
207 | <p>Errors during installation:</p> | |
208 | <p> | |
209 | <ul> | |
210 | <?php foreach($errors as $error) :?> | |
211 | <li><?php echo $error; ?></li> | |
212 | <?php endforeach; ?> | |
213 | </ul> | |
214 | </p> | |
215 | <p><a href="index.php">Please reload</a> this page when you think you resolved these problems.</p> | |
216 | </div> | |
217 | <?php endif; ?> | |
218 | <?php if (!empty($successes)) : ?> | |
219 | <div class='messages success install'> | |
220 | <p> | |
221 | <ul> | |
222 | <?php foreach($successes as $success) :?> | |
223 | <li><?php echo $success; ?></li> | |
224 | <?php endforeach; ?> | |
225 | </ul> | |
226 | </p> | |
227 | </div> | |
228 | <?php else : ?> | |
229 | <?php if (file_exists('inc/poche/config.inc.php') && is_dir('vendor')) : ?> | |
230 | <div class='messages success install'> | |
231 | <p> | |
232 | 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>. | |
233 | </p> | |
234 | </div> | |
235 | <?php endif; ?> | |
236 | <?php endif; ?> | |
237 | <p>To install wallabag, you just have to fill the following fields. That's all.</p> | |
238 | <p>Don't forget to check your server compatibility <a href="wallabag_compatibility_test.php?from=install">here</a>.</p> | |
239 | <form method="post"> | |
240 | <fieldset> | |
241 | <legend><strong>Technical settings</strong></legend> | |
242 | <?php if (!is_dir('vendor')) : ?> | |
243 | <div class='messages notice install'>wallabag needs twig, a template engine (<a href="http://twig.sensiolabs.org/">?</a>). Two ways to install it:<br /> | |
244 | <ul> | |
245 | <li>automatically download and extract vendor.zip into your wallabag folder. | |
246 | <p><input type="submit" name="download" value="Download vendor.zip" /></p> | |
247 | <?php if (!extension_loaded('zip')) : ?> | |
248 | <b>Be careful, zip extension is not enabled in your PHP configuration. You'll have to unzip vendor.zip manually.</b> | |
249 | <?php endif; ?> | |
250 | <em>This method is mainly recommended if you don't have a dedicated server.</em></li> | |
251 | <li>use <a href="http://getcomposer.org/">Composer</a> :<pre><code>curl -s http://getcomposer.org/installer | php | |
252 | php composer.phar install</code></pre></li> | |
253 | </ul> | |
254 | </div> | |
255 | <?php endif; ?> | |
256 | <p> | |
257 | Database engine: | |
258 | <ul> | |
259 | <li><label for="sqlite">SQLite</label> <input name="db_engine" type="radio" checked="" id="sqlite" value="sqlite" /> | |
260 | <div id="pdo_sqlite" class='messages error install'> | |
261 | <p>You have to enable <a href="http://php.net/manual/ref.pdo-sqlite.php">pdo_sqlite extension</a>.</p> | |
262 | </div> | |
263 | </li> | |
264 | <li> | |
265 | <label for="mysql">MySQL</label> <input name="db_engine" type="radio" id="mysql" value="mysql" /> | |
266 | <ul id="mysql_infos"> | |
267 | <li><label for="mysql_server">Server</label> <input type="text" placeholder="localhost" id="mysql_server" name="mysql_server" /></li> | |
268 | <li><label for="mysql_database">Database</label> <input type="text" placeholder="wallabag" id="mysql_database" name="mysql_database" /></li> | |
269 | <li><label for="mysql_user">User</label> <input type="text" placeholder="user" id="mysql_user" name="mysql_user" /></li> | |
270 | <li><label for="mysql_password">Password</label> <input type="text" placeholder="p4ssw0rd" id="mysql_password" name="mysql_password" /></li> | |
271 | </ul> | |
272 | </li> | |
273 | <li> | |
274 | <label for="postgres">PostgreSQL</label> <input name="db_engine" type="radio" id="postgres" value="postgres" /> | |
275 | <ul id="pg_infos"> | |
276 | <li><label for="pg_server">Server</label> <input type="text" placeholder="localhost" id="pg_server" name="pg_server" /></li> | |
277 | <li><label for="pg_database">Database</label> <input type="text" placeholder="wallabag" id="pg_database" name="pg_database" /></li> | |
278 | <li><label for="pg_user">User</label> <input type="text" placeholder="user" id="pg_user" name="pg_user" /></li> | |
279 | <li><label for="pg_password">Password</label> <input type="text" placeholder="p4ssw0rd" id="pg_password" name="pg_password" /></li> | |
280 | </ul> | |
281 | </li> | |
282 | </ul> | |
283 | </p> | |
284 | </fieldset> | |
285 | ||
286 | <fieldset> | |
287 | <legend><strong>User settings</strong></legend> | |
288 | <p> | |
289 | <label for="username">Username</label> | |
290 | <input type="text" required id="username" name="username" value="wallabag" /> | |
291 | </p> | |
292 | <p> | |
293 | <label for="password">Password</label> | |
294 | <input type="password" required id="password" name="password" value="wallabag" /> | |
295 | <label for="show">Show password:</label> <input style="margin-left:-80px;" name="show" id="show" type="checkbox" onchange="document.getElementById('password').type = this.checked ? 'text' : 'password'"> | |
296 | </p> | |
297 | <p> | |
298 | <label for="email">Email (not required)</label> | |
299 | <input type="email" id="email" name="email" /> | |
300 | </p> | |
301 | </fieldset> | |
302 | ||
303 | <input type="submit" id="install_button" value="Install wallabag" name="install" /> | |
304 | </form> | |
305 | </div> | |
306 | <script> | |
307 | $("#mysql_infos").hide(); | |
308 | $("#pg_infos").hide(); | |
309 | ||
310 | <?php | |
311 | if (!extension_loaded('pdo_sqlite')) : ?> | |
312 | $("#install_button").hide(); | |
313 | <?php | |
314 | else : | |
315 | ?> | |
316 | $("#pdo_sqlite").hide(); | |
317 | <?php | |
318 | endif; | |
319 | ?> | |
320 | ||
321 | $("input[name=db_engine]").click(function() | |
322 | { | |
323 | if ( $("#mysql").prop('checked')) { | |
324 | $("#mysql_infos").show(); | |
325 | $("#pg_infos").hide(); | |
326 | $("#pdo_sqlite").hide(); | |
327 | $("#install_button").show(); | |
328 | } | |
329 | else { | |
330 | if ( $("#postgres").prop('checked')) { | |
331 | $("#mysql_infos").hide(); | |
332 | $("#pg_infos").show(); | |
333 | $("#pdo_sqlite").hide(); | |
334 | $("#install_button").show(); | |
335 | } | |
336 | else { | |
337 | $("#mysql_infos").hide(); | |
338 | $("#pg_infos").hide(); | |
339 | <?php | |
340 | if (!extension_loaded('pdo_sqlite')) : ?> | |
341 | $("#pdo_sqlite").show(); | |
342 | $("#install_button").hide(); | |
343 | <?php | |
344 | endif; | |
345 | ?> | |
346 | } | |
347 | } | |
348 | }); | |
349 | </script> | |
350 | </body> | |
351 | </html> |