-
Notifications
You must be signed in to change notification settings - Fork 1
/
control_del.php
206 lines (185 loc) · 6.72 KB
/
control_del.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
// Delete a mailserver controls object
// $Id: control_del.php,v 2.29 2007-03-14 12:10:50 turbo Exp $
//
require("./include/pql_session.inc");
require($_SESSION["path"]."/include/pql_config.inc");
// {{{ Get users that uses this mailserver - we need to know this twice.
// Once the first time we're called, and once when the acctuall deletion
// will take place.
// Therefor a little function here to simplify, and avoid duplication.
// I'm lazy, so sue me! :)
function control_del_find_users($host) {
global $_pql;
// See if there's any users that have this host as mailHost
$filter = pql_get_define("PQL_ATTR_MAILHOST").'='.$host;
foreach($_SESSION["BASE_DN"] as $dn) {
$usrs = $_pql->search($dn, $filter);
if(is_array($usrs)) {
for($i=0; $i < count($usrs); $i++)
$users[] = $usrs[$i];
}
}
return($users);
}
// }}}
if(pql_get_define("PQL_CONF_CONTROL_USE")) {
// {{{ include control api if control is used
include($_SESSION["path"]."/include/pql_control.inc");
$_pql_control = new pql_control($_SESSION["USER_HOST"], $_SESSION["USER_DN"], $_SESSION["USER_PASS"]);
// }}}
if(!$_REQUEST["submit"] or $_REQUEST["error"]) {
include($_SESSION["path"]."/header.html");
// Check to see if this object exists
// TODO: Replace with '$_pql_control->search()'
$filter = "(".pql_get_define("PQL_ATTR_CN") . "=" . $_REQUEST["mxhost"] . ")";
$sr = ldap_search($_pql_control->ldap_linkid, $_SESSION["USER_SEARCH_DN_CTR"], $filter,
array(pql_get_define("PQL_ATTR_MAILHOST")), "BASE");
if(ldap_count_entries($_pql_control->ldap_linkid, $sr) > 0) {
// Exists - get DN
$dn = ldap_get_dn($_pql_control->ldap_linkid,
ldap_first_entry($_pql_control->ldap_linkid, $sr));
$users = control_del_find_users($_REQUEST["mxhost"]);
if(is_array($users)) {
// There's users - get MX and QmailLDAP/Controls objects
$result = $_pql_control->get_dn($_SESSION["USER_SEARCH_DN_CTR"],
'(&(cn=*)(objectclass=qmailControl))');
for($i=0; $i < count($result); $i++)
$hosts[] = $_pql_control->get_attribute($result[$i], pql_get_define("PQL_ATTR_CN"));
?>
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="GET">
<input type="hidden" name="oldmx" value="<?php echo $_REQUEST["mxhost"]?>">
<span class="title2"><?php echo $LANG->_("There's users on this mail server!<br>What would you like to do with them?")?></span><br>
<input type="radio" name="action" value="ignore" CHECKED><?php echo $LANG->_('Ignore')?><br>
<input type="radio" name="action" value="delete"><?php echo $LANG->_('Delete all users')?><br>
<input type="radio" name="action" value="move" <?php if($_REQUEST["error"]) { ?>CHECKED<?php } ?>>
<?php echo $LANG->_('Move users to server:')?><br>
<?php if($_REQUEST["error"]) {
echo " ";
echo pql_format_error_span($LANG->_("Hostname missing!"));
echo "<br>";
}
for($i=0; $i < count($hosts); $i++) {
if($hosts[$i] != $_REQUEST["mxhost"]) {
$host = pql_maybe_idna_decode($hosts[$i]);
?>
<input type="radio" name="newmx" value="<?php echo $host?>"><b><?php echo $host?></b><br>
<?php }
}
?>
<input type="radio" name="newmx" value="user"><?php echo $LANG->_('User specified')?>
<input type="text" name="mxhost" value="<?php echo $_REQUEST["newmx"]?>" size="30"><br>
<br>
<input type="submit" name="submit" value="<?php echo "-->>"?>">
</form>
<table cellspacing="0" cellpadding="3" border="0">
<th>
<tr class="<?php pql_format_table(); ?>">
<td><img src="images/info.png" width="16" height="16" alt="" border="0"></td>
<td><?php echo $LANG->_('NOTE: Deleting or moving a user will not touch their mail- or homedirectory! You will have to delete/move them to the new server manually.')?></td>
</tr>
</th>
</table>
<?php } else
// No users using this mailserver...
$delete_object = 1;
}
} else {
// We've submitted
switch($_REQUEST["action"]) {
case "ignore":
// {{{ Don't touch the users - delete object directly
$delete_object = 1;
break;
// }}}
case "delete":
// {{{ 1. Delete all users
$users = control_del_find_users($_REQUEST["oldmx"]);
if(is_array($users)) {
for($i=0; $i < count($users); $i++)
pql_user_del($_REQUEST["domain"], $users[$i], 1);
}
// }}}
// {{{ 2. Delete object
$delete_object = 1;
break;
// }}}
case "move":
// {{{ 1. Move user(s) to other MX/Host. Where?
if($_REQUEST["newmx"] == "") {
// We haven't specified a (pre-defined) MX/host to move the users to - do over!
$oldmx = $_REQUEST["oldmx"]; unset($_REQUEST);
$url = $_SERVER["PHP_SELF"]."?mxhost=$oldmx&error=1";
pql_header($url, 1);
} else {
if(($_REQUEST["newmx"] == 'user') and !$_REQUEST["mxhost"]) {
// No (user specified) MX/host specified - do over!
$oldmx = $_REQUEST["oldmx"]; unset($_REQUEST);
$url = $_SERVER["PHP_SELF"]."?mxhost=$oldmx&error=1";
pql_header($url, 1);
} else {
// Move the user(s) to user specified server
// OR
// Move the user(s) to specified server
if($_REQUEST["newmx"] == 'user')
$host = $_REQUEST["mxhost"];
else
$host = $_REQUEST["newmx"];
$users = control_del_find_users($_REQUEST["oldmx"]);
if(is_array($users)) {
for($i=0; $i < count($users); $i++) {
pql_modify_attribute($users[$i],
pql_get_define("PQL_ATTR_MAILHOST"),
'', $host);
}
}
}
}
// }}}
// {{{ 2. Delete object
$delete_object = 1;
break;
// }}}
}
}
// {{{ delete object
if($delete_object) {
if($_REQUEST["mxhost"])
$mxhost = $_REQUEST["mxhost"];
elseif($_REQUEST["oldmx"]) {
$mxhost = $_REQUEST["oldmx"];
$dn = pql_get_define("PQL_ATTR_CN").'='.$mxhost.','.$_SESSION["USER_SEARCH_DN_CTR"];
}
if(pql_get_define("PQL_CONF_DEBUG_ME"))
die("I'm debugging, so '<b>$dn</b>' isn't deleted!");
else {
if(! $_pql_control->delete($dn)) {
// Could not delete object
$url = "control_detail.php?mxhost=".$mxhost."&msg=";
$url .= urlencode(pql_complete_constant($LANG->_("Failed to delete mailserver %host%.",
array('host' => $mxhost))));
} else {
// Successfully deleted object
$url = "home.php?rlnb=2&msg=";
$url .= urlencode(pql_complete_constant($LANG->_("Successfully deleted mailserver %host%.",
array('host' => $mxhost))));
}
pql_header($url);
}
}
// }}}
}
// else - PQL_CONF_CONTROL_USE isn't set!
?>
</body>
</html>
<?php
pql_flush();
/*
* Local variables:
* mode: php
* mode: font-lock
* tab-width: 4
* End:
*/
?>