forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.php
1891 lines (1771 loc) · 106 KB
/
setup.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
/**
*
* Installation script.
*
* To make this script a bit more simpler to figure out, here is a listing of the "state"(s)
* which are basically the steps that this installation script goes through.
* state:
* empty or 0 - Ensures required file and directory permission are correctly set prior to starting installation.
* 1 - Step 1: Select database setup (ie. create the database or use a database already initialized)
* 2 - Step 2: Enter in database and openemr user information
* 3 - Step 3: Create database
* 4 - Step 4: Instructions on configuring PHP
* 5 - Step 5: Instructions on configuring Apache
* 6 - Step 6: Select a theme
* 7 - Final step: Several miscellaneous instruction, login credentials, and link to OpenEMR
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Roberto Vasquez <[email protected]>
* @author Scott Wakefield <[email protected]>
* @author Ranganath Pathak <[email protected]>
* @author Brady Miller <[email protected]>
* @copyright Copyright (c) 2016 Roberto Vasquez <[email protected]>
* @copyright Copyright (c) 2016 Scott Wakefield <[email protected]>
* @copyright Copyright (c) 2019 Ranganath Pathak <[email protected]>
* @copyright Copyright (c) 2019-2021 Brady Miller <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
// Checks if the server's PHP version is compatible with OpenEMR:
require_once(dirname(__FILE__) . "/src/Common/Compatibility/Checker.php");
$response = OpenEMR\Common\Compatibility\Checker::checkPhpVersion();
if ($response !== true) {
die(htmlspecialchars($response));
}
// Set the maximum excution time and time limit to unlimited.
ini_set('max_execution_time', 0);
ini_set('display_errors', 0);
set_time_limit(0);
// Warning. If you set $allow_multisite_setup to true, this is a potential security vulnerability.
// Recommend setting it back to false (or removing this setup.php script entirely) after you
// are done with the multisite procedure.
$allow_multisite_setup = false;
// Warning. If you set $allow_cloning_setup to true, this is a potential security vulnerability.
// Recommend setting it back to false (or removing this setup.php script entirely) after you
// are done with the cloning setup procedure.
$allow_cloning_setup = false;
if (!$allow_cloning_setup && !empty($_REQUEST['clone_database'])) {
require_once(dirname(__FILE__) . "/src/Common/Session/SessionUtil.php");
OpenEMR\Common\Session\SessionUtil::setupScriptSessionStart();
OpenEMR\Common\Session\SessionUtil::setupScriptSessionCookieDestroy();
die("To turn on support for cloning setup, need to edit this script and change \$allow_cloning_setup to true. After you are done setting up the cloning, ensure you change \$allow_cloning_setup back to false or remove this script altogether");
}
function recursive_writable_directory_test($dir)
{
// first, collect the directory and subdirectories
$ri = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
$dirNames = array();
foreach ($ri as $file) {
if ($file->isDir()) {
if (!preg_match("/\.\.$/", $file->getPathname())) {
$dirName = realpath($file->getPathname());
if (!in_array($dirName, $dirNames)) {
$dirNames[] = $dirName;
}
}
}
}
// second, flag the directories that are not writable
$resultsNegative = array();
foreach ($dirNames as $value) {
if (!is_writable($value)) {
$resultsNegative[] = $value;
}
}
// third, send the output and return if didn't pass the test
if (!empty($resultsNegative)) {
echo "<p>";
$mainDirTest = "";
$outputs = array();
foreach ($resultsNegative as $failedDir) {
if (basename($failedDir) == basename($dir)) {
// need to reorder output so the main directory is at the top of the list
$mainDirTest = "<span class='text-danger'>UNABLE</span> to open directory '" . text(realpath($failedDir)) . "' for writing by web server.<br />\r\n";
} else {
$outputs[] = "<span class='text-danger'>UNABLE</span> to open subdirectory '" . text(realpath($failedDir)) . "' for writing by web server.<br />\r\n";
}
}
if ($mainDirTest) {
// need to reorder output so the main directory is at the top of the list
array_unshift($outputs, $mainDirTest);
}
foreach ($outputs as $output) {
echo $output;
}
echo "(configure directory permissions; see below for further instructions)</p>\r\n";
return 1;
} else {
echo "<code class='ml-5'>" . text(realpath($dir)) . "</code> directory and its subdirectories are <span class='text-success font-weight-bold'>ready</span>.<br /><br />\r\n";
return 0;
}
}
// Include standard libraries/classes
require_once dirname(__FILE__) . "/vendor/autoload.php";
use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Common\Session\SessionUtil;
use OpenEMR\Common\Utils\RandomGenUtils;
$state = isset($_POST["state"]) ? ($_POST["state"]) : '';
$installer = new Installer($_REQUEST);
// Make this true for IPPF.
$ippf_specific = false;
$error_page_end = <<<EPE
</div>
</div>
</div><!--end of container div-->
</body>
</html>
EPE;
// If this script was invoked with no site ID, then ask for one. (only if allow multisite is on, otherwise will assume default site)
if (empty($_REQUEST['site']) && $allow_multisite_setup && empty($state)) {
$site_id = <<<SITEID
<!DOCTYPE html>
<html>
<head>
<title>OpenEMR Setup Tool</title>
<link rel="stylesheet" href="public/assets/bootstrap/dist/css/bootstrap.min.css">
<script src="public/assets/jquery/dist/jquery.min.js"></script>
<script src="public/assets/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="public/assets/@fortawesome/fontawesome-free/css/all.min.css">
<link rel="shortcut icon" href="public/images/favicon.ico" />
<style>
.oe-pull-away {
float:right;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">OpenEMR Setup</a>
<div class="collapse navbar-collapse justify-content-end">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#" data-target="#myModal" data-toggle="modal" href="#" id="help-href" name="help-href" title="Click to view Help">Help</span></a>
</li>
</ul>
</div>
</div>
</nav>
<div class='container mt-3'>
<div class="row">
<div class="col-12">
<h3 class="mb-3 border-bottom">Optional Site ID Selection</h3>
<div class="jumbotron p-5">
<p>
Most OpenEMR installations support only one site. If that is
true for you then ignore the rest of this text and just click Continue.
</p>
<p class='p-2 bg-warning'>
If you are using the multisite setup module for the first time please read the
'Multi Site Installation' section of the help file before proceeding.
</p>
<p>
Otherwise please enter a unique Site ID here.
</p>
<p>
A Site ID is a short identifier with no spaces or special
characters other than periods or dashes. It is case-sensitive and we
suggest sticking to lower case letters for ease of use.
</p>
<p>
If each site will have its own host/domain name, then use that
name as the Site ID (e.g. www.example.com).
</p>
<p>
The site ID is used to identify which site you will log in to.
If it is a hostname then it is taken from the hostname in the URL.
Otherwise you must append "?site=<i>siteid</i>" to the URL used for
logging in.
</p>
<p>
It is OK for one of the sites to have "default" as its ID. This
is the ID that will be used if it cannot otherwise be determined.
</p>
<br />
<form method='post'>
<input type='hidden' name='state' value='0' />
<div class="form-row">
<div class="col-auto">
Site ID:
</div>
<div class="col">
<input type='text' class='form-control' name='site' value='default'>
</div>
<div class="col-12 mt-3">
<button type='submit' class='btn btn-primary' value='Continue'><i class="fas fa-chevron-right"></i> Continue</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div><!--end of container div-->
SITEID;
echo $site_id . "\r\n";
$installer->setupHelpModal();
echo "</body>" . "\r\n";
echo "</html>" . "\r\n";
exit();
}
// Support "?site=siteid" in the URL, otherwise assume "default".
$site_id = 'default';
if (!empty($_REQUEST['site'])) {
$site_id = trim($_REQUEST['site']);
}
// Die if site ID is empty or has invalid characters.
if (empty($site_id) || preg_match('/[^A-Za-z0-9\\-.]/', $site_id)) {
SessionUtil::setupScriptSessionStart();
SessionUtil::setupScriptSessionCookieDestroy();
die("Site ID '" . text($site_id) . "' contains invalid characters.");
}
// If multisite is turned off, then only allow default for site.
if (!$allow_multisite_setup && $site_id != 'default') {
SessionUtil::setupScriptSessionStart();
SessionUtil::setupScriptSessionCookieDestroy();
die("To turn on support for multisite setup, need to edit this script and change \$allow_multisite_setup to true. After you are done setting up the cloning, ensure you change \$allow_multisite_setup back to false or remove this script altogether");
}
// Disable file and directory permissions check by setting to false
$checkPermissions = true;
global $OE_SITE_DIR; // The Installer sets this
$docsDirectory = "$OE_SITE_DIR/documents";
//These are files and dir checked before install for
// correct permissions.
if (is_dir($OE_SITE_DIR)) {
$writableFileList = array($installer->conffile);
$writableDirList = array($docsDirectory);
} else {
$writableFileList = array();
$writableDirList = array($OE_SITES_BASE);
}
// Include the sqlconf file if it exists yet.
$config = 0;
if (file_exists($installer->conffile)) {
require_once($installer->conffile);
} elseif ($state > 3) {
// State 3 should have created the site directory if it is missing.
SessionUtil::setupScriptSessionStart();
SessionUtil::setupScriptSessionCookieDestroy();
die("Internal error, site directory is missing.");
}
// Should never have $config set when state less than 4
// (this means already installed)
if (!empty($config) && (($state ?? 0) < 4)) {
SessionUtil::setupScriptSessionStart();
SessionUtil::setupScriptSessionCookieDestroy();
error_log("OpenEMR has already been installed. If you wish to force re-installation, then edit " . errorLogEscape($installer->conffile) . " (change the 'config' variable to 0), and re-run the setup.php script.");
die("OpenEMR has already been installed. If you wish to force re-installation, see log for details.<br />\n");
}
// This will effectively only allow entry into the setup.php script at the first step and will bar entry to the
// script if openemr has already been installed.
// 2 mechanisms are also in place to ensure go through script in chronological order
// - a session variable tracks the next state expected and kills script is not correct
// - only the next state csrf is handed out in the form
if (empty($state)) {
// ensure not already installed
if (!empty($config)) {
SessionUtil::setupScriptSessionStart();
SessionUtil::setupScriptSessionCookieDestroy();
error_log("OpenEMR has already been installed. If you wish to force re-installation, then edit " . errorLogEscape($installer->conffile) . " (change the 'config' variable to 0), and re-run the setup.php script.");
die("OpenEMR has already been installed. If you wish to force re-installation, see log for details.<br />\n");
}
// set up new blank session and csrf mechanism
SessionUtil::setupScriptSessionStart();
session_regenerate_id(true);
$_SESSION = [];
CsrfUtils::setupCsrfKey();
} else {
// start up session and check csrf
SessionUtil::setupScriptSessionStart();
$state = (int)$state;
$verifyCsrf = false;
if (($state > 0) && ($state < 8)) {
$verifyCsrf = CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"], "state" . $state);
} else {
SessionUtil::setupScriptSessionCookieDestroy();
die("Not authorized (invalid state)");
}
if (!$verifyCsrf) {
SessionUtil::setupScriptSessionCookieDestroy();
die("Not authorized (invalid csrf)");
}
// ensure correct state is going (ie. do not allow users to muck around with this)
if ($_SESSION['bootstrapStateInSetup'] != $state) {
SessionUtil::setupScriptSessionCookieDestroy();
die("Not authorized (incorrect state)");
}
// ensure that users are not mucking with database settings
if ($state > 3) {
if (
($sqlconf["host"] != $installer->server) ||
($sqlconf["port"] != $installer->port) ||
($sqlconf["dbase"] != $installer->dbname) ||
($sqlconf["login"] != $installer->login) ||
($sqlconf["pass"] != $installer->pass)
) {
SessionUtil::setupScriptSessionCookieDestroy();
die("Not authorized (database)");
}
}
// state 7 is last state so might as well kill the session now to ensure no funny business
if ($state == 7) {
SessionUtil::setupScriptSessionCookieDestroy();
}
}
?>
<html>
<head>
<title>OpenEMR Setup Tool</title>
<!--<link rel=stylesheet href="interface/themes/style_blue.css">-->
<link rel="stylesheet" href="public/assets/bootstrap/dist/css/bootstrap.min.css">
<script src="public/assets/jquery/dist/jquery.min.js"></script>
<script src="public/assets/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="public/assets/@fortawesome/fontawesome-free/css/all.min.css">
<link rel="shortcut icon" href="public/images/favicon.ico" />
<style>
.noclone { }
table.phpset {
border-collapse:collapse;
}
table.phpset td, table.phpset th {
font-size:9pt;
border:1px solid gray;
padding:2px;
}
.table.no-border tr td, .table.no-border tr th {
border-width: 0;
}
td {
font-size:10pt;
}
.inputtext {
padding-left:2px;
padding-right:2px;
}
.button {
font-family:sans-serif;
font-size:9pt;
font-weight:bold;
}
.label-div > a {
display:none;
}
.label-div:hover > a {
display:inline-block;
}
div[id$="_info"] {
background: #F7FAB3;
padding: 20px;
margin: 10px 15px 0px 15px;
}
div[id$="_info"] > a {
margin-left:10px;
}
.checkboxgroup {
display: inline-block;
text-align: center;
}
.checkboxgroup label {
display: block;
}
.oe-pull-away{
float:right;
}
.oe-help-x {
color: grey;
padding: 0 5px;
}
.oe-superscript {
position: relative;
top: -.5em;
font-size: 70%!important;
}
.oe-setup-legend{
background-color: #f5f5f5;
padding:0 10px;
}
.button-wait {
color: grey;
cursor: not-allowed;
opacity: 0.6;
}
@media only screen {
fieldset > [class*="col-"] {
width: 100%;
text-align:left!Important;
}
}
</style>
<script>
// onclick handler for "clone database" checkbox
function cloneClicked() {
var cb = document.forms[0].clone_database;
$('.noclone').css('display', cb.checked ? 'none' : 'block');
}
</script>
</head>
<body>
<nav class="navbar navbar-expand navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">OpenEMR Setup</a>
<div class="collapse navbar-collapse justify-content-end">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#" data-target="#myModal" data-toggle="modal" href="#" id="help-href" name="help-href" title="Click to view Help">Help</span></a>
</li>
</ul>
</div>
</div>
</nav>
<div class='mt-3 container'>
<div class="row">
<div class="col-12">
<?php
$error = "<span class='text-danger font-weight-bold'>ERROR</span>";
$caution = "<span class='text-danger font-weight-bold'>CAUTION</span>";
$ok = "<span class='text-success font-weight-bold'>OK</span>";
$note = "<span class='text-primary font-weight-bold'>NOTE</span>";
if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
echo "$caution: It appears that you have register_globals enabled in your php.ini\n" .
"configuration file. This causes unacceptable security risks. You must\n" .
"turn it off before continuing with installation.\n";
exit(1);
}
if (!extension_loaded("xml")) {
echo "$error: PHP XML extension missing. To continue, install PHP XML extension, then restart web server.";
exit(1);
}
if (!(extension_loaded("mysql") || extension_loaded("mysqlnd") || extension_loaded("mysqli"))) {
echo "$error: PHP MySQL extension missing. To continue, install and enable MySQL extension, then restart web server.";
exit(1);
}
if (!(extension_loaded("mbstring") )) {
echo "$error: PHP mb_string extension missing. To continue, install and enable mb_string extension, then restart web server.";
exit(1);
}
if (!(extension_loaded("openssl") )) {
echo "$error: PHP openssl extension missing. To continue, install PHP openssl extension, then restart web server.";
exit(1);
}
?>
<?php
if ($state == 7) {
?>
<h3 class="mb-3 border-bottom">Final step - Success</h3>
<div class="jumbotron p-5">
<p>Congratulations! OpenEMR is now installed.</p>
<ul>
<li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
OpenEMR's admin->acl menu.</li>
<li>Reviewing <code> <?php echo text($OE_SITE_DIR); ?>/config.php </code> is a good idea. This file
contains some settings that you may want to change.</li>
<li>There's much information and many extra tools bundled within the OpenEMR installation directory.
Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
<li>To ensure a consistent look and feel throughout the application,
<a href='http://www.mozilla.org/products/firefox/'>Firefox</a> and <a href="https://www.google.com/chrome/browser/desktop/index.html">Chrome</a> are recommended. The OpenEMR development team exclusively tests with modern versions of these browsers.</li>
<li>The OpenEMR project home page, documentation, and forums can be found at <a href = "https://www.open-emr.org" rel='noopener' target="_blank">https://www.open-emr.org</a></li>
<li>We pursue grants to help fund the future development of OpenEMR. To apply for these grants, we need to estimate how many times this program is installed and how many practices are evaluating or using this software. It would be awesome if you would email us at <a href="mailto:[email protected]">[email protected]</a> if you have installed this software. The more details about your plans with this software, the better, but even just sending us an email stating you just installed it is very helpful.</li>
</ul>
<p>We recommend you print these instructions for future reference.</p>
<?php
echo "<p> The selected theme is :</p>";
$installer->displayNewThemeDiv();
if (empty($installer->clone_database)) {
echo "<p><b>The initial OpenEMR user is <span class='text-primary'>'" . text($installer->iuser) . "'</span> and the password is <span class='text-primary'>'" . text($installer->iuserpass) . "'</span></b></p>";
} else {
echo "<p>The initial OpenEMR user name and password is the same as that of source site <b>'" . text($installer->source_site_id) . "'</span></b></p>";
}
echo "<p>If you edited the PHP or Apache configuration files during this installation process, then we recommend you restart your Apache server before following below OpenEMR link.</p>";
echo "<p>In Linux use the following command:</p>";
echo "<p><code>sudo apachectl -k restart</code></p>";
?>
<p>Click to start using OpenEMR.</p>
<div class="row">
<div class="col-12">
<a href='./?site=<?php echo attr_url($site_id); ?>' class='btn btn-primary'>
<i class="fas fa-chevron-right"></i> Start
</a>
</div>
</div>
</div>
<?php
$installer->setCurrentTheme();
$end_div = <<<ENDDIV
</div>
</div>
</div><!--end of container div-->
ENDDIV;
echo $end_div . "\r\n";
$installer->setupHelpModal();
echo "</body>" . "\r\n";
echo "</html>" . "\r\n";
exit();
}
?>
<?php
$inst = isset($_POST["inst"]) ? ($_POST["inst"]) : '';
switch ($state) {
case 1:
$_SESSION['bootstrapStateInSetup'] = 2;
$state_esc = text($state);
$site_id_esc = attr($site_id);
$csrf_id_esc = attr(CsrfUtils::collectCsrfToken('state2'));
$step1 = <<<STP1
<h3 class="mb-3 border-bottom">Step $state_esc - Select Database Setup</h3>
<div class="jumbotron p-5">
<p>Now I need to know whether you want me to create the database on my own or if you have already created the database for me to use. For me to create the database, you will need to supply the MySQL root password.</p>
<br />
<p class='p-1 bg-warning'>$caution: clicking on <span class="font-weight-bold">Proceed to Step 2</span> may delete or cause damage to existing data on your system. Before you continue <span class="font-weight-bold">please backup your data</span>.</p>
<br />
<form method='post'>
<input name='state' type='hidden' value='2' />
<input name='site' type='hidden' value='$site_id_esc' />
<input name='csrf_token_form' type='hidden' value='$csrf_id_esc' />
<div class="form-check">
<input checked class='form-check-input' id='inst1' name='inst' type='radio' value='1' />
<label class="form-check-label" for="inst1">
Have setup create the database
</label>
</div>
<br />
<div class="form-check">
<input id='inst2' class='form-check-input' name='inst' type='radio' value='2' />
<label class="form-check-label" for="inst2">
I have already created the database
</label>
</div>
<div class="form-group">
<div class="col mt-3">
<button type='submit' class='btn btn-primary' value='Continue'>
<i class="fas fa-chevron-right"></i> Proceed to Step 2
</button>
</div>
</div>
</form>
<br />
</div>
STP1;
echo $step1 . "\r\n";
break;
case 2:
$_SESSION['bootstrapStateInSetup'] = 3;
$state_esc = text($state);
$site_id_esc = attr($site_id);
$inst_esc = attr($inst);
$csrf_id_esc = attr(CsrfUtils::collectCsrfToken('state3'));
$step2top = <<<STP2TOP
<h3 class="mb-3 border-bottom">Step $state_esc - Database and OpenEMR Initial User Setup Details</h3>
<div class="jumbotron p-5">
<p>Now you need to supply the MySQL server information and path information. Detailed instructions on each item can be found in the
<a href='Documentation/INSTALL' rel='noopener' target='_blank'><u>'INSTALL'</u>
</a> manual file.
</p>
<form method='post' id='myform'>
<input name='state' type='hidden' value='3' />
<input name='site' type='hidden' value='$site_id_esc' />
<input name='inst' type='hidden' value='$inst_esc' />
<input name='csrf_token_form' type='hidden' value='$csrf_id_esc' />
STP2TOP;
echo $step2top . "\r\n";
$step2tabletop1 = <<<STP2TBLTOP1
<fieldset>
<legend name="form_legend" id="form_legend" class='oe-setup-legend'>MySQL Server Details<i id="enter-details-tooltip" class="fa fa-info-circle oe-text-black oe-superscript enter-details-tooltip" aria-hidden="true"></i></legend>
<div class="ml-2 row">
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="server">Server Host:</label>
<a href="#server_info" class="info-anchor icon-tooltip" data-toggle="collapse" ><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='server' id='server' type='text' class='form-control' value='localhost' />
</div>
</div>
<div id="server_info" class="collapse">
<a href="#server_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>If you run MySQL and Apache/PHP on the same computer, then leave this as 'localhost'.</p>
<p>If they are on separate computers, then enter the IP address of the computer running MySQL.</p>
</div>
</div>
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="port">Server Port:</label>
<a href="#port_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='port' id='port' type='text' class='form-control' value='3306' />
</div>
</div>
<div id="port_info" class="collapse">
<a href="#port_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>This is the MySQL port.</p>
<p>The default port for MySQL is 3306.</p>
</div>
</div>
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="dbname">Database Name:</label> <a href="#dbname_info" class="info-anchor icon-tooltip" data-toggle="collapse" ><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='dbname' id='dbname' type='text' class='form-control' value='openemr' />
</div>
</div>
<div id="dbname_info" class="collapse">
<a href="#dbname_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>This will be the name of the OpenEMR database in MySQL.</p>
<p>'openemr' is the recommended name.</p>
<p>This database will contain patient data as well as data pertaining to the OpenEMR installation.</p>
</div>
</div>
</div>
<div class="ml-2 row">
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="login">Login Name:</label> <a href="#login_info" class="info-anchor icon-tooltip" data-toggle="collapse" ><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='login' ID='login' type='text' class='form-control' value='openemr' />
</div>
</div>
<div id="login_info" class="collapse">
<a href="#login_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>This is the name that OpenEMR will use to login to the MySQL database.</p>
<p>'openemr' is the recommended name.</p>
</div>
</div>
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="pass">Password:</label>
<a href="#pass_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='pass' id='pass' class='form-control' type='password' value='' required />
</div>
</div>
<div id="pass_info" class="collapse">
<a href="#pass_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>This is the Login Password that OpenEMR will use to accesses the MySQL database.</p>
<p>It should be at least 12 characters long and composed of both numbers and letters.</p>
<p>It cannot contain any of these characters: \ ; ( ) < > / ' "</p>
</div>
</div>
STP2TBLTOP1;
echo $step2tabletop1 . "\r\n";
if ($inst != 2) {
$step2tabletop2 = <<<STP2TBLTOP2
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="root">Name for Root Account:</label>
<a href="#root_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='root' id='root' type='text' class='form-control' value='root' />
</div>
</div>
<div id="root_info" class="collapse">
<a href="#root_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>This is name for the MySQL root account.</p>
<p>For localhost, it is usually ok to leave it as 'root'.</p>
</div>
</div>
</div>
<div class="ml-2 row">
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="rootpass">Root Password:</label>
<a href="#rootpass_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='rootpass' id='rootpass' type='password' class='form-control' value='' />
</div>
</div>
<div id="rootpass_info" class="collapse">
<a href="#rootpass_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>This is your MySQL server root password.</p>
</div>
</div>
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="loginhost">User Hostname:</label>
<a href="#loginhost_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='loginhost' id='loginhost' type='text' class='form-control' value='localhost' />
</div>
</div>
<div id="loginhost_info" class="collapse">
<a href="#loginhost_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>If you run Apache/PHP and MySQL on the same computer, then leave this as 'localhost'.</p>
<p>If they are on separate computers, then enter the IP address of the computer running Apache/PHP.</p>
</div>
</div>
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="collate">UTF-8 Collation:</label> <a href="#collate_info" class="info-anchor icon-tooltip" data-toggle="collapse" ><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<select name='collate' id=='collate' class='form-control'>
<option selected value='utf8mb4_general_ci'>
General (Recommended)
</option>
<option value='utf8mb4_unicode_ci'>
Unicode
</option>
<option value='utf8mb4_roman_ci'>
Classical Latin
</option>
<option value='utf8mb4_croatian_ci'>
Croatian
</option>
<option value='utf8mb4_czech_ci'>
Czech
</option>
<option value='utf8mb4_danish_ci'>
Danish
</option>
<option value='utf8mb4_esperanto_ci'>
Esperanto
</option>
<option value='utf8mb4_estonian_ci'>
Estonian
</option>
<option value='utf8mb4_german2_ci'>
German
</option>
<option value='utf8mb4_hungarian_ci'>
Hungarian
</option>
<option value='utf8mb4_icelandic_ci'>
Icelandic
</option>
<option value='utf8mb4_latvian_ci'>
Latvian
</option>
<option value='utf8mb4_lithuanian_ci'>
Lithuanian
</option>
<option value='utf8mb4_persian_ci'>
Persian
</option>
<option value='utf8mb4_polish_ci'>
Polish
</option>
<option value='utf8mb4_romanian_ci'>
Romanian
</option>
<option value='utf8mb4_sinhala_ci'>
Sinhala
</option>
<option value='utf8mb4_slovak_ci'>
Slovak
</option>
<option value='utf8mb4_slovenian_ci'>
Slovenian
</option>
<option value='utf8mb4_spanish_ci'>
Spanish (Modern)
</option>
<option value='utf8mb4_spanish2_ci'>
Spanish (Traditional)
</option>
<option value='utf8mb4_swedish_ci'>
Swedish
</option>
<option value='utf8mb4_turkish_ci'>
Turkish
</option>
<option value='utf8mb4_vietnamese_ci'>
Vietnamese
</option>
</select>
</div>
</div>
<div id="collate_info" class="collapse">
<a href="#collate_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>This is the collation setting for MySQL.</p>
<p>Collation refers to a set of rules that determine how data is sorted and compared in a database.</p>
<p>Leave as 'General' if you are not sure.</p>
<p>If the language you are planning to use in OpenEMR is in the menu, then you can select it.</p>
<p>Otherwise, just select 'General'.</p>
</div>
</div>
</div>
STP2TBLTOP2;
echo $step2tabletop2 . "\r\n";
}
// Include a "source" site ID drop-list and a checkbox to indicate
// if cloning its database. When checked, do not display initial user
// and group stuff below.
$dh = opendir($OE_SITES_BASE);
if (!$dh) {
die("Cannot read directory '" . text($OE_SITES_BASE) . "'.");
}
$siteslist = array();
while (false !== ($sfname = readdir($dh))) {
if (substr($sfname, 0, 1) == '.') {
continue;
}
if ($sfname == 'CVS') {
continue;
}
if ($sfname == $site_id) {
continue;
}
$sitedir = "$OE_SITES_BASE/$sfname";
if (!is_dir($sitedir)) {
continue;
}
if (!is_file("$sitedir/sqlconf.php")) {
continue;
}
$siteslist[$sfname] = $sfname;
}
closedir($dh);
// If this is not the first site...
if (!empty($siteslist)) {
ksort($siteslist);
$source_site_top = <<<SOURCESITETOP
<div class="ml-2 row">
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="source_site_id">Source Site:</label>
<a href="#source_site_id_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<select name='source_site_id'id='source_site_id' class='form-control'>
SOURCESITETOP;
echo $source_site_top . "\r\n";
foreach ($siteslist as $sfname) {
echo "<option value='" . attr($sfname) . "'";
if ($sfname == 'default') {
echo " selected";
}
echo ">" . text($sfname) . "</option>";
}
$source_site_bot = <<<SOURCESITEBOT
</select>
</div>
</div>
<div id="source_site_id_info" class="collapse">
<a href="#source_site_id_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>The site directory that will be a model for the new site.</p>
</div>
</div>
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="clone_database">Clone Source Database:</label>
<a href="#clone_database_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input type='checkbox' name='clone_database' id='clone_database' onclick='cloneClicked()' />
</div>
</div>
<div id="clone_database_info" class="collapse">
<a href="#clone_database_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>Clone the source site's database instead of creating a fresh one.</p>
</div>
</div>
</div>
SOURCESITEBOT;
echo $source_site_bot . "\r\n";
}
$randomusernamepre = RandomGenUtils::produceRandomString(3, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
$randomusernamepost = RandomGenUtils::produceRandomString(2, "0123456789");
$randomusername = $randomusernamepre . "-admin-" . $randomusernamepost;
// App Based TOTP secret
// Shared key (per rfc6238 and rfc4226) should be 20 bytes (160 bits) and encoded in base32, which should
// be 32 characters in base32
// Would be nice to use the OpenEMR\Common\Utils\RandomGenUtils\produceRandomBytes() function and then encode to base32,
// but does not appear to be a standard way to encode binary to base32 in php.
$randomsecret = RandomGenUtils::produceRandomString(32, "234567ABCDEFGHIJKLMNOPQRSTUVWXYZ");
if (empty($randomsecret) || empty($randomusernamepre) || empty($randomusernamepost)) {
error_log('OpenEMR Error : Random String error - exiting');
die();
}
$disableCheckbox = "";
if (empty($randomsecret)) {
$randomsecret = "";
$disableCheckbox = "disabled";
}
$randomsecret_esc = attr($randomsecret);
$randomusername_esc = attr($randomusername);
$step2tablebot = <<<STP2TBLBOT
</fieldset>
<br />
<fieldset class='noclone'>
<legend name="form_legend" id="form_legend" class='oe-setup-legend'>OpenEMR Initial User Details<i id="enter-details-tooltip" class="fa fa-info-circle oe-text-black oe-superscript enter-details-tooltip" aria-hidden="true"></i></legend>
<div class="ml-2 row">
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="iuser">Initial User Login Name:</label> <a href="#iuser_info" class="info-anchor icon-tooltip" data-toggle="collapse" ><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='iuser' id='iuser' type='text' class='form-control' value='$randomusername_esc' minlength='12' />
</div>
</div>
<div id="iuser_info" class="collapse">
<a href="#iuser_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>This is the login name of the first user that will be created for you.</p>
<p>Limit this to one word with at least 12 characters and composed of both numbers and letters.</p>
</div>
</div>
<div class="col-sm-4">
<div class="clearfix form-group">
<div class="label-div">
<label class="font-weight-bold" for="iuserpass">Initial User Password:</label>
<a href="#iuserpass_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
</div>
<div>
<input name='iuserpass' id='iuserpass' type='password' class='form-control' value='' minlength='12' />
</div>
</div>
<div id="iuserpass_info" class="collapse">
<a href="#iuserpass_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
<p>This is the password for the initial user.
</div>
</div>
<div class="col-sm-4">
<div class="clearfix form-group">