MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / update_nmconnection

Method update_nmconnection

utils.py:708–733  ·  view source on GitHub ↗
(self, ssid, password)

Source from the content-addressed store, hash-verified

706 handler.wfile.write(json.dumps({"status": "error", "message": str(e)}).encode('utf-8'))
707
708 def update_nmconnection(self, ssid, password):
709 config_path = '/etc/NetworkManager/system-connections/preconfigured.nmconnection'
710 with open(config_path, 'w') as f:
711 f.write(f"""
712[connection]
713id=preconfigured
714uuid={uuid.uuid4()}
715type=wifi
716autoconnect=true
717
718[wifi]
719ssid={ssid}
720mode=infrastructure
721
722[wifi-security]
723key-mgmt=wpa-psk
724psk={password}
725
726[ipv4]
727method=auto
728
729[ipv6]
730method=auto
731""")
732 subprocess.Popen(['sudo', 'chmod', '600', config_path]).communicate()
733 subprocess.Popen(['sudo', 'nmcli', 'connection', 'reload']).communicate()
734
735 def save_configuration(self, handler):
736 try:

Callers 1

connect_wifiMethod · 0.95

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected