-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser_del.php
More file actions
245 lines (220 loc) · 9.5 KB
/
user_del.php
File metadata and controls
245 lines (220 loc) · 9.5 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
// delete a user
// $Id: user_del.php,v 2.50 2007-03-14 12:10:53 turbo Exp $
//
// {{{ Setup session etc
require("./include/pql_session.inc");
require($_SESSION["path"]."/include/pql_config.inc");
require($_SESSION["path"]."/include/pql_ezmlm.inc");
require($_SESSION["path"]."/include/pql_krbafs.inc");
$_pql = new pql($_SESSION["USER_HOST"], $_SESSION["USER_DN"], $_SESSION["USER_PASS"]);
include($_SESSION["path"]."/header.html");
if(pql_get_define("PQL_CONF_DEBUG_ME")) {
echo "<pre>";
echo "Request array: "; printr($_REQUEST);
echo "</pre>";
}
$url["domain"] = pql_format_urls($_REQUEST["domain"]);
$url["rootdn"] = pql_format_urls($_REQUEST["rootdn"]);
$url["user"] = pql_format_urls($_REQUEST["user"]);
// }}}
// {{{ Get organization name for domain and common name of user
$o = $_pql->get_attribute($_REQUEST["domain"], pql_get_define("PQL_ATTR_O"));
if(!$o) {
// No 'organization' attribute (or it's not configured - 0)
// Use the RDN
$o = $_REQUEST["domain"];
}
$cn = $_pql->get_attribute($_REQUEST["user"], pql_get_define("PQL_ATTR_CN"));
?>
<span class="title1"><?php echo pql_complete_constant($LANG->_('Remove user %user% from domain %domain%'), array("domain" => $o, "user" => $cn)); ?></span>
<br><br>
<?php
// }}}
if(isset($_REQUEST["ok"]) || !pql_get_define("PQL_CONF_VERIFY_DELETE", $_REQUEST["rootdn"])) {
// {{{ Delete a user from the database
$delete_forwards = (isset($_REQUEST["delete_forwards"]) || pql_get_define("PQL_CONF_VERIFY_DELETE", $_REQUEST["rootdn"])) ? true : false;
$delete_admins = (isset($_REQUEST["delete_admins"]) || pql_get_define("PQL_CONF_VERIFY_DELETE", $_REQUEST["rootdn"])) ? true : false;
$unsubscribe = (isset($_REQUEST["unsubscribe"]) || pql_get_define("PQL_CONF_VERIFY_DELETE", $_REQUEST["rootdn"])) ? true : false;
// {{{ Get the user principal
$principal = pql_kadmin_get_principal($_REQUEST["user"]);
if($principal)
pql_kadmin_delprinc($principal);
// }}}
// {{{ Get the users mail addresses before the object gets deleted
if($_REQUEST["unsubscribe"]) {
$mails = $_pql->get_attribute($_REQUEST["user"], pql_get_define("PQL_ATTR_MAIL"));
$aliases = $_pql->get_attribute($_REQUEST["user"], pql_get_define("PQL_ATTR_MAILALTERNATE"));
if($mails and !is_array($mails))
$mails = array($mails);
// Combine the two attributes into one array.
if(is_array($aliases)) {
foreach($aliases as $alias)
$mails[] = $alias;
}
}
// }}}
$msg = '';
// {{{ Is there a matching group object?
// Get the 'uid' value from the user
$results = $_pql->search($_REQUEST["user"], 'objectClass=*', 'BASE');
if($results[pql_get_define("PQL_ATTR_UID")]) {
foreach($_SESSION["BASE_DN"] as $dn) {
$filter = '(cn='.$results[pql_get_define("PQL_ATTR_UID")].')';
$results = $_pql->search($dn, $filter);
if(@$results["dn"]) {
// Flat object - only one hit
if($_pql->delete($results["dn"])) {
$msg = pql_complete_constant($LANG->_('Successfully removed group %dn%'),
array('dn' => $results["dn"])).'<br>';
$DNs[] = $results["dn"];
} else
$msg = pql_complete_constant($LANG->_('Failed to remove group %dn%'),
array('dn' => $results["dn"])).'<br>';
} elseif(@$results[0]["dn"]) {
// Multiple objects
for($i=0; $results[$i]["dn"]; $i++) {
if($_pql->delete($results[$i]["dn"])) {
$msg = pql_complete_constant($LANG->_('Successfully removed group %dn%'),
array('dn' => $results[$i]["dn"])).'<br>';
$DNs[] = $results[$i]["dn"];
} else
$msg = pql_complete_constant($LANG->_('Failed to remove group %dn%'),
array('dn' => $results[$i]["dn"])).'<br>';
}
}
}
}
// }}}
// {{{ Delete the user
if(pql_user_del($_REQUEST["domain"], $_REQUEST["user"], $delete_forwards)) {
$msg .= $LANG->_('Successfully removed user') . ": <b>" . $cn . "</b>";
$DNs[] = $_REQUEST["user"];
$rlnb = "&rlnb=1";
// ----------------------------------------
// {{{ Remove all administrator/ezmlmAdministrator/controlsAdministrator and seealso
// attributes that reference this user.
if($_REQUEST["delete_admins"]) {
// We're only interested in these attributes
$attribs = array(pql_get_define("PQL_ATTR_ADMINISTRATOR"),
pql_get_define("PQL_ATTR_ADMINISTRATOR_CONTROLS"),
pql_get_define("PQL_ATTR_ADMINISTRATOR_EZMLM"),
pql_get_define("PQL_ATTR_SEEALSO"));
pql_replace_values($attribs, $_REQUEST["user"]);
}
// }}}
// {{{ Unsubscribe user from all mailinglists (on this host naturaly :)
if($_REQUEST["unsubscribe"]) {
// Get all domains, looking for mailing lists
$domains = pql_get_domains();
if(is_array($domains)) {
foreach($domains as $key => $this_domain) {
// Get base directory for mails in all domains
if(($basemaildir = $_pql->get_attribute($this_domain, pql_get_define("PQL_ATTR_BASEMAILDIR")))) {
// Get the lists in this directory
$user = $_pql->get_attribute($_REQUEST["domain"], pql_get_define("PQL_ATTR_EZMLM_USER"));
$ezmlm = new ezmlm($user, $basemaildir);
if(is_array($ezmlm->mailing_lists[0])) {
// Go through each list in this domain
foreach($ezmlm->mailing_lists as $number => $data) {
if(is_array($data["subscriber"])) {
// Go through each subscriber in this list
foreach($data["subscriber"] as $subscriber) {
// Go through each of the users mail addresses
foreach($mails as $mail) {
if(preg_match("/$mail/i", $subscriber)) {
// The user is subscribed to this list - unsubscribe
echo "Unsubscribing user from list ".$data["name"]."<br>";
$ezmlm->unsubscribe($number, $subscriber);
}
} // FOREACH address in the subscriber list.
} // FOREACH subscriber.
} // IF there are subscribers.
} // FOREACH mailing lists.
} // IF there are ezmlm mailing lists.
} // IF there is $basemaildir.
} // FOREACH domain.
} // IF there are domains to check.
} // IF unsubscribing from all mailing lists.
// }}}
// ----------------------------------------
// Do _something_ to the users mailbox
switch($_REQUEST["mail_action"]) {
case "delete_mail":
case "archive_mail":
case "donate_mail":
$msg .= "<br>".$LANG->_('Sorry, no changes have been made to the mailbox. It\'s not implemented in phpQLAdmin yet');
break;
}
} else
$msg .= $LANG->_('Failed to remove user') . ": " . ldap_error($_pql->ldap_linkid);
// }}}
// {{{ Now it's time to run the special user removal script
if(pql_get_define("PQL_CONF_SCRIPT_DELETE_USER", $_REQUEST["rootdn"])) {
// Setup the environment with the user details
putenv("PQL_CONF_DOMAIN=$domain");
putenv("PQL_CONF_WEBUSER=".posix_getuid());
putenv("PQL_MAIL_ACTION=".$_REQUEST["mail_action"]);
// Execute the user removal script (0 => show output)
if(pql_execute(pql_get_define("PQL_CONF_SCRIPT_DELETE_USER", $_REQUEST["rootdn"]), 0)) {
echo pql_complete_constant($LANG->_('The %what% removal script failed'),
array('what' => $LANG->_('user'))) . "!<br>";
$msg .= urlencode(pql_complete_constant($LANG->_('The %what% removal script failed'),
array('what' => $LANG->_('user'))) ."!") . ". <br>";
} else {
echo "<b>" . pql_complete_constant($LANG->_('Successfully executed the %what% removal script'),
array('what' => $LANG->_('user'))) . "</b><br>";
$msg .= urlencode(pql_complete_constant($LANG->_('Successfully executed the %what% removal script'),
array('what' => $LANG->_('user')))) . ". <br>";
}
}
// }}}
// {{{ Redirect to domain-detail page
$msg = urlencode($msg);
$link = "domain_detail.php?rootdn=".$url["rootdn"]."&domain=".$url["domain"]."&msg=$msg$rlnb";
if(pql_get_define("PQL_CONF_DEBUG_ME")) {
echo "<p>DNs removed: ";
printr($DNs);
}
pql_header($link);
// }}}
// }}}
} else {
// {{{ Get confirmation and ask HOW to delete a user
?>
<br>
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="GET">
<input type="hidden" name="user" value="<?php echo $url["user"]?>">
<input type="hidden" name="rootdn" value="<?php echo $url["rootdn"]?>">
<input type="hidden" name="domain" value="<?php echo $url["domain"]?>">
<span class="title3"><?php echo $LANG->_('What should we do with forwards to this user')?>?</span><br>
<input type="checkbox" name="delete_forwards" checked> <?php echo $LANG->_('Delete all forwards')?><br>
<input type="checkbox" name="delete_admins" checked> <?php echo $LANG->_('Remove user from administrator/seeAlso')?><br>
<input type="checkbox" name="unsubscribe" checked> <?php echo $LANG->_('Unsubscribe user from all mailing lists')?><br><br>
<?php if(pql_get_define("PQL_CONF_SCRIPT_DELETE_USER", $_REQUEST["rootdn"])) { ?>
<span class="title3"><?php echo $LANG->_('What should we do with the users mailbox')?>?</span><br>
<input type="radio" name="mail_action" value="delete_mail"> <?php echo $LANG->_('Delete it')?><br>
<input type="radio" name="mail_action" value="archive_mail" checked> <?php echo $LANG->_('Archive it')?><br>
<input type="radio" name="mail_action" value="donate_mail"> <?php echo $LANG->_('Donate it to another user')?><br><br>
<?php } ?>
<span class="title2"><?php echo $LANG->_('Are you really sure')?>?</span>
<input type="submit" name="ok" value="<?php echo $LANG->_('Yes')?>">
<input type="button" name="back" value="<?php echo $LANG->_('No')?>" onClick="history.back();">
</form>
<br>
<?php
// }}}
} // end of if
?>
</body>
</html>
<?php
pql_flush();
/*
* Local variables:
* mode: php
* mode: font-lock
* tab-width: 4
* End:
*/
?>