Search in sources :

Example 1 with GwtFirewallNatEntry

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

the class GwtNetworkServiceImpl method findDeviceFirewallNATs.

@Override
public ArrayList<GwtFirewallNatEntry> findDeviceFirewallNATs(GwtXSRFToken xsrfToken) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
    List<GwtFirewallNatEntry> gwtNatEntries = new ArrayList<GwtFirewallNatEntry>();
    try {
        List<NetConfig> firewallConfigs = nas.getFirewallConfiguration();
        if (firewallConfigs != null && !firewallConfigs.isEmpty()) {
            for (NetConfig netConfig : firewallConfigs) {
                if (netConfig instanceof FirewallNatConfig) {
                    s_logger.debug("findDeviceFirewallNATs() :: adding new NAT Entry");
                    GwtFirewallNatEntry entry = new GwtFirewallNatEntry();
                    entry.setInInterface(((FirewallNatConfig) netConfig).getSourceInterface());
                    entry.setOutInterface(((FirewallNatConfig) netConfig).getDestinationInterface());
                    entry.setProtocol(((FirewallNatConfig) netConfig).getProtocol());
                    entry.setSourceNetwork(((FirewallNatConfig) netConfig).getSource());
                    entry.setDestinationNetwork(((FirewallNatConfig) netConfig).getDestination());
                    String masquerade = ((FirewallNatConfig) netConfig).isMasquerade() ? "yes" : "no";
                    entry.setMasquerade(masquerade);
                    gwtNatEntries.add(entry);
                }
            }
        }
        return new ArrayList<GwtFirewallNatEntry>(gwtNatEntries);
    } catch (KuraException e) {
        s_logger.warn("Failed", e);
        throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) GwtFirewallNatEntry(org.eclipse.kura.web.shared.model.GwtFirewallNatEntry) 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) FirewallNatConfig(org.eclipse.kura.net.firewall.FirewallNatConfig)

Example 2 with GwtFirewallNatEntry

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

the class NatTabUi method initEditButton.

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

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

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

Example 3 with GwtFirewallNatEntry

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

the class NatTabUi method duplicateEntry.

private boolean duplicateEntry(GwtFirewallNatEntry firewallNatEntry) {
    boolean isDuplicateEntry = false;
    List<GwtFirewallNatEntry> entries = this.natDataProvider.getList();
    if (entries != null && firewallNatEntry != null) {
        for (GwtFirewallNatEntry entry : entries) {
            String sourceNetwork = entry.getSourceNetwork() != null ? entry.getSourceNetwork() : "0.0.0.0/0";
            String destinationNetwork = entry.getDestinationNetwork() != null ? entry.getDestinationNetwork() : "0.0.0.0/0";
            String newSourceNetwork = firewallNatEntry.getSourceNetwork() != null ? firewallNatEntry.getSourceNetwork() : "0.0.0.0/0";
            String newDestinationNetwork = firewallNatEntry.getDestinationNetwork() != null ? firewallNatEntry.getDestinationNetwork() : "0.0.0.0/0";
            if (entry.getInInterface().equals(firewallNatEntry.getInInterface()) && entry.getOutInterface().equals(firewallNatEntry.getOutInterface()) && entry.getProtocol().equals(firewallNatEntry.getProtocol()) && sourceNetwork.equals(newSourceNetwork) && destinationNetwork.equals(newDestinationNetwork)) {
                isDuplicateEntry = true;
                break;
            }
        }
    }
    return isDuplicateEntry;
}
Also used : GwtFirewallNatEntry(org.eclipse.kura.web.shared.model.GwtFirewallNatEntry)

Example 4 with GwtFirewallNatEntry

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

the class NatTabUi method initModal.

private void initModal() {
    // Handle Buttons
    this.cancel.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            NatTabUi.this.natForm.hide();
        }
    });
    this.submit.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            checkFieldsValues();
            if (NatTabUi.this.groupInput.getValidationState() == ValidationState.ERROR || NatTabUi.this.groupOutput.getValidationState() == ValidationState.ERROR || NatTabUi.this.groupSource.getValidationState() == ValidationState.ERROR || NatTabUi.this.groupDestination.getValidationState() == ValidationState.ERROR) {
                return;
            }
            // Fetch form data
            GwtFirewallNatEntry natEntry = new GwtFirewallNatEntry();
            natEntry.setInInterface(NatTabUi.this.input.getText());
            natEntry.setOutInterface(NatTabUi.this.output.getText());
            natEntry.setProtocol(NatTabUi.this.protocol.getSelectedItemText());
            natEntry.setSourceNetwork(NatTabUi.this.source.getText());
            natEntry.setDestinationNetwork(NatTabUi.this.destination.getText());
            natEntry.setMasquerade(NatTabUi.this.enable.getSelectedItemText());
            if (NatTabUi.this.submit.getId().equals("new")) {
                NatTabUi.this.newNatEntry = natEntry;
                NatTabUi.this.editNatEntry = null;
            } else if (NatTabUi.this.submit.getId().equals("edit")) {
                NatTabUi.this.editNatEntry = natEntry;
                NatTabUi.this.newNatEntry = null;
            }
            NatTabUi.this.natForm.hide();
            setDirty(true);
        }
    });
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) GwtFirewallNatEntry(org.eclipse.kura.web.shared.model.GwtFirewallNatEntry) ClickEvent(com.google.gwt.event.dom.client.ClickEvent)

Example 5 with GwtFirewallNatEntry

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

the class NatTabUi method initApplyButton.

private void initApplyButton() {
    this.apply.setText(MSGS.firewallApply());
    this.apply.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            List<GwtFirewallNatEntry> intermediateList = NatTabUi.this.natDataProvider.getList();
            ArrayList<GwtFirewallNatEntry> tempList = new ArrayList<GwtFirewallNatEntry>();
            final List<GwtFirewallNatEntry> updatedNatConf = tempList;
            for (GwtFirewallNatEntry entry : intermediateList) {
                tempList.add(entry);
            }
            if (updatedNatConf != null) {
                EntryClassUi.showWaitModal();
                NatTabUi.this.gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

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

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        NatTabUi.this.gwtNetworkService.updateDeviceFirewallNATs(token, updatedNatConf, new AsyncCallback<Void>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                EntryClassUi.hideWaitModal();
                                FailureHandler.handle(caught);
                            }

                            @Override
                            public void onSuccess(Void result) {
                                setDirty(false);
                                NatTabUi.this.apply.setEnabled(false);
                                EntryClassUi.hideWaitModal();
                            }
                        });
                    }
                });
            }
        }
    });
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) GwtFirewallNatEntry(org.eclipse.kura.web.shared.model.GwtFirewallNatEntry) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken)

Aggregations

GwtFirewallNatEntry (org.eclipse.kura.web.shared.model.GwtFirewallNatEntry)12 ArrayList (java.util.ArrayList)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)4 GwtXSRFToken (org.eclipse.kura.web.shared.model.GwtXSRFToken)4 List (java.util.List)3 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)2 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)2 Button (com.extjs.gxt.ui.client.widget.button.Button)2 KuraException (org.eclipse.kura.KuraException)2 NetworkAdminService (org.eclipse.kura.net.NetworkAdminService)2 FirewallNatConfig (org.eclipse.kura.net.firewall.FirewallNatConfig)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