This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
install.php
4195 lines (3862 loc) · 250 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
set_time_limit(300);
define('DBARRAY_NUM', MYSQLI_NUM);
define('DBARRAY_ASSOC', MYSQLI_ASSOC);
define('DBARRAY_BOTH', MYSQLI_BOTH);
if (!defined('DB_EXPLAIN'))
define('DB_EXPLAIN', false);
if (!defined('DB_QUERIES'))
define('DB_QUERIES', false);
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
die('WebStore requires at least PHP version of 5.3 (5.4 is preferable). Sorry cannot continue installation.');
}
define ('__SUBDIRECTORY__', preg_replace('/\/?\w+\.php$/', '', $_SERVER['PHP_SELF']));
define ('__DOCROOT__', substr(dirname(__FILE__), 0, strlen(dirname(__FILE__)) - strlen(__SUBDIRECTORY__)));
define ('__VIRTUAL_DIRECTORY__', '');
//Installer can only run if the site hasn't been set up
if(file_exists("config/main.php") && isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != __SUBDIRECTORY__ . "/install.php?check")
{
header("Location: index.php");
exit;
}
if(isset($_POST['getpg']))
{
if(file_exists("progress.txt"))
{
$c = file_get_contents("progress.txt");
if(empty($c)) $c=1;
echo json_encode(array('result'=>"success",'progress'=>$c));
}
else echo json_encode(array('result'=>"success",'progress'=>1));
return;
}
if(isset($argv)) $arg = arguments($argv); else $arg=array();
if(count($arg))
{
//We're running this install from the command line
//usage: php install.php --dbhost=localhost --dbuser=root
// --dbpass=mypass --dbname=webstore --url=store.example.com
// --oldbname=webstorebak (optional)
//WARNING: This method of install does not run the environment check
//We cannot guarantee all libraries are installed
//(This is because command line php may differ from Apache server php)
if(isset($arg['help'])) showCommandLine();
if(isset($arg['dbupdate']) && $arg['dbupdate']==1)
{
echo "**dbupdate command removed**\n\nUpdates should use yiic since you're already on the command line\n\n";
echo "\nCommand: core/protected/yiic migrate up --interactive=0\n\n";
die();
}
if(file_exists("config/main.php")) die("\nENTER 1 OR 2 FOR INSTRUCTIONS (ENTER 2 TO PAGE)\n\nENTER SEED NUMBER
INITIALIZING...\n\nYOU MUST DESTROY 17 KINGONS IN 30 STARDATES WITH 3 STARBASES\n\n-=--=--=--=--=--=--=--=-\n
*\n STARDATE 2100\n * * CONDITION GREEN\n <*> QUADRANT 5,2\n * SECTOR 5,4\n ENERGY 3000\n SHIELDS 0\n * PHOTON TORPEDOES 10\n-=--=--=--=--=--=--=--=-\nCOMMAND\n\nHey, ensign Wesley, Web Store is already installed!\n\n");
$arrRequired = array('dbhost','dbuser','dbpass','dbname','url');
foreach($arrRequired as $item)
if(!isset($arg[$item]))
showCommandLine();
echo "\n**Installing Web Store**\n\n";
$upgrade=0;
if(isset($arg['dboldname']))
{
$_POST['dboldname']=$arg['dboldname'];
$upgrade=1;
}
$arg=modifyArgs($arg);
downloadLatest();
zipAndFolders();
writeDB($arg['dbhost'],$arg['dbuser'],$arg['dbpass'],$arg['dbname']);
$db = createDbConnection();
$sqlline = 1;
$endline = 99999999;
$tag="";
$saveperc=0;
while($sqlline<=$endline)
{
$retVal = runInstall($db,$sqlline);
$j = json_decode($retVal);
if($j->result=="success")
{
$sqlline = $j->line+1;
$endline = $j->total;
if(isset($j->tag) && $tag != $j->tag)
{
echo $j->tag."\n";
$tag=$j->tag;
}
$perc = round($sqlline/$endline*50,0);
if ($perc != $saveperc)
{
$saveperc = $perc;
echo $perc."%\n";
}
} else {
echo $j->result;
die();
}
}
if(isset($arg['hosted']))
$hosted=1;
else
$hosted=0;
echo "\nLaunching Yii bootstrap\n";
runYii($arg['url'],$arg['scriptname'],1,$upgrade,$hosted);
}
else
{
//We're running this install from the browser
// Set up initial pathing so install can continue
$step = 1;
if (isset($_POST['step']))
$step = preg_replace('/[^0-9]/', '', $_POST['step']);
if (isset($_POST['sqlline']))
{
$db = createDbConnection();
echo runInstall($db,preg_replace('/[^0-9]/', '', $_POST['sqlline']));
exit();
}
switch ($step)
{
case 2:displayFormTwo(); break;
case 3:displayForm(); break;
case 1: default:
$checkenv = xls_check_server_environment();
if ((in_array("fail", $checkenv) && $_SERVER['REQUEST_URI'] != __SUBDIRECTORY__ . "/install.php?ignore")
|| $_SERVER['REQUEST_URI'] == __SUBDIRECTORY__ . "/install.php?check"
) {
displayNotAcceptable($checkenv);
} else {
displayForm();
}
break;
}
}
function showCommandLine()
{
die("\n*error halting*\n\nusage: php install.php --dbhost=localhost --dbuser=root --dbpass=mypass --dbname=webstore --url=store.example.com --dboldname=webstorebak (optional) --hosted=1 (optional)\n\n");
}
function runYii($url,$scriptname,$sqlline=1,$upgrade,$hosted)
{
global $arg;
$_SERVER=array(
'REQUEST_URI' => $scriptname,
'SERVER_NAME' => $url,
'SCRIPT_FILENAME' => realpath(__FILE__),
'SCRIPT_NAME' => $scriptname,
'PHP_SELF' => $scriptname,
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko)',
'HTTP_HOST' => $url,
'QUERY_STRING' => '',
);
$_SESSION['DUMMY']="nothing"; //force creation of session just in case
//This is the halfway point, we have to switch to the Yii framework now, so let's bootstrap it
$yii=dirname(__FILE__).'/core/framework/yii.php';
$config=dirname(__FILE__).'/config/main.php';
require_once($yii);
$objYii = Yii::createWebApplication($config);
do
{
$_POST['online']=$sqlline;
$_POST['upgrade']=$upgrade;
$_POST['hosted']=$hosted;
ob_start();
if($upgrade)
$objYii->runController("install/upgrade");
else
$objYii->runController("install/install");
$retVal = ob_get_contents();
$j = json_decode($retVal);
if(isset($j->result) && $j->result=="success")
{
ob_clean();
$sqlline = $j->makeline;
$endline = $j->total;
if(isset($j->tag))
echo $j->tag." ";
echo (50+$sqlline)."%\n";
} else die();
ob_end_flush();
} while ($sqlline<50);
if(!isset($arg['dbupdate'])) //IOW only command line db updates
echo "\n** finished **\n\nCustomer needs to go to http://" .$url . str_replace('install.php', 'admin/license', $scriptname) ." to complete installation.\n\n";
}
function xls_check_file_signatures($complete = false)
{
$url = "http://updater.lightspeedretail.com";
$url .= "/webstore/hash";
$json = json_encode(array('version'=> _ws_version()));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$strXml = curl_exec($ch);
curl_close($ch);
$oXML = new SimpleXMLElement($strXml);
$signatures = $oXML->signatures;
$versions = explode(",",$oXML->versions);
$checked = array();
$checked['<b>--File Signatures Check for ' . _ws_version() . '--</b>'] = "pass";
$fn = unserialize($signatures);
if (!isset($signatures)) {
$checked['Signature File in /core/protected/modules/admin'] = "fail";
}
foreach ($fn as $key => $value) {
if (!file_exists($key)) {
$checked[$key] = "MISSING";
} else {
$hashes = explode(",", $value);
$hashfile = md5_file($key);
if (!in_array($hashfile, $hashes)) {
$checked[$key] = "modified";
} elseif (_ws_version() != $versions[array_search($hashfile, $hashes)] || $complete) {
$checked[$key] = $versions[array_search($hashfile, $hashes)];
}
}
}
return $checked;
}
function makeHtaccess()
{
//Update Rewrite Base in htaccess
$origText = "RewriteBase /";
$replText = "RewriteBase ".$_SERVER['SCRIPT_NAME'];
$replText = str_replace("/install.php", "", $replText);
if ($replText=="RewriteBase ") $replText="RewriteBase /";
$strFileContents = file_get_contents('htaccess');
@$strFileContents2 = file_get_contents('.htaccess');
if ($strFileContents2 && $strFileContents2 ==$replText )
{
//our .htaccess is fine
} elseif ($strFileContents) {
$fp = @fopen('.htaccess', 'w');
if ($fp) {
$str = str_replace($origText, $replText, $strFileContents);
fwrite($fp, $str, strlen($str));
fclose($fp);
} else die("cannot create/update your .htaccess file. Try renaming/removing the existing one and running install again.");
}
//Write robots.txt too
$strFileContents = "User-agent: *
Disallow:
Sitemap: http://www.example.com/store/sitemap.xml
";
$replText = $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . "/sitemap.xml";
$replText = str_replace("/install.php", "", $replText);
$fp = @fopen('robots.txt', 'w');
if ($fp) {
$str = str_replace('http://www.example.com/store/sitemap.xml', $replText, $strFileContents);
fwrite($fp, $str, strlen($str));
fclose($fp);
} else die("cannot create/update your robots.txt file. Try renaming/removing the existing one and running install again.");
}
function _ws_version()
{
if(file_exists("core/protected/config/wsver.php"))
{
include_once("core/protected/config/wsver.php");
return XLSWS_VERSION;
}
else return 3;
}
function displayForm()
{
displayHeader();
$dbhost = "localhost";
$dbport = "3306";
$dbuser = ini_get('mysql.default_user');
$dbpass = "";
$dbname = "";
?>
<h2>Welcome!</h2>
<div class="hero-unit">
<p>This process will install the latest Web Store, optionally importing your old 2.x information. This initial page will set up the database for you, and then you will be redirected for additional setup steps. We've made install as simple as possible to get you going on your new eCommerce store!</p>
<p><strong>Warning: Do not close this browser window until your setup has completed. Doing so will cause an incomplete install and you will have to begin again.</strong></p>
</div>
<h2>Install</h2>
<label>Enter your database connection information below. <strong>Note: This database must already exist and be blank.</strong></label>
<!-- Search form with input field and button -->
<form id="installform" action="install.php?<?php if(isset($_GET['debug'])) echo "&debug";if(isset($_GET['qa'])) echo "&qa=".$_GET['qa']; ?>" method="POST" class="well form-search">
<table class="table table-striped">
<tr>
<td nowrap>MySQL Database Host (Server name or IP):</td>
<td><input id="dbhost" name="dbhost" value="<?php echo $dbhost; ?>" type="text" class="input-medium"></td>
</tr>
<tr>
<td nowrap>MySQL Port:</td>
<td><input id="dbport" name="dbport" value="<?php echo $dbport; ?>" type="text" class="input-medium"></td>
</tr>
<tr>
<td nowrap>MySQL Username:</td>
<td><input id="dbuser" name="dbuser" value="<?php echo $dbuser; ?>" type="text" class="input-medium"></td>
</tr>
<tr>
<td nowrap>MySQL Password:</td>
<td><input id="dbpass" name="dbpass" value="<?php echo $dbpass; ?>" type="password" class="input-medium"></td>
</tr>
<tr>
<td nowrap>Database Name:</td>
<td><input id="dbname" name="dbname" value="<?php echo $dbname; ?>" type="text" class="input-medium"></td>
</tr>
</table>
<input type="hidden" name="step" value="2">
<p><strong>If you are upgrading, enter your old database name here. Because this installer copies your database, you cannot use the same database name if upgrading. If your original database was named "webstore" and you wish to keep that name, you will need to rename your existing database to something like "webstoreold" first, and then create a new blank "webstore" database.</strong></p>
<table class="table table-striped">
<tr>
<td nowrap>Web Store 2.x Database Name:</td>
<td><input name="dboldname" value="" type="text" class="input-medium"></td>
</tr>
</table>
<button type="submit" class="btn btn-primary pull-right">Install</button>
<P> </P>
</form>
</div>
<?php
displayFooter();
}
function displayNotAcceptable($checkenv)
{
displayHeader();
$warning_text = "<table class='table table-striped'>";
if (stripos($_SERVER['REQUEST_URI'],"install.php?check") !== false) {
?><h2>System Check</h2><?php
$warning_text .= "<tr><td colspan='2'><b>SYSTEM CHECK for " . _ws_version() . "</b></td></tr>";
$warning_text .= "<tr><td colspan='2'>The chart below shows the results of the system check and if upgrades have been performed.</td></td>";
//For 2.1.x upgrade, have the upgrades been run?
if (stripos($_SERVER['REQUEST_URI'],"install.php?check") !== false) {
//$checkenv = array_merge($checkenv, xls_check_upgrades());
$checkenv = array_merge($checkenv, xls_check_file_signatures());
}
} else {
?>
<h2>Error</h2>
<div class="hero-unit">
<p>Oops, we've detected a problem with your environment that will conflict with Web Store. The environment check results are shown below. Anything that has failed will need to be addressed, then just refresh this page.</p>
</div>
<?php
$warning_text .= "<tr><td colspan='2'><b>CANNOT INSTALL</b></td></tr>";
$warning_text .= "<tr><td colspan='2'>There are issues with your PHP environment which need to be fixed before you can install WebStore. Please check the chart below for required changes to your PHP installation which must be changed, and subdirectories which you need to make writeable. (Making php.ini changes on a web hosting service will vary by company. Please consult their technical support for exact instructions.)</td></td>";
}
$warning_text .= "<tr><td colspan='2'><hr></td></tr>";
$curver = _ws_version();
foreach ($checkenv as $key => $value) {
$warning_text
.= "<tr><td>$key</td><td>" . (($value == "pass" || $value == $curver) ? "$value"
: "<font color='#cc0000'><b>$value</b></font>") . "</td>";
}
$warning_text .= "</table>";
?>
<div>
<?php echo $warning_text; ?>
</div>
<p> </p>
<?php
displayFooter();
}
function displayFormTwo()
{
$sanitized = preg_replace('/[^a-zA-Z0-9\.\,\(\)@#!?_]/', '', $_POST);
writeDB($sanitized['dbhost'],$sanitized['dbuser'],$sanitized['dbpass'],$sanitized['dbname']);
displayHeader();
if (strlen($_POST['dboldname'])>0)
{
$headerstring = "Installing and migrating...";
$quip = "You probably have time to get a coffee.";
}
else
{
$headerstring = "Installing...";
$quip = "This shouldn't take too long.";
}
if (!isset($_POST['dboldname'])) $_POST['dboldname'] = "";
?>
<h2><?php echo $headerstring; ?></h2>
<div class="hero-unit">
<p id="quip"><?php echo $quip; ?></p>
<div class="progress progress-striped active">
<div class="bar" id="progressbar" style="width: 0%;"></div>
</div>
<div id="waitbar">
</div>
<div id="stats"></div>
</div>
<script language="javascript">
var prunning=0;
var pinttimer=0;
var online=1;
var total = 0;
var delay=50;
function startInstall(key) {
document.getElementById('progressbar').style.width = "1%";
pinttimer=self.setInterval(function(){runInstall(key)},50);
runInstall(key);
}
function runInstall(key)
{
if (prunning==1)
{
if(online==2)
{
var postvar = "getpg=1";
$.post("install.php", postvar, function(data)
{
if (data[0]=="{")
{
obj = JSON.parse(data);
if (obj.result=='success' && obj.progress>1) {
document.getElementById('progressbar').style.width = obj.progress + "%";
document.getElementById('progressbar').style.backgroundColor = "#AA0000";
}
}
});
}
return;
}
prunning=1;
var postvar = "sqlline="+ online +
"&dbname=" + "<?php echo $_POST['dbname'] ?>" +
"&dboldname=" + "<?php echo $_POST['dboldname'] ?><?php if(isset($_GET['qa'])) echo "&qa=".$_GET['qa']?><?php if(isset($_GET['debug'])) echo "&debug=1"?>";
//document.getElementById('waitbar').innerHTML = 'about to post '+postvar;
$.ajax({
url: "install.php",
type:'POST',data:postvar,
error: function(jqXHR, textStatus, errorThrown){
delay=delay+1000;
document.getElementById('quip').innerHTML = "Server appears to be throttling connections, setting delay to "+((delay-50)/1000)+ " seconds";
clearInterval(pinttimer);
pinttimer=self.setInterval(function(){runInstall(key)},delay);
prunning=0;
}
}).done(
function(data){
//document.getElementById('waitbar').innerHTML = "got back "+data;
if (data[0]=="{")
{
obj = JSON.parse(data);
if (obj.result=='success')
{
var perc = Math.round((100*(online/obj.total)));
perc = perc/2;
if(perc<1) perc=1;
document.getElementById('progressbar').style.width = perc + "%";
document.getElementById('progressbar').style.backgroundColor = "#149BDF";
if (!obj.tag) obj.tag = "";
document.getElementById('stats').innerHTML = obj.tag;
<?php if(isset($_GET['debug'])): ?>
document.getElementById('stats').innerHTML = obj.tag + " Running line "+online + " of " + obj.total + " (" + perc + "%)";
<?php endif; ?>
if (online==obj.total) {
clearInterval(pinttimer);
prunning=0;
online = 1;
pinttimer=self.setInterval(function(){runUpgrade(key)},delay);
}else {
prunning=0;
if (obj.line) online = (obj.line*1) +1;
else online = online + 1;
if (delay>1050)
{
delay=delay-1000;
document.getElementById('quip').innerHTML =
"Server appears to be throttling connections, setting delay to "+((delay-50)/1000)+ " seconds";
clearInterval(pinttimer);
pinttimer=self.setInterval(function(){runInstall(key)},delay);
}
}
}
}
else {
clearInterval(pinttimer);
if(data.indexOf("Table 'xlsws_customer' already exists")>0)
data = "Helpful information: This appears to be an error caused by installing into a database that is not blank. Web Store 3 requires a blank database to install.\n\n" + data;
data = "An error has occured. If this does not appear to be an issue you can easily remedy based on the information below, please contact Web Store technical support for additional assistance.\n\n" + data;
document.getElementById('progressbar').style.width = 0;
document.getElementById('stats').innerHTML = "";
document.getElementById('quip').innerHTML = "Error, install halted.";
alert(data);
}
//document.getElementById('waitbar').innerHTML = "end of function";
});
}
function runUpgrade(key)
{
if (prunning>2400)
{
clearInterval(pinttimer);
prunning=0;
alert("The install process has become unresponsive. This may indicate a problem with the database. Please contact technical support for additional information. Error information may be available in the xlsws_log table of your database for troubleshooting purposes.");
document.getElementById('progressbar').style.width = 0;
document.getElementById('stats').innerHTML = "Check xlsws_log for error information.";
document.getElementById('quip').innerHTML = "Error, install halted.";
}
if (prunning>0) { prunning++; return; }
prunning=1;
var postvar = "online="+ online + "&total=" + total +
"&dbname=" + "<?php echo $_POST['dbname'] ?>" +
"&dboldname=" + "<?php echo $_POST['dboldname'] ?>";
var exporturl = window.location.href.replace("/install.php", "/install/<?php echo strlen($_POST['dboldname']) > 0 ? 'upgrade' : 'install' ?>");
$.ajax({
url: exporturl,
type:'POST',data:postvar,
error: function(jqXHR, textStatus, errorThrown){
delay=delay+1000;
document.getElementById('quip').innerHTML = "Server appears to be throttling connections, setting delay to "+((delay-50)/1000)+ "seconds";
clearInterval(pinttimer);
pinttimer=self.setInterval(function(){runUpgrade(key)},delay);
prunning=0;
}
}).done(function(data){
if (data[0]=="{")
{
obj = JSON.parse(data);
if (obj.result=='success')
{
total = obj.total;
online = obj.makeline;
var perc = 50 + online;
document.getElementById('progressbar').style.width = perc + "%";
if (!obj.tag) obj.tag = "";
document.getElementById('stats').innerHTML = obj.tag;
<?php if(isset($_GET['debug'])): ?>
document.getElementById('stats').innerHTML = obj.tag + " at " + " (" + perc + "%)";
<?php endif; ?>
if (online==obj.total) {
clearInterval(pinttimer);
window.location.href = window.location.href.replace("/install.php", "/admin/license");
}
else
{
prunning=0;
}
}
else
{
clearInterval(pinttimer);
alert(obj.result);
}
}
else
{
clearInterval(pinttimer);
alert(data);
}
});
}
startInstall();
</script>
<?php
displayFooter();
}
function displayHeader()
{
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web Store Installation</title>
<link rel="stylesheet" href="http://cdn.lightspeedretail.com/bootstrap/css/bootstrap.css">
<style type="text/css">
.header-new {
background: url("http://www.lightspeedretail.com/wp-content/themes/lightspeed/images/bg-header.jpg") repeat scroll 0 0 transparent;
height: 80px;
position: relative;
width: 100%;
z-index: 999;
}
.header-inner {margin: 0 auto; width: 960px; }
.header-new .logo { float: left; padding: 24px 0 0 10px; width: 15%; }
.header-inner .logo a { width: 30px; height: 37px; }
.header-inner .logo a path.logo-flame { fill: #ed5153; }
.header-new .welcome { float: right; padding: 30px 20px 20px 10px; font-size: 28px; }
.table { width: 700px; margin: 0 auto; }
.hero-unit { padding: 20px; }
.hero-unit p { font-size: 0.9em; }
#stats { font-size: 0.7em; }
</style>
<script src="http://cdn.lightspeedretail.com/bootstrap/js/jquery.min.js"></script>
<script src="http://cdn.lightspeedretail.com/bootstrap/js/bootstrap.js"></script>
</head>
<body>
<div class="header-new">
<div class="header-inner">
<div class="logo">
<a class="navigation-secondary-logo" href="https://www.lightspeedhq.com/" rel="home" title="Lightspeed POS">
<svg class="logo-primary" viewBox="0 0 475 110" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<path class="logo-flame" d="M36.9,0.9 L41.9,9.6 C42.9,11.4 42.9,13.6 41.9,15.4 L12.1,67.1 L26.2,91.5 C28.4,95.3 32.5,97.7 36.9,97.7 C41.3,97.7 45.4,95.3 47.6,91.5 L61.7,67.1 L58,60.5 L42,88.2 C41,90 39,91.1 37,91.1 C34.9,91.1 33,90 32,88.2 L19.7,67.1 L47.4,19.1 L52.4,27.8 C53.4,29.6 53.4,31.8 52.4,33.6 L33.1,67.1 L36.9,73.7 L57.9,37.3 L71.7,61.2 C73.8,64.9 73.8,69.4 71.7,73.1 L57.7,97.4 C55.6,101.1 48.9,109.4 36.9,109.4 C24.9,109.4 18.3,101.1 16.1,97.4 L2.1,73.1 C-8.43769499e-15,69.4 -8.43769499e-15,64.9 2.1,61.2 L36.9,0.9"></path>
<g class="logo-text" transform="translate(102.000000, 25.000000)">
<rect x="0" y="1.8" width="9.7" height="57.3"></rect>
<circle cx="22.7" cy="6.6" r="5.7"></circle>
<rect x="17.8" y="19.3" width="9.8" height="39.8"></rect>
<path d="M53.3,18.3 C42.2,18.3 33.2,26.1 33.2,38.5 C33.2,50.9 41,58.5 53.4,58.5 C58.3,58.5 63.5,61 63.5,66.5 C63.5,72 59.1,75.1 53.4,75.1 C47.7,75.1 43,71.7 43,66.5 L33.2,66.5 C33.2,77.2 41.8,84.3 53.4,84.3 C64.9,84.3 73.3,77.5 73.3,66.5 C73.3,61.4 71.7,56.6 65.1,53.3 C71.6,50.3 73.5,43.4 73.5,38.4 C73.5,26.1 64.4,18.3 53.3,18.3 L53.3,18.3 Z M53.4,50.4 C47.7,50.4 43,45.5 43,38.5 C43,31.6 47.7,26.5 53.4,26.5 C59.1,26.5 63.7,31.7 63.7,38.5 C63.7,45.4 59,50.4 53.4,50.4 L53.4,50.4 Z"></path>
<path d="M101.9,18.3 C97.4,18.3 93.1,19.7 89.5,24.2 L89.5,1.7 L79.7,1.7 L79.7,59 L89.5,59 L89.5,38.8 C89.5,32.9 93.5,28 99.3,28 C104.5,28 108.3,31.1 108.3,38.3 L108.3,59 L118.1,59 L118.1,37.6 C118.2,25.9 113.2,18.3 101.9,18.3 L101.9,18.3 Z"></path>
<path d="M142,52.3 C140.8,52.3 139.8,51.9 139.2,51.1 C138.6,50.3 138.3,49.1 138.3,47.3 L138.3,27.7 L146.2,27.7 L147.1,19.2 L138.4,19.2 L138.4,8.3 L128.5,9.4 L128.5,19.3 L121,19.3 L121,27.8 L128.5,27.8 L128.5,47.6 C128.5,51.7 129.5,54.8 131.4,56.9 C133.3,59 136.2,60.1 139.9,60.1 C141.6,60.1 143.2,59.9 144.9,59.4 C146.6,58.9 148.1,58.2 149.4,57.3 L146,51 C144.7,51.9 143.3,52.3 142,52.3 L142,52.3 Z"></path>
<path d="M182.3,37.7 C178.3,35.2 173.6,34.9 169,34.6 C166.3,34.4 162.2,33.8 162.2,30.3 C162.2,27.8 164.8,26.4 169.5,26.4 C173.3,26.4 176.6,27.3 179.4,29.9 L184.9,23.5 C180.3,19.5 175.6,18.3 169.3,18.3 C162,18.3 152.4,21.5 152.4,30.7 C152.4,34.5 154.4,38 157.7,40 C161.4,42.3 166.2,42.6 170.3,43.1 C173.1,43.4 177.7,44.1 176.9,48 C176.4,50.7 173.1,51.5 170.8,51.6 C168.3,51.7 165.8,51.5 163.3,50.9 C160.7,50.2 158.6,49 156.3,47.5 L151.3,53.8 C151.6,54 151.9,54.3 151.9,54.3 C158.3,59.6 167.2,61.3 175.3,59.5 C181.4,58.1 186.6,53.7 186.6,47.1 C186.8,43.4 185.6,39.7 182.3,37.7 L182.3,37.7 Z"></path>
<path d="M214.6,18.3 C210.1,18.3 204.8,20.2 201.7,24.6 L201.4,19.2 L191.9,19.2 L191.9,76.5 L201.7,75.4 L201.7,54.4 C204.5,58.7 210.6,60.1 214.8,60.1 C227.5,60.1 234.9,50.6 234.9,39.1 C234.9,27.4 226.8,18.3 214.6,18.3 L214.6,18.3 Z M213.8,51.6 C207.1,51.6 202.6,45.5 202.6,39.3 C202.6,33.1 206.8,26.5 213.8,26.5 C220.9,26.5 225,33.2 225,39.3 C225.1,45.5 220.5,51.6 213.8,51.6 L213.8,51.6 Z"></path>
<path d="M247.7,42.7 C248.8,47.4 253.1,51.5 260.1,51.5 C263.7,51.5 268.5,49.7 270.8,47.4 L277.1,53.6 C272.9,57.9 266,60 260,60 C247.6,60 238.6,51.8 238.6,39.1 C238.6,27.1 247.9,18.3 259.3,18.3 C271.3,18.3 281.3,26.5 280.3,42.7 L247.7,42.7 L247.7,42.7 Z M270.8,35.2 C269.7,30.5 265,26.4 259.3,26.4 C254,26.4 249.1,30 247.7,35.2 L270.8,35.2 L270.8,35.2 Z"></path>
<path d="M293.1,42.7 C294.2,47.4 298.5,51.5 305.5,51.5 C309.1,51.5 313.9,49.7 316.2,47.4 L322.5,53.6 C318.3,57.9 311.4,60 305.4,60 C293,60 284,51.8 284,39.1 C284,27.1 293.3,18.3 304.7,18.3 C316.7,18.3 326.7,26.5 325.7,42.7 L293.1,42.7 L293.1,42.7 Z M316.3,35.2 C315.2,30.5 310.5,26.4 304.8,26.4 C299.5,26.4 294.6,30 293.2,35.2 L316.3,35.2 L316.3,35.2 Z"></path>
<path d="M349.4,60.1 C353.9,60.1 359.2,58.2 362.3,53.8 L362.6,59.1 L372.1,59.1 L372.1,1.8 L362.3,1.8 L362.3,24 C359.5,19.7 353.3,18.4 349.1,18.4 C336.4,18.4 329.1,27.8 329.1,39.4 C329.1,51 337.2,60.1 349.4,60.1 L349.4,60.1 Z M350.1,26.8 C356.8,26.8 361.3,32.9 361.3,39.1 C361.3,45.3 357.1,51.9 350.1,51.9 C343,51.9 338.9,45.2 338.9,39.1 C338.9,32.9 343.4,26.8 350.1,26.8 L350.1,26.8 Z"></path>
</g>
</svg>
</a>
</div>
<div class="welcome">Web Store Installation</div>
</div>
</div>
<div class="container">
<?php
}
function displayFooter()
{
?>
<script>
$('#installform').submit(validate);
function validate(){
var dbhost = $('#dbhost').val();
if (!$.trim(dbhost)) {alert('Database Host is required!'); return false; }
var dbuser = $('#dbuser').val();
if (!$.trim(dbuser)) {alert('Database Username is required!'); return false; }
var dbpass = $('#dbpass').val();
if (!$.trim(dbpass)) {alert('Database Password is required!'); return false; }
var dbname = $('#dbname').val();
if (!$.trim(dbname)) {alert('Database name is required!'); return false; }
}
</script>
</body>
</html>
<?php
}
function writeDB($dbhost,$dbuser,$dbpass,$dbname)
{
if (strlen($dbhost)==0 || strlen($dbuser)==0 || strlen($dbname)==0 || strlen($dbpass)==0)
return json_encode(array('result'=>"Database connection info missing."));
$strtoexport = "<?php
return array(
'connectionString' => 'mysql:host=".$dbhost.";dbname=".$dbname."',
'emulatePrepare' => true,
'username' => '".$dbuser."',
'password' => '".$dbpass."',
'charset' => 'utf8',
'tablePrefix'=>'xlsws_',
'schemaCachingDuration'=>30,
);";
@mkdir("config",0755,true);
$fp2 = fopen("config/wsdb.php","w");
if ($fp2 === false) die("Error, can't write file config/wsdb.php");
fwrite($fp2,$strtoexport);
fclose($fp2);
}
class DB_Class {
var $db;
var $olddb;
var $newdb;
var $schemaNumber = 0;
public function __construct($servername, $dbuser, $dbpassword, $dbname) {
$this->db = new mysqli($servername, $dbuser, $dbpassword);
if (!$this->db)
{ error_log("Unable to connect to Database Server. Invalid server, username or password.",3,"errorlog.txt");
echo("Unable to connect to Database Server. Invalid server, username or password."); die(); }
$this->newdb = $dbname;
}
public function changedb($to)
{
if ($to=="old")
{
$blnSuccess =$this->db->select_db($this->olddb);
if (!$blnSuccess)
{
error_log("Cannot find or use \"".$this->olddb."\" database to upgrade.", 3, "errorlog.txt");
echo ("Cannot find or use \"".$this->olddb."\" database to upgrade.");
die();
}
$this->getSchema();
}
if ($to=="new")
{
$blnSuccess =$this->db->select_db($this->newdb);
if (!$blnSuccess)
{
error_log("Cannot find or use \"".$this->newdb."\" database. Make sure it has been created and is blank", 3, "errorlog.txt");
echo ("Cannot find or use \"".$this->newdb."\" database. Make sure it has been created and is blank.");
die();
}
$this->getSchema();
}
}
public function getSchema()
{
$res = $this->fetch("show tables");
$tablenames= array();
foreach ($res as $row=>$value)
foreach ($value as $k=>$v)
$tablenames[] = $v;
if (in_array('xlsws_configuration',$tablenames))
{
$res = $this->fetch("SHOW COLUMNS FROM xlsws_configuration" );
foreach ($res as $row) $fieldnames[] = $row['Field'];
if(in_array('key',$fieldnames)) $kn = "key";
if(in_array('key_name',$fieldnames)) $kn = "key_name";
if(in_array('value',$fieldnames)) $vn = "value";
if(in_array('key_value',$fieldnames)) $vn = "key_value";
$res = $this->fetch("select `".$vn."` as id from xlsws_configuration where `".$kn."`='DATABASE_SCHEMA_VERSION'");
if (isset($res[0]))
$this->schemaNumber=$res[0]['id'];
else $this->schemaNumber=0;
} else $this->schemaNumber=0;
}
public function query($sql) {
if(!empty($sql))
{
$result = $this->db->query($sql) or die("Invalid query: " . $this->db->error."\n\nwhen attemping to run ".$sql);
return $result;
}
else return;
}
public function fetch($sql) {
$data = array();
$result = $this->query($sql);
while ($row = $result->fetch_array()){
$data[] = $row;
}
return $data;
}
public function add_index($table,$indexname) {
$res = $this->fetch("SHOW INDEXES FROM $table WHERE key_name='$indexname'" );
if($res) return false; //index already exists
$this->query("ALTER TABLE `$table` ADD INDEX `$indexname` (`$indexname`)");
return true;
}
public function add_column($table , $column , $create_sql , $version = false) {
$res = $this->fetch("SHOW COLUMNS FROM $table WHERE Field='$column'" );
if($res) return false;
$this->query($create_sql);
return true;
}
public function check_column_type($table , $column , $type , $misc ,$version = false){
$res = $this->fetch("SHOW COLUMNS FROM $table WHERE Field='$column'" );
if(!$res) return;
$ctype = $res[0]['Type'];
if($ctype != $type)
$this->query("ALTER TABLE `$table` CHANGE `$column` `$column` $type $misc ;");
}
//title,key,value,helper,config,sort,options
public function add_config_key($key,$title,$value,$helper,$config,$sort,$options = null, $template_specific=0, $param=1,$required=null)
{
$res = $this->fetch("SHOW COLUMNS FROM xlsws_configuration" );
foreach ($res as $row) $fields[] = $row['Field'];
if(in_array('key',$fields)) $kn = "key";
if(in_array('key_name',$fields)) $kn = "key_name";
if(in_array('value',$fields)) $vn = "value";
if(in_array('key_value',$fields)) $vn = "key_value";
$conf = $this->fetch("select * from xlsws_configuration where `".$kn."`='".$key."'");
if(!$conf)
{
$res = $this->fetch("SHOW COLUMNS FROM xlsws_configuration" );
foreach ($res as $row) $fieldnames[] = $row['Field'];
$sql = "insert into xlsws_configuration set title='".mysqli_real_escape_string($this->db,$title)."' ";
if(in_array('key',$fieldnames)) $sql .= ", `key`='$key' ";
if(in_array('key_name',$fieldnames)) $sql .= ", `key_name`='$key' ";
if(in_array('value',$fieldnames)) $sql .= ", `value`='$value' ";
if(in_array('key_value',$fieldnames)) $sql .= ", `key_value`='$value' ";
$sql .= ",helper_text='".mysqli_real_escape_string($this->db,$helper)."', `configuration_type_id`='$config', `sort_order`='$sort' ";
if(!is_null($options)) $sql .= ", `options`='".$options."'";
if(in_array('template_specific',$fieldnames)) $sql .= ", `template_specific`=".$template_specific;
if(in_array('param',$fieldnames)) $sql .= ", `param`=".$param;
if(in_array('required',$fieldnames) && !is_null($required)) $sql .= ", `required`=".$required;
$sql .= ", `created`='".date("Y-m-d H:i:s")."'";
$this->query($sql);
}
}
public function add_table($table , $create_sql , $version = false){
$res = $this->fetch("show tables");
foreach ($res as $row=>$value)
foreach ($value as $k=>$v)
$fieldnames[] = $v;
if(!in_array($table,$fieldnames)){
$this->query($create_sql);
}
}
public function update_row($table , $key_column , $key , $value_column , $value , $version = false){
$sql = "UPDATE $table SET $value_column = $value WHERE $key_column = $key ";
$this->query($sql);
}
}
function downloadFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progressCallback');
if(stripos($url,".zip") !== false)
curl_setopt($ch, CURLOPT_NOPROGRESS, false); // needed to make progress function work
else
curl_setopt($ch, CURLOPT_NOPROGRESS, true); // needed to make progress function work
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$resp = curl_exec($ch);
curl_close($ch);
return $resp;
}
function progressCallback( $download_size, $downloaded, $upload_size, $uploaded_size )
{
if ($download_size == 0)
$progress = 1;
else
$progress = round( ($downloaded / $download_size * 100 ),0);
file_put_contents("progress.txt",$progress);
}
function downloadLatest()
{
if(isset($_POST['debug'])) error_log(__FUNCTION__,3,"error.txt");
//if we've already downloaded and extracted, don't do it twice
if (!file_exists('core') && !file_exists('webstore.zip'))
{
$dest = (isset($_POST['qa']) ? "qa/".$_POST['qa'] : "latestwebstore");
$cdn = (isset($_POST['qa']) ? "webstore-qa" : "webstore-full");
$jLatest= downloadFile("http://updater.lightspeedretail.com/site/".$dest);
$result = json_decode($jLatest);
$strWebstoreInstall = "http://cdn.lightspeedretail.com/webstore/".$cdn."/".$result->latest->filename;
if(isset($_POST['debug'])) error_log("downloading $strWebstoreInstall",3,"error.txt");
$data = downloadFile($strWebstoreInstall);
if (stripos($data,"404 - Not Found")>0 || empty($data))
echo("ERROR downloading ".$result->latest->filename." from Lightspeed");
if(isset($_POST['debug'])) error_log("writing to to".$result->latest->filename,3,"error.txt");
$f=file_put_contents("webstore.zip", $data);
if(isset($_POST['debug'])) error_log("wrote to".$result->latest->filename,3,"error.txt");
if ($f)
{
if(!isset($_POST['debug'])) @unlink("progress.txt");
}
else {
echo("ERROR downloading ".$result->latest->filename." from Lightspeed");
}
}
}
function zipAndFolders()
{
if(isset($_POST['debug'])) error_log(__FUNCTION__,3,"error.txt");
//if we've already downloaded and extracted, don't do it twice
if (!file_exists('core') && file_exists("webstore.zip"))
{
if(isset($_POST['debug'])) error_log("decompressing webstore.zip",3,"error.txt");
decompress("webstore.zip");
if(isset($_POST['debug'])) error_log("removing webstore.zip",3,"error.txt");
if(!isset($_POST['debug'])) @unlink("webstore.zip");
}
// Verify the cache folders exist and if not, create them
// These may fail if cache isn't yet writable, so we ignore errors
// and will get them again after fixing cache
if (!file_exists('assets')) {
@mkdir('assets');
}
if (!file_exists('runtime')) {
@mkdir('runtime');
}
if (!file_exists('runtime/cache')) {
@mkdir('runtime/cache');
}
if (!file_exists('themes')) {
@mkdir('themes');
}
}
/**
* This is actually a copy of our zip.php from Web store from Florian
* This violates our DRY principle but we need everything in the installer
* @param string $zipFile
* @param string $dirFromZip
* @param null $zipDir
* @return bool
*/