Skip to content

Commit

Permalink
Added Force wireless network scan button
Browse files Browse the repository at this point in the history
Added polkit rules

Fixed tests
  • Loading branch information
salvatore-coppola committed Aug 2, 2023
1 parent 0629a8e commit f1859f1
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 35 deletions.
30 changes: 29 additions & 1 deletion kura/distrib/src/main/resources/common/manage_kura_users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ ResultInactive=no
ResultActive=no
ResultAny=yes" >/etc/polkit-1/localauthority/50-local.d/53-org.freedesktop.modemmanager.pkla
fi
if [ ! -f /etc/polkit-1/localauthority/50-local.d/54-fi.w1.wpa_supplicant1.pkla ]; then
echo "[No password prompt for kurad user when using Wpa Supplicant]
Identity=unix-user:kurad
Action=fi.w1.wpa_supplicant1.*
ResultInactive=no
ResultActive=no
ResultAny=yes" >/etc/polkit-1/localauthority/50-local.d/54-fi.w1.wpa_supplicant1.pkla
fi
fi
else
if [[ $NN == "NO" ]]; then
Expand All @@ -81,7 +89,8 @@ ResultAny=yes" >/etc/polkit-1/localauthority/50-local.d/53-org.freedesktop.modem
if [ ! -f /usr/share/polkit-1/rules.d/kura-nm.rules ]; then
echo "polkit.addRule(function(action, subject) {
if ((action.id.indexOf(\"org.freedesktop.NetworkManager.\") == 0 ||
action.id.indexOf(\"org.freedesktop.ModemManager1.\") == 0) &&
action.id.indexOf(\"org.freedesktop.ModemManager1.\") == 0 ||
action.id.indexOf(\"fi.w1.wpa_supplicant1.\")) &&
subject.user == \"kurad\") {
return polkit.Result.YES;
}
Expand Down Expand Up @@ -130,6 +139,21 @@ if (action.id == \"org.freedesktop.systemd1.manage-unit-files\" &&
done = 1
} 1' /etc/dbus-1/system.d/bluetooth.conf >tempfile && mv tempfile /etc/dbus-1/system.d/bluetooth.conf
fi

# grant kurad user the privileges to manage wpa supplicant via dbus
grep -lR kurad /etc/dbus-1/system.d/wpa_supplicant.conf
if [ $?!= 0 ]; then
cp /etc/dbus-1/system.d/wpa_supplicant.conf /etc/dbus-1/system.d/wpa_supplicant.conf.save
awk 'done != 1 && /^<\/busconfig>/ {
print " <policy user=\"kurad\">"
print " <allow own=\"fi.w1.wpa_supplicant1\"/>"
print " <allow send_destination=\"fi.w1.wpa_supplicant1\"/>"
print " <allow send_interface=\"fi.w1.wpa_supplicant1\"/>"
print " <allow receive_sender=\"fi.w1.wpa_supplicant1\" receive_type=\"signal\"/>"
print " </policy>\n"
done = 1
} 1' /etc/dbus-1/system.d/wpa_supplicant.conf >tempfile && mv tempfile /etc/dbus-1/system.d/wpa_supplicant.conf
fi

# Change kura folder ownership and permission
chown -R kurad:kurad /opt/eclipse
Expand Down Expand Up @@ -161,6 +185,9 @@ function delete_users {
if [ -f /etc/polkit-1/localauthority/50-local.d/53-org.freedesktop.modemmanager.pkla ]; then
rm -f /etc/polkit-1/localauthority/50-local.d/53-org.freedesktop.modemmanager.pkla
fi
if [ -f /etc/polkit-1/localauthority/50-local.d/54-fi.w1.wpa_supplicant1.pkla ]; then
rm -f /etc/polkit-1/localauthority/50-local.d/54-fi.w1.wpa_supplicant1.pkla
fi

# recover pam policy
if [ -f /etc/pam.d/su ]; then
Expand All @@ -170,6 +197,7 @@ function delete_users {

# recover old dbus config
mv /etc/dbus-1/system.d/bluetooth.conf.save /etc/dbus-1/system.d/bluetooth.conf
mv /etc/dbus-1/system.d/wpa_supplicant.conf.save /etc/dbus-1/system.d/wpa_supplicant.conf
}

INSTALL=YES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ interface TabWirelessUiUiBinder extends UiBinder<Widget, TabWirelessUi> {
@UiField
Alert scanFail;

@UiField
Button buttonSsidForceUpdate;

@UiField
Text searchingText;
@UiField
Expand Down Expand Up @@ -450,7 +453,10 @@ public void setNetInterface(GwtNetInterfaceConfig config) {

private void updateChanneList(GwtWifiConfig config) {
int channelToSelect = 0;
if (config.getChannels() != null) {

List<Integer> channels = config.getChannels();

if (channels != null && !channels.isEmpty()) {
channelToSelect = config.getChannels().get(0);
}

Expand Down Expand Up @@ -625,10 +631,8 @@ private void setRadioModeByValue(String radioModeValue) {
}

private void setBandFromRadioMode(String radioModeValue) {
boolean isValue5GHz = radioModeValue.equals(WIFI_RADIO_ANAC)
|| radioModeValue.equals(WIFI_RADIO_A);
boolean isValue2GHz = radioModeValue.equals(WIFI_RADIO_BG)
|| radioModeValue.equals(WIFI_RADIO_B);
boolean isValue5GHz = radioModeValue.equals(WIFI_RADIO_ANAC) || radioModeValue.equals(WIFI_RADIO_A);
boolean isValue2GHz = radioModeValue.equals(WIFI_RADIO_BG) || radioModeValue.equals(WIFI_RADIO_B);
boolean isValueBoth = radioModeValue.equals(WIFI_RADIO_BGN);

for (int i = 0; i < this.radio.getItemCount(); i++) {
Expand Down Expand Up @@ -679,7 +683,7 @@ private void refreshForm() {
this.radio.setEnabled(true);
this.channelList.setEnabled(true);
loadRadioMode();

if (this.isNet2) {
this.buttonPassword.setVisible(false);
}
Expand All @@ -694,6 +698,7 @@ private void refreshForm() {
if (WIFI_MODE_STATION_MESSAGE.equals(this.wireless.getSelectedItemText())) {
this.ssid.setEnabled(true);
this.buttonSsid.setEnabled(true);
logger.info("buttonSsid value: " + this.buttonSsid);
this.verify.setEnabled(false);
if (!this.security.getSelectedItemText().equals(WIFI_SECURITY_NONE_MESSAGE)) {
if (this.password.getValue() != null && this.password.getValue().length() > 0) {
Expand Down Expand Up @@ -722,6 +727,7 @@ private void refreshForm() {
} else {
this.ssid.setEnabled(true);
this.buttonSsid.setEnabled(false);
logger.info("buttonSsid value: " + this.buttonSsid);
if (!this.security.getSelectedItemText().equals(WIFI_SECURITY_NONE_MESSAGE)) {
this.password.setEnabled(true);
this.buttonPassword.setEnabled(false);
Expand Down Expand Up @@ -896,7 +902,20 @@ private void initForm() {
TabWirelessUi.this.scanFail.setVisible(false);
}
initModal();
loadSsidData();
loadSsidData(false);
});

this.buttonSsidForceUpdate.addClickHandler(event -> {
if (!TabWirelessUi.this.ssidInit) {
initSsid();
TabWirelessUi.this.ssidDataProvider.getList().clear();
TabWirelessUi.this.searching.setVisible(true);
TabWirelessUi.this.noSsid.setVisible(false);
TabWirelessUi.this.ssidGrid.setVisible(false);
TabWirelessUi.this.scanFail.setVisible(false);
}
initModal();
loadSsidData(true);
});

// Radio Mode
Expand Down Expand Up @@ -953,7 +972,7 @@ private void initForm() {
this.password.addBlurHandler(e -> this.password.validate());
this.password.setAllowBlank(false);
this.password.addMouseOutHandler(event -> resetHelp());

this.buttonPassword.addClickHandler(event -> {
EntryClassUi.showWaitModal();
TabWirelessUi.this.buttonPassword.setEnabled(false);
Expand Down Expand Up @@ -1195,7 +1214,7 @@ private List<GwtWifiHotspotEntry> getChannelFrequencyByIndex(int selectedIndex)
String selectedItem = this.channelList.getItemText(selectedIndex);

GwtWifiHotspotEntry frequencyEntry = new GwtWifiHotspotEntry();

if (selectedItem.equals(AUTOMATIC_CHANNEL_DESCRIPTION)) {
frequencyEntry.setChannel(0);
frequencyEntry.setFrequency(0);
Expand Down Expand Up @@ -1468,7 +1487,7 @@ private void disableLastChannelItem() {
element.addClassName("list-group-item disabled");
}

private void loadSsidData() {
private void loadSsidData(boolean recompute) {
this.ssidDataProvider.getList().clear();
this.searching.setVisible(true);
this.noSsid.setVisible(false);
Expand All @@ -1487,8 +1506,7 @@ public void onSuccess(GwtXSRFToken token) {
TabWirelessUi.this.gwtNetworkService.findWifiHotspots(token,
TabWirelessUi.this.selectedNetIfConfig.getName(),
TabWirelessUi.this.selectedNetIfConfig.getAccessPointWifiConfig().getWirelessSsid(),
false,
new AsyncCallback<List<GwtWifiHotspotEntry>>() {
recompute, new AsyncCallback<List<GwtWifiHotspotEntry>>() {

@Override
public void onFailure(Throwable caught) {
Expand Down Expand Up @@ -1527,7 +1545,7 @@ public void onSuccess(List<GwtWifiHotspotEntry> result) {
}

private int getChannelIndexFromValue(int channelValue) {

logger.info("getChannelIndexFromValue for channel: " + channelValue);

if (channelValue == 0) {
Expand Down Expand Up @@ -1762,7 +1780,7 @@ public void onFailure(Throwable caught) {

@Override
public void onSuccess(List<GwtWifiChannelFrequency> freqChannels) {

logger.info("Processing result from findFrequencies for "
+ TabWirelessUi.this.selectedNetIfConfig.getName() + "/" + radioMode);

Expand All @@ -1772,13 +1790,18 @@ public void onSuccess(List<GwtWifiChannelFrequency> freqChannels) {

freqChannels.stream().forEach(TabWirelessUi.this::addItemChannelList);

int channel = TabWirelessUi.this.activeConfig.getChannels().get(0);
List<Integer> currentChannels = TabWirelessUi.this.activeConfig.getChannels();

if (currentChannels != null && !currentChannels.isEmpty()) {
int channel = TabWirelessUi.this.activeConfig.getChannels().get(0);

int selectedChannelIndex = getChannelIndexFromValue(channel);
int channelIndex = selectedChannelIndex == -1 ? 0 : selectedChannelIndex;
int selectedChannelIndex = getChannelIndexFromValue(channel);
int channelIndex = selectedChannelIndex == -1 ? 0 : selectedChannelIndex;

logger.info("Setting channel to: " + channel);
TabWirelessUi.this.channelList.setSelectedIndex(channelIndex);
logger.info("Setting channel to: " + channel);
TabWirelessUi.this.channelList.setSelectedIndex(channelIndex);

}

boolean hasChannels = TabWirelessUi.this.channelList.getItemCount() > 0;

Expand Down Expand Up @@ -1863,8 +1886,7 @@ public void onSuccess(Boolean acSupported) {
private void fillRadioMode(boolean acSupported) {
if (!this.isNet2) {
for (GwtWifiRadioMode mode : GwtWifiRadioMode.values()) {
if (Boolean.FALSE.equals(acSupported)
&& mode == GwtWifiRadioMode.netWifiRadioModeANAC) {
if (Boolean.FALSE.equals(acSupported) && mode == GwtWifiRadioMode.netWifiRadioModeANAC) {
continue;
}
this.radio.addItem(MessageUtils.get(mode.name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
<b:Alert type="DANGER" ui:field="scanFail">
<b.html:Text ui:field="scanFailText" />
</b:Alert>
<b:Button ui:field="buttonSsidForceUpdate" icon="SEARCH" iconFixedWidth="true" text="{msgs.netWifiWirelessForceScan}" />
</b:PanelBody>
</b:Panel>
</b:ModalBody>
Expand All @@ -283,6 +284,6 @@
</b:PanelBody>
</b:Panel>
</b:ModalBody>
</b:Modal>
</b:Modal>
</b:Container>
</ui:UiBinder>
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ netWifiWirelessPasswordDoesNotMatch=Passwords do not match
netWifiWirelessEnabledForWANError=Invalid selection when TCP/IP is Enabled for WAN
netWifiWirelessWpaAcceptedProtocols=Accepted Protocols
netWifiWirelessPairwiseCiphers=Pairwise Ciphers
netWifiWirelessGroupCiphers= Group Ciphers
netWifiWirelessGroupCiphers=Group Ciphers
netWifiWirelessBgscanModule=Bgscan Module
netWifiWirelessBgscanSignalStrengthThreshold=Bgscan Signal Strength Threshold (dBm)
netWifiWirelessBgscanShortInterval=Bgscan Short Interval (secs)
Expand All @@ -546,6 +546,7 @@ netWifiWirelessPingAccessPoint=Ping Access Point & renew DHCP lease if not reach
netWifiWirelessIgnoreSSID=Ignore Broadcast SSID
netWifiWirelessInvalidSSID=Invalid SSID name.
netWifiWirelessAccessList=Access List
netWifiWirelessForceScan=Force Wireless Network Scan
netWifiToolTipWirelessMode=<b>Station Mode</b><br>Connect to a wireless access point. Input the access point''s SSID as the Network Name, select the Wireless Security it is configured with, and enter a password if needed.<br><br><b>Access Point</b><br>Create a wireless access point. Specify a Network Name for the access point, then select a Wireless Security type and enter a password as needed. Select other options as appropriate.
netWifiToolTipWirelessModeDisabled=The wireless interface is not used
netWifiToolTipWirelessModeStation=Connect to a wireless access point. Input the access point''s SSID as the Network Name, select the Wireless Security it is configured with, and enter a password if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.RETURNS_SMART_NULLS;
import static org.mockito.Mockito.atLeastOnce;
Expand Down Expand Up @@ -91,10 +92,15 @@
import org.junit.After;
import org.junit.Test;

import fi.w1.Wpa_supplicant1;
import fi.w1.wpa_supplicant1.Interface;

public class NMDbusConnectorTest {

private static final String MM_MODEM_BUS_NAME = "org.freedesktop.ModemManager1.Modem";
private final DBusConnection dbusConnection = mock(DBusConnection.class, RETURNS_SMART_NULLS);
private final Wpa_supplicant1 mockedWpaSupplicant = mock(Wpa_supplicant1.class);
private final Interface mockedInterface = mock(Interface.class);
private final NetworkManager mockedNetworkManager = mock(NetworkManager.class);
private final ModemManager1 mockedModemManager = mock(ModemManager1.class);
private final Settings mockedNetworkManagerSettings = mock(Settings.class);
Expand Down Expand Up @@ -909,6 +915,22 @@ public void applyingDisableConfigurationShouldCleanUnusedConnectionsIfActiveConn
thenConnectionIsNotDeleted("/connection/path/mock/5");
}

@Test
public void shouldTriggerWirelessNetworkScan() throws DBusException, IOException {

givenBasicMockedDbusConnector();
givenMockedDevice("wlan0", "wlan0", NMDeviceType.NM_DEVICE_TYPE_WIFI, NMDeviceState.NM_DEVICE_STATE_FAILED,
true, false, false);
givenMockedDeviceList();

whenGetInterfaceStatusWithRecompute("wlan0", this.commandExecutorService);

thenNoExceptionIsThrown();
thenInterfaceStatusIsNotNull();
thenNetInterfaceTypeIs(NetworkInterfaceType.WIFI);
thenScanIsTriggered();
}

/*
* Given
*/
Expand All @@ -927,6 +949,16 @@ public void givenBasicMockedDbusConnector() throws DBusException, IOException {
when(this.dbusConnection.getRemoteObject(eq("org.freedesktop.ModemManager1"),
eq("/org/freedesktop/ModemManager1"), any()))
.thenReturn(this.mockedModemManager);

when(this.dbusConnection.getRemoteObject(eq("fi.w1.wpa_supplicant1"),
eq("/fi/w1/wpa_supplicant1"), any())).thenReturn(this.mockedWpaSupplicant);

DBusPath fakeDbusInterfacePath = new DBusPath("/fake/dbus/path");

when(this.mockedWpaSupplicant.GetInterface(anyString())).thenReturn(fakeDbusInterfacePath);

when(this.dbusConnection.getRemoteObject(eq("fi.w1.wpa_supplicant1"), eq(fakeDbusInterfacePath.getPath()), any()))
.thenReturn(this.mockedInterface);

}

Expand Down Expand Up @@ -1339,7 +1371,24 @@ private void whenApplySingleIsCalledWith(String deviceId) {

private void whenGetInterfaceStatus(String netInterface, CommandExecutorService commandExecutorService) {
try {
this.netInterface = this.instanceNMDbusConnector.getInterfaceStatus(netInterface, commandExecutorService);
this.netInterface = this.instanceNMDbusConnector.getInterfaceStatus(netInterface, false,
commandExecutorService);
} catch (DBusException e) {
this.hasDBusExceptionBeenThrown = true;
} catch (NoSuchElementException e) {
this.hasNoSuchElementExceptionThrown = true;
} catch (NullPointerException e) {
this.hasNullPointerExceptionThrown = true;
} catch (KuraException e) {
this.hasKuraExceptionThrown = true;
}
}

private void whenGetInterfaceStatusWithRecompute(String netInterface,
CommandExecutorService commandExecutorService) {
try {
this.netInterface = this.instanceNMDbusConnector.getInterfaceStatus(netInterface, true,
commandExecutorService);
} catch (DBusException e) {
this.hasDBusExceptionBeenThrown = true;
} catch (NoSuchElementException e) {
Expand Down Expand Up @@ -1466,6 +1515,10 @@ private void thenLocationSetupWasCalledWith(EnumSet<MMModemLocationSource> expec
.Setup(MMModemLocationSource.toBitMaskFromMMModemLocationSource(expectedLocationSources), expectedFlag);
}

private void thenScanIsTriggered() {
verify(this.mockedInterface, times(1)).Scan(any());
}

private void thenModemStatusHasCorrectValues(boolean hasBearers, boolean hasSims) {
assertTrue(this.netInterface instanceof ModemInterfaceStatus);
ModemInterfaceStatus modemStatus = (ModemInterfaceStatus) this.netInterface;
Expand Down
Loading

0 comments on commit f1859f1

Please sign in to comment.