forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_patient_info.php
193 lines (166 loc) · 6.61 KB
/
get_patient_info.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
<?php
// Copyright (C) 2011 Cassian LUP <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//starting the PHP session (also regenerating the session id to avoid session fixation attacks)
session_start();
session_regenerate_id(true);
//
//landing page definition -- where to go if something goes wrong
$landingpage = "index.php?site=".$_SESSION['site_id'];
//
//checking whether the request comes from index.php
if (!isset($_SESSION['itsme'])) {
session_destroy();
header('Location: '.$landingpage.'&w');
exit;
}
//
//some validation
if (!isset($_POST['uname']) || empty($_POST['uname'])) {
session_destroy();
header('Location: '.$landingpage.'&w&c');
exit;
}
if (!isset($_POST['pass']) || empty($_POST['pass'])) {
session_destroy();
header('Location: '.$landingpage.'&w&c');
exit;
}
//
require_once("../library/translation.inc.php");
// set the language
if (!empty($_POST['languageChoice'])) {
$_SESSION['language_choice'] = (int)$_POST['languageChoice'];
}
else if (empty($_SESSION['language_choice'])) {
// just in case both are empty, then use english
$_SESSION['language_choice'] = 1;
}
else {
// keep the current session language token
}
$_SESSION['language_direction'] = getLanguageDir( $_SESSION['language_choice'] );
//SANITIZE ALL ESCAPES
$fake_register_globals=false;
//STOP FAKE REGISTER GLOBALS
$sanitize_all_escapes=true;
//Settings that will override globals.php
$ignoreAuth = 1;
//
//Authentication (and language setting)
require_once('../interface/globals.php');
require_once("$srcdir/authentication/common_operations.php");
$password_update=isset($_SESSION['password_update']);
unset($_SESSION['password_update']);
$plain_code= $_POST['pass'];
$authorizedPortal=false; //flag
DEFINE("TBL_PAT_ACC_ON","patient_access_onsite");
DEFINE("COL_PID","pid");
DEFINE("COL_POR_PWD","portal_pwd");
DEFINE("COL_POR_USER","portal_username");
DEFINE("COL_POR_SALT","portal_salt");
DEFINE("COL_POR_PWD_STAT","portal_pwd_status");
$sql= "SELECT ".implode(",",array(COL_ID,COL_PID,COL_POR_PWD,COL_POR_SALT,COL_POR_PWD_STAT))
." FROM ".TBL_PAT_ACC_ON
." WHERE ".COL_POR_USER."=?";
$auth = privQuery($sql, array($_POST['uname']));
if($auth===false)
{
session_destroy();
header('Location: '.$landingpage.'&w');
exit;
}
if(empty($auth[COL_POR_SALT]))
{
if(SHA1($plain_code)!=$auth[COL_POR_PWD])
{
session_destroy();
header('Location: '.$landingpage.'&w');
exit;
}
$new_salt=oemr_password_salt();
$new_hash=oemr_password_hash($plain_code,$new_salt);
$sqlUpdatePwd= " UPDATE " . TBL_PAT_ACC_ON
." SET " .COL_POR_PWD."=?, "
. COL_POR_SALT . "=? "
." WHERE ".COL_ID."=?";
privStatement($sqlUpdatePwd,array($new_hash,$new_salt,$auth[COL_ID]));
}
else {
if(oemr_password_hash($plain_code,$auth[COL_POR_SALT])!=$auth[COL_POR_PWD])
{
session_destroy();
header('Location: '.$landingpage.'&w');
exit;
}
}
$_SESSION['portal_username']=$_POST['uname'];
$sql = "SELECT * FROM `patient_data` WHERE `pid` = ?";
if ($userData = sqlQuery($sql, array($auth['pid']) )) { // if query gets executed
if (empty($userData)) {
// no records for this pid, so escape
session_destroy();
header('Location: '.$landingpage.'&w');
exit;
}
if ($userData['allow_patient_portal'] != "YES") {
// Patient has not authorized portal, so escape
session_destroy();
header('Location: '.$landingpage.'&w');
exit;
}
if ($auth['pid'] != $userData['pid']) {
// Not sure if this is even possible, but should escape if this happens
session_destroy();
header('Location: '.$landingpage.'&w');
exit;
}
if ( $password_update)
{
$code_new=$_POST['pass_new'];
$code_new_confirm=$_POST['pass_new_confirm'];
if(!(empty($_POST['pass_new'])) && !(empty($_POST['pass_new_confirm'])) && ($code_new == $code_new_confirm)) {
$new_salt=oemr_password_salt();
$new_hash=oemr_password_hash($code_new,$new_salt);
// Update the password and continue (patient is authorized)
privStatement("UPDATE ".TBL_PAT_ACC_ON
." SET ".COL_POR_PWD."=?,".COL_POR_SALT."=?,".COL_POR_PWD_STAT."=1 WHERE id=?", array($new_hash,$new_salt,$auth['id']) );
$authorizedPortal = true;
}
}
if ($auth['portal_pwd_status'] == 0) {
if(!$authorizedPortal) {
// Need to enter a new password in the index.php script
$_SESSION['password_update'] = 1;
header('Location: '.$landingpage);
exit;
}
}
if ($auth['portal_pwd_status'] == 1) {
// continue (patient is authorized)
$authorizedPortal = true;
}
if ($authorizedPortal) {
// patient is authorized (prepare the session variables)
unset($_SESSION['password_update']); // just being safe
unset($_SESSION['itsme']); // just being safe
$_SESSION['pid'] = $auth['pid'];
$_SESSION['patient_portal_onsite'] = 1;
}
else {
session_destroy();
header('Location: '.$landingpage.'&w');
exit;
}
}
else { //problem with query
session_destroy();
header('Location: '.$landingpage.'&w');
exit;
}
require_once('summary_pat_portal.php');
?>