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