]>
Commit | Line | Data |
---|---|---|
792097fb | 1 | <?php |
3602405e NL |
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 | ||
792097fb NL |
11 | $errors = array(); |
12 | $successes = array(); | |
1be13ba1 NL |
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 | ||
fecb62a3 | 34 | if (isset($_POST['download'])) { |
fb5a9666 | 35 | if (!file_put_contents("cache/vendor.zip", fopen("http://static.wallabag.org/files/vendor.zip", 'r'))) { |
d967a1fa | 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.'; |
792097fb NL |
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 | } | |
fecb62a3 | 58 | else if (isset($_POST['install'])) { |
792097fb NL |
59 | if (!is_dir('vendor')) { |
60 | $errors[] = 'You must install twig before.'; | |
61 | } | |
62 | else { | |
63 | $continue = true; | |
64 | // Create config.inc.php | |
43c7b978 | 65 | if (!copy('inc/poche/config.inc.default.php', 'inc/poche/config.inc.php')) { |
792097fb NL |
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); | |
1be13ba1 | 97 | $sql_structure = ""; |
792097fb NL |
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 | } | |
feecea28 | 113 | else if ($_POST['db_engine'] == 'postgres') { |
792097fb NL |
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 = executeQuery($handle, $sql_structure, array()); | |
145 | ||
146 | // Create user | |
147 | $handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
148 | ||
149 | $sql = 'INSERT INTO users (username, password, name) VALUES (?, ?, ?)'; | |
150 | $params = array($username, $salted_password, $username); | |
151 | $query = executeQuery($handle, $sql, $params); | |
152 | ||
153 | $id_user = $handle->lastInsertId(); | |
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 | ||
1be13ba1 | 163 | $successes[] = 'wallabag is now installed. You can now <a href="index.php?clean=0">access it !</a>'; |
792097fb NL |
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]--> | |
d967a1fa | 177 | <title>wallabag - installation</title> |
792097fb NL |
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"> | |
d967a1fa | 188 | <script src="themes/default/js/jquery-2.0.3.min.js"></script> |
792097fb NL |
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)) : ?> | |
d09a5674 | 206 | <div class='messages error install'> |
792097fb NL |
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)) : ?> | |
d09a5674 | 219 | <div class='messages success install'> |
792097fb NL |
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> | |
d09a5674 NL |
228 | <?php else : ?> |
229 | <?php if (file_exists('inc/poche/config.inc.php') && is_dir('vendor')) : ?> | |
230 | <div class='messages success install'> | |
231 | <p> | |
1be13ba1 | 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>. |
d09a5674 NL |
233 | </p> |
234 | </div> | |
235 | <?php endif; ?> | |
792097fb NL |
236 | <?php endif; ?> |
237 | <p>To install wallabag, you just have to fill the following fields. That's all.</p> | |
1be13ba1 | 238 | <p>Don't forget to check your server compatibility <a href="wallabag_compatibility_test.php?from=install">here</a>.</p> |
792097fb NL |
239 | <form method="post"> |
240 | <fieldset> | |
241 | <legend><strong>Technical settings</strong></legend> | |
242 | <?php if (!is_dir('vendor')) : ?> | |
1be13ba1 | 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 /> |
792097fb NL |
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> | |
1be13ba1 NL |
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> | |
792097fb NL |
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> | |
feecea28 | 274 | <label for="postgres">PostgreSQL</label> <input name="db_engine" type="radio" id="postgres" value="postgres" /> |
792097fb NL |
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> | |
1be13ba1 | 279 | <li><label for="pg_password">Password</label> <input type="text" placeholder="p4ssw0rd" id="pg_password" name="pg_password" /></li> |
792097fb NL |
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" /> | |
046b9316 | 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'"> |
792097fb NL |
296 | </p> |
297 | <p> | |
046b9316 | 298 | <label for="email">Email (not required)</label> |
299 | <input type="email" id="email" name="email" /> | |
792097fb NL |
300 | </p> |
301 | </fieldset> | |
302 | ||
1be13ba1 | 303 | <input type="submit" id="install_button" value="Install wallabag" name="install" /> |
792097fb NL |
304 | </form> |
305 | </div> | |
306 | <script> | |
307 | $("#mysql_infos").hide(); | |
308 | $("#pg_infos").hide(); | |
1be13ba1 NL |
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 | ||
792097fb NL |
321 | $("input[name=db_engine]").click(function() |
322 | { | |
323 | if ( $("#mysql").prop('checked')) { | |
324 | $("#mysql_infos").show(); | |
325 | $("#pg_infos").hide(); | |
1be13ba1 NL |
326 | $("#pdo_sqlite").hide(); |
327 | $("#install_button").show(); | |
792097fb NL |
328 | } |
329 | else { | |
feecea28 | 330 | if ( $("#postgres").prop('checked')) { |
792097fb NL |
331 | $("#mysql_infos").hide(); |
332 | $("#pg_infos").show(); | |
1be13ba1 NL |
333 | $("#pdo_sqlite").hide(); |
334 | $("#install_button").show(); | |
792097fb NL |
335 | } |
336 | else { | |
337 | $("#mysql_infos").hide(); | |
338 | $("#pg_infos").hide(); | |
1be13ba1 NL |
339 | <?php |
340 | if (!extension_loaded('pdo_sqlite')) : ?> | |
341 | $("#pdo_sqlite").show(); | |
342 | $("#install_button").hide(); | |
343 | <?php | |
344 | endif; | |
345 | ?> | |
792097fb NL |
346 | } |
347 | } | |
348 | }); | |
349 | </script> | |
350 | </body> | |
351 | </html> |