-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
delete-domain.pl
executable file
·118 lines (104 loc) · 3.1 KB
/
delete-domain.pl
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
#!/usr/local/bin/perl
=head1 delete-domain.pl
Delete one or more virtual servers.
To delete one or many servers (and all of their sub-servers and alias domains)
from the system, use this program. The domains to remove can be specified with
the C<--domain> flag, which can be given multiple times. Alternately, you can
select virtual servers by username, using the C<--user> flag.
The C<--only> option can be used to not actually delete the servers, but
instead simply remove them from the control of Virtualmin. Similarly, the
C<--preserve-remote> flag tells Virtualmin to not delete any databases,
home directories or users stored on remote systems. This can be useful when
removing a domain that is replicated across multiple hosts with shared
storage.
Be careful with this program, as unlike the server deletion function in the
Virtualmin web interface, it will NOT prompt for confirmation!
=cut
package virtual_server;
if (!$module_name) {
$main::no_acl_check++;
$ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin";
$ENV{'WEBMIN_VAR'} ||= "/var/webmin";
if ($0 =~ /^(.*)\/[^\/]+$/) {
chdir($pwd = $1);
}
else {
chop($pwd = `pwd`);
}
$0 = "$pwd/delete-domain.pl";
require './virtual-server-lib.pl';
$< == 0 || die "delete-domain.pl must be run as root";
}
&licence_status();
@OLDARGV = @ARGV;
&set_all_text_print();
# Parse command-line args
while(@ARGV > 0) {
local $a = shift(@ARGV);
if ($a eq "--domain") {
push(@domains, shift(@ARGV));
}
elsif ($a eq "--user") {
push(@users, shift(@ARGV));
}
elsif ($a eq "--only") {
$only = 1;
}
elsif ($a eq "--preserve-remote") {
$preserve = 1;
}
elsif ($a eq "--pre-command") {
$precommand = shift(@ARGV);
}
elsif ($a eq "--post-command") {
$postcommand = shift(@ARGV);
}
elsif ($a eq "--multiline") {
$multiline = 1;
}
elsif ($a eq "--help") {
&usage();
}
else {
&usage("Unknown parameter $a");
}
}
# Find the domains, minus any sub-domains of already selected parents
@domains || @users || usage("No users or domains specified");
@doms = &get_domains_by_names_users(\@domains, \@users, \&usage);
foreach $d (@doms) {
$idmap{$d->{'id'}} = $d;
}
@doms = grep { !$_->{'parent'} || !$idmap{$_->{'parent'}} } @doms;
@doms = sort { $b->{'dns_subof'} <=> $a->{'dns_subof'} } @doms;
# Kill them
$config{'pre_command'} = $precommand if ($precommand);
$config{'post_command'} = $postcommand if ($postcommand);
foreach $d (@doms) {
print "Deleting virtual server $d->{'dom'} ..\n";
if ($d->{'protected'}) {
print ".. skip : protected domain\n\n";
next;
}
&$indent_print();
$err = &delete_virtual_server($d, $only, 0, $preserve);
&$outdent_print();
if ($err) {
print "$err\n";
exit 1;
}
print ".. deleted\n\n";
}
&virtualmin_api_log(\@OLDARGV, $doms[0]);
sub usage
{
print $_[0],"\n\n" if ($_[0]);
print "Deletes an existing Virtualmin virtual server and all sub-servers,\n";
print "mailboxes and alias domains.\n";
print "\n";
print "virtualmin delete-domain [--domain domain.name]*\n";
print " [--user username]*\n";
print " [--only]\n";
print " [--preserve-remote]\n";
exit(1);
}