Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Import existing networks from wpa_supplicant #227

Open
Miniontoby opened this issue Jul 9, 2023 · 8 comments
Open

[feature] Import existing networks from wpa_supplicant #227

Miniontoby opened this issue Jul 9, 2023 · 8 comments

Comments

@Miniontoby
Copy link

Miniontoby commented Jul 9, 2023

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
@davesteele
Copy link
Owner

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

Comitup will use any predefined NetworkManager WiFi connections.

@Miniontoby
Copy link
Author

Miniontoby commented Jul 10, 2023

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

@davesteele
Copy link
Owner

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

@Miniontoby
Copy link
Author

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

@davesteele
Copy link
Owner

comitup-cli

The Comitup class in statemgr.py.

@davesteele
Copy link
Owner

... and look at the man pages.

@Miniontoby
Copy link
Author

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)

@davesteele
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants