-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patheos_upgrade.php
4483 lines (3816 loc) · 149 KB
/
eos_upgrade.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @name EosAlpha BBS
* @copyright 2011 Alex Vie silvercircle(AT)gmail(DOT)com
*
* This software is a derived product, based on:
*
* Simple Machines Forum (SMF)
* copyright: 2011 Simple Machines (http://www.simplemachines.org)
* license: BSD, See included LICENSE.TXT for terms and conditions.
*
* @version 1.0pre
*/
// Version information...
define('SMF_VERSION', '1.0');
define('SMF_LANG_VERSION', '1.0');
$GLOBALS['required_php_version'] = '5.2.0';
$GLOBALS['required_mysql_version'] = '5.0.50';
$databases = array(
'mysql' => array(
'name' => 'MySQL',
'version' => '4.0.18',
'version_check' => 'return min(mysql_get_server_info(), mysql_get_client_info());',
'utf8_support' => true,
'utf8_version' => '4.1.0',
'utf8_version_check' => 'return mysql_get_server_info();',
'alter_support' => true,
)
);
// General options for the script.
$timeLimitThreshold = 3;
$upgrade_path = dirname(__FILE__);
$upgradeurl = $_SERVER['PHP_SELF'];
// Where the SMF images etc are kept.
// Disable the need for admins to login?
$disable_security = 0;
// How long, in seconds, must admin be inactive to allow someone else to run?
$upcontext['inactive_timeout'] = 10;
// All the steps in detail.
// Number,Name,Function,Progress Weight.
$upcontext['steps'] = array(
0 => array(1, 'Login', 'WelcomeLogin', 2),
1 => array(2, 'Upgrade Options', 'UpgradeOptions', 2),
2 => array(3, 'Backup', 'BackupDatabase', 10),
3 => array(4, 'Database Changes', 'DatabaseChanges', 70),
4 => array(5, 'Delete Upgrade', 'DeleteUpgrade', 1),
);
// Just to remember which one has files in it.
$upcontext['database_step'] = 3;
@set_time_limit(600);
// Clean the upgrade path if this is from the client.
if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
for ($i = 1; $i < $_SERVER['argc']; $i++)
{
if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
}
// Are we from the client?
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
{
$command_line = true;
$disable_security = 1;
}
else
$command_line = false;
// Load this now just because we can.
require_once($upgrade_path . '/Settings.php');
// Are we logged in?
if (isset($upgradeData))
{
$upcontext['user'] = unserialize(base64_decode($upgradeData));
// Check for sensible values.
if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
$upcontext['user']['started'] = time();
if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
$upcontext['user']['updated'] = 0;
$upcontext['started'] = $upcontext['user']['started'];
$upcontext['updated'] = $upcontext['user']['updated'];
}
// Nothing sensible?
if (empty($upcontext['updated']))
{
$upcontext['started'] = time();
$upcontext['updated'] = 0;
$upcontext['user'] = array(
'id' => 0,
'name' => 'Guest',
'pass' => 0,
'started' => $upcontext['started'],
'updated' => $upcontext['updated'],
);
}
// Load up some essential data...
loadEssentialData();
// Are we going to be mimic'ing SSI at this point?
if (isset($_GET['ssi']))
{
require_once($sourcedir . '/lib/Subs.php');
require_once($sourcedir . '/Errors.php');
require_once($sourcedir . '/Load.php');
require_once($sourcedir . '/Security.php');
require_once($sourcedir . '/lib/Subs-Package.php');
loadUserSettings();
loadPermissions();
}
// All the non-SSI stuff.
if (!function_exists('ip2range'))
require_once($sourcedir . '/lib/Subs.php');
if (!function_exists('un_htmlspecialchars'))
{
function un_htmlspecialchars($string)
{
return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)) + array(''' => '\'', ' ' => ' '));
}
}
if (!function_exists('text2words'))
{
function text2words($text)
{
global $smcFunc;
// Step 1: Remove entities/things we don't consider words:
$words = preg_replace('~(?:[\x0B\0\xA0\t\r\s\n(){}\\[\\]<>!@$%^*.,:+=`\~\?/\\\\]+|&(?:amp|lt|gt|quot);)+~', ' ', $text);
// Step 2: Entities we left to letters, where applicable, lowercase.
$words = preg_replace('~([^&\d]|^)[#;]~', '$1 ', un_htmlspecialchars(strtolower($words)));
// Step 3: Ready to split apart and index!
$words = explode(' ', $words);
$returned_words = array();
foreach ($words as $word)
{
$word = trim($word, '-_\'');
if ($word != '')
$returned_words[] = substr($word, 0, 20);
}
return array_unique($returned_words);
}
}
if (!function_exists('clean_cache'))
{
// Empty out the cache folder.
function clean_cache($type = '')
{
global $cachedir, $sourcedir;
// No directory = no game.
if (!is_dir($cachedir))
return;
// Remove the files in SMF's own disk cache, if any
$dh = opendir($cachedir);
while ($file = readdir($dh))
{
if ($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess' && (!$type || substr($file, 0, strlen($type)) == $type))
@unlink($cachedir . '/' . $file);
}
closedir($dh);
// Invalidate cache, to be sure!
// ... as long as Load.php can be modified, anyway.
@touch($sourcedir . '/' . 'Load.php');
clearstatcache();
}
}
// MD5 Encryption.
if (!function_exists('md5_hmac'))
{
function md5_hmac($data, $key)
{
if (strlen($key) > 64)
$key = pack('H*', md5($key));
$key = str_pad($key, 64, chr(0x00));
$k_ipad = $key ^ str_repeat(chr(0x36), 64);
$k_opad = $key ^ str_repeat(chr(0x5c), 64);
return md5($k_opad . pack('H*', md5($k_ipad . $data)));
}
}
// http://www.faqs.org/rfcs/rfc959.html
if (!class_exists('ftp_connection'))
{
class ftp_connection
{
var $connection = 'no_connection', $error = false, $last_message, $pasv = array();
// Create a new FTP connection...
function ftp_connection($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
{
if ($ftp_server !== null)
$this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass);
}
function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]')
{
if (substr($ftp_server, 0, 6) == 'ftp://')
$ftp_server = substr($ftp_server, 6);
elseif (substr($ftp_server, 0, 7) == 'ftps://')
$ftp_server = 'ssl://' . substr($ftp_server, 7);
if (substr($ftp_server, 0, 7) == 'http://')
$ftp_server = substr($ftp_server, 7);
$ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => ''));
// Connect to the FTP server.
$this->connection = @fsockopen($ftp_server, $ftp_port, $err, $err, 5);
if (!$this->connection)
{
$this->error = 'bad_server';
return;
}
// Get the welcome message...
if (!$this->check_response(220))
{
$this->error = 'bad_response';
return;
}
// Send the username, it should ask for a password.
fwrite($this->connection, 'USER ' . $ftp_user . "\r\n");
if (!$this->check_response(331))
{
$this->error = 'bad_username';
return;
}
// Now send the password... and hope it goes okay.
fwrite($this->connection, 'PASS ' . $ftp_pass . "\r\n");
if (!$this->check_response(230))
{
$this->error = 'bad_password';
return;
}
}
function chdir($ftp_path)
{
if (!is_resource($this->connection))
return false;
// No slash on the end, please...
if (substr($ftp_path, -1) == '/' && $ftp_path !== '/')
$ftp_path = substr($ftp_path, 0, -1);
fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n");
if (!$this->check_response(250))
{
$this->error = 'bad_path';
return false;
}
return true;
}
function chmod($ftp_file, $chmod)
{
if (!is_resource($this->connection))
return false;
// Convert the chmod value from octal (0777) to text ("777").
fwrite($this->connection, 'SITE CHMOD ' . decoct($chmod) . ' ' . $ftp_file . "\r\n");
if (!$this->check_response(200))
{
$this->error = 'bad_file';
return false;
}
return true;
}
function unlink($ftp_file)
{
// We are actually connected, right?
if (!is_resource($this->connection))
return false;
// Delete file X.
fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n");
if (!$this->check_response(250))
{
fwrite($this->connection, 'RMD ' . $ftp_file . "\r\n");
// Still no love?
if (!$this->check_response(250))
{
$this->error = 'bad_file';
return false;
}
}
return true;
}
function check_response($desired)
{
// Wait for a response that isn't continued with -, but don't wait too long.
$time = time();
do
$this->last_message = fgets($this->connection, 1024);
while (substr($this->last_message, 3, 1) != ' ' && time() - $time < 5);
// Was the desired response returned?
return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired;
}
function passive()
{
// We can't create a passive data connection without a primary one first being there.
if (!is_resource($this->connection))
return false;
// Request a passive connection - this means, we'll talk to you, you don't talk to us.
@fwrite($this->connection, 'PASV' . "\r\n");
$time = time();
do
$response = fgets($this->connection, 1024);
while (substr($response, 3, 1) != ' ' && time() - $time < 5);
// If it's not 227, we weren't given an IP and port, which means it failed.
if (substr($response, 0, 4) != '227 ')
{
$this->error = 'bad_response';
return false;
}
// Snatch the IP and port information, or die horribly trying...
if (preg_match('~\((\d+),\s*(\d+),\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))\)~', $response, $match) == 0)
{
$this->error = 'bad_response';
return false;
}
// This is pretty simple - store it for later use ;).
$this->pasv = array('ip' => $match[1] . '.' . $match[2] . '.' . $match[3] . '.' . $match[4], 'port' => $match[5] * 256 + $match[6]);
return true;
}
function create_file($ftp_file)
{
// First, we have to be connected... very important.
if (!is_resource($this->connection))
return false;
// I'd like one passive mode, please!
if (!$this->passive())
return false;
// Seems logical enough, so far...
fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n");
// Okay, now we connect to the data port. If it doesn't work out, it's probably "file already exists", etc.
$fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
if (!$fp || !$this->check_response(150))
{
$this->error = 'bad_file';
@fclose($fp);
return false;
}
// This may look strange, but we're just closing it to indicate a zero-byte upload.
fclose($fp);
if (!$this->check_response(226))
{
$this->error = 'bad_response';
return false;
}
return true;
}
function list_dir($ftp_path = '', $search = false)
{
// Are we even connected...?
if (!is_resource($this->connection))
return false;
// Passive... non-agressive...
if (!$this->passive())
return false;
// Get the listing!
fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n");
// Connect, assuming we've got a connection.
$fp = @fsockopen($this->pasv['ip'], $this->pasv['port'], $err, $err, 5);
if (!$fp || !$this->check_response(array(150, 125)))
{
$this->error = 'bad_response';
@fclose($fp);
return false;
}
// Read in the file listing.
$data = '';
while (!feof($fp))
$data .= fread($fp, 4096);
fclose($fp);
// Everything go okay?
if (!$this->check_response(226))
{
$this->error = 'bad_response';
return false;
}
return $data;
}
function locate($file, $listing = null)
{
if ($listing === null)
$listing = $this->list_dir('', true);
$listing = explode("\n", $listing);
@fwrite($this->connection, 'PWD' . "\r\n");
$time = time();
do
$response = fgets($this->connection, 1024);
while (substr($response, 3, 1) != ' ' && time() - $time < 5);
// Check for 257!
if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0)
$current_dir = strtr($match[1], array('""' => '"'));
else
$current_dir = '';
for ($i = 0, $n = count($listing); $i < $n; $i++)
{
if (trim($listing[$i]) == '' && isset($listing[$i + 1]))
{
$current_dir = substr(trim($listing[++$i]), 0, -1);
$i++;
}
// Okay, this file's name is:
$listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]);
if (substr($file, 0, 1) == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1))
return $listing[$i];
if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1))
return $listing[$i];
if (basename($listing[$i]) == $file || $listing[$i] == $file)
return $listing[$i];
}
return false;
}
function create_dir($ftp_dir)
{
// We must be connected to the server to do something.
if (!is_resource($this->connection))
return false;
// Make this new beautiful directory!
fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n");
if (!$this->check_response(257))
{
$this->error = 'bad_file';
return false;
}
return true;
}
function detect_path($filesystem_path, $lookup_file = null)
{
$username = '';
if (isset($_SERVER['DOCUMENT_ROOT']))
{
if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
{
$username = $match[1];
$path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
if (substr($path, -1) == '/')
$path = substr($path, 0, -1);
if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
$path .= dirname($_SERVER['PHP_SELF']);
}
elseif (substr($filesystem_path, 0, 9) == '/var/www/')
$path = substr($filesystem_path, 8);
else
$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
}
else
$path = '';
if (is_resource($this->connection) && $this->list_dir($path) == '')
{
$data = $this->list_dir('', true);
if ($lookup_file === null)
$lookup_file = $_SERVER['PHP_SELF'];
$found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
if ($found_path == false)
$found_path = dirname($this->locate(basename($lookup_file)));
if ($found_path != false)
$path = $found_path;
}
elseif (is_resource($this->connection))
$found_path = true;
return array($username, $path, isset($found_path));
}
function close()
{
// Goodbye!
fwrite($this->connection, 'QUIT' . "\r\n");
fclose($this->connection);
return true;
}
}
}
// Have we got tracking data - if so use it (It will be clean!)
if (isset($_GET['data']))
{
$upcontext['upgrade_status'] = unserialize(base64_decode($_GET['data']));
$upcontext['current_step'] = $upcontext['upgrade_status']['curstep'];
$upcontext['language'] = $upcontext['upgrade_status']['lang'];
$upcontext['rid'] = $upcontext['upgrade_status']['rid'];
$is_debug = $upcontext['upgrade_status']['debug'];
$support_js = $upcontext['upgrade_status']['js'];
// Load the language.
if (file_exists($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php'))
require_once($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php');
}
// Set the defaults.
else
{
$upcontext['current_step'] = 0;
$upcontext['rid'] = mt_rand(0, 5000);
$upcontext['upgrade_status'] = array(
'curstep' => 0,
'lang' => isset($_GET['lang']) ? $_GET['lang'] : basename($language, '.lng'),
'rid' => $upcontext['rid'],
'pass' => 0,
'debug' => 0,
'js' => 0,
);
$upcontext['language'] = $upcontext['upgrade_status']['lang'];
}
// Don't do security check if on Yabbse
if (!isset($modSettings['smfVersion']))
$disable_security = true;
// If this isn't the first stage see whether they are logging in and resuming.
if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
checkLogin();
// This only exists if we're on SMF ;)
if (isset($modSettings['smfVersion']))
{
$request = $smcFunc['db_query']('', '
SELECT variable, value
FROM {db_prefix}themes
WHERE id_theme = {int:id_theme}
AND variable IN ({string:theme_url}, {string:theme_dir}, {string:images_url})',
array(
'id_theme' => 1,
'theme_url' => 'theme_url',
'theme_dir' => 'theme_dir',
'images_url' => 'images_url',
'db_error_skip' => true,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$modSettings[$row['variable']] = $row['value'];
$smcFunc['db_free_result']($request);
}
if (!isset($modSettings['theme_url']))
{
$modSettings['theme_dir'] = $boarddir . '/Themes/default';
$modSettings['theme_url'] = 'Themes/default';
$modSettings['images_url'] = 'Themes/default/images';
}
if (!isset($settings['default_theme_url']))
$settings['default_theme_url'] = $modSettings['theme_url'];
if (!isset($settings['default_theme_dir']))
$settings['default_theme_dir'] = $modSettings['theme_dir'];
$upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
// Default title...
$upcontext['page_title'] = isset($modSettings['smfVersion']) ? 'Updating Your SMF Install!' : 'Upgrading from YaBB SE!';
$upcontext['right_to_left'] = isset($txt['lang_rtl']) ? $txt['lang_rtl'] : false;
if ($command_line)
cmdStep0();
// Don't error if we're using xml.
if (isset($_GET['xml']))
$upcontext['return_error'] = true;
// Loop through all the steps doing each one as required.
$upcontext['overall_percent'] = 0;
foreach ($upcontext['steps'] as $num => $step)
{
if ($num >= $upcontext['current_step'])
{
// The current weight of this step in terms of overall progress.
$upcontext['step_weight'] = $step[3];
// Make sure we reset the skip button.
$upcontext['skip'] = false;
// We cannot proceed if we're not logged in.
if ($num != 0 && !$disable_security && $upcontext['user']['pass'] != $upcontext['upgrade_status']['pass'])
{
$upcontext['steps'][0][2]();
break;
}
// Call the step and if it returns false that means pause!
if (function_exists($step[2]) && $step[2]() === false)
break;
elseif (function_exists($step[2]))
$upcontext['current_step']++;
}
$upcontext['overall_percent'] += $step[3];
}
upgradeExit();
// Exit the upgrade script.
function upgradeExit($fallThrough = false)
{
global $upcontext, $upgradeurl, $boarddir, $command_line;
// Save where we are...
if (!empty($upcontext['current_step']) && !empty($upcontext['user']['id']))
{
$upcontext['user']['step'] = $upcontext['current_step'];
$upcontext['user']['substep'] = $_GET['substep'];
$upcontext['user']['updated'] = time();
$upgradeData = base64_encode(serialize($upcontext['user']));
copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
changeSettings(array('upgradeData' => '"' . $upgradeData . '"'));
}
// Handle the progress of the step, if any.
if (!empty($upcontext['step_progress']) && isset($upcontext['steps'][$upcontext['current_step']]))
{
$upcontext['step_progress'] = round($upcontext['step_progress'], 1);
$upcontext['overall_percent'] += $upcontext['step_progress'] * ($upcontext['steps'][$upcontext['current_step']][3] / 100);
}
$upcontext['overall_percent'] = (int) $upcontext['overall_percent'];
// We usually dump our templates out.
if (!$fallThrough)
{
// This should not happen my dear... HELP ME DEVELOPERS!!
if (!empty($command_line))
{
if (function_exists('debug_print_backtrace'))
debug_print_backtrace();
echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
flush();
die();
}
if (!isset($_GET['xml']))
template_upgrade_above();
else
{
header('Content-Type: text/xml; charset=ISO-8859-1');
// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
$upcontext['get_data'] = array();
foreach ($_GET as $k => $v)
{
if (substr($k, 0, 3) != 'amp' && !in_array($k, array('xml', 'substep', 'lang', 'data', 'step', 'filecount')))
{
$upcontext['get_data'][$k] = $v;
}
}
template_xml_above();
}
// Call the template.
if (isset($upcontext['sub_template']))
{
$upcontext['upgrade_status']['curstep'] = $upcontext['current_step'];
$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(serialize($upcontext['upgrade_status']));
// Custom stuff to pass back?
if (!empty($upcontext['query_string']))
$upcontext['form_url'] .= $upcontext['query_string'];
call_user_func('template_' . $upcontext['sub_template']);
}
// Was there an error?
if (!empty($upcontext['forced_error_message']))
echo $upcontext['forced_error_message'];
// Show the footer.
if (!isset($_GET['xml']))
template_upgrade_below();
else
template_xml_below();
}
// Bang - gone!
die();
}
// Used to direct the user to another location.
function redirectLocation($location, $addForm = true)
{
global $upgradeurl, $upcontext, $command_line;
// Command line users can't be redirected.
if ($command_line)
upgradeExit(true);
// Are we providing the core info?
if ($addForm)
{
$upcontext['upgrade_status']['curstep'] = $upcontext['current_step'];
$location = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(serialize($upcontext['upgrade_status'])) . $location;
}
while (@ob_end_clean());
header('Location: ' . strtr($location, array('&' => '&')));
// Exit - saving status as we go.
upgradeExit(true);
}
// Load all essential data and connect to the DB as this is pre SSI.php
function loadEssentialData()
{
global $db_server, $db_user, $db_passwd, $db_name, $db_connection, $db_prefix, $db_character_set, $db_type;
global $modSettings, $sourcedir, $smcFunc, $upcontext;
// Do the non-SSI stuff...
@set_magic_quotes_runtime(0);
error_reporting(E_ALL);
define('SMF', 1);
// Start the session.
if (@ini_get('session.save_handler') == 'user')
@ini_set('session.save_handler', 'files');
@session_start();
if (empty($smcFunc))
$smcFunc = array();
// Initialize everything...
initialize_inputs();
// Get the database going!
if (empty($db_type))
$db_type = 'mysql';
if (file_exists($sourcedir . '/lib/Subs-Db-' . $db_type . '.php'))
{
require_once($sourcedir . '/lib/Subs-Db-' . $db_type . '.php');
// Make the connection...
$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, array('non_fatal' => true));
// Oh dear god!!
if ($db_connection === null)
die('Unable to connect to database - please check username and password are correct in Settings.php');
if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
$smcFunc['db_query']('', '
SET NAMES ' . $db_character_set,
array(
'db_error_skip' => true,
)
);
// Load the modSettings data...
$request = $smcFunc['db_query']('', '
SELECT variable, value
FROM {db_prefix}settings',
array(
'db_error_skip' => true,
)
);
$modSettings = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$modSettings[$row['variable']] = $row['value'];
$smcFunc['db_free_result']($request);
}
else
{
return throw_error('Cannot find ' . $sourcedir . '/lib/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
}
// If they don't have the file, they're going to get a warning anyway so we won't need to clean request vars.
if (file_exists($sourcedir . '/QueryString.php'))
{
require_once($sourcedir . '/QueryString.php');
EoS_QueryString::cleanRequest();
}
if (!isset($_GET['substep']))
$_GET['substep'] = 0;
}
function initialize_inputs()
{
global $sourcedir, $start_time, $upcontext, $db_type;
$start_time = time();
umask(0);
// Fun. Low PHP version...
if (!isset($_GET))
{
$GLOBALS['_GET']['step'] = 0;
return;
}
ob_start();
// Better to upgrade cleanly and fall apart than to screw everything up if things take too long.
ignore_user_abort(true);
// This is really quite simple; if ?delete is on the URL, delete the upgrader...
if (isset($_GET['delete']))
{
@unlink(__FILE__);
// And the extra little files ;).
@unlink(dirname(__FILE__) . '/upgrade_1-0.sql');
@unlink(dirname(__FILE__) . '/upgrade_1-1.sql');
@unlink(dirname(__FILE__) . '/webinstall.php');
$dh = opendir(dirname(__FILE__));
while ($file = readdir($dh))
{
if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
@unlink(dirname(__FILE__) . '/' . $file);
}
closedir($dh);
header('Location: http://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.gif');
exit;
}
// Are we calling the backup css file?
if (isset($_GET['infile_css']))
{
header('Content-Type: text/css');
template_css();
exit;
}
// Anybody home?
if (!isset($_GET['xml']))
{
$upcontext['remote_files_available'] = false;
$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
if ($test)
$upcontext['remote_files_available'] = true;
@fclose($test);
}
// Something is causing this to happen, and it's annoying. Stop it.
$temp = 'upgrade_php?step';
while (strlen($temp) > 4)
{
if (isset($_GET[$temp]))
unset($_GET[$temp]);
$temp = substr($temp, 1);
}
// Force a step, defaulting to 0.
$_GET['step'] = (int) @$_GET['step'];
$_GET['substep'] = (int) @$_GET['substep'];
}
// Step 0 - Let's welcome them in and ask them to login!
function WelcomeLogin()
{
global $boarddir, $sourcedir, $db_prefix, $language, $modSettings, $cachedir, $upgradeurl, $upcontext, $disable_security;
global $smcFunc, $db_type, $databases, $txt;
$upcontext['sub_template'] = 'welcome_message';
// Check for some key files - one template, one language, and a new and an old source file.
$check = @file_exists($boarddir . '/Themes/default/index.template.php')
&& @file_exists($sourcedir . '/QueryString.php')
&& @file_exists($sourcedir . '/lib/Subs-Db-' . $db_type . '.php')
&& @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
// Need legacy scripts?
if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
if (!$check)
// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
return throw_error('The upgrader was unable to find some crucial files.<br /><br />Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
// Do they meet the install requirements?
if (!php_version_check())
return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br /><br />Please ask your host to upgrade.');
if (!db_version_check())
return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br /><br />Please ask your host to upgrade.');
// Do they have ALTER privileges?
if (!empty($databases[$db_type]['alter_support']) && $smcFunc['db_query']('alter_boards', 'ALTER TABLE {db_prefix}boards ORDER BY id_board', array()) === false)
return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br /><br />Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
// Do a quick version spot check.
$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
if (empty($match[1]) || $match[1] != SMF_VERSION)
return throw_error('The upgrader found some old or outdated files.<br /><br />Please make certain you uploaded the new versions of all the files included in the package.');
// What absolutely needs to be writable?
$writable_files = array(
$boarddir . '/Settings.php',
$boarddir . '/Settings_bak.php',
);
// Check the cache directory.
$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
if (!file_exists($cachedir_temp))
@mkdir($cachedir_temp);
if (!file_exists($cachedir_temp))
return throw_error('The cache directory could not be found.<br /><br />Please make sure you have a directory called "cache" in your forum directory before continuing.');
if (!file_exists($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br />SMF will not work without the primary language files installed.<br /><br />Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
elseif (!isset($_GET['skiplang']))
{
$temp = substr(@implode('', @file($boarddir . '/Themes/default/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br /><br />Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br /> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
}
// This needs to exist!
if (!file_exists($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php'))
return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br /><br />Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br /> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
else
require_once($boarddir . '/Themes/default/languages/Install.' . $upcontext['language'] . '.php');
if (!makeFilesWritable($writable_files))
return false;
// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br /><br />If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br />If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
// Upgrade the agreement.
elseif (isset($modSettings['agreement']))
{
$fp = fopen($boarddir . '/agreement.txt', 'w');
fwrite($fp, $modSettings['agreement']);
fclose($fp);
}
// We're going to check that their board dir setting is right incase they've been moving stuff around.
if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
$upcontext['warning'] = '
It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to "' . $boarddir . '" but should probably be "' . dirname(__FILE__) . '". Settings.php currently lists your paths as:<br />
<ul>