Search in sources :

Example 1 with GwtFirewallPortForwardEntry

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

Example 2 with GwtFirewallPortForwardEntry

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

the class PortForwardingTabUi method initDeleteButton.

private void initDeleteButton() {
    this.delete.setText(MSGS.deleteButton());
    this.delete.addClickHandler(new ClickHandler() {

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

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

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

Example 3 with GwtFirewallPortForwardEntry

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

the class PortForwardingTabUi method initEditButton.

private void initEditButton() {
    this.edit.setText(MSGS.editButton());
    this.edit.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            GwtFirewallPortForwardEntry selection = PortForwardingTabUi.this.selectionModel.getSelectedObject();
            if (selection != null) {
                showModal(selection);
            }
        }
    });
    this.portForwardingForm.addHideHandler(new ModalHideHandler() {

        @Override
        public void onHide(ModalHideEvent evt) {
            if (PortForwardingTabUi.this.editPortForwardEntry != null) {
                GwtFirewallPortForwardEntry oldEntry = PortForwardingTabUi.this.selectionModel.getSelectedObject();
                PortForwardingTabUi.this.portForwardDataProvider.getList().remove(oldEntry);
                if (!duplicateEntry(PortForwardingTabUi.this.editPortForwardEntry)) {
                    PortForwardingTabUi.this.portForwardDataProvider.getList().add(PortForwardingTabUi.this.editPortForwardEntry);
                    PortForwardingTabUi.this.portForwardDataProvider.flush();
                    PortForwardingTabUi.this.apply.setEnabled(true);
                    PortForwardingTabUi.this.editPortForwardEntry = null;
                } else {
                    // end duplicate
                    PortForwardingTabUi.this.portForwardDataProvider.getList().add(oldEntry);
                    PortForwardingTabUi.this.portForwardDataProvider.flush();
                }
            }
        }
    });
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) GwtFirewallPortForwardEntry(org.eclipse.kura.web.shared.model.GwtFirewallPortForwardEntry) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ModalHideHandler(org.gwtbootstrap3.client.shared.event.ModalHideHandler) ModalHideEvent(org.gwtbootstrap3.client.shared.event.ModalHideEvent)

Example 4 with GwtFirewallPortForwardEntry

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

the class GwtNetworkServiceImpl method findDeviceFirewallPortForwards.

@Override
public ArrayList<GwtFirewallPortForwardEntry> findDeviceFirewallPortForwards(GwtXSRFToken xsrfToken) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
    List<GwtFirewallPortForwardEntry> gwtPortForwardEntries = new ArrayList<GwtFirewallPortForwardEntry>();
    try {
        List<NetConfig> firewallConfigs = nas.getFirewallConfiguration();
        if (firewallConfigs != null && !firewallConfigs.isEmpty()) {
            for (NetConfig netConfig : firewallConfigs) {
                if (netConfig instanceof FirewallPortForwardConfigIP4) {
                    s_logger.debug("findDeviceFirewallPortForwards() :: adding new Port Forward Entry");
                    GwtFirewallPortForwardEntry entry = new GwtFirewallPortForwardEntry();
                    entry.setInboundInterface(((FirewallPortForwardConfigIP4) netConfig).getInboundInterface());
                    entry.setOutboundInterface(((FirewallPortForwardConfigIP4) netConfig).getOutboundInterface());
                    entry.setAddress(((FirewallPortForwardConfigIP4) netConfig).getAddress().getHostAddress());
                    entry.setProtocol(((FirewallPortForwardConfigIP4) netConfig).getProtocol().toString());
                    entry.setInPort(((FirewallPortForwardConfigIP4) netConfig).getInPort());
                    entry.setOutPort(((FirewallPortForwardConfigIP4) netConfig).getOutPort());
                    String masquerade = ((FirewallPortForwardConfigIP4) netConfig).isMasquerade() ? "yes" : "no";
                    entry.setMasquerade(masquerade);
                    entry.setPermittedNetwork(((FirewallPortForwardConfigIP4) netConfig).getPermittedNetwork().toString());
                    entry.setPermittedMAC(((FirewallPortForwardConfigIP4) netConfig).getPermittedMac());
                    entry.setSourcePortRange(((FirewallPortForwardConfigIP4) netConfig).getSourcePortRange());
                    gwtPortForwardEntries.add(entry);
                }
            }
        }
        return new ArrayList<GwtFirewallPortForwardEntry>(gwtPortForwardEntries);
    } catch (KuraException e) {
        s_logger.warn("Failed", e);
        throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) GwtFirewallPortForwardEntry(org.eclipse.kura.web.shared.model.GwtFirewallPortForwardEntry) KuraException(org.eclipse.kura.KuraException) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) ArrayList(java.util.ArrayList) NetConfig(org.eclipse.kura.net.NetConfig) FirewallPortForwardConfigIP4(org.eclipse.kura.net.firewall.FirewallPortForwardConfigIP4) NetworkAdminService(org.eclipse.kura.net.NetworkAdminService)

Example 5 with GwtFirewallPortForwardEntry

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

the class PortForwardingConfigTab method initToolBar.

