Пример #1
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"])
Пример #2
0
def solarpage(request, method):
    """Returns information about the solar controller attached to this node"""
    global ts_id, amphours_reset
    
    if request.query.find("resetAH=true") != -1:
        log_info("Resetting AMP hours at user request")
        reset_amphours()
    
    ah_reset = time.strftime("%c", time.localtime(amphours_reset))
    info = (ts_id, ts_serial(), ts_hwver(), ts_battv(), ts_battsensev(), \
            ts_arrayv(), ts_chargei(), ts_battvs(), \
            ts_readreg(TS_HSTEMP_DEG), ts_readreg(TS_BATTEMP_DEG), ts_refv(), \
            ah_reset, ts_amphours(), ts_totalamphours(), ts_controlmode_s(), \
            ts_controlstate_s(), ts_pwm(), ts_readreg(TS_KWH))
    
    # Build interfaces information
    output = """<div class="content">
<h2>Solar Controller (%s) Status</h2><br />
<style>
TH {
    width: 20em;
}
</style>
<div>
<table cellpadding=2 cellspacing=1 border=0>
<tbody>
<tr>
    <th>Serial Number:</th>
    <td>%s</td>
</tr>
<tr>
    <th>Hardware Version:</th>
    <td>%s</td>
</tr>
<tr>
    <th>Battery Voltage:</th>
    <td>%2.2fV</td>
</tr>
<tr>
    <th>Battery Sense Voltage:</th>
    <td>%2.2fV</td>
</tr>
<tr>
    <th>Array Voltage:</th>
    <td>%2.2fV</td>
</tr>
<tr>
    <th>Charge Current:</th>
    <td>%2.2fA</td>
</tr>
<tr>
    <th>Battery Voltage (Slow):</th>
    <td>%2.2fV</td>
</tr>
<tr>
    <th>Heatsink Temperature:</th>
    <td>%2.0fC</td>
</tr>
<tr>
    <th>Battery Temperature:</th>
    <td>%2.0fC</td>
</tr>
<tr>
    <th>Reference Voltage:</th>
    <td>%2.2fV</td>
</tr>
<tr>
    <th>Amp Hours<br />(since %s):</th>
    <td valign="top">%s&nbsp;&nbsp;
    <a href="/status/solar?resetAH=true">[reset now]</a>
    </td>
</tr>
<tr>
    <th>Amp Hours (Total):</th>
    <td>%s</td>
</tr>
<tr>
    <th>Control Mode:</th>
    <td>%s</td>
</tr>
<tr>
    <th>Control State:</th>
    <td>%s</td>
</tr>
<tr>
    <th>PWM Duty Cycle:</th>
    <td>%d%%</td>
</tr>
<tr>
    <th>Kilowatt Hours:</th>
    <td>%s</td>
</tr>
</tbody>
</table>
</div>
""" % info

    returnPage(request, "Solar Controller Status", output) 
Пример #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