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