This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.php
1019 lines (877 loc) · 28.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
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
/**
* WoWRoster.net WoWRoster
*
* Roster Installer
*
*
* @copyright 2002-2011 WoWRoster.net
* @license http://www.gnu.org/licenses/gpl.html Licensed under the GNU General Public License v3.
* @package WoWRoster
* @subpackage Install
*/
if( !defined('IN_ROSTER') )
{
exit('Direct access to install.php is not allowed. Please go to index.php to install.');
}
// Get the config file
if( file_exists(ROSTER_BASE . 'conf.php') )
{
include_once (ROSTER_BASE . 'conf.php');
}
/**
* URL path to Roster's directory
* This is needed in template.php
* And since we don't want to include cmslink.lib.php, this will have to do
* Blank should be fine
*/
define('ROSTER_PATH', '');
// ---------------------------------------------------------
// Template Wrap class
// ---------------------------------------------------------
if( !include_once (ROSTER_LIB . 'template.php') )
{
die('Could not include lib/template.php - check to make sure that the file exists!');
}
/**
* Template Parser
* TemplateWrap: Special for the installer
*
* @package WoWRoster
* @subpackage Template
*/
class Template_Wrap extends RosterTemplate
{
var $error_message = array(); // Array of errors @var $error_message
var $install_message = array(); // Array of messages @var $install_message
var $header_inc = false; // Printed header? @var $header_inc
var $tail_inc = false; // Printed footer? @var $tail_inc
function Template_Wrap( )
{
if( !is_dir(ROSTER_TPLDIR . 'install') )
{
trigger_error("'install' theme does not exist", E_USER_ERROR);
}
$this->tpl = 'install';
include_once (ROSTER_LIB . 'cache.php');
$cache = new RosterCache();
$cache->cleanCache();
$this->assign_vars(array(
'MSG_TITLE' => '',
'MSG_TEXT' => '',
'S_SQL' => false,
'U_QUERYCOUNT' => 0
));
//$this->_tpldata['.'][0]['REQUEST_URI'] = str_replace('&', '&', substr(request_uri(),strlen(ROSTER_PATH)));
$this->root = ROSTER_TPLDIR . $this->tpl;
}
function message_die( $text = '' , $title = '' )
{
$this->set_handle('body', 'install_error.html');
$this->install_message = array();
$this->assign_vars(array(
'MSG_TITLE' => ($title != '') ? $title : ' ',
'MSG_TEXT' => ($text != '') ? $text : ' '
));
if( !$this->header_inc )
{
$this->page_header();
}
$this->page_tail();
}
function message_append( $message )
{
$this->install_message[sizeof($this->install_message) + 1] = $message;
}
function message_out( $die = false )
{
sort($this->install_message);
reset($this->install_message);
$install_message = implode('<br /><br />', $this->install_message);
if( $die )
{
$this->install_message = '';
$this->message_die($install_message, 'Installation ' . ((sizeof($this->install_message) == 1) ? 'Note' : 'Notes'));
}
else
{
$this->assign_vars(array(
'MSG_TITLE' => 'Installation ' . ((sizeof($this->install_message) == 1) ? 'Note' : 'Notes'),
'MSG_TEXT' => $install_message
));
}
}
function error_append( $error )
{
$this->error_message[(sizeof($this->error_message) + 1)] = $error;
}
function error_out( $die = false )
{
sort($this->error_message);
reset($this->error_message);
$error_message = implode('<br /><br />', $this->error_message);
if( $die )
{
$this->message_die($error_message, 'Installation ' . ((sizeof($this->error_message) == 1) ? 'Error' : 'Errors'));
}
else
{
$this->assign_vars(array(
'MSG_TITLE' => 'Installation ' . ((sizeof($this->error_message) == 1) ? 'Error' : 'Errors'),
'MSG_TEXT' => $error_message
));
}
}
function page_header( )
{
global $STEP;
$this->header_inc = true;
$this->assign_vars(array(
'INSTALL_STEP' => $STEP,
'TEMPLATE_PATH' => 'templates/install',
'FORMACTION' => 'index.php'
));
$this->set_handle('header', 'install_header.html');
}
function page_tail( )
{
global $DEFAULTS, $db;
$this->assign_var('S_SHOW_BUTTON', true);
if( sizeof($this->install_message) > 0 )
{
$this->message_out(false);
}
if( sizeof($this->error_message) > 0 )
{
$this->assign_var('S_SHOW_BUTTON', false);
$this->error_message[0] = '<span style="font-weight:bold;font-size:14px;" class="negative">NOTICE</span>';
$this->error_out(false);
}
$this->assign_vars(array(
'S_SHOW_DEBUG' => true,
'U_RENDERTIME' => substr(format_microtime() - ROSTER_STARTTIME, 0, 5),
'ROSTER_VERSION' => $DEFAULTS['version']
));
$this->assign_var('NOTICE', '');
/*/ BETA ONLY, COMMENT THIS IN RC OR LATER!
if( file_exists(ROSTER_BASE . 'valid.inc') )
{
$v_content = '';
ob_start();
require (ROSTER_BASE . 'valid.inc');
$v_content = ob_get_clean();
$this->assign_var('NOTICE', $v_content);
}
// END BETA ONLY */
if( is_object($db) )
{
$db->close_db();
}
$this->set_handle('footer', 'install_tail.html');
$this->display('header');
$this->display('body');
$this->display('footer');
exit();
}
function sql_output( $db = NULL )
{
$this->assign_vars(array(
'U_QUERYCOUNT' => is_object($db) ? $db->query_count : 0,
'S_SQL' => is_object($db) ? true : false
));
if( is_object($db) )
{
foreach( $db->queries as $file => $queries )
{
foreach( $queries as $query )
{
$this->assign_block_vars('sql_row', array(
'TIME' => $query['time'],
'TEXT' => nl2br(htmlentities($query['query']))
));
}
}
}
}
}
$STEP = (isset($_POST['install_step']) ? $_POST['install_step'] : '0');
// If Roster is already installed, don't let them install it again
if( defined('ROSTER_INSTALLED') )
{
$tpl = new Template_Wrap();
$tpl->set_handle('body', 'install_error.html');
$tpl->message_die('WoWRoster is already installed - please remove the file <strong>install.php</strong>', 'Installation Error');
}
// View phpinfo() if requested
if( (isset($_GET['mode'])) && ($_GET['mode'] == 'phpinfo') )
{
phpinfo();
exit();
}
// System defaults / available database abstraction layers
$DEFAULTS = array(
'version' => ROSTER_VERSION,
'default_lang' => 'enUS',
'table_prefix' => 'roster_',
'dbal' => 'pdo'
);
$REQUIRE = array(
'php_version' => '5.6.0',
'mysql_version' => '4.1.0'
);
// Database settings
$DBALS = array(
'mysql' => array(
'label' => 'MySQL 4.1.x / 5',
'structure' => 'mysql',
'comments' => 'remove_remarks',
'delim' => ';',
'delim_basic' => ';'
),
'pdo' => array(
'label' => 'MySQL 5 / PHP 5.6+',
'structure' => 'pdo',
'comments' => 'remove_remarks',
'delim' => ';',
'delim_basic' => ';'
)
);
// Set locales
$LOCALES = array(
'English' => array(
'label' => 'English',
'type' => 'enUS'
),
'German' => array(
'label' => 'German',
'type' => 'deDE'
),
'French' => array(
'label' => 'French',
'type' => 'frFR'
),
'Spanish' => array(
'label' => 'Spanish',
'type' => 'esES'
)
);
/**
* Figure out what we're doing...
*/
switch( $STEP )
{
case 0:
process_step0();
break;
case 1:
process_step1();
break;
case 2:
process_step2();
break;
case 3:
process_step3();
break;
case 4:
process_step4();
break;
default:
process_step1();
break;
}
/**
* And do it
*/
function process_step0( )
{
$tpl = new Template_Wrap();
$tpl->set_handle('body', 'install_step0.html');
if( file_exists(ROSTER_BASE . 'license.txt') )
{
if( function_exists('readgzfile') )
{
ob_start();
readgzfile(ROSTER_BASE . 'license.txt');
$content = ob_get_clean();
$content = htmlentities($content);
$content = nl2br($content);
$tpl->assign_var('LICENSE', $content);
}
else
{
$tpl->assign_var('LICENSE', false);
}
}
else
{
$tpl->set_handle('body', 'install_error.html');
$tpl->message_die('You removed the license.txt file<br /><br />This file MUST be present to install WoWRoster!', 'Installation Error');
}
$tpl->page_header();
$tpl->page_tail();
}
function process_step1( )
{
global $DEFAULTS, $REQUIRE;
$tpl = new Template_Wrap();
$tpl->set_handle('body', 'install_step1.html');
/**
* Check to make sure conf.php exists and is readable / writeable
*/
$config_file = ROSTER_BASE . 'conf.php';
$conf_write = 'green';
$conf_tip = 'Write access confirmed';
if( !file_exists($config_file) )
{
if( !@touch($config_file) )
{
$conf_tip = 'The <strong>conf.php</strong> file does not exist and could not be created in WoWRoster\'s root folder.<br />'
. 'You must create an empty conf.php file on your server before proceeding. And give it write access';
$conf_write = 'red';
$tpl->error_append($conf_tip);
}
else
{
$conf_tip = 'The <strong>conf.php</strong> file has been created in WoWRoster\'s root folder<br />'
. 'Deleting this file will interfere with the operation of your WoWRoster installation.';
$conf_write = 'green';
$tpl->message_append($conf_tip);
}
}
else
{
if( (!is_writeable($config_file)) || (!is_readable($config_file)) )
{
if( !@chmod($config_file, 0666) )
{
$conf_tip = 'The file <strong>conf.php</strong> is not set to be readable/writable and could not be changed automatically.<br />'
. 'Please change the permissions to 0666 manually by executing <strong>chmod 0666 conf.php</strong> on your server.';
$conf_write = 'red';
$tpl->error_append($conf_tip);
}
else
{
$conf_tip = '<strong>conf.php</strong> has been set to be readable/writable in order to let this installer '
. 'write your configuration file automatically.';
$conf_write = 'green';
$tpl->message_append($conf_tip);
}
}
// config file exists and is writeable, we're good to go
}
$tpl->assign_block_vars('dir', array(
'CAPTION' => 'Config File',
'NAME' => 'conf.php',
'TIP' => addslashes($conf_tip),
'WRITE' => $conf_write
));
clearstatcache();
/**
* Check to make sure cache exists and is writeable
*/
$cache_write = 'green';
$cache_tip = 'Write access confirmed';
if( !file_exists(ROSTER_CACHEDIR) )
{
if( !@mkdir(ROSTER_CACHEDIR, 0777) )
{
$cache_tip = 'The cache directory could not be created, create a directory named "cache" manually in the root directory.';
$cache_write = 'red';
$tpl->error_append($cache_tip);
}
else
{
$cache_tip = 'A cache directory was created';
$cache_write = 'green';
$tpl->message_append($cache_tip);
}
}
else
{
if( !is_writeable(ROSTER_CACHEDIR) )
{
if( !@chmod(ROSTER_CACHEDIR, 0777) )
{
$cache_tip = 'The cache directory is not set to be writable and could not be changed automatically.<br />'
. 'Please change the permissions to 0777 manually by executing <strong>chmod 0777 cache</strong> on your server.';
$cache_write = 'red';
$tpl->error_append($cache_tip);
}
else
{
$cache_tip = 'The cache directory has been set to be writable.';
$cache_write = 'green';
$tpl->message_append($cache_tip . '<br />Write access confirmed');
}
}
// Cache directory exists and is writeable, we're good to go
}
$tpl->assign_block_vars('dir', array(
'CAPTION' => 'Cache Directory',
'NAME' => 'cache',
'TIP' => addslashes($cache_tip),
'WRITE' => $cache_write
));
clearstatcache();
/**
* WoWRoster versions
*/
$our_roster_version = $DEFAULTS['version'];
$their_roster_version = 'Unknown';
$their_roster_updated = 'Unknown';
$location = str_replace('http://www.wowroster.net', '', ROSTER_UPDATECHECK);
$sh = @fsockopen('wowroster.net', 80, $errno, $error, 5);
if( !$sh )
{
$their_roster_version = 'Connection to wowroster.net failed.';
}
else
{
@fputs($sh, "GET $location HTTP/1.1\r\nHost: wowroster.net\r\nConnection: close\r\n\r\n");
while( !@feof($sh) )
{
$content = @fgets($sh, 512);
if( preg_match('#<version>(.+)</version>#i', $content, $version) )
{
$their_roster_version = $version[1];
break;
}
if( preg_match('#<updated>(.+)</updated>#i', $content, $updated) )
{
$their_roster_updated = date('D M jS, g:ia', $updated[1]);
break;
}
}
}
@fclose($sh);
// WoWRoster Versions
$our_roster_version = ((version_compare($our_roster_version, $their_roster_version, '>=')) ? '<span class="positive">' : '<span class="negative">') . $our_roster_version . '</span>';
// PHP Versions
$our_php_version = ((phpversion() >= $REQUIRE['php_version']) ? '<span class="positive">' : '<span class="negative">') . phpversion() . '</span>';
$their_php_version = $REQUIRE['php_version'] . ' +';
// Modules
$our_mysql = ( (extension_loaded('mysql')) ? '<span class="positive">Yes</span>' : ( (extension_loaded('pdo_mysql')) ? '<span class="positive">Yes</span>' : '<span class="negative">No</span>' ) );
// Required?
$their_mysql = $REQUIRE['mysql_version'] . '+';
$our_gd = (function_exists('imageTTFBBox') && function_exists('imageTTFText') && function_exists('imagecreatetruecolor')) ? '<span class="positive">Yes</span>' : '<span class="negative">No</span>';
// Required?
$their_gd = 'Optional';
// CURL check
$our_curl = in_array('curl', get_loaded_extensions()) ? '<span class="positive">Yes</span>' : '<span class="negative">No</span>';
$their_curl = 'Required for Blizzard API';
$ismyswl = false;
if (extension_loaded('mysql')){$ismyswl = true;}
if (extension_loaded('mysqli')){$ismyswl = true;}
if (extension_loaded('pdo_mysql')){$ismyswl = true;}
if( (phpversion() < $REQUIRE['php_version']) || !$ismyswl)
{
$tpl->error_append('<span style="font-weight:bold;font-size:14px;">Sorry, your server does not meet the minimum requirements for WoWRoster</span>');
}
else
{
$tpl->message_append('WoWRoster has scanned your server and determined that it meets the minimum requirements.');
$tpl->assign_var('S_SHOW_BUTTON', true);
}
/**
* Output the page
*/
$tpl->assign_vars(array(
'OUR_ROSTER_VERSION' => $our_roster_version,
'THEIR_ROSTER_VERSION' => $their_roster_version,
'THEIR_ROSTER_UPDATED' => $their_roster_updated,
'OUR_PHP_VERSION' => $our_php_version,
'THEIR_PHP_VERSION' => $their_php_version,
'OUR_MYSQL' => $our_mysql,
'THEIR_MYSQL' => $their_mysql,
'OUR_GD' => $our_gd,
'THEIR_GD' => $their_gd,
'OUR_CURL' => $our_curl,
'THEIR_CURL' => $their_curl
));
$tpl->page_header();
$tpl->page_tail();
}
function process_step2( )
{
global $DEFAULTS, $DBALS, $LOCALES;
$tpl = new Template_Wrap();
$tpl->set_handle('body', 'install_step2.html');
/**
* Build the default language drop-down
*/
foreach( $LOCALES as $locale_type => $locale_desc )
{
if( file_exists(ROSTER_BASE . 'localization' . DIR_SEP . $locale_desc['type'] . '.php') )
{
$tpl->assign_block_vars('locale_row', array(
'VALUE' => $locale_desc['type'],
'OPTION' => $locale_type
));
}
}
/**
* Build the database drop-down
*/
foreach( $DBALS as $db_type => $db_options )
{
$tpl->assign_block_vars('dbal_row', array(
'VALUE' => $db_type,
'OPTION' => $db_options['label']
));
}
/**
* Determine server settings
*/
if( !empty($_SERVER['SERVER_NAME']) || !empty($_ENV['SERVER_NAME']) )
{
$server_name = 'http://' . ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $_ENV['SERVER_NAME']);
}
elseif( !empty($_SERVER['HTTP_HOST']) || !empty($_ENV['HTTP_HOST']) )
{
$server_name = 'http://' . ((!empty($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST']);
}
else
{
$server_name = '';
}
$tpl->message_append('Before proceeding, please verify that the database name you provided is already created<br />and that the user you provided has permission to create tables in that database');
/**
* Output the page
*/
$tpl->assign_vars(array(
'DB_HOST' => 'localhost',
'TABLE_PREFIX' => $DEFAULTS['table_prefix'],
'SERVER_NAME' => $server_name
));
$tpl->page_header();
$tpl->page_tail();
}
function process_step3( )
{
global $DEFAULTS, $DBALS, $LOCALES, $REQUIRE;
$tpl = new Template_Wrap();
$tpl->set_handle('body', 'install_step3.html');
/**
* Get our posted data
*/
$db_config['dbtype'] = post_or_db('dbtype');
$db_config['host'] = post_or_db('dbhost');
$db_config['database'] = post_or_db('dbname');
$db_config['username'] = post_or_db('dbuser');
$db_config['password'] = post_or_db('dbpass');
$db_config['table_prefix'] = post_or_db('table_prefix', $DEFAULTS);
$default_locale = post_or_db('default_lang', $DEFAULTS);
$server_name = post_or_db('server_name');
$create['username'] = post_or_db('dbuser_c');
$create['password'] = post_or_db('dbpass_c');
define('ROSTER_DB_DIR', ROSTER_LIB . 'dbal' . DIR_SEP);
$dbal_file = ROSTER_DB_DIR . $db_config['dbtype'] . '.php';
if( !file_exists($dbal_file) )
{
$tpl->message_die('Unable to find the database abstraction layer for <strong>' . $db_config['dbtype'] . '</strong>, check to make sure ' . $dbal_file . ' exists.');
}
/**
* Database population
*/
include_once ($dbal_file);
// Hey, looks like we are making the database, YAY!
if( $create['username'] != '' && $create['password'] != '' )
{
include_once ($dbal_file);
$db = new roster_db($db_config['host'], '', $create['username'], $create['password']);
$db->query("CREATE DATABASE IF NOT EXISTS `" . $db_config['database'] . "`;");
unset($db, $create);
}
// Try to connect
$db = new roster_db($db_config['host'], $db_config['database'], $db_config['username'], $db_config['password'], $db_config['table_prefix']);
$db->log_level();
$db->error_die();
// Check to make sure a connection was made
if( !is_resource($db->link_id) && !$db->connection)
{
// Attempt to
$tpl->message_die('Failed to connect to database <strong>' . $db_config['database'] . '</strong> as <strong>' . $db_config['username'] . '@' . $db_config['host'] . '</strong><br />' . $db->this_error . ' - '.$db->connect_error().' - '.$db->error().'<br /><br />' . '<form method="post" action="index.php" name="post"><input type="hidden" name="install_step" value="2" /><div align="center"><input type="submit" name="submit" value="Try Again" /></div></form>');
}
$db_structure_file = ROSTER_DB_DIR . 'structure' . DIR_SEP . $db_config['dbtype'] . '_structure.sql';
$db_data_file = ROSTER_DB_DIR . 'structure' . DIR_SEP . $db_config['dbtype'] . '_data.sql';
$remove_remarks_function = $DBALS[$db_config['dbtype']]['comments'];
// I require MySQL version 4.1.0 minimum.
$server_version = $db->server_info();
$client_version = $db->client_info();
if( (isset($server_version) && isset($client_version)) )
{
$tpl->message_append('MySQL server version ' . $REQUIRE['mysql_version'] . ' or higher is required for WoWRoster.<br /><br />
<strong>You are running:</strong>
<ul>
<li><strong>Your server version: ' . $server_version . '</strong></li>
<li><strong>Your client version: ' . $client_version . '</strong></li>
</ul>
Your server meets the MySQL requirements for WoWRoster.');
if( version_compare($server_version, $REQUIRE['mysql_version'], '<') )
{
$tpl->message_die('MySQL server version ' . $REQUIRE['mysql_version'] . ' or higher is required for WoWRoster.<br /><br />
<strong>You are running:</strong>
<ul>
<li><strong>Your server version: ' . $server_version . '</strong></li>
<li><strong>Your client version: ' . $client_version . '</strong></li>
</ul>
We are sorry, your MySQL server version is not high enough to install WoWRoster, please upgrade MySQL.');
}
}
else
{
$tpl->message_die('Failed to get version information for database <strong>' . $db_config['database'] . '</strong> as <strong>' . $db_config['username'] . '@' . $db_config['host'] . '</strong><br />'
. $db->connect_error() . '<br /><br />'
. '<form method="post" action="index.php" name="post"><input type="hidden" name="install_step" value="2" /><div align="center"><input type="submit" name="submit" value="Try Again" /></div></form>');
}
// Parse structure file and create database tables
$sql = @fread(@fopen($db_structure_file, 'r'), @filesize($db_structure_file));
$sql = preg_replace('#renprefix\_(\S+?)([\s\.,]|$)#', $db_config['table_prefix'] . '\\1\\2', $sql);
$sql = $remove_remarks_function($sql);
$sql = parse_sql($sql, $DBALS[$db_config['dbtype']]['delim']);
$sql_count = count($sql);
$i = 0;
while( $i < $sql_count )
{
if( isset($sql[$i]) && $sql[$i] != '' )
{
if( !($db->query($sql[$i])) )
{
$tpl->message_die('Error in SQL query<br />'
. $sql[$i] . '<br />'
. 'Error: ' . $db->error() . '<br />'
. '<a href="index.php">Restart Installation</a>');
}
}
$i++;
}
unset($sql);
// Parse the data file and populate the database tables
$sql = @fread(@fopen($db_data_file, 'r'), @filesize($db_data_file));
$sql = preg_replace('#renprefix\_(\S+?)([\s\.,]|$)#', $db_config['table_prefix'] . '\\1\\2', $sql);
$sql = $remove_remarks_function($sql);
$sql = parse_sql($sql, $DBALS[$db_config['dbtype']]['delim']);
$sql_count = count($sql);
$i = 0;
while( $i < $sql_count )
{
if( isset($sql[$i]) && $sql[$i] != '' )
{
if( !($db->query($sql[$i])) )
{
$tpl->message_die('Error in SQL query<br />'
. $sql[$i] . '<br />'
. 'Error: ' . $db->error() . '<br />'
. '<a href="index.php">Restart Installation</a>');
}
}
$i++;
}
unset($sql);
/**
* Update some config settings
*/
$db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '$default_locale' WHERE `config_name` = 'locale';");
$db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '" . ROSTER_VERSION . "' WHERE `config_name` = 'version';");
$db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '$server_name' WHERE `config_name` = 'website_address';");
/**
* Write the config file
*/
$config_file = "<?php\n";
$config_file .= "/**\n * AUTO-GENERATED CONF FILE\n * DO NOT EDIT !!!\n */\n\n";
$config_file .= "\$db_config['host'] = " . var_export($db_config['host'], true) . ";\n";
$config_file .= "\$db_config['username'] = " . var_export($db_config['username'], true) . ";\n";
$config_file .= "\$db_config['password'] = " . var_export($db_config['password'], true) . ";\n";
$config_file .= "\$db_config['database'] = " . var_export($db_config['database'], true) . ";\n";
$config_file .= "\$db_config['table_prefix'] = " . var_export($db_config['table_prefix'], true) . ";\n";
$config_file .= "\$db_config['dbtype'] = " . var_export($db_config['dbtype'], true) . ";\n";
// Set our permissions to execute-only
@umask(0111);
if( !$fp = @fopen('conf.php', 'w') )
{
$error_message = 'The <strong>conf.php</strong> file couldn\'t be opened for writing. Paste the following in to conf.php and save the file to continue:<br /><pre>' . htmlspecialchars($config_file) . '</pre>';
$tpl->error_append($error_message);
}
else
{
@fputs($fp, $config_file);
@fclose($fp);
$tpl->message_append('Your configuration file has been written with the initial values<br />But installation will not be complete until you create an administrator account in this step');
}
/**
* Output the page
*/
$tpl->sql_output($db);
$tpl->page_header();
$tpl->page_tail();
}
function process_step4( )
{
global $DEFAULTS;
$tpl = new Template_Wrap();
$tpl->set_handle('body', 'install_step4.html');
/**
* Get our posted data
*/
$user_password1 = post_or_db('user_password1');
$user_password2 = post_or_db('user_password2');
/**
* Update admin account
*/
include (ROSTER_BASE . 'conf.php');
define('ROSTER_DB_DIR', ROSTER_LIB . 'dbal' . DIR_SEP);
switch( $db_config['dbtype'] )
{
case 'mysql':
include_once (ROSTER_DB_DIR . 'mysql.php');
break;
case 'PDO':
include_once (ROSTER_DB_DIR . 'pdo.php');
break;
default:
include_once (ROSTER_DB_DIR . 'mysql.php');
break;
}
$db = new roster_db($db_config['host'], $db_config['database'], $db_config['username'], $db_config['password'], $db_config['table_prefix']);
$db->log_level();
$db->error_die();
if( !is_resource($db->link_id) )
{
$tpl->message_die('Failed to connect to database <strong>' . $db_config['database'] . '</strong> as <strong>' . $db_config['username'] . '@' . $db_config['host'] . '</strong><br /><br /><a href="index.php">Restart Installation</a>');
}
/**
* Insert account data. This isn't in the data sql file because we don't
* want to include it in a settings reset
*/
if( $user_password1 == '' || $user_password2 == '' )
{
$pass_word = md5('admin');
}
elseif( $user_password1 == $user_password2 )
{
$pass_word = md5($user_password1);
}
else
{
$pass_word = md5('admin');
}
$db->query("INSERT INTO `" . $db->table('user_members') . "` (`usr`) VALUES ('Admin');");
$db->query("UPDATE `" . $db->table('user_members') . "` SET `pass` = '" . $pass_word . "',`access` = '11:0:1:2',`active`='1',`user_permissions` = '{\"id\":\"1\",\"roster_cp\":\"1\",\"gp_update\":\"1\",\"cp_update\":\"1\",\"lua_update\":\"1\"}' WHERE `usr` = 'Admin';");
$tpl->message_append('The WoWRoster Admin account has created<br />Please do not forget your password');
/**
* Rewrite the config file to its final form
*/
$config_file = file(ROSTER_BASE . 'conf.php');
$config_file[] = "\ndefine('ROSTER_INSTALLED', true);";
$config_file = implode('', $config_file);
// Set our permissions to execute-only
@umask(0111);
if( !$fp = @fopen('conf.php', 'w') )
{
$error_message = 'The <strong>conf.php</strong> file couldn\'t be opened for writing.<br />Paste the following in to conf.php and save the file to continue:<br /><pre>' . htmlspecialchars($config_file) . '</pre>';
$tpl->error_append($error_message);
}
else
{
@fwrite($fp, $config_file, strlen($config_file));
@fclose($fp);
}
/**
* Print out the login form
*/
if( ($user_password1 != $user_password2) || $user_password1 == '' || $user_password2 == '' )
{
$tpl->message_append('<span style="font-weight:bold;font-size:14px;" class="negative">NOTICE</span><br /><br />Your passwords did not match, so it has been reset to <strong>admin</strong><br />You can change it by logging in and going to your account settings.');
}
$tpl->message_append('Your administrator account has been created, log in to be taken to the WoWRoster configuration page.');
$tpl->sql_output($db);
$tpl->page_header();
$tpl->page_tail();
}
// ---------------------------------------------------------
// Functions!
// ---------------------------------------------------------
/**
* Checks if a POST field value exists;
* If it does, we use that one, otherwise we use the optional database field value,
* or return a null string if $db_row contains no data
*
* @param string $post_field POST field name
* @param array $db_row Array of DB values
* @param string $db_field DB field name
* @return string
*/
function post_or_db( $post_field , $db_row = array() , $db_field = '' )
{
if( @sizeof($db_row) > 0 )
{
if( $db_field == '' )
{
$db_field = $post_field;
}
$db_value = $db_row[$db_field];
}
else
{
$db_value = '';
}
return (isset($_POST[$post_field]) || !empty($_POST[$post_field])) ? $_POST[$post_field] : $db_value;
}
/**
* Removes comments from a SQL data file
*
* @param string $sql SQL file contents
* @return string
*/
function remove_remarks( $sql )
{
if( $sql == '' )
{
die('Could not obtain SQL structure/data');
}
$retval = '';
$lines = explode("\n", $sql);
unset($sql);
foreach( $lines as $line )
{
// Only parse this line if there's something on it, and we're not on the last line
if( strlen($line) > 0 )
{
// If '#' is the first character, strip the line
$retval .= (substr($line, 0, 1) != '#') ? $line . "\n" : "\n";
}
}
unset($lines, $line);
return $retval;
}
/**
* Parse multi-line SQL statements into a single line
*
* @param string $sql SQL file contents
* @param char $delim End-of-statement SQL delimiter
* @return array
*/
function parse_sql( $sql , $delim )
{
if( $sql == '' )
{
die('Could not obtain SQL structure/data');
}
$retval = array();
$statements = explode($delim, $sql);
unset($sql);