Beispiel #1
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)
Beispiel #2
0
def admin_setupbackhaul(request, method):
    """Returns the HTML for backhaul setup page"""
   
    errmsg = ""

    if method == "POST":
        data = request.getPostData()
        # Incoming data
        if "essid" in data.keys():
            if configureBhaulInterface(data["essid"]):
                return admin(request, "GET")
            # Failed
            parts = data["essid"].split("-")
            ap = "-".join(parts[1:])
            errmsg = "Failed to associate with %s" % ap
        
    # Normal page GET
    output = """<div class="content">
<h2>CPE Administration - Select Access Point</h2><br />
Please select the access point to connect to from the following list.
<br /><br />
"""
    if errmsg != "":
        output += """<span class="error">%s</span><br /><br />""" % errmsg
        
    (toutput, othernets) = getBackhaulHTML()
    output += toutput

    if len(othernets.keys()) > 0:
        output += """<h2>Other networks</h2><br />
        The following other networks were detected. This CPE is not
        able to connect to these networks. You may need to
        co-ordinate channel usage with the operators of the listed 
        networks to minimise the chance of interference.<br /><br />
        """
        for essid, (channel,qual) in othernets.items():
            output += """<h3>%s on Channel %s</h3>
            <div id="ssmeter-%s" class="ssmeter">%s</div>
            <div style="clear: all;">&nbsp;</div><br /><br />
            """ % (essid, channel, essid, getSSMeter(qual))

    output += """<a href="/admin">&lt;&lt;&nbsp;Return to CPE 
    Administration page</a><br />"""

    return returnPage(request, "CPE Administration", output, \
                scripts=["/resources/admin.js"])
Beispiel #3
0
def admin(request, method, returnDirect=True):
    """Returns the HTML for administration page"""
    
    isperr = ""
    reconnect = False

    if method == "POST":
        data = request.getPostData()
        # Incoming data
        invalid=True
        if "password" in data.keys():
            try:
                if data["password"] == "":
                    raise ccs_cpe_error("Cannot set blank password!")
                if len(data["password"]) < 8:
                    raise ccs_cpe_error("Password must be at " \
                            "least 8 characters!")
                # Now change the password
                setCPEPassword(data["password"])
            except ccs_cpe_error:
                (type, value, tb) = sys.exc_info()
                request.send_error(400, value)
                request.end_headers()
                request.finish()
                return
            except:
                log_error("Failed to change password!", \
                        sys.exc_info())
                request.send_error(400, "Unexpected Error")
                request.end_headers()
                request.finish()
                return
            request.send_response(200, "Password updated")
            request.end_headers()
            request.finish()
            return
        if "isppassword" in data.keys():
            try:
                # Now change the details
                setISPDetails(data["ispusername"], data["isppassword"])
            except ccs_cpe_error:
                (type, value, tb) = sys.exc_info()
                isperr = value
            except:
                log_error("Failed to change password!", \
                        sys.exc_info())
                isperr = "Could not change password!"
            if isperr == "":
                reconnect = True
            invalid = False
        elif "reconnect" in data.keys():
            log_info("User Triggered reassociation to update credentials")
            log_command("/sbin/ifdown %s 2>&1" % BACKHAUL_IFNAME)
            ensureBackhaulUp()
            request.send_response(200, "Reconnected")
            request.end_headers()
            request.finish()
            return
        elif "reset" in data.keys():
            try:
                resetCPE()
            except:
                remountro("factory-reset")
                log_error("Exception resetting device", sys.exc_info())
                request.send_error(400, "Failed to reset device")
                request.end_headers()
                request.finish()
                return
            log_info("Device reset complete. Factory configuration restored")
            request.send_response(200, "Device reset")
            request.end_headers()
            request.finish()
            return
        elif "restart" in data.keys():
            # Device config has been reset, restart crcnet-monitor
            log_info("Received restart request from %s. Restarting..." % \
                    request.client_address[0])
            os.system("/etc/init.d/crcnet-monitor restart & 2>&1")
            request.send_response(200, "Device restarted")
            request.end_headers()
            request.finish()
            return
        
        if invalid:
            log_warn("Invalid POST request to /admin from %s" %
                    request.client_address[0]) 
            request.send_error(400, "Invalid method for this page!")
            request.end_headers()
            request.finish()
            return
    
    # Normal page GET
    output = """<div id="admin" class="content">
<h2>CPE Administration</h2><br />
<style>
TH:first-child {
    width: 14em;
}
</style>

<table>
<tr>
    <th>CPE Serial no:</th>
    <td>%s</td>
</tr>
<tr>
    <th valign="top">CPE Password:</th>
    <td><input id="password" value="*****"><br />
    <small>Enter the new admin password in the box above.</small></td>
</tr>
<tr>
    <th>Reset Device:</th>
    <td><input type="button" value="Reset to Default Settings" id="factory_reset"></td>
</tr>
</table>
<br />
""" % getCPESerial()

    # Configure the backhaul interface
    #################################
    if reconnect:
        bhaul_status = "warning"
        bhaul_desc = """<script language="javascript" type="text/javascript">
remaining=30
function progress() {
    remaining--;
    if (remaining == 0) {
        clearInterval(id);
        reload();
        return;
    }
    $("rem").innerHTML=remaining;
}
function reload() {
    l = document.location.toString();
    document.location = l;
}
id = window.setInterval(progress, 1000);
pars="reconnect=true";
myAjax = new Ajax.Request("/admin", {method: 'post', postBody: pars});
</script>
Details updated. Reconnecting... <span id="rem">30</span> seconds left
"""
        change = ""
    else:
        bhaul_status, bhaul_desc, stats = getBackhaulStatus()
        change = """<a href="/admin/setup_backhaul">[change]</a>"""
    if isperr != "":
        isperr = "<div class=\"statuserror\">%s</div>" % isperr

    output += """
<h2>Backhaul Settings (using %s interface)</h2><br />
<form method="post" action="/admin">
%s
<table>
<tr>
<th>Access Point:</th>
<td><span class="status%s">%s</span>&nbsp;&nbsp;%s
</td>
</tr>
<tr>
<th>Username:</th>
<td><input name="ispusername" value="%s"></td>
</tr>
<tr>
<th>Password:</th>
<td><input name="isppassword" value="%s"></td>
</tr>
<tr>
<tr>
<th>Save Details:</th>
<td><input type="submit" value="Save Username &amp; Password"></td>
</tr>
<tr>
</table>
""" % (BACKHAUL_IFNAME, isperr, bhaul_status, bhaul_desc, change, 
        getISPUsername(), getISPPassword())
    if not reconnect:
        output += """<div id="ssmeter-%s" class="ssmeter">""" % BACKHAUL_IFNAME
        output += getSSMeter(stats)
        output += "</div><br clear=\"all\" />"
        output += "<a href=\"/status/interfaces\">Click here for detailed " \
                "signal strength information</a><br /><br />"

    output += """
</div>
<div id="reset" class="content hidden">
<h2>Resetting Device...</h2><br />
<br />
Please wait while your device is reset to its factory configuration.
This process may take up to 30 seconds to complete successfully.<br />
<br />
<div id="resetstatus" style="font-weight:bold;"></div>
</div>
"""
        
    # Return the page
    if returnDirect:
        return returnPage(request, "CPE Administration", output, \
                scripts=["/resources/admin.js"])
    else:
        return output