/
install.php
340 lines (309 loc) · 12.1 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
<?php
/**
* Installation of Lilina
*
* Installation functions including
* @author Ryan McCue <cubegames@gmail.com>
* @package Lilina
* @version 1.0
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/** */
define('LILINA_PATH', dirname(__FILE__));
define('LILINA_INCPATH', LILINA_PATH . '/inc');
define('LILINA_CONTENT_DIR', LILINA_PATH . '/content');
header('Content-Type: text/html; charset=UTF-8');
require_once(LILINA_INCPATH . '/core/misc-functions.php');
require_once(LILINA_INCPATH . '/core/install-functions.php');
require_once(LILINA_INCPATH . '/core/file-functions.php');
require_once(LILINA_INCPATH . '/core/version.php');
lilina_level_playing_field();
if(version_compare('5.2', phpversion(), '>'))
lilina_nice_die('<p>Your server is running PHP version ' . phpversion() . ' but Lilina needs PHP 5.2 or newer</p>');
//Make sure Lilina's not installed
if(lilina_is_installed()) {
if( !lilina_settings_current() ) {
if(isset($_GET['action']) && $_GET['action'] == 'upgrade') {
upgrade();
}
else {
lilina_nice_die('<p>Your installation of Lilina is out of date. Please <a href="install.php?action=upgrade">upgrade your settings</a> first</p>');
}
}
else {
lilina_nice_die('<p>Lilina is already installed. <a href="index.php">Head back to the main page</a></p>');
}
}
global $installer;
$installer = new Installer();
/**
* upgrade() - Run upgrade processes on supplied data
*
* {{@internal Missing Long Description}}}
*/
function upgrade() {
global $lilina;
//require_once(LILINA_INCPATH . '/core/plugin-functions.php');
require_once(LILINA_INCPATH . '/core/feed-functions.php');
require_once(LILINA_INCPATH . '/core/version.php');
require_once(LILINA_INCPATH . '/core/misc-functions.php');
/** Rename possible old files */
if(@file_exists(LILINA_PATH . '/.myfeeds.data'))
rename(LILINA_PATH . '/.myfeeds.data', LILINA_PATH . '/content/system/config/feeds.data');
elseif(@file_exists(LILINA_PATH . '/conf/.myfeeds.data'))
rename(LILINA_PATH . '/conf/.myfeeds.data', LILINA_PATH . '/content/system/config/feeds.data');
elseif(@file_exists(LILINA_PATH . '/conf/.feeds.data'))
rename(LILINA_PATH . '/conf/.feeds.data', LILINA_PATH . '/content/system/config/feeds.data');
elseif(@file_exists(LILINA_PATH . '/conf/feeds.data'))
rename(LILINA_PATH . '/conf/feeds.data', LILINA_PATH . '/content/system/config/feeds.data');
if(@file_exists(LILINA_PATH . '/conf/settings.php'))
rename(LILINA_PATH . '/conf/settings.php', LILINA_PATH . '/content/system/config/settings.php');
require_once(LILINA_PATH . '/inc/core/conf.php');
/*
if(@file_exists(LILINA_PATH . '/content/system/config/feeds.data')) {
$feeds = file_get_contents(LILINA_PATH . '/content/system/config/feeds.data');
$feeds = unserialize( base64_decode($feeds) );
/** Are we pre-versioned? * /
if(!isset($feeds['version'])){
/** Is this 0.7? * /
if(!is_array($feeds['feeds'][0])) {
/** 1 dimensional array, each value is a feed URL string * /
foreach($feeds['feeds'] as $new_feed) {
Feeds::get_instance()->add($new_feed);
}
}
/** We must be in between 0.7 and r147, when we started versioning * /
elseif(!isset($feeds['feeds'][0]['url'])) {
foreach($feeds['feeds'] as $new_feed) {
Feeds::get_instance()->add($new_feed['feed'], $new_feed['name']);
}
}
/** The feeds are up to date, but we don't have a version * /
else {
}
}
elseif($feeds['version'] != $lilina['feed-storage']['version']) {
/** Note the lack of breaks here, this means the cases cascade * /
switch(true) {
case $feeds['version'] < 147:
/** We had a b0rked upgrader, so we need to make sure everything is okay * /
foreach($feeds['feeds'] as $this_feed) {
}
case $feeds['version'] < 237:
/** We moved stuff around this version, but we've handled that above. * /
}
}
else {
}
global $data;
$data = $feeds;
$data['version'] = $lilina['feed-storage']['version'];
save_feeds();
} //end file_exists()
*/
/** Just in case... */
unset($BASEURL);
require(LILINA_PATH . '/content/system/config/settings.php');
if(isset($BASEURL) && !empty($BASEURL)) {
// 0.7 or below
$raw_php = "<?php
// What you want to call your Lilina installation
\$settings['sitename'] = '$SITETITLE';\n
// The URL to your server
\$settings['baseurl'] = '$BASEURL';\n
// Username and password to log into the administration panel\n// 'pass' is MD5ed
\$settings['auth'] = array(
'user' => '$USERNAME',
'pass' => '" . md5($PASSWORD) . "'
);\n
// All the enabled plugins, stored in a serialized string
\$settings['enabled_plugins'] = '';\n
// Version of these settings; don't change this
\$settings['settings_version'] = " . $lilina['settings-storage']['version'] . ";\n?>";
if(!($settings_file = @fopen(LILINA_PATH . '/content/system/config/settings.php', 'w+')) || !is_resource($settings_file)) {
lilina_nice_die('<p>Failed to upgrade settings: Saving content/system/config/settings.php failed</p>', 'Upgrade failed');
}
fputs($settings_file, $raw_php);
fclose($settings_file);
}
elseif(!isset($settings['settings_version'])) {
// Between 0.7 and r147
// Fine to just use existing settings
$raw_php = file_get_contents(LILINA_PATH . '/content/system/config/settings.php');
$raw_php = str_replace('?>', "// Version of these settings; don't change this\n" .
"\$settings['settings_version'] = " . $lilina['settings-storage']['version'] . ";\n?>", $raw_php);
if(!($settings_file = @fopen(LILINA_PATH . '/conf/settings.php', 'w+')) || !is_resource($settings_file)) {
lilina_nice_die('<p>Failed to upgrade settings: Saving content/system/config/settings.php failed</p>', 'Upgrade failed');
}
fputs($settings_file, $raw_php);
fclose($settings_file);
}
elseif($settings['settings_version'] != $lilina['settings-storage']['version']) {
/** Note the lack of breaks here, this means the cases cascade */
switch(true) {
case $settings['settings_version'] < 237:
/** We moved stuff around this version, but we've handled that above. */
case $settings['settings_version'] < 297:
new_options_297();
case $settings['settings_version'] < 302:
new_options_302();
case $settings['settings_version'] < 339:
new_options_339();
case $settings['settings_version'] < 368:
new_options_368();
case $settings['settings_version'] < 480:
new_options_368();
}
$raw_php = file_get_contents(LILINA_PATH . '/content/system/config/settings.php');
$raw_php = str_replace(
"\$settings['settings_version'] = " . $settings['settings_version'] . ";",
"\$settings['settings_version'] = " . $lilina['settings-storage']['version'] . ";",
$raw_php);
if(!($settings_file = @fopen(LILINA_PATH . '/content/system/config/settings.php', 'w+')) || !is_resource($settings_file)) {
lilina_nice_die('<p>Failed to upgrade settings: Saving content/system/config/settings.php failed</p>', 'Upgrade failed');
}
fputs($settings_file, $raw_php);
fclose($settings_file);
require_once(LILINA_INCPATH . '/core/class-datahandler.php');
if(!save_options()) {
lilina_nice_die('<p>Failed to upgrade settings: Saving content/system/config/options.data failed</p>', 'Upgrade failed');
}
}
$string = '';
if(count(MessageHandler::get()) === 0) {
lilina_nice_die('<p>Your installation has been upgraded successfully. Now, <a href="index.php">get back to reading!</a></p>', 'Upgrade Successful');
return;
}
else
$string .= '<p>Your installation has <strong>not</strong> been upgraded successfully. Here\'s the error:</p><ul><li>';
lilina_nice_die($string . implode('</li><li>', MessageHandler::get()) . '</li></ul>', 'Upgrade failed');
}
function default_options() {
global $options;
$options['offset'] = 0;
$options['encoding'] = 'utf-8';
$options['template'] = 'default';
$options['locale'] = 'en';
$options['timezone'] = 'UTC';
$options['sitename'] = 'Lilina News Aggregator';
$options['updateon'] = 'pageview';
$options['feeds_version'] = LILINA_FEEDSTORAGE_VERSION;
}
function new_options_297() {
global $options;
$options['offset'] = 0;
$options['encoding'] = 'utf-8';
if(empty($options['template']))
$options['template'] = 'default';
if(empty($options['locale']))
$options['locale'] = 'en';
}
function new_options_302() {
global $options;
$options['timezone'] = 'UTC';
}
/**
* It appears we missed this at some point
*/
function new_options_339() {
global $options;
if(empty($options['encoding']))
$options['encoding'] = 'utf-8';
}
function new_options_368() {
global $options, $settings;
if(empty($options['sitename'])) {
if(!empty($settings['sitename']))
$options['sitename'] = $settings['sitename'];
else
$options['sitename'] = 'Lilina News Aggregator';
}
}
function new_options_480() {
global $options;
$options['updateon'] = 'pageview';
}
function create_settings_file() {
}
//Initialize variables
if(!empty($_POST['page'])) {
$page = htmlspecialchars($_POST['page']);
}
elseif(!empty($_GET['page'])) {
$page = htmlspecialchars($_GET['page']);
}
else {
$page = false;
}
$from = (isset($_POST['from'])) ? htmlspecialchars($_POST['from']) : false;
$sitename = isset($_POST['sitename']) ? $_POST['sitename'] : false;
$username = isset($_POST['username']) ? $_POST['username'] : false;
$password = isset($_POST['password']) ? $_POST['password'] : false;
$error = ((!$sitename || !$username || !$password) && $page && $page != 1) ? true : false;
if($page === "1" && !isset($_REQUEST['skip']))
$installer->compatibility_test();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Installation - Lilina News Aggregator</title>
<link rel="stylesheet" type="text/css" href="admin/resources/reset.css" />
<link rel="stylesheet" type="text/css" href="install.css" />
</head>
<body>
<div id="content">
<?php
switch($page) {
case 1:
?>
<h1 id="title">Setting Up</h1>
<p>To install, we're going to need some quick details for your site. This includes the title and setting up your administrative user.</p>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
<fieldset id="general">
<h2>General Settings</h2>
<div class="row">
<label for="sitename">Name of site</label>
<input type="text" value="<?php echo (!$sitename) ? 'Lilina News Aggregator' : $sitename;?>" name="sitename" id="sitename" class="input" size="40" />
<p class="sidenote">Give your site something to identify it by. This can be changed later.</p>
</div>
</fieldset>
<fieldset id="security">
<h2>Security Settings</h2>
<div class="row">
<label for="username">Admin Username</label>
<input type="text" value="<?php echo (!$username) ? 'admin' : $username;?>" name="username" id="username" class="input" size="40" />
<p class="sidenote">“admin” probably isn't the best choice, but it'll do.</p>
</div>
<div class="row">
<label for="password">Admin Password</label>
<input type="text" value="<?php echo (!$password) ? generate_password() : $password;?>" name="password" id="password" class="input" size="40" />
<p class="sidenote">Pick something strong and memorable. If you forget this, you might have to reinstall!</p>
</div>
</fieldset>
<input type="hidden" value="2" name="page" id="page" />
<input type="submit" value="Next" class="submit" />
</form>
<?php
break;
case 2:
$installer->install($sitename, $username, $password);
break;
default:
?>
<h1 id="title">Installation</h1>
<p>Welcome to Lilina installation. We're now going to start installing. Make sure that the <code>content/system/</code> directory and all subdirectories are <a href="readme.html#permissions">writable</a>.</p>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
<input type="hidden" name="page" value="1" />
<input type="submit" value="Install" class="submit" />
</form>
<?php
break;
}
?>
</div>
<div id="footer">
<p>Powered by <a href="http://getlilina.org/">Lilina</a> <span class="version"><?php echo LILINA_CORE_VERSION; ?></span>. Read the <a href="http://codex.getlilina.org/">documentation</a> or get help on the <a href="http://getlilina.org/forums/">forums</a></p>
</div>
</body>
</html>