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);
}
}
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();
}
}
}
});
}
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;
}
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);
}
});
}
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();
}
});
}
});
}
}
});
}
Aggregations