/
install_utils.php
executable file
·2306 lines (2008 loc) · 80.2 KB
/
install_utils.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
/**
*
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
* Copyright (C) 2011 - 2018 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
*/
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
require_once('include/utils/php_zip_utils.php');
require_once('include/upload_file.php');
////////////////
//// GLOBAL utility
/**
* Calls a custom function (if it exists) based on the first parameter,
* and returns result of function call, or 'undefined' if the function doesn't exist
* @param string function name to call in custom install hooks
* @return mixed function call result, or 'undefined'
*/
function installerHook($function_name, $options = array())
{
if (!isset($GLOBALS['customInstallHooksExist'])) {
if (file_exists('custom/install/install_hooks.php')) {
installLog("installerHook: Found custom/install/install_hooks.php");
require_once('custom/install/install_hooks.php');
$GLOBALS['customInstallHooksExist'] = true;
} else {
installLog("installerHook: Info: custom/install/install_hooks.php not present, no custom hooks to execute");
$GLOBALS['customInstallHooksExist'] = false;
}
}
if ($GLOBALS['customInstallHooksExist'] === false) {
return 'undefined';
} else {
if (function_exists($function_name)) {
installLog("installerHook: function {$function_name} found, calling and returning the return value");
return $function_name($options);
} else {
installLog("installerHook: function {$function_name} not found in custom install hooks file");
return 'undefined';
}
}
}
///////////////////////////////////////////////////////////////////////////////
//// FROM welcome.php
/**
* returns lowercase lang encoding
* @return string encoding or blank on false
*/
function parseAcceptLanguage()
{
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (strpos($lang, ';')) {
$exLang = explode(';', $lang);
return strtolower(str_replace('-', '_', $exLang[0]));
} else {
$match = array();
if (preg_match("#\w{2}\-?\_?\w{2}#", $lang, $match)) {
return strtolower(str_replace('-', '_', $match[0]));
}
}
return '';
}
///////////////////////////////////////////////////////////////////////////////
//// FROM localization.php
/**
* copies the temporary unzip'd files to their final destination
* removes unzip'd files from system if $uninstall=true
* @param bool uninstall true if uninstalling a language pack
* @return array sugar_config
*/
function commitLanguagePack($uninstall=false)
{
global $sugar_config;
global $mod_strings;
global $base_upgrade_dir;
global $base_tmp_upgrade_dir;
$errors = array();
$manifest = urldecode($_REQUEST['manifest']);
$zipFile = urldecode($_REQUEST['zipFile']);
$version = "";
$show_files = true;
$unzip_dir = mk_temp_dir($base_tmp_upgrade_dir);
$zip_from_dir = ".";
$zip_to_dir = ".";
$zip_force_copy = array();
if ($uninstall == false && isset($_SESSION['INSTALLED_LANG_PACKS']) && in_array($zipFile, $_SESSION['INSTALLED_LANG_PACKS'])) {
return;
}
// unzip lang pack to temp dir
if (isset($zipFile) && !empty($zipFile)) {
if (is_file($zipFile)) {
unzip($zipFile, $unzip_dir);
} else {
echo $mod_strings['ERR_LANG_MISSING_FILE'].$zipFile;
die(); // no point going any further
}
}
// filter for special to/from dir conditions (langpacks generally don't have them)
if (isset($manifest) && !empty($manifest)) {
if (is_file($manifest)) {
include($manifest);
if (isset($manifest['copy_files']['from_dir']) && $manifest['copy_files']['from_dir'] != "") {
$zip_from_dir = $manifest['copy_files']['from_dir'];
}
if (isset($manifest['copy_files']['to_dir']) && $manifest['copy_files']['to_dir'] != "") {
$zip_to_dir = $manifest['copy_files']['to_dir'];
}
if (isset($manifest['copy_files']['force_copy']) && $manifest['copy_files']['force_copy'] != "") {
$zip_force_copy = $manifest['copy_files']['force_copy'];
}
if (isset($manifest['version'])) {
$version = $manifest['version'];
}
} else {
$errors[] = $mod_strings['ERR_LANG_MISSING_FILE'].$manifest;
}
}
// find name of language pack: find single file in include/language/xx_xx.lang.php
$d = dir("$unzip_dir/$zip_from_dir/include/language");
while ($f = $d->read()) {
if ($f == "." || $f == "..") {
continue;
} else {
if (preg_match("/(.*)\.lang\.php\$/", $f, $match)) {
$new_lang_name = $match[1];
}
}
}
if ($new_lang_name == "") {
die($mod_strings['ERR_LANG_NO_LANG_FILE'].$zipFile);
}
$new_lang_desc = getLanguagePackName("$unzip_dir/$zip_from_dir/include/language/$new_lang_name.lang.php");
if ($new_lang_desc == "") {
die("No language pack description found at include/language/$new_lang_name.lang.php inside $install_file.");
}
// add language to available languages
$sugar_config['languages'][$new_lang_name] = ($new_lang_desc);
// get an array of all files to be moved
$filesFrom = array();
$filesFrom = findAllFiles($unzip_dir, $filesFrom);
///////////////////////////////////////////////////////////////////////////
//// FINALIZE
if ($uninstall) {
// unlink all pack files
foreach ($filesFrom as $fileFrom) {
//echo "deleting: ".getcwd().substr($fileFrom, strlen($unzip_dir), strlen($fileFrom))."<br>";
@unlink(getcwd().substr($fileFrom, strlen($unzip_dir), strlen($fileFrom)));
}
// remove session entry
if (isset($_SESSION['INSTALLED_LANG_PACKS']) && is_array($_SESSION['INSTALLED_LANG_PACKS'])) {
foreach ($_SESSION['INSTALLED_LANG_PACKS'] as $k => $langPack) {
if ($langPack == $zipFile) {
unset($_SESSION['INSTALLED_LANG_PACKS'][$k]);
unset($_SESSION['INSTALLED_LANG_PACKS_VERSION'][$k]);
unset($_SESSION['INSTALLED_LANG_PACKS_MANIFEST'][$k]);
$removedLang = $k;
}
}
// remove language from config
$new_langs = array();
$old_langs = $sugar_config['languages'];
foreach ($old_langs as $key => $value) {
if ($key != $removedLang) {
$new_langs += array( $key => $value );
}
}
$sugar_config['languages'] = $new_langs;
}
} else {
// copy filesFrom to filesTo
foreach ($filesFrom as $fileFrom) {
@copy($fileFrom, getcwd().substr($fileFrom, strlen($unzip_dir), strlen($fileFrom)));
}
$_SESSION['INSTALLED_LANG_PACKS'][$new_lang_name] = $zipFile;
$_SESSION['INSTALLED_LANG_PACKS_VERSION'][$new_lang_name] = $version;
$serial_manifest = array();
$serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
$serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
$serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
$_SESSION['INSTALLED_LANG_PACKS_MANIFEST'][$new_lang_name] = base64_encode(serialize($serial_manifest));
}
writeSugarConfig($sugar_config);
return $sugar_config;
}
function commitPatch($unlink = false, $type = 'patch')
{
require_once('ModuleInstall/ModuleInstaller.php');
require_once('include/entryPoint.php');
global $mod_strings;
global $base_upgrade_dir;
global $base_tmp_upgrade_dir;
$db = DBManagerFactory::getInstance();
$GLOBALS['db'] = $db;
$errors = array();
$files = array();
global $current_user;
$current_user = BeanFactory::newBean('Users');
$current_user->is_admin = '1';
$old_mod_strings = $mod_strings;
if (is_dir($base_upgrade_dir)) {
$files = findAllFiles("$base_upgrade_dir/$type", $files);
$mi = new ModuleInstaller();
$mi->silent = true;
$mod_strings = return_module_language('en', "Administration");
foreach ($files as $file) {
if (!preg_match('#.*\.zip\$#', $file)) {
continue;
}
// handle manifest.php
$target_manifest = remove_file_extension($file) . '-manifest.php';
include($target_manifest);
$unzip_dir = mk_temp_dir($base_tmp_upgrade_dir);
unzip($file, $unzip_dir);
if (file_exists("$unzip_dir/scripts/pre_install.php")) {
require_once("$unzip_dir/scripts/pre_install.php");
pre_install();
}
if (isset($manifest['copy_files']['from_dir']) && $manifest['copy_files']['from_dir'] != "") {
$zip_from_dir = $manifest['copy_files']['from_dir'];
}
$source = "$unzip_dir/$zip_from_dir";
$dest = getcwd();
copy_recursive($source, $dest);
if (file_exists("$unzip_dir/scripts/post_install.php")) {
require_once("$unzip_dir/scripts/post_install.php");
post_install();
}
$new_upgrade = new UpgradeHistory();
$new_upgrade->filename = $file;
$new_upgrade->md5sum = md5_file($file);
$new_upgrade->type = $manifest['type'];
$new_upgrade->version = $manifest['version'];
$new_upgrade->status = "installed";
//$new_upgrade->author = $manifest['author'];
$new_upgrade->name = $manifest['name'];
$new_upgrade->description = $manifest['description'];
$serial_manifest = array();
$serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
$serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
$serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
$new_upgrade->manifest = base64_encode(serialize($serial_manifest));
$new_upgrade->save();
unlink($file);
}//rof
}//fi
$mod_strings = $old_mod_strings;
}
function commitModules($unlink = false, $type = 'module')
{
require_once('ModuleInstall/ModuleInstaller.php');
require_once('include/entryPoint.php');
global $mod_strings;
global $base_upgrade_dir;
global $base_tmp_upgrade_dir;
$db = DBManagerFactory::getInstance();
$GLOBALS['db'] = $db;
$errors = array();
$files = array();
global $current_user;
$current_user = BeanFactory::newBean('Users');
$current_user->is_admin = '1';
$old_mod_strings = $mod_strings;
if (is_dir(sugar_cached("upload/upgrades"))) {
$files = findAllFiles(sugar_cached("upload/upgrades/$type"), $files);
$mi = new ModuleInstaller();
$mi->silent = true;
$mod_strings = return_module_language('en', "Administration");
foreach ($files as $file) {
if (!preg_match('#.*\.zip\$', $file)) {
continue;
}
$lic_name = 'accept_lic_'.str_replace('.', '_', urlencode(basename($file)));
$can_install = true;
if (isset($_REQUEST[$lic_name])) {
if ($_REQUEST[$lic_name] == 'yes') {
$can_install = true;
} else {
$can_install = false;
}
}
if ($can_install) {
// handle manifest.php
$target_manifest = remove_file_extension($file) . '-manifest.php';
if ($type == 'langpack') {
$_REQUEST['manifest'] = $target_manifest;
$_REQUEST['zipFile'] = $file;
commitLanguagePack();
continue;
}
include($target_manifest);
$unzip_dir = mk_temp_dir($base_tmp_upgrade_dir);
unzip($file, $unzip_dir);
$_REQUEST['install_file'] = $file;
$mi->install($unzip_dir);
$new_upgrade = new UpgradeHistory();
$new_upgrade->filename = $file;
$new_upgrade->md5sum = md5_file($file);
$new_upgrade->type = $manifest['type'];
$new_upgrade->version = $manifest['version'];
$new_upgrade->status = "installed";
// $new_upgrade->author = $manifest['author'];
$new_upgrade->name = $manifest['name'];
$new_upgrade->description = $manifest['description'];
$new_upgrade->id_name = (isset($installdefs['id_name'])) ? $installdefs['id_name'] : '';
$serial_manifest = array();
$serial_manifest['manifest'] = (isset($manifest) ? $manifest : '');
$serial_manifest['installdefs'] = (isset($installdefs) ? $installdefs : '');
$serial_manifest['upgrade_manifest'] = (isset($upgrade_manifest) ? $upgrade_manifest : '');
$new_upgrade->manifest = base64_encode(serialize($serial_manifest));
$new_upgrade->save();
//unlink($file);
}//fi
}//rof
}//fi
$mod_strings = $old_mod_strings;
}
/**
* creates UpgradeHistory entries
* @param mode string Install or Uninstall
*/
function updateUpgradeHistory()
{
if (isset($_SESSION['INSTALLED_LANG_PACKS']) && count($_SESSION['INSTALLED_LANG_PACKS']) > 0) {
foreach ($_SESSION['INSTALLED_LANG_PACKS'] as $k => $zipFile) {
$new_upgrade = new UpgradeHistory();
$new_upgrade->filename = $zipFile;
$new_upgrade->md5sum = md5_file($zipFile);
$new_upgrade->type = 'langpack';
$new_upgrade->version = $_SESSION['INSTALLED_LANG_PACKS_VERSION'][$k];
$new_upgrade->status = "installed";
$new_upgrade->manifest = $_SESSION['INSTALLED_LANG_PACKS_MANIFEST'][$k];
$new_upgrade->save();
}
}
}
/**
* removes the installed language pack, but the zip is still in the cache dir
*/
function removeLanguagePack()
{
global $mod_strings;
global $sugar_config;
$errors = array();
$manifest = urldecode($_REQUEST['manifest']);
$zipFile = urldecode($_REQUEST['zipFile']);
if (isset($manifest) && !empty($manifest)) {
if (is_file($manifest)) {
if (!unlink($manifest)) {
$errors[] = $mod_strings['ERR_LANG_CANNOT_DELETE_FILE'].$manifest;
}
} else {
$errors[] = $mod_strings['ERR_LANG_MISSING_FILE'].$manifest;
}
unset($_SESSION['packages_to_install'][$manifest]);
}
if (isset($zipFile) && !empty($zipFile)) {
if (is_file($zipFile)) {
if (!unlink($zipFile)) {
$errors[] = $mod_strings['ERR_LANG_CANNOT_DELETE_FILE'].$zipFile;
}
} else {
$errors[] = $mod_strings['ERR_LANG_MISSING_FILE'].$zipFile;
}
}
if (count($errors > 0)) {
echo "<p class='error'>";
foreach ($errors as $error) {
echo "{$error}<br>";
}
echo "</p>";
}
unlinkTempFiles($manifest, $zipFile);
}
/**
* takes the current value of $sugar_config and writes it out to config.php (sorta the same as the final step)
* @param array sugar_config
*/
function writeSugarConfig($sugar_config)
{
ksort($sugar_config);
$sugar_config_string = "<?php\n" .
'// created: ' . date('Y-m-d H:i:s') . "\n" .
'$sugar_config = ' .
var_export($sugar_config, true) .
";\n?>\n";
if (is_writable('config.php')) {
write_array_to_file("sugar_config", $sugar_config, "config.php");
}
}
/**
* uninstalls the Language pack
*/
function uninstallLangPack()
{
global $sugar_config;
// remove language from config
$new_langs = array();
$old_langs = $sugar_config['languages'];
foreach ($old_langs as $key => $value) {
if ($key != $_REQUEST['new_lang_name']) {
$new_langs += array( $key => $value );
}
}
$sugar_config['languages'] = $new_langs;
writeSugarConfig($sugar_config);
}
/**
* retrieves the name of the language
*/
if (!function_exists('getLanguagePackName')) {
function getLanguagePackName($the_file)
{
require_once((string)$the_file);
if (isset($app_list_strings["language_pack_name"])) {
return($app_list_strings["language_pack_name"]);
}
return("");
}
}
function getInstalledLangPacks($showButtons=true)
{
global $mod_strings;
global $next_step;
$ret = "<tr><td colspan=7 align=left>{$mod_strings['LBL_LANG_PACK_INSTALLED']}</td></tr>";
//$ret .="<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
$ret .= "<tr>
<td width='15%' ><b>{$mod_strings['LBL_ML_NAME']}</b></td>
<td width='15%' ><b>{$mod_strings['LBL_ML_VERSION']}</b></td>
<td width='15%' ><b>{$mod_strings['LBL_ML_PUBLISHED']}</b></td>
<td width='15%' ><b>{$mod_strings['LBL_ML_UNINSTALLABLE']}</b></td>
<td width='15%' ><b>{$mod_strings['LBL_ML_DESCRIPTION']}</b></td>
<td width='15%' ></td>
<td width='15%' ></td>
</tr>\n";
$files = array();
$files = findAllFiles(sugar_cached("upload/upgrades"), $files);
if (isset($_SESSION['INSTALLED_LANG_PACKS']) && !empty($_SESSION['INSTALLED_LANG_PACKS'])) {
if (count($_SESSION['INSTALLED_LANG_PACKS'] > 0)) {
foreach ($_SESSION['INSTALLED_LANG_PACKS'] as $file) {
// handle manifest.php
$target_manifest = remove_file_extension($file) . '-manifest.php';
include($target_manifest);
$name = empty($manifest['name']) ? $file : $manifest['name'];
$version = empty($manifest['version']) ? '' : $manifest['version'];
$published_date = empty($manifest['published_date']) ? '' : $manifest['published_date'];
$icon = '';
$description = empty($manifest['description']) ? 'None' : $manifest['description'];
$uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes';
$manifest_type = $manifest['type'];
$deletePackage = getPackButton('uninstall', $target_manifest, $file, $next_step, $uninstallable, $showButtons);
//$ret .="<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
$ret .= "<tr>";
$ret .= "<td width='15%' >".$name."</td>";
$ret .= "<td width='15%' >".$version."</td>";
$ret .= "<td width='15%' >".$published_date."</td>";
$ret .= "<td width='15%' >".$uninstallable."</td>";
$ret .= "<td width='15%' >".$description."</td>";
$ret .= "<td width='15%' ></td>";
$ret .= "<td width='15%' >{$deletePackage}</td>";
$ret .= "</tr>";
}
} else {
$ret .= "</tr><td colspan=7><i>{$mod_strings['LBL_LANG_NO_PACKS']}</i></td></tr>";
}
} else {
$ret .= "</tr><td colspan=7><i>{$mod_strings['LBL_LANG_NO_PACKS']}</i></td></tr>";
}
return $ret;
}
function uninstallLanguagePack()
{
return commitLanguagePack(true);
}
function getSugarConfigLanguageArray($langZip)
{
global $sugar_config;
include(remove_file_extension($langZip)."-manifest.php");
$ret = '';
if (isset($installdefs['id']) && isset($manifest['name'])) {
$ret = $installdefs['id']."::".$manifest['name']."::".$manifest['version'];
}
return $ret;
}
///////////////////////////////////////////////////////////////////////////////
//// FROM performSetup.php
function getInstallDbInstance()
{
return DBManagerFactory::getTypeInstance($_SESSION['setup_db_type'], array("db_manager" => $_SESSION['setup_db_manager']));
}
function getDbConnection()
{
$dbconfig = array(
"db_host_name" => $_SESSION['setup_db_host_name'],
"db_user_name" => $_SESSION['setup_db_admin_user_name'],
"db_password" => $_SESSION['setup_db_admin_password'],
"db_host_instance" => $_SESSION['setup_db_host_instance'],
"db_port" => $_SESSION['setup_db_port_num'],
);
if (empty($_SESSION['setup_db_create_database'])) {
$dbconfig["db_name"] = $_SESSION['setup_db_database_name'];
$dbconfig["db_user_name"] = $_SESSION['setup_db_sugarsales_user'];
$dbconfig["db_password"] = $_SESSION['setup_db_sugarsales_password'];
}
$db = getInstallDbInstance();
if (!empty($_SESSION['setup_db_options'])) {
$db->setOptions($_SESSION['setup_db_options']);
}
$db->connect($dbconfig, true);
return $db;
}
/**
* creates the Sugar DB user (if not admin)
*/
function handleDbCreateSugarUser()
{
global $mod_strings;
global $setup_db_database_name;
global $setup_db_host_name;
global $setup_db_host_instance;
global $setup_db_port_num;
global $setup_db_admin_user_name;
global $setup_db_admin_password;
global $sugar_config;
global $setup_db_sugarsales_user;
global $setup_site_host_name;
global $setup_db_sugarsales_password;
echo $mod_strings['LBL_PERFORM_CREATE_DB_USER'];
$db = getDbConnection();
$db->createDbUser($setup_db_database_name, $setup_site_host_name, $setup_db_sugarsales_user, $setup_db_sugarsales_password);
$err = $db->lastError();
if ($err == '') {
echo $mod_strings['LBL_PERFORM_DONE'];
} else {
echo "<div style='color:red;'>";
echo "An error occurred when creating user:<br>";
echo "$err<br>";
echo "</div>";
installLog("An error occurred when creating user: $err");
}
}
/**
* ensures that the charset and collation for a given database is set
* MYSQL ONLY
*/
function handleDbCharsetCollation()
{
global $mod_strings;
global $setup_db_database_name;
global $setup_db_host_name;
global $setup_db_admin_user_name;
global $setup_db_admin_password;
global $sugar_config;
if ($_SESSION['setup_db_type'] == 'mysql') {
$db = getDbConnection();
$db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8", true);
$db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci", true);
}
}
/**
* creates the new database
*/
function handleDbCreateDatabase()
{
global $mod_strings;
global $setup_db_database_name;
global $setup_db_host_name;
global $setup_db_host_instance;
global $setup_db_port_num;
global $setup_db_admin_user_name;
global $setup_db_admin_password;
global $sugar_config;
echo "{$mod_strings['LBL_PERFORM_CREATE_DB_1']} {$setup_db_database_name} {$mod_strings['LBL_PERFORM_CREATE_DB_2']} {$setup_db_host_name}...";
$db = getDbConnection();
if ($db->dbExists($setup_db_database_name)) {
$db->dropDatabase($setup_db_database_name);
}
$db->createDatabase($setup_db_database_name);
echo $mod_strings['LBL_PERFORM_DONE'];
}
/**
* handles creation of Log4PHP properties file
* This function has been deprecated. Use SugarLogger.
*/
function handleLog4Php()
{
return;
}
function installLog($entry)
{
global $mod_strings;
$nl = '
'.gmdate("Y-m-d H:i:s").'...';
$log = clean_path(getcwd().'/install.log');
// create if not exists
if (!file_exists($log)) {
$fp = @sugar_fopen($log, 'w+'); // attempts to create file
if (!is_resource($fp)) {
$GLOBALS['log']->fatal('could not create the install.log file');
}
} else {
$fp = @sugar_fopen($log, 'a+'); // write pointer at end of file
if (!is_resource($fp)) {
$GLOBALS['log']->fatal('could not open/lock install.log file');
}
}
if (@fwrite($fp, $nl.$entry) === false) {
$GLOBALS['log']->fatal('could not write to install.log: '.$entry);
}
if (is_resource($fp)) {
fclose($fp);
}
}
/**
* takes session vars and creates config.php
* @return array bottle collection of error messages
*/
function handleSugarConfig()
{
global $bottle;
global $cache_dir;
global $mod_strings;
global $setup_db_host_name;
global $setup_db_host_instance;
global $setup_db_port_num;
global $setup_db_sugarsales_user;
global $setup_db_sugarsales_password;
global $setup_db_database_name;
global $setup_site_host_name;
global $setup_site_log_dir;
global $setup_site_log_file;
global $setup_site_session_path;
global $setup_site_guid;
global $setup_site_url;
global $setup_sugar_version;
global $sugar_config;
global $setup_site_log_level;
echo "<b>{$mod_strings['LBL_PERFORM_CONFIG_PHP']} (config.php)</b><br>";
///////////////////////////////////////////////////////////////////////////////
//// $sugar_config SETTINGS
if (is_file('config.php')) {
$is_writable = is_writable('config.php');
// require is needed here (config.php is sometimes require'd from install.php)
require('config.php');
} else {
$is_writable = is_writable('.');
}
// build default sugar_config and merge with new values
$sugar_config = sugarArrayMerge(get_sugar_config_defaults(), $sugar_config);
// always lock the installer
$sugar_config['installer_locked'] = true;
// we're setting these since the user was given a fair chance to change them
$sugar_config['dbconfig']['db_host_name'] = $setup_db_host_name;
if (!empty($setup_db_host_instance)) {
$sugar_config['dbconfig']['db_host_instance'] = $setup_db_host_instance;
} else {
$sugar_config['dbconfig']['db_host_instance'] = '';
}
if (!isset($_SESSION['setup_db_manager'])) {
$_SESSION['setup_db_manager'] = DBManagerFactory::getManagerByType($_SESSION['setup_db_type']);
}
$sugar_config['dbconfig']['db_user_name'] = $setup_db_sugarsales_user;
$sugar_config['dbconfig']['db_password'] = $setup_db_sugarsales_password;
$sugar_config['dbconfig']['db_name'] = $setup_db_database_name;
$sugar_config['dbconfig']['db_type'] = $_SESSION['setup_db_type'];
$sugar_config['dbconfig']['db_port'] = $setup_db_port_num;
$sugar_config['dbconfig']['db_manager'] = $_SESSION['setup_db_manager'];
if (!empty($_SESSION['setup_db_options'])) {
$sugar_config['dbconfigoption'] = array_merge($sugar_config['dbconfigoption'], $_SESSION['setup_db_options']);
}
$sugar_config['dbconfig']['collation'] = $_SESSION['setup_db_collation'];
$sugar_config['dbconfig']['charset'] = $_SESSION['setup_db_charset'];
$sugar_config['cache_dir'] = $cache_dir;
$sugar_config['default_charset'] = $mod_strings['DEFAULT_CHARSET'];
$sugar_config['default_email_client'] = 'sugar';
$sugar_config['default_email_editor'] = 'html';
$sugar_config['host_name'] = $setup_site_host_name;
$sugar_config['js_custom_version'] = '';
$sugar_config['use_real_names'] = true;
$sugar_config['disable_convert_lead'] = false;
$sugar_config['log_dir'] = $setup_site_log_dir;
$sugar_config['log_file'] = $setup_site_log_file;
$sugar_config['enable_line_editing_detail'] = true;
$sugar_config['enable_line_editing_list'] = true;
$sugar_config['filter_module_fields'] = array(
'Users' => array(
'show_on_employees',
'portal_only',
'is_group',
'system_generated_password',
'external_auth_only',
'sugar_login',
'authenticate_id',
'pwd_last_changed',
'is_admin',
'user_name',
'user_hash',
'password',
'last_login',
'oauth_tokens',
),
'Employees' => array(
'show_on_employees',
'portal_only',
'is_group',
'system_generated_password',
'external_auth_only',
'sugar_login',
'authenticate_id',
'pwd_last_changed',
'is_admin',
'user_name',
'user_hash',
'password',
'last_login',
'oauth_tokens',
)
);
$sugar_config['hide_subpanels'] = true;
// Setup FTS
if (!empty($_SESSION['setup_fts_type'])) {
$sugar_config['full_text_engine'] = array(
$_SESSION['setup_fts_type'] => getFtsSettings()
);
if (isset($_SESSION['setup_fts_hide_config'])) {
$sugar_config['hide_full_text_engine_config'] = $_SESSION['setup_fts_hide_config'];
}
}
/*nsingh(bug 22402): Consolidate logger settings under $config['logger'] as liked by the new logger! If log4pphp exists,
these settings will be overwritten by those in log4php.properties when the user access admin->system settings.*/
$sugar_config['logger'] =
array('level'=>$setup_site_log_level,
'file' => array(
'ext' => '.log',
'name' => 'suitecrm',
'dateFormat' => '%c',
'maxSize' => '10MB',
'maxLogs' => 10,
'suffix' => ''), // bug51583, change default suffix to blank for backwards comptability
);
$sugar_config['session_dir'] = $setup_site_session_path;
$sugar_config['site_url'] = $setup_site_url;
$sugar_config['sugar_version'] = $setup_sugar_version;
$sugar_config['tmp_dir'] = $cache_dir.'xml/';
$sugar_config['upload_dir'] = 'upload/';
// $sugar_config['use_php_code_json'] = returnPhpJsonStatus(); // true on error
if (isset($_SESSION['setup_site_sugarbeet_anonymous_stats'])) {
$sugar_config['sugarbeet'] = $_SESSION['setup_site_sugarbeet_anonymous_stats'];
}
$sugar_config['demoData'] = $_SESSION['demoData'];
if (isset($setup_site_guid)) {
$sugar_config['unique_key'] = $setup_site_guid;
}
if (empty($sugar_config['unique_key'])) {
$sugar_config['unique_key'] = md5(create_guid());
}
// add installed langs to config
// entry in upgrade_history comes AFTER table creation
if (isset($_SESSION['INSTALLED_LANG_PACKS']) && is_array($_SESSION['INSTALLED_LANG_PACKS']) && !empty($_SESSION['INSTALLED_LANG_PACKS'])) {
foreach ($_SESSION['INSTALLED_LANG_PACKS'] as $langZip) {
$lang = getSugarConfigLanguageArray($langZip);
if (!empty($lang)) {
$exLang = explode('::', $lang);
if (is_array($exLang) && count($exLang) == 3) {
$sugar_config['languages'][$exLang[0]] = $exLang[1];
}
}
}
}
if (file_exists('install/lang.config.php')) {
include('install/lang.config.php');
if (!empty($config['languages'])) {
foreach ($config['languages'] as $lang=>$label) {
$sugar_config['languages'][$lang] = $label;
}
}
}
ksort($sugar_config);
$sugar_config_string = "<?php\n" .
'// created: ' . date('Y-m-d H:i:s') . "\n" .
'$sugar_config = ' .
var_export($sugar_config, true) .
";\n?>\n";
if ($is_writable && write_array_to_file("sugar_config", $sugar_config, "config.php")) {
// was 'Done'
} else {
echo 'failed<br>';
echo "<p>{$mod_strings['ERR_PERFORM_CONFIG_PHP_1']}</p>\n";
echo "<p>{$mod_strings['ERR_PERFORM_CONFIG_PHP_2']}</p>\n";
echo "<TEXTAREA rows=\"15\" cols=\"80\">".$sugar_config_string."</TEXTAREA>";
echo "<p>{$mod_strings['ERR_PERFORM_CONFIG_PHP_3']}</p>";
$bottle[] = $mod_strings['ERR_PERFORM_CONFIG_PHP_4'];
}
//Now merge the config_si.php settings into config.php
if (file_exists('config.php') && file_exists('config_si.php')) {
require_once('modules/UpgradeWizard/uw_utils.php');
merge_config_si_settings(false, 'config.php', 'config_si.php');
}
//// END $sugar_config
///////////////////////////////////////////////////////////////////////////////
return $bottle;
}
/**
* Get FTS settings
* @return array
*/
function getFtsSettings()
{
// Base settings
$ftsSettings = array(
'host' => $_SESSION['setup_fts_host'],
'port' => $_SESSION['setup_fts_port'],
);
// Add optional settings
$ftsOptional = array(
'curl',
'transport',
'index_settings',
'index_strategy',
);
foreach ($ftsOptional as $ftsOpt) {
$ftsConfigKey = "setup_fts_{$ftsOpt}";
if (!empty($_SESSION[$ftsConfigKey])) {
$ftsSettings[$ftsOpt] = $_SESSION[$ftsConfigKey];
}
}
return $ftsSettings;
}
/**
* (re)write the .htaccess file to prevent browser access to the log file
*/
function handleHtaccess()
{
global $mod_strings;
global $sugar_config;
$ignoreCase = '';
if (!empty($_SERVER['SERVER_SOFTWARE']) && (substr_count(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache/2') > 0)) {
$ignoreCase = '(?i)';
}
$htaccess_file = '.htaccess';
$contents = '';
$basePath = parse_url($sugar_config['site_url'], PHP_URL_PATH);
if (empty($basePath)) {
$basePath = '/';
}
$cacheDir = $sugar_config['cache_dir'];
$restrict_str = <<<EOQ
# BEGIN SUITECRM RESTRICTIONS
EOQ;
if (ini_get('suhosin.perdir') !== false && strpos(ini_get('suhosin.perdir'), 'e') !== false) {
$restrict_str .= "php_value suhosin.executor.include.whitelist upload\n";
}
$restrict_str .= <<<EOQ
RedirectMatch 403 {$ignoreCase}.*\.log$
RedirectMatch 403 {$ignoreCase}/+not_imported_.*\.txt
RedirectMatch 403 {$ignoreCase}/+(soap|cache|xtemplate|data|examples|include|log4php|metadata|modules|vendor)/+.*\.(php|tpl|phar)
RedirectMatch 403 {$ignoreCase}/+emailmandelivery\.php
RedirectMatch 403 {$ignoreCase}/+.git
RedirectMatch 403 {$ignoreCase}/+.{$cacheDir}