|
1
|
|
|
<?php defined('BASEPATH') OR exit('No direct script access allowed'); |
|
2
|
|
|
|
|
3
|
|
|
class Authentication extends My_Public { |
|
4
|
|
|
|
|
5
|
|
|
public function __construct() { |
|
6
|
|
|
parent::__construct(); |
|
7
|
|
|
$this->load->library('encrypt'); |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
public function index() { |
|
11
|
|
|
|
|
12
|
|
|
redirect('home'); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function external_login() { |
|
16
|
|
|
|
|
17
|
|
|
$ip = $_SERVER['REMOTE_ADDR']; |
|
18
|
|
|
if ($this->user_model->ip_is_private($ip) === TRUE) { |
|
19
|
|
|
|
|
20
|
|
|
redirect('/'); |
|
21
|
|
|
} else { |
|
22
|
|
|
|
|
23
|
|
|
if (isset($_SESSION['external_login']) === TRUE) { |
|
24
|
|
|
|
|
25
|
|
|
redirect('/'); |
|
26
|
|
|
} else { |
|
27
|
|
|
|
|
28
|
|
|
$uid = $_SESSION['uid']; |
|
29
|
|
|
if ($this->user_model->external_login_blocked($uid) === TRUE) { |
|
30
|
|
|
|
|
31
|
|
|
redirect('/authentication/user-lockout'); |
|
32
|
|
|
} else { |
|
33
|
|
|
|
|
34
|
|
|
$this->load->helper('form'); |
|
35
|
|
|
$this->load->library('form_validation'); |
|
36
|
|
|
|
|
37
|
|
|
// validation rules |
|
38
|
|
|
$this->form_validation->set_rules('password', 'Password', 'required'); |
|
39
|
|
|
|
|
40
|
|
|
if ($this->form_validation->run() == false) { |
|
41
|
|
|
|
|
42
|
|
|
$this->load->view('templates/header'); |
|
43
|
|
|
$this->load->view('templates/ldap'); |
|
44
|
|
|
$this->load->view('templates/footer'); |
|
45
|
|
|
} else { |
|
46
|
|
|
|
|
47
|
|
|
$username = $_SESSION['username']; |
|
48
|
|
|
$password = $this->input->post('password'); |
|
49
|
|
|
|
|
50
|
|
|
if ($this->user_model->resolve_user_login($username, $password)) { |
|
51
|
|
|
|
|
52
|
|
|
$this->session->set_userdata('external_login', TRUE); |
|
53
|
|
|
redirect($_SESSION['last_url']); |
|
54
|
|
|
} else { |
|
55
|
|
|
|
|
56
|
|
|
if ($this->user_model->external_login_blocked($uid) === TRUE) { |
|
57
|
|
|
|
|
58
|
|
|
redirect('/authentication/user-lockout'); |
|
59
|
|
|
|
|
60
|
|
|
$function = 'external_login_LOCKOUT'; |
|
61
|
|
|
$this->user_model->function_log($function); |
|
62
|
|
|
|
|
63
|
|
|
} else { |
|
64
|
|
|
|
|
65
|
|
|
$function = 'external_login_PASSWORD_INCORRECT'; |
|
66
|
|
|
$this->user_model->function_log($function); |
|
67
|
|
|
|
|
68
|
|
|
$data = new stdClass(); |
|
69
|
|
|
$data->error = 'Wrong password please try again.'; |
|
70
|
|
|
|
|
71
|
|
|
// loose an attempt |
|
72
|
|
|
$this->user_model->external_login_fail($uid); |
|
73
|
|
|
|
|
74
|
|
|
$this->load->view('templates/header'); |
|
75
|
|
|
$this->load->view('templates/ldap', $data); |
|
76
|
|
|
$this->load->view('templates/footer'); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function logout() { |
|
86
|
|
|
|
|
87
|
|
|
if (isset($_COOKIE['CI-CONCRETE5']) === FALSE) { |
|
88
|
|
|
|
|
89
|
|
|
redirect('/'); |
|
90
|
|
|
} else { |
|
91
|
|
|
|
|
92
|
|
|
// clear session |
|
93
|
|
|
foreach ($_SESSION as $key => $value) { |
|
94
|
|
|
unset($_SESSION[$key]); |
|
95
|
|
|
} |
|
96
|
|
|
setcookie('CI-CONCRETE5', 'expired', time() - (1), "/"); |
|
97
|
|
|
redirect($_COOKIE['CONCRETE5_LOGOUT']); |
|
98
|
|
|
|
|
99
|
|
|
$function = 'LOGOUT'; |
|
100
|
|
|
$this->user_model->function_log($function); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
// END logout |
|
105
|
|
|
|
|
106
|
|
|
public function not_found() { |
|
107
|
|
|
|
|
108
|
|
|
$this->load->view('templates/error/404'); |
|
109
|
|
|
$function = '404_page_not_found'; |
|
110
|
|
|
$this->user_model->function_log($function); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function permissions() { |
|
114
|
|
|
|
|
115
|
|
|
$this->load->view('templates/error/permissions'); |
|
116
|
|
|
$function = 'PERMISSION_DENIED'; |
|
117
|
|
|
$this->user_model->function_log($function); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function internal() { |
|
121
|
|
|
|
|
122
|
|
|
$this->load->view('templates/error/internal'); |
|
123
|
|
|
$function = 'INTERNAL_ACCESS_ONLY'; |
|
124
|
|
|
$this->user_model->function_log($function); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function passkey() { |
|
128
|
|
|
|
|
129
|
|
|
$ip = $_SERVER['REMOTE_ADDR']; |
|
130
|
|
|
if ($this->user_model->ip_is_private($ip) === FALSE) { |
|
131
|
|
|
|
|
132
|
|
|
redirect('authentication/internal'); |
|
133
|
|
|
|
|
134
|
|
|
} else { |
|
135
|
|
|
|
|
136
|
|
|
$this->load->helper('form'); |
|
137
|
|
|
$this->load->library('form_validation'); |
|
138
|
|
|
|
|
139
|
|
|
// validation rules |
|
140
|
|
|
$this->form_validation->set_rules('passid', 'PassID', 'required'); |
|
141
|
|
|
$this->form_validation->set_rules('passkey', 'Passkey', 'required'); |
|
142
|
|
|
|
|
143
|
|
|
if ($this->form_validation->run() == false) { |
|
144
|
|
|
|
|
145
|
|
|
$this->load->view('templates/header'); |
|
146
|
|
|
$this->load->view('templates/passkey'); |
|
147
|
|
|
$this->load->view('templates/footer'); |
|
148
|
|
|
} else { |
|
149
|
|
|
|
|
150
|
|
|
$passid = $this->input->post('passid'); |
|
151
|
|
|
$passkey = $this->input->post('passkey'); |
|
152
|
|
|
|
|
153
|
|
|
if ($this->user_model->resolve_passkey($passid, $passkey)) { |
|
154
|
|
|
|
|
155
|
|
|
$this->user_model->log_passkey($ip, $passid); |
|
156
|
|
|
$details = $this->user_model->get_passkey_details($passid); |
|
157
|
|
|
|
|
158
|
|
|
$function = 'passkey_SUCCESSFUL'; |
|
159
|
|
|
$this->user_model->function_log($function); |
|
160
|
|
|
|
|
161
|
|
|
if (isset($_COOKIE['CI_PASSKEY']) === FALSE) { |
|
162
|
|
|
|
|
163
|
|
|
$encrypt_item = array('passkey_array', $passid); |
|
164
|
|
|
|
|
165
|
|
|
setcookie('CI_PASSKEY', serialize($encrypt_item), time() + (18000), "/"); |
|
166
|
|
|
redirect($details[0]['url']); |
|
167
|
|
|
|
|
168
|
|
|
} else { |
|
169
|
|
|
|
|
170
|
|
|
$current_array = unserialize($_COOKIE['CI_PASSKEY']); |
|
171
|
|
|
|
|
172
|
|
|
if (!in_array($passid, $current_array)) { |
|
173
|
|
|
|
|
174
|
|
|
$current_array[] = $passid; |
|
175
|
|
|
|
|
176
|
|
|
setcookie('CI_PASSKEY', serialize($current_array), time() + (18000), "/"); |
|
177
|
|
|
redirect($details[0]['url']); |
|
178
|
|
|
|
|
179
|
|
|
} else { |
|
180
|
|
|
redirect($details[0]['url']); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
} |
|
184
|
|
|
} else { |
|
185
|
|
|
|
|
186
|
|
|
$function = 'passkey_INCORRECT'; |
|
187
|
|
|
$this->user_model->function_log($function); |
|
188
|
|
|
|
|
189
|
|
|
$data = new stdClass(); |
|
190
|
|
|
$data->error = 'Wrong password please try again.'; |
|
191
|
|
|
|
|
192
|
|
|
$this->load->view('templates/header'); |
|
193
|
|
|
$this->load->view('templates/passkey', $data); |
|
194
|
|
|
$this->load->view('templates/footer'); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
// END controller |