Search in sources :

Example 1 with FirewallOpenPortConfigIP

use of org.eclipse.kura.net.firewall.FirewallOpenPortConfigIP in project kura by eclipse.

the class GwtNetworkServiceImpl method updateDeviceFirewallOpenPorts.

@Override
public void updateDeviceFirewallOpenPorts(GwtXSRFToken xsrfToken, List<GwtFirewallOpenPortEntry> entries) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
    List<FirewallOpenPortConfigIP<? extends IPAddress>> firewallOpenPortConfigIPs = new ArrayList<FirewallOpenPortConfigIP<? extends IPAddress>>();
    s_logger.debug("updating open ports");
    try {
        for (GwtFirewallOpenPortEntry entry : entries) {
            String network = null;
            String prefix = null;
            if (entry.getPermittedNetwork() != null) {
                String[] parts = entry.getPermittedNetwork().split("/");
                network = parts[0];
                prefix = parts[1];
            }
            FirewallOpenPortConfigIP<IP4Address> firewallOpenPortConfigIP = new FirewallOpenPortConfigIP4();
            if (entry.getPortRange() != null) {
                if (entry.getPortRange().indexOf(':') > 0) {
                    firewallOpenPortConfigIP.setPortRange(entry.getPortRange());
                } else {
                    firewallOpenPortConfigIP.setPort(Integer.parseInt(entry.getPortRange()));
                }
            }
            firewallOpenPortConfigIP.setProtocol(NetProtocol.valueOf(GwtSafeHtmlUtils.htmlEscape(entry.getProtocol())));
            if (network != null && prefix != null) {
                firewallOpenPortConfigIP.setPermittedNetwork(new NetworkPair<IP4Address>((IP4Address) IPAddress.parseHostAddress(network), Short.parseShort(prefix)));
            }
            firewallOpenPortConfigIP.setPermittedInterfaceName(GwtSafeHtmlUtils.htmlEscape(entry.getPermittedInterfaceName()));
            firewallOpenPortConfigIP.setUnpermittedInterfaceName(GwtSafeHtmlUtils.htmlEscape(entry.getUnpermittedInterfaceName()));
            firewallOpenPortConfigIP.setPermittedMac(GwtSafeHtmlUtils.htmlEscape(entry.getPermittedMAC()));
            firewallOpenPortConfigIP.setSourcePortRange(GwtSafeHtmlUtils.htmlEscape(entry.getSourcePortRange()));
            s_logger.debug("adding open port entry for {}", entry.getPortRange());
            firewallOpenPortConfigIPs.add(firewallOpenPortConfigIP);
        }
        nas.setFirewallOpenPortConfiguration(firewallOpenPortConfigIPs);
    } catch (KuraException e) {
        s_logger.warn("Exception while updating firewall open ports", e);
        throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
    } catch (NumberFormatException e) {
        s_logger.warn("Exception while updating firewall open ports", e);
        throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
    } catch (UnknownHostException e) {
        s_logger.warn("Exception while updating firewall open ports", e);
        throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : GwtFirewallOpenPortEntry(org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) UnknownHostException(java.net.UnknownHostException) IP4Address(org.eclipse.kura.net.IP4Address) ArrayList(java.util.ArrayList) FirewallOpenPortConfigIP(org.eclipse.kura.net.firewall.FirewallOpenPortConfigIP) KuraException(org.eclipse.kura.KuraException) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) NetworkAdminService(org.eclipse.kura.net.NetworkAdminService) FirewallOpenPortConfigIP4(org.eclipse.kura.net.firewall.FirewallOpenPortConfigIP4) IPAddress(org.eclipse.kura.net.IPAddress)

Aggregations

UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 KuraException (org.eclipse.kura.KuraException)1 IP4Address (org.eclipse.kura.net.IP4Address)1 IPAddress (org.eclipse.kura.net.IPAddress)1 NetworkAdminService (org.eclipse.kura.net.NetworkAdminService)1 FirewallOpenPortConfigIP (org.eclipse.kura.net.firewall.FirewallOpenPortConfigIP)1 FirewallOpenPortConfigIP4 (org.eclipse.kura.net.firewall.FirewallOpenPortConfigIP4)1 GwtKuraException (org.eclipse.kura.web.shared.GwtKuraException)1 GwtFirewallOpenPortEntry (org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry)1