HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2019-03-07 35727b04e330b323ace37d8a6de9d9b264dd7e96
IPv6 changes
1 files added
14 files modified
154 ■■■■ changed files
hsarback/src/de/hsadmin/core/util/IPv6Trick.java 60 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java 6 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/apache-vhost.vm 4 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/zonefile.vm 8 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/Hive.java 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/INetAddress.java 10 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java 4 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java 36 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/hosts.vm 8 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/httpd-virtual.vm 4 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/pac-addr-ipv4.vm 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/pac-addr-ipv6.vm 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/proftpd-pacs-conf.vm 2 ●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/remote/PacRemote.java 4 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/core/util/IPv6Trick.java
New file
@@ -0,0 +1,60 @@
package de.hsadmin.core.util;
import java.net.InetAddress;
import java.net.UnknownHostException;
import de.hsadmin.core.qserv.ProcessorException;
public class IPv6Trick {
    private static final String IPv4_83_223_79 = "83.223.79";     // Alboin-Kontor Berlin
    private static final String IPv4_83_223_91 = "83.223.91";     // Alboin-Kontor Berlin
    private static final String IPv4_83_223_95 = "83.223.95";     // Alboin-Kontor Berlin
    private static final String IPv6_PREFIX_AK = "2a01:37:1000::1";
    private static final String IPv4_83_223_78 = "83.223.78";     // e-Shelter Berlin
    private static final String IPv4_83_223_94 = "83.223.94";     // e-Shelter Berlin
    private static final String IPv6_PREFIX_ES = "2a01:37:2000::1";
    public static String convertIPv4ToIPv6(final String ipv4address) throws ProcessorException {
        if (ipv4address == null || ipv4address.length() == 0) {
            throw new ProcessorException("no IPv4 address given");
        }
         try {
             final InetAddress inetV4Address = InetAddress.getByName(ipv4address);
            if (ipv4address.startsWith(IPv4_83_223_79)             // Alboin-Kontor Berlin
                    || ipv4address.startsWith(IPv4_83_223_91)
                    || ipv4address.startsWith(IPv4_83_223_95) ) {
                return embedIPv4Address(inetV4Address, InetAddress.getByName(IPv6_PREFIX_AK));
            }
            if (ipv4address.startsWith(IPv4_83_223_78)             // e-Shelter Berlin
                    || ipv4address.startsWith(IPv4_83_223_94) ) {
                return embedIPv4Address(inetV4Address, InetAddress.getByName(IPv6_PREFIX_ES));
            }
        } catch (UnknownHostException e) {
            throw new ProcessorException(e);
        }
        throw new ProcessorException("unknown IPv4 address given");
    }
    private static String embedIPv4Address(final InetAddress ipv4address, final InetAddress ipv6Mask) throws UnknownHostException {
        final byte[] ipv4Bytes = ipv4address.getAddress();
        final byte[] ipv6Bytes = ipv6Mask.getAddress();
        ipv6Bytes[10] = ipv4Bytes[0];
        ipv6Bytes[11] = ipv4Bytes[1];
        ipv6Bytes[12] = ipv4Bytes[2];
        ipv6Bytes[13] = ipv4Bytes[3];
        ipv6Bytes[14] = 0;
        ipv6Bytes[15] = 0;
        final InetAddress ipv6Address = InetAddress.getByAddress(ipv6Bytes);
        final String ipv6String = ipv6Address.getHostAddress();
        if (ipv6String.startsWith("/")) {
            return ipv6String.substring(1);
        } else {
            return ipv6String;
        }
    }
}
hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -129,7 +129,7 @@
    }
    private Processor createMailinSetupProcessor(EntityManager em, Domain dom, Pac pac) throws ProcessorException {
        final String inetAddr = pac.getCurINetAddr().getInetAddr();
        final String inet4Addr = pac.getCurINetAddr().getInet4Addr();
        final CompoundProcessor cp = new CompoundProcessor(
            createPostgreyConfiguration(em),
            new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains || true", 
@@ -150,8 +150,8 @@
            }
            cp.appendProcessor(
                    new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport || true", 
                            dom.getName() + " smtp:" + inetAddr + ":225\n" +
                            "." + dom.getName() + " smtp:" + inetAddr + ":225\n")
                            dom.getName() + " smtp:" + inet4Addr + ":225\n" +
                            "." + dom.getName() + " smtp:" + inet4Addr + ":225\n")
                    );        
        } else {
            cp.appendProcessor(
hsarback/src/de/hsadmin/mods/dom/apache-vhost.vm
@@ -3,7 +3,7 @@
# Do not edit manually. Changes will be overwritten.
#
<VirtualHost ${pac.curINetAddr.inetAddr}:80 ${pac.oldINetAddr.inetAddr}:80 ${pac.curINet6Addr.inetAddr}:80 ${pac.oldINet6Addr.inetAddr}:80>
<VirtualHost ${pac.curINetAddr.inet4Addr}:80 ${pac.oldINetAddr.inet4Addr}:80 ${pac.curINetAddr.inet6Addr}:80 ${pac.oldINetAddr.inet6Addr}:80>
    ServerName ${dom.name}
    ServerAlias ${dom.serveraliases}
    ServerAdmin webmaster@${dom.name}
@@ -76,7 +76,7 @@
    Action application/x-httpd-php /fastcgi-bin/phpstub
</VirtualHost>
<VirtualHost ${pac.curINetAddr.inetAddr}:443 ${pac.oldINetAddr.inetAddr}:443 ${pac.curINet6Addr.inetAddr}:443 ${pac.oldINet6Addr.inetAddr}:443>
<VirtualHost ${pac.curINetAddr.inet4Addr}:443 ${pac.oldINetAddr.inet4Addr}:443 ${pac.curINetAddr.inet6Addr}:443 ${pac.oldINetAddr.inet6Addr}:443>
    ServerName ${dom.name}
    ServerAlias ${dom.serveraliases}
    ServerAdmin webmaster@${dom.name}
hsarback/src/de/hsadmin/mods/dom/named-hsh-conf.vm
@@ -4,5 +4,5 @@
//
#foreach( $domain in ${domains} )
zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetAddr.inetAddr}; }; };
zone "${domain.name}" { type slave; file "sec.${domain.name}"; masters { ${domain.user.pac.hive.inetAddr.inet4Addr}; }; };
#end
hsarback/src/de/hsadmin/mods/dom/zonefile.vm
@@ -15,12 +15,12 @@
${dom.name}.      IN    MX  30 mailin2.hostsharing.net.
${dom.name}.      IN    MX  30 mailin3.hostsharing.net.
${dom.name}.      IN    A ${pac.curINetAddr.inetAddr}
;${dom.name}.      IN    AAAA ${pac.curINet6Addr.inetAddr}
${dom.name}.      IN    A ${pac.curINetAddr.inet4Addr}
;${dom.name}.      IN    AAAA ${pac.curINetAddr.inet6Addr}
*.${dom.name}.    IN    MX  30 mailin1.hostsharing.net.
*.${dom.name}.    IN    MX  30 mailin2.hostsharing.net.
*.${dom.name}.    IN    MX  30 mailin3.hostsharing.net.
*.${dom.name}.    IN    A    ${pac.curINetAddr.inetAddr}
;*.${dom.name}.    IN    AAAA ${pac.curINet6Addr.inetAddr}
*.${dom.name}.    IN    A    ${pac.curINetAddr.inet4Addr}
;*.${dom.name}.    IN    AAAA ${pac.curINetAddr.inet6Addr}
hsarback/src/de/hsadmin/mods/pac/Hive.java
@@ -145,7 +145,7 @@
    }
    
    public String getDefaultGateway() {
        String hiveIP = getInetAddr().getInetAddr();
        String hiveIP = getInetAddr().getInet4Addr();
        return Config.getInstance().getProperty("hsadmin.default_gateway", hiveIP.substring(0, hiveIP.lastIndexOf('.')) + ".1");
    }
}
hsarback/src/de/hsadmin/mods/pac/INetAddress.java
@@ -13,6 +13,8 @@
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.qserv.ProcessorException;
import de.hsadmin.core.util.IPv6Trick;
import de.hsadmin.mods.user.UnixUser;
@Entity(name = "INetAddresses")
@@ -51,7 +53,7 @@
    @Override
    public String createStringKey() {
        return getInetAddr();
        return getInet4Addr();
    }
    @Override
