fix empty directory bug
[openemr.git] / setup.php
blob3fb2ecd7758f03ce891940b4b95dc37f97d9c16f
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 //Below section is only for variables that require a path.
14 // The $manualPath variable can be edited by 3rd party
15 // installation scripts to manually set path. (this will
16 // allow straightforward use of this script by 3rd party
17 // installers)
18 $manualPath = "";
19 $dumpfile = $manualPath."sql/database.sql";
20 $icd9 = $manualPath."sql/icd9.sql";
21 $conffile = $manualPath."library/sqlconf.php";
22 $conffile2 = $manualPath."interface/globals.php";
23 $gaclConfigFile1 = $manualPath."gacl/gacl.ini.php";
24 $gaclConfigFile2 = $manualPath."gacl/gacl.class.php";
25 $docsDirectory = $manualPath."documents";
26 $billingDirectory = $manualPath."edi";
27 $gaclWritableDirectory = $manualPath."gacl/admin/templates_c";
28 $requiredDirectory1 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
29 $requiredDirectory2 = $manualPath."interface/main/calendar/modules/PostCalendar/pntemplates/cache";
30 $gaclSetupScript1 = $manualPath."gacl/setup.php";
31 $gaclSetupScript2 = $manualPath."acl_setup.php";
33 //These are files and dir checked before install for
34 // existence and correct permissions.
35 $writableFileList = array($conffile, $conffile2, $gaclConfigFile1, $gaclConfigFile2);
36 $writableDirList = array($docsDirectory, $billingDirectory, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
39 include_once($conffile);
41 <HTML>
42 <HEAD>
43 <TITLE>OpenEMR Setup Tool</TITLE>
44 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
45 </HEAD>
46 <BODY>
48 <span class="title">OpenEMR Setup</span>
49 <br><br>
50 <span class="text">
52 <?php
53 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
54 echo "It appears that you have register_globals enabled in your php.ini\n" .
55 "configuration file. This causes unacceptable security risks. You must\n" .
56 "turn it off before continuing with installation.\n";
57 exit();
61 <?php
62 if ($state == 5) {
65 <p>Congratulations! OpenEMR is now successfully installed.</p>
67 <ul>
68 <li>Please restore secure permissions on the four configuration files: /openemr/interface/globals.php,
69 /openemr/library/sqlconf.php, /openemr/gacl/gacl.ini.php, and /openemr/gacl/gacl.class.php files.
70 In linux, recommend changing file permissions with the 'chmod 644 filename' command.</li>
71 <li>To ensure proper functioning of OpenEMR you must make sure your PHP installation (normally
72 set in your php.ini file) has "display_errors = Off", "register_globals = Off", and
73 "magic_quotes_gpc = Off".</li>
74 <li>In order to take full advantage of the patient documents capability you must make sure
75 your PHP installation (normally set in your php.ini file) has
76 "file_uploads enabled", that "upload_max_filesize" is appropriate for your
77 use and that "upload_tmp_dir" is set to a correct value if the default of "/tmp"
78 won't work on your system.</li>
79 <li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
80 OpenEMR's admin->acl menu.</li>
81 <li>Reading openemr/includes/config.php and openemr/interface/globals.php is a good idea. These files
82 contain many options to choose from including themes.</li>
83 <li>There's much information and many extra tools bundled within the OpenEMR installation directory.
84 Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
85 <li>To ensure a consistent look and feel through out the application using
86 <a href='http://www.mozilla.org/products/firefox/'>Firefox</a> is recommended.</li>
87 </ul>
88 <p>The "openemrwebroot/documents" and "openemrwebroot/edi" contain patient information, and
89 it is important to secure these directories. This can be done by placing pertinent .htaccess
90 files in these directories or by pasting the below in your apache configuration file:<br>
91 &lt;Directory "<?php echo realpath($docsDirectory);?>"&gt;<br>
92 order deny,allow<br>
93 Deny from all<br>
94 &lt;/Directory&gt;<br>
95 &lt;Directory "<?php echo realpath($billingDirectory);?>"&gt;<br>
96 order deny,allow<br>
97 Deny from all<br>
98 &lt;/Directory&gt;<br>
99 </p>
101 <b>The initial OpenEMR user is "<?php echo $iuser; ?>" and the password is "pass".</b>
102 You should change this password!
103 </p>
105 <a href='./'>Click here to start using OpenEMR. </a>
106 </p>
109 exit();
113 <?php
115 $server = $_POST["server"];
116 $port = $_POST["port"];
117 $dbname = $_POST["dbname"];
118 $root = $_POST["root"];
119 $login = $_POST["login"];
120 $pass = $_POST["pass"];
121 $loginhost = $_POST["loginhost"];
122 $rootpass = $_POST["rootpass"];
123 $iuser = $_POST["iuser"];
124 $iuname = $_POST["iuname"];
125 $igroup = $_POST["igroup"];
126 $openemrBasePath = $_POST["openemrBasePath"];
127 $openemrWebPath = $_POST["openemrWebPath"];
128 //END POST VARIABLES
131 if (($config == 1) && ($state != 4)) {
132 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";
134 else {
135 switch ($state) {
137 case 1:
138 echo "<b>Step $state</b><br><br>\n";
139 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
140 <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>
141 <br><br>\n
142 <FORM METHOD='POST'>\n
143 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
144 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the database<br>\n
145 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the database<br>\n
146 <br>\n
147 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
148 break;
150 case 2:
151 echo "<b>Step $state</b><br><br>\n";
152 echo "Now you need to supply the MySQL server information and path information.
153 <br><br>
154 <FORM METHOD='POST'>
155 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
156 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
157 <TABLE>\n
158 <TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>MYSQL SERVER:</font></TD></TR>
159 <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>
160 <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>
161 <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>
162 <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>
163 <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";
164 if ($inst != 2) {
165 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>
166 <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";
167 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>";
169 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
170 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR USER:</font></TD></TR>";
171 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>
172 <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>
173 <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>
175 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
176 echo "<TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>OPENEMR PATHS:</font></TD></TR>";
177 echo "<TR VALIGN='TOP'><TD COLSPAN=3></TD></TR>
178 <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>
179 <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>
181 echo "</TABLE>
182 <br>
183 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
185 break;
188 case 3:
190 if ($login == "" || !isset($login)) {
191 echo "ERROR. Please pick a proper 'Login Name'.<br>\n";
192 echo "Click Back in browser to re-enter.<br>\n";
193 break;
195 if (strpbrk($iuser,' ')) {
196 echo "ERROR. The 'Initial User' field can only contain one word and no spaces.<br>\n";
197 echo "Click Back in browser to re-enter.<br>\n";
198 break;
200 if ($pass == "" || !isset($pass)) {
201 echo "ERROR. Please pick a proper 'Password'.<br>\n";
202 echo "Click Back in browser to re-enter.<br>\n";
203 break;
206 echo "<b>Step $state</b><br><br>\n";
207 echo "Configuring OpenEMR...<br><br>\n";
210 if ($inst != 2) {
211 echo "Connecting to MySQL Server...\n";
212 flush();
213 if ($server == "localhost")
214 $dbh = mysql_connect("$server","$root","$rootpass");
215 else
216 $dbh = mysql_connect("$server:$port","$root","$rootpass");
217 if ($dbh == FALSE) {
218 echo "ERROR. Check your login credentials.\n";
219 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
220 break;
222 else
223 echo "OK.<br>\n";
224 echo "Creating database...\n";
225 flush();
226 if (mysql_query("create database $dbname",$dbh) == FALSE) {
227 echo "ERROR. Check your login credentials.\n";
228 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
229 break;
231 else
232 echo "OK.<br>\n";
233 echo "Creating user with permissions for database...\n";
234 flush();
235 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
236 echo "ERROR when granting privileges to the specified user.\n";
237 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
238 echo "ERROR.\n";
239 break;
241 else
242 echo "OK.<br>\n";
243 echo "Reconnecting as new user...\n";
244 mysql_close($dbh);
246 else
247 echo "Connecting to MySQL Server...\n";
249 if ($server == "localhost")
250 $dbh = mysql_connect("$server","$login","$pass");
251 else
252 $dbh = mysql_connect("$server:$port","$login","$pass");
254 if ($dbh == FALSE) {
255 echo "ERROR. Check your login credentials.\n";
256 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
257 break;
259 else
260 echo "OK.<br>\n";
261 echo "Opening database...";
262 flush();
263 if (mysql_select_db("$dbname",$dbh) == FALSE) {
264 echo "ERROR. Check your login credentials.\n";
265 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
266 break;
268 else
269 echo "OK.<br>\n";
270 flush();
271 if ($upgrade != 1) {
272 echo "Creating initial tables...\n";
273 mysql_query("USE $dbname",$dbh);
274 flush();
275 $fd = fopen($dumpfile, 'r');
276 if ($fd == FALSE) {
277 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
278 flush();
279 break;
281 $query = "";
282 $line = "";
283 while (!feof ($fd)){
284 $line = fgets($fd,1024);
285 $line = rtrim($line);
286 if (substr($line,0,2) == "--") // Kill comments
287 continue;
288 if (substr($line,0,1) == "#") // Kill comments
289 continue;
290 if ($line == "")
291 continue;
292 $query = $query.$line; // Check for full query
293 $chr = substr($query,strlen($query)-1,1);
294 if ($chr == ";") { // valid query, execute
295 $query = rtrim($query,";");
296 mysql_query("$query",$dbh);
297 $query = "";
300 echo "OK<br>\n";
301 fclose($fd);
302 flush();
303 echo "Adding Initial User...\n";
304 flush();
305 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
306 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
307 echo "ERROR. Could not run queries.\n";
308 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
309 flush();
310 break;
312 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
313 echo "ERROR. Could not run queries.\n";
314 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
315 flush();
316 break;
318 echo "OK<br>\n";
319 flush();
320 /* echo "Inserting ICD-9-CM Codes into Database...\n";
321 flush();
322 $fd = fopen($icd9, 'r');
323 if ($fd == FALSE) {
324 echo "ERROR. Could not open dumpfile.\n";
325 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
326 flush();
327 break;
329 $query = "";
330 $line = "";
331 while (!feof ($fd)){
332 $line = fgets($fd,1024);
333 $line = rtrim($line);
334 if (substr($line,0,2) == "--") // Kill comments
335 continue;
336 if (substr($line,0,1) == "#") // Kill comments
337 continue;
338 if ($line == "")
339 continue;
340 $query = $query.$line; // Check for full query
341 $chr = substr($query,strlen($query)-1,1);
342 if ($chr == ";") { // valid query, execute
343 $query = rtrim($query,";");
344 mysql_query("$query",$dbh);
345 $query = "";
348 echo "OK\n";
349 fclose($fd);*/
350 flush();
353 echo "<br>Writing SQL Configuration...<br>";
354 @touch($conffile); // php bug
355 $fd = @fopen($conffile, 'w');
356 $string = "<?
357 // OpenEMR
358 // MySQL Config
359 // Referenced from sql.inc
363 $it_died = 0; //fmg: variable keeps running track of any errors
365 fwrite($fd,$string) or $it_died++;
366 fwrite($fd,"\$host\t= '$server';\n") or $it_died++;
367 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
368 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
369 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
370 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++;
373 $string = '
375 $sqlconf = array();
376 $sqlconf["host"]= $host;
377 $sqlconf["port"] = $port;
378 $sqlconf["login"] = $login;
379 $sqlconf["pass"] = $pass;
380 $sqlconf["dbase"] = $dbase;
381 //////////////////////////
382 //////////////////////////
383 //////////////////////////
384 //////DO NOT TOUCH THIS///
385 $config = 1; /////////////
386 //////////////////////////
387 //////////////////////////
388 //////////////////////////
391 ?><? // done just for coloring
393 fwrite($fd,$string) or $it_died++;
395 //it's rather irresponsible to not report errors when writing this file.
396 if ($it_died != 0) {
397 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
398 flush();
399 break;
401 fclose($fd);
403 echo "Successfully wrote SQL configuration.<BR><br>";
405 echo "Writing OpenEMR webserver paths to config file...<br>";
406 //edit interface/globals.php
407 //first, ensure slashes are in correct direction (windows specific fix)
408 $openemrBasePath = str_replace('\\\\', '/', $openemrBasePath);
409 $openemrBasePath = str_replace('\\', '/', $openemrBasePath);
410 $openemrWebPath = str_replace('\\\\', '/', $openemrWebPath);
411 $openemrWebPath = str_replace('\\', '/', $openemrWebPath);
412 //second, edit file
413 $data = file($conffile2) or die("Could not read ".$conffile2." file.");
414 $finalData = "";
415 $isCount = 0;
416 foreach ($data as $line) {
417 $isHit = 0;
418 if ((strpos($line,"\$webserver_root = \"")) === false) {
420 else {
421 $isHit = 1;
422 $isCount += 1;
423 $finalData .= "\$webserver_root = \"$openemrBasePath\";\n";
425 if ((strpos($line,"\$web_root = \"")) === false) {
427 else {
428 $isHit = 1;
429 $isCount += 1;
430 $finalData .= "\$web_root = \"$openemrWebPath\";\n";
432 if (!$isHit) {
433 $finalData .= $line;
436 $fd = @fopen($conffile2, 'w') or die("Could not open ".$conffile2." file.");
437 fwrite($fd, $finalData);
438 fclose($fd);
439 if ($isCount == 2) {
440 echo "Successfully wrote OpenEMR webserver paths to config file<br><br>";
442 else {
443 echo "<FONT COLOR='red'>ERROR</FONT> writing openemr webserver root paths to config file ($conffile2). ($isCount)<br><br>\n";
446 echo "\n<br>Next step will install and configure access controls (php-GACL).<br>\n";
448 echo "
449 <FORM METHOD='POST'>\n
450 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
451 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
452 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
453 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
454 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
455 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
456 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
457 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
458 <br>\n
459 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
462 break;
464 case 4:
465 echo "<b>Step $state</b><br><br>\n";
466 echo "Installing and Configuring Access Controls (php-GACL)...<br><br>";
468 //first, edit two gacl config files
469 echo "Writing php-GACL configuration settings to config files...<br>";
470 // edit gacl.ini.php
471 $data = file($gaclConfigFile1) or die("Could not read ".$gaclConfigFile1." file.");
472 $finalData = "";
473 foreach ($data as $line) {
474 $isHit = 0;
475 if ((strpos($line,"db_host")) === false) {
477 else {
478 $isHit = 1;
479 $finalData .= "db_host = \"${host}\"\n";
481 if ((strpos($line,"db_user")) === false) {
483 else {
484 $isHit = 1;
485 $finalData .= "db_user = \"${login}\"\n";
487 if ((strpos($line,"db_password")) === false) {
489 else {
490 $isHit = 1;
491 $finalData .= "db_password = \"${pass}\"\n";
493 if ((strpos($line,"db_name")) === false) {
495 else {
496 $isHit = 1;
497 $finalData .= "db_name = \"${dbname}\"\n";
499 if (!$isHit) {
500 $finalData .= $line;
503 $fd = @fopen($gaclConfigFile1, 'w') or die("Could not open ".$gaclConfigFile1." file.");
504 fwrite($fd, $finalData);
505 fclose($fd);
507 // edit gacl.class.php
508 $data = file($gaclConfigFile2) or die("Could not read ".$gaclConfigFile2." file.");
509 $finalData = "";
510 foreach ($data as $line) {
511 $isHit = 0;
512 if ((strpos($line,"var \$_db_host = ")) === false) {
514 else {
515 $isHit = 1;
516 $finalData .= "var \$_db_host = '$host';\n";
518 if ((strpos($line,"var \$_db_user = ")) === false) {
520 else {
521 $isHit = 1;
522 $finalData .= "var \$_db_user = '$login';\n";
524 if ((strpos($line,"var \$_db_password = ")) === false) {
526 else {
527 $isHit = 1;
528 $finalData .= "var \$_db_password = '$pass';\n";
530 if ((strpos($line,"var \$_db_name = ")) === false) {
532 else {
533 $isHit = 1;
534 $finalData .= "var \$_db_name = '$dbname';\n";
536 if (!$isHit) {
537 $finalData .= $line;
540 $fd = @fopen($gaclConfigFile2, 'w') or die("Could not open ".$gaclConfigFile2." file.");
541 fwrite($fd, $finalData);
542 fclose($fd);
543 echo "Finished writing php-GACL configuration settings to config files.<br><br>";
545 //second, run gacl config scripts
546 require $gaclSetupScript1;
547 require $gaclSetupScript2;
548 echo "<br>";
550 //third, give the administrator user admin priviledges
551 $groupArray = array("Administrators");
552 set_user_aro($groupArray,$iuser,$iuname,"","");
553 echo "Gave the '$iuser' user (password is 'pass') administrator access.<br><br>";
555 echo "Done installing and configuring access controls (php-GACL). Click 'continue' to see further instructions.";
557 echo "<br><FORM METHOD='POST'>\n
558 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
559 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
560 <br>\n
561 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
563 break;
565 case 0:
566 default:
567 echo "<p>Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.</p>\n";
568 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";
570 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";
572 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>";
574 echo "<p>We will now ensure correct file permissions and directories before starting installation:</p>\n";
575 echo "<FONT COLOR='green'>Ensuring following files are world-writable...</FONT><br>\n";
576 $errorWritable = 0;
577 foreach ($writableFileList as $tempFile) {
578 if (is_writable($tempFile)) {
579 echo "'".realpath($tempFile)."' file is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
581 else {
582 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open file '".realpath($tempFile)."' for writing.<br>\n";
583 echo "(configure file permissions; see below for further instructions)</p>\n";
584 $errorWritable = 1;
587 if ($errorWritable) {
588 echo "<p><FONT COLOR='red'>You can't proceed until all above files are ready (world-writable).</FONT><br>\n";
589 echo "In linux, recommend changing file permissions with the 'chmod 666 filename' command.<br>\n";
590 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>\n";
591 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
592 break;
595 echo "<br><FONT COLOR='green'>Ensuring following directories exist...</FONT><br>\n";
596 $errorWritable = 0;
597 foreach ($writableDirList as $tempDir) {
598 if (file_exists($tempDir)) {
599 echo "'".realpath($tempDir)."' directory <FONT COLOR='green'><b>exists</b></FONT>.<br>\n";
601 else {
602 $tempPath = realpath($tempDir);
603 if ($tempPath == "") {
604 //this is a fix specific to microsoft windows
605 $tempPath = realpath('./').DIRECTORY_SEPARATOR.$tempDir;
606 $tempPath = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $tempPath);
608 echo "<p><FONT COLOR='red'>UNABLE</FONT> to find directory '".$tempPath."'.<br>\n";
609 echo "(please create directory; see below for further instructions)</p>\n";
610 $errorWritable = 1;
613 if ($errorWritable) {
614 echo "<p><FONT COLOR='red'>You can't proceed until all above directories exist.</FONT><br>\n";
615 echo "In linux, recommend using the 'mkdir directory_name' command<br>\n";
616 echo "Add above marked directories and then click the 'Check Again' button to re-check for directories.<br>\n";
617 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
618 break;
621 echo "<br><FONT COLOR='green'>Ensuring following directories have proper permissions...</FONT><br>\n";
622 $errorWritable = 0;
623 foreach ($writableDirList as $tempDir) {
624 if (is_writable($tempDir)) {
625 echo "'".realpath($tempDir)."' directory is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
627 else {
628 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open directory '".realpath($tempDir)."' for writing by web server.<br>\n";
629 echo "(configure directory permissions; see below for further instructions)</p>\n";
630 $errorWritable = 1;
633 if ($errorWritable) {
634 echo "<p><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>\n";
635 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";
636 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>\n";
637 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p></FORM><br>\n";
638 break;
641 echo "<br>All required files and directories have been verified. Click to continue installation.<br>\n";
642 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
649 </span>
651 </BODY>
652 </HTML>