some fixes so this can be re-run in full without screwing up
[openemr.git] / setup.php
blob04a7764cd33a80685d12545c9ecaede22c89e20d
1 <?php
2 //required for normal operation because of recent changes in PHP:
3 extract($_GET);
4 extract($_POST);
5 //turn off PHP compatibility warnings
6 ini_set("session.bug_compat_warn","off");
8 $url = "";
9 $upgrade = 0;
10 $defhost = 'localhost';
11 $state = $_POST["state"];
13 //If having problems with file and directory permission
14 // checking, then can be manually disabled here.
15 $checkPermissions = "TRUE";
17 //Below section is only for variables that require a path.
18 // The $manualPath variable can be edited by 3rd party
19 // installation scripts to manually set path. (this will
20 // allow straightforward use of this script by 3rd party
21 // installers)
22 $manualPath = "";
23 $dumpfile = $manualPath."sql/database.sql";
24 $icd9 = $manualPath."sql/icd9.sql";
25 $conffile = $manualPath."library/sqlconf.php";
26 $conffile2 = $manualPath."interface/globals.php";
27 $gaclConfigFile1 = $manualPath."gacl/gacl.ini.php";
28 $gaclConfigFile2 = $manualPath."gacl/gacl.class.php";
29 $docsDirectory = $manualPath."documents";
30 $billingDirectory = $manualPath."edi";
31 $gaclWritableDirectory = $manualPath."gacl/admin/templates_c";
32 $requiredDirectory1 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
33 $requiredDirectory2 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/cache";
34 $gaclSetupScript1 = $manualPath."gacl/setup.php";
35 $gaclSetupScript2 = $manualPath."acl_setup.php";
37 //These are files and dir checked before install for
38 // correct permissions.
39 $writableFileList = array($conffile, $conffile2, $gaclConfigFile1, $gaclConfigFile2);
40 $writableDirList = array($docsDirectory, $billingDirectory, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
43 include_once($conffile);
45 <HTML>
46 <HEAD>
47 <TITLE>OpenEMR Setup Tool</TITLE>
48 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
49 </HEAD>
50 <BODY>
52 <span class="title">OpenEMR Setup</span>
53 <br><br>
54 <span class="text">
56 <?php
57 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
58 echo "It appears that you have register_globals enabled in your php.ini\n" .
59 "configuration file. This causes unacceptable security risks. You must\n" .
60 "turn it off before continuing with installation.\n";
61 exit();
65 <?php
66 if ($state == 5) {
69 <p>Congratulations! OpenEMR is now successfully installed.</p>
71 <ul>
72 <li>Please restore secure permissions on the four configuration files: /openemr/interface/globals.php,
73 /openemr/library/sqlconf.php, /openemr/gacl/gacl.ini.php, and /openemr/gacl/gacl.class.php files.
74 In linux, recommend changing file permissions with the 'chmod 644 filename' command.</li>
75 <li>To ensure proper functioning of OpenEMR you must make sure your PHP installation (normally
76 set in your php.ini file) has "display_errors = Off", "register_globals = Off", and
77 "magic_quotes_gpc = Off".</li>
78 <li>In order to take full advantage of the patient documents capability you must make sure
79 your PHP installation (normally set in your php.ini file) has
80 "file_uploads enabled", that "upload_max_filesize" is appropriate for your
81 use and that "upload_tmp_dir" is set to a correct value if the default of "/tmp"
82 won't work on your system.</li>
83 <li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
84 OpenEMR's admin->acl menu.</li>
85 <li>Reading openemr/includes/config.php and openemr/interface/globals.php is a good idea. These files
86 contain many options to choose from including themes.</li>
87 <li>There's much information and many extra tools bundled within the OpenEMR installation directory.
88 Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
89 <li>To ensure a consistent look and feel through out the application using
90 <a href='http://www.mozilla.org/products/firefox/'>Firefox</a> is recommended.</li>
91 </ul>
92 <p>The "openemrwebroot/documents" and "openemrwebroot/edi" contain patient information, and
93 it is important to secure these directories. This can be done by placing pertinent .htaccess
94 files in these directories or by pasting the below in your apache configuration file:<br>
95 &lt;Directory "<?php echo realpath($docsDirectory);?>"&gt;<br>
96 order deny,allow<br>
97 Deny from all<br>
98 &lt;/Directory&gt;<br>
99 &lt;Directory "<?php echo realpath($billingDirectory);?>"&gt;<br>
100 order deny,allow<br>
101 Deny from all<br>
102 &lt;/Directory&gt;<br>
103 </p>
105 <b>The initial OpenEMR user is "<?php echo $iuser; ?>" and the password is "pass".</b>
106 You should change this password!
107 </p>
109 <a href='./'>Click here to start using OpenEMR. </a>
110 </p>
113 exit();
117 <?php
119 $server = $_POST["server"];
120 $port = $_POST["port"];
121 $dbname = $_POST["dbname"];
122 $root = $_POST["root"];
123 $login = $_POST["login"];
124 $pass = $_POST["pass"];
125 $loginhost = $_POST["loginhost"];
126 $rootpass = $_POST["rootpass"];
127 $iuser = $_POST["iuser"];
128 $iuname = $_POST["iuname"];
129 $igroup = $_POST["igroup"];
130 $openemrBasePath = $_POST["openemrBasePath"];
131 $openemrWebPath = $_POST["openemrWebPath"];
132 //END POST VARIABLES
135 if (($config == 1) && ($state != 4)) {
136 echo "OpenEMR is already configured. If you wish to re-configure the SQL server, edit $conffile, or change the 'config' variable to 0, and re-run this script.<br>\n";
138 else {
139 switch ($state) {
141 case 1:
142 echo "<b>Step $state</b><br><br>\n";
143 echo "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.\n
144 <span class='title'> <br />NOTE: clicking on \"Continue\" may delete or cause damage to data on your system. Before you continue please backup your data.</span>
145 <br><br>\n
146 <FORM METHOD='POST'>\n
147 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
148 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the database<br>\n
149 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the database<br>\n
150 <br>\n
151 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
152 break;
154 case 2:
155 echo "<b>Step $state</b><br><br>\n";
156 echo "Now you need to supply the MySQL server information and path information.
157 <br><br>
158 <FORM METHOD='POST'>
159 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
160 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
161 <TABLE>\n
162 <TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>MYSQL SERVER:</font></TD></TR>
163 <TR VALIGN='TOP'><TD><span class='text'>Server Host: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='server' SIZE='30'></TD><TD><span class='text'>(This is the IP address of the machine running MySQL. If this is on the same machine as the webserver, leave this as 'localhost'.)</span><br></TD></TR>
164 <TR VALIGN='TOP'><TD><span class='text'>Server Port: </span></TD><TD><INPUT TYPE='TEXT' VALUE='3306' NAME='port' SIZE='30'></TD><TD><span class='text'>(The default port for MySQL is 3306.)</span><br></TD></TR>
165 <TR VALIGN='TOP'><TD><span class='text'>Database Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='dbname' SIZE='30'></TD><TD><span class='text'>(This is the name of the OpenEMR database in MySQL - 'openemr' is the recommended)</span><br></TD></TR>
166 <TR VALIGN='TOP'><TD><span class='text'>Login Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='login' SIZE='30'></TD><TD><span class='text'>(This is the name of the OpenEMR login name in MySQL - 'openemr' is the recommended)</span><br></TD></TR>
167 <TR VALIGN='TOP'><TD><span class='text'>Password: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='pass' SIZE='30'></TD><TD><span class='text'>(This is the Login Password for when PHP accesses MySQL - it should be at least 8 characters long and composed of both numbers and letters)</span><br></TD></TR>\n";
168 if ($inst != 2) {
169 echo "<TR VALIGN='TOP'><TD><span class='text'>Name for Root Account: </span></TD><TD><INPUT TYPE='TEXT' VALUE='root' NAME='root' SIZE='30'></TD><TD><span class='text'>(This is name for MySQL root account. For localhost, it is usually ok to leave it 'root'.)</span><br></TD></TR>
170 <TR VALIGN='TOP'><TD><span class='text'>Root Pass: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='rootpass' SIZE='30'></TD><TD><span class='text'>(This is your MySQL root password. For localhost, it is usually ok to leave it blank.)</span><br></TD></TR>\n";
171 echo "<TR VALIGN='TOP'><TD><span class='text'>User Hostname: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='loginhost' SIZE='30'></TD><TD><span class='text'>(If you run Apache/PHP and MySQL on the same computer, then leave this as 'localhost'. If they are on separate computers, then enter the IP address of the computer running Apache/PHP.)</span><br></TD></TR>";
173 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
174 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR USER:</font></TD></TR>";
175 echo "<TR VALIGN='TOP'><TD><span class='text'>Initial User:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuser' VALUE='admin'></TD><TD><span class='text'>(This is the login name of user that will be created for you. Limit this to one word.)</span></TD></TR>
176 <TR VALIGN='TOP'><TD><span class='text'>Initial User's Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuname' VALUE='Administrator'></TD><TD><span class='text'>(This is the real name of the 'initial user'.)</span></TD></TR>
177 <TR VALIGN='TOP'><TD><span class='text'>Initial Group:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='igroup' VALUE='Default'></TD><TD><span class='text'>(This is the group that will be created for your users. This should be the name of your practice.)</span></TD></TR>
179 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
180 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR PATHS:</font></TD></TR>";
181 echo "<TR VALIGN='TOP'><TD COLSPAN=3></TD></TR>
182 <TR VALIGN='TOP'><TD><span class='text'>Absolute Path:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='openemrBasePath' VALUE='".realpath('./')."'></TD><TD><span class='text'>(This is the full absolute directory path to openemr. The value here is automatically created, and should not need to be modified. Do not worry about direction of slashes; they will be automatically corrected.)</span></TD></TR>
183 <TR VALIGN='TOP'><TD><span class='text'>Relative HTML Path:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='openemrWebPath' VALUE='/openemr'></TD><TD><span class='text'>(Set this to the relative html path, ie. what you would type into the web browser after the server address to get to OpenEMR. For example, if you type 'http://127.0.0.1/clinic/openemr/ to load OpenEMR, set this to '/clinic/openemr' without the trailing slash. Do not worry about direction of slashes; they will be automatically corrected.)</span></TD></TR>
185 echo "</TABLE>
186 <br>
187 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
189 break;
192 case 3:
194 if ($login == "" || !isset($login)) {
195 echo "ERROR. Please pick a proper 'Login Name'.<br>\n";
196 echo "Click Back in browser to re-enter.<br>\n";
197 break;
199 if (strpbrk($iuser,' ')) {
200 echo "ERROR. The 'Initial User' field can only contain one word and no spaces.<br>\n";
201 echo "Click Back in browser to re-enter.<br>\n";
202 break;
204 if ($pass == "" || !isset($pass)) {
205 echo "ERROR. Please pick a proper 'Password'.<br>\n";
206 echo "Click Back in browser to re-enter.<br>\n";
207 break;
210 echo "<b>Step $state</b><br><br>\n";
211 echo "Configuring OpenEMR...<br><br>\n";
214 if ($inst != 2) {
215 echo "Connecting to MySQL Server...\n";
216 flush();
217 if ($server == "localhost")
218 $dbh = mysql_connect("$server","$root","$rootpass");
219 else
220 $dbh = mysql_connect("$server:$port","$root","$rootpass");
221 if ($dbh == FALSE) {
222 echo "ERROR. Check your login credentials.\n";
223 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
224 break;
226 else
227 echo "OK.<br>\n";
228 echo "Creating database...\n";
229 flush();
230 if (mysql_query("create database $dbname",$dbh) == FALSE) {
231 echo "ERROR. Check your login credentials.\n";
232 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
233 break;
235 else
236 echo "OK.<br>\n";
237 echo "Creating user with permissions for database...\n";
238 flush();
239 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
240 echo "ERROR when granting privileges to the specified user.\n";
241 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
242 echo "ERROR.\n";
243 break;
245 else
246 echo "OK.<br>\n";
247 echo "Reconnecting as new user...\n";
248 mysql_close($dbh);
250 else
251 echo "Connecting to MySQL Server...\n";
253 if ($server == "localhost")
254 $dbh = mysql_connect("$server","$login","$pass");
255 else
256 $dbh = mysql_connect("$server:$port","$login","$pass");
258 if ($dbh == FALSE) {
259 echo "ERROR. Check your login credentials.\n";
260 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
261 break;
263 else
264 echo "OK.<br>\n";
265 echo "Opening database...";
266 flush();
267 if (mysql_select_db("$dbname",$dbh) == FALSE) {
268 echo "ERROR. Check your login credentials.\n";
269 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
270 break;
272 else
273 echo "OK.<br>\n";
274 flush();
275 if ($upgrade != 1) {
276 echo "Creating initial tables...\n";
277 mysql_query("USE $dbname",$dbh);
278 flush();
279 $fd = fopen($dumpfile, 'r');
280 if ($fd == FALSE) {
281 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
282 flush();
283 break;
285 $query = "";
286 $line = "";
287 while (!feof ($fd)){
288 $line = fgets($fd,1024);
289 $line = rtrim($line);
290 if (substr($line,0,2) == "--") // Kill comments
291 continue;
292 if (substr($line,0,1) == "#") // Kill comments
293 continue;
294 if ($line == "")
295 continue;
296 $query = $query.$line; // Check for full query
297 $chr = substr($query,strlen($query)-1,1);
298 if ($chr == ";") { // valid query, execute
299 $query = rtrim($query,";");
300 mysql_query("$query",$dbh);
301 $query = "";
304 echo "OK<br>\n";
305 fclose($fd);
306 flush();
307 echo "Adding Initial User...\n";
308 flush();
309 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
310 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
311 echo "ERROR. Could not run queries.\n";
312 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
313 flush();
314 break;
316 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
317 echo "ERROR. Could not run queries.\n";
318 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
319 flush();
320 break;
322 echo "OK<br>\n";
323 flush();
324 /* echo "Inserting ICD-9-CM Codes into Database...\n";
325 flush();
326 $fd = fopen($icd9, 'r');
327 if ($fd == FALSE) {
328 echo "ERROR. Could not open dumpfile.\n";
329 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
330 flush();
331 break;
333 $query = "";
334 $line = "";
335 while (!feof ($fd)){
336 $line = fgets($fd,1024);
337 $line = rtrim($line);
338 if (substr($line,0,2) == "--") // Kill comments
339 continue;
340 if (substr($line,0,1) == "#") // Kill comments
341 continue;
342 if ($line == "")
343 continue;
344 $query = $query.$line; // Check for full query
345 $chr = substr($query,strlen($query)-1,1);
346 if ($chr == ";") { // valid query, execute
347 $query = rtrim($query,";");
348 mysql_query("$query",$dbh);
349 $query = "";
352 echo "OK\n";
353 fclose($fd);*/
354 flush();
357 echo "<br>Writing SQL Configuration...<br>";
358 @touch($conffile); // php bug
359 $fd = @fopen($conffile, 'w');
360 $string = "<?
361 // OpenEMR
362 // MySQL Config
363 // Referenced from sql.inc
367 $it_died = 0; //fmg: variable keeps running track of any errors
369 fwrite($fd,$string) or $it_died++;
370 fwrite($fd,"\$host\t= '$server';\n") or $it_died++;
371 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
372 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
373 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
374 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++;
377 $string = '
379 $sqlconf = array();
380 $sqlconf["host"]= $host;
381 $sqlconf["port"] = $port;
382 $sqlconf["login"] = $login;
383 $sqlconf["pass"] = $pass;
384 $sqlconf["dbase"] = $dbase;
385 //////////////////////////
386 //////////////////////////
387 //////////////////////////
388 //////DO NOT TOUCH THIS///
389 $config = 1; /////////////
390 //////////////////////////
391 //////////////////////////
392 //////////////////////////
395 ?><? // done just for coloring
397 fwrite($fd,$string) or $it_died++;
399 //it's rather irresponsible to not report errors when writing this file.
400 if ($it_died != 0) {
401 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
402 flush();
403 break;
405 fclose($fd);
407 echo "Successfully wrote SQL configuration.<BR><br>";
409 echo "Writing OpenEMR webserver paths to config file...<br>";
410 //edit interface/globals.php
411 //first, ensure slashes are in correct direction (windows specific fix)
412 $openemrBasePath = str_replace('\\\\', '/', $openemrBasePath);
413 $openemrBasePath = str_replace('\\', '/', $openemrBasePath);
414 $openemrWebPath = str_replace('\\\\', '/', $openemrWebPath);
415 $openemrWebPath = str_replace('\\', '/', $openemrWebPath);
416 //second, edit file
417 $data = file($conffile2) or die("Could not read ".$conffile2." file.");
418 $finalData = "";
419 $isCount = 0;
420 foreach ($data as $line) {
421 $isHit = 0;
422 if ((strpos($line,"\$webserver_root = \"")) === false) {
424 else {
425 $isHit = 1;
426 $isCount += 1;
427 $finalData .= "\$webserver_root = \"$openemrBasePath\";\n";
429 if ((strpos($line,"\$web_root = \"")) === false) {
431 else {
432 $isHit = 1;
433 $isCount += 1;
434 $finalData .= "\$web_root = \"$openemrWebPath\";\n";
436 if (!$isHit) {
437 $finalData .= $line;
440 $fd = @fopen($conffile2, 'w') or die("Could not open ".$conffile2." file.");
441 fwrite($fd, $finalData);
442 fclose($fd);
443 if ($isCount == 2) {
444 echo "Successfully wrote OpenEMR webserver paths to config file<br><br>";
446 else {
447 echo "<FONT COLOR='red'>ERROR</FONT> writing openemr webserver root paths to config file ($conffile2). ($isCount)<br><br>\n";
450 echo "\n<br>Next step will install and configure access controls (php-GACL).<br>\n";
452 echo "
453 <FORM METHOD='POST'>\n
454 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
455 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
456 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
457 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
458 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
459 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
460 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
461 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
462 <br>\n
463 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
466 break;
468 case 4:
469 echo "<b>Step $state</b><br><br>\n";
470 echo "Installing and Configuring Access Controls (php-GACL)...<br><br>";
472 //first, edit two gacl config files
473 echo "Writing php-GACL configuration settings to config files...<br>";
474 // edit gacl.ini.php
475 $data = file($gaclConfigFile1) or die("Could not read ".$gaclConfigFile1." file.");
476 $finalData = "";
477 foreach ($data as $line) {
478 $isHit = 0;
479 if ((strpos($line,"db_host")) === false) {
481 else {
482 $isHit = 1;
483 $finalData .= "db_host = \"${host}\"\n";
485 if ((strpos($line,"db_user")) === false) {
487 else {
488 $isHit = 1;
489 $finalData .= "db_user = \"${login}\"\n";
491 if ((strpos($line,"db_password")) === false) {
493 else {
494 $isHit = 1;
495 $finalData .= "db_password = \"${pass}\"\n";
497 if ((strpos($line,"db_name")) === false) {
499 else {
500 $isHit = 1;
501 $finalData .= "db_name = \"${dbname}\"\n";
503 if (!$isHit) {
504 $finalData .= $line;
507 $fd = @fopen($gaclConfigFile1, 'w') or die("Could not open ".$gaclConfigFile1." file.");
508 fwrite($fd, $finalData);
509 fclose($fd);
511 // edit gacl.class.php
512 $data = file($gaclConfigFile2) or die("Could not read ".$gaclConfigFile2." file.");
513 $finalData = "";
514 foreach ($data as $line) {
515 $isHit = 0;
516 if ((strpos($line,"var \$_db_host = ")) === false) {
518 else {
519 $isHit = 1;
520 $finalData .= "var \$_db_host = '$host';\n";
522 if ((strpos($line,"var \$_db_user = ")) === false) {
524 else {
525 $isHit = 1;
526 $finalData .= "var \$_db_user = '$login';\n";
528 if ((strpos($line,"var \$_db_password = ")) === false) {
530 else {
531 $isHit = 1;
532 $finalData .= "var \$_db_password = '$pass';\n";
534 if ((strpos($line,"var \$_db_name = ")) === false) {
536 else {
537 $isHit = 1;
538 $finalData .= "var \$_db_name = '$dbname';\n";
540 if (!$isHit) {
541 $finalData .= $line;
544 $fd = @fopen($gaclConfigFile2, 'w') or die("Could not open ".$gaclConfigFile2." file.");
545 fwrite($fd, $finalData);
546 fclose($fd);
547 echo "Finished writing php-GACL configuration settings to config files.<br><br>";
549 //second, run gacl config scripts
550 require $gaclSetupScript1;
551 require $gaclSetupScript2;
552 echo "<br>";
554 //third, give the administrator user admin priviledges
555 $groupArray = array("Administrators");
556 set_user_aro($groupArray,$iuser,$iuname,"","");
557 echo "Gave the '$iuser' user (password is 'pass') administrator access.<br><br>";
559 echo "Done installing and configuring access controls (php-GACL). Click 'continue' to see further instructions.";
561 echo "<br><FORM METHOD='POST'>\n
562 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
563 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
564 <br>\n
565 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
567 break;
569 case 0:
570 default:
571 echo "<p>Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.</p>\n";
572 echo "<ul><li>Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.</li>\n";
574 echo "<li>Detailed installation instructions can be found in the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.</li>\n";
576 Echo "<li>If you are upgrading from a previous version, do NOT use this script. Please read the 'Upgrading' section found in the <a href='INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.</li></ul>";
578 if ($checkPermissions == "TRUE") {
579 echo "<p>We will now ensure correct file and directory permissions before starting installation:</p>\n";
580 echo "<FONT COLOR='green'>Ensuring following files are world-writable...</FONT><br>\n";
581 $errorWritable = 0;
582 foreach ($writableFileList as $tempFile) {
583 if (is_writable($tempFile)) {
584 echo "'".realpath($tempFile)."' file is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
586 else {
587 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open file '".realpath($tempFile)."' for writing.<br>\n";
588 echo "(configure file permissions; see below for further instructions)</p>\n";
589 $errorWritable = 1;
592 if ($errorWritable) {
593 echo "<p><FONT COLOR='red'>You can't proceed until all above files are ready (world-writable).</FONT><br>\n";
594 echo "In linux, recommend changing file permissions with the 'chmod 666 filename' command.<br>\n";
595 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>\n";
596 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
597 break;
600 echo "<br><FONT COLOR='green'>Ensuring following directories have proper permissions...</FONT><br>\n";
601 $errorWritable = 0;
602 foreach ($writableDirList as $tempDir) {
603 if (is_writable($tempDir)) {
604 echo "'".realpath($tempDir)."' directory is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
606 else {
607 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open directory '".realpath($tempDir)."' for writing by web server.<br>\n";
608 echo "(configure directory permissions; see below for further instructions)</p>\n";
609 $errorWritable = 1;
612 if ($errorWritable) {
613 echo "<p><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>\n";
614 echo "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 'chown -R apache:apache directory_name' command.<br>\n";
615 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>\n";
616 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
617 break;
620 echo "<br>All required files and directories have been verified. Click to continue installation.<br>\n";
622 else {
623 echo "<br>Click to continue installation.<br>\n";
626 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
633 </span>
635 </BODY>
636 </HTML>