-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeletedomain.php
More file actions
152 lines (132 loc) · 4.55 KB
/
deletedomain.php
File metadata and controls
152 lines (132 loc) · 4.55 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
<?php
if (!defined('WC_BASE')) define('WC_BASE', __DIR__);
$ref=WC_BASE."/index.php";
if ($ref!=$_SERVER['SCRIPT_FILENAME']){
header("Location: index.php");
exit();
}
?>
<!-- #################### deletedomain.php start #################### -->
<tr>
<td width="10"> </td>
<td valign="top">
<?php
if ($authorized) {
$query = "SELECT * FROM accountuser WHERE domain_name='".$_GET['domain']."' ORDER BY username";
$result1 = $handle->query($query);
$cnt1 = $result1->numRows();
if (empty($_GET['confirmed'])) {
?>
<h3>
<?php print _("Delete a Domain from the System");?>
</h3>
<h3>
<?php print _("Do you really want to delete the Domain");?>
<span style="color: red;">
<?php echo $_GET['domain'];?>
</span>
<?php
print _("with all its defined accounts, admins, and emailadresses");
?>
?
</h3>
<p>
<?php print _("This can take a while depending on how many account have to be deleted");?>
</p>
<p style="color: red;">
<?php print _("Your action will delete");?>
<span style="font-weight: bolder;">
<?php echo $cnt1;?>
</span>
<?php print _("accounts");?>
</p>
<form action="index.php" method="get">
<input type="hidden" name="action" value="deletedomain">
<input type="hidden" name="confirmed" value="true">
<input type="hidden" name="domain" value="<?php print $_GET['domain']; ?>">
<input class="button"
type="submit" name="confirmed"
value="<?php print _("Yes, delete");?>">
<input class="button"
type="submit" name="cancel"
value="<?php print _("Cancel");?>">
</form>
<?php
} elseif (!empty($_GET['confirmed']) && !empty($_GET['cancel'])) {
?>
<h3>
<?php print _("Action cancelled, nothing deleted");?>
</h3>
<?php
include WC_BASE . "/browse.php";
} elseif (!empty($_GET['confirmed']) && empty($_GET['cancel'])) {
$cyr_conn = new cyradm;
$cyr_conn->imap_login();
# First Delete all stuff related to the domain from the database
$query = "DELETE FROM `virtual` WHERE alias LIKE '%@".$_GET['domain']."'";
$result = $handle->query($query);
$query = "DELETE FROM accountuser WHERE domain_name='".$_GET['domain']."'";
$result = $handle->query($query);
$query = "DELETE FROM domain WHERE domain_name='".$_GET['domain']."'";
$result = $handle->query($query);
for ($i=0; $i<$cnt1; $i++) {
$row = $result1->fetchRow(DB_FETCHMODE_ASSOC, $i);
$username = $row['username'];
$query = "DELETE FROM `virtual` WHERE username='".$username."'";
$result = $handle->query($query);
# Removing forwards
$query = "DELETE FROM `virtual` WHERE alias='".$username."'";
$result = $handle->query($query);
# And also delete the Usermailboxes from the cyrus system
if ($DOMAIN_AS_PREFIX){
print $cyr_conn->deletemb("user/".$username);
} else {
print $cyr_conn->deletemb("user.".$username);
}
}
# Finally the domain must be removed from the domainadmin table
$query = "SELECT * FROM domainadmin WHERE domain_name='".$_GET['domain']."'";
$result = $handle->query($query);
$cnt = $result->numRows();
for ($i=0; $i < $cnt; $i++) {
# After getting the resulttable we search for the adminuser
# in each row
$row = $result->fetchRow(DB_FETCHMODE_ASSOC,$i);
$username = $row['adminuser'];
$query = "SELECT * FROM domainadmin where adminuser='".$username."'";
$result2 = $handle->query($query);
$cnt2 = $result1->numRows();
# If the adminuser is only the admin for the domain to be
# deleted, then this adminuser also needs to be deleted
if ($cnt2 == 1){
$query = "DELETE FROM adminuser where username='".$username."'";
$result = $handle->query($query);
}
}
# Finally delete every entry with the domain to be deleted
$query = "DELETE FROM domainadmin where domain_name='".$_GET['domain']."'";
$result = $handle->query($query);
?>
<h3>
<?php print _("Domain");?>
<span style="color: red;">
<?php echo $_GET['domain']; ?>
</span>
<?php print _("successfully deleted");?>
</h3>
<?php
unset($_GET['domain']);
include WC_BASE . "/browse.php";
} // End If (empty($_GET['confirmed']))
} else {
?>
<h3>
<?php print $err_msg;?>
</h3>
<a href="index.php?action=browse"><?php print _("Back");?></a>
<?php
}
?>
</td>
</tr>
<!-- #################### deletedomain.php start #################### -->