@@ -67,10 +69,14 @@
        this.id = id;
    }
    public String getInetAddr() {
    public String getInet4Addr() {
        return name;
    }
    public String getInet6Addr() throws ProcessorException {
        return IPv6Trick.convertIPv4ToIPv6(name);
    }
    public void setInetAddr(String inetAddr) {
        this.name = inetAddr;
    }
hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
@@ -49,10 +49,10 @@
        basepac = (BasePac) qBasepac.getSingleResult();
        pac.setBasepac(basepac);
        INetAddress curINetAddr = pac.getCurINetAddr();
        if (curINetAddr == null || curINetAddr.getInetAddr() == null || curINetAddr.getInetAddr().length() == 0) {
        if (curINetAddr == null || curINetAddr.getInet4Addr() == null || curINetAddr.getInet4Addr().length() == 0) {
            throw new HSAdminException("curinetaddr required");
        }
        Query qINetAddr = em.createNativeQuery("SELECT * FROM inet_addr WHERE inet_addr = inet '" + curINetAddr.getInetAddr() + "'", INetAddress.class);
        Query qINetAddr = em.createNativeQuery("SELECT * FROM inet_addr WHERE inet_addr = inet '" + curINetAddr.getInet4Addr() + "'", INetAddress.class);
        curINetAddr = (INetAddress) qINetAddr.getSingleResult();
        pac.setCurINetAddr(curINetAddr);
        Customer customer = pac.getCustomer();
hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java
@@ -175,30 +175,30 @@
                );
    }
    private Processor createIfUp(final Pac pac) {
        return new CompoundProcessor(new ShellProcessor("ip addr add "
                + pac.getCurINetAddr().getInetAddr()
    private Processor createIfUp(final Pac pac) throws ProcessorException {
        return new CompoundProcessor(
            new ShellProcessor("ip addr add "
                + pac.getCurINetAddr().getInet4Addr()
                + "/32 dev eth0"
                + pac.getName()
            ),
        new ShellProcessor("ip addr add "
        + pac.getCurINet6Addr().getInetAddr()
        + "/128 dev eth0 noprefixroute preferred_lft 0"
        + pac.getName()
      ));
            new ShellProcessor("ip addr add "
                + pac.getCurINetAddr().getInet6Addr()
                + "/128 dev eth0 noprefixroute preferred_lft 0"
            )
        );
    }
    private Processor createIfDown(final Pac pac) {
        return new CompoundProcessor(new ShellProcessor("ip addr del "
                + pac.getCurINetAddr().getInetAddr()
    private Processor createIfDown(final Pac pac) throws ProcessorException {
        return new CompoundProcessor(
            new ShellProcessor("ip addr del "
                + pac.getCurINetAddr().getInet4Addr()
                + "/32 dev eth0"
                + pac.getName()
            ),
        new ShellProcessor("ip addr add "
        + pac.getCurINet6Addr().getInetAddr()
        + "/128 dev eth0 noprefixroute preferred_lft 0"
        + pac.getName()
      ));
            new ShellProcessor("ip addr del "
                + pac.getCurINetAddr().getInet6Addr()
                + "/128 dev eth0 noprefixroute preferred_lft 0"
            )
        );
    }
    private UnixUser getPacAdminUser(Pac pac) throws ProcessorException {
hsarback/src/de/hsadmin/mods/pac/hosts.vm
@@ -11,10 +11,10 @@
ff02::2                         ip6-allrouters
ff02::3                         ip6-allhosts
${hive.inetAddr.inetAddr} ${hive.name}.hostsharing.net ${hive.name} localhive
${hive.inet6Addr.inetAddr} ${hive.name}.hostsharing.net ${hive.name} localhive
${hive.inetAddr.inet4Addr} ${hive.name}.hostsharing.net ${hive.name} localhive
${hive.inetAddr.inet6Addr} ${hive.name}.hostsharing.net ${hive.name} localhive
#foreach( $pac in ${hive.webpacs} )
${pac.curINetAddr.inetAddr} ${pac.name}.hostsharing.net ${pac.name}
${pac.curINet6Addr.inetAddr} ${pac.name}.hostsharing.net ${pac.name}
${pac.curINetAddr.inet4Addr} ${pac.name}.hostsharing.net ${pac.name}
${pac.curINetAddr.inet6Addr} ${pac.name}.hostsharing.net ${pac.name}
#end
hsarback/src/de/hsadmin/mods/pac/httpd-virtual.vm
@@ -4,7 +4,7 @@
#
#foreach( $pac in ${hive.webpacs} )
<VirtualHost ${pac.curINetAddr.inetAddr}:80 ${pac.curINet6Addr.inetAddr}:80>
<VirtualHost ${pac.curINetAddr.inet4Addr}:80 ${pac.curINetAddr.inet6Addr}:80>
    ServerName _
    ServerAdmin webmaster@${pac.name}.hostsharing.net
@@ -15,7 +15,7 @@
</VirtualHost>
<VirtualHost ${pac.curINetAddr.inetAddr}:443 ${pac.curINet6Addr.inetAddr}:443>
<VirtualHost ${pac.curINetAddr.inet4Addr}:443 ${pac.curINetAddr.inet6Addr}:443>
    ServerName _
    ServerAdmin webmaster@${pac.name}.hostsharing.net
hsarback/src/de/hsadmin/mods/pac/pac-addr-ipv4.vm
@@ -4,5 +4,5 @@
#
#
#foreach( $pac in ${hive.webpacs} )
eth0:${pac.name}:${pac.curINetAddr.inetAddr}/32
eth0:${pac.name}:${pac.curINetAddr.inet4Addr}/32
#end
hsarback/src/de/hsadmin/mods/pac/pac-addr-ipv6.vm
@@ -4,5 +4,5 @@
#
#
#foreach( $pac in ${hive.webpacs} )
eth0:${pac.name}:${pac.curINet6Addr.inetAddr}/128
eth0:${pac.name}:${pac.curINetAddr.inet6Addr}/128
#end
hsarback/src/de/hsadmin/mods/pac/proftpd-pacs-conf.vm
@@ -4,7 +4,7 @@
#
#foreach( $pac in ${hive.webpacs} )
<VirtualHost ${pac.curINetAddr.inetAddr} ${pac.curINet6Addr.inetAddr}>
<VirtualHost ${pac.curINetAddr.inet4Addr} ${pac.curINetAddr.inet6Addr}>
        DefaultRoot             ~ ${pac.name}
        ServerName              "${pac.name}.hostsharing.net"
        AllowOverwrite          on
hsarback/src/de/hsadmin/remote/PacRemote.java
@@ -25,7 +25,7 @@
        resultMap.put("id", Long.toString(pac.getId()));
        resultMap.put("hive", pac.getHiveName());
        resultMap.put("customer", pac.getCustomer().getName());
        resultMap.put("curinetaddr", pac.getCurINetAddr().getInetAddr());
        resultMap.put("curinetaddr", pac.getCurINetAddr().getInet4Addr());
        resultMap.put("created", TextUtil.format(pac.getCreated()));
        resultMap.put("free", TextUtil.format(pac.isFree()));
        Date cancelled = pac.getCancelled();
@@ -76,7 +76,7 @@
        }
        INetAddress curINetAddr = pac.getCurINetAddr();
        String inetAddrString = (String) setParams.get("curinetaddr");
        if ((curINetAddr == null || curINetAddr.getInetAddr() == null) && assertNotNull(inetAddrString)) {
        if ((curINetAddr == null || curINetAddr.getInet4Addr() == null) && assertNotNull(inetAddrString)) {
            curINetAddr = new INetAddress(inetAddrString);
            pac.setCurINetAddr(curINetAddr);
        }