|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed'); |
|
4
|
|
|
|
|
5
|
|
|
class Temporary_account extends My_Force_Login { |
|
6
|
|
|
|
|
7
|
|
|
public function __construct() { |
|
8
|
|
|
parent::__construct(); |
|
9
|
|
|
$this->load->model('computing-support/Temporary_account_model', 'temporary_account_model'); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
public function index() { |
|
13
|
|
|
|
|
14
|
|
|
$this->load->helper('form'); |
|
15
|
|
|
$this->load->library('form_validation'); |
|
16
|
|
|
|
|
17
|
|
|
$data = array(); |
|
18
|
|
|
$data['faculty'] = $this->temporary_account_model->get_faculty(); |
|
19
|
|
|
$data['department'] = $this->temporary_account_model->get_department(); |
|
20
|
|
|
$data['tempid'] = "tempuser" . $this->temporary_account_model->get_next_temp(); |
|
21
|
|
|
|
|
22
|
|
|
//validation |
|
23
|
|
|
$this->form_validation->set_rules('faculty', 'Faculty', 'trim|required'); |
|
24
|
|
|
$this->form_validation->set_rules('requester', 'Staff requester', 'trim|required|min_length[3]'); |
|
25
|
|
|
$this->form_validation->set_rules('first_name', 'Users first name', 'trim|required|min_length[3]'); |
|
26
|
|
|
$this->form_validation->set_rules('last_name', 'Users last name', 'trim|required|min_length[3]'); |
|
27
|
|
|
|
|
28
|
|
|
if ($this->form_validation->run() === FALSE) { |
|
29
|
|
|
|
|
30
|
|
|
$this->load->view('templates/header'); |
|
31
|
|
|
$this->load->view('computing-support/temporary-account/view', $data); |
|
32
|
|
|
$this->load->view('templates/footer'); |
|
33
|
|
|
} else { |
|
34
|
|
|
|
|
35
|
|
|
$logged = $this->input->post('logged'); |
|
36
|
|
|
$faculty = $this->input->post('faculty'); |
|
37
|
|
|
$department = $this->input->post('department'); |
|
38
|
|
|
$requester = $this->input->post('requester'); |
|
39
|
|
|
$first_name = $this->input->post('first_name'); |
|
40
|
|
|
$last_name = $this->input->post('last_name'); |
|
41
|
|
|
$email = $this->input->post('email'); |
|
42
|
|
|
$username = $this->input->post('username'); |
|
43
|
|
|
$expiry = $this->input->post('expiry'); |
|
44
|
|
|
|
|
45
|
|
|
if ($this->temporary_account_model->create($logged, $faculty, $department, $requester, $first_name, $last_name, $email, $username, $expiry)) { |
|
46
|
|
|
|
|
47
|
|
|
$this->email->from('[email protected]', 'Temporary Logon Account Request'); |
|
48
|
|
|
$this->email->to('[email protected]'); |
|
49
|
|
|
$this->email->subject('Temporary Logon Account Request'); |
|
50
|
|
|
$this->email->message('A temporary network account has been requested by ' . $_SESSION['ldap']['full_name'] |
|
51
|
|
|
. ' for ' . $this->input->post('requester') |
|
52
|
|
|
. '' |
|
53
|
|
|
. 'the user will be: ' . $this->input->post('first_name') . ' ' . $this->input->post('last_name') |
|
54
|
|
|
. '' |
|
55
|
|
|
. 'Approve https://intranet.cant-col.ac.uk/dashboard/computing-support/temporary-account/approve'); |
|
56
|
|
|
$this->email->send(); |
|
57
|
|
|
|
|
58
|
|
|
$this->load->view('templates/header'); |
|
59
|
|
|
$this->load->view('computing-support/temporary-account/complete'); |
|
60
|
|
|
$this->load->view('templates/footer'); |
|
61
|
|
|
} else { |
|
62
|
|
|
|
|
63
|
|
|
$data = array(); |
|
|
|
|
|
|
64
|
|
|
$data = new stdClass(); |
|
65
|
|
|
$data->error = 'There was a problem requesting this account. Please try again.'; |
|
66
|
|
|
|
|
67
|
|
|
// failed to create user |
|
68
|
|
|
$this->load->view('templates/header'); |
|
69
|
|
|
$this->load->view('computing-support/temporary-account/view', $data); |
|
70
|
|
|
$this->load->view('templates/footer'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
View Code Duplication |
public function history() { |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
|
78
|
|
|
|
|
79
|
|
|
$data = array(); |
|
80
|
|
|
$data['temporary_account'] = $this->temporary_account_model->get_all(); |
|
81
|
|
|
|
|
82
|
|
|
$this->load->view('templates/header'); |
|
83
|
|
|
$this->load->view('computing-support/temporary-account/history', $data); |
|
84
|
|
|
$this->load->view('templates/footer'); |
|
85
|
|
|
} else { |
|
86
|
|
|
redirect('permissions'); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function check() { |
|
91
|
|
|
|
|
92
|
|
|
$data = array(); |
|
93
|
|
|
$data['temporary_account'] = $this->temporary_account_model->check_status(); |
|
94
|
|
|
|
|
95
|
|
|
$this->load->view('templates/header'); |
|
96
|
|
|
$this->load->view('computing-support/temporary-account/check', $data); |
|
97
|
|
|
$this->load->view('templates/footer'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
View Code Duplication |
public function pending() { |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
|
103
|
|
|
|
|
104
|
|
|
$data = array(); |
|
105
|
|
|
$data['temporary_account'] = $this->temporary_account_model->get_pending(); |
|
106
|
|
|
|
|
107
|
|
|
$this->load->view('templates/header'); |
|
108
|
|
|
$this->load->view('computing-support/temporary-account/pending', $data); |
|
109
|
|
|
$this->load->view('templates/footer'); |
|
110
|
|
|
} else { |
|
111
|
|
|
redirect('permissions'); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function cancel() { |
|
116
|
|
|
|
|
117
|
|
|
$id = $_GET['id']; |
|
118
|
|
|
$check_user = $this->temporary_account_model->match_id_user($id); |
|
119
|
|
|
if ($check_user[0]['logged'] == $_SESSION['ldap']['full_name'] || $check_user[0]['requested'] == $_SESSION['ldap']['full_name']) { |
|
120
|
|
|
|
|
121
|
|
|
if (isset($_GET['id'])) { |
|
122
|
|
|
|
|
123
|
|
|
$id = $_GET['id']; |
|
124
|
|
|
$this->temporary_account_model->cancel($id); |
|
125
|
|
|
|
|
126
|
|
|
$function = 'temp_account_CANCEL_' . $id; |
|
127
|
|
|
$this->user_model->function_log($function); |
|
128
|
|
|
|
|
129
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
|
130
|
|
|
} |
|
131
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
|
132
|
|
|
} else { |
|
133
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
View Code Duplication |
public function reject() { |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
|
140
|
|
|
|
|
141
|
|
|
if (isset($_GET['id'])) { |
|
142
|
|
|
|
|
143
|
|
|
$id = $_GET['id']; |
|
144
|
|
|
$this->temporary_account_model->reject($id); |
|
145
|
|
|
|
|
146
|
|
|
$function = 'temp_account_REJECT_' . $id; |
|
147
|
|
|
$this->user_model->function_log($function); |
|
148
|
|
|
|
|
149
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
|
153
|
|
|
} else { |
|
154
|
|
|
redirect($_SERVER['HTTP_REFERER']); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function approve() { |
|
159
|
|
|
|
|
160
|
|
|
if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
|
161
|
|
|
|
|
162
|
|
|
if (isset($_GET['id'])) { |
|
163
|
|
|
|
|
164
|
|
|
$id = $_GET['id']; |
|
165
|
|
|
//$this->temporary_account_model->approve($id); |
|
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
$function = 'temp_account_APPROVED_' . $id; |
|
168
|
|
|
$this->user_model->function_log($function); |
|
169
|
|
|
|
|
170
|
|
|
$data = array(); |
|
171
|
|
|
$data['AD'] = $this->temporary_account_model->get_account($id); |
|
172
|
|
|
|
|
173
|
|
|
//AD account start |
|
174
|
|
|
//AD Server |
|
175
|
|
|
$AD_server = $this->config->item('ldapserver'); |
|
176
|
|
|
$AD_Auth_User = $this->config->item('ldapshortdomain').$this->config->item('ldapadminun'); //Administrative user |
|
177
|
|
|
$AD_Auth_PWD = $this->config->item('ldapadminpass'); //The password |
|
178
|
|
|
//Create Active Directory timestamp |
|
179
|
|
|
date_default_timezone_set($this->config->item('timezone')); |
|
180
|
|
|
|
|
181
|
|
|
//Format dd-mm-yyyy |
|
182
|
|
|
//Expiry is beginning of day (thats why +1 day |
|
183
|
|
|
$dateFromForm = date('d-m-Y', strtotime($data['AD'][0]['expiry']. ' +1 day')); |
|
184
|
|
|
|
|
185
|
|
|
//Format hh:mm:ss |
|
186
|
|
|
$timeFromForm = "00:00:00"; |
|
187
|
|
|
|
|
188
|
|
|
$dateWithTime = $dateFromForm . " " . $timeFromForm; |
|
|
|
|
|
|
189
|
|
|
|
|
190
|
|
View Code Duplication |
function convertDateToUnix($input) { |
|
|
|
|
|
|
191
|
|
|
$format = 'd-m-Y H:i:s'; |
|
192
|
|
|
$date = DateTime::createFromFormat($format, $input); |
|
193
|
|
|
$UNIXTimestamp = $date->getTimestamp(); |
|
194
|
|
|
return $UNIXTimestamp; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
function convertUnixtoWin($input) { |
|
|
|
|
|
|
198
|
|
|
return ($input + 11644473600) * 10000000; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
//$UNIX = convertDateToUnix($dateWithTime); |
|
|
|
|
|
|
202
|
|
|
//$WIN = convertUnixtoWin($UNIX); |
|
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
//Create Unicode password |
|
205
|
|
|
$passwordWithQuotes = '"' . $data['AD'][0]['password'] . '"'; |
|
206
|
|
|
$ldaprecord = array(); |
|
207
|
|
|
$ldaprecord["unicodepwd"] = iconv('UTF-8', 'UTF-16LE', $passwordWithQuotes); |
|
208
|
|
|
|
|
209
|
|
|
//Build Active Directory record |
|
210
|
|
|
$ldaprecord["cn"] = $data['AD'][0]['username']; |
|
211
|
|
|
$ldaprecord["givenName"] = $data['AD'][0]['first_name']; |
|
212
|
|
|
$ldaprecord["sn"] = $data['AD'][0]['last_name']; |
|
213
|
|
|
$ldaprecord["mail"] = $data['AD'][0]['email']; |
|
214
|
|
|
$ldaprecord["sAMAccountName"] = $data['AD'][0]['username']; |
|
215
|
|
|
$ldaprecord["displayName"] = $data['AD'][0]['first_name'] . " " . $data['AD'][0]['last_name']; |
|
216
|
|
|
$ldaprecord["l"] = "Canterbury"; |
|
217
|
|
|
$ldaprecord["description"] = "Temp account created by dashboard for " . $ldaprecord["displayName"]; |
|
218
|
|
|
//$ldaprecord["accountExpires"] = $WIN; |
|
|
|
|
|
|
219
|
|
|
$ldaprecord["UserAccountControl"] = "512"; //512 - Enabled Account |
|
220
|
|
|
$ldaprecord['userPrincipalName'] = $data['AD'][0]['username'] . '@cant-col.ac.uk'; |
|
221
|
|
|
$ldaprecord['objectclass'][0] = "top"; |
|
222
|
|
|
$ldaprecord['objectclass'][1] = "person"; |
|
223
|
|
|
$ldaprecord['objectclass'][2] = "organizationalPerson"; |
|
224
|
|
|
$ldaprecord['objectclass'][3] = "user"; |
|
225
|
|
|
$dn = 'CN=' . $ldaprecord["cn"] . ',OU=Temp Accounts,OU=Students,OU=Accounts,DC=cant-col,DC=ac,DC=uk'; |
|
226
|
|
|
|
|
227
|
|
|
// Connect to Active Directory |
|
228
|
|
|
$ds = ldap_connect('ldaps://' . $AD_server); |
|
229
|
|
|
|
|
230
|
|
|
if ($ds) { |
|
231
|
|
|
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
232
|
|
|
ldap_bind($ds, $AD_Auth_User, $AD_Auth_PWD); //Bind |
|
233
|
|
|
ldap_add($ds, $dn, $ldaprecord); //Create account |
|
234
|
|
|
ldap_close($ds); //Close connection |
|
235
|
|
|
$this->temporary_account_model->created_account($id); |
|
236
|
|
|
} else { |
|
|
|
|
|
|
237
|
|
|
//redirect('computing-support/temporary-account/error?id='.$id); |
|
|
|
|
|
|
238
|
|
|
} |
|
239
|
|
|
//AD account end. |
|
240
|
|
|
|
|
241
|
|
|
//redirect($_SERVER['HTTP_REFERER']); |
|
|
|
|
|
|
242
|
|
|
$this->load->view('templates/header'); |
|
243
|
|
|
$this->load->view('computing-support/temporary-account/view'); |
|
244
|
|
|
$this->load->view('templates/footer'); |
|
245
|
|
|
|
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
//redirect($_SERVER['HTTP_REFERER']); |
|
|
|
|
|
|
249
|
|
|
} else { |
|
|
|
|
|
|
250
|
|
|
//redirect($_SERVER['HTTP_REFERER']); |
|
|
|
|
|
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
public function error() { |
|
255
|
|
|
|
|
256
|
|
|
if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) { |
|
257
|
|
|
|
|
258
|
|
|
$this->load->view('templates/header'); |
|
259
|
|
|
$this->load->view('computing-support/temporary-account/error', $data); |
|
|
|
|
|
|
260
|
|
|
$this->load->view('templates/footer'); |
|
261
|
|
|
} else { |
|
262
|
|
|
redirect('permissions'); |
|
263
|
|
|
} |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.