예제 #1
0
파일: pifi.py 프로젝트: ihelal/pifi
def remove(ssid):
    for device in nm.managedWifiDevices():
        if device.State == NetworkManager.NM_DEVICE_STATE_ACTIVATED:
            current_connection = device.GetAppliedConnection(0)
            # SSID returned as list of bytes
            if ssid == b''.join(current_connection[0]['802-11-wireless']
                                ['ssid']).decode("utf-8"):
                print("WARN: Connection is currently active")
                print("WARN: Deleting can disrupt existing SSH connetions")
                if query_yes_no("Continue Deletion?") == False:
                    return

    pending = var_io.readPendingConnections()
    for con in pending:
        if ssid == con['802-11-wireless']['ssid']:
            pending.remove(con)

    try:
        var_io.writePendingConnections(pending)
    except PermissionError:
        print(
            "Error writing to /var/lib/pifi/pending, make sure you are running with sudo"
        )
        return

    for con in nm.existingConnections():
        settings = con.GetSettings()
        if ssid == settings['802-11-wireless']['ssid']:
            pass
            con.Delete()
예제 #2
0
    def test_managed_wifi_devices_no_devices(self):
        nm = mock.MagicMock()
        nm.configure_mock(**{'NetworkManager.GetDevices.return_value': list()})

        generator = nm_helper.managedWifiDevices(NetworkManager=nm)
        with self.assertRaises(StopIteration):
            next(generator)
예제 #3
0
    def test_managed_wifi_devices_no_wifi_devices(self):
        dev = mock.MagicMock()
        dev.configure_mock(**{'DeviceType': 0})

        nm = mock.MagicMock()
        nm.configure_mock(
            **{
                'NetworkManager.GetDevices.return_value': [dev],
                'NM_DEVICE_TYPE_WIFI': 2
            })

        generator = nm_helper.managedWifiDevices(NetworkManager=nm)
        with self.assertRaises(StopIteration):
            next(generator)
예제 #4
0
파일: pifi.py 프로젝트: MoffKalast/pifi
def remove(argv):
    parser = argparse.ArgumentParser(
        description="Remove a network from both pending and current connections"
    )
    parser.add_argument("ssid")
    parser.add_argument("-y", action="store_true")
    args = parser.parse_args(argv)

    ssid = args.ssid
    skip_prompt = args.y

    for device in nm.managedWifiDevices():
        if device.State == NetworkManager.NM_DEVICE_STATE_ACTIVATED:
            current_connection = device.GetAppliedConnection(0)
            # SSID returned as list of bytes
            if ssid == b"".join(
                current_connection[0]["802-11-wireless"]["ssid"]
            ).decode("utf-8"):
                print("WARN: Connection is currently active")
                print("WARN: Deleting can disrupt existing SSH connetions")

                # If skip_prompt is true, short circuit the if, otherwise go into the query
                if not skip_prompt and not query_yes_no("Continue Removal?"):
                    return

    pending = var_io.readPendingConnections()
    for con in pending:
        if ssid == con["802-11-wireless"]["ssid"]:
            pending.remove(con)

    try:
        var_io.writePendingConnections(pending)
    except PermissionError:
        print(
            "Error writing to /var/lib/pifi/pending, make sure you are running with sudo"
        )
        return

    for con in nm.existingConnections():
        settings = con.GetSettings()
        if ssid == settings["802-11-wireless"]["ssid"]:
            pass
            con.Delete()