private void initToolBar() {
    m_portForwardToolBar = new ToolBar();
    m_portForwardToolBar.setId("firewall-port-forwarding-toolbar");
    m_applyButton = new Button(MSGS.firewallApply(), AbstractImagePrototype.create(Resources.INSTANCE.accept()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            Log.debug("about to updateDeviceFirewallPortForwards()");
            gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

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

                @Override
                public void onSuccess(GwtXSRFToken token) {
                    List<GwtFirewallPortForwardEntry> updatedPortForwardConf = getCurrentConfigurations();
                    if (updatedPortForwardConf != null) {
                        Log.debug("got updatedPortForwardConf: " + updatedPortForwardConf.size());
                        mask(MSGS.applying());
                        gwtNetworkService.updateDeviceFirewallPortForwards(token, updatedPortForwardConf, new AsyncCallback<Void>() {

                            public void onSuccess(Void result) {
                                Log.debug("updated!");
                                m_dirty = false;
                                m_applyButton.disable();
                                unmask();
                            }

                            public void onFailure(Throwable caught) {
                                Log.debug("caught: " + caught.toString());
                                unmask();
                                FailureHandler.handle(caught);
                            }
                        });
                    }
                }
            });
        }
    });
    m_applyButton.disable();
    m_portForwardToolBar.add(m_applyButton);
    m_portForwardToolBar.add(new SeparatorToolItem());
    // 
    // New Open Port Button
    m_newButton = new Button(MSGS.newButton(), AbstractImagePrototype.create(Resources.INSTANCE.add()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            final PortForwardForm portForwardForm = new PortForwardForm(m_currentSession);
            portForwardForm.addListener(Events.Hide, new Listener<ComponentEvent>() {

                public void handleEvent(ComponentEvent be) {
                    // add the new entry to the grid and select it
                    if (portForwardForm.getNewPortForwardEntry() != null) {
                        if (!duplicateEntry(portForwardForm.getNewPortForwardEntry())) {
                            m_grid.getStore().add(portForwardForm.getNewPortForwardEntry());
                            if (!portForwardForm.isCanceled()) {
                                m_applyButton.enable();
                                m_dirty = true;
                            }
                        } else {
                            MessageBox.alert(MSGS.firewallPortForwardFormError(), MSGS.firewallPortForwardFormDuplicate(), new Listener<MessageBoxEvent>() {

                                public void handleEvent(MessageBoxEvent ce) {
                                // noop
                                }
                            });
                        }
                    }
                }
            });
            portForwardForm.show();
        }
    });
    m_portForwardToolBar.add(m_newButton);
    m_portForwardToolBar.add(new SeparatorToolItem());
    // 
    // Edit Open Port Button
    m_editButton = new Button(MSGS.editButton(), AbstractImagePrototype.create(Resources.INSTANCE.edit()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (m_grid != null) {
                final GwtFirewallPortForwardEntry portForwardEntry = m_grid.getSelectionModel().getSelectedItem();
                if (portForwardEntry != null) {
                    final PortForwardForm portForwardForm = new PortForwardForm(m_currentSession, m_grid.getSelectionModel().getSelectedItem());
                    portForwardForm.addListener(Events.Hide, new Listener<ComponentEvent>() {

                        public void handleEvent(ComponentEvent be) {
                            if (!duplicateEntry(portForwardForm.getNewPortForwardEntry())) {
                                m_grid.getStore().remove(portForwardEntry);
                                m_grid.getStore().add(portForwardForm.getExistingPortForwardEntry());
                                if (!portForwardForm.isCanceled()) {
                                    m_dirty = true;
                                    m_applyButton.enable();
                                }
                            } else {
                                MessageBox.alert(MSGS.firewallPortForwardFormError(), MSGS.firewallPortForwardFormDuplicate(), new Listener<MessageBoxEvent>() {

                                    public void handleEvent(MessageBoxEvent ce) {
                                    // noop
                                    }
                                });
                            }
                        }
                    });
                    portForwardForm.show();
                }
            }
        }
    });
    m_editButton.setEnabled(false);
    m_portForwardToolBar.add(m_editButton);
    m_portForwardToolBar.add(new SeparatorToolItem());
    // 
    // Delete Open Port Entry Button
    m_deleteButton = new Button(MSGS.deleteButton(), AbstractImagePrototype.create(Resources.INSTANCE.delete()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (m_grid != null) {
                final GwtFirewallPortForwardEntry portForwardEntry = m_grid.getSelectionModel().getSelectedItem();
                if (portForwardEntry != null) {
                    // ask for confirmation
                    MessageBox.confirm(MSGS.confirm(), MSGS.firewallPortForwardDeleteConfirmation(portForwardEntry.getInPort().toString()), new Listener<MessageBoxEvent>() {

                        public void handleEvent(MessageBoxEvent ce) {
                            Log.debug("Trying to delete: " + portForwardEntry.getInPort().toString());
                            Log.debug("Button " + ce.getButtonClicked().getText());
                            if (ce.getButtonClicked().getText().equals("Yes")) {
                                m_grid.getStore().remove(portForwardEntry);
                                m_applyButton.enable();
                                m_dirty = true;
                            }
                        }
                    });
                }
            }
        }
    });
    m_deleteButton.setEnabled(false);
    m_portForwardToolBar.add(m_deleteButton);
}
Also used : Listener(com.extjs.gxt.ui.client.event.Listener) LoadListener(com.extjs.gxt.ui.client.event.LoadListener) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener) SelectionChangedListener(com.extjs.gxt.ui.client.event.SelectionChangedListener) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) SeparatorToolItem(com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken) MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) 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) ToolBar(com.extjs.gxt.ui.client.widget.toolbar.ToolBar) List(java.util.List) ArrayList(java.util.ArrayList) ComponentEvent(com.extjs.gxt.ui.client.event.ComponentEvent) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Aggregations

GwtFirewallPortForwardEntry (org.eclipse.kura.web.shared.model.GwtFirewallPortForwardEntry)13 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 FirewallPortForwardConfigIP4 (org.eclipse.kura.net.firewall.FirewallPortForwardConfigIP4)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 Listener (com.extjs.gxt.ui.client.event.Listener)1 LoadListener (com.extjs.gxt.ui.client.event.LoadListener)1 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1