-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
install.php
2619 lines (2131 loc) · 80 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
/*
* e107 website system
*
* Copyright (C) 2008-2012 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* e107 v2.x Installation file
*
*/
// minimal software version
define('MIN_PHP_VERSION', '7.4');
define('MIN_MYSQL_VERSION', '4.1.2');
define('MAKE_INSTALL_LOG', true);
// ensure CHARSET is UTF-8 if used
//define('CHARSET', 'utf-8');
/* Default Options and Paths for Installer */
$MySQLprefix = 'e107_';
$HANDLERS_DIRECTORY = "e107_handlers/"; // needed for e107 class init
header('Content-type: text/html; charset=utf-8');
define("e107_INIT", TRUE);
define("DEFAULT_INSTALL_THEME", 'bootstrap5');
define('HELPICON', "<span class='e-tip glyphicon glyphicon-question-sign' style='float:right;padding-top:3px'></span>"); // <i class="glyphicon glyphicon-question-sign"></i>
$e107info = array();
require_once("e107_admin/ver.php");
define("e_VERSION", $e107info['e107_version']);
$e_ROOT = realpath(__DIR__ ."/");
if ((substr($e_ROOT,-1) !== '/') && (substr($e_ROOT,-1) !== '\\') )
{
$e_ROOT .= DIRECTORY_SEPARATOR; // Should function correctly on both windows and Linux now.
}
define('e_ROOT', $e_ROOT);
unset($e_ROOT);
class installLog
{
const logFile = "e107Install.log";
/**
* @param Throwable $exception
* @return void
*/
static function exceptionHandler($exception)
{
$message = $exception->getMessage();
self::add($message, "error");
}
static function errorHandler($errno=null, $errstr=null, $errfile=null, $errline=null)
{
$error = "Error on line ".$errline." in file ".$errfile." : ".$errstr;
switch($errno)
{
case E_ERROR:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_PARSE:
self::add($error, "fatal");
break;
case E_USER_ERROR:
case E_RECOVERABLE_ERROR:
self::add($error, "error");
break;
case E_WARNING:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_WARNING:
self::add($error, "warn");
break;
case E_NOTICE:
case E_USER_NOTICE:
self::add($error, "notice");
break;
case E_STRICT:
self::add($error, "debug");
break;
default:
if(!empty($errno))
{
self::add($error, "warn");
}
}
return true;
}
static function clear()
{
if(!MAKE_INSTALL_LOG || !is_writable(__DIR__))
{
return null;
}
$logFile = __DIR__ .'/'.self::logFile;
file_put_contents($logFile,'');
}
/**
* Write a line of text to the log file (if enabled) - prepend time/date, append \n
* @param string $message
* @param string $type
* @return null
*/
static function add($message, $type='info')
{
if(!MAKE_INSTALL_LOG || !is_writable(__DIR__))
{
return null;
}
$logFile = __DIR__ .'/'.self::logFile; // e107InstallLog.log';
$now = time();
$message = $now.', '.date('c')."\t".$type."\t".$message."\n";
file_put_contents($logFile, $message, FILE_APPEND);
return null;
}
}
set_exception_handler(array('installLog','exceptionHandler'));
set_error_handler(array('installLog',"errorHandler"));
register_shutdown_function(array('installLog',"errorHandler"));
/*define("e_UC_PUBLIC", 0);
define("e_UC_MAINADMIN", 250);
define("e_UC_READONLY", 251);
define("e_UC_GUEST", 252);
define("e_UC_MEMBER", 253);
define("e_UC_ADMIN", 254);
define("e_UC_NOBODY", 255);*/
define("E107_INSTALL",true);
if($_SERVER['QUERY_STRING'] !== "debug") // install.php?debug
{
error_reporting(0); // suppress all errors unless debugging.
}
else
{
error_reporting(E_ALL);
}
if($_SERVER['QUERY_STRING'] === 'clear')
{
unset($_SESSION);
}
//error_reporting(E_ALL);
/*function e107_ini_set($var, $value)
{
if (function_exists('ini_set'))
{
ini_set($var, $value);
}
}*/
// setup some php options
ini_set('arg_separator.output', '&');
ini_set('session.use_only_cookies', 1);
ini_set('session.use_trans_sid', 0);
if (function_exists('date_default_timezone_set'))
{
date_default_timezone_set('UTC');
}
define('MAGIC_QUOTES_GPC', false); // (ini_get('magic_quotes_gpc') ? true : false));
$php_version = PHP_VERSION;
if(version_compare($php_version, MIN_PHP_VERSION, "<"))
{
die_fatal_error('A minimum version of PHP '.MIN_PHP_VERSION.' is required'); // no LAN DEF translation accepted by lower versions <5.3
}
// Check needed to continue (extension check in stage 4 is too late)
if(!class_exists('DOMDocument', false))
{
die_fatal_error("You need to install the DOM extension to install e107."); // NO LAN
}
// Ensure that '.' is the first part of the include path
$inc_path = explode(PATH_SEPARATOR, ini_get('include_path'));
if($inc_path[0] !== ".")
{
array_unshift($inc_path, ".");
$inc_path = implode(PATH_SEPARATOR, $inc_path);
ini_set("include_path", $inc_path);
}
unset($inc_path);
if(!function_exists("mysql_connect") && !defined('PDO::ATTR_DRIVER_NAME'))
{
die_fatal_error("e107 requires PHP to be installed or compiled with PDO or the MySQL extension to work correctly, please see the MySQL manual for more information.");
}
# Check for the realpath(). Some hosts (I'm looking at you, Awardspace) are totally dumb and
# they think that disabling realpath() will somehow (I'm assuming) help improve their pathetic
# local security. Fact is, it just prevents apps from doing their proper local inclusion security
# checks. So, we refuse to work with these people.
$functions_ok = true;
$disabled_functions = ini_get('disable_functions');
if (trim($disabled_functions) != '')
{
$disabled_functions = explode( ',', $disabled_functions );
foreach ($disabled_functions as $function)
{
if(trim($function) === "realpath")
{
$functions_ok = false;
}
}
}
if($functions_ok == true && function_exists("realpath") == false)
{
$functions_ok = false;
}
if($functions_ok == false)
{
die_fatal_error("e107 requires the realpath() function to be enabled and your host appears to have disabled it. This function is required for some <b>important</b> security checks and there is <b>NO workaround</b>. Please contact your host for more information.");
}
//obsolete $installer_folder_name = 'e107_install';
include_once("./{$HANDLERS_DIRECTORY}core_functions.php");
include_once("./{$HANDLERS_DIRECTORY}e107_class.php");
function check_class($whatever='')
{
unset($whatever);
return true;
}
function getperms($arg, $ap = '')
{
unset($arg,$ap);
return true;
}
$override = array();
if(isset($_POST['previous_steps']))
{
$tmp = unserialize(base64_decode($_POST['previous_steps']));
$override = (isset($tmp['paths']) && isset($tmp['paths']['hash'])) ? array('site_path'=>$tmp['paths']['hash']) : array();
unset($tmp);
unset($tmpadminpass1);
}
//$e107_paths = compact('ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'CACHE_DIRECTORY', 'DOWNLOADS_DIRECTORY', 'UPLOADS_DIRECTORY', 'MEDIA_DIRECTORY', 'LOGS_DIRECTORY', 'SYSTEM_DIRECTORY', 'CORE_DIRECTORY');
$e107_paths = array();
$e107 = e107::getInstance();
$ebase = realpath(__DIR__);
if($e107->initInstall($e107_paths, $ebase, $override)===false)
{
die_fatal_error("Error creating the following empty file: <b>".$ebase.DIRECTORY_SEPARATOR."e107_config.php</b><br />Please create it manually and then run the installation again.");
}
unset($e107_paths,$override,$ebase);
// NEW - session handler
require_once(e_HANDLER.'session_handler.php');
define('e_SECURITY_LEVEL', e_session::SECURITY_LEVEL_NONE);
define('e_COOKIE', 'e107install');
e107::getSession(); // starts session, creates default namespace
// session_start();
function include_lan($path, $force = false)
{
unset($force);
return include($path);
}
//obsolete $e107->e107_dirs['INSTALLER'] = "{$installer_folder_name}/";
if(isset($_GET['create_tables']))
{
create_tables_unattended();
exit;
}
$e_install = new e_install();
$e_forms = new e_forms();
$e_install->template->SetTag("installer_css_http", $_SERVER['PHP_SELF']."?object=stylesheet");
//obsolete $e_install->template->SetTag("installer_folder_http", e_HTTP.$installer_folder_name."/");
$e_install->template->SetTag("files_dir_http", e_FILE_ABS);
$e_install->renderPage();
/**
* Set Cookie
* @param string $name
* @param string $value
* @param integer $expire seconds
* @param string $path
* @param string $domain
* @param boolean $secure
* @return void
*/
function cookie($name, $value, $expire=0, $path = e_HTTP, $domain = '', $secure = false)
{
setcookie($name, $value, $expire, $path, $domain, (bool) $secure);
}
class e_install
{
// private $paths;
public $template;
private $debug_info;
// private $debug_db_info;
private $e107;
public $previous_steps;
private $stage;
private $post_data;
private $required = array();
private $session;
protected $pdo = false;
protected $debug = false;
// public function __construct()
function __construct()
{
// notice removal, required from various core routines
define('USERID', 1);
define('USER', true);
define('ADMIN', true);
// define('e_UC_MAINADMIN', 250);
define('E107_DEBUG_LEVEL',0);
if($_SERVER['QUERY_STRING'] === "debug")
{
$this->debug = true;
}
if(defined('PDO::ATTR_DRIVER_NAME'))
{
$this->pdo = true;
define('e_PDO', true);
}
if(!empty($this->previous_steps['mysql']['prefix']))
{
define('MPREFIX', $this->previous_steps['mysql']['prefix']);
}
$tp = e107::getParser();
// session instance
$this->session = e107::getSession();
// $this->logLine('Query string: ');
$this->template = new SimpleTemplate();
if(ob_get_level() > 1)
{
while (@ob_end_clean())
{
unset($whatever);
}
}
global $e107;
$this->e107 = $e107;
if(isset($_POST['previous_steps']))
{
$this->previous_steps = unserialize(base64_decode($_POST['previous_steps']));
// Save unfiltered admin password (#4004) - " are transformed into "
$tmpadminpass2 = (isset($this->previous_steps['admin'])) ? $this->previous_steps['admin']['password'] : '';
$this->previous_steps = $tp->filter($this->previous_steps);
// Restore unfiltered admin password
$this->previous_steps['admin']['password'] = $tmpadminpass2;
unset($_POST['previous_steps']);
unset($tmpadminpass2);
}
else
{
$this->previous_steps = array();
}
$this->get_lan_file();
$this->post_data = $tp->filter($_POST);
$this->template->SetTag('required', '');
if(isset($this->previous_steps['language']))
{
define("e_LANGUAGE", $this->previous_steps['language']);
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/".e_LANGUAGE.".php");
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_admin.php");
}
}
function add_button($id, $title='', $align = "right", $type = "submit")
{
global $e_forms;
$e_forms->form .= "<div class='buttons-bar inline' style='text-align: {$align}; z-index: 10;'>";
if($id !== 'start')
{
// $this->form .= "<a class='btn btn-large ' href='javascript:history.go(-1)'>« ".LAN_BACK."</a> ";
$prevStage = ($this->stage - 1);
$e_forms->form .= "<button class='btn btn-default btn-secondary btn-large no-validate ' name='back' value='".$prevStage."' type='submit'>« ".LAN_BACK."</button> ";
}
if($id !== 'back')
{
$e_forms->form .= "<input type='{$type}' id='{$id}' name='{$id}' value='{$title} »' class='btn btn-large btn-primary' />";
}
$e_forms->form .= "</div>\n";
}
function renderPage()
{
if(!isset($_POST['stage']))
{
$_POST['stage'] = 1;
}
$_POST['stage'] = (int) $_POST['stage'];
if(!empty($_POST['back']))
{
$_POST['stage'] = (int) $_POST['back'];
}
switch ($_POST['stage'])
{
case 1:
$this->stage_1();
break;
case 2:
$this->stage_2();
break;
case 3:
$this->stage_3();
break;
case 4:
$this->stage_4();
break;
case 5:
$this->stage_5();
break;
case 6:
$this->stage_6();
break;
case 7:
$this->stage_7();
break;
case 8:
$this->stage_8();
break;
default:
$this->raise_error("Install stage information from client makes no sense to me.");
}
if($_SERVER['QUERY_STRING'] === "debug")
{
$this->template->SetTag("debug_info", print_a($this->previous_steps,TRUE));
}
else
{
$this->template->SetTag("debug_info", (!empty($this->debug_info) ? print_a($this->debug_info,TRUE)."Backtrace:<br />".print_a($this,TRUE) : ""));
}
echo $this->template->ParseTemplate(template_data(), TEMPLATE_TYPE_DATA);
}
function raise_error($details)
{
$this->debug_info[] = array (
'info' => array (
'details' => $details,
'backtrace' => debug_backtrace()
)
);
}
function display_required()
{
if(empty($this->required))
{
return;
}
$this->required = array_filter($this->required);
if(!empty($this->required))
{
$this->template->SetTag("required","<div class='message'>". implode("<br />",$this->required)."</div>");
$this->required = array();
}
}
/**
* Stage 1
* @return null
*/
private function stage_1()
{
global $e_forms;
$this->stage = 1;
installLog::clear();
installLog::add('Stage 1 started');
$this->template->SetTag("installation_heading", LANINS_001);
$this->template->SetTag("stage_pre", LANINS_002);
$this->template->SetTag("stage_num", LANINS_003);
$this->template->SetTag("stage_title", LANINS_004);
$this->template->SetTag("percent", 10);
$this->template->SetTag("bartype", 'warning');
$e_forms->start_form("language_select", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] === "debug" ? "?debug" : ""));
$e_forms->add_select_item("language", $this->get_languages(), "English");
$this->finish_form();
$this->add_button("start", LAN_CONTINUE);
$output = "
<div style='text-align: center;'>
<div class='alert alert-info alert-block text-center'>
<label for='language'>".LANINS_005."</label>
</div>\n
<br />\n
<div class='col-md-offset-4 col-md-6'>
".$e_forms->return_form()."
</div><br />
</div>";
$this->template->SetTag("stage_content", $output);
installLog::add('Stage 1 completed');
return null;
}
private function stage_2()
{
global $e_forms;
$this->stage = 2;
installLog::add('Stage 2 started');
if(!empty($_POST['language']))
{
$this->previous_steps['language'] = $_POST['language'];
}
$this->template->SetTag("installation_heading", LANINS_001);
$this->template->SetTag("stage_pre", LANINS_002);
$this->template->SetTag("stage_num", LANINS_021);
$this->template->SetTag("stage_title", LANINS_022);
$this->template->SetTag("percent", 25);
$this->template->SetTag("bartype", 'warning');
if(!isset($this->previous_steps['mysql']['createdb']))
{
$this->previous_steps['mysql']['createdb'] = 1; // default to yes.
}
// $this->template->SetTag("onload", "document.getElementById('name').focus()");
// $page_info = nl2br(LANINS_023);
$page_info = "<div class='alert alert-block alert-info'>".LANINS_141."</div>";
$e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] === "debug" ? "?debug" : ""));
$isrequired = (($_SERVER['SERVER_ADDR'] === "127.0.0.1") || ($_SERVER['SERVER_ADDR'] === "localhost") || ($_SERVER['SERVER_ADDR'] === "::1") || preg_match('/^192\.168\.\d{1,3}\.\d{1,3}$/',$_SERVER['SERVER_ADDR'])) ? "" : "required='required'"; // Deals with IP V6, and 192.168.x.x address ranges, could be improved to validate x.x to a valid IP but for this use, I dont think its required to be that picky.
$output = "
<div style='width: 100%; padding-left: auto; padding-right: auto;'>
<table class='table table-striped table-bordered' >
<tr>
<td style='border-top: 1px solid #999;'><label for='server'>".LANINS_024."</label>".HELPICON."
<span class='field-help'>".LANINS_030."</span></td>
<td style='border-top: 1px solid #999;'>
<input class='form-control input-large' type='text' id='server' name='server' autofocus size='40' value='".varset($this->previous_steps['mysql']['server'],'localhost')."' maxlength='100' required='required' />
</td>
</tr>
<tr>
<td><label for='name'>".LANINS_025."</label>".HELPICON."<span class='field-help'>".LANINS_031."</span></td>
<td>
<input class='form-control input-large' type='text' name='name' id='name' value='".varset($this->previous_steps['mysql']['user'])."' size='40' maxlength='100' required='required' />
</td>
</tr>
<tr>
<td><label for='password'>".LANINS_026."</label>".HELPICON."<span class='field-help'>".LANINS_032."</span></td>
<td>
<input class='form-control input-large' type='password' name='password' size='40' id='password' value='".varset($this->previous_steps['mysql']['password'])."' maxlength='100' {$isrequired} pattern='[^\x22]+' />
</td>
</tr>
<tr>
<td><label for='db'>".LANINS_027."</label>".HELPICON."<span class='field-help'>".LANINS_033."</span></td>
<td class='form-inline'>
<input class='form-control input-large' type='text' name='db' size='20' id='db' value='".varset($this->previous_steps['mysql']['db'])."' maxlength='100' required='required' pattern='^[a-zA-Z0-9][a-zA-Z0-9_-]*' />
<label class='checkbox-inline'><input type='checkbox' name='createdb' value='1' ".($this->previous_steps['mysql']['createdb'] ==1 ? "checked='checked'" : "")." /><small>".LANINS_028."</small></label>
</td>
</tr>
<tr>
<td><label for='prefix'>".LANINS_029."</label>".HELPICON."<span class='field-help'>".LANINS_034."</span></td>
<td>
<input class='form-control input-large' type='text' name='prefix' size='20' id='prefix' value='e107_' pattern='[a-z0-9]*_$' maxlength='100' required='required' />
</td>
</tr>
</table>
<br /><br />
</div>
\n";
$e_forms->add_plain_html($output);
$this->finish_form();
$this->add_button("submit", LAN_CONTINUE);
$this->template->SetTag("stage_content", $page_info.$e_forms->return_form());
installLog::add('Stage 2 completed');
}
/**
* Replace hash paths and create folders if needed.
*
* @return null
*/
private function updatePaths()
{
$hash = $this->e107->makeSiteHash($this->previous_steps['mysql']['db'],$this->previous_steps['mysql']['prefix']);
$this->e107->site_path = $hash;
$this->previous_steps['paths']['hash'] = $hash;
installLog::add("Directory Hash Set: ".$hash);
$omit = array('FILES_DIRECTORY','WEB_IMAGES_DIRECTORY');
foreach($this->e107->e107_dirs as $dir => $p)
{
if(in_array($dir, $omit)) { continue; }
$this->e107->e107_dirs[$dir] = str_replace("[hash]", $hash, $this->e107->e107_dirs[$dir]);
if(!is_dir($this->e107->e107_dirs[$dir]))
{
@mkdir($this->e107->e107_dirs[$dir]);
}
}
return null;
}
private function stage_3()
{
global $e_forms;
$this->stage = 3;
$alertType = 'warning';
installLog::add('Stage 3 started');
$this->template->SetTag("installation_heading", LANINS_001);
$this->template->SetTag("stage_pre", LANINS_002);
$this->template->SetTag("stage_num", LANINS_036);
$this->template->SetTag("onload", "document.getElementById('name').focus()");
$this->template->SetTag("percent", 40);
$this->template->SetTag("bartype", 'warning');
$tp = e107::getParser();
if(!empty($_POST['server']))
{
$this->previous_steps['mysql']['server'] = trim($tp->filter($_POST['server']));
$this->previous_steps['mysql']['user'] = trim($tp->filter($_POST['name']));
$this->previous_steps['mysql']['password'] = trim($tp->filter($_POST['password']));
$this->previous_steps['mysql']['db'] = trim($tp->filter($_POST['db']));
$this->previous_steps['mysql']['createdb'] = isset($_POST['createdb']) && $_POST['createdb'] == true;
$this->previous_steps['mysql']['prefix'] = trim($tp->filter($_POST['prefix']));
$this->setDb();
}
if(!empty($_POST['overwritedb']))
{
$this->previous_steps['mysql']['overwritedb'] = 1;
}
$success = $this->check_name($this->previous_steps['mysql']['db']) && $this->check_name($this->previous_steps['mysql']['prefix'], TRUE);
if ($success)
{
$success = $this->checkDbFields($this->previous_steps['mysql']); // Check for invalid characters
}
if(!$success || $this->previous_steps['mysql']['server'] == "" || $this->previous_steps['mysql']['user'] == "")
{
$this->stage = 3;
$this->template->SetTag("stage_num", LANINS_021);
$e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] === "debug" ? "?debug" : ""));
$head = LANINS_039."<br /><br />\n";
$output = "
<div style='width: 100%; padding-left: auto; padding-right: auto;'>
<table class='table table-bordered table-striped'>
<tr>
<td style='border-top: 1px solid #999;'><label for='server'>".LANINS_024."</label></td>
<td style='border-top: 1px solid #999;'><input class='form-control' type='text' id='server' name='server' size='40' value='{$this->previous_steps['mysql']['server']}' maxlength='100' required /></td>
<td style='width: 40%; border-top: 1px solid #999;'>".LANINS_030."</td>
</tr>
<tr>
<td><label for='name'>".LANINS_025."</label></td>
<td><input class='form-control' type='text' name='name' id='name' size='40' value='{$this->previous_steps['mysql']['user']}' maxlength='100' onload='this.focus()' /></td>
<td>".LANINS_031."</td>
</tr>
<tr>
<td><label for='password'>".LANINS_026."</label></td>
<td><input class='form-control' type='password' name='password' id='password' size='40' value='{$this->previous_steps['mysql']['password']}' maxlength='100' /></td>
<td>".LANINS_032."</td>
</tr>
<tr>
<td><label for='db'>".LANINS_027."</label></td>
<td><input type='text' name='db' id='db' size='20' value='{$this->previous_steps['mysql']['db']}' maxlength='100' />
<br /><label class='defaulttext'><input type='checkbox' name='createdb' " .($this->previous_steps['mysql']['createdb'] == 1 ? " checked='checked'" : "") . " value='1' />".LANINS_028."</label></td>
<td>".LANINS_033."</td>
</tr>
<tr>
<td><label for='prefix'>".LANINS_029."</label></td>
<td><input type='text' name='prefix' id='prefix' size='20' value='{$this->previous_steps['mysql']['prefix']}' maxlength='100' /></td>
<td>".LANINS_034."</td>
</tr>";
if (!$success)
{
$output .= "<tr><td colspan='3'>".LANINS_105."</td></tr>";
}
$output .= "
</table>
<br /><br />
</div>
\n";
$e_forms->add_plain_html($output);
$this->add_button("submit", LAN_CONTINUE);
$this->template->SetTag("stage_title", LANINS_040);
}
else
{
$this->template->SetTag("stage_title", LANINS_037.($this->previous_steps['mysql']['createdb'] == 1 ? LANINS_038 : ""));
$sql = e107::getDb();
if (!$res = $sql->connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']))
// if (!$res = @mysql_connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']))
{
$success = FALSE;
$e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] === "debug" ? "?debug" : ""));
$page_content = LANINS_041.nl2br("\n\n<b>".LANINS_083."\n</b><i>".$sql->getLastErrorText()."</i>");
$alertType = 'error';
}
elseif(($this->previous_steps['mysql']['createdb'] == 1) && empty($this->previous_steps['mysql']['overwritedb']) && $sql->database($this->previous_steps['mysql']['db'], $this->previous_steps['mysql']['prefix']))
{
$e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] === "debug" ? "?debug" : ""));
$head = str_replace('[x]', '<b>'.$this->previous_steps['mysql']['db'].'</b>', "<div class='alert alert-warning'>". LANINS_127."</div>");
$alertType = 'error';
$this->add_button('overwritedb', LANINS_128);
/* $e_forms->add_plain_html("
<input type='submit' id='overwritedb' name='overwritedb' value=\"".LANINS_128." »\" class='btn btn-large btn-primary' />"
);*/
$this->finish_form(3);
$this->template->SetTag("stage_content", "<div class='alert alert-block alert-{$alertType}'>".$head."</div>".$e_forms->return_form());
installLog::add('Stage 3 completed');
return;
}
else
{
$e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] === "debug" ? "?debug" : ""));
$page_content = "<span class='glyphicon glyphicon-ok'></span> ".LANINS_042;
// @TODO Check database version here?
/*
$mysql_note = mysql_get_server_info();
if (version_compare($mysql_note, MIN_MYSQL_VERSION, '>='))
{
$success = FALSE;
}
*/
// Do brute force for now - Should be enough
if(!empty($this->previous_steps['mysql']['overwritedb']))
{
if($this->dbqry('DROP DATABASE `'.$this->previous_steps['mysql']['db'].'` '))
{
$page_content .= "<br /><span class='glyphicon glyphicon-ok'></span> ".LANINS_136;
}
else
{
$success = false;
$page_content .= "<br /><br />".LANINS_043.nl2br("\n\n<b>".LANINS_083."\n</b><i>".e107::getDb()->getLastErrorText()."</i>");
}
}
if($this->previous_steps['mysql']['createdb'] == 1)
{
$notification = "<br /><span class='glyphicon glyphicon-ok'></span> ".LANINS_044;
$query = 'CREATE DATABASE `'.$this->previous_steps['mysql']['db'].'` CHARACTER SET `utf8mb4` ';
}
else
{
$notification = "<br /><span class='glyphicon glyphicon-ok'></span> ".LANINS_137;
$query = 'ALTER DATABASE `'.$this->previous_steps['mysql']['db'].'` CHARACTER SET `utf8mb4` ';
}
if (!$this->dbqry($query))
{
$success = false;
$alertType = 'error';
$page_content .= "<br /><br />";
$page_content .= (empty($this->previous_steps['mysql']['createdb'])) ? LANINS_129 : LANINS_043;
$page_content .= nl2br("\n\n<b>".LANINS_083."\n</b><i>".e107::getDb()->getLastErrorText()."</i>");
}
else
{
$this->dbqry('SET NAMES `utf8mb4`');
$page_content .= $notification; // "
}
}
if($success)
{
// $page_content .= "<br /><br />".LANINS_045."<br /><br />";
$this->add_button("submit", LAN_CONTINUE);
$alertType = 'success';
}
else
{
$this->add_button("back", LAN_CONTINUE);
}
$head = $page_content;
}
if ($success)
{
$this->finish_form();
}
else
{
$this->finish_form(3);
}
$this->template->SetTag("stage_content", "<div class='alert alert-block alert-{$alertType}'>".$head."</div>".$e_forms->return_form());
installLog::add('Stage 3 completed');
return null;
}
private function stage_4()
{
global $e_forms;
$this->stage = 4;
installLog::add('Stage 4 started');
$this->template->SetTag("installation_heading", LANINS_001);
$this->template->SetTag("stage_pre", LANINS_002);
$this->template->SetTag("stage_num", LANINS_007);
$this->template->SetTag("stage_title", LANINS_008);
$this->template->SetTag("percent", 50);
$this->template->SetTag("bartype", 'warning');
$not_writable = $this->check_writable_perms(); // Some directories MUST be writable
$opt_writable = $this->check_writable_perms('can_write'); // Some directories CAN optionally be writable
$version_fail = false;
$perms_errors = "";
$mysql_pass = false;
$this->setDb();
if(count($not_writable))
{
$perms_pass = false;
foreach ($not_writable as $file)
{
$perms_errors .= (substr($file, -1) === "/" ? LANINS_010a : LANINS_010)."<br /><b>{$file}</b><br />\n";
}
$perms_notes = LANINS_018;
}
elseif (count($opt_writable))
{
$perms_pass = true;
foreach ($opt_writable as $file)
{
$perms_errors .= (substr($file, -1) === "/" ? LANINS_010a : LANINS_010)."<br /><b>{$file}</b><br />\n";
}
$perms_notes = LANINS_106;
}
elseif (filesize('e107_config.php') > 1)
{ // Must start from an empty e107_config.php
$perms_pass = FALSE;
$perms_errors = LANINS_121;
$perms_notes = "<span class='glyphicon glyphicon-remove'></span> ".LANINS_122;
}
else
{
$perms_pass = true;
$perms_errors = " ";
$perms_notes = "<span class='glyphicon glyphicon-ok'></span> ".LANINS_017;
}
if(!function_exists("mysql_connect") && !defined('PDO::ATTR_DRIVER_NAME'))
{
$version_fail = true;
$mysql_note = LAN_ERROR;
$mysql_help = LANINS_012;
}
elseif (!e107::getDb()->connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']))
// elseif (!@mysql_connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']))
{
$mysql_note = LAN_ERROR;
$mysql_help = LANINS_013;
}
else
{
// $mysql_note = mysql_get_server_info();
$mysql_note = e107::getDb()->getServerInfo();
if($this->pdo == true)
{
$mysql_note .= " (PDO)";
}
if (version_compare($mysql_note, MIN_MYSQL_VERSION, '>='))
{
$mysql_help = "<span class='glyphicon glyphicon-ok'></span> ".LANINS_017;
$mysql_pass = true;
}
else
{
$mysql_help = "<span class='glyphicon glyphicon-remove'></span> ".LANINS_105;
}
}
$php_version = PHP_VERSION;
if(version_compare($php_version, MIN_PHP_VERSION, ">="))
{
$php_help = "<span class='glyphicon glyphicon-ok'></span> ".LANINS_017;
}
else
{
$php_help = "<span class='glyphicon glyphicon-remove'></span> ".LANINS_019;
}
$e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] === "debug" ? "?debug" : ""));
$permColor = ($perms_pass == true) ? "text-success" : "text-danger";
$PHPColor = ($version_fail == false) ? "text-success" : "text-danger";
$mysqlColor = ($mysql_pass == true) ? "text-success" : "text-danger";
$extensionCheck = array(
'pdo' => array('label' => "PDO (MySQL)", 'status' => extension_loaded('pdo_mysql'), 'url' => 'https:/php.net/manual/en/book.pdo.php'),