Skip to content

Commit 91d51cd

Browse files
committed
Add flags to show IPv6 shared addresses as well
1 parent 8625e77 commit 91d51cd

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

Diff for: list-shared-addresses.pl

+47-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ =head1 list-shared-addresses.pl
1111
and easily parsed list with the C<--multiline> flag. Or to just get a list
1212
of addresses, use the C<--name-only> parameter.
1313
14+
By default only shared IPv4 addresses are shown, but you can use the C<--ipv6>
15+
flag to also include IPv6 addresses.
16+
1417
=cut
1518

1619
package virtual_server;
@@ -32,24 +35,59 @@ package virtual_server;
3235
# Parse command-line args
3336
$owner = 1;
3437
&parse_common_cli_flags(\@ARGV);
38+
$ipv4 = 1;
39+
$ipv6 = 0;
3540
while(@ARGV > 0) {
3641
local $a = shift(@ARGV);
37-
&usage("Unknown parameter $a");
42+
if ($a eq "--ipv6") {
43+
$ipv6 = 1;
44+
}
45+
elsif ($a eq "--no-ipv6") {
46+
$ipv6 = 0;
47+
}
48+
elsif ($a eq "--ipv4") {
49+
$ipv4 = 1;
50+
}
51+
elsif ($a eq "--no-ipv4") {
52+
$ipv4 = 0;
53+
}
54+
else {
55+
&usage("Unknown parameter $a");
56+
}
3857
}
58+
$ipv4 || $ipv6 || &usage("At least one of IPv4 or IPv6 mode must be enabled");
59+
!$ipv6 || &supports_ip6() || &usage("This system does not support IPv6");
3960

4061
# Get the IPs
41-
push(@ips, { 'ip' => &get_default_ip(), 'type' => 'default' });
62+
if ($ipv4) {
63+
push(@ips, { 'ip' => &get_default_ip(), 'type' => 'default' });
64+
}
65+
if ($ipv4) {
66+
push(@ips, { 'ip' => &get_default_ip6(), 'type' => 'default' });
67+
}
4268
if (defined(&list_resellers)) {
4369
foreach $r (&list_resellers()) {
44-
if ($r->{'acl'}->{'defip'}) {
70+
if ($ipv4 && $r->{'acl'}->{'defip'}) {
4571
push(@ips, { 'ip' => $r->{'acl'}->{'defip'},
4672
'type' => 'reseller',
4773
'reseller' => $r->{'name'} });
4874
}
75+
if ($ipv6 && $r->{'acl'}->{'defip6'}) {
76+
push(@ips, { 'ip' => $r->{'acl'}->{'defip6'},
77+
'type' => 'reseller',
78+
'reseller' => $r->{'name'} });
79+
}
4980
}
5081
}
51-
foreach $ip (&list_shared_ips()) {
52-
push(@ips, { 'ip' => $ip, 'type' => 'shared' });
82+
if ($ipv4) {
83+
foreach $ip (&list_shared_ips()) {
84+
push(@ips, { 'ip' => $ip, 'type' => 'shared' });
85+
}
86+
}
87+
if ($ipv6) {
88+
foreach $ip (&list_shared_ip6s()) {
89+
push(@ips, { 'ip' => $ip, 'type' => 'shared' });
90+
}
5391
}
5492

5593
if ($multiline) {
@@ -60,7 +98,8 @@ package virtual_server;
6098
if ($ip->{'reseller'}) {
6199
print " Reseller: $ip->{'reseller'}\n"
62100
}
63-
@doms = &get_domain_by("ip", $ip->{'ip'});
101+
@doms = (&get_domain_by("ip", $ip->{'ip'}),
102+
&get_domain_by("ip6", $ip->{'ip'}));
64103
foreach $d (@doms) {
65104
print " Virtual server: $d->{'dom'}\n";
66105
}
@@ -94,6 +133,8 @@ sub usage
94133
print "\n";
95134
print "virtualmin list-shared-addresses [--multiline | --json | --xml |\n";
96135
print " --name-only]\n";
136+
print " [--ipv4 | --no-ipv4]\n";
137+
print " [--ipv6 | --no-ipv6]\n";
97138
exit(1);
98139
}
99140

0 commit comments

Comments
 (0)