/
utils.php
executable file
·6053 lines (5331 loc) · 192 KB
/
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 - 2021 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 __DIR__ . '/../php_version.php';
require_once __DIR__ . '/../include/SugarObjects/SugarConfig.php';
require_once __DIR__ . '/../include/utils/security_utils.php';
use voku\helper\AntiXSS;
/**
* @param $sugar_config
*/
function make_sugar_config(&$sugar_config)
{
/* used to convert non-array config.php file to array format */
global $admin_export_only;
global $cache_dir;
global $calculate_response_time;
global $create_default_user;
global $dateFormats;
global $dbconfig;
global $dbconfigoption;
global $default_action;
global $default_charset;
global $default_currency_name;
global $default_currency_symbol;
global $default_currency_iso4217;
global $defaultDateFormat;
global $default_language;
global $default_module;
global $default_password;
global $default_theme;
global $defaultTimeFormat;
global $default_user_is_admin;
global $default_user_name;
global $disable_export;
global $disable_persistent_connections;
global $display_email_template_variable_chooser;
global $display_inbound_email_buttons;
global $google_auth_json;
global $history_max_viewed;
global $host_name;
global $import_dir;
global $languages;
global $list_max_entries_per_page;
global $lock_default_user_name;
global $log_memory_usage;
global $nameFormats;
global $requireAccounts;
global $RSS_CACHE_TIME;
global $session_dir;
global $site_URL;
global $site_url;
global $sugar_version;
global $timeFormats;
global $tmp_dir;
global $translation_string_prefix;
global $unique_key;
global $upload_badext;
global $upload_dir;
global $upload_maxsize;
global $import_max_execution_time;
global $list_max_entries_per_subpanel;
global $passwordsetting;
// assumes the following variables must be set:
// $dbconfig, $dbconfigoption, $cache_dir, $session_dir, $site_URL, $upload_dir
$sugar_config = array(
'admin_export_only' => empty($admin_export_only) ? false : $admin_export_only,
'export_delimiter' => empty($export_delimiter) ? ',' : $export_delimiter,
'cache_dir' => empty($cache_dir) ? 'cache/' : $cache_dir,
'calculate_response_time' => empty($calculate_response_time) ? true : $calculate_response_time,
'create_default_user' => empty($create_default_user) ? false : $create_default_user,
'chartEngine' => 'Jit',
'pdf' => [
'defaultEngine' => 'TCPDFEngine'
],
'date_formats' => empty($dateFormats) ? array(
'Y-m-d' => '2010-12-23',
'd-m-Y' => '23-12-2010',
'm-d-Y' => '12-23-2010',
'Y/m/d' => '2010/12/23',
'd/m/Y' => '23/12/2010',
'm/d/Y' => '12/23/2010',
'Y.m.d' => '2010.12.23',
'd.m.Y' => '23.12.2010',
'm.d.Y' => '12.23.2010',
) : $dateFormats,
'dbconfig' => $dbconfig, // this must be set!!
'dbconfigoption' => $dbconfigoption, // this must be set!!
'default_action' => empty($default_action) ? 'index' : $default_action,
'default_charset' => empty($default_charset) ? 'UTF-8' : $default_charset,
'default_currency_name' => empty($default_currency_name) ? 'US Dollar' : $default_currency_name,
'default_currency_symbol' => empty($default_currency_symbol) ? '$' : $default_currency_symbol,
'default_currency_iso4217' => empty($default_currency_iso4217) ? '$' : $default_currency_iso4217,
'default_date_format' => empty($defaultDateFormat) ? 'm/d/Y' : $defaultDateFormat,
'default_locale_name_format' => empty($defaultNameFormat) ? 's f l' : $defaultNameFormat,
'default_export_charset' => 'UTF-8',
'default_language' => empty($default_language) ? 'en_us' : $default_language,
'default_module' => empty($default_module) ? 'Home' : $default_module,
'default_password' => empty($default_password) ? '' : $default_password,
'default_permissions' => array(
'dir_mode' => 02770,
'file_mode' => 0755,
'chown' => '',
'chgrp' => '',
),
'default_theme' => empty($default_theme) ? 'SuiteP' : $default_theme,
'default_time_format' => empty($defaultTimeFormat) ? 'h:ia' : $defaultTimeFormat,
'default_user_is_admin' => empty($default_user_is_admin) ? false : $default_user_is_admin,
'default_user_name' => empty($default_user_name) ? '' : $default_user_name,
'disable_export' => empty($disable_export) ? false : $disable_export,
'disable_persistent_connections' => empty($disable_persistent_connections) ? false : $disable_persistent_connections,
'display_email_template_variable_chooser' => empty($display_email_template_variable_chooser) ? false : $display_email_template_variable_chooser,
'display_inbound_email_buttons' => empty($display_inbound_email_buttons) ? false : $display_inbound_email_buttons,
'google_auth_json' => empty($google_auth_json) ? '' : $google_auth_json,
'history_max_viewed' => empty($history_max_viewed) ? 50 : $history_max_viewed,
'host_name' => empty($host_name) ? 'localhost' : $host_name,
'import_dir' => $import_dir, // this must be set!!
'import_max_records_per_file' => 100,
'import_max_records_total_limit' => '',
'languages' => empty($languages) ? array('en_us' => 'English (US)') : $languages,
'list_max_entries_per_page' => empty($list_max_entries_per_page) ? 20 : $list_max_entries_per_page,
'list_max_entries_per_subpanel' => empty($list_max_entries_per_subpanel) ? 10 : $list_max_entries_per_subpanel,
'lock_default_user_name' => empty($lock_default_user_name) ? false : $lock_default_user_name,
'log_memory_usage' => empty($log_memory_usage) ? false : $log_memory_usage,
'name_formats' => empty($nameFormats) ? array(
's f l' => 's f l',
'f l' => 'f l',
's l' => 's l',
'l, s f' => 'l, s f',
'l, f' => 'l, f',
's l, f' => 's l, f',
'l s f' => 'l s f',
'l f s' => 'l f s',
) : $nameFormats,
'oauth2_encryption_key' => base64_encode(random_bytes(32)),
'portal_view' => 'single_user',
'resource_management' => array(
'special_query_limit' => 50000,
'special_query_modules' => array('AOR_Reports', 'Export', 'Import', 'Administration', 'Sync'),
'default_limit' => 1000,
),
'require_accounts' => empty($requireAccounts) ? true : $requireAccounts,
'rss_cache_time' => empty($RSS_CACHE_TIME) ? '10800' : $RSS_CACHE_TIME,
'session_dir' => $session_dir, // this must be set!!
'site_url' => empty($site_URL) ? $site_url : $site_URL, // this must be set!!
'showDetailData' => true, // if true, read-only ACL fields will still appear on EditViews as non-editable
'showThemePicker' => true,
'sugar_version' => empty($sugar_version) ? 'unknown' : $sugar_version,
'time_formats' => empty($timeFormats) ? array(
'H:i' => '23:00',
'h:ia' => '11:00 pm',
'h:iA' => '11:00PM',
'H.i' => '23.00',
'h.ia' => '11.00 pm',
'h.iA' => '11.00PM',
) : $timeFormats,
'tmp_dir' => $tmp_dir, // this must be set!!
'translation_string_prefix' => empty($translation_string_prefix) ? false : $translation_string_prefix,
'unique_key' => empty($unique_key) ? md5(create_guid()) : $unique_key,
'upload_badext' => empty($upload_badext) ? array(
'php',
'php3',
'php4',
'php5',
'php6',
'php7',
'php8',
'pl',
'cgi',
'py',
'asp',
'cfm',
'js',
'vbs',
'html',
'htm',
'phtml',
'phar',
) : $upload_badext,
'valid_image_ext' => [
'gif',
'png',
'jpg',
'jpeg',
'svg'
],
'upload_dir' => $upload_dir, // this must be set!!
'upload_maxsize' => empty($upload_maxsize) ? 30000000 : $upload_maxsize,
'allowed_preview' => [
'pdf',
'gif',
'png',
'jpeg',
'jpg'
],
'import_max_execution_time' => empty($import_max_execution_time) ? 3600 : $import_max_execution_time,
'lock_homepage' => false,
'lock_subpanels' => false,
'max_dashlets_homepage' => 15,
'dashlet_display_row_options' => array('1', '3', '5', '10'),
'default_max_tabs' => empty($max_tabs) ? 10 : $max_tabs,
'default_subpanel_tabs' => empty($subpanel_tabs) ? true : $subpanel_tabs,
'default_subpanel_links' => empty($subpanel_links) ? false : $subpanel_links,
'default_swap_last_viewed' => empty($swap_last_viewed) ? false : $swap_last_viewed,
'default_swap_shortcuts' => empty($swap_shortcuts) ? false : $swap_shortcuts,
'default_navigation_paradigm' => empty($navigation_paradigm) ? 'gm' : $navigation_paradigm,
'default_call_status' => 'Planned',
'js_lang_version' => 1,
'passwordsetting' => empty($passwordsetting) ? array(
'SystemGeneratedPasswordON' => '',
'generatepasswordtmpl' => '',
'lostpasswordtmpl' => '',
'factoremailtmpl' => '',
'forgotpasswordON' => true,
'linkexpiration' => '1',
'linkexpirationtime' => '30',
'linkexpirationtype' => '1',
'systexpiration' => '0',
'systexpirationtime' => '',
'systexpirationtype' => '0',
'systexpirationlogin' => '',
) : $passwordsetting,
'use_sprites' => function_exists('imagecreatetruecolor'),
'search_wildcard_infront' => false,
'search_wildcard_char' => '%',
'jobs' => array(
'min_retry_interval' => 60, // minimal job retry delay
'max_retries' => 5, // how many times to retry the job
'timeout' => 86400, // how long a job may spend as running before being force-failed
'soft_lifetime' => 7, // how many days until job record will be soft deleted after completion
'hard_lifetime' => 21, // how many days until job record will be purged from DB
),
'cron' => array(
'max_cron_jobs' => 10, // max jobs per cron schedule run
'max_cron_runtime' => 60, // max runtime for cron jobs
'min_cron_interval' => 30, // minimal interval between cron jobs
),
'strict_id_validation' => false,
);
}
/**
* Used for getting base values for array style config.php
* @return array
* @throws Exception
*/
function get_sugar_config_defaults(): array
{
global $locale;
$sugar_config_defaults = [
'admin_export_only' => false,
'anti_malware_scanners' => [
'SuiteCRM\Utility\AntiMalware\Providers\ClamTCP' => [
'name' => 'ClamAntiVirus TCP',
'support_page' => 'https://www.clamav.net/',
'enabled' => false,
'path' => null,
'options' => [
'ip' => '127.0.0.1',
'port' => 3310,
'type' => 'local'
],
],
'SuiteCRM\Utility\AntiMalware\Providers\Sophos' => [
'name' => 'Sophos Anti Virus (Linux)',
'support_page' => 'https://www.sophos.com/en-us/products/free-tools/sophos-antivirus-for-linux.aspx',
'enabled' => false,
'path' => '/opt/sophos-av/bin/savscan',
'options' => '-ss'
]
],
'export_delimiter' => ',',
'export_excel_compatible' => false,
'cache_dir' => 'cache/',
'calculate_response_time' => true,
'create_default_user' => false,
'chartEngine' => 'Jit',
'date_formats' => [
'Y-m-d' => '2010-12-23',
'm-d-Y' => '12-23-2010',
'd-m-Y' => '23-12-2010',
'Y/m/d' => '2010/12/23',
'm/d/Y' => '12/23/2010',
'd/m/Y' => '23/12/2010',
'Y.m.d' => '2010.12.23',
'd.m.Y' => '23.12.2010',
'm.d.Y' => '12.23.2010',
],
'name_formats' => [
's f l' => 's f l',
'f l' => 'f l',
's l' => 's l',
'l, s f' => 'l, s f',
'l, f' => 'l, f',
's l, f' => 's l, f',
'l s f' => 'l s f',
'l f s' => 'l f s',
],
'dbconfigoption' => [
'persistent' => true,
'autofree' => false,
'debug' => 0,
'ssl' => false,
],
'default_action' => 'index',
'default_charset' => return_session_value_or_default('default_charset', 'UTF-8'),
'default_currency_name' => return_session_value_or_default('default_currency_name', 'US Dollar'),
'default_currency_symbol' => return_session_value_or_default('default_currency_symbol', '$'),
'default_currency_iso4217' => return_session_value_or_default('default_currency_iso4217', 'USD'),
'default_currency_significant_digits' => return_session_value_or_default('default_currency_significant_digits',
2),
'default_number_grouping_seperator' => return_session_value_or_default('default_number_grouping_seperator',
','),
'default_decimal_seperator' => return_session_value_or_default('default_decimal_seperator', '.'),
'default_date_format' => 'm/d/Y',
'default_locale_name_format' => 's f l',
'default_export_charset' => 'UTF-8',
'default_language' => return_session_value_or_default('default_language', 'en_us'),
'default_module' => 'Home',
'default_password' => '',
'default_permissions' => [
'dir_mode' => 02770,
'file_mode' => 0755,
'user' => '',
'group' => '',
],
'default_theme' => return_session_value_or_default('site_default_theme', 'SuiteP'),
'default_time_format' => 'h:ia',
'default_user_is_admin' => false,
'default_user_name' => '',
'disable_export' => false,
'disable_persistent_connections' => return_session_value_or_default('disable_persistent_connections', false),
'default_module_favicon' => false,
'dashlet_auto_refresh_min' => 30,
'stack_trace_errors' => false,
'developerMode' => false,
'stackTrace' => false,
'display_email_template_variable_chooser' => false,
'display_inbound_email_buttons' => false,
'dump_slow_queries' => false,
'email_address_separator' => ',', // use RFC2368 spec unless we have a noncompliant email client
'email_default_editor' => 'html',
'email_default_client' => 'sugar',
'email_default_delete_attachments' => true,
'email_warning_notifications' => true,
'email_enable_auto_send_opt_in' => false,
'email_enable_confirm_opt_in' => SugarEmailAddress::COI_STAT_DISABLED,
'filter_module_fields' => [
'Users' => [
'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' => [
'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',
]
],
'google_auth_json' => '',
'history_max_viewed' => 50,
'installer_locked' => true,
'import_max_records_per_file' => 100,
'import_max_records_total_limit' => '',
'languages' => ['en_us' => 'English (US)'],
'large_scale_test' => false,
'list_max_entries_per_page' => 20,
'list_max_entries_per_subpanel' => 10,
'lock_default_user_name' => false,
'log_memory_usage' => false,
'oauth2_encryption_key' => base64_encode(random_bytes(32)),
'portal_view' => 'single_user',
'pdf' => [
'defaultEngine' => 'TCPDFEngine'
],
'resource_management' => [
'special_query_limit' => 50000,
'special_query_modules' => ['AOR_Reports', 'Export', 'Import', 'Administration', 'Sync'],
'default_limit' => 1000,
],
'require_accounts' => true,
'rss_cache_time' => return_session_value_or_default('rss_cache_time', '10800'),
'save_query' => 'all',
'showDetailData' => true, // if true, read-only ACL fields will still appear on EditViews as non-editable
'showThemePicker' => true,
'slow_query_time_msec' => '100',
'sugarbeet' => true,
'time_formats' => [
'H:i' => '23:00',
'h:ia' => '11:00pm',
'h:iA' => '11:00PM',
'h:i a' => '11:00 pm',
'h:i A' => '11:00 PM',
'H.i' => '23.00',
'h.ia' => '11.00pm',
'h.iA' => '11.00PM',
'h.i a' => '11.00 pm',
'h.i A' => '11.00 PM',
],
'tracker_max_display_length' => 15,
'translation_string_prefix' => return_session_value_or_default('translation_string_prefix', false),
'upload_badext' => [
'php',
'php3',
'php4',
'php5',
'php6',
'php7',
'php8',
'pl',
'cgi',
'py',
'asp',
'cfm',
'js',
'vbs',
'html',
'htm',
'phtml',
'phar',
],
'valid_image_ext' => [
'gif',
'png',
'jpg',
'jpeg',
'svg',
'bmp'
],
'allowed_preview' => [
'pdf',
'gif',
'png',
'jpeg',
'jpg'
],
'upload_maxsize' => 30000000,
'allowed_preview' => [
'pdf',
'gif',
'png',
'jpeg',
'jpg'
],
'import_max_execution_time' => 3600,
// 'use_php_code_json' => returnPhpJsonStatus(),
'verify_client_ip' => true,
'js_custom_version' => '',
'js_lang_version' => 1,
'lead_conv_activity_opt' => 'donothing',
'lock_homepage' => false,
'lock_subpanels' => false,
'max_dashlets_homepage' => '15',
'default_max_tabs' => 10,
'dashlet_display_row_options' => ['1', '3', '5', '10'],
'default_subpanel_tabs' => true,
'default_subpanel_links' => false,
'default_swap_last_viewed' => false,
'default_swap_shortcuts' => false,
'default_navigation_paradigm' => 'gm',
'admin_access_control' => false,
'use_common_ml_dir' => false,
'common_ml_dir' => '',
'vcal_time' => '2',
'calendar' => [
'default_view' => 'week',
'show_calls_by_default' => true,
'show_tasks_by_default' => true,
'show_completed_by_default' => true,
'editview_width' => 990,
'editview_height' => 485,
'day_timestep' => 15,
'week_timestep' => 30,
'items_draggable' => true,
'items_resizable' => true,
'enable_repeat' => true,
'max_repeat_count' => 1000,
],
'passwordsetting' => empty($passwordsetting) ? [
'SystemGeneratedPasswordON' => '',
'generatepasswordtmpl' => '',
'lostpasswordtmpl' => '',
'factoremailtmpl' => '',
'forgotpasswordON' => false,
'linkexpiration' => '1',
'linkexpirationtime' => '30',
'linkexpirationtype' => '1',
'systexpiration' => '1',
'systexpirationtime' => '7',
'systexpirationtype' => '1',
'systexpirationlogin' => '',
] : $passwordsetting,
'use_real_names' => true,
'search_wildcard_infront' => false,
'search_wildcard_char' => '%',
'jobs' => [
'min_retry_interval' => 30, // 30 seconds minimal job retry
'max_retries' => 5, // how many times to retry the job
'timeout' => 86400, // how long a job may spend as running before being force-failed
],
'cron' => [
'max_cron_jobs' => 10, // max jobs per cron schedule run
'max_cron_runtime' => 30, // max runtime for cron jobs
'min_cron_interval' => 30, // minimal interval between cron jobs
],
'strict_id_validation' => false,
'id_validation_pattern' => '/^[a-zA-Z0-9_-]*$/i',
'session_gc' => [
'enable' => true,
'gc_probability' => 1,
'gc_divisor' => 100,
]
];
if (!is_object($locale)) {
$locale = new Localization();
}
$sugar_config_defaults = sugarArrayMerge($locale->getLocaleConfigDefaults(), $sugar_config_defaults);
return $sugar_config_defaults;
}
/**
* Gets the username of the user under which the PHP script is currently running
* Notes:
* - works on Windows and Linux, tries a variety of methods to accommodate different systems and hosting restrictions
* - on Windows, return full username in form DOMAIN\USER
* - returns empty string if failed
*/
function getRunningUser()
{
// works on Windows and Linux, but might return null on systems that include "exec" in
// disabled_functions in php.ini (typical in shared hosting)
$runningUser = exec('whoami');
if ($runningUser == null) { // matches null, false and ""
if (is_windows()) {
$runningUser = getenv('USERDOMAIN').'\\'.getenv('USERNAME');
} elseif (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
$usr = posix_getpwuid(posix_geteuid());
$runningUser = $usr['name'];
}
}
return ($runningUser == null) ? '' : $runningUser;
}
/**
* Adds a username to the allowed_cron_users array in config.php
* Notes:
* - this is Linux only, does nothing on Windows
* - does not repeat the user if he is already there
* - creates the sub-array if previously unexisting
* - special treatment for user 'root' to require manual intervention from an admin to allow
* @param string $addUser the name of the user to add [usually obtained with getRunningUser()]
*/
function addCronAllowedUser($addUser)
{
global $sugar_config;
if (is_windows() || !isset($sugar_config) || !isset($addUser) || ($addUser == '')) {
return;
}
if (!array_key_exists('cron', $sugar_config)) {
$sugar_config['cron'] = array();
}
if (!array_key_exists('allowed_cron_users', $sugar_config['cron'])) {
$sugar_config['cron']['allowed_cron_users'] = array();
}
if (!in_array($addUser, $sugar_config['cron']['allowed_cron_users'])) {
if ($addUser == 'root') {
$addUser = 'root_REMOVE_THIS_NOTICE_IF_YOU_REALLY_WANT_TO_ALLOW_ROOT';
if (!in_array($addUser, $sugar_config['cron']['allowed_cron_users'])) {
$sugar_config['cron']['allowed_cron_users'][] = $addUser;
$GLOBALS['log']->error("You're using 'root' as the web-server user. This should be avoided " .
"for security reasons. Review allowed_cron_users configuration in config.php.");
}
} else {
$sugar_config['cron']['allowed_cron_users'][] = $addUser;
$GLOBALS['log']->info("Web server user $addUser added to allowed_cron_users in config.php.");
}
}
ksort($sugar_config);
write_array_to_file('sugar_config', $sugar_config, 'config.php');
}
/**
* @deprecated use SugarView::getMenu() instead
*/
function load_menu($path)
{
global $module_menu;
if (file_exists($path . 'Menu.php')) {
require $path . 'Menu.php';
}
if (file_exists('custom/' . $path . 'Ext/Menus/menu.ext.php')) {
require 'custom/' . $path . 'Ext/Menus/menu.ext.php';
}
if (file_exists('custom/application/Ext/Menus/menu.ext.php')) {
require 'custom/application/Ext/Menus/menu.ext.php';
}
return $module_menu;
}
/**
* get_notify_template_file
* This function will return the location of the email notifications template to use.
*
* @return string relative file path to email notifications template file
*/
function get_notify_template_file($language)
{
/*
* Order of operation:
* 1) custom version of specified language
* 2) stock version of specified language
* 3) custom version of en_us template
* 4) stock en_us template
*/
// set $file to the base code template so it's set if none of the conditions pass
$file = 'include/language/en_us.notify_template.html';
if (file_exists("custom/include/language/{$language}.notify_template.html")) {
$file = "custom/include/language/{$language}.notify_template.html";
} elseif (file_exists("include/language/{$language}.notify_template.html")) {
$file = "include/language/{$language}.notify_template.html";
} elseif (file_exists('custom/include/language/en_us.notify_template.html')) {
$file = 'custom/include/language/en_us.notify_template.html';
}
return $file;
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function sugar_config_union($default, $override)
{
// a little different then array_merge and array_merge_recursive. we want
// the second array to override the first array if the same value exists,
// otherwise merge the unique keys. it handles arrays of arrays recursively
// might be suitable for a generic array_union
if (!is_array($override)) {
$override = array();
}
foreach ($default as $key => $value) {
if (!array_key_exists($key, $override)) {
$override[$key] = $value;
} elseif (is_array($key)) {
$override[$key] = sugar_config_union($value, $override[$key]);
}
}
return $override;
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function make_not_writable($file)
{
// Returns true if the given file/dir has been made not writable
$ret_val = false;
if (is_file($file) || is_dir($file)) {
if (!is_writable($file)) {
$ret_val = true;
} else {
$original_fileperms = fileperms($file);
// take away writable permissions
$new_fileperms = $original_fileperms & ~0x0092;
@sugar_chmod($file, $new_fileperms);
if (!is_writable($file)) {
$ret_val = true;
}
}
}
return $ret_val;
}
/**
* This function returns the name of the person.
* It currently returns "first last". It should not put the space if either name is not available.
* It should not return errors if either name is not available.
* If no names are present, it will return ""
*
* @deprecated This function is unused and will be removed in a future release.
*
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
*/
function return_name($row, $first_column, $last_column)
{
$first_name = '';
$last_name = '';
$full_name = '';
if (isset($row[$first_column])) {
$first_name = stripslashes($row[$first_column]);
}
if (isset($row[$last_column])) {
$last_name = stripslashes($row[$last_column]);
}
$full_name = $first_name;
// If we have a first name and we have a last name
if ($full_name != '' && $last_name != '') {
// append a space, then the last name
$full_name .= ' ' . $last_name;
} // If we have no first name, but we have a last name
elseif ($last_name != '') {
// append the last name without the space.
$full_name .= $last_name;
}
return $full_name;
}
function get_languages()
{
global $sugar_config;
$lang = $sugar_config['languages'];
if (!empty($sugar_config['disabled_languages'])) {
foreach (explode(',', $sugar_config['disabled_languages']) as $disable) {
unset($lang[$disable]);
}
}
return $lang;
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function get_all_languages()
{
global $sugar_config;
return $sugar_config['languages'];
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function get_language_display($key)
{
global $sugar_config;
return $sugar_config['languages'][$key];
}
/**
* Returns the currently active language string.
*
* @return string
*/
function get_current_language()
{
global $sugar_config;
if (!empty($_SESSION['authenticated_user_language'])) {
return $_SESSION['authenticated_user_language'];
} else {
return $sugar_config['default_language'];
}
}
function get_assigned_user_name($assigned_user_id, $is_group = '')
{
static $saved_user_list = null;
if (empty($saved_user_list)) {
$saved_user_list = get_user_array(false, '', '', false, null, $is_group);
}
if (isset($saved_user_list[$assigned_user_id])) {
return $saved_user_list[$assigned_user_id];
}
return '';
}
/**
* retrieves the user_name column value (login).
*
* @param string id GUID of user
*
* @return string
*/
function get_user_name($id)
{
$db = DBManagerFactory::getInstance();
if ($db === null) {
$db = DBManagerFactory::getInstance();
}
$idQuoted = $db->quoted($id);
$q = "SELECT user_name FROM users WHERE id=$idQuoted";
$r = $db->query($q);
$a = $db->fetchByAssoc($r);
return (empty($a)) ? '' : $a['user_name'];
}
/**
* Get currently authenticated user
* @return User
*/
function get_authenticated_user(): ?User {
$authenticatedUserId = $_SESSION['authenticated_user_id'] ?? '';
if (empty($authenticatedUserId)){
return null;
}
/** @var User $authenticatedUser */
$authenticatedUser = BeanFactory::getBean('Users', $authenticatedUserId);
if (empty($authenticatedUser)) {
return null;
}
return $authenticatedUser;
}
//TODO Update to use global cache
/**
* get_user_array.
*
* This is a helper function to return an Array of users depending on the parameters passed into the function.
* This function uses the get_register_value function by default to use a caching layer where supported.
* This function has been updated return the array sorted by user preference of name display (bug 62712)
*
* @param bool $add_blank Boolean value to add a blank entry to the array results, true by default
* @param string $status String value indicating the status to filter users by, "Active" by default
* @param string $user_id String value to specify a particular user id value (searches the id column of users table), blank by default
* @param bool $use_real_name Boolean value indicating whether or not results should include the full name or just user_name, false by default
* @param string $user_name_filter String value indicating the user_name filter (searches the user_name column of users table) to optionally search with, blank by default
* @param string $portal_filter String query filter for portal users (defaults to searching non-portal users), change to blank if you wish to search for all users including portal users
* @param bool $from_cache Boolean value indicating whether or not to use the get_register_value function for caching, true by default
*
* @return array Array of users matching the filter criteria that may be from cache (if similar search was previously run)
*/
function get_user_array($add_blank = true, $status = 'Active', $user_id = '', $use_real_name = false, $user_name_filter = '', $portal_filter = ' AND portal_only=0 ', $from_cache = true)
{
global $locale, $sugar_config, $current_user;
if (empty($locale)) {
$locale = new Localization();
}
if ($from_cache) {
$key_name = $add_blank . $status . $user_id . $use_real_name . $user_name_filter . $portal_filter;
$user_array = get_register_value('user_array', $key_name);
}
if (empty($user_array)) {
$db = DBManagerFactory::getInstance();
$temp_result = array();
// Including deleted users for now.
if (empty($status)) {
$query = 'SELECT id, first_name, last_name, user_name FROM users WHERE 1=1' . $portal_filter;
} else {
$query = "SELECT id, first_name, last_name, user_name from users WHERE status='$status'" . $portal_filter;
}
/* BEGIN - SECURITY GROUPS */
global $current_user, $sugar_config;
if (!is_admin($current_user) && isset($sugar_config['securitysuite_filter_user_list']) && $sugar_config['securitysuite_filter_user_list'] == true && (empty($_REQUEST['module']) || $_REQUEST['module'] != 'Home') && (empty($_REQUEST['action']) || $_REQUEST['action'] != 'DynamicAction')
) {
require_once 'modules/SecurityGroups/SecurityGroup.php';
global $current_user;
$group_where = SecurityGroup::getGroupUsersWhere($current_user->id);
$query .= ' AND (' . $group_where . ') ';
}
/* END - SECURITY GROUPS */
if (!empty($user_name_filter)) {
$user_name_filter = $db->quote($user_name_filter);
$query .= " AND user_name LIKE '$user_name_filter%' ";
}
if (!empty($user_id)) {
$query .= " OR id='{$user_id}'";
}
//get the user preference for name formatting, to be used in order by
$order_by_string = ' user_name ASC ';
if (!empty($current_user) && !empty($current_user->id)) {
$formatString = $current_user->getPreference('default_locale_name_format');
//create the order by string based on position of first and last name in format string
$order_by_string = ' user_name ASC ';
$firstNamePos = strpos($formatString, 'f');
$lastNamePos = strpos($formatString, 'l');
if ($firstNamePos !== false || $lastNamePos !== false) {
//its possible for first name to be skipped, check for this
if ($firstNamePos === false) {
$order_by_string = 'last_name ASC';
} else {
$order_by_string = ($lastNamePos < $firstNamePos) ? 'last_name, first_name ASC' : 'first_name, last_name ASC';
}
}
}
$query = $query . ' ORDER BY ' . $order_by_string;
$GLOBALS['log']->debug("get_user_array query: $query");
$result = $db->query($query, true, 'Error filling in user array: ');
if ($add_blank == true) {
// Add in a blank row
$temp_result[''] = '';
}
// Get the id and the name.
while ($row = $db->fetchByAssoc($result)) {
if ($use_real_name == true || showFullName()) {
if (isset($row['last_name'])) { // cn: we will ALWAYS have both first_name and last_name (empty value if blank in db)
$temp_result[$row['id']] = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
} else {
$temp_result[$row['id']] = $row['user_name'];
}
} else {
$temp_result[$row['id']] = $row['user_name'];
}
}