Search in sources :

Example 1 with FirewallPortForwardConfigIP

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

the class GwtNetworkServiceImpl method updateDeviceFirewallPortForwards.

@Override
public void updateDeviceFirewallPortForwards(GwtXSRFToken xsrfToken, List<GwtFirewallPortForwardEntry> entries) throws GwtKuraException {
    s_logger.debug("updateDeviceFirewallPortForwards() :: updating port forward entries");
    checkXSRFToken(xsrfToken);
    NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
    List<FirewallPortForwardConfigIP<? extends IPAddress>> firewallPortForwardConfigIPs = new ArrayList<FirewallPortForwardConfigIP<? extends IPAddress>>();
    try {
        for (GwtFirewallPortForwardEntry entry : entries) {
            String network = null;
            String prefix = null;
            if (entry.getPermittedNetwork() != null) {
                String[] parts = entry.getPermittedNetwork().split("/");
                network = parts[0];
                prefix = parts[1];
            }
            FirewallPortForwardConfigIP<IP4Address> firewallPortForwardConfigIP = new FirewallPortForwardConfigIP4();
            firewallPortForwardConfigIP.setInboundInterface(GwtSafeHtmlUtils.htmlEscape(entry.getInboundInterface()));
            firewallPortForwardConfigIP.setOutboundInterface(GwtSafeHtmlUtils.htmlEscape(entry.getOutboundInterface()));
            firewallPortForwardConfigIP.setAddress((IP4Address) IPAddress.parseHostAddress(GwtSafeHtmlUtils.htmlEscape(entry.getAddress())));
            firewallPortForwardConfigIP.setProtocol(NetProtocol.valueOf(GwtSafeHtmlUtils.htmlEscape(entry.getProtocol())));
            firewallPortForwardConfigIP.setInPort(entry.getInPort());
            firewallPortForwardConfigIP.setOutPort(entry.getOutPort());
            boolean masquerade = entry.getMasquerade().equals("yes") ? true : false;
            firewallPortForwardConfigIP.setMasquerade(masquerade);
            if (network != null && prefix != null) {
                firewallPortForwardConfigIP.setPermittedNetwork(new NetworkPair<IP4Address>((IP4Address) IPAddress.parseHostAddress(network), Short.parseShort(prefix)));
            }
            firewallPortForwardConfigIP.setPermittedMac(GwtSafeHtmlUtils.htmlEscape(entry.getPermittedMAC()));
            firewallPortForwardConfigIP.setSourcePortRange(GwtSafeHtmlUtils.htmlEscape(entry.getSourcePortRange()));
            s_logger.debug("adding port forward entry for inbound iface {} - port {}", GwtSafeHtmlUtils.htmlEscape(entry.getInboundInterface()), entry.getInPort());
            firewallPortForwardConfigIPs.add(firewallPortForwardConfigIP);
        }
        nas.setFirewallPortForwardingConfiguration(firewallPortForwardConfigIPs);
    } catch (KuraException e) {
        s_logger.warn("Exception while updating firewall port forwards", e);
        throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
    } catch (NumberFormatException e) {
        s_logger.warn("Exception while updating firewall port forwards", e);
        throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
    } catch (UnknownHostException e) {
        s_logger.warn("Exception while updating firewall port forwards", e);
        throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) UnknownHostException(java.net.UnknownHostException) IP4Address(org.eclipse.kura.net.IP4Address) ArrayList(java.util.ArrayList) FirewallPortForwardConfigIP(org.eclipse.kura.net.firewall.FirewallPortForwardConfigIP) GwtFirewallPortForwardEntry(org.eclipse.kura.web.shared.model.GwtFirewallPortForwardEntry) KuraException(org.eclipse.kura.KuraException) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) FirewallPortForwardConfigIP4(org.eclipse.kura.net.firewall.FirewallPortForwardConfigIP4) NetworkAdminService(org.eclipse.kura.net.NetworkAdminService) 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 FirewallPortForwardConfigIP (org.eclipse.kura.net.firewall.FirewallPortForwardConfigIP)1 FirewallPortForwardConfigIP4 (org.eclipse.kura.net.firewall.FirewallPortForwardConfigIP4)1 GwtKuraException (org.eclipse.kura.web.shared.GwtKuraException)1 GwtFirewallPortForwardEntry (org.eclipse.kura.web.shared.model.GwtFirewallPortForwardEntry)1