(request: WSGIRequest)
return render(request, "network_info.html", context)
Renders the /network_info page. Only admin is allowed to see this page.
Renders the /network_info page. Only admin is allowed to see this page.
Renders the / network_info page . Only admin is allowed to see this page .
def index(request: WSGIRequest) -> HttpResponse:
    """Renders the /network_info page. Only admin is allowed to see this page."""
    context = base.context(request)

    # hotspot information
    context["hotspot_enabled"] = False
    try:
        if subprocess.call(["/usr/local/sbin/raveberry/hotspot_enabled"]) != 0:
            # Hotspot is enabled, show its info as well
            context["hotspot_enabled"] = True

            with open("/etc/hostapd/hostapd_protected.conf") as f:
                for line in f:
                    line = line.strip()
                    if line.startswith("ssid"):
                        ssid = line.split("=")[1]
                    if line.startswith("wpa_passphrase"):
                        password = line.split("=")[1]

            device = util.get_devices()[-1]
            ip = util.ip_of_device(device)
            url = f"http://{ip}/"

            context["hotspot_ssid"] = ssid
            context["hotspot_password"] = password
            context["hotspot_wifi_qr"] = _qr_path(f"WIFI:S:{ssid};T:WPA;P:{password};;")
            context["hotspot_url"] = url
            context["hotspot_url_qr"] = _qr_path(url)
            context["hotspot_ip"] = ip
    except FileNotFoundError:
        # hotspot was not configured
        pass

    # connected network information
    ssid = None
    password = None
    try:
        ssid = subprocess.check_output(
            "/sbin/iwgetid --raw".split(), universal_newlines=True
        )[:-1]
        wifi_active = True
    except (subprocess.CalledProcessError, FileNotFoundError):
        wifi_active = False

    if wifi_active:
        try:
            password = subprocess.check_output(
                ["sudo", "/usr/local/sbin/raveberry/password_for_ssid", ssid],
                universal_newlines=True,
            )
        except subprocess.CalledProcessError:
            pass

    device = util.get_devices()[0]
    ip = util.ip_of_device(device)

    wifi_qr = _qr_path(f"WIFI:S:{ssid};T:WPA;P:{password};;")
    raveberry_url = f"http://{ip}/"
    raveberry_qr = _qr_path(raveberry_url)

    if wifi_active:
        context["ssid"] = ssid
        context["password"] = password
        context["wifi_qr"] = wifi_qr
    else:
        context["ssid"] = None
        context["password"] = None
        context["wifi_qr"] = None
    context["url"] = raveberry_url
    context["url_qr"] = raveberry_qr
    context["ip"] = ip
    return render(request, "network_info.html", context)
def index ( request : WSGIRequest ) -> HttpResponse : context = base . context ( request ) # hotspot information context [ "hotspot_enabled" ] = False try : if subprocess . call ( [ "/usr/local/sbin/raveberry/hotspot_enabled" ] ) != 0 : # Hotspot is enabled, show its info as well context [ "hotspot_enabled" ] = True with open ( "/etc/hostapd/hostapd_protected.conf" ) as f : for line in f : line = line . strip ( ) if line . startswith ( "ssid" ) : ssid = line . split ( "=" ) [ 1 ] if line . startswith ( "wpa_passphrase" ) : password = line . split ( "=" ) [ 1 ] device = util . get_devices ( ) [ - 1 ] ip = util . ip_of_device ( device ) url = f"http://{ip}/" context [ "hotspot_ssid" ] = ssid context [ "hotspot_password" ] = password context [ "hotspot_wifi_qr" ] = _qr_path ( f"WIFI:S:{ssid};T:WPA;P:{password};;" ) context [ "hotspot_url" ] = url context [ "hotspot_url_qr" ] = _qr_path ( url ) context [ "hotspot_ip" ] = ip except FileNotFoundError : # hotspot was not configured pass # connected network information ssid = None password = None try : ssid = subprocess . check_output ( "/sbin/iwgetid --raw" . split ( ) , universal_newlines = True ) [ : - 1 ] wifi_active = True except ( subprocess . CalledProcessError , FileNotFoundError ) : wifi_active = False if wifi_active : try : password = subprocess . check_output ( [ "sudo" , "/usr/local/sbin/raveberry/password_for_ssid" , ssid ] , universal_newlines = True , ) except subprocess . CalledProcessError : pass device = util . get_devices ( ) [ 0 ] ip = util . ip_of_device ( device ) wifi_qr = _qr_path ( f"WIFI:S:{ssid};T:WPA;P:{password};;" ) raveberry_url = f"http://{ip}/" raveberry_qr = _qr_path ( raveberry_url ) if wifi_active : context [ "ssid" ] = ssid context [ "password" ] = password context [ "wifi_qr" ] = wifi_qr else : context [ "ssid" ] = None context [ "password" ] = None context [ "wifi_qr" ] = None context [ "url" ] = raveberry_url context [ "url_qr" ] = raveberry_qr context [ "ip" ] = ip return render ( request , "network_info.html" , context )