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