/
controller.guard.php
192 lines (169 loc) · 3.38 KB
/
controller.guard.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
<?php
// BASIC LOGIN
include_once("model.classes.php");
error_reporting(-1);
ini_set('error_reporting', E_ALL);
set_time_limit ( 60 * 60 * 3 ); // 3 hours
include_once("utility.functions.php");
$BIN_DIR=__dir__;
// watch for jobs
$INT_32_OR_64=32;
if (strpos(php_uname('m'),"64")!==false)
{
$INT_32_OR_64=64;
}
$PATH_SEPERATOR="/";
$IS_LINUX=true;
$IS_WINDOWS=false;
if ( strpos(php_uname('s'),"nux")===false)
{
$IS_WINDOWS=true;
$IS_LINUX=false;
$PATH_SEPERATOR="\\";
}
include_once("model.database.php");
// open settings file
$settings_file=($BIN_DIR.$PATH_SEPERATOR."his-config.php");
if ( !file_exists($settings_file) )
{
$settings_file=(dirname($BIN_DIR).$PATH_SEPERATOR."his-config.php");
}
if ( file_exists($settings_file) )
{
include_once($settings_file);
}
else
{
include("view.menu.public.php");
include("view.public.php");
exit;
}
if (!$APP['db']->connected)
{
echo "ERROR: Not connected to database.";
exit;
}
$u=false;
global $u;
$GLOBALS['u']=$u;
$APP['u']=$u;
if ( isset($_COOKIE["hisdata"]) )
{
$cookie_data=$_COOKIE['hisdata'];
$cookie_data = explode(":",$cookie_data);
$cookie_user = $cookie_data[0];
$cookie_pass = $cookie_data[1];
$u = new user_user_name();
$u->get_from_hashrange($cookie_user);
if ($u->user_name!="undefined")
{
if ($u->pw != $cookie_pass)
{
$u=false;
}
}
}
else if ( isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) )
{
// UID + Secret
$u = new user_id_user();
$u->get_from_hashrange($_SERVER['PHP_AUTH_USER']);
if ($u->user_name!="undefined")
{
if ($u->secret != $_SERVER['PHP_AUTH_PW'])
{
$u=false;
}
}
else
{
$u=false;
}
}
else if ( isset($_POST['uid']) && isset($_POST['secret']) )
{
// UID + Secret
$u = new user_id_user();
$u->get_from_hashrange($_POST['uid']);
if ($u->user_name!="undefined")
{
if ($u->secret != $_POST['secret'])
{
$u=false;
}
}
else
{
$u=false;
}
}
else if ( isset($_GET['uid']) && isset($_GET['secret']) )
{
// UID + Secret
$u = new user_id_user();
$u->get_from_hashrange($_GET['uid']);
if ($u->user_name!="undefined")
{
if ($u->secret != $_GET['secret'])
{
$u=false;
}
}
else
{
$u=false;
}
}
else if ( false )
{
// LDAP PLACEHOLDER - NEED TO TEST
$u = false;
/*
$ldapconfig['host'] = 'localhost';
$ldapconfig['port'] = NULL;
$ldapconfig['basedn'] = 'dc=localhost,dc=com';
$ldapconfig['authrealm'] = 'My Realm';
function ldap_authenticate() {
global $ldapconfig;
global $PHP_AUTH_USER;
global $PHP_AUTH_PW;
if ($PHP_AUTH_USER != "" && $PHP_AUTH_PW != "") {
$ds=@ldap_connect($ldapconfig['host'],$ldapconfig['port']);
$r = @ldap_search( $ds, $ldapconfig['basedn'], 'uid=' . mysqli_escape_string($PHP_AUTH_USER) );
if ($r) {
$result = @ldap_get_entries( $ds, $r);
if ($result[0]) {
if (@ldap_bind( $ds, $result[0]['dn'], mysqli_escape_string($PHP_AUTH_PW) ) ) {
return $result[0];
}
}
}
}
header('WWW-Authenticate: Basic realm="'.$ldapconfig['authrealm'].'"');
header('HTTP/1.0 401 Unauthorized');
return NULL;
}
if (($result = ldap_authenticate()) == NULL) {
echo('Authorization Failed');
exit(0);
}
echo('Authorization success');
print_r($result);
*/
}
if (!$u)
{
// is public interface enabled or not?
if ( !endsWith($_SERVER['SCRIPT_NAME'],"status.php") )
{
include("view.menu.public.php");
include("view.public.php");
exit;
}
else
{
echo "login failure";
exit;
}
}
?>