/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.PortRanges
 *  com.l7tech.gateway.common.transport.ResolutionConfiguration
 *  com.l7tech.gateway.common.transport.SsgActiveConnector
 *  com.l7tech.gateway.common.transport.SsgConnector
 *  com.l7tech.gateway.common.transport.TransportAdmin
 *  com.l7tech.gateway.common.transport.TransportAdmin$CurrentAdminConnectionException
 *  com.l7tech.gateway.common.transport.TransportDescriptor
 *  com.l7tech.gateway.common.transport.firewall.SsgFirewallRule
 *  com.l7tech.message.Message
 *  com.l7tech.objectmodel.DeleteException
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.objectmodel.SaveException
 *  com.l7tech.objectmodel.UpdateException
 *  com.l7tech.util.Config
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.InetAddressUtil
 */
package com.l7tech.server.transport;

import com.l7tech.common.io.PortRanges;
import com.l7tech.gateway.common.transport.ResolutionConfiguration;
import com.l7tech.gateway.common.transport.SsgActiveConnector;
import com.l7tech.gateway.common.transport.SsgConnector;
import com.l7tech.gateway.common.transport.TransportAdmin;
import com.l7tech.gateway.common.transport.TransportDescriptor;
import com.l7tech.gateway.common.transport.firewall.SsgFirewallRule;
import com.l7tech.message.Message;
import com.l7tech.objectmodel.DeleteException;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.server.DefaultKey;
import com.l7tech.server.tomcat.SsgHttpConstants;
import com.l7tech.server.transport.ResolutionConfigurationManager;
import com.l7tech.server.transport.SsgActiveConnectorManager;
import com.l7tech.server.transport.SsgConnectorManager;
import com.l7tech.server.transport.TransportAdminHelper;
import com.l7tech.server.transport.firewall.SsgFirewallRuleManager;
import com.l7tech.util.Config;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.InetAddressUtil;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;

public class TransportAdminImpl
implements TransportAdmin {
    private final SsgActiveConnectorManager a;
    private final SsgConnectorManager b;
    private final ResolutionConfigurationManager c;
    private final Config d;
    private final SsgFirewallRuleManager e;
    private final TransportAdminHelper f;
    private static final String[] g;

    public TransportAdminImpl(SsgActiveConnectorManager ssgActiveConnectorManager, SsgConnectorManager ssgConnectorManager, SsgFirewallRuleManager ssgFirewallRuleManager, ResolutionConfigurationManager resolutionConfigurationManager, DefaultKey defaultKey, Config config) {
        this.a = ssgActiveConnectorManager;
        this.b = ssgConnectorManager;
        this.c = resolutionConfigurationManager;
        this.d = config;
        this.e = ssgFirewallRuleManager;
        this.f = new TransportAdminHelper(defaultKey);
    }

    public Collection<SsgConnector> findAllSsgConnectors() throws FindException {
        return this.b.findAll();
    }

    public SsgConnector findSsgConnectorByPrimaryKey(Goid goid) throws FindException {
        return (SsgConnector)this.b.findByPrimaryKey(goid);
    }

    private boolean a(Goid goid) {
        Goid goid2 = SsgHttpConstants.getCurrentThreadSsgConnectorGoid();
        return goid.equals((Object)goid2);
    }

    public Goid saveSsgConnector(SsgConnector ssgConnector) throws SaveException, UpdateException, TransportAdmin.CurrentAdminConnectionException {
        try {
            if (this.a(ssgConnector.getGoid())) {
                throw new TransportAdmin.CurrentAdminConnectionException(g[3]);
            }
        }
        catch (SaveException saveException) {
            throw TransportAdminImpl.a((Exception)((Object)saveException));
        }
        try {
            if (ssgConnector.getGoid().equals((Object)SsgConnector.DEFAULT_GOID)) {
                return this.b.save((PersistentEntity)ssgConnector);
            }
        }
        catch (SaveException saveException) {
            throw TransportAdminImpl.a((Exception)((Object)saveException));
        }
        this.b.update((PersistentEntity)ssgConnector);
        return ssgConnector.getGoid();
    }

    public void deleteSsgConnector(Goid goid) throws DeleteException, FindException, TransportAdmin.CurrentAdminConnectionException {
        try {
            if (this.a(goid)) {
                throw new TransportAdmin.CurrentAdminConnectionException(g[1]);
            }
        }
        catch (DeleteException deleteException) {
            throw TransportAdminImpl.a((Exception)((Object)deleteException));
        }
        this.b.delete(goid);
    }

    public SsgActiveConnector findSsgActiveConnectorByPrimaryKey(Goid goid) throws FindException {
        return (SsgActiveConnector)this.a.findByPrimaryKey(goid);
    }

    public SsgActiveConnector findSsgActiveConnectorByTypeAndName(String string, String string2) throws FindException {
        block7: {
            try {
                try {
                    if (string != null && string2 != null) break block7;
                }
                catch (FindException findException) {
                    throw TransportAdminImpl.a((Exception)((Object)findException));
                }
                return null;
            }
            catch (FindException findException) {
                throw TransportAdminImpl.a((Exception)((Object)findException));
            }
        }
        Collection<SsgActiveConnector> collection = this.findSsgActiveConnectorsByType(string);
        for (SsgActiveConnector ssgActiveConnector : collection) {
            try {
                if (!string2.equals(ssgActiveConnector.getName())) continue;
                return ssgActiveConnector;
            }
            catch (FindException findException) {
                throw TransportAdminImpl.a((Exception)((Object)findException));
            }
        }
        return null;
    }

    public Collection<SsgActiveConnector> findSsgActiveConnectorsByType(String string) throws FindException {
        return this.a.findSsgActiveConnectorsByType(string);
    }

    public Goid saveSsgActiveConnector(SsgActiveConnector ssgActiveConnector) throws SaveException, UpdateException {
        try {
            if (ssgActiveConnector.getGoid().equals((Object)SsgActiveConnector.DEFAULT_GOID)) {
                return this.a.save((PersistentEntity)ssgActiveConnector);
            }
        }
        catch (SaveException saveException) {
            throw TransportAdminImpl.a((Exception)((Object)saveException));
        }
        this.a.update((PersistentEntity)ssgActiveConnector);
        return ssgActiveConnector.getGoid();
    }

    public void deleteSsgActiveConnector(Goid goid) throws DeleteException, FindException {
        this.a.delete(goid);
    }

    public String[] getAllProtocolVersions(boolean bl2) {
        return this.f.getAllProtocolVersions(bl2);
    }

    public String[] getAllCipherSuiteNames() {
        return this.f.getAllCipherSuiteNames();
    }

    @Deprecated
    public String[] getDefaultCipherSuiteNames() {
        return this.f.getDefaultCipherSuiteNames();
    }

    public String[] getDefaultInboundCipherSuiteNames() {
        return this.f.getDefaultInboundCipherSuiteNames();
    }

    public String[] getDefaultOutboundCipherSuiteNames() {
        return this.f.getDefaultOutboundCipherSuiteNames();
    }

    public String[] getVisibleCipherSuiteNames() {
        return this.f.getVisibleCipherSuiteNames();
    }

    public InetAddress[] getAvailableBindAddresses() {
        try {
            ArrayList<InetAddress> arrayList = new ArrayList<InetAddress>();
            Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
            while (enumeration.hasMoreElements()) {
                NetworkInterface networkInterface = enumeration.nextElement();
                Enumeration<InetAddress> enumeration2 = networkInterface.getInetAddresses();
                try {
                    while (enumeration2.hasMoreElements()) {
                        arrayList.add(enumeration2.nextElement());
                    }
                }
                catch (SocketException socketException) {
                    throw TransportAdminImpl.a(socketException);
                }
            }
            return arrayList.toArray(new InetAddress[arrayList.size()]);
        }
        catch (SocketException socketException) {
            throw new RuntimeException(g[2] + ExceptionUtils.getMessage((Throwable)socketException), socketException);
        }
    }

    public TransportDescriptor[] getModularConnectorInfo() {
        return this.b.getTransportProtocols();
    }

    public PortRanges getReservedPorts() {
        return this.b.getReservedPorts();
    }

    public boolean isUseIpv6() {
        return InetAddressUtil.isUseIpv6();
    }

    public ResolutionConfiguration getResolutionConfigurationByName(String string) throws FindException {
        return (ResolutionConfiguration)this.c.findByUniqueName(string);
    }

    public Goid saveResolutionConfiguration(ResolutionConfiguration resolutionConfiguration) throws SaveException {
        Goid goid;
        if (resolutionConfiguration.isUnsaved()) {
            goid = this.c.save((PersistentEntity)resolutionConfiguration);
        } else {
            goid = resolutionConfiguration.getGoid();
            try {
                this.c.update((PersistentEntity)resolutionConfiguration);
            }
            catch (UpdateException updateException) {
                throw new SaveException(ExceptionUtils.getMessage((Throwable)updateException), (Throwable)updateException);
            }
        }
        return goid;
    }

    public long getXmlMaxBytes() {
        return Message.getMaxBytes();
    }

    public boolean isSnmpQueryEnabled() {
        return this.d.getBooleanProperty(g[4], true);
    }

    public Collection<SsgFirewallRule> findAllFirewallRules() throws FindException {
        return this.e.findAll();
    }

    public void deleteFirewallRule(Goid goid) throws DeleteException, FindException, TransportAdmin.CurrentAdminConnectionException {
        this.e.delete(goid);
    }

    public Goid saveFirewallRule(SsgFirewallRule ssgFirewallRule) throws SaveException, UpdateException, TransportAdmin.CurrentAdminConnectionException {
        try {
            if (this.a(ssgFirewallRule.getGoid())) {
                throw new TransportAdmin.CurrentAdminConnectionException(g[0]);
            }
        }
        catch (SaveException saveException) {
            throw TransportAdminImpl.a((Exception)((Object)saveException));
        }
        try {
            if (ssgFirewallRule.getGoid().equals((Object)SsgFirewallRule.DEFAULT_GOID)) {
                return this.e.save((PersistentEntity)ssgFirewallRule);
            }
        }
        catch (SaveException saveException) {
            throw TransportAdminImpl.a((Exception)((Object)saveException));
        }
        this.e.update((PersistentEntity)ssgFirewallRule);
        return ssgFirewallRule.getGoid();
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[5];
                var3_1 = 0;
                var2_2 = "`\r\u0019lL\u0002_A\fXcO\u0003\u0016S\u001aXmO\t\u0011P\u0000\faRG\u0019Z\u0011XmU\u0015\rP\r\f.A\u0003\u0012\\\rXmO\t\u0011P\u0000\fgO\t7`\r\u0019lL\u0002_A\fXjE\u000b\u001aA\u0006XmO\t\u0011P\u0000\faRG\u0019Z\u0011XmU\u0015\rP\r\f.A\u0003\u0012\\\rXmO\t\u0011P\u0000\fgO\t\"`\r\u0019lL\u0002_A\fXiE\u0013_[\u0006\fyO\u0015\u0014\u0015\n\u0016zE\u0015\u0019T\u0000\u001d}\u001aG";
                var4_3 = "`\r\u0019lL\u0002_A\fXcO\u0003\u0016S\u001aXmO\t\u0011P\u0000\faRG\u0019Z\u0011XmU\u0015\rP\r\f.A\u0003\u0012\\\rXmO\t\u0011P\u0000\fgO\t7`\r\u0019lL\u0002_A\fXjE\u000b\u001aA\u0006XmO\t\u0011P\u0000\faRG\u0019Z\u0011XmU\u0015\rP\r\f.A\u0003\u0012\\\rXmO\t\u0011P\u0000\fgO\t\"`\r\u0019lL\u0002_A\fXiE\u0013_[\u0006\fyO\u0015\u0014\u0015\n\u0016zE\u0015\u0019T\u0000\u001d}\u001aG".length();
                var1_4 = 55;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 60;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = TransportAdminImpl.a(v0, TransportAdminImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "w\u001a\u000e{[\u0015HV\u001bOtX\u0014\u0001D\rOzX\u001e\u0006G\u0017\u001bvEP\u000eM\u0006OzB\u0002\u001aG\u001a\u001b9V\u0014\u0005K\u001aOzX\u001e\u0006G\u0017\u001bpX\u001e @\u0001\u0006uC\u0019\u0006q\u0011\u001do^\u0013\r\f\u0007\u0001tG!\u001dG\u0006\u00167R\u001e\t@\u0018\n}";
                    var4_3 = "w\u001a\u000e{[\u0015HV\u001bOtX\u0014\u0001D\rOzX\u001e\u0006G\u0017\u001bvEP\u000eM\u0006OzB\u0002\u001aG\u001a\u001b9V\u0014\u0005K\u001aOzX\u001e\u0006G\u0017\u001bpX\u001e @\u0001\u0006uC\u0019\u0006q\u0011\u001do^\u0013\r\f\u0007\u0001tG!\u001dG\u0006\u00167R\u001e\t@\u0018\n}".length();
                    var1_4 = 55;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 43;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = TransportAdminImpl.a(v0, TransportAdminImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        TransportAdminImpl.g = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x43);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 9;
                    case 1 -> 95;
                    case 2 -> 68;
                    case 3 -> 50;
                    case 4 -> 28;
                    case 5 -> 91;
                    default -> 67;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

