Changeset 1060


Ignore:
Timestamp:
09/20/06 16:27:25 (8 years ago)
Author:
mglb1
Message:

Fixed bugs with fetching the MOTD

  • Fetch the MOTD via an Ajax call
  • Add a configuration parameter to completely disable fetching the MOTD

Until we get a multi-threaded server fetching the MOTD from a server
that is unavailable has the potential to block the entire server for
up to 2 minutes, which is rather unpleasant.

Fixes #30

Location:
ccsd
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • ccsd/private/resources/rurallink.js

    r1051 r1060  
    7070}; 
    7171Behaviour.register(myrules); 
    72 Behaviour.addLoadEvent(initialisePage); 
     72mvBehaviour.addLoadEvent(initialisePage); 
    7373 
    7474function doAjaxWizard() { 
  • ccsd/trunk/crcnetd/_utils/ccsd_cfengine.py

    r1041 r1060  
    11191119    # PHP sends in an associative array we want the values only 
    11201120    hosts = hosts.values() 
     1121    print hosts 
    11211122 
    11221123    # Loop through the specified hosts and mark them as pending 
  • ccsd/trunk/crcnetd/modules/ccs_monitor_web.py

    r1045 r1060  
    2828from crcnetd._utils.ccsd_clientserver import registerPage, registerDir, \ 
    2929        registerRealm 
    30 from crcnetd._utils.ccsd_config import config_get, init_pref_store, pref_get 
     30from crcnetd._utils.ccsd_config import config_get, init_pref_store, pref_get, \ 
     31        config_getboolean 
    3132from crcnetd.version import ccsd_version, ccsd_revision 
    3233 
     
    332333# Content Pages 
    333334############################################################################## 
    334 def displayMOTD(request): 
     335@registerPage("/motd") 
     336def getMOTD(request, method): 
    335337    """Returns HTML to display the Message of the Day""" 
    336338     
     
    340342            DEFAULT_MOTD_REFRESH) 
    341343    motdURL = config_get("www", "motdURL", DEFAULT_MOTD_URL) 
     344    fetchMotd = config_getboolean("www", "fetch_motd", False) 
    342345    updateNote = "" 
    343346     
     
    347350        mtime = -1 
    348351 
    349     if mtime == -1 or time.time()-mtime > motdRefreshInterval or \ 
    350             request.query.find("refreshMotd=true") != -1: 
     352    if (mtime == -1 or time.time()-mtime > motdRefreshInterval or \ 
     353            request.query.find("refreshMotd=true") != -1) and fetchMotd: 
    351354        # Get new MOTD 
    352355        try: 
     
    366369            mtime = -1 
    367370    else: 
    368         fd = open(motdFile, "r") 
    369         motd = fd.read() 
    370         fd.close() 
    371  
     371        try: 
     372            fd = open(motdFile, "r") 
     373            motd = fd.read() 
     374            fd.close() 
     375        except: 
     376            motd = "No news available" 
     377         
    372378    # Calculate how long till next update 
    373379    if mtime != -1: 
     
    378384 
    379385    # Generate the output 
    380     output = """<div class="content"> 
    381 <h2>Latest News <span class="note">%s&nbsp; 
     386    output = """<h2>Latest News <span class="note">%s&nbsp; 
    382387<a href="/?refreshMotd=true">[Refresh Now]</a> 
    383388</span> 
    384389</h2><br /> 
    385390%s 
    386 </div> 
    387391""" % (updateNote, motd.replace("\n", "<br />")) 
    388      
    389     return output 
     392 
     393    length = len(output) 
     394    request.send_response(200) 
     395    request.send_header("Length", length) 
     396    request.end_headers() 
     397    request.wfile.write(output) 
     398    request.finish() 
     399    return 
    390400 
    391401@registerPage("/") 
    392402def homepage(request, method): 
    393403     
    394     output = "" 
     404    output = """<div class="content" id="motd">""" 
    395405     
    396406    # MOTD at the top 
    397     output += displayMOTD(request) 
     407    output += "<h2>Loading Latest News...</h2><br />" 
     408    output += "Please wait while the latest news is retrieved." 
     409    output += "</div>" 
    398410     
    399411    # Try and load the status summary from the status module 
     
    412424""" % status 
    413425 
    414     returnPage(request, "CPE Navigation", output) 
     426    returnPage(request, "CPE Navigation", output,  
     427            scripts=["/resources/homepage.js"]) 
    415428 
    416429@registerPage("/contact") 
Note: See TracChangeset for help on using the changeset viewer.