| 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] |
| 713 | id=preconfigured |
| 714 | uuid={uuid.uuid4()} |
| 715 | type=wifi |
| 716 | autoconnect=true |
| 717 | |
| 718 | [wifi] |
| 719 | ssid={ssid} |
| 720 | mode=infrastructure |
| 721 | |
| 722 | [wifi-security] |
| 723 | key-mgmt=wpa-psk |
| 724 | psk={password} |
| 725 | |
| 726 | [ipv4] |
| 727 | method=auto |
| 728 | |
| 729 | [ipv6] |
| 730 | method=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: |