0
+ − 1
<?php
+ − 2
+ − 3
/*
+ − 4
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
166
+ − 5
* Version 1.1.1
0
+ − 6
* upgrade.php - upgrade script
+ − 7
* Copyright (C) 2006-2007 Dan Fuhry
+ − 8
*
+ − 9
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ − 10
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ − 11
*
+ − 12
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ − 13
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ − 14
*/
+ − 15
+ − 16
define('IN_ENANO_INSTALL', 'true');
+ − 17
+ − 18
if(!defined('scriptPath')) {
+ − 19
$sp = dirname($_SERVER['REQUEST_URI']);
+ − 20
if($sp == '/' || $sp == '\\') $sp = '';
+ − 21
define('scriptPath', $sp);
+ − 22
}
+ − 23
+ − 24
if(!defined('contentPath')) {
+ − 25
$sp = dirname($_SERVER['REQUEST_URI']);
+ − 26
if($sp == '/' || $sp == '\\') $sp = '';
+ − 27
define('contentPath', $sp);
+ − 28
}
+ − 29
+ − 30
global $_starttime, $this_page, $sideinfo;
+ − 31
$_starttime = microtime(true);
+ − 32
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 33
// Determine directory (special case for development servers)
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 34
if ( strpos(__FILE__, '/repo/') && file_exists('.enanodev') )
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 35
{
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 36
$filename = str_replace('/repo/', '/', __FILE__);
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 37
}
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 38
else
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 39
{
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 40
$filename = __FILE__;
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 41
}
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 42
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 43
define('ENANO_ROOT', dirname($filename));
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 44
0
+ − 45
require(ENANO_ROOT.'/includes/constants.php');
+ − 46
+ − 47
if(defined('ENANO_DEBUG'))
+ − 48
{
+ − 49
require_once(ENANO_ROOT.'/includes/debugger/debugConsole.php');
+ − 50
}
+ − 51
else
+ − 52
{
+ − 53
function dc_here($m) { return false; }
+ − 54
function dc_dump($a, $g) { return false; }
+ − 55
function dc_watch($n) { return false; }
+ − 56
function dc_start_timer($u) { return false; }
+ − 57
function dc_stop_timer($m) { return false; }
+ − 58
}
+ − 59
+ − 60
// SCRIPT CONFIGURATION
+ − 61
// Everything related to versions goes here!
+ − 62
+ − 63
// Valid versions to upgrade from
177
+ − 64
$valid_versions = Array('1.0b1', '1.0b2', '1.0b3', '1.0b4', '1.0RC1', '1.0RC2', '1.0RC3', '1.0', '1.0.1', '1.0.1.1', '1.0.2b1', '1.0.2', 'Stable1.0ToUnstable1.1');
0
+ − 65
+ − 66
// Basically a list of dependencies, which should be resolved automatically
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 67
// If, for example, upgrading from 1.0b1 to 1.0RC1 requires one extra query that would not
0
+ − 68
// normally be required (for whatever reason) then you would add a custom version number to the array under key '1.0b1'.
+ − 69
$deps_list = Array(
+ − 70
'1.0b1' => Array('1.0b2'),
+ − 71
'1.0b2' => Array('1.0b3'),
+ − 72
'1.0b3' => Array('1.0b4'),
+ − 73
'1.0b4' => Array('1.0RC1'),
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 74
'1.0RC1' => Array('1.0RC2'),
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
diff
changeset
+ − 75
'1.0RC2' => Array('1.0RC3'),
129
0b5244001799
Rebranded as 1.0.1.1; fixed category page drawing bug; updated link to GPL in the about page to the GPLv2
Dan
diff
changeset
+ − 76
'1.0RC3' => Array('1.0'),
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
diff
changeset
+ − 77
'1.0' => Array('1.0.1'),
149
+ − 78
'1.0.1' => Array('1.0.1.1'),
177
+ − 79
'1.0.1.1' => Array('1.0.2b1'),
+ − 80
'1.0.2b1' => Array('Stable1.0ToUnstable1.1'),
+ − 81
'Stable1.0ToUnstable1.1' => Array('1.1.1')
0
+ − 82
);
177
+ − 83
$this_version = '1.1.1';
0
+ − 84
$func_list = Array(
112
+ − 85
'1.0' => Array('u_1_0_1_update_del_votes'),
31
+ − 86
'1.0b4' => Array('u_1_0_RC1_update_user_ids', 'u_1_0_RC1_add_admins_to_group', 'u_1_0_RC1_alter_files_table', 'u_1_0_RC1_destroy_session_cookie', 'u_1_0_RC1_set_contact_email', 'u_1_0_RC1_update_page_text'), // ,
16
+ − 87
// '1.0RC2' => Array('u_1_0_populate_userpage_comments')
31
+ − 88
'1.0RC3' => Array('u_1_0_RC3_make_users_extra')
0
+ − 89
);
+ − 90
+ − 91
if(!isset($_GET['mode']))
+ − 92
{
+ − 93
$_GET['mode'] = 'login';
+ − 94
}
+ − 95
+ − 96
function err($t)
+ − 97
{
+ − 98
global $template;
+ − 99
echo $t;
+ − 100
$template->footer();
+ − 101
exit;
+ − 102
}
+ − 103
+ − 104
require(ENANO_ROOT.'/includes/template.php');
+ − 105
+ − 106
// Initialize the session manager
+ − 107
require(ENANO_ROOT.'/includes/functions.php');
+ − 108
require(ENANO_ROOT.'/includes/dbal.php');
+ − 109
require(ENANO_ROOT.'/includes/paths.php');
+ − 110
require(ENANO_ROOT.'/includes/sessions.php');
+ − 111
require(ENANO_ROOT.'/includes/plugins.php');
+ − 112
require(ENANO_ROOT.'/includes/rijndael.php');
+ − 113
require(ENANO_ROOT.'/includes/render.php');
+ − 114
$db = new mysql();
+ − 115
$db->connect();
+ − 116
+ − 117
$plugins = new pluginLoader();
+ − 118
+ − 119
if(!defined('ENANO_CONFIG_FETCHED'))
+ − 120
{
+ − 121
// Select and fetch the site configuration
+ − 122
$e = $db->sql_query('SELECT config_name, config_value FROM '.table_prefix.'config;');
+ − 123
if ( !$e )
+ − 124
{
+ − 125
$db->_die('Some critical configuration information could not be selected.');
+ − 126
}
+ − 127
else
+ − 128
{
+ − 129
define('ENANO_CONFIG_FETCHED', ''); // Used in die_semicritical to figure out whether to call getConfig() or not
+ − 130
}
+ − 131
+ − 132
$enano_config = Array();
+ − 133
while($r = $db->fetchrow())
+ − 134
{
+ − 135
$enano_config[$r['config_name']] = $r['config_value'];
+ − 136
}
+ − 137
$db->free_result();
+ − 138
}
+ − 139
+ − 140
$v = enano_version();
+ − 141
if(in_array($v, Array(false, '', '1.0b3', '1.0b4')))
+ − 142
{
+ − 143
$ul_admin = 2;
+ − 144
$ul_mod = 1;
+ − 145
$ul_member = 0;
+ − 146
$ul_guest = -1;
+ − 147
}
+ − 148
else
+ − 149
{
+ − 150
$ul_admin = USER_LEVEL_ADMIN;
+ − 151
$ul_mod = USER_LEVEL_MOD;
+ − 152
$ul_member = USER_LEVEL_MEMBER;
+ − 153
$ul_guest = USER_LEVEL_GUEST;
+ − 154
}
+ − 155
+ − 156
$_GET['title'] = 'unset';
+ − 157
+ − 158
$session = new sessionManager();
+ − 159
$paths = new pathManager();
+ − 160
$session->start();
+ − 161
+ − 162
$template = new template_nodb();
+ − 163
$template->load_theme('oxygen', 'bleu', false);
+ − 164
+ − 165
$modestrings = Array(
+ − 166
'login' => 'Administrative login',
+ − 167
'welcome' => 'Welcome',
+ − 168
'setversion' => 'Select Enano version',
+ − 169
'confirm' => 'Confirm upgrade',
+ − 170
'upgrade' => 'Database installation',
+ − 171
'finish' => 'Upgrade complete'
+ − 172
);
+ − 173
+ − 174
$sideinfo = '';
+ − 175
$vars = $template->extract_vars('elements.tpl');
+ − 176
$p = $template->makeParserText($vars['sidebar_button']);
+ − 177
foreach ( $modestrings as $id => $str )
+ − 178
{
+ − 179
if ( $_GET['mode'] == $id )
+ − 180
{
+ − 181
$flags = 'style="font-weight: bold; text-decoration: underline;"';
+ − 182
$this_page = $str;
+ − 183
}
+ − 184
else
+ − 185
{
+ − 186
$flags = '';
+ − 187
}
+ − 188
$p->assign_vars(Array(
+ − 189
'HREF' => '#',
+ − 190
'FLAGS' => $flags . ' onclick="return false;"',
+ − 191
'TEXT' => $str
+ − 192
));
+ − 193
$sideinfo .= $p->run();
+ − 194
}
+ − 195
+ − 196
$template->init_vars();
+ − 197
+ − 198
function upg_assign_vars($schema)
+ − 199
{
+ − 200
$schema = str_replace('{{SITE_NAME}}', mysql_real_escape_string(getConfig('site_name')), $schema);
+ − 201
$schema = str_replace('{{SITE_DESC}}', mysql_real_escape_string(getConfig('site_desc')), $schema);
+ − 202
$schema = str_replace('{{COPYRIGHT}}', mysql_real_escape_string(getConfig('copyright_notice')), $schema);
+ − 203
$schema = str_replace('{{TABLE_PREFIX}}', table_prefix, $schema);
+ − 204
if(getConfig('wiki_mode')=='1') $schema = str_replace('{{WIKI_MODE}}', '1', $schema);
+ − 205
else $schema = str_replace('{{WIKI_MODE}}', '0', $schema);
+ − 206
return $schema;
+ − 207
}
+ − 208
+ − 209
/* Version-specific functions */
+ − 210
+ − 211
function u_1_0_RC1_update_user_ids()
+ − 212
{
+ − 213
global $db;
+ − 214
// First, make sure this hasn't already been done
+ − 215
$q = $db->sql_query('SELECT username FROM '.table_prefix.'users WHERE user_id=1;');
+ − 216
if ( !$q )
+ − 217
$db->_die();
+ − 218
$row = $db->fetchrow();
+ − 219
if ( $row['username'] == 'Anonymous' )
+ − 220
return true;
+ − 221
// Find the first unused user ID
+ − 222
$used = Array();
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
diff
changeset
+ − 223
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users;');
0
+ − 224
if ( !$q )
+ − 225
$db->_die();
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
diff
changeset
+ − 226
$notfirst = false;
0
+ − 227
while ( $row = $db->fetchrow() )
+ − 228
{
+ − 229
$i = intval($row['user_id']);
+ − 230
$used[$i] = true;
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
diff
changeset
+ − 231
if ( !isset($used[$i - 1]) && $notfirst )
0
+ − 232
{
+ − 233
$id = $i - 1;
+ − 234
break;
+ − 235
}
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
diff
changeset
+ − 236
$notfirst = true;
0
+ − 237
}
+ − 238
if ( !isset($id) )
+ − 239
$id = $i + 1;
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
diff
changeset
+ − 240
if ( $id == 0 )
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
diff
changeset
+ − 241
$id = 2;
0
+ − 242
$db->free_result();
+ − 243
+ − 244
$q = $db->sql_query('UPDATE '.table_prefix.'users SET user_id=' . $id . ' WHERE user_id=1;');
+ − 245
if(!$q)
+ − 246
$db->_die();
+ − 247
$q = $db->sql_query('UPDATE '.table_prefix.'users SET user_id=1 WHERE user_id=-1 AND username=\'Anonymous\';');
+ − 248
if(!$q)
+ − 249
$db->_die();
+ − 250
+ − 251
}
+ − 252
+ − 253
function u_1_0_RC1_add_admins_to_group()
+ − 254
{
+ − 255
global $db;
+ − 256
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE user_level=' . USER_LEVEL_ADMIN . ';');
+ − 257
if ( !$q )
+ − 258
$db->_die();
+ − 259
$base = 'INSERT INTO '.table_prefix.'group_members(group_id,user_id) VALUES';
+ − 260
$blocks = Array();
+ − 261
while ( $row = $db->fetchrow($q) )
+ − 262
{
+ − 263
$blocks[] = '(2,' . $row['user_id'] . ')';
+ − 264
}
+ − 265
$blocks = implode(',', $blocks);
+ − 266
$sql = $base . $blocks . ';';
+ − 267
if(!$db->sql_query($sql))
+ − 268
$db->_die();
+ − 269
}
+ − 270
+ − 271
function u_1_0_RC1_alter_files_table()
+ − 272
{
+ − 273
global $db;
+ − 274
if(!is_dir(ENANO_ROOT.'/files'))
+ − 275
@mkdir(ENANO_ROOT . '/files');
+ − 276
if(!is_dir(ENANO_ROOT.'/files'))
+ − 277
die('ERROR: Couldn\'t create files directory');
+ − 278
$q = $db->sql_unbuffered_query('SELECT * FROM '.table_prefix.'files;', $db->_conn);
+ − 279
if(!$q) $db->_die();
+ − 280
while ( $row = $db->fetchrow() )
+ − 281
{
+ − 282
$file_data = base64_decode($row['data']);
+ − 283
$path = ENANO_ROOT . '/files/' . md5( $row['filename'] . '_' . $file_data ) . '_' . $row['time_id'] . $row['file_extension'];
+ − 284
@unlink($path);
+ − 285
$handle = @fopen($path, 'w');
+ − 286
if(!$handle)
+ − 287
die('fopen failed');
+ − 288
fwrite($handle, $file_data);
+ − 289
fclose($handle);
+ − 290
+ − 291
}
+ − 292
+ − 293
$q = $db->sql_query('ALTER TABLE '.table_prefix.'files DROP PRIMARY KEY, ADD COLUMN file_id int(12) NOT NULL auto_increment FIRST, ADD PRIMARY KEY (file_id), ADD COLUMN file_key varchar(32) NOT NULL;');
+ − 294
if(!$q) $db->_die();
+ − 295
+ − 296
$list = Array();
+ − 297
$q = $db->sql_unbuffered_query('SELECT * FROM '.table_prefix.'files;', $db->_conn);
+ − 298
if(!$q) $db->_die();
+ − 299
while ( $row = $db->fetchrow($q) )
+ − 300
{
+ − 301
$file_data = base64_decode($row['data']);
+ − 302
$key = md5( $row['filename'] . '_' . $file_data );
+ − 303
$list[] = 'UPDATE '.table_prefix.'files SET file_key=\'' . $key . '\' WHERE file_id=' . $row['file_id'] . ';';
+ − 304
}
+ − 305
+ − 306
foreach ( $list as $sql )
+ − 307
{
+ − 308
if(!$db->sql_query($sql)) $db->_die();
+ − 309
}
+ − 310
+ − 311
if(!$db->sql_query('ALTER TABLE '.table_prefix.'files DROP data')) $db->_die();
+ − 312
+ − 313
}
+ − 314
+ − 315
function u_1_0_RC1_destroy_session_cookie()
+ − 316
{
+ − 317
unset($_COOKIE['sid']);
+ − 318
setcookie('sid', '', time()-3600*24, scriptPath);
+ − 319
setcookie('sid', '', time()-3600*24, scriptPath.'/');
+ − 320
}
+ − 321
+ − 322
function u_1_0_RC1_set_contact_email()
+ − 323
{
+ − 324
global $db;
+ − 325
$q = $db->sql_query('SELECT email FROM '.table_prefix.'users WHERE user_level='.USER_LEVEL_ADMIN.' ORDER BY user_level ASC LIMIT 1;');
+ − 326
if(!$q)
+ − 327
$db->_die();
+ − 328
$row = $db->fetchrow();
+ − 329
setConfig('contact_email', $row['email']);
+ − 330
}
+ − 331
+ − 332
function u_1_0_RC1_update_page_text()
+ − 333
{
+ − 334
global $db;
+ − 335
$q = $db->sql_unbuffered_query('SELECT page_id,namespace,page_text,char_tag FROM '.table_prefix.'page_text');
+ − 336
if (!$q)
+ − 337
$db->_die();
+ − 338
+ − 339
$qs = array();
+ − 340
+ − 341
while ( $row = $db->fetchrow($q) )
+ − 342
{
+ − 343
$row['page_text'] = str_replace(Array(
+ − 344
"{QUOT:{$row['char_tag']}}",
+ − 345
"{APOS:{$row['char_tag']}}",
+ − 346
"{SLASH:{$row['char_tag']}}"
+ − 347
), Array(
+ − 348
'"', "'", '\\'
+ − 349
), $row['page_text']);
+ − 350
$qs[] = 'UPDATE '.table_prefix.'page_text SET page_text=\'' . mysql_real_escape_string($row['page_text']) . '\'
+ − 351
WHERE page_id=\'' . mysql_real_escape_string($row['page_id']) . '\' AND
+ − 352
namespace=\'' . mysql_real_escape_string($row['namespace']) . '\';';
+ − 353
}
+ − 354
+ − 355
foreach($qs as $query)
+ − 356
{
+ − 357
if(!$db->sql_query($query))
+ − 358
$db->_die();
+ − 359
}
+ − 360
}
+ − 361
112
+ − 362
function u_1_0_1_update_del_votes()
0
+ − 363
{
+ − 364
global $db;
112
+ − 365
$q = $db->sql_query('SELECT urlname, namespace, delvote_ips FROM '.table_prefix.'pages;');
0
+ − 366
if ( !$q )
+ − 367
$db->_die();
+ − 368
112
+ − 369
while ( $row = $db->fetchrow($q) )
0
+ − 370
{
112
+ − 371
$ips = strval($row['delvote_ips']);
+ − 372
if ( is_array( @unserialize($ips) ) )
+ − 373
continue;
+ − 374
$ips = explode('|', $ips);
+ − 375
$new = array(
+ − 376
'ip' => array(),
+ − 377
'u' => array()
+ − 378
);
+ − 379
$i = 0;
+ − 380
$prev = '';
+ − 381
$prev_is_ip = false;
+ − 382
foreach ( $ips as $ip )
+ − 383
{
+ − 384
$i++;
+ − 385
$current_is_ip = is_valid_ip($ip);
+ − 386
if ( $current_is_ip && $prev_is_ip )
+ − 387
{
113
+ − 388
$i++;
112
+ − 389
$new['u'][] = $prev;
+ − 390
}
+ − 391
if ( $current_is_ip )
+ − 392
{
+ − 393
$new['ip'][] = $ip;
+ − 394
}
+ − 395
else
+ − 396
{
+ − 397
$new['u'][] = $ip;
+ − 398
}
+ − 399
$prev = $ip;
+ − 400
$prev_is_ip = $current_is_ip;
+ − 401
}
113
+ − 402
if ( $i % 2 == 1 && $prev_is_ip )
+ − 403
{
+ − 404
$new['u'][] = $ip;
+ − 405
}
112
+ − 406
$new = serialize($new);
+ − 407
$e = $db->sql_query('UPDATE '.table_prefix.'pages SET delvote_ips=\'' . $db->escape($new) . '\' WHERE urlname=\'' . $db->escape($row['urlname']) . '\' AND namespace=\'' . $db->escape($row['namespace']) . '\';');
+ − 408
if ( !$e )
+ − 409
$db->_die();
0
+ − 410
}
112
+ − 411
$db->free_result($q);
0
+ − 412
}
+ − 413
31
+ − 414
function u_1_0_RC3_make_users_extra()
+ − 415
{
+ − 416
global $db;
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
diff
changeset
+ − 417
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE user_id > 0;');
31
+ − 418
if ( !$q )
+ − 419
$db->_die();
+ − 420
+ − 421
$ids = array();
+ − 422
while ( $row = $db->fetchrow() )
+ − 423
{
+ − 424
$ids[] = intval($row['user_id']);
+ − 425
}
+ − 426
+ − 427
$ids = '(' . implode('),(', $ids) . ')';
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
diff
changeset
+ − 428
if ( $ids == '' )
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
diff
changeset
+ − 429
return false;
31
+ − 430
$sql = "INSERT INTO " . table_prefix . "users_extra(user_id) VALUES$ids;";
+ − 431
+ − 432
if ( !$db->sql_query($sql) )
+ − 433
$db->_die();
+ − 434
}
+ − 435
0
+ − 436
switch($_GET['mode'])
+ − 437
{
+ − 438
case "login":
110
+ − 439
if ( $session->user_logged_in && $session->user_level < $ul_admin )
+ − 440
{
+ − 441
$template->header();
+ − 442
echo '<p>Your user account does not have permission to perform an upgrade of Enano. Return to the <a href="index.php">index page</a>.</p>';
+ − 443
$template->footer();
+ − 444
exit;
+ − 445
}
0
+ − 446
if($session->user_logged_in && $session->user_level >= $ul_admin)
+ − 447
{
+ − 448
if(isset($_POST['login']))
+ − 449
{
181
06bdbdfec160
Upgrade UI should work now (upgrades still don't work); do not pull this revision as there is a security hole in the lockout system pending a fix
Dan
diff
changeset
+ − 450
$result = $session->login_without_crypto($_POST['username'], $_POST['password'], false, $ul_admin);
0
+ − 451
if($session->sid_super)
+ − 452
{
+ − 453
header('Location: upgrade.php?mode=welcome&auth='.$session->sid_super);
+ − 454
exit;
+ − 455
}
+ − 456
}
+ − 457
$template->header();
+ − 458
?>
+ − 459
<form action="upgrade.php?mode=login" method="post">
+ − 460
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4">
+ − 461
<tr>
+ − 462
<th colspan="2">You must re-authenticate to perform this upgrade.</th>
+ − 463
</tr>
+ − 464
<?php
+ − 465
if(isset($_POST['login']))
+ − 466
{
181
06bdbdfec160
Upgrade UI should work now (upgrades still don't work); do not pull this revision as there is a security hole in the lockout system pending a fix
Dan
diff
changeset
+ − 467
echo '<tr><td colspan="2"><p style="color: red;">Login failed: '. $result['error'] . '</p></td></tr>';
0
+ − 468
}
+ − 469
?>
+ − 470
<tr>
+ − 471
<td>Username:</td><td><input type="text" name="username" size="30" /></td>
+ − 472
</tr>
+ − 473
<tr>
+ − 474
<td>Password:</td><td><input type="password" name="password" size="30" /></td>
+ − 475
</tr>
+ − 476
<tr>
+ − 477
<td colspan="2" style="text-align: center;"><input type="submit" name="login" value="Log in" />
+ − 478
</tr>
+ − 479
</table>
+ − 480
</form>
+ − 481
<?php
+ − 482
}
+ − 483
else
+ − 484
{
+ − 485
if(isset($_POST['login']))
+ − 486
{
+ − 487
$result = $session->login_without_crypto($_POST['username'], $_POST['password'], false, $ul_member);
+ − 488
if($result == 'success')
+ − 489
{
+ − 490
header('Location: upgrade.php');
+ − 491
exit;
+ − 492
}
+ − 493
}
+ − 494
$template->header();
+ − 495
?>
+ − 496
<form action="upgrade.php?mode=login" method="post">
+ − 497
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4">
+ − 498
<tr>
+ − 499
<th colspan="2">Please log in to continue with this upgrade.</th>
+ − 500
</tr>
+ − 501
<?php
+ − 502
if(isset($_POST['login']))
+ − 503
{
+ − 504
echo '<tr><td colspan="2"><p style="color: red;">Login failed. Bad password?</p></td></tr>';
+ − 505
}
+ − 506
?>
+ − 507
<tr>
+ − 508
<td>Username:</td><td><input type="text" name="username" size="30" /></td>
+ − 509
</tr>
+ − 510
<tr>
+ − 511
<td>Password:</td><td><input type="password" name="password" size="30" /></td>
+ − 512
</tr>
+ − 513
<tr>
+ − 514
<td colspan="2" style="text-align: center;"><input type="submit" name="login" value="Log in" />
+ − 515
</tr>
+ − 516
</table>
+ − 517
</form>
+ − 518
<?php
+ − 519
}
+ − 520
break;
+ − 521
case "welcome":
+ − 522
if(!$session->sid_super) { $template->header(); echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; }
+ − 523
+ − 524
// Just show a simple welcome page to display version information
+ − 525
$template->header();
+ − 526
require('config.php');
+ − 527
+ − 528
?>
+ − 529
+ − 530
<div style="text-align: center; margin-top: 10px;">
+ − 531
<img alt="[ Enano CMS Project logo ]" src="images/enano-artwork/installer-greeting-blue.png" style="display: block; margin: 0 auto; padding-left: 134px;" />
+ − 532
<h2>Welcome to the Enano upgrade wizard</h2>
+ − 533
<?php
+ − 534
if ( file_exists('./_nightly.php') )
+ − 535
{
+ − 536
echo '<div class="warning-box" style="text-align: left; margin: 10px auto; display: table; width: 60%;"><b>You are about to upgrade to a NIGHTLY BUILD of Enano.</b><br />Nightly builds CANNOT be re-upgraded to the final release. They may also contain serious flaws, security problems, or extraneous debugging information. Continuing this process on a production site is NOT recommended.</div>';
+ − 537
}
+ − 538
?>
+ − 539
</div>
+ − 540
<div style="display: table; margin: 0 auto;">
+ − 541
<p>You are about to upgrade Enano to version <b><?php echo $this_version; ?></b>. Before you continue, please ensure that:</p>
+ − 542
<ul>
+ − 543
<li>You have completely backed up your database (<b><?php echo "$dbhost:$dbname"; ?></b>)</li>
+ − 544
<li>You have backed up the entire Enano directory (<b><?php echo ENANO_ROOT; ?></b>)</li>
+ − 545
<li>You have reviewed the release notes for this version, and you<br />are comfortable with any known bugs or issues</li>
91
+ − 546
<li>If you've configured Enano to work using a MySQL user with restricted<br />privileges, you need to enable ALTER, CREATE TABLE, and CREATE INDEX privileges<br />for this upgrade to work.</li>
0
+ − 547
</ul>
+ − 548
</div>
+ − 549
<div style="text-align: center; margin-top: 10px;">
+ − 550
<form action="upgrade.php?mode=setversion&auth=<?php echo $session->sid_super; ?>" method="post">
+ − 551
<input type="submit" value="Continue with upgrade" />
+ − 552
</form>
+ − 553
</div>
+ − 554
+ − 555
<?php
+ − 556
+ − 557
break;
+ − 558
case "setversion":
+ − 559
if(!$session->sid_super) { $template->header(); echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; }
+ − 560
$v = ( function_exists('enano_version') ) ? enano_version() : '';
+ − 561
if(!in_array($v, $valid_versions) && $v != '')
+ − 562
{
+ − 563
$template->header();
+ − 564
?>
+ − 565
<p>Your version of Enano (<?php echo $v; ?>) can't be upgraded to this version (<?php echo $this_version; ?>).</p>
+ − 566
<?php
+ − 567
break;
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 568
}
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 569
else if($v == '')
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 570
{
0
+ − 571
// OK, we don't know which version he's running. So we'll cheat ;-)
+ − 572
$template->header();
+ − 573
echo "<form action='upgrade.php?mode=confirm&auth={$session->sid_super}' method='post'>";
+ − 574
?>
+ − 575
<p>Sorry, we couldn't detect which version of Enano you're running on your server. Please select which version of Enano you have below, and make absolutely sure that you're correct.</p>
+ − 576
<p><select name="version"><?php
+ − 577
foreach($valid_versions as $c)
+ − 578
{
+ − 579
echo "<option value='{$c}'>{$c}</option>";
+ − 580
}
+ − 581
?></select></p>
+ − 582
<p>
+ − 583
<input type="submit" value="Continue" />
+ − 584
</p>
+ − 585
<?php
+ − 586
echo `</form>`;
+ − 587
break;
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 588
}
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 589
else
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 590
{
0
+ − 591
header('Location: upgrade.php?mode=confirm&auth='.$session->sid_super);
+ − 592
}
+ − 593
break;
+ − 594
case "confirm":
+ − 595
$enano_version = ( isset($_POST['version']) ) ? $_POST['version'] : enano_version();
+ − 596
+ − 597
$template->header();
+ − 598
if(!$session->sid_super) { echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; }
+ − 599
?>
+ − 600
<form action="upgrade.php?mode=upgrade&auth=<?php echo $session->sid_super; ?>" method="post">
+ − 601
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4">
+ − 602
<tr>
+ − 603
<td colspan="2"><p><b>Are you sure you want to perform this upgrade?</b></p><p>You can still cancel the upgrade process now. If<br />the upgrade fails, you will need to roll back<br />any actions made using manual SQL queries.</p><p><b>Please clear your browser cache or<br />shift-reload after the upgrade.</b><br />If you fail to do so, some page elements may<br />be broken.</td>
+ − 604
</tr>
+ − 605
<tr>
+ − 606
<td colspan="2" style="text-align: center;">
+ − 607
<input type="hidden" name="enano_version" value="<?php echo $enano_version; ?>" />
+ − 608
<input type="submit" name="doit" value="Upgrade Enano!" />
+ − 609
</td>
+ − 610
</tr>
+ − 611
</table>
+ − 612
</form>
+ − 613
<?php
+ − 614
break;
+ − 615
case "upgrade":
+ − 616
$template->header();
+ − 617
if(!$session->sid_super) { echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; }
+ − 618
if(!isset($_POST['enano_version'])) { echo '<p>Can\'t find the version information on the POST query, are you trying to do this upgrade directly? Please <a href="upgrade.php">restart the upgrade</a>.</p>'; break; }
+ − 619
$enano_version = $_POST['enano_version'];
+ − 620
echo '<p>Preparing for schema execution...';
+ − 621
// Build an array of queries
+ − 622
$schema = file_get_contents('upgrade.sql');
+ − 623
+ − 624
// Strip out and process version blocks
149
+ − 625
preg_match_all('#---BEGIN ([0-9A-z\.\-]*?)---'."\n".'((.*?)'."\n)?".'---END \\1---#is', $schema, $matches);
0
+ − 626
+ − 627
$from_list =& $matches[1];
149
+ − 628
$query_list =& $matches[3];
0
+ − 629
+ − 630
foreach($matches[0] as $m)
+ − 631
{
+ − 632
$schema = str_replace($m, '', $schema);
+ − 633
}
+ − 634
$schema = explode("\n", $schema);
+ − 635
foreach($schema as $k => $q)
+ − 636
{
+ − 637
if(substr($q, 0, 2) == '--' || $q == '')
+ − 638
{
+ − 639
unset($schema[$k]);
+ − 640
//die('<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>');
+ − 641
}
+ − 642
else
+ − 643
{
+ − 644
$schema[$k] = upg_assign_vars($schema[$k]);
+ − 645
}
+ − 646
}
+ − 647
+ − 648
foreach($query_list as $k => $q)
+ − 649
{
+ − 650
$query_list[$k] = explode("\n", $query_list[$k]);
+ − 651
foreach($query_list[$k] as $i => $s)
+ − 652
{
+ − 653
$tq =& $query_list[$k][$i];
+ − 654
if(substr($s, 0, 2) == '--' || $s == '')
+ − 655
{
+ − 656
unset($query_list[$k][$i]);
+ − 657
//die('<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>');
+ − 658
}
+ − 659
else
+ − 660
{
+ − 661
$query_list[$k][$i] = upg_assign_vars($query_list[$k][$i]);
+ − 662
}
+ − 663
}
+ − 664
$query_list[$k] = array_values($query_list[$k]);
+ − 665
}
+ − 666
+ − 667
$assoc_list = Array();
+ − 668
+ − 669
foreach($from_list as $i => $v)
+ − 670
{
+ − 671
$assoc_list[$v] = $query_list[$i];
+ − 672
}
+ − 673
+ − 674
$schema = array_values($schema);
+ − 675
+ − 676
$deps_resolved = false;
+ − 677
$installing_versions = Array($enano_version);
+ − 678
+ − 679
while(true)
+ − 680
{
+ − 681
$v = array_keys($deps_list);
+ − 682
foreach($v as $i => $ver)
+ − 683
{
+ − 684
if(in_array($ver, $installing_versions))
+ − 685
{
+ − 686
// $ver is on the list of versions to be installed. Add its dependencies to the list of versions to install.
+ − 687
foreach($deps_list[$ver] as $dep)
+ − 688
{
+ − 689
if(!in_array($dep, $installing_versions))
+ − 690
{
+ − 691
$installing_versions[] = $dep;
+ − 692
}
+ − 693
}
+ − 694
}
+ − 695
if($i == count($deps_list) - 1)
+ − 696
{
+ − 697
break 2;
+ − 698
}
+ − 699
}
+ − 700
}
+ − 701
+ − 702
foreach($installing_versions as $this_ver)
+ − 703
{
+ − 704
$schema = array_merge($schema, $assoc_list[$this_ver]);
+ − 705
}
+ − 706
+ − 707
// Time for some proper SQL syntax!
+ − 708
// Also check queries for so-called injection attempts to make
+ − 709
// sure that it doesn't fail during the upgrade process and
+ − 710
// leave the user with a half-upgraded database
+ − 711
foreach($schema as $s => $q)
+ − 712
{
+ − 713
if(substr($q, strlen($q)-1, 1) != ';')
+ − 714
{
+ − 715
$schema[$s] .= ';';
+ − 716
}
+ − 717
if ( !$db->check_query($schema[$s]) )
+ − 718
{
+ − 719
// Uh-oh, the check failed, bail out
+ − 720
// The DBAL runs sanity checks on all queries for safety,
+ − 721
// so if the check fails in mid-upgrade we are in deep
+ − 722
// dodo doo-doo.
+ − 723
echo 'Query failed sanity check, this should never happen and is a bug.</p><p>Query was:</p><pre>'.$schema[$s].'</pre>';
+ − 724
break 2;
+ − 725
}
+ − 726
}
+ − 727
+ − 728
$schema = array_values($schema);
+ − 729
+ − 730
// Used extensively for debugging
+ − 731
// echo '<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>';
+ − 732
// break;
+ − 733
+ − 734
echo 'done!<br />Executing upgrade schema...';
+ − 735
+ − 736
// OK, do the loop, baby!!!
+ − 737
foreach($schema as $q)
+ − 738
{
+ − 739
$r = $db->sql_query($q);
+ − 740
if(!$r)
+ − 741
{
+ − 742
echo $db->get_error();
+ − 743
break 2;
+ − 744
}
+ − 745
}
+ − 746
+ − 747
// Call any custom functions
+ − 748
foreach ( $installing_versions as $ver )
+ − 749
{
+ − 750
if ( isset($func_list[$ver]) )
+ − 751
{
+ − 752
foreach($func_list[$ver] as $function)
+ − 753
{
+ − 754
@call_user_func($function);
+ − 755
}
+ − 756
}
+ − 757
}
+ − 758
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 759
// Log the upgrade
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 760
$q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,author,page_text,edit_summary) VALUES(\'security\', \'upgrade_enano\', ' . time() . ', \'' . date('d M Y h:i a') . '\', \'' . mysql_real_escape_string($session->username) . '\', \'' . mysql_real_escape_string($this_version) . '\', \'' . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . '\');');
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 761
0
+ − 762
echo 'done!</p>';
+ − 763
echo '<p>You will be redirected shortly. If you aren\'t redirected, <a href="index.php">click here</a>.</p>
+ − 764
<script type="text/javascript">setTimeout("window.location=\'index.php\'", 2000)</script>';
+ − 765
break;
+ − 766
}
+ − 767
$template->footer();
+ − 768
+ − 769
?>