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
|
#!/usr/local/bin/perl
# delete_domain.cgi
# Delete a domain, after asking first
require './virtual-server-lib.pl';
&require_bind() if ($config{'dns'});
&require_useradmin();
&require_mail() if ($config{'mail'});
&ReadParse();
$d = &get_domain($in{'dom'});
$d && $d->{'uid'} && $d->{'gid'} || &error("Domain $in{'dom'} does not exist!");
$access{'edit'} && &can_edit_domain($d) || &error($text{'edit_ecannot'});
&master_admin() || $d->{'parent'} || &error($text{'edit_ecannot'});
if ($in{'confirm'}) {
&ui_print_unbuffered_header(undef, $text{'delete_title'}, "");
}
else {
&ui_print_header(undef, $text{'delete_title'}, "");
}
@users = &list_domain_users($d, 1);
@aliases = &list_domain_aliases($d);
@subs = &get_domain_by("parent", $d->{'id'});
@aliasdoms = &get_domain_by("alias", $d->{'id'});
@aliasdoms = grep { $_->{'parent'} != $d->{'id'} } @aliasdoms;
if (!$in{'confirm'}) {
# Ask the user if he is sure
print &check_clicks_function();
if ($d->{'unix'}) {
$sz = &disk_usage_kb($d->{'home'});
print "<p>",&text('delete_rusure2', "<tt>$d->{'dom'}</tt>",
&nice_size($sz*1024)),"<p>\n";
}
else {
print "<p>",&text('delete_rusure3', "<tt>$d->{'dom'}</tt>"),"<p>\n";
}
$pfx = $d->{'parent'} ? "sublosing_" : "losing_";
print "<ul>\n";
foreach $f (@features) {
if ($d->{$f} && ($config{$f} || $f eq 'unix')) {
print "<li>",$text{'feature_'.$f}," - ",
$text{$pfx.$f},"<br>\n";
}
}
foreach $f (@feature_plugins) {
if ($d->{$f}) {
print "<li>",&plugin_call($f, "feature_name")," - ",
&plugin_call($f, "feature_losing"),"<br>\n";
}
}
if (@users || @aliases) {
print "<li>",&text('delete_mailboxes', scalar(@users), scalar(@aliases)),"<br>\n";
}
print "</ul>\n";
if (@subs) {
print "<p><font size=+1>",&text('delete_subs',
join(", ", map { "<tt>$_->{'dom'}</tt>" } @subs)),
"</font><p>\n";
}
if (@aliasdoms) {
print "<p><font size=+1>",&text('delete_aliasdoms',
join(", ", map { "<tt>$_->{'dom'}</tt>" } @aliasdoms)),
"</font><p>\n";
}
print "<center><form action=delete_domain.cgi>\n";
print "<input type=hidden name=dom value='$in{'dom'}'>\n";
print "<input type=submit name=confirm ",
"value='$text{'delete_ok'}' onClick='check_clicks(form)'>\n";
if ($access{'edit'} == 1) {
print "<p><input type=checkbox name=only value=1> ",
"$text{'delete_only'}<br>\n";
}
print "</form></center>\n";
&ui_print_footer("edit_domain.cgi?dom=$in{'dom'}", $text{'edit_return'},
"", $text{'index_return'});
}
else {
# Go ahead and delete this domain and all sub-domains ..
foreach $dd (@aliasdoms, @subs, $d) {
# Run the before command
&set_domain_envs($dd, "DELETE_DOMAIN");
$merr = &making_changes();
&error(&text('delete_emaking', "<tt>$merr</tt>"))
if (defined($merr));
# Delete domain file
print &text('delete_domain', "<tt>$dd->{'dom'}</tt>"),"<br>\n";
&delete_domain($dd);
print $text{'setup_done'},"<p>\n";
$in{'only'} = 0 if ($access{'edit'} != 1);
if (!$in{'only'}) {
if (@users) {
# Delete mail users and their mail files
print $text{'delete_users'},"<br>\n";
foreach $u (@users) {
&delete_user($u, $dd);
&delete_mail_file($u);
&system_logged("rm -rf '$u->{'home'}'")
if (-d $u->{'home'} &&
$u->{'home'} ne "/");
}
print $text{'setup_done'},"<p>\n";
}
# Delete all virtusers
if (@users || @aliases) {
print $text{'delete_aliases'},"<br>\n";
foreach $v (&list_virtusers()) {
if ($v->{'from'} =~ /\@(\S+)$/ &&
$1 eq $dd->{'dom'}) {
&delete_virtuser($v);
}
}
print $text{'setup_done'},"<p>\n";
}
# Take down IP
if ($dd->{'iface'}) {
&delete_virt($dd);
}
}
# Delete all features (or just 'webmin' if un-importing). Any
# failures are ignored!
my $f;
if (!$in{'only'}) {
# Delete all plugins
foreach $f (@feature_plugins) {
if ($dd->{$f}) {
local $main::error_must_die = 1;
eval { &plugin_call($f,
"feature_delete",$dd) };
if ($@) {
&$second_print(
&text('delete_failure',
&plugin_call($f,
"feature_name"), $@));
}
}
}
}
foreach $f ($in{'only'} ? ( "webmin" ) : reverse(@features)) {
if ($config{$f} && $dd->{$f} || $f eq 'unix') {
local $dfunc = "delete_$f";
local $main::error_must_die = 1;
eval { &$dfunc($dd) };
if ($@) {
&$second_print(&text('delete_failure',
$text{'feature_'.$f}, $@));
$dom->{$f} = 0;
}
}
}
# Update the parent domain Webmin user, so that his ACL
# is refreshed
if ($dd->{'parent'} && $dd->{'parent'} != $d->{'id'}) {
$parentdom = &get_domain($d->{'parent'});
&modify_webmin($parentdom, $parentdom);
}
}
# Run the after command
&run_post_actions();
&made_changes();
&webmin_log("delete", "domain", $d->{'dom'}, $d);
&ui_print_footer("", $text{'index_return'});
}
|