Search in sources :

Example 1 with GwtFirewallOpenPortEntry

use of org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry in project kura by eclipse.

the class GwtNetworkServiceImpl method findDeviceFirewallOpenPorts.

@Override
public ArrayList<GwtFirewallOpenPortEntry> findDeviceFirewallOpenPorts(GwtXSRFToken xsrfToken) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
    List<GwtFirewallOpenPortEntry> gwtOpenPortEntries = new ArrayList<GwtFirewallOpenPortEntry>();
    try {
        List<NetConfig> firewallConfigs = nas.getFirewallConfiguration();
        if (firewallConfigs != null && !firewallConfigs.isEmpty()) {
            for (NetConfig netConfig : firewallConfigs) {
                if (netConfig instanceof FirewallOpenPortConfigIP4) {
                    s_logger.debug("findDeviceFirewallOpenPorts() :: adding new Open Port Entry: {}", ((FirewallOpenPortConfigIP4) netConfig).getPort());
                    GwtFirewallOpenPortEntry entry = new GwtFirewallOpenPortEntry();
                    if (((FirewallOpenPortConfigIP4) netConfig).getPortRange() != null) {
                        entry.setPortRange(((FirewallOpenPortConfigIP4) netConfig).getPortRange());
                    } else {
                        entry.setPortRange(String.valueOf(((FirewallOpenPortConfigIP4) netConfig).getPort()));
                    }
                    entry.setProtocol(((FirewallOpenPortConfigIP4) netConfig).getProtocol().toString());
                    entry.setPermittedNetwork(((FirewallOpenPortConfigIP4) netConfig).getPermittedNetwork().getIpAddress().getHostAddress() + "/" + ((FirewallOpenPortConfigIP4) netConfig).getPermittedNetwork().getPrefix());
                    entry.setPermittedInterfaceName(((FirewallOpenPortConfigIP4) netConfig).getPermittedInterfaceName());
                    entry.setUnpermittedInterfaceName(((FirewallOpenPortConfigIP4) netConfig).getUnpermittedInterfaceName());
                    entry.setPermittedMAC(((FirewallOpenPortConfigIP4) netConfig).getPermittedMac());
                    entry.setSourcePortRange(((FirewallOpenPortConfigIP4) netConfig).getSourcePortRange());
                    gwtOpenPortEntries.add(entry);
                }
            }
        }
        return new ArrayList<GwtFirewallOpenPortEntry>(gwtOpenPortEntries);
    } catch (KuraException 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) KuraException(org.eclipse.kura.KuraException) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) ArrayList(java.util.ArrayList) NetConfig(org.eclipse.kura.net.NetConfig) NetworkAdminService(org.eclipse.kura.net.NetworkAdminService) FirewallOpenPortConfigIP4(org.eclipse.kura.net.firewall.FirewallOpenPortConfigIP4)

Example 2 with GwtFirewallOpenPortEntry

use of org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry 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)

Example 3 with GwtFirewallOpenPortEntry

use of org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry in project kura by eclipse.

the class OpenPortsTabUi method initDeleteButton.

private void initDeleteButton() {
    this.delete.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            GwtFirewallOpenPortEntry selection = OpenPortsTabUi.this.selectionModel.getSelectedObject();
            if (selection != null) {
                OpenPortsTabUi.this.alert.setTitle(MSGS.confirm());
                OpenPortsTabUi.this.alertBody.setText(MSGS.firewallOpenPortDeleteConfirmation(String.valueOf(selection.getPortRange())));
                OpenPortsTabUi.this.alert.show();
            }
        }
    });
    this.yes.setText(MSGS.yesButton());
    this.no.setText(MSGS.noButton());
    this.no.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            OpenPortsTabUi.this.alert.hide();
        }
    });
    this.yes.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            OpenPortsTabUi.this.alert.hide();
            OpenPortsTabUi.this.openPortsDataProvider.getList().remove(OpenPortsTabUi.this.selectionModel.getSelectedObject());
            refreshTable();
            OpenPortsTabUi.this.apply.setEnabled(true);
            setVisibility();
            setDirty(true);
        }
    });
}
Also used : GwtFirewallOpenPortEntry(org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent)

Example 4 with GwtFirewallOpenPortEntry

use of org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry in project kura by eclipse.

the class OpenPortsTabUi method initModal.

private void initModal() {
    this.cancel.setText(MSGS.cancelButton());
    this.cancel.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            OpenPortsTabUi.this.openPortsForm.hide();
            OpenPortsTabUi.this.openPortEntry = null;
            OpenPortsTabUi.this.editOpenPortEntry = null;
            OpenPortsTabUi.this.newOpenPortEntry = null;
        }
    });
    this.submit.setText(MSGS.submitButton());
    this.submit.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            checkFieldsValues();
            if (OpenPortsTabUi.this.groupPort.getValidationState() == ValidationState.ERROR || OpenPortsTabUi.this.groupPermittedNw.getValidationState() == ValidationState.ERROR || OpenPortsTabUi.this.groupPermittedI.getValidationState() == ValidationState.ERROR || OpenPortsTabUi.this.groupUnpermittedI.getValidationState() == ValidationState.ERROR || OpenPortsTabUi.this.groupPermittedMac.getValidationState() == ValidationState.ERROR || OpenPortsTabUi.this.groupSource.getValidationState() == ValidationState.ERROR) {
                return;
            }
            // create a new entry
            OpenPortsTabUi.this.openPortEntry = new GwtFirewallOpenPortEntry();
            OpenPortsTabUi.this.openPortEntry.setPortRange(OpenPortsTabUi.this.port.getText());
            OpenPortsTabUi.this.openPortEntry.setProtocol(OpenPortsTabUi.this.protocol.getSelectedItemText());
            if (OpenPortsTabUi.this.permittedNw.getText() != null && !"".equals(OpenPortsTabUi.this.permittedNw.getText().trim())) {
                OpenPortsTabUi.this.openPortEntry.setPermittedNetwork(OpenPortsTabUi.this.permittedNw.getText());
            } else {
                OpenPortsTabUi.this.openPortEntry.setPermittedNetwork("0.0.0.0/0");
            }
            if (OpenPortsTabUi.this.permittedI.getText() != null && !"".equals(OpenPortsTabUi.this.permittedI.getText().trim())) {
                OpenPortsTabUi.this.openPortEntry.setPermittedInterfaceName(OpenPortsTabUi.this.permittedI.getText());
            }
            if (OpenPortsTabUi.this.unpermittedI.getText() != null && !"".equals(OpenPortsTabUi.this.unpermittedI.getText().trim())) {
                OpenPortsTabUi.this.openPortEntry.setUnpermittedInterfaceName(OpenPortsTabUi.this.unpermittedI.getText());
            }
            if (OpenPortsTabUi.this.permittedMac.getText() != null && !"".equals(OpenPortsTabUi.this.permittedMac.getText().trim())) {
                OpenPortsTabUi.this.openPortEntry.setPermittedMAC(OpenPortsTabUi.this.permittedMac.getText());
            }
            if (OpenPortsTabUi.this.source.getText() != null && !"".equals(OpenPortsTabUi.this.source.getText().trim())) {
                OpenPortsTabUi.this.openPortEntry.setSourcePortRange(OpenPortsTabUi.this.source.getText());
            }
            if (OpenPortsTabUi.this.submit.getId().equals("new")) {
                OpenPortsTabUi.this.newOpenPortEntry = OpenPortsTabUi.this.openPortEntry;
                OpenPortsTabUi.this.editOpenPortEntry = null;
            } else if (OpenPortsTabUi.this.submit.getId().equals("edit")) {
                OpenPortsTabUi.this.editOpenPortEntry = OpenPortsTabUi.this.openPortEntry;
                OpenPortsTabUi.this.newOpenPortEntry = null;
            }
            setDirty(true);
            OpenPortsTabUi.this.openPortsForm.hide();
        }
    });
}
Also used : GwtFirewallOpenPortEntry(org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent)

Example 5 with GwtFirewallOpenPortEntry

use of org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry in project kura by eclipse.

the class FirewallButtonBar method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new FitLayout());
    m_buttonBar = new ButtonBar();
    m_buttonBar.setHeight(20);
    m_buttonBar.setAlignment(HorizontalAlignment.CENTER);
    m_applyButton = new Button(MSGS.firewallApply(), AbstractImagePrototype.create(Resources.INSTANCE.accept()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            Log.debug("about to updateDeviceFirewallOpenPorts() and updateDeviceFirewallPortForwards()");
            final List<GwtFirewallOpenPortEntry> updatedOpenPortConf = m_firewallTabs.getUpdatedOpenPortConfiguration();
            final List<GwtFirewallPortForwardEntry> updatedPortForwardConf = m_firewallTabs.getUpdatedPortForwardConfiguration();
            if (updatedOpenPortConf != null) {
                Log.debug("got updatedOpenPortConf: " + updatedOpenPortConf.size());
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtNetworkService.updateDeviceFirewallOpenPorts(token, updatedOpenPortConf, new AsyncCallback<Void>() {

                            public void onSuccess(Void result) {
                                Log.debug("updated!");
                            }

                            public void onFailure(Throwable caught) {
                                Log.debug("caught: " + caught.toString());
                                FailureHandler.handle(caught);
                            }
                        });
                    }
                });
            }
            if (updatedPortForwardConf != null) {
                Log.debug("got updatedPortForwardConf: " + updatedPortForwardConf.size());
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtNetworkService.updateDeviceFirewallPortForwards(token, updatedPortForwardConf, new AsyncCallback<Void>() {

                            public void onSuccess(Void result) {
                                Log.debug("updated!");
                            }

                            public void onFailure(Throwable caught) {
                                Log.debug("caught: " + caught.toString());
                                FailureHandler.handle(caught);
                            }
                        });
                    }
                });
            }
        }
    });
    // m_applyButton.setWidth(100);
    m_buttonBar.add(m_applyButton);
    m_buttonBar.enable();
    add(m_applyButton);
}
Also used : GwtFirewallOpenPortEntry(org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry) ButtonBar(com.extjs.gxt.ui.client.widget.button.ButtonBar) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken) GwtFirewallPortForwardEntry(org.eclipse.kura.web.shared.model.GwtFirewallPortForwardEntry) Button(com.extjs.gxt.ui.client.widget.button.Button) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Aggregations

GwtFirewallOpenPortEntry (org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry)11 ArrayList (java.util.ArrayList)6 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)5 GwtXSRFToken (org.eclipse.kura.web.shared.model.GwtXSRFToken)5 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)3 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)3 Button (com.extjs.gxt.ui.client.widget.button.Button)3 List (java.util.List)3 KuraException (org.eclipse.kura.KuraException)2 NetworkAdminService (org.eclipse.kura.net.NetworkAdminService)2 FirewallOpenPortConfigIP4 (org.eclipse.kura.net.firewall.FirewallOpenPortConfigIP4)2 GwtKuraException (org.eclipse.kura.web.shared.GwtKuraException)2 ListLoadResult (com.extjs.gxt.ui.client.data.ListLoadResult)1 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)1 ComponentEvent (com.extjs.gxt.ui.client.event.ComponentEvent)1 FieldEvent (com.extjs.gxt.ui.client.event.FieldEvent)1 Listener (com.extjs.gxt.ui.client.event.Listener)1 LoadListener (com.extjs.gxt.ui.client.event.LoadListener)1