/
DeleteUserDo.php
135 lines (89 loc) · 3.65 KB
/
DeleteUserDo.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
<?php
$allowed_ops = array("uid", "mail", "userPassword", "image_captcha");
require_once "./setup/config.php";
require_once "./libraries/Locale.inc.php";
require_once "./themes/$app_theme/header.php";
require_once "./libraries/Functions.inc.php";
require_once "./libraries/Parameters.inc.php";
require_once "./libraries/LDAPConnection.inc.php";
?>
<h2><?= _("Request Status") ?></h2>
<?php
// USER INPUT VALIDATION -------------------------------------------------------
// Some of the parameters were not set, the form was not used to get here
if (!isset($uid) || !isset($mail) || !isset($userPassword) || !isset($image_captcha)) {
VariableNotSet();
// Some of the parameters are empty
} elseif ($uid == '' || $mail == '' || $userPassword == '' || $image_captcha == '') {
EmptyVariable();
// The cookie has expired
} elseif (!isset($session_captcha)) {
ExpiredCaptcha();
// We compare the cookie hash with the user entry
// If they are different, the user messed up
} elseif ($session_captcha <> $image_captcha) {
WrongCaptcha();
// Invalid username
} elseif (preg_match("/^[A-Za-z0-9_-]+$/", $uid) == 0) {
InvalidUsername();
// Username has less than 3 characters or more than 30
} elseif ((strlen($uid) < 3) || (strlen($uid) > 30)) {
WrongUIDLength();
// Invalid Password
} elseif (preg_match("/^[A-Za-z0-9@#$%^&+=!.-_]+$/", $userPassword) == 0) {
InvalidPassword();
// Password has less than 8 characters or more than 30
} elseif ((strlen($userPassword) < 8) || (strlen($userPassword) > 30)) {
WrongPasswordLength();
// Invalid e-mail
} elseif (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
InvalidEMail();
} else {
// VALIDATION PASSED -------------------------------------------------------
// Encoding the password
$userPassword = EncodePassword($userPassword, $ldap_enc);
// We are going to search for a user matching the data entered
// We stablish what attributes are going to be retrieved from each entry
$search_limit = array("dn");
// The filter string to search through LDAP
$search_string = "(&(mail=" . $mail . ")(userPassword=" . $userPassword . ")(uid=" . $uid . "))";
// The attribute the array of entries is going to be sorted by
$sort_string = 'dn';
// Searching ...
$search_entries = AssistedLDAPSearch($ldapc, $ldap_base, $search_string, $search_limit, $sort_string);
// How much did we get?
$result_count = $search_entries['count'];
// If we didn't get any entries, then the entry doesn't exist or the user
// provided wrong data
if ($result_count == 0) {
NoResults();
// If we got more than one entry, then something is really messed up with
// the database, there must not be more than one entry with the same data
} elseif ($result_count > 1) {
MultipleResults();
// If we got one coincidence, then we can proceed to deletion
} elseif ($result_count == 1) {
// Assigning DN to delete
$dn = $search_entries[0]["dn"];
// Deleting ...
$del = AssistedLDAPDelete($ldapc, $dn);
// If the deleting went OK, we send the notification e-mail to the user
if ($del) {
$send = AssistedEMail("DeleteUserDo", $mail);
}
// If the mailing went OK ...
if ($send) {
// We log the event
WriteLog("DeleteUserDo");
// Print the good news to the user
Success("DeleteUserDo");
} else {
// We fail nicely, at least
Fail("DeleteUserDo");
}
}
}
// Closing the connection
$ldapx = AssistedLDAPClose($ldapc);
require_once "./themes/$app_theme/footer.php";
?>