SPF ip6 enabled Hack

5 posts / 0 new
Last post
#1 Tue, 08/27/2013 - 11:30
jimmy06

SPF ip6 enabled Hack

This hack is to enable Virtualmin to display and edit ipv6 SPF records.

First locate where the webmin install is located then open the file "virtual-server/edit_spf.cgi"

On line 23

# Extra a, mx, ip4
$edspf = $spf || $defspf;
foreach $t ('a', 'mx', 'ip4', 'include') {
print &ui_table_row(&hlink($text{'spf_'.$t}, 'spf_'.$t),
&ui_textarea('extra_'.$t,
     join("\n", @{$edspf->{$t.':'}}), 3, 40));
}

Change to

# Extra a, mx, ip4 and ip6
$edspf = $spf || $defspf;
foreach $t ('a', 'mx', 'ip4', 'ip6', 'include') {
print &ui_table_row(&hlink($text{'spf_'.$t}, 'spf_'.$t),
&ui_textarea('extra_'.$t,
     join("\n", @{$edspf->{$t.':'}}), 3, 40));
}

Close file.

Open "virtual-server/lang/en"

add the line

setup_eip6=Missing or invalid IPv6 address

close the file.

Open "virtual-server/save_spf.cgi"

Find

elsif ($a eq "ip4") {
# Must be a valid IP or IP/cidr or IP/mask
&check_ipaddress($v) ||
  ($v =~ /^([0-9\.]+)\/(\d+)$/ &&
   $2 > 0 && $2 <= 32 &&
   &check_ipaddress("$1")) ||
  ($v =~ /^([0-9\.]+)\/([0-9\.]+)$/ &&
   &check_ipaddress("$1") &&
   &check_ipaddress("$2")) ||
&error(&text('spf_e'.$t, $v));
}

Add after

elsif ($a eq "ip6") {
                                # Must be a valid IP or IP/cidr or IP/mask
#This needs to be completed
                                }

Close file.

Make the file "virtual-server/help/spf_ip6.html" and open it paste

<header>Allowed sender IP addresses</header>

This field is similar to <b>Allowed sender hostnames</b>, but is for entering
IP addresses of systems that also send email from this domain, and do not
have hostnames. <p>

<footer>

Close file

Open "virtual-server/modify-dns.pl"

go to line 80

you should see

elsif ($a =~ /^--spf-add-(a|mx|ip4)$/) {
$add = shift(@ARGV);
$type = $1;
$add =~ /^[a-z0-9\.\-\_]+$/ ||
    &usage("$a must be followed by a hostname or IP address");
push(@{$add{$type}}, $add);
}
elsif ($a =~ /^--spf-remove-(a|mx|ip4)$/) {
$rem = shift(@ARGV);
$type = $1;
$rem =~ /^[a-z0-9\.\-\_]+$/ ||
    &usage("$a must be followed by a hostname or IP address");
push(@{$rem{$type}}, $rem);
}

change this to

elsif ($a =~ /^--spf-add-(a|mx|ip4|ip6)$/) {
$add = shift(@ARGV);
$type = $1;
$add =~ /^[a-z0-9\.\-\_]+$/ ||
    &usage("$a must be followed by a hostname or IP address");
push(@{$add{$type}}, $add);
}
elsif ($a =~ /^--spf-remove-(a|mx|ip4|ip6)$/) {
$rem = shift(@ARGV);
$type = $1;
$rem =~ /^[a-z0-9\.\-\_]+$/ ||
    &usage("$a must be followed by a hostname or IP address");
push(@{$rem{$type}}, $rem);
}

I think that's all I changed.

Now when you look at the DNS Options you should see a section for IPv6 address's.

Also you can now use modify-dns.pl to add ip6 SPF records.

Example

virtual-server/modify-dns.pl --all-domains --spf-add-ip6 2a90:490:190:4fff::ffff
Tue, 08/27/2013 - 12:36
JamieCameron

Thanks for this patch / suggestion. I will incorporate and equivalent change into the next Virtualmin release.

''

Tue, 08/27/2013 - 17:37 (Reply to #2)
jimmy06

Cool. Like I wrote in one of the comments and meant to mention. This does not check the ipv6 address is in a real address so no error checking. but you know what to fix for that better then me :)

I only wrote this due to Google stepping up there anti spam on ipv6 recently and mail was not SPF passing :(

Tue, 08/27/2013 - 18:10 (Reply to #3)
JamieCameron

Yes, I added a check to ensure that the IPv6 address is in the correct format.

''

Wed, 08/28/2013 - 19:25 (Reply to #4)
jimmy06

I look forward to seeing this soon ish LOL

Topic locked