forked from LeedRSS/Leed
/
install.php
395 lines (371 loc) · 14.2 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
/*
@nom: install
@auteur: Idleman (idleman@idleman.fr)
@description: Page d'installation du script (a supprimer après installation)
*/
require_once('Functions.class.php');
require_once('i18n.php');
global $i18n;
$install_terminee=false;
/* Prend le choix de langue de l'utilisateur, soit :
* - lorsqu'il vient de changer la langue du sélecteur ($lang)
* - lorsqu'il vient de lancer l'installeur ($install_changeLngLeed)
*/
$lang = '';
if (isset($_GET['lang'])) $lang = $_GET['lang'];
elseif (isset($_POST['install_changeLngLeed'])) $lang = $_POST['install_changeLngLeed'];
$installDirectory = dirname(__FILE__).'/install';
if (empty($lang))
$currentLanguage = i18n_init(Functions::getBrowserLanguages(),$installDirectory);
else
$currentLanguage = i18n_init($lang,$installDirectory);
$languageList = $i18n->languages;
if (file_exists('constant.php')) {
die(_t('ALREADY_INSTALLED'));
}
// Cookie de la session
$cookiedir = '';
if(dirname($_SERVER['SCRIPT_NAME'])!='/') $cookiedir=dirname($_SERVER["SCRIPT_NAME"]).'/';
session_set_cookie_params(0, $cookiedir);
session_start();
// Protection des variables
$_ = array_merge($_GET, $_POST);
$whiteList = array(
/* La liste blanche recense les variables ne devant pas être passées via
la sécurisation, mais simplement échappées pour Php. */
'mysqlHost', 'mysqlLogin', 'mysqlMdp', 'mysqlBase', 'mysqlPrefix',
);
foreach($_ as $key=>&$val){
$val = in_array($key, $whiteList)
? str_replace("'", "\'", $val)
: Functions::secure($val);
}
// Valeurs par défaut, remplacées si une autre valeur est saisie.
foreach (array('login','mysqlBase','mysqlHost','mysqlLogin','mysqlMdp','mysqlPrefix','password','root') as $var) {
/* Initalise les variables avec le contenu des champs
* pour rappeler les valeurs déjà saisies. */
if (!empty($_[$var]))
$$var = $_[$var];
else
$$var = '';
}
if (empty($root)) {
// Ne peut être vide, alors on met la valeur par défaut
$root = str_replace(
basename(__FILE__),
'',
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']
);
}
if (!isset($_['mysqlPrefix'])) {
// Le formulaire n'étant pas soumis, on met cette valeur par défaut.
$mysqlPrefix = 'leed__'; // séparation en groupe de tables PhpMyAdmin
}
$lib_errors = _t('ERROR');
$lib_success = _t('SUCCESS');
if(isset($_['installButton'])){
if (empty($_['password']) || empty($_['login'])) {
$test[$lib_errors][] = _t('INSTALL_ERROR_USERPWD');
}
if (!Functions::testDb(
$_['mysqlHost'], $_['mysqlLogin'], $_['mysqlMdp'], $_['mysqlBase']
)) {
$test[$lib_errors][] = _t('INSTALL_ERROR_CONNEXION');
} else {
$test[$lib_success][] = _t('INSTALL_INFO_CONNEXION');
}
}
if(!is_writable('./')){
$test[$lib_errors][]=_t('INSTALL_ERROR_RIGHT', array(str_replace(basename(__FILE__),'',__FILE__)));
}else{
$test[$lib_success][]=_t('INSTALL_INFO_RIGHT');
}
if (!@function_exists('mysqli_connect')){
$test[$lib_errors][] = _t('INSTALL_ERROR_MYSQLICONNECT');
}else{
$test[$lib_success][] = _t('INSTALL_INFO_MYSQLICONNECT');
}
if (!@function_exists('file_get_contents')){
$test[$lib_errors][] = _t('INSTALL_ERROR_FILEGET');
}else{
$test[$lib_success][] = _t('INSTALL_INFO_FILEGET');
}
if (!@function_exists('file_put_contents')){
$test[$lib_errors][] = _t('INSTALL_ERROR_FILEPUT');
}else{
$test[$lib_success][] = _t('INSTALL_INFO_FILEPUT');
}
if (!@function_exists('curl_exec')){
$test[$lib_errors][] = _t('INSTALL_ERROR_CURL');
}else{
$test[$lib_success][] = _t('INSTALL_INFO_CURL');
}
if (@version_compare(PHP_VERSION, '5.1.0') <= 0){
$test[$lib_errors][] = _t('INSTALL_ERROR_PHPV', array(PHP_VERSION));
}else{
$test[$lib_success][] = _t('INSTALL_INFO_PHPV', array(PHP_VERSION));
}
if(ini_get('safe_mode') && ini_get('max_execution_time')!=0){
$test[$lib_errors][] = _t('INSTALL_ERROR_SAFEMODE');
}else{
$test[$lib_success][] = _t('INSTALL_INFO_SAFEMODE');
}
if (isset($_['installButton']) && empty($test[$lib_errors])) { // Pas d'erreur, l'installation peut se faire.
$constant = "<?php
define('VERSION_NUMBER','1.6');
define('VERSION_NAME','Dev');
//Host de Mysql, le plus souvent localhost ou 127.0.0.1
define('MYSQL_HOST','{$mysqlHost}');
//Identifiant MySQL
define('MYSQL_LOGIN','{$mysqlLogin}');
//mot de passe MySQL
define('MYSQL_MDP','{$mysqlMdp}');
//Nom de la base MySQL ou se trouvera leed
define('MYSQL_BDD','{$mysqlBase}');
//Prefix des noms des tables leed pour les bases de données uniques
define('MYSQL_PREFIX','{$mysqlPrefix}');
?>";
file_put_contents('constant.php', $constant);
if (!is_readable('constant.php'))
die('"constant.php" not found!');
require_once('constant.php');
require_once('MysqlEntity.class.php');
class_exists('Update') or require_once('Update.class.php');
Update::ExecutePatch(true);
require_once('Feed.class.php');
require_once('Event.class.php');
require_once('User.class.php');
require_once('Folder.class.php');
require_once('Configuration.class.php');
$cryptographicSalt = User::generateSalt();
$synchronisationCode = substr(sha1(rand(0,30).time().rand(0,30)),0,10);
$root = (substr($_['root'], strlen($_['root'])-1)=='/'?$_['root']:$_['root'].'/');
// DOSSIERS À CONSERVER TELS QUELS, SI DÉJÀ EXISTANTS
$feedManager = new Feed(); $feedManager->create();
$eventManager = new Event(); $eventManager->create();
// COMPTE ADMINISTRATEUR, RÀZ SI NÉCESSAIRE
$userManager = new User();
if ($userManager->tableExists()) {
// Suppose qu'il n'y a qu'un seul utilisateur
$userManager->truncate();
}
$userManager->create();
$admin = new User();
$admin->setLogin($_['login']);
$admin->setPassword($_['password'],$cryptographicSalt);
$admin->save();
$_SESSION['currentUser'] = serialize($admin);
// DOSSIERS DE FLUX, RECRÉE LE DOSSIER GÉNÉRAL SI NÉCESSAIRE
$folderManager = new Folder();
$folderManager->create();
if ($folderManager->rowCount()==0) {
//Création du dossier général
$folder = new Folder();
$folder->setName(_t('GENERAL_FOLDER'));
$folder->setParent(-1);
$folder->setIsopen(1);
$folder->save();
}
// REMET À ZÉRO LA CONFIGURATION
$configurationManager = new Configuration();
if ($configurationManager->tableExists()) {
$configurationManager->truncate();
}
$configurationManager->create();
$configurationManager->add('articleDisplayAnonymous','0');
$configurationManager->add('articleDisplayAuthor','1');
$configurationManager->add('articleDisplayDate','1');
$configurationManager->add('articleDisplayFolderSort','1');
$configurationManager->add('articleDisplayHomeSort','1');
$configurationManager->add('articleDisplayLink','1');
$configurationManager->add('articleDisplayMode','summary');
$configurationManager->add('articlePerPages','5');
$configurationManager->add('cryptographicSalt', $cryptographicSalt);
$configurationManager->add('displayOnlyUnreadFeedFolder','false');
$configurationManager->add('feedMaxEvents','50');
$configurationManager->add('language', $_POST['install_changeLngLeed']);
$configurationManager->add('optionFeedIsVerbose',1);
$configurationManager->add('paginationScale',5);
$configurationManager->add('syncGradCount','10');
$configurationManager->add('synchronisationCode',$synchronisationCode);
$configurationManager->add('synchronisationEnableCache','0');
$configurationManager->add('synchronisationForceFeed','0');
$configurationManager->add('synchronisationType','auto');
$configurationManager->add('theme','marigolds');
$configurationManager->add('root',$root);
$install_terminee=true;
} /* Ci-dessous, on y va si :
- la page est simplement affichée, sans avoir été validée
- le formulaire est soumis, mais l'installation ne peut se faire
*/
?>
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title><?php echo _t('INSTALL_TITLE') ?></title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="templates/marigolds/css/style.css">
<style>
code {
color:#000;
font-size: 1em;
}
.install h1 {
margin-bottom: 1.3em;
}
.install h2 {
margin-bottom: 0.1em;
font-size: 1.5em;
}
.install ul {
margin: 0;
padding: 0;
}
.install li {
list-style: none outside none;
}
.install span {
display: inline-block;
width: 8em;
padding-right: 1em;
}
button#installButton {
margin-top: 1em;
font-size: 2em;
}
.message {
color: #ffffff;
margin-bottom: 2em;
}
.message li {
border:1px solid #212121
}
.messageError {
background-color: #F16529;
}
.messageSuccess {
background-color: #008000;
}
</style>
</head>
<body>
<div class="global-wrapper">
<div id="header-container">
<header class="wrapper clearfix">
<h1 class="logo" id="title"><a href="./index.php">L<i>eed</i></a></h1>
<nav>
</nav>
</header>
</div>
<?php
if ($install_terminee){
echo '<div id="main-container">
<div id="main" class="wrapper clearfix">
<div id="menuBar"></div>
<h1>'._t('INSTALL_TITLE_END').'</h1>
<span>'._t('INSTALL_END').'</span>
<hr>
<button id="installButton" name="installButton" onclick="document.location.href=\'settings.php#preferenceBloc\'">'._t('INSTALL_BTN_END').'</button>
';
// écriture des balises de fin et ne pas faire la suite
echo '</div>
<div id="footer-container">
<footer class="wrapper">
<p>Leed "Light Feed" by <a target="_blank" href="http://blog.idleman.fr">Idleman</a></p>
</footer>
</div>
</body>
</html>';
exit();
}
?>
<div id="main-container">
<div id="main" class="wrapper clearfix">
<div id="menuBar">
<aside>
<h3 class="left"><?php echo _t('INSTALL_PRE_REQUIS') ?></h3>
<ul class="clear" style="margin:0">
<?php
foreach($test as $type=>$messages){
$class = 'message ';
$class .= $lib_errors==$type ? 'messageError':'messageSuccess';
echo "<li class='$class'>$type :\n<ul>";
foreach ($messages as $message){
echo "<li>$message</li>\n";
}
echo "</ul></li>";
}
?>
</ul>
</aside>
</div>
<form action="install.php" method="POST" class="install">
<h1><?php echo _t('INSTALL_TITLE') ?></h1>
<h2><?php echo _t('INSTALL_TAB_GENERAL') ?></h2>
<ul>
<li>
<span><?php echo _t('INSTALL_LANGUAGE') ?></span>
<select name="install_changeLngLeed" onchange="window.location.href='install.php?lang='+this[this.selectedIndex].value">
<?php
foreach($languageList as $lang){
$sel = $lang==$currentLanguage?'selected=selected':'';
echo "<option $sel value='$lang'>$lang</option>";
}
?>
</select>
</li>
<li>
<span><?php echo _t('PROJECT_ROOT') ?></span>
<input type="text" name="root" value="<?php echo $root; ?>">
</li>
</ul>
<h2><?php echo _t('INSTALL_TAB_BDD') ?></h2>
<ul>
<li>
<span><?php echo _t('INSTALL_HOST') ?></span>
<input type="text" name="mysqlHost" value="<?php echo $mysqlHost; ?>" placeholder="<?php echo _t('INSTALL_COMMENT_HOST') ?>">
</li>
<li>
<span><?php echo _t('LOGIN') ?></span>
<input type="text" name="mysqlLogin" value="<?php echo $mysqlLogin; ?>">
</li>
<li>
<span><?php echo _t('PASSWORD') ?></span>
<input type="text" autocomplete="off" name="mysqlMdp" value="<?php echo $mysqlMdp; ?>" placeholder="<?php echo _t('INSTALL_DISPLAY_CLEAR') ?>">
</li>
<li>
<span><?php echo _t('INSTALL_BDD') ?></span>
<input type="text" name="mysqlBase" value="<?php echo $mysqlBase; ?>" placeholder="<?php echo _t('INSTALL_COMMENT_BDD') ?>">
</li>
<li>
<span><?php echo _t('INSTALL_PREFIX_TABLE') ?></span>
<input type="text" name="mysqlPrefix" value="<?php echo $mysqlPrefix; ?>">
</li>
</ul>
<h2><?php echo _t('INSTALL_TAB_ADMIN') ?></h2>
<ul>
<li>
<span><?php echo _t('LOGIN') ?></span>
<input type="text" name="login" value="<?php echo $login; ?>" placeholder="<?php echo _t('LOGIN') ?>">
</li>
<li>
<span><?php echo _t('PASSWORD') ?></span>
<input type="text" autocomplete="off" name="password" value="<?php echo $password; ?>" placeholder="<?php echo _t('INSTALL_DISPLAY_CLEAR') ?>">
</li>
</ul>
<button id="installButton" name="installButton"><?php echo _t('INSTALL_BTN') ?></button>
</form>
</div>
<div id="footer-container">
<footer class="wrapper">
<p>Leed "Light Feed" by <a target="_blank" href="http://blog.idleman.fr">Idleman</a></p>
</footer>
</div>
</body>
</html>