예제 #1
0
def getBackhaulStatus():
    """Returns the status of the backhaul interface"""

    nopeer = {"snr":0,"signal":0,"noise":0}
    
    ifaces = getInterfaces(returnOne=BACKHAUL_IFNAME)
    if len(ifaces) != 1:
        return ("critical", "Backhaul interface not found", nopeer)
    iface = ifaces[0]
    wiface = iwtools.get_interface(BACKHAUL_IFNAME)

    if not iface["up"]:
        ifaces = debian_interfaces()
        apname = ifaces[BACKHAUL_IFNAME]["wpa-ssid"].replace(ESSID_PREFIX, "")
        return ("critical", "%s - Not associated" % apname, nopeer)
    
    essid = wiface.get_essid()
    if not essid.startswith(ESSID_PREFIX) and essid != "Any":
        log_warn("Associated to invalid AP: %s" % essid)
        return ("warning", "Not associated to correct Access Point", nopeer)
    parts = essid.split("-")

    stats = wiface.get_stats()
    if getActiveUsername() != getISPUsername():
        return ("warning", "Connected as '%s' not '%s'" % \
                (getActiveUsername(), getISPUsername()), stats)

    return ("ok", "%s" % "-".join(parts[1:]), stats)
예제 #2
0
def checkUpstream():
    
    ifaces = debian_interfaces()
    diface = ifaces[BACKHAUL_IFNAME]
    if diface["wpa-ssid"] == "default":
        # Not configured, scan for valid APs
        try:
            log_command("/sbin/ip link set up dev %s 2>&1" % BACKHAUL_IFNAME)
            wiface = iwtools.get_interface(BACKHAUL_IFNAME)
            scanres = wiface.scanall()
        except:
            log_error("Could not complete scan on backhaul interface (%s)!" % \
                    BACKHAUL_IFNAME, sys.exc_info())
            scanres = []
        # Exclude networks that don't match our ESSID
        aps = [ n for n in scanres if n.essid.startswith(ESSID_PREFIX)]
        # Pick the one with the highest SNR
        best = None
        for ap in aps:
            if best is None or ap.qual["snr"] > best.qual["snr"]:
                best = ap
        # Select it
        if best is not None:
            log_info("Selecting Access Point '%s' based on SNR strength" % \
                    best.essid)
            configureBhaulInterface(best.essid)

        # Hope for the best
        return

    # Check that the backhaul is up
    doUp = False
    ifaces = getInterfaces(returnOne=BACKHAUL_IFNAME)
    if len(ifaces) != 1:
        ensureBackhaulUp()
        return

    iface = ifaces[0]        
    if not iface["up"]:
        ensureBackhaulUp()
        return
    
    # Check credentials are up to date
    if diface["wpa-identity"] != getActiveUsername() or \
            diface["wpa-password"] != getActivePassword():
        # Take down so that we re-authenticate
        log_info("Triggering reassociation to update credentials")
        log_command("/sbin/ifdown %s 2>&1" % BACKHAUL_IFNAME)
        ensureBackhaulUp()
        return

    # Check IP layer is OK
    dg = getGatewayIP()
    if dg == "":
        log_info("Triggering reassociation to acquire gateway")
        log_command("/sbin/ifdown %s 2>&1" % BACKHAUL_IFNAME)
        ensureBackhaulUp()
        return
예제 #3
0
def getBackhaulHTML(submitButtons=True, inputPrefix=""):
    
    othernets = {}
    output = ""

    try:
        ensureBackhaulUp()
        wiface = iwtools.get_interface(BACKHAUL_IFNAME)
        scanres = wiface.scanall()
    except:
        log_error("Could not complete scan on backhaul interface (%s)!" % \
                BACKHAUL_IFNAME, sys.exc_info())
        scanres = []

    n=0
    for network in scanres:
        if not network.essid.startswith(ESSID_PREFIX):
            # Skip non matching networks
            othernets[network.essid] = (network.channel, network.qual)
            continue
        # Get the AP name from the ESSID
        parts = network.essid.split("-")
        if len(parts) < 2:
            othernets[network.essid] = (network.channel, network.qual)
            continue
        name = "-".join(parts[1:])

        # Write the record
        output += """<h3>%s</h3>
        <div id="ssmeter-%s" class="ssmeter">%s</div>
        <div style="clear: all;">&nbsp;</div><br />
        """ % (name, name, getSSMeter(network.qual))
        
        if submitButtons:
            output += """<form action="/admin/setup_backhaul" method="post">
            <input type="hidden" name="essid" value="%s" />
            <input type="submit" value="Connect to %s &gt;&gt;" />
            </form><br />""" % (network.essid, name)
        else:
            output += """Connect to <b>'%s'</b>&nbsp;<input type="radio" """ \
                    """id="%sessid" name="%sessid" value="%s" /><br />""" % \
                    (name, inputPrefix, inputPrefix, network.essid)
        output += "<br />"
        n+=1 

    if n==0:
        output += "<br /><b>No access points found to connect to!</b>" \
                "<br /><br />"

    return (output, othernets)