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

Method connect_wifi

utils.py:472–498  ·  view source on GitHub ↗
(self, handler)

Source from the content-addressed store, hash-verified

470 return networks
471
472 def connect_wifi(self, handler):
473 try:
474 content_length = int(handler.headers['Content-Length'])
475 post_data = handler.rfile.read(content_length).decode('utf-8')
476 params = json.loads(post_data)
477 ssid = params['ssid']
478 password = params['password']
479
480 self.update_nmconnection(ssid, password)
481 command = f'sudo nmcli connection up "preconfigured"'
482 connect_result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
483 stdout, stderr = connect_result.communicate()
484 if connect_result.returncode != 0:
485 raise Exception(stderr)
486
487 self.shared_data.wifichanged = True
488
489 handler.send_response(200)
490 handler.send_header('Content-type', 'application/json')
491 handler.end_headers()
492 handler.wfile.write(json.dumps({"status": "success", "message": "Connected to " + ssid}).encode('utf-8'))
493
494 except Exception as e:
495 handler.send_response(500)
496 handler.send_header('Content-type', 'application/json')
497 handler.end_headers()
498 handler.wfile.write(json.dumps({"status": "error", "message": str(e)}).encode('utf-8'))
499
500 def disconnect_and_clear_wifi(self, handler):
501 try:

Callers

nothing calls this directly

Calls 5

update_nmconnectionMethod · 0.95
decodeMethod · 0.45
readMethod · 0.45
writeMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected