PHP8 and CCDA (#4486)
[openemr.git] / setup.php
blob32c8f88511008ca9e2d7397d80a6f80fdf04dc6d
1 <?php
3 /**
5 * Installation script.
7 * @package OpenEMR
8 * @link https://www.open-emr.org
9 * @author Roberto Vasquez <robertogagliotta@gmail.com>
10 * @author Scott Wakefield <scott@npclinics.com.au>
11 * @author Ranganath Pathak <pathak@scrs1.org>
12 * @author Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2016 Roberto Vasquez <robertogagliotta@gmail.com>
14 * @copyright Copyright (c) 2016 Scott Wakefield <scott@npclinics.com.au>
15 * @copyright Copyright (c) 2019 Ranganath Pathak <pathak@scrs1.org>
16 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
17 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
20 // Checks if the server's PHP version is compatible with OpenEMR:
21 require_once(dirname(__FILE__) . "/src/Common/Compatibility/Checker.php");
22 $response = OpenEMR\Common\Compatibility\Checker::checkPhpVersion();
23 if ($response !== true) {
24 die(htmlspecialchars($response));
27 // Set the maximum excution time and time limit to unlimited.
28 ini_set('max_execution_time', 0);
29 ini_set('display_errors', 0);
30 set_time_limit(0);
32 // Warning. If you set $allow_multisite_setup to true, this is a potential security vulnerability.
33 // Recommend setting it back to false (or removing this setup.php script entirely) after you
34 // are done with the multisite procedure.
35 $allow_multisite_setup = false;
37 // Warning. If you set $allow_cloning_setup to true, this is a potential security vulnerability.
38 // Recommend setting it back to false (or removing this setup.php script entirely) after you
39 // are done with the cloning setup procedure.
40 $allow_cloning_setup = false;
41 if (!$allow_cloning_setup && !empty($_REQUEST['clone_database'])) {
42 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");
45 function recursive_writable_directory_test($dir)
47 // first, collect the directory and subdirectories
48 $ri = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
49 $dirNames = array();
50 foreach ($ri as $file) {
51 if ($file->isDir()) {
52 if (!preg_match("/\.\.$/", $file->getPathname())) {
53 $dirName = realpath($file->getPathname());
54 if (!in_array($dirName, $dirNames)) {
55 $dirNames[] = $dirName;
61 // second, flag the directories that are not writable
62 $resultsNegative = array();
63 foreach ($dirNames as $value) {
64 if (!is_writable($value)) {
65 $resultsNegative[] = $value;
69 // third, send the output and return if didn't pass the test
70 if (!empty($resultsNegative)) {
71 echo "<p>";
72 $mainDirTest = "";
73 $outputs = array();
74 foreach ($resultsNegative as $failedDir) {
75 if (basename($failedDir) == basename($dir)) {
76 // need to reorder output so the main directory is at the top of the list
77 $mainDirTest = "<span class='text-danger'>UNABLE</span> to open directory '" . realpath($failedDir) . "' for writing by web server.<br />\r\n";
78 } else {
79 $outputs[] = "<span class='text-danger'>UNABLE</span> to open subdirectory '" . realpath($failedDir) . "' for writing by web server.<br />\r\n";
82 if ($mainDirTest) {
83 // need to reorder output so the main directory is at the top of the list
84 array_unshift($outputs, $mainDirTest);
86 foreach ($outputs as $output) {
87 echo $output;
89 echo "(configure directory permissions; see below for further instructions)</p>\r\n";
90 return 1;
91 } else {
92 echo "<code class='ml-5'>" . realpath($dir) . "</code> directory and its subdirectories are <span class='text-success font-weight-bold'>ready</span>.<br /><br />\r\n";
93 return 0;
97 // Include standard libraries/classes
98 require_once dirname(__FILE__) . "/vendor/autoload.php";
100 use OpenEMR\Common\Utils\RandomGenUtils;
102 $COMMAND_LINE = php_sapi_name() == 'cli';
104 $state = isset($_POST["state"]) ? ($_POST["state"]) : '';
105 $installer = new Installer($_REQUEST);
106 // Make this true for IPPF.
107 $ippf_specific = false;
109 $error_page_end = <<<EPE
110 </div>
111 </div>
112 </div><!--end of container div-->
113 </body>
114 </html>
115 EPE;
117 // If this script was invoked with no site ID, then ask for one.
118 if (!$COMMAND_LINE && empty($_REQUEST['site'])) {
119 $site_id = <<<SITEID
120 <!DOCTYPE html>
121 <html>
122 <head>
123 <title>OpenEMR Setup Tool</title>
124 <link rel="stylesheet" href="public/assets/bootstrap/dist/css/bootstrap.min.css">
125 <script src="public/assets/jquery/dist/jquery.min.js"></script>
126 <script src="public/assets/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
127 <link rel="stylesheet" href="public/assets/@fortawesome/fontawesome-free/css/all.min.css">
128 <link rel="shortcut icon" href="public/images/favicon.ico" />
129 <style>
130 .oe-pull-away {
131 float:right;
133 </style>
134 </head>
135 <body>
136 <nav class="navbar navbar-expand navbar-light bg-light">
137 <div class="container">
138 <a class="navbar-brand" href="#">OpenEMR Setup</a>
139 <div class="collapse navbar-collapse justify-content-end">
140 <ul class="navbar-nav">
141 <li class="nav-item active">
142 <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>
143 </li>
144 </ul>
145 </div>
146 </div>
147 </nav>
149 <div class='container mt-3'>
150 <div class="row">
151 <div class="col-12">
152 <h3 class="mb-3 border-bottom">Optional Site ID Selection</h3>
153 <div class="jumbotron p-5">
155 Most OpenEMR installations support only one site. If that is
156 true for you then ignore the rest of this text and just click Continue.
157 </p>
158 <p class='p-2 bg-warning'>
159 If you are using the multisite setup module for the first time please read the
160 'Multi Site Installation' section of the help file before proceeding.
161 </p>
163 Otherwise please enter a unique Site ID here.
164 </p>
166 A Site ID is a short identifier with no spaces or special
167 characters other than periods or dashes. It is case-sensitive and we
168 suggest sticking to lower case letters for ease of use.
169 </p>
171 If each site will have its own host/domain name, then use that
172 name as the Site ID (e.g. www.example.com).
173 </p>
175 The site ID is used to identify which site you will log in to.
176 If it is a hostname then it is taken from the hostname in the URL.
177 Otherwise you must append "?site=<i>siteid</i>" to the URL used for
178 logging in.
179 </p>
181 It is OK for one of the sites to have "default" as its ID. This
182 is the ID that will be used if it cannot otherwise be determined.
183 </p>
184 <br />
185 <form method='post'>
186 <input type='hidden' name='state' value='0' />
187 <div class="form-row">
188 <div class="col-auto">
189 Site ID:
190 </div>
191 <div class="col">
192 <input type='text' class='form-control' name='site' value='default'>
193 </div>
194 <div class="col-12 mt-3">
195 <button type='submit' class='btn btn-primary' value='Continue'><i class="fas fa-chevron-right"></i> Continue</button>
196 </div>
197 </div>
198 </form>
199 </div>
200 </div>
201 </div>
202 </div><!--end of container div-->
203 SITEID;
204 echo $site_id . "\r\n";
205 $installer->setupHelpModal();
206 echo "</body>" . "\r\n";
207 echo "</html>" . "\r\n";
209 exit();
212 // Support "?site=siteid" in the URL, otherwise assume "default".
213 $site_id = 'default';
214 if (!$COMMAND_LINE && !empty($_REQUEST['site'])) {
215 $site_id = trim($_REQUEST['site']);
218 // Die if site ID is empty or has invalid characters.
219 if (empty($site_id) || preg_match('/[^A-Za-z0-9\\-.]/', $site_id)) {
220 die("Site ID '" . htmlspecialchars($site_id, ENT_NOQUOTES) . "' contains invalid characters.");
223 // If multisite is turned off, then only allow default for site.
224 if (!$allow_multisite_setup && $site_id != 'default') {
225 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");
228 // Disable file and directory permissions check by setting to false
229 $checkPermissions = true;
231 global $OE_SITE_DIR; // The Installer sets this
233 $docsDirectory = "$OE_SITE_DIR/documents";
235 //These are files and dir checked before install for
236 // correct permissions.
237 if (is_dir($OE_SITE_DIR)) {
238 $writableFileList = array($installer->conffile);
239 $writableDirList = array($docsDirectory);
240 } else {
241 $writableFileList = array();
242 $writableDirList = array($OE_SITES_BASE);
245 // Include the sqlconf file if it exists yet.
246 $config = 0;
247 if (file_exists($OE_SITE_DIR)) {
248 include_once($installer->conffile);
249 } elseif ($state > 3) {
250 // State 3 should have created the site directory if it is missing.
251 die("Internal error, site directory is missing.");
254 <html>
255 <head>
256 <title>OpenEMR Setup Tool</title>
257 <!--<link rel=stylesheet href="interface/themes/style_blue.css">-->
258 <link rel="stylesheet" href="public/assets/bootstrap/dist/css/bootstrap.min.css">
259 <script src="public/assets/jquery/dist/jquery.min.js"></script>
260 <script src="public/assets/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
261 <link rel="stylesheet" href="public/assets/@fortawesome/fontawesome-free/css/all.min.css">
262 <link rel="shortcut icon" href="public/images/favicon.ico" />
264 <style>
265 .noclone { }
266 table.phpset {
267 border-collapse:collapse;
269 table.phpset td, table.phpset th {
270 font-size:9pt;
271 border:1px solid gray;
272 padding:2px;
274 .table.no-border tr td, .table.no-border tr th {
275 border-width: 0;
277 td {
278 font-size:10pt;
280 .inputtext {
281 padding-left:2px;
282 padding-right:2px;
285 .button {
286 font-family:sans-serif;
287 font-size:9pt;
288 font-weight:bold;
291 .label-div > a {
292 display:none;
294 .label-div:hover > a {
295 display:inline-block;
297 div[id$="_info"] {
298 background: #F7FAB3;
299 padding: 20px;
300 margin: 10px 15px 0px 15px;
302 div[id$="_info"] > a {
303 margin-left:10px;
305 .checkboxgroup {
306 display: inline-block;
307 text-align: center;
309 .checkboxgroup label {
310 display: block;
312 .oe-pull-away{
313 float:right;
315 .oe-help-x {
316 color: grey;
317 padding: 0 5px;
319 .oe-superscript {
320 position: relative;
321 top: -.5em;
322 font-size: 70%!important;
324 .oe-setup-legend{
325 background-color: #f5f5f5;
326 padding:0 10px;
328 .button-wait {
329 color: grey;
330 cursor: not-allowed;
331 opacity: 0.6;
333 @media only screen {
334 fieldset > [class*="col-"] {
335 width: 100%;
336 text-align:left!Important;
339 </style>
340 <script>
341 // onclick handler for "clone database" checkbox
342 function cloneClicked() {
343 var cb = document.forms[0].clone_database;
344 $('.noclone').css('display', cb.checked ? 'none' : 'block');
346 </script>
348 </head>
349 <body>
350 <nav class="navbar navbar-expand navbar-light bg-light">
351 <div class="container">
352 <a class="navbar-brand" href="#">OpenEMR Setup</a>
353 <div class="collapse navbar-collapse justify-content-end">
354 <ul class="navbar-nav">
355 <li class="nav-item active">
356 <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>
357 </li>
358 </ul>
359 </div>
360 </div>
361 </nav>
362 <div class='mt-3 container'>
363 <div class="row">
364 <div class="col-12">
365 <?php
366 $error = "<span class='text-danger font-weight-bold'>ERROR</span>";
367 $caution = "<span class='text-danger font-weight-bold'>CAUTION</span>";
368 $ok = "<span class='text-success font-weight-bold'>OK</span>";
369 $note = "<span class='text-primary font-weight-bold'>NOTE</span>";
371 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
372 echo "$caution: It appears that you have register_globals enabled in your php.ini\n" .
373 "configuration file. This causes unacceptable security risks. You must\n" .
374 "turn it off before continuing with installation.\n";
375 exit(1);
378 if (!extension_loaded("xml")) {
379 echo "$error: PHP XML extension missing. To continue, install PHP XML extension, then restart web server.";
380 exit(1);
383 if (!(extension_loaded("mysql") || extension_loaded("mysqlnd") || extension_loaded("mysqli"))) {
384 echo "$error: PHP MySQL extension missing. To continue, install and enable MySQL extension, then restart web server.";
385 exit(1);
388 if (!(extension_loaded("mbstring") )) {
389 echo "$error: PHP mb_string extension missing. To continue, install and enable mb_string extension, then restart web server.";
390 exit(1);
393 if (!(extension_loaded("openssl") )) {
394 echo "$error: PHP openssl extension missing. To continue, install PHP openssl extension, then restart web server.";
395 exit(1);
399 <?php
400 if ($state == 7) {
402 <h3 class="mb-3 border-bottom">Final step - Success</h3>
403 <div class="jumbotron p-5">
404 <p>Congratulations! OpenEMR is now installed.</p>
405 <ul>
406 <li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
407 OpenEMR's admin->acl menu.</li>
408 <li>Reviewing <code> <?php echo $OE_SITE_DIR; ?>/config.php </code> is a good idea. This file
409 contains some settings that you may want to change.</li>
410 <li>There's much information and many extra tools bundled within the OpenEMR installation directory.
411 Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
412 <li>To ensure a consistent look and feel throughout the application,
413 <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>
414 <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>
415 <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:hello@open-emr.org">hello@open-emr.org</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>
416 </ul>
417 <p>We recommend you print these instructions for future reference.</p>
418 <?php
419 echo "<p> The selected theme is :</p>";
420 $installer->displayNewThemeDiv();
421 if (empty($installer->clone_database)) {
422 echo "<p><b>The initial OpenEMR user is <span class='text-primary'>'" . $installer->iuser . "'</span> and the password is <span class='text-primary'>'" . $installer->iuserpass . "'</span></b></p>";
423 } else {
424 echo "<p>The initial OpenEMR user name and password is the same as that of source site <b>'" . $installer->source_site_id . "'</span></b></p>";
426 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>";
427 echo "<p>In Linux use the following command:</p>";
428 echo "<p><code>sudo apachectl -k restart</code></p>";
431 <p>Click to start using OpenEMR.</p>
432 <div class="row">
433 <div class="col-12">
434 <a href='./?site=<?php echo $site_id; ?>' class='btn btn-primary'>
435 <i class="fas fa-chevron-right"></i> Start
436 </a>
437 </div>
438 </div>
440 </div>
441 <?php
442 $installer->setCurrentTheme();
444 $end_div = <<<ENDDIV
445 </div>
446 </div>
447 </div><!--end of container div-->
448 ENDDIV;
449 echo $end_div . "\r\n";
450 $installer->setupHelpModal();
451 echo "</body>" . "\r\n";
452 echo "</html>" . "\r\n";
454 exit();
458 <?php
460 $inst = isset($_POST["inst"]) ? ($_POST["inst"]) : '';
462 if (($config == 1) && ($state < 4)) {
463 echo "OpenEMR has already been installed. If you wish to force re-installation, then edit $installer->conffile (change the 'config' variable to 0), and re-run this script.<br />\n";
464 } else {
465 switch ($state) {
466 case 1:
467 $step1 = <<<STP1
468 <h3 class="mb-3 border-bottom">Step $state - Select Database Setup</h3>
469 <div class="jumbotron p-5">
470 <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>
471 <br />
472 <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>
473 <br />
474 <form method='post'>
475 <input name='state' type='hidden' value='2' />
476 <input name='site' type='hidden' value='$site_id' />
477 <div class="form-check">
478 <input checked class='form-check-input' id='inst1' name='inst' type='radio' value='1' />
479 <label class="form-check-label" for="inst1">
480 Have setup create the database
481 </label>
482 </div>
483 <br />
484 <div class="form-check">
485 <input id='inst2' class='form-check-input' name='inst' type='radio' value='2' />
486 <label class="form-check-label" for="inst2">
487 I have already created the database
488 </label>
489 </div>
490 <div class="form-group">
491 <div class="col mt-3">
492 <button type='submit' class='btn btn-primary' value='Continue'>
493 <i class="fas fa-chevron-right"></i> Proceed to Step 2
494 </button>
495 </div>
496 </div>
497 </form>
498 <br />
499 </div>
500 STP1;
501 echo $step1 . "\r\n";
502 break;
504 case 2:
505 $step2top = <<<STP2TOP
506 <h3 class="mb-3 border-bottom">Step $state - Database and OpenEMR Initial User Setup Details</h3>
507 <div class="jumbotron p-5">
508 <p>Now you need to supply the MySQL server information and path information. Detailed instructions on each item can be found in the
509 <a href='Documentation/INSTALL' rel='noopener' target='_blank'><u>'INSTALL'</u>
510 </a> manual file.
511 </p>
512 <form method='post' id='myform'>
513 <input name='state' type='hidden' value='3' />
514 <input name='site' type='hidden' value='$site_id' />
515 <input name='inst' type='hidden' value='$inst' />
516 STP2TOP;
517 echo $step2top . "\r\n";
520 $step2tabletop1 = <<<STP2TBLTOP1
521 <fieldset>
522 <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>
523 <div class="ml-2 row">
524 <div class="col-sm-4">
525 <div class="clearfix form-group">
526 <div class="label-div">
527 <label class="font-weight-bold" for="server">Server Host:</label>
528 <a href="#server_info" class="info-anchor icon-tooltip" data-toggle="collapse" ><i class="fa fa-question-circle" aria-hidden="true"></i></a>
529 </div>
530 <div>
531 <input name='server' id='server' type='text' class='form-control' value='localhost' />
532 </div>
533 </div>
534 <div id="server_info" class="collapse">
535 <a href="#server_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
536 <p>If you run MySQL and Apache/PHP on the same computer, then leave this as 'localhost'.</p>
537 <p>If they are on separate computers, then enter the IP address of the computer running MySQL.</p>
538 </div>
539 </div>
540 <div class="col-sm-4">
541 <div class="clearfix form-group">
542 <div class="label-div">
543 <label class="font-weight-bold" for="port">Server Port:</label>
544 <a href="#port_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
545 </div>
546 <div>
547 <input name='port' id='port' type='text' class='form-control' value='3306' />
548 </div>
549 </div>
550 <div id="port_info" class="collapse">
551 <a href="#port_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
552 <p>This is the MySQL port.</p>
553 <p>The default port for MySQL is 3306.</p>
554 </div>
555 </div>
556 <div class="col-sm-4">
557 <div class="clearfix form-group">
558 <div class="label-div">
559 <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>
560 </div>
561 <div>
562 <input name='dbname' id='dbname' type='text' class='form-control' value='openemr' />
563 </div>
564 </div>
565 <div id="dbname_info" class="collapse">
566 <a href="#dbname_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
567 <p>This will be the name of the OpenEMR database in MySQL.</p>
568 <p>'openemr' is the recommended name.</p>
569 <p>This database will contain patient data as well as data pertaining to the OpenEMR installation.</p>
570 </div>
571 </div>
572 </div>
573 <div class="ml-2 row">
574 <div class="col-sm-4">
575 <div class="clearfix form-group">
576 <div class="label-div">
577 <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>
578 </div>
579 <div>
580 <input name='login' ID='login' type='text' class='form-control' value='openemr' />
581 </div>
582 </div>
583 <div id="login_info" class="collapse">
584 <a href="#login_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
585 <p>This is the name that OpenEMR will use to login to the MySQL database.</p>
586 <p>'openemr' is the recommended name.</p>
587 </div>
588 </div>
589 <div class="col-sm-4">
590 <div class="clearfix form-group">
591 <div class="label-div">
592 <label class="font-weight-bold" for="pass">Password:</label>
593 <a href="#pass_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
594 </div>
595 <div>
596 <input name='pass' id='pass' class='form-control' type='password' value='' required />
597 </div>
598 </div>
599 <div id="pass_info" class="collapse">
600 <a href="#pass_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
601 <p>This is the Login Password that OpenEMR will use to accesses the MySQL database.</p>
602 <p>It should be at least 12 characters long and composed of both numbers and letters.</p>
603 </div>
604 </div>
605 STP2TBLTOP1;
606 echo $step2tabletop1 . "\r\n";
607 if ($inst != 2) {
608 $step2tabletop2 = <<<STP2TBLTOP2
609 <div class="col-sm-4">
610 <div class="clearfix form-group">
611 <div class="label-div">
612 <label class="font-weight-bold" for="root">Name for Root Account:</label>
613 <a href="#root_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
614 </div>
615 <div>
616 <input name='root' id='root' type='text' class='form-control' value='root' />
617 </div>
618 </div>
619 <div id="root_info" class="collapse">
620 <a href="#root_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
621 <p>This is name for the MySQL root account.</p>
622 <p>For localhost, it is usually ok to leave it as 'root'.</p>
623 </div>
624 </div>
625 </div>
626 <div class="ml-2 row">
627 <div class="col-sm-4">
628 <div class="clearfix form-group">
629 <div class="label-div">
630 <label class="font-weight-bold" for="rootpass">Root Password:</label>
631 <a href="#rootpass_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
632 </div>
633 <div>
634 <input name='rootpass' id='rootpass' type='password' class='form-control' value='' />
635 </div>
636 </div>
637 <div id="rootpass_info" class="collapse">
638 <a href="#rootpass_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
639 <p>This is your MySQL server root password.</p>
640 </div>
641 </div>
642 <div class="col-sm-4">
643 <div class="clearfix form-group">
644 <div class="label-div">
645 <label class="font-weight-bold" for="loginhost">User Hostname:</label>
646 <a href="#loginhost_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
647 </div>
648 <div>
649 <input name='loginhost' id='loginhost' type='text' class='form-control' value='localhost' />
650 </div>
651 </div>
652 <div id="loginhost_info" class="collapse">
653 <a href="#loginhost_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
654 <p>If you run Apache/PHP and MySQL on the same computer, then leave this as 'localhost'.</p>
655 <p>If they are on separate computers, then enter the IP address of the computer running Apache/PHP.</p>
656 </div>
657 </div>
658 <div class="col-sm-4">
659 <div class="clearfix form-group">
660 <div class="label-div">
661 <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>
662 </div>
663 <div>
664 <select name='collate' id=='collate' class='form-control'>
665 <option selected value='utf8mb4_general_ci'>
666 General (Recommended)
667 </option>
668 <option value='utf8mb4_unicode_ci'>
669 Unicode
670 </option>
671 <option value='utf8mb4_roman_ci'>
672 Classical Latin
673 </option>
674 <option value='utf8mb4_croatian_ci'>
675 Croatian
676 </option>
677 <option value='utf8mb4_czech_ci'>
678 Czech
679 </option>
680 <option value='utf8mb4_danish_ci'>
681 Danish
682 </option>
683 <option value='utf8mb4_esperanto_ci'>
684 Esperanto
685 </option>
686 <option value='utf8mb4_estonian_ci'>
687 Estonian
688 </option>
689 <option value='utf8mb4_german2_ci'>
690 German
691 </option>
692 <option value='utf8mb4_hungarian_ci'>
693 Hungarian
694 </option>
695 <option value='utf8mb4_icelandic_ci'>
696 Icelandic
697 </option>
698 <option value='utf8mb4_latvian_ci'>
699 Latvian
700 </option>
701 <option value='utf8mb4_lithuanian_ci'>
702 Lithuanian
703 </option>
704 <option value='utf8mb4_persian_ci'>
705 Persian
706 </option>
707 <option value='utf8mb4_polish_ci'>
708 Polish
709 </option>
710 <option value='utf8mb4_romanian_ci'>
711 Romanian
712 </option>
713 <option value='utf8mb4_sinhala_ci'>
714 Sinhala
715 </option>
716 <option value='utf8mb4_slovak_ci'>
717 Slovak
718 </option>
719 <option value='utf8mb4_slovenian_ci'>
720 Slovenian
721 </option>
722 <option value='utf8mb4_spanish_ci'>
723 Spanish (Modern)
724 </option>
725 <option value='utf8mb4_spanish2_ci'>
726 Spanish (Traditional)
727 </option>
728 <option value='utf8mb4_swedish_ci'>
729 Swedish
730 </option>
731 <option value='utf8mb4_turkish_ci'>
732 Turkish
733 </option>
734 <option value='utf8mb4_vietnamese_ci'>
735 Vietnamese
736 </option>
737 </select>
738 </div>
739 </div>
740 <div id="collate_info" class="collapse">
741 <a href="#collate_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
742 <p>This is the collation setting for MySQL.</p>
743 <p>Collation refers to a set of rules that determine how data is sorted and compared in a database.</p>
744 <p>Leave as 'General' if you are not sure.</p>
745 <p>If the language you are planning to use in OpenEMR is in the menu, then you can select it.</p>
746 <p>Otherwise, just select 'General'.</p>
747 </div>
748 </div>
749 </div>
750 STP2TBLTOP2;
751 echo $step2tabletop2 . "\r\n";
753 // Include a "source" site ID drop-list and a checkbox to indicate
754 // if cloning its database. When checked, do not display initial user
755 // and group stuff below.
756 $dh = opendir($OE_SITES_BASE);
757 if (!$dh) {
758 die("Cannot read directory '$OE_SITES_BASE'.");
761 $siteslist = array();
762 while (false !== ($sfname = readdir($dh))) {
763 if (substr($sfname, 0, 1) == '.') {
764 continue;
767 if ($sfname == 'CVS') {
768 continue;
771 if ($sfname == $site_id) {
772 continue;
775 $sitedir = "$OE_SITES_BASE/$sfname";
776 if (!is_dir($sitedir)) {
777 continue;
780 if (!is_file("$sitedir/sqlconf.php")) {
781 continue;
784 $siteslist[$sfname] = $sfname;
787 closedir($dh);
788 // If this is not the first site...
789 if (!empty($siteslist)) {
790 ksort($siteslist);
791 $source_site_top = <<<SOURCESITETOP
792 <div class="ml-2 row">
793 <div class="col-sm-4">
794 <div class="clearfix form-group">
795 <div class="label-div">
796 <label class="font-weight-bold" for="source_site_id">Source Site:</label>
797 <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>
798 </div>
799 <div>
800 <select name='source_site_id'id='source_site_id' class='form-control'>
801 SOURCESITETOP;
802 echo $source_site_top . "\r\n";
803 foreach ($siteslist as $sfname) {
804 echo "<option value='$sfname'";
805 if ($sfname == 'default') {
806 echo " selected";
809 echo ">$sfname</option>";
811 $source_site_bot = <<<SOURCESITEBOT
812 </select>
814 </div>
815 </div>
816 <div id="source_site_id_info" class="collapse">
817 <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>
818 <p>The site directory that will be a model for the new site.</p>
819 </div>
820 </div>
821 <div class="col-sm-4">
822 <div class="clearfix form-group">
823 <div class="label-div">
824 <label class="font-weight-bold" for="clone_database">Clone Source Database:</label>
825 <a href="#clone_database_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
826 </div>
827 <div>
828 <input type='checkbox' name='clone_database' id='clone_database' onclick='cloneClicked()' />
829 </div>
830 </div>
831 <div id="clone_database_info" class="collapse">
832 <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>
833 <p>Clone the source site's database instead of creating a fresh one.</p>
834 </div>
835 </div>
836 </div>
837 SOURCESITEBOT;
838 echo $source_site_bot . "\r\n";
841 $randomusernamepre = RandomGenUtils::produceRandomString(3, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
842 $randomusernamepost = RandomGenUtils::produceRandomString(2, "0123456789");
843 $randomusername = $randomusernamepre . "-admin-" . $randomusernamepost;
845 // App Based TOTP secret
846 // Shared key (per rfc6238 and rfc4226) should be 20 bytes (160 bits) and encoded in base32, which should
847 // be 32 characters in base32
848 // Would be nice to use the OpenEMR\Common\Utils\RandomGenUtils\produceRandomBytes() function and then encode to base32,
849 // but does not appear to be a standard way to encode binary to base32 in php.
850 $randomsecret = RandomGenUtils::produceRandomString(32, "234567ABCDEFGHIJKLMNOPQRSTUVWXYZ");
851 if (empty($randomsecret) || empty($randomusernamepre) || empty($randomusernamepost)) {
852 error_log('OpenEMR Error : Random String error - exiting');
853 die();
855 $disableCheckbox = "";
856 if (empty($randomsecret)) {
857 $randomsecret = "";
858 $disableCheckbox = "disabled";
861 $step2tablebot = <<<STP2TBLBOT
862 </fieldset>
863 <br />
864 <fieldset class='noclone'>
865 <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>
866 <div class="ml-2 row">
867 <div class="col-sm-4">
868 <div class="clearfix form-group">
869 <div class="label-div">
870 <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>
871 </div>
872 <div>
873 <input name='iuser' id='iuser' type='text' class='form-control' value='$randomusername' minlength='12' />
874 </div>
875 </div>
876 <div id="iuser_info" class="collapse">
877 <a href="#iuser_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
878 <p>This is the login name of the first user that will be created for you.</p>
879 <p>Limit this to one word with at least 12 characters and composed of both numbers and letters.</p>
880 </div>
881 </div>
882 <div class="col-sm-4">
883 <div class="clearfix form-group">
884 <div class="label-div">
885 <label class="font-weight-bold" for="iuserpass">Initial User Password:</label>
886 <a href="#iuserpass_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
887 </div>
888 <div>
889 <input name='iuserpass' id='iuserpass' type='password' class='form-control' value='' minlength='12' />
890 </div>
891 </div>
892 <div id="iuserpass_info" class="collapse">
893 <a href="#iuserpass_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
894 <p>This is the password for the initial user.
895 </div>
896 </div>
897 <div class="col-sm-4">
898 <div class="clearfix form-group">
899 <div class="label-div">
900 <label class="font-weight-bold" for="iufname">Initial User's First Name:</label>
901 <a href="#iufname_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
902 </div>
903 <div>
904 <input name='iufname' id='iufname 'type='text' class='form-control' value='Administrator' />
905 </div>
906 </div>
907 <div id="iufname_info" class="collapse">
908 <a href="#iufname_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
909 <p>This is the First name of the 'initial user'.</p>
910 </div>
911 </div>
912 </div>
913 <div class="ml-2 row">
914 <div class="col-sm-4">
915 <div class="clearfix form-group">
916 <div class="label-div">
917 <label class="font-weight-bold" for="iuname">Initial User's Last Name:</label>
918 <a href="#iuname_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
919 </div>
920 <div>
921 <input name='iuname' id='iuname' type='text' class='form-control' value='Administrator' />
922 </div>
923 </div>
924 <div id="iuname_info" class="collapse">
925 <a href="#iuname_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
926 <p>This is the Last name of the 'initial user'.</p>
927 </div>
928 </div>
929 <div class="col-sm-4">
930 <div class="clearfix form-group">
931 <div class="label-div">
932 <label class="font-weight-bold" for="igroup">Initial Group:</label>
933 <a href="#igroup_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
934 </div>
935 <div>
936 <input name='igroup' id='igroup' class='form-control' type='text' value='Default' />
937 </div>
938 </div>
939 <div id="igroup_info" class="collapse">
940 <a href="#igroup_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
941 <p>This is the group that will be created for your users.</p>
942 <p>This should be the name of your practice.</p>
943 </div>
944 </div>
945 </div>
946 </fieldset>
947 <br />
948 <fieldset class='noclone py-2 bg-warning'>
949 <legend name="form_legend" id="form_legend" class='oe-setup-legend text-danger'>Enable 2 Factor Authentication for Initial User (more secure - optional) <i id="2fa-section" class="fa fa-info-circle oe-text-black oe-superscript 2fa-section-tooltip" aria-hidden="true"></i></legend>
950 <div class="ml-2 row">
951 <div class="col-sm-3">
952 <div class="clearfix form-group">
953 <div class="label-div">
954 <label class="font-weight-bold" for="i2fa">Configure 2FA:</label>
955 <a href="#i2fa_info" class="info-anchor icon-tooltip" data-toggle="collapse"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
956 </div>
957 <div>
958 <input name='i2faenable' id='i2faenable' type='checkbox' $disableCheckbox/> Enable 2FA
959 <input type='hidden' name='i2fasecret' id='i2fasecret' value='$randomsecret' />
960 </div>
961 </div>
962 <div id="i2fa_info" class="collapse">
963 <a href="#i2fa_info" data-toggle="collapse" class="oe-pull-away"><i class="fa fa-times oe-help-x" aria-hidden="true"></i></a>
964 <p>If selected will allow TOTP 2 factor authentication for the initial user.</p>
965 <p>Click on the help file for more information.</p>
966 </div>
967 </div>
968 <div class="col-sm-5">
969 <div class="clearfix form-group">
970 <p class="text-danger font-weight-bold">IMPORTANT IF ENABLED</p>
971 <p>If enabled, you must have an authenticator app on your phone ready to scan the QR code displayed next.</p>
972 </div>
973 </div>
974 <div class="col-sm-4">
975 <div class="clearfix form-group">
976 <p>Example authenticator apps include:</p>
977 <ul>
978 <li>Google Auth
979 (<a href="https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8" target="_blank">iOS</a>, <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&amp;hl=en">Android</a>)</li>
980 <li>Authy
981 (<a href="https://itunes.apple.com/us/app/authy/id494168017?mt=8">iOS</a>, <a href="https://play.google.com/store/apps/details?id=com.authy.authy&amp;hl=en">Android</a>)</li>
982 </ul>
983 </div>
984 </div>
985 </div>
986 </fieldset>
987 <p class='mt-4 mark'>Click the <b>Create DB and User</b> button below to create the database and first user <a href='#create_db_button' title='Click me'><i class="fa fa-arrow-circle-down" aria-hidden="true"></i></a>. $note: This process will take a few minutes.</p>
988 <p class='p-1 bg-success text-white oe-spinner' style='visibility:hidden;'>Upon successful completion will automatically take you to the next step.<i class='fa fa-spinner fa-pulse fa-fw'></i></p>
989 <div class="form-row">
990 <div class="col-12">
991 <button type='submit' id='create_db_button' value='Continue' class='wait btn btn-primary'>
992 <i class="fas fa-chevron-right"></i> Create DB and User
993 </button>
994 </div>
995 </div>
996 </form>
997 </div>
998 STP2TBLBOT;
999 echo $step2tablebot . "\r\n";
1000 break;
1002 case 3:
1003 // Form Validation
1004 // (applicable if not cloning from another database)
1006 $pass_step2_validation = true;
1007 $error_step2_message = "$error - ";
1009 if (! $installer->char_is_valid($_REQUEST['server'])) {
1010 $pass_step2_validation = false;
1011 $error_step2_message .= "A database server host is required <br />\n";
1014 if (! $installer->char_is_valid($_REQUEST['port'])) {
1015 $pass_step2_validation = false;
1016 $error_step2_message .= "A database server port value is required <br />\n";
1019 if (! $installer->databaseNameIsValid($_REQUEST['dbname'])) {
1020 $pass_step2_validation = false;
1021 $error_step2_message .= "A database name is required <br />\n";
1024 if (! $installer->collateNameIsValid($_REQUEST['collate'])) {
1025 $pass_step2_validation = false;
1026 $error_step2_message .= "A collation name is required <br />\n";
1029 if (! $installer->char_is_valid($_REQUEST['login'])) {
1030 $pass_step2_validation = false;
1031 $error_step2_message .= "A database login name is required <br />\n";
1034 if (! $installer->char_is_valid($_REQUEST['pass'])) {
1035 $pass_step2_validation = false;
1036 $error_step2_message .= "A database login password is required <br />\n";
1039 if (!$pass_step2_validation) {
1040 $error_step2_message .= $error_page_end . "\r\n";
1041 die($error_step2_message);
1045 if (empty($installer->clone_database)) {
1046 if (! $installer->login_is_valid()) {
1047 echo "$error. Please pick a proper 'Login Name'.<br />\n";
1048 echo "Click Back in browser to re-enter.<br />\n";
1049 break;
1052 if (! $installer->iuser_is_valid()) {
1053 echo "$error. The 'Initial User' field can only contain one word and no spaces.<br />\n";
1054 echo "Click Back in browser to re-enter.<br />\n";
1055 break;
1058 if (! $installer->user_password_is_valid()) {
1059 echo "$error. Please pick a proper 'Initial User Password'.<br />\n";
1060 echo "Click Back in browser to re-enter.<br />\n";
1061 break;
1065 if (! $installer->password_is_valid()) {
1066 echo "$error. Please pick a proper 'Password'.<br />\n";
1067 echo "Click Back in browser to re-enter.<br />\n";
1068 break;
1071 echo "<h3 class='mb-3 border-bottom'>Step $state - Creating Database and First User</h3>";
1072 echo "<div class='jumbotron p-5'>";
1074 // Skip below if database shell has already been created.
1075 if ($inst != 2) {
1076 echo "Connecting to MySQL Server...\n";
1077 flush();
1078 if (! $installer->root_database_connection()) {
1079 echo "$error. Check your login credentials.\n";
1080 echo $installer->error_message;
1081 break;
1082 } else {
1083 echo "$ok.<br />\n";
1084 flush();
1088 // Only pertinent if cloning another installation database
1089 if ($allow_cloning_setup && !empty($installer->clone_database)) {
1090 echo "Dumping source database...";
1091 flush();
1092 if (! $installer->create_dumpfiles()) {
1093 echo $installer->error_message;
1094 break;
1095 } else {
1096 echo "$ok.<br />\n";
1097 flush();
1101 // Only pertinent if mirroring another installation directory
1102 if (! empty($installer->source_site_id)) {
1103 echo "Creating site directory...";
1104 if (! $installer->create_site_directory()) {
1105 echo $installer->error_message;
1106 break;
1107 } else {
1108 echo "$ok.<br />";
1109 flush();
1113 // Skip below if database shell has already been created.
1114 if ($inst != 2) {
1115 echo "Creating database...\n";
1116 flush();
1117 if (! $installer->create_database()) {
1118 echo "$error. Check your login credentials.\n";
1119 echo $installer->error_message;
1120 break;
1121 } else {
1122 echo "$ok.<br />\n";
1123 flush();
1126 echo "Creating user with permissions for database...\n";
1127 flush();
1128 $user_mysql_error = true;
1129 if (! $installer->create_database_user()) {
1130 echo "$error when creating specified user.\n";
1131 echo $installer->error_message;
1132 break;
1133 } else {
1134 $user_mysql_error = false;
1136 if (! $installer->grant_privileges()) {
1137 echo "$error when granting privileges to the specified user.\n";
1138 echo $installer->error_message;
1139 break;
1140 } else {
1141 $user_mysql_error = false;
1143 if (!$user_mysql_error) {
1144 echo "$ok.<br />\n";
1145 flush();
1148 echo "Reconnecting as new user...\n";
1149 flush();
1150 $installer->disconnect();
1151 } else {
1152 echo "Connecting to MySQL Server...\n";
1155 if (! $installer->user_database_connection()) {
1156 echo "$error. Check your login credentials.\n";
1157 echo $installer->error_message;
1158 break;
1159 } else {
1160 echo "$ok.<br />\n";
1161 flush();
1164 // Load the database files
1165 $dump_results = $installer->load_dumpfiles();
1166 if (! $dump_results) {
1167 echo "$error.\n";
1168 echo $installer->error_message;
1169 break;
1170 } else {
1171 echo $dump_results;
1172 flush();
1175 echo "Writing SQL configuration...\n";
1176 flush();
1177 if (! $installer->write_configuration_file()) {
1178 echo "$error.\n";
1179 echo $installer->error_message;
1180 break;
1181 } else {
1182 echo "$ok.<br />\n";
1183 flush();
1186 // Only pertinent if not cloning another installation database
1187 if (empty($installer->clone_database)) {
1188 echo "Setting version indicators...\n";
1189 flush();
1190 if (! $installer->add_version_info()) {
1191 echo "$error.\n";
1192 echo $installer->error_message;
1194 break;
1195 } else {
1196 echo "$ok<br />\n";
1197 flush();
1200 echo "Writing global configuration defaults...\n";
1201 flush();
1202 if (! $installer->insert_globals()) {
1203 echo "$error.\n";
1204 echo $installer->error_message;
1206 break;
1207 } else {
1208 echo "$ok<br />\n";
1209 flush();
1212 echo "Setting up Access Controls...\n";
1213 require("$OE_SITE_DIR/sqlconf.php");
1214 if (! $installer->install_gacl()) {
1215 echo "$error -.\n";
1216 echo $installer->error_message;
1217 break;
1218 } else {
1219 echo "$ok<br />\n";
1220 flush();
1224 echo "Adding Initial User...\n";
1225 flush();
1226 if (! $installer->add_initial_user()) {
1227 echo "$error.\n";
1228 echo $installer->error_message;
1229 break;
1231 echo "$ok<br />\n";
1232 flush();
1234 echo "Adding Additional Users...\n";
1235 flush();
1236 if (! $installer->install_additional_users()) {
1237 echo "$error.\n";
1238 echo $installer->error_message;
1239 break;
1241 echo "$ok<br />\n";
1242 flush();
1245 // If user has selected to set MFA App Based 2FA, display QR code to scan
1246 $qr = $installer->get_initial_user_2fa_qr();
1247 if ($qr) {
1248 $qrDisplay = <<<TOTP
1249 <br />
1250 <table>
1251 <tr>
1252 <td>
1253 <strong class='text-danger'>IMPORTANT!!</strong>
1254 <p><strong>You must scan the following QR code with your preferred authenticator app.</strong></p>
1255 <img src='$qr' width="150" />
1256 </td>
1257 </tr>
1258 <tr>
1259 <td>
1260 Example authenticator apps include:
1261 <ul>
1262 <li>Google Auth
1263 (<a href="https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8">iOS</a>, <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en">Android</a>)</li>
1264 <li>Authy
1265 (<a href="https://itunes.apple.com/us/app/authy/id494168017?mt=8">iOS</a>, <a href="https://play.google.com/store/apps/details?id=com.authy.authy&hl=en">Android</a>)</li>
1266 </ul>
1267 </td>
1268 </tr>
1269 </table>
1270 TOTP;
1271 echo $qrDisplay;
1274 if ($allow_cloning_setup && !empty($installer->clone_database)) {
1275 // Database was cloned, skip ACL setup.
1276 $btn_text = 'Proceed to Select a Theme';
1277 echo "<br />";
1278 echo "<p>The database was cloned, access control list exists therefore skipping ACL setup</p>";
1279 echo "<p class='p-1 bg-warning'>Click <b>$btn_text</b> for further instructions.</p>";
1280 $next_state = 7;
1281 } else {
1282 $btn_text = 'Proceed to Step 4';
1283 echo "<br />";
1284 echo "<p><b>Granted user <span class='text-primary'>$installer->iuser</span> administrator access control (password is <span class='text-primary'>$installer->iuserpass</span>).</b></p>";
1285 echo "<p>The next step will configure php.</p>";
1286 echo "<p class='mark'>Click <strong>$btn_text</strong> to continue.</p>";
1287 $next_state = 4;
1290 $form_top = <<<FRMTOP
1291 <form method='post'>
1292 <input name='state' type='hidden' value='$next_state' />
1293 <input name='site' type='hidden' value='$site_id' />
1294 <input name='iuser' type='hidden' value='{$installer->iuser}' />
1295 <input name='iuserpass' type='hidden' value='{$installer->iuserpass}' />
1296 <input name='iuname' type='hidden' value='{$installer->iuname}' />
1297 <input name='iufname' type='hidden' value='{$installer->iufname}' />
1298 <input name='login' type='hidden' value='{$installer->login}' />
1299 <input name='pass' type='hidden' value='{$installer->pass}' />
1300 <input name='server' type='hidden' value='{$installer->server}' />
1301 <input name='port' type='hidden' value='{$installer->port}' />
1302 <input name='loginhost' type='hidden' value='{$installer->loginhost}' />
1303 <input name='dbname' type='hidden' value='{$installer->dbname}' />
1304 FRMTOP;
1305 echo $form_top . "\r\n";
1306 if ($allow_cloning_setup) {
1307 echo "<input type='hidden' name='clone_database' value='$installer->clone_database' />";
1308 echo "<input name='source_site_id' type='hidden' value='$installer->source_site_id' />";
1310 $form_bottom = <<<FRMBOT
1311 <div class="form-row">
1312 <div class="col-12">
1313 <button type='submit' id='step-4-btn' class="btn btn-primary" value='Continue'>
1314 <i class="fas fa-chevron-right"></i> $btn_text
1315 </button>
1316 </div>
1317 </div>
1318 </form>
1319 </div>
1320 FRMBOT;
1321 echo $form_bottom . "\r\n";
1322 break;
1324 case 4:
1325 $step4_top = <<<STP4TOP
1326 <h3 class="mb-3 border-bottom">Step $state - Configure PHP</h3>
1327 <div class="jumbotron p-5">
1328 <p>Configuration of PHP...</p>
1329 <p>We recommend making the following changes to your PHP installation, which can normally be done by editing the php.ini configuration file:</p>
1330 <ul>
1331 STP4TOP;
1332 echo $step4_top . "\r\n";
1334 $gotFileFlag = 0;
1335 $phpINIfile = php_ini_loaded_file();
1336 if ($phpINIfile) {
1337 echo "<li><span class='text-success'>Your php.ini file can be found at " . $phpINIfile . "</span></li>\n";
1338 $gotFileFlag = 1;
1341 $short_tag = ini_get('short_open_tag') ? 'On' : 'Off';
1342 $short_tag_style = (strcmp($short_tag, 'Off') === 0) ? '' : 'text-danger';
1343 $display_errors = ini_get('display_errors') ? 'On' : 'Off';
1344 $display_errors_style = (strcmp($display_errors, "Off") === 0) ? '' : 'text-danger';
1345 $register_globals = ini_get('register_globals') ? 'On' : 'Off';
1346 $register_globals_style = (strcmp($register_globals, 'Off') === 0) ? '' : 'text-danger';
1347 $max_input_vars = ini_get('max_input_vars');
1348 $max_input_vars_style = $max_input_vars < 3000 ? 'text-danger' : '';
1349 $max_execution_time = (int)ini_get('max_execution_time');
1350 $max_execution_time_style = $max_execution_time >= 60 || $max_execution_time === 0 ? '' : 'text-danger';
1351 $max_input_time = ini_get('max_input_time');
1352 $max_input_time_style = (strcmp($max_input_time, '-1') === 0) ? '' : 'text-danger';
1353 $post_max_size = ini_get('post_max_size');
1354 $post_max_size_style = $post_max_size < 30 ? 'text-danger' : '';
1355 $memory_limit = ini_get('memory_limit');
1356 $memory_limit_style = $memory_limit < 256 ? 'text-danger' : '';
1357 $mysqli_allow_local_infile = ini_get('mysqli.allow_local_infile') ? 'On' : 'Off';
1358 $mysqli_allow_local_infile_style = (strcmp($mysqli_allow_local_infile, 'On') === 0) ? '' : 'text-danger';
1360 $step4_table = <<<STP4TAB
1361 <li>To ensure proper functioning of OpenEMR you must make sure that PHP settings include:
1362 <table class='phpset'>
1363 <tr>
1364 <th>Setting</th>
1365 <th>Required value</th>
1366 <th>Current value</th>
1367 </tr>
1368 <tr>
1369 <td>short_open_tag</td>
1370 <td>Off</td>
1371 <td class='$short_tag_style'>$short_tag</td>
1372 </tr>
1373 <tr>
1374 <td>display_errors</td>
1375 <td>Off</td>
1376 <td class='$display_errors_style'>$display_errors</td>
1377 </tr>
1378 <tr>
1379 <td>register_globals</td>
1380 <td>Off</td>
1381 <td class='$register_globals_style'>$register_globals</td>
1382 </tr>
1383 <tr>
1384 <td>max_input_vars</td>
1385 <td>at least 3000</td>
1386 <td class='$max_input_vars_style'>$max_input_vars</td>
1387 </tr>
1388 <tr>
1389 <td>max_execution_time</td>
1390 <td>at least 60</td>
1391 <td class='$max_execution_time_style'>$max_execution_time</td>
1392 </tr>
1393 <tr>
1394 <td>max_input_time</td>
1395 <td>-1</td>
1396 <td class='$max_input_time_style'>$max_input_time</td>
1397 </tr>
1398 <tr>
1399 <td>post_max_size</td>
1400 <td>at least 30M</td>
1401 <td class='$post_max_size_style'>$post_max_size</td>
1402 </tr>
1403 <tr>
1404 <td>memory_limit</td>
1405 <td>at least 256M</td>
1406 <td class='$memory_limit_style'>$memory_limit</td>
1407 </tr>
1408 <tr>
1409 <td>mysqli.allow_local_infile</td>
1410 <td>On</td>
1411 <td class='$mysqli_allow_local_infile_style'>$mysqli_allow_local_infile</td>
1412 </tr>
1413 </table>
1414 </li>
1415 <li>In order to take full advantage of the patient documents capability you must make sure that settings in php.ini file include "file_uploads = On", that "upload_max_filesize" is appropriate for your use and that "upload_tmp_dir" is set to a correct value that will work on your system.
1416 </li>
1417 STP4TAB;
1418 echo $step4_table . "\r\n";
1420 if (!$gotFileFlag) {
1421 echo "<li>If you are having difficulty finding your php.ini file, then refer to the <a href='Documentation/INSTALL' rel='noopener' target='_blank'><u>'INSTALL'</u></a> manual for suggestions.</li>\n";
1424 $btn_text = 'Proceed to Step 5';
1425 $step4_bottom = <<<STP4BOT
1426 </ul>
1428 <p>We recommend you print these instructions for future reference.</p>
1429 <p>The next step will configure the Apache web server.</p>
1430 <p class='mark'>Click <strong>$btn_text</strong> to continue.</p>
1431 <br />
1432 <form method='post'>
1433 <input type='hidden' name='state' value='5' />
1434 <input type='hidden' name='site' value='$site_id' />
1435 <input type='hidden' name='iuser' value='{$installer->iuser}' />
1436 <input type='hidden' name='iuserpass' value='{$installer->iuserpass}' />
1437 <input name='login' type='hidden' value='{$installer->login}' />
1438 <input name='pass' type='hidden' value='{$installer->pass}' />
1439 <input name='server' type='hidden' value='{$installer->server}' />
1440 <input name='port' type='hidden' value='{$installer->port}' />
1441 <input name='loginhost' type='hidden' value='{$installer->loginhost}' />
1442 <input name='dbname' type='hidden' value='{$installer->dbname}' />
1443 <div class="form-row">
1444 <div class="col-12">
1445 <button type='submit' class='btn btn-primary' value='Continue'>
1446 <i class="fas fa-chevron-right"></i> $btn_text
1447 </button>
1448 </div>
1449 </div>
1450 </form>
1451 </div>
1452 STP4BOT;
1453 echo $step4_bottom . "\r\n";
1454 break;
1456 case 5:
1457 echo "<h3 class='mb-3 border-bottom'>Step $state - Configure Apache Web Server</h3>";
1458 echo "<div class='jumbotron p-5'>";
1459 echo "<p>Configuration of Apache web server...</p><br />\n";
1460 echo "The <code>\"" . preg_replace("/${site_id}/", "*", realpath($docsDirectory)) . "\"</code> directory contain patient information, and
1461 it is important to secure these directories. Additionally, some settings are required for the Zend Framework to work in OpenEMR. This can be done by pasting the below to end of your apache configuration file:<br /><br />
1462 &nbsp;&nbsp;<code>&lt;Directory \"" . realpath(dirname(__FILE__)) . "\"&gt;<br />
1463 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AllowOverride FileInfo<br />
1464 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Require all granted<br />
1465 &nbsp;&nbsp;<code>&lt;/Directory&gt;</code><br />
1466 &nbsp;&nbsp;&lt;Directory \"" . realpath(dirname(__FILE__)) . "/sites\"&gt;<br />
1467 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AllowOverride None<br />
1468 &nbsp;&nbsp;&lt;/Directory&gt;</code><br />
1469 &nbsp;&nbsp;<code>&lt;Directory \"" . preg_replace("/${site_id}/", "*", realpath($docsDirectory)) . "\"&gt;<br />
1470 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Require all denied<br />
1471 &nbsp;&nbsp;&lt;/Directory&gt;</code><br /><br />";
1473 $btn_text = 'Proceed to Select a Theme';
1474 $step5_bottom = <<<STP5BOT
1475 <p>If you are having difficulty finding your apache configuration file, then refer to the <a href='Documentation/INSTALL' rel='noopener' target='_blank'><u>'INSTALL'</u></a> manual for suggestions.</p>
1476 <p>We recommend you print these instructions for future reference.</p>
1477 <p class='mark'>Click <strong>'$btn_text'</strong> to select a theme.</p>
1478 <br />
1479 <form method='post'>
1480 <input type='hidden' name='state' value='6' />
1481 <input type='hidden' name='site' value='$site_id' />
1482 <input type='hidden' name='iuser' value='{$installer->iuser}' />
1483 <input type='hidden' name='iuserpass' value='{$installer->iuserpass}' />
1484 <input name='login' type='hidden' value='{$installer->login}' />
1485 <input name='pass' type='hidden' value='{$installer->pass}' />
1486 <input name='server' type='hidden' value='{$installer->server}' />
1487 <input name='port' type='hidden' value='{$installer->port}' />
1488 <input name='loginhost' type='hidden' value='{$installer->loginhost}' />
1489 <input name='dbname' type='hidden' value='{$installer->dbname}' />
1490 <div class="form-row">
1491 <div class="col-12">
1492 <button type='submit' class='btn btn-primary' value='Continue'>
1493 <i class="fas fa-chevron-right"></i> $btn_text
1494 </button>
1495 </div>
1496 </div>
1497 </form>
1498 <div>
1499 STP5BOT;
1500 echo $step5_bottom . "\r\n";
1501 break;
1503 case 6:
1504 echo "<h3 class='mb-3 border-bottom'>Step $state - Select a Theme</h3>";
1505 echo "<div class='jumbotron p-5'>";
1506 echo "<p>Select a theme for OpenEMR...</p>\n";
1507 $btn_text = "Proceed to Final Step";
1508 $installer->displaySelectedThemeDiv();
1509 $theme_form = <<<TMF
1510 <div class='row'>
1511 <div class="col-12">
1512 <form method='post'>
1513 <input type='hidden' name='state' value='7' />
1514 <input type='hidden' name='site' value='$site_id' />
1515 <input type='hidden' name='iuser' value='{$installer->iuser}' />
1516 <input type='hidden' name='iuserpass' value='{$installer->iuserpass}' />
1517 <input name='login' type='hidden' value='{$installer->login}' />
1518 <input name='pass' type='hidden' value='{$installer->pass}' />
1519 <input name='server' type='hidden' value='{$installer->server}' />
1520 <input name='port' type='hidden' value='{$installer->port}' />
1521 <input name='loginhost' type='hidden' value='{$installer->loginhost}' />
1522 <input name='dbname' type='hidden' value='{$installer->dbname}' />
1523 <input type='hidden' name='new_theme' id = 'new_theme' value='{$installer->getCurrentTheme()}' />
1524 <input name='clone_database' type='hidden' value='{$installer->clone_database}' />
1525 <input name='source_site_id' type='hidden' value='{$installer->source_site_id}' />
1526 <h4>Select One:</h4>
1527 <div class="checkbox">
1528 <label><input type="checkbox" class="check" value="show_theme" />Show More Themes</label>
1529 </div>
1530 <div class="checkbox">
1531 <label><input type="checkbox" class="check" value="keep_current" />Keep Current</label>
1532 </div>
1533 <div class='hide_button' style="display:none;">
1534 <button type='submit' class='btn btn-primary' value='Continue' id='continue'>
1535 <i class="fas fa-chevron-right"></i> {$btn_text}
1536 </button>
1537 </div>
1538 </form>
1539 </div>
1540 </div>
1541 TMF;
1542 echo $theme_form . "\r\n";
1543 echo '<div class="row hideaway" style="display:none;">' . "\r\n";
1544 echo '<div class="col-12">' . "\r\n";
1545 echo ' <h4>Select New Theme: <h5>(scroll down to view all)</h5></h4>' . "\r\n";
1546 echo ' <br />' . "\r\n";
1547 $installer->displayThemesDivs();
1548 echo "</div>";
1549 break;
1551 case 0:
1552 default:
1553 $top = <<<TOP
1554 <h3 class="mb-3 border-bottom">Pre Install - Checking File and Directory Permissions</h3>
1555 <div class="jumbotron p-5">
1557 Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.
1558 </p>
1559 <ul>
1560 <li>
1561 Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.
1562 </li>
1563 <li>
1564 <span class="text-highlight">Detailed installation instructions can be found in the <a href='Documentation/INSTALL' rel='noopener' target='_blank'><u>'INSTALL'</u></a> manual file.</span>
1565 </li>
1566 <li>
1567 If you are upgrading from a previous version, <strong>DO NOT</strong> use this script. Please read the <strong>'Upgrading'</strong> section found in the <a href='Documentation/INSTALL' rel='noopener' target='_blank'><u>'INSTALL'</u></a> manual file.
1568 </li>
1569 </ul>
1570 TOP;
1571 echo $top;
1572 if ($checkPermissions) {
1573 echo "<p>We will now ensure correct file and directory permissions before starting installation:</p>\n";
1574 echo "<p class='text-success m-0'>Ensuring following file is world-writable...</p>\n";
1575 $errorWritable = 0;
1576 foreach ($writableFileList as $tempFile) {
1577 if (is_writable($tempFile)) {
1578 echo "<code class='ml-5'>" . realpath($tempFile) . "</code> file is <span class='text-success font-weight-bold'>ready</span><br /><br />\n";
1579 } else {
1580 echo "<p><span class='text-danger'>UNABLE</span> to open file '" . realpath($tempFile) . "' for writing.<br />\n";
1581 echo "(configure file permissions; see below for further instructions)</p>\n";
1582 $errorWritable = 1;
1586 if ($errorWritable) {
1587 $check_file = <<<CHKFILE
1588 <p class="text-danger">You can't proceed until all above files are ready (world-writable).</p>
1589 <p>In linux, recommend changing file permissions with the <strong>'chmod 666 filename'</strong> command.</p>
1590 <p class='p-1 bg-danger text-white'>Fix above file permissions and then click the <strong>'Check Again'</strong> button to re-check files.</p>
1591 <br />
1592 <form method='post'>
1593 <input type='hidden' name='site' value='$site_id' />
1594 <button type='submit' class='btn btn-primary' value='check again'>Check Again</button>
1595 </form>
1596 CHKFILE;
1597 echo $check_file . "\r\n";
1598 break;
1601 $errorWritable = 0;
1602 foreach ($writableDirList as $tempDir) {
1603 echo "<p class='text-success m-0'>Ensuring the <code>" . realpath($tempDir) . "</code> directory and its subdirectories have proper permissions...</p>\n";
1604 $errorWritable = recursive_writable_directory_test($tempDir);
1607 if ($errorWritable) {
1608 $check_directory = <<<CHKDIR
1609 <p class="text-danger">You can't proceed until all directories and subdirectories are ready.</p>
1610 <p>In linux, recommend changing owners of these directories to the web server. For example, in many linux OS's the web server user is 'apache', 'nobody', or 'www-data'. So if 'apache' were the web server user name, could use the command <strong>'chown -R apache:apache directory_name'</strong> command.</p>
1611 <p class='p-1 bg-warning'>Fix above directory permissions and then click the <strong>'Check Again'</strong> button to re-check directories.</p>
1612 <br />
1613 <form method='post'>
1614 <input type='hidden' name='site' value='$site_id' />
1615 <button type='submit' value='check again'><b>Check Again</b></button>
1616 </form>
1617 CHKDIR;
1618 echo $check_directory . "\r\n";
1619 break;
1622 //RP_CHECK_LOGIC
1623 $form = <<<FRM
1624 <p>All required files and directories have been verified.</p>
1625 <p class='mark'>Click <span class="font-weight-bold">Proceed to Step 1</span> to continue with a new installation.</p>
1626 <p class='p-1 bg-warning'>$caution: If you are upgrading from a previous version, <strong>DO NOT</strong> use this script. Please read the <strong>'Upgrading'</strong> section found in the <a href='Documentation/INSTALL' rel='noopener' target='_blank'><u>'INSTALL'</u></a> manual file.</p>
1627 <br />
1628 <form method='post'>
1629 <input name='state' type='hidden' value='1' />
1630 <input name='site' type='hidden' value='$site_id' />
1631 <div class="form-group">
1632 <div class="col">
1633 <button type='submit' class='btn btn-primary' value='Continue'>
1634 <i class="fas fa-chevron-right"></i> Proceed to Step 1
1635 </button>
1636 </div>
1637 </div>
1638 </form>
1639 FRM;
1640 echo $form . "\r\n";
1641 } else {
1642 $form = <<<FRM
1643 <br />
1644 <p class='p-1 bg-warning'>$caution: Permisssions checking has been disabled. All required files and directories have NOT been verified, please manually verify sites/$site_id .</p>
1645 <p class='mark'>Click <b>Proceed to Step 1</b> to continue with a new installation.</p>
1646 <p class='p-1 bg-warning'>$caution: If you are upgrading from a previous version, <strong>DO NOT</strong> use this script. Please read the <strong>'Upgrading'</strong> section found in the <a href='Documentation/INSTALL' rel='noopener' target='_blank'><span style='text-decoration: underline;'>'INSTALL'</span></a> manual file.</p>
1647 <br />
1648 <form method='post'>
1649 <input name='state' type='hidden' value='1'>
1650 <input name='site' type='hidden' value='$site_id'>
1651 <button type='submit' value='Continue'><b>Proceed to Step 1</b></button>
1652 </form>
1653 FRM;
1654 echo $form . "\r\n"; }
1657 $bot = <<<BOT
1658 </div>
1659 </div>
1660 </div>
1661 BOT;
1662 echo $bot . "\r\n";
1666 </div><!--end of container div -->
1667 <?php $installer->setupHelpModal();?>
1668 <script>
1669 //jquery-ui tooltip
1670 $(function () {
1671 $('.icon-tooltip').prop( "title", "Click to see more information").tooltip({
1672 show: {
1673 delay: 700,
1674 duration: 0
1677 $('.enter-details-tooltip').prop( "title", "Additional help to fill out this form is available by hovering over labels of each box and clicking on the dark blue help ? icon that is revealed. On mobile devices tap once on the label to reveal the help icon and tap on the icon to show the help section").tooltip();
1678 $('.2fa-section-tooltip').prop( "title", "Two factor authentication prevents unauthorized access to openEMR thus improves security. It is optional. More information is available in the help file under Step 2 Database and OpenEMR Initial User Setup Details.").tooltip();
1682 </script>
1683 <script>
1684 $(function () {
1685 $("input[type='radio']").click(function() {
1686 var radioValue = $("input[name='stylesheet']:checked").val();
1687 var imgPath = "public/images/stylesheets/";
1688 var currStyle = $("#current_theme_title").text();
1689 var currStyleTitle = currStyle;
1690 currStyle = currStyle.replace(/\b\w/g, l => l.toLowerCase());
1691 currStyle = currStyle.split(" ");
1692 currStyle = currStyle.join("_");
1693 currStyle = "style_" + currStyle + ".png";
1694 if (radioValue) {
1695 var currThemeText = radioValue.split("_");
1696 currThemeText = currThemeText.join(" ");
1697 currThemeText = currThemeText.replace(/\b\w/g, l => l.toUpperCase());
1698 var styleSelected = confirm("You have selected style - " + currThemeText + "\n" + "Click OK to apply selection");
1699 if (styleSelected) {
1700 $("#current_theme").attr("src", imgPath + "style_" + radioValue + ".png");
1701 $("#current_theme_title").text(currThemeText);
1702 $("#new_theme").val("style_" + radioValue + ".css");
1703 } else {
1704 $("#current_theme").attr("src", imgPath + currStyle);
1705 $("#current_theme_title").text(currStyleTitle);
1706 $(this).prop("checked", false);
1710 $('.check').click(function() {
1711 $('.check').not(this).prop('checked', false);
1712 if($('.check:checked').val() == 'show_theme'){
1713 $(".hideaway").show();
1714 } else if($('.check:checked').val() == 'keep_current'){
1715 $(".hideaway").hide();
1718 if($('.check').filter(':checked').length > 0) {
1719 $(".hide_button").show();
1720 } else {
1721 $(".hide_button").hide();
1722 $(".hideaway").hide();
1725 $('.wait').removeClass('button-wait');
1727 $( "#create_db_button" ).hover(
1728 function() {
1729 if (($('#iuserpass' ).val().length > 11 && $('#iuser' ).val().length > 11 ) || ($('#clone_database').prop('checked'))){
1731 $("button").click(function(){
1732 $(".oe-spinner").css("visibility", "visible");
1735 $('.wait').click(function(){
1736 $('.wait').addClass('button-wait');
1742 $("#step-4-btn").click(function(){
1743 $(".oe-spinner").css("visibility", "visible");
1744 $(this).addClass('button-wait');
1747 </script>
1748 </body>
1749 </html>