comitup icon indicating copy to clipboard operation
comitup copied to clipboard

[feature] Import existing networks from wpa_supplicant

Open Miniontoby opened this issue 2 years ago • 8 comments

Hi,

Please add a way to (automaticly) import existing wifi network from wpa_supplicant (when installing)

I installed this a month ago on my pi zero which had already internet, but it didn't use the networks that were already in /etc/wpa_supplicant.conf (or how it is called).

If you would add this, then that would be nice. I know like nearly everyone installs this on a new pi, but I didn't and I saw this missed chance.

Btw I love this project. It is a very helpful utility if you don't have a screen and/or HDMI cable available.

Kind regards,

  • Miniontoby

Miniontoby avatar Jul 09 '23 16:07 Miniontoby

Comitup uses NetworkManager, which obsoletes wpa_supplicant.conf (and the interfaces file).

Comitup will use any predefined NetworkManager WiFi connections.

davesteele avatar Jul 09 '23 18:07 davesteele

Wait,

But that is NOT my question!

I know it makes wpa_supplicant.conf useless, but you should read out that file (at installation) for any predefined networks!

wpa_supplicant.conf has the networkname and password saved in plaintext

Miniontoby avatar Jul 10 '23 12:07 Miniontoby

I have no plans to do that, but I endeavor to review patches promptly.

davesteele avatar Jul 10 '23 16:07 davesteele

What command is ran to connect to a new network in this thing? Cause I can find dbus controlled, but I cannot find the code of the comitup dbus

Miniontoby avatar Jul 10 '23 17:07 Miniontoby

comitup-cli

The Comitup class in statemgr.py.

davesteele avatar Jul 10 '23 17:07 davesteele

... and look at the man pages.

davesteele avatar Jul 10 '23 18:07 davesteele

Here is a script to import from wpa_supplicant:

(it needs the comitup python lib to work, but it could be added in the apt install script after the lib has been installed)

#!/usr/bin/env python3

from re import finditer

try:
    from comitup.nm import make_connection_for
except:
    print ("[ERROR] Comitup python lib missing!")
    quit()

try:
    f = open("/etc/wpa_supplicant/wpa_supplicant.conf", "r")
except FileNotFoundError:
    print ("[WARNING] No wpa_supplicant file, skipping import")
    quit()

wpa_conf = f.read()
f.close()

matches = finditer(r"network=\{\n([\s\t]+(ssid=\"([^\"]+)\"|psk=\"([^\"]+)\"|[\w\=\"-_]+)\n)+\}( |)", wpa_conf)
for match in matches:
    ssid = match.group(3)
    psk = match.group(4)
    print ("[INFO] Adding {ssid} {psk}".format(ssid=ssid, psk="without psk" if psk is None else "with psk"))
    make_connection_for(ssid, psk)

Miniontoby avatar Jul 11 '23 12:07 Miniontoby

Thanks. It's not quite ready for inclusion in the package, but I've linked it from the Install Page. That should be on the path for those who would need it.

davesteele avatar Jul 11 '23 19:07 davesteele