allow non-practitioner access to patient/med by default if no phpgacl
[openemr.git] / setup.php
blob1a1ca157d3e85c36f8be641b0bed0151f164f496
1 <?php
3 //required for normal operation because of recent changes in PHP:
4 extract($_GET);
5 extract($_POST);
6 //turn off PHP compatibility warnings
7 ini_set("session.bug_compat_warn","off");
9 $url = "";
10 $dumpfile = "sql/database.sql";
11 $icd9 = "sql/icd9.sql";
12 $conffile = "library/sqlconf.php";
13 $upgrade = 0;
14 $defhost = 'localhost';
15 $state = $_POST["state"];
17 include_once($conffile);
19 <HTML>
20 <HEAD>
21 <TITLE>OpenEMR Setup Tool</TITLE>
22 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
23 </HEAD>
24 <BODY>
26 <span class="title">OpenEMR Setup</span>
27 <br><br>
28 <span class="text">
30 <?php
31 if ($state == 5) {
34 <p>Congratulations! OpenEMR is now successfully installed.
36 <ul>
37 <li>Please Edit the 'interface/globals.php' file now to specify the correct
38 URL paths, and to select a theme.</li>
39 <li>Please make sure that the two folders underneath
40 'openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/'
41 exist and are writable by the web server. The two subdirectories are
42 'compiled' and 'cache'.<br>
43 Try "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/compiled"
44 and
45 "chown apache:apache -R openemrwebroot/interface/main/calendar/modules/PostCalendar/pntemplates/cache".
46 (If either subdirectory doesn't exist, create it first then do the chown above).<br>
47 The user name and group of apache may differ depending on your distro, i.e.
48 for Debian is www-data and www-data.</li>
49 </ul>
50 <p>
51 In order to take full advantage of the documents capability you
52 must give your web server permissions on the document storage
53 directory. Try "chown apache:apache -R openemrwebroot/documents"
54 and then "chmod g+w openemrwebroot/documents".
55 You must also make sure your PHP installation (normally set in
56 your php.ini file) has "file_uploads enabled", that
57 "upload_max_filesize" is appropriate for your use and that
58 "upload_tmp_dir" is set to a correct value if the default of
59 "/tmp" won't work on your system.
60 </p>
61 <p>
62 There's many information and extra tools bundled within OpenEMR Files.
63 <br>Please refer to openemr/Documentation
64 <br>Many forms and other useful scripts can be found at openemr/contrib
65 <br>OpenEMR now comes with optional GACL support, a fine grained access control system. Please refer to openemr/Documentation/README.phpgacl for -easy- installation.
66 </p>
67 <p>
68 Reading openemr/includes/config.php and openemr/interface/globals.php is a good idea.
69 </p>
70 <p>
71 To ensure a consistent look and feel through out the application
72 using <a href='http://www.mozilla.org/products/firefox/'> Firefox</a>
73 is recommended.
74 </p>
75 <p>
76 <a href='./'>Click here to start using OpenEMR. </a>
77 </p>
80 exit();
84 <?php
86 $server = $_POST["server"];
87 $port = $_POST["port"];
88 $dbname = $_POST["dbname"];
89 $login = $_POST["login"];
90 $pass = $_POST["pass"];
91 $loginhost = $_POST["loginhost"];
92 $rootpass = $_POST["rootpass"];
95 if ($config == 1) {
96 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";
98 else {
99 switch ($state) {
101 case 1:
102 echo "<b>Step $state</b><br><br>\n";
103 echo "Now I need to know whether you want me to create the databases on my own or if you have already created the database for me to use. If you are upgrading, you will want to select the latter function. For me to create the databases, you will need to supply the MySQL root password.\n
104 <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>
105 <br><br>\n
106 <FORM METHOD='POST'>\n
107 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
108 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the databases<br>\n
109 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the databases<br>\n
110 <br>\n
111 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
112 break;
114 case 2:
115 echo "<b>Step $state</b><br><br>\n";
116 echo "Now you need to supply the MySQL server information.
117 <br><br>
118 <FORM METHOD='POST'>
119 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
120 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
121 <TABLE>\n
122 <TR><TD><font color='red'>SERVER:</font></TD></TR>
123 <TR><TD><span class='text'>Server Host: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='server' SIZE='30'><span class='text'>(This is the IP address of the machine running MySQL)</span><br></TD></TR>
124 <TR><TD><span class='text'>Server Port: </span></TD><TD><INPUT TYPE='TEXT' VALUE='3306' NAME='port' SIZE='30'><span class='text'>(The default port for MySQL is 3306)</span><br></TD></TR>
125 <TR><TD><span class='text'>Database Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='dbname' SIZE='30'><span class='text'>(This is the name of the OpenEMR database - 'openemr' is the recommended)</span><br></TD></TR>
126 <TR><TD><span class='text'>Login Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='login' SIZE='30'><span class='text'>(This is the name of the OpenEMR login name - 'openemr' is the recommended)</span><br></TD></TR>
127 <TR><TD><span class='text'>Password: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='pass' SIZE='30'><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";
128 if ($inst != 2) {
129 echo "<TR><TD><font color='red'>CLIENT:</font></TD></TR>";
130 echo "<TR><TD><span class='text'>User Hostname: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='loginhost' SIZE='30'><span class='text'>(This is the IP address of the server machine running Apache and PHP - if you are setting up one computer, this is the same as the Server Host above)</span><br></TD></TR>
131 <TR><TD><span class='text'>Root Pass: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='rootpass' SIZE='30'><span class='text'>(This is your MySQL root password. For localhost, it is usually ok to leave it blank.)</span><br></TD></TR>\n";
133 echo "<TR><TD><font color='red'>USER:</font></TD></TR>";
134 echo "<TR><TD COLSPAN=2></TD></TR>
135 <TR><TD><span class='text'>Initial User:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuser' VALUE='admin'><span class='text'>(This is the user that will be created for you. It will be an authorized user, so it should be for a Doctor or other Practitioner)</span></TD></TR>
136 <TR><TD><span class='text'>Initial User's Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuname' VALUE='Administrator'><span class='text'>(This is the real name of the initial user.)</span></TD></TR>
137 <TR><TD><span class='text'>Initial Group:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='igroup' VALUE='Default'><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>
139 echo "</TABLE>
140 <br>
141 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
143 break;
146 case 3:
149 echo "<b>Step $state</b><br><br>\n";
150 if ($pass == "" || $login == "" || !isset($login) || !isset($pass)) {
151 echo "ERROR. Please pick a proper username and/or password.<br>\n";
152 break;
155 if ($inst != 2) {
156 echo "Connecting to MySQL Server...\n";
157 flush();
158 if ($server == "localhost")
159 $dbh = mysql_connect("$server","root","$rootpass");
160 else
161 $dbh = mysql_connect("$server:$port","root","$rootpass");
162 if ($dbh == FALSE) {
163 echo "ERROR. Check your login credentials.\n";
164 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
165 break;
167 else
168 echo "OK.<br>\n";
169 echo "Creating database...\n";
170 flush();
171 if (mysql_query("create database $dbname",$dbh) == FALSE) {
172 echo "ERROR. Check your login credentials.\n";
173 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
174 break;
176 else
177 echo "OK.<br>\n";
178 echo "Creating user with permissions for database...\n";
179 flush();
180 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
181 echo "ERROR when granting privileges to the specified user.\n";
182 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
183 echo "ERROR.\n";
184 break;
186 else
187 echo "OK.<br>\n";
188 echo "Reconnecting as new user...\n";
189 mysql_close($dbh);
191 else
192 echo "Connecting to MySQL Server...\n";
194 if ($server == "localhost")
195 $dbh = mysql_connect("$server","$login","$pass");
196 else
197 $dbh = mysql_connect("$server:$port","$login","$pass");
199 if ($dbh == FALSE) {
200 echo "ERROR. Check your login credentials.\n";
201 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
202 break;
204 else
205 echo "OK.<br>\n";
206 echo "Opening database...";
207 flush();
208 if (mysql_select_db("$dbname",$dbh) == FALSE) {
209 echo "ERROR. Check your login credentials.\n";
210 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
211 break;
213 else
214 echo "OK.<br>\n";
215 flush();
216 if ($upgrade != 1) {
217 echo "Creating initial tables...\n";
218 mysql_query("USE $dbname",$dbh);
219 flush();
220 $fd = fopen($dumpfile, 'r');
221 if ($fd == FALSE) {
222 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
223 flush();
224 break;
226 $query = "";
227 $line = "";
228 while (!feof ($fd)){
229 $line = fgets($fd,1024);
230 $line = rtrim($line);
231 if (substr($line,0,2) == "--") // Kill comments
232 continue;
233 if (substr($line,0,1) == "#") // Kill comments
234 continue;
235 if ($line == "")
236 continue;
237 $query = $query.$line; // Check for full query
238 $chr = substr($query,strlen($query)-1,1);
239 if ($chr == ";") { // valid query, execute
240 $query = rtrim($query,";");
241 mysql_query("$query",$dbh);
242 $query = "";
245 echo "OK<br>\n";
246 fclose($fd);
247 flush();
248 echo "Adding Initial User...\n";
249 flush();
250 $iuser = $_POST["iuser"];
251 $iuname = $_POST["iuname"];
252 $igroup = $_POST["igroup"];
253 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
254 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
255 echo "ERROR. Could not run queries.\n";
256 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
257 flush();
258 break;
260 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
261 echo "ERROR. Could not run queries.\n";
262 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
263 flush();
264 break;
266 echo "OK<br>\n";
267 flush();
268 /* echo "Inserting ICD-9-CM Codes into Database...\n";
269 flush();
270 $fd = fopen($icd9, 'r');
271 if ($fd == FALSE) {
272 echo "ERROR. Could not open dumpfile.\n";
273 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
274 flush();
275 break;
277 $query = "";
278 $line = "";
279 while (!feof ($fd)){
280 $line = fgets($fd,1024);
281 $line = rtrim($line);
282 if (substr($line,0,2) == "--") // Kill comments
283 continue;
284 if (substr($line,0,1) == "#") // Kill comments
285 continue;
286 if ($line == "")
287 continue;
288 $query = $query.$line; // Check for full query
289 $chr = substr($query,strlen($query)-1,1);
290 if ($chr == ";") { // valid query, execute
291 $query = rtrim($query,";");
292 mysql_query("$query",$dbh);
293 $query = "";
296 echo "OK\n";
297 fclose($fd);*/
298 flush();
300 echo "\n<br>Please make sure 'library/sqlconf.php' is world-writeable for the next step.<br>\n";
303 echo "
304 <FORM METHOD='POST'>\n
305 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
306 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
307 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
308 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
309 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
310 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
311 <br>\n
312 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
315 break;
317 case 4:
318 echo "<b>Step $state</b><br><br>\n";
319 echo "Writing SQL Configuration to disk...\n";
320 @touch($conffile); // php bug
321 $fd = @fopen($conffile, 'w');
322 if ($fd == FALSE) {
323 echo "ERROR. Could not open config file '$conffile' for writing.\n";
324 flush();
325 break;
327 $string = "<?
328 // OpenEMR
329 // MySQL Config
330 // Referenced from sql.inc
334 $it_died = 0; //fmg: variable keeps running track of any errors
336 fwrite($fd,$string) or $it_died++;
337 fwrite($fd,"\$host\t= '$host';\n") or $it_died++;
338 fwrite($fd,"\$port\t= '$port';\n") or $it_died++;
339 fwrite($fd,"\$login\t= '$login';\n") or $it_died++;
340 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++;
341 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++;
344 $string = '
346 $sqlconf = array();
347 $sqlconf["host"]= $host;
348 $sqlconf["port"] = $port;
349 $sqlconf["login"] = $login;
350 $sqlconf["pass"] = $pass;
351 $sqlconf["dbase"] = $dbase;
352 //////////////////////////
353 //////////////////////////
354 //////////////////////////
355 //////DO NOT TOUCH THIS///
356 $config = 1; /////////////
357 //////////////////////////
358 //////////////////////////
359 //////////////////////////
362 ?><? // done just for coloring
364 fwrite($fd,$string) or $it_died++;
366 //it's rather irresponsible to not report errors when writing this file.
367 if ($it_died != 0) {
368 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
369 flush();
370 break;
372 fclose($fd);
374 echo "OK<BR>\nPlease restore secure permissions on the 'library/sqlconf.php' file now.\n<br><FORM METHOD='POST'>\n
375 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
376 <br>\n
377 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
379 break;
381 case 0:
382 default:
383 echo "Welcome to OpenEMR. This utility will step you through the configuration of OpenEMR for your practice. Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.<br><br>\n";
385 Echo "<p>If you are upgrading from a previous version, please read the README file.<br><br>";
387 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
394 </span>
396 </BODY>
397 </HTML>