Example #1
0
File: pifi.py Project: 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()
Example #2
0
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()