]> git.immae.eu Git - github/wallabag/wallabag.git/blame - install/index.php
[fix] undefined vars in install script
[github/wallabag/wallabag.git] / install / index.php
CommitLineData
792097fb
NL
1<?php
2$errors = array();
3$successes = array();
fecb62a3 4if (isset($_POST['download'])) {
fb5a9666
NL
5 if (!file_put_contents("cache/vendor.zip", fopen("http://static.wallabag.org/files/vendor.zip", 'r'))) {
6 $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
7 }
8 else {
9 if (extension_loaded('zip')) {
10 $zip = new ZipArchive();
11 if ($zip->open("cache/vendor.zip") !== TRUE){
12 $errors[] = 'Impossible to open cache/vendor.zip. Please unzip it manually in your wallabag folder.';
13 }
14 if ($zip->extractTo(realpath(''))) {
15 @unlink("cache/vendor.zip");
16 $successes[] = 'twig is now installed, you can install wallabag.';
17 }
18 else {
19 $errors[] = 'Impossible to extract cache/vendor.zip. Please unzip it manually in your wallabag folder.';
20 }
21 $zip->close();
22 }
23 else {
24 $errors[] = 'zip extension is not enabled in your PHP configuration. Please unzip cache/vendor.zip in your wallabag folder.';
25 }
26 }
27}
fecb62a3 28else if (isset($_POST['install'])) {
792097fb
NL
29 if (!is_dir('vendor')) {
30 $errors[] = 'You must install twig before.';
31 }
32 else {
33 $continue = true;
34 // Create config.inc.php
35 if (!copy('inc/poche/config.inc.php.new', 'inc/poche/config.inc.php')) {
36 $errors[] = 'Installation aborted, impossible to create inc/poche/config.inc.php file. Maybe you don\'t have write access to create it.';
37 $continue = false;
38 }
39 else {
40 function generate_salt() {
41 mt_srand(microtime(true)*100000 + memory_get_usage(true));
42 return md5(uniqid(mt_rand(), true));
43 }
44
45 $content = file_get_contents('inc/poche/config.inc.php');
46 $salt = generate_salt();
47 $content = str_replace("define ('SALT', '');", "define ('SALT', '".$salt."');", $content);
48 file_put_contents('inc/poche/config.inc.php', $content);
49 }
50
51 if ($continue) {
52
53 // User informations
54 $username = trim($_POST['username']);
55 $password = trim($_POST['password']);
56 $salted_password = sha1($password . $username . $salt);
57
58 // Database informations
59 if ($_POST['db_engine'] == 'sqlite') {
60 if (!copy('install/poche.sqlite', 'db/poche.sqlite')) {
61 $errors[] = 'Impossible to create inc/poche/config.inc.php file.';
62 $continue = false;
63 }
64 else {
65 $db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite';
66 $handle = new PDO($db_path);
67 }
68 }
69 else {
70 $content = file_get_contents('inc/poche/config.inc.php');
1d0995bb 71 $sql_structure = '';
792097fb
NL
72
73 if ($_POST['db_engine'] == 'mysql') {
74 $db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database'];
75 $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['mysql_server']."');", $content);
76 $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['mysql_database']."');", $content);
77 $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['mysql_user']."');", $content);
78 $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['mysql_password']."');", $content);
79 $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password']);
80
81 $sql_structure = file_get_contents('install/mysql.sql');
82 }
83 else if ($_POST['db_engine'] == 'postgresql') {
84 $db_path = 'pgsql:host=' . $_POST['pg_server'] . ';dbname=' . $_POST['pg_database'];
85 $content = str_replace("define ('STORAGE_SERVER', 'localhost');", "define ('STORAGE_SERVER', '".$_POST['pg_server']."');", $content);
86 $content = str_replace("define ('STORAGE_DB', 'poche');", "define ('STORAGE_DB', '".$_POST['pg_database']."');", $content);
87 $content = str_replace("define ('STORAGE_USER', 'poche');", "define ('STORAGE_USER', '".$_POST['pg_user']."');", $content);
88 $content = str_replace("define ('STORAGE_PASSWORD', 'poche');", "define ('STORAGE_PASSWORD', '".$_POST['pg_password']."');", $content);
89 $handle = new PDO($db_path, $_POST['pg_user'], $_POST['pg_password']);
90
91 $sql_structure = file_get_contents('install/postgres.sql');
92 }
93
94 $content = str_replace("define ('STORAGE', 'sqlite');", "define ('STORAGE', '".$_POST['db_engine']."');", $content);
95 file_put_contents('inc/poche/config.inc.php', $content);
96 }
97
98 if ($continue) {
99
100 function executeQuery($handle, $sql, $params) {
101 try
102 {
103 $query = $handle->prepare($sql);
104 $query->execute($params);
105 return $query->fetchAll();
106 }
107 catch (Exception $e)
108 {
109 return FALSE;
110 }
111 }
112
113 // create database structure
114 $query = executeQuery($handle, $sql_structure, array());
115
116 // Create user
117 $handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
118
119 $sql = 'INSERT INTO users (username, password, name) VALUES (?, ?, ?)';
120 $params = array($username, $salted_password, $username);
121 $query = executeQuery($handle, $sql, $params);
122
123 $id_user = $handle->lastInsertId();
124
125 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
126 $params = array($id_user, 'pager', '10');
127 $query = executeQuery($handle, $sql, $params);
128
129 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
130 $params = array($id_user, 'language', 'en_EN.UTF8');
131 $query = executeQuery($handle, $sql, $params);
132
1d0995bb 133 $successes[] = 'wallabag is now installed. Don\'t forget to delete install folder. Then, <a href="index.php">reload this page</a>.';
792097fb
NL
134 }
135 }
136 }
137}
138?>
139<!DOCTYPE html>
140<html>
141 <head>
142 <meta name="viewport" content="initial-scale=1.0">
143 <meta charset="utf-8">
144 <!--[if IE]>
145 <meta http-equiv="X-UA-Compatible" content="IE=10">
146 <![endif]-->
147 <title>wallabag — installation</title>
148 <link rel="shortcut icon" type="image/x-icon" href="themes/baggy/img/favicon.ico" />
149 <link rel="apple-touch-icon-precomposed" sizes="144x144" href="themes/baggy/img/apple-touch-icon-144x144-precomposed.png">
150 <link rel="apple-touch-icon-precomposed" sizes="72x72" href="themes/baggy/img/apple-touch-icon-72x72-precomposed.png">
151 <link rel="apple-touch-icon-precomposed" href="themes/baggy/img/apple-touch-icon-precomposed.png">
152 <link href='//fonts.googleapis.com/css?family=PT+Sans:700' rel='stylesheet' type='text/css'>
153 <link rel="stylesheet" href="themes/baggy/css/ratatouille.css" media="all">
154 <link rel="stylesheet" href="themes/baggy/css/font.css" media="all">
155 <link rel="stylesheet" href="themes/baggy/css/main.css" media="all">
156 <link rel="stylesheet" href="themes/baggy/css/messages.css" media="all">
157 <link rel="stylesheet" href="themes/baggy/css/print.css" media="print">
158 <script src="themes/baggy/js/jquery-2.0.3.min.js"></script>
159 <script src="themes/baggy/js/init.js"></script>
160 </head>
161 <body>
162 <header class="w600p center mbm">
163 <h1 class="logo">
164 <img width="100" height="100" src="themes/baggy/img/logo-w.png" alt="logo poche" />
165 </h1>
166 </header>
167 <div id="main">
168 <button id="menu" class="icon icon-menu desktopHide"><span>Menu</span></button>
169 <ul id="links" class="links">
170 <li><a href="http://www.wallabag.org/frequently-asked-questions/">FAQ</a></li>
171 <li><a href="http://doc.wallabag.org/">doc</a></li>
172 <li><a href="http://www.wallabag.org/help/">help</a></li>
173 <li><a href="http://www.wallabag.org/">wallabag.org</a></li>
174 </ul>
175 <?php if (!empty($errors)) : ?>
d09a5674 176 <div class='messages error install'>
792097fb
NL
177 <p>Errors during installation:</p>
178 <p>
179 <ul>
180 <?php foreach($errors as $error) :?>
181 <li><?php echo $error; ?></li>
182 <?php endforeach; ?>
183 </ul>
184 </p>
185 <p><a href="index.php">Please reload</a> this page when you think you resolved these problems.</p>
186 </div>
187 <?php endif; ?>
188 <?php if (!empty($successes)) : ?>
d09a5674 189 <div class='messages success install'>
792097fb
NL
190 <p>
191 <ul>
192 <?php foreach($successes as $success) :?>
193 <li><?php echo $success; ?></li>
194 <?php endforeach; ?>
195 </ul>
196 </p>
197 </div>
d09a5674
NL
198 <?php else : ?>
199 <?php if (file_exists('inc/poche/config.inc.php') && is_dir('vendor')) : ?>
200 <div class='messages success install'>
201 <p>
1d0995bb 202 wallabag seems already installed. If you want to update it, you only have to delete install folder.
d09a5674
NL
203 </p>
204 </div>
205 <?php endif; ?>
792097fb
NL
206 <?php endif; ?>
207 <p>To install wallabag, you just have to fill the following fields. That's all.</p>
1d0995bb 208 <p>Don't forget to check your server compatibility <a href="wallabag_compatibility_test.php">here</a>.</p>
792097fb
NL
209 <form method="post">
210 <fieldset>
211 <legend><strong>Technical settings</strong></legend>
212 <?php if (!is_dir('vendor')) : ?>
1d0995bb 213 <div class='messages notice install'>wallabag needs twig, a template engine (<a href="http://twig.sensiolabs.org/">?</a>). Two ways to install it:
792097fb
NL
214 <ul>
215 <li>automatically download and extract vendor.zip into your wallabag folder.
216 <p><input type="submit" name="download" value="Download vendor.zip" /></p>
217 <?php if (!extension_loaded('zip')) : ?>
218 <b>Be careful, zip extension is not enabled in your PHP configuration. You'll have to unzip vendor.zip manually.</b>
219 <?php endif; ?>
220 <em>This method is mainly recommended if you don't have a dedicated server.</em></li>
221 <li>use <a href="http://getcomposer.org/">Composer</a> :<pre><code>curl -s http://getcomposer.org/installer | php
222php composer.phar install</code></pre></li>
223 </ul>
224 </div>
225 <?php endif; ?>
226 <p>
227 Database engine:
228 <ul>
1d0995bb 229 <li><label for="sqlite">SQLite</label> <input name="db_engine" type="radio" checked="" id="sqlite" value="sqlite" /></li>
792097fb
NL
230 <li>
231 <label for="mysql">MySQL</label> <input name="db_engine" type="radio" id="mysql" value="mysql" />
232 <ul id="mysql_infos">
233 <li><label for="mysql_server">Server</label> <input type="text" placeholder="localhost" id="mysql_server" name="mysql_server" /></li>
234 <li><label for="mysql_database">Database</label> <input type="text" placeholder="wallabag" id="mysql_database" name="mysql_database" /></li>
235 <li><label for="mysql_user">User</label> <input type="text" placeholder="user" id="mysql_user" name="mysql_user" /></li>
236 <li><label for="mysql_password">Password</label> <input type="text" placeholder="p4ssw0rd" id="mysql_password" name="mysql_password" /></li>
237 </ul>
238 </li>
239 <li>
240 <label for="postgresql">PostgreSQL</label> <input name="db_engine" type="radio" id="postgresql" value="postgresql" />
241 <ul id="pg_infos">
242 <li><label for="pg_server">Server</label> <input type="text" placeholder="localhost" id="pg_server" name="pg_server" /></li>
243 <li><label for="pg_database">Database</label> <input type="text" placeholder="wallabag" id="pg_database" name="pg_database" /></li>
244 <li><label for="pg_user">User</label> <input type="text" placeholder="user" id="pg_user" name="pg_user" /></li>
1d0995bb 245 id <li><label for="pg_password">Password</label> <input type="text" placeholder="p4ssw0rd" id="pg_password" name="pg_password" /></li>
792097fb
NL
246 </ul>
247 </li>
248 </ul>
249 </p>
250 </fieldset>
251
252 <fieldset>
253 <legend><strong>User settings</strong></legend>
254 <p>
255 <label for="username">Username</label>
256 <input type="text" required id="username" name="username" value="wallabag" />
257 </p>
258 <p>
259 <label for="password">Password</label>
260 <input type="password" required id="password" name="password" value="wallabag" />
261 </p>
262 <p>
263 <label for="show">Show password:</label> <input name="show" id="show" type="checkbox" onchange="document.getElementById('password').type = this.checked ? 'text' : 'password'">
264 </p>
265 </fieldset>
266
1d0995bb 267 <input type="submit" value="Install wallabag" name="install" />
792097fb
NL
268 </form>
269 </div>
270 <script>
271 $("#mysql_infos").hide();
272 $("#pg_infos").hide();
273 $("input[name=db_engine]").click(function()
274 {
275 if ( $("#mysql").prop('checked')) {
276 $("#mysql_infos").show();
277 $("#pg_infos").hide();
278 }
279 else {
280 if ( $("#postgresql").prop('checked')) {
281 $("#mysql_infos").hide();
282 $("#pg_infos").show();
283 }
284 else {
285 $("#mysql_infos").hide();
286 $("#pg_infos").hide();
287 }
288 }
289 });
290 </script>
291 </body>
292</html>