Skip to content

Commit

Permalink
feat: Firewall IPV6 support in UI
Browse files Browse the repository at this point in the history
Signed-off-by: MMaiero <[email protected]>
  • Loading branch information
MMaiero committed Aug 14, 2023
1 parent 7e59ca0 commit fa7a42e
Show file tree
Hide file tree
Showing 14 changed files with 3,376 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2011, 2020 Eurotech and/or its affiliates and others
*
* Copyright (c) 2011, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* Eurotech
*******************************************************************************/
Expand All @@ -15,6 +15,9 @@
import org.eclipse.kura.web.client.messages.Messages;
import org.eclipse.kura.web.client.ui.Tab;
import org.eclipse.kura.web.client.ui.Tab.RefreshHandler;
import org.eclipse.kura.web.client.util.FailureHandler;
import org.eclipse.kura.web.shared.service.GwtNetworkService;
import org.eclipse.kura.web.shared.service.GwtNetworkServiceAsync;
import org.gwtbootstrap3.client.ui.Anchor;
import org.gwtbootstrap3.client.ui.Button;
import org.gwtbootstrap3.client.ui.Modal;
Expand All @@ -25,6 +28,7 @@
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
Expand All @@ -36,12 +40,20 @@ public class FirewallPanelUi extends Composite {
interface FirewallPanelUiUiBinder extends UiBinder<Widget, FirewallPanelUi> {
}

private final GwtNetworkServiceAsync gwtNetworkService = GWT.create(GwtNetworkService.class);

@UiField
OpenPortsTabUi openPortsPanel;
@UiField
PortForwardingTabUi portForwardingPanel;
@UiField
NatTabUi ipForwardingPanel;
@UiField
OpenPortsIPv6TabUi openPortsIPv6Panel;
@UiField
PortForwardingIPv6TabUi portForwardingIPv6Panel;
@UiField
NatIPv6TabUi ipForwardingIPv6Panel;

private static final Messages MSGS = GWT.create(Messages.class);

Expand All @@ -53,6 +65,12 @@ interface FirewallPanelUiUiBinder extends UiBinder<Widget, FirewallPanelUi> {
TabListItem portForwarding;
@UiField
TabListItem ipForwarding;
@UiField
TabListItem openPortsIPv6;
@UiField
TabListItem portForwardingIPv6;
@UiField
TabListItem ipForwardingIPv6;

@UiField
Modal dirtyModal;
Expand All @@ -62,42 +80,72 @@ interface FirewallPanelUiUiBinder extends UiBinder<Widget, FirewallPanelUi> {
Button no;

private TabListItem currentlySelectedTab;
private Tab.RefreshHandler openPortsHandler;
private Tab.RefreshHandler portForwardingHandler;
private Tab.RefreshHandler ipForwardingHandler;
private final Tab.RefreshHandler openPortsHandler;
private final Tab.RefreshHandler portForwardingHandler;
private final Tab.RefreshHandler ipForwardingHandler;
private final Tab.RefreshHandler openPortsIPv6Handler;
private final Tab.RefreshHandler portForwardingIPv6Handler;
private final Tab.RefreshHandler ipForwardingIPv6Handler;

public FirewallPanelUi() {

initWidget(uiBinder.createAndBindUi(this));
detectIfNet2();
this.firewallIntro.add(new Span("<p>" + MSGS.firewallIntro() + "</p>"));

this.openPorts.setText(MSGS.firewallOpenPorts());
this.portForwarding.setText(MSGS.firewallPortForwarding());
this.ipForwarding.setText(MSGS.firewallNat());

this.openPortsIPv6.setText(MSGS.firewallOpenPortsIPv6());
this.portForwardingIPv6.setText(MSGS.firewallPortForwardingIPv6());
this.ipForwardingIPv6.setText(MSGS.firewallNatIPv6());

this.openPortsHandler = new Tab.RefreshHandler(this.openPortsPanel);
this.openPorts.addClickHandler(event -> handleEvent(event, this.openPortsHandler));
this.portForwardingHandler = new Tab.RefreshHandler(this.portForwardingPanel);
this.portForwarding.addClickHandler(event -> handleEvent(event, this.portForwardingHandler));
this.ipForwardingHandler = new Tab.RefreshHandler(this.ipForwardingPanel);
this.ipForwarding.addClickHandler(event -> handleEvent(event, this.ipForwardingHandler));

this.openPortsIPv6Handler = new Tab.RefreshHandler(this.openPortsIPv6Panel);
this.openPortsIPv6.addClickHandler(event -> handleEvent(event, this.openPortsIPv6Handler));
this.portForwardingIPv6Handler = new Tab.RefreshHandler(this.portForwardingIPv6Panel);
this.portForwardingIPv6.addClickHandler(event -> handleEvent(event, this.portForwardingIPv6Handler));
this.ipForwardingIPv6Handler = new Tab.RefreshHandler(this.ipForwardingIPv6Panel);
this.ipForwardingIPv6.addClickHandler(event -> handleEvent(event, this.ipForwardingIPv6Handler));
}

public void initFirewallPanel() {
FirewallPanelUi.this.currentlySelectedTab = openPorts;
FirewallPanelUi.this.currentlySelectedTab = this.openPorts;

this.portForwardingPanel.clear();
this.ipForwardingPanel.clear();
this.openPortsPanel.refresh();

this.portForwardingIPv6Panel.clear();
this.ipForwardingIPv6Panel.clear();
this.openPortsIPv6Panel.refresh();

this.openPorts.showTab();
}

public boolean isDirty() {
return this.openPortsPanel.isDirty() || this.portForwardingPanel.isDirty() || this.ipForwardingPanel.isDirty();
boolean ipv4PanelsDirty = this.openPortsPanel.isDirty() || this.portForwardingPanel.isDirty()
|| this.ipForwardingPanel.isDirty();
boolean ipv6PanelsDirty = this.openPortsIPv6Panel.isDirty() || this.portForwardingIPv6Panel.isDirty()
|| this.ipForwardingIPv6Panel.isDirty();
return ipv4PanelsDirty || ipv6PanelsDirty;
}

public void setDirty(boolean b) {
this.openPortsPanel.setDirty(b);
this.portForwardingPanel.setDirty(b);
this.ipForwardingPanel.setDirty(b);

this.openPortsIPv6Panel.setDirty(b);
this.portForwardingIPv6Panel.setDirty(b);
this.ipForwardingIPv6Panel.setDirty(b);
}

private void showDirtyModal(TabListItem newTabListItem, RefreshHandler newTabRefreshHandler) {
Expand Down Expand Up @@ -136,8 +184,35 @@ private Tab getTab(TabListItem item) {
return this.portForwardingPanel;
} else if (item.getDataTarget().equals("#ipForwardingPanel")) {
return this.ipForwardingPanel;
} else if (item.getDataTarget().equals("#openPortsIPv6Panel")) {
return this.openPortsIPv6Panel;
} else if (item.getDataTarget().equals("#portForwardingIPv6Panel")) {
return this.portForwardingIPv6Panel;
} else if (item.getDataTarget().equals("#ipForwardingIPv6Panel")) {
return this.ipForwardingIPv6Panel;
} else {
return this.openPortsPanel;
}
}

private void detectIfNet2() {
this.gwtNetworkService.isNet2(new AsyncCallback<Boolean>() {

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

@Override
public void onSuccess(Boolean result) {
initNet2FeaturesOnly(result);
}
});
}

private void initNet2FeaturesOnly(boolean isNet2) {
this.openPortsIPv6.setVisible(isNet2);
this.portForwardingIPv6.setVisible(isNet2);
this.ipForwardingIPv6.setVisible(isNet2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
Copyright (c) 2011, 2020 Eurotech and/or its affiliates and others
Copyright (c) 2011, 2023 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -41,12 +41,18 @@
<b:Row>
<b:Well size="SMALL">
<b:NavTabs>
<b:TabListItem dataTarget="#openPortsPanel" text="Open Ports"
<b:TabListItem dataTarget="#openPortsPanel" text="{msgs.firewallOpenPorts}"
ui:field="openPorts" active="true"/>
<b:TabListItem dataTarget="#portForwardingPanel" text="Port Forwarding"
<b:TabListItem dataTarget="#portForwardingPanel" text="{msgs.firewallPortForwarding}"
ui:field="portForwarding"/>
<b:TabListItem dataTarget="#ipForwardingPanel" text="IP Forwarding/Masquerading"
<b:TabListItem dataTarget="#ipForwardingPanel" text="{msgs.firewallNat}"
ui:field="ipForwarding" />
<b:TabListItem dataTarget="#openPortsIPv6Panel" text="{msgs.firewallOpenPortsIPv6}"
ui:field="openPortsIPv6"/>
<b:TabListItem dataTarget="#portForwardingIPv6Panel" text="{msgs.firewallPortForwardingIPv6}"
ui:field="portForwardingIPv6"/>
<b:TabListItem dataTarget="#ipForwardingIPv6Panel" text="{msgs.firewallNatIPv6}"
ui:field="ipForwardingIPv6" />
</b:NavTabs>
<b:TabContent>
<b:TabPane b:id="openPortsPanel" active="true">
Expand All @@ -58,6 +64,15 @@
<b:TabPane b:id="ipForwardingPanel">
<firewall:NatTabUi ui:field="ipForwardingPanel"></firewall:NatTabUi>
</b:TabPane>
<b:TabPane b:id="openPortsIPv6Panel">
<firewall:OpenPortsIPv6TabUi ui:field="openPortsIPv6Panel"></firewall:OpenPortsIPv6TabUi>
</b:TabPane>
<b:TabPane b:id="portForwardingIPv6Panel">
<firewall:PortForwardingIPv6TabUi ui:field="portForwardingIPv6Panel"></firewall:PortForwardingIPv6TabUi>
</b:TabPane>
<b:TabPane b:id="ipForwardingIPv6Panel">
<firewall:NatIPv6TabUi ui:field="ipForwardingIPv6Panel"></firewall:NatIPv6TabUi>
</b:TabPane>
</b:TabContent>
</b:Well>
</b:Row>
Expand Down
Loading

0 comments on commit fa7a42e

Please sign in to comment.