Changeset 712


Ignore:
Timestamp:
06/01/06 04:34:21 (7 years ago)
Author:
mglb1
Message:
  • Retrieve DNS server IPs from the DSL modem and give them to pdnsd
  • Check pdnsd status at regular intervals to ensure we always have valid DNS information
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ccsd/private/modules/ccs_monitor_rurallink.py

    r710 r712  
    6767DSL_NETMASK = "8" 
    6868DSL_TELNET_TIMEOUT = 2 
     69 
     70# How often (seconds) to check DNS settings 
     71DNS_UPDATE_INTERVAL = 60 
    6972 
    7073ISP_IF_DISCONNECT = """<a href="/rladmin/isp-disconnect">[Disconnect]</a>""" 
     
    20162019    return "<i>No username configured</i>" 
    20172020     
     2021def getDSLNameservers(): 
     2022    """Retrieves the ISP allocated nameservers""" 
     2023    dns1 = None 
     2024    dns2 = None 
     2025    conn = None 
     2026    try: 
     2027        conn = DSLLogin() 
     2028    except: 
     2029        pass 
     2030    if conn is None: 
     2031        return None, None 
     2032 
     2033    # Ask for the DHCP server configuration details 
     2034    conn.write("get dhcp server cfg\n") 
     2035     
     2036    # Wait for the prompt 
     2037    r = conn.read_until("$", DSL_TELNET_TIMEOUT) 
     2038    conn.close() 
     2039                 
     2040    # Extract DHCP server addresses 
     2041    lines = r.strip().split("\n") 
     2042    for line in lines: 
     2043        if line.strip().startswith("Def Pri"): 
     2044            try: 
     2045                parts = line.split(":") 
     2046                dns1 = parts[1].split()[0].strip() 
     2047                dns2 = parts[2].strip() 
     2048            except: 
     2049                log_error("Could not parse DNS servers from DSL modem!") 
     2050                log_debug(line.strip()) 
     2051            break 
     2052    if dns1 == "0.0.0.0": dns1 = None 
     2053    if dns2 == "0.0.0.0": dns2 = None 
     2054 
     2055    # Return them 
     2056    return dns1, dns2 
     2057 
    20182058def connectDSL(): 
    20192059    """Tells the modem to connect""" 
     
    23792419        raise ccs_rurallink_error("Unknown ISP type passed to ISPDisconnect!") 
    23802420 
     2421@registerRecurring(DNS_UPDATE_INTERVAL) 
     2422def updateDNS(): 
     2423    """Checks that pdnsd has appropriate name servers configured""" 
     2424    global rl_isptype, rl_masterip 
     2425     
     2426    if isMasterNode(): 
     2427        if rl_isptype == ISP_DSL: 
     2428            # Check if pdnsd has any servers 
     2429            fh = os.popen("/usr/sbin/pdnsd-ctl status | grep ip: | " \ 
     2430                "grep -v ping") 
     2431            lines = fh.readlines() 
     2432            rv = fh.close() 
     2433            if rv is not None or len(lines)==0: 
     2434                # It doesn't, get some 
     2435                ns1, ns2 = getDSLNameservers() 
     2436                if ns1 is not None: 
     2437                    log_command("/usr/sbin/pdnsd-ctl server pppdns1 up %s " \ 
     2438                        "2>&1" % ns1) 
     2439                    log_info("Set NS1 to %s" % ns1) 
     2440                if ns2 is not None: 
     2441                    log_command("/usr/sbin/pdnsd-ctl server pppdns2 up %s " \ 
     2442                        "2>&1" % ns2) 
     2443                    log_info("Set NS2 to %s" % ns2) 
     2444        # Use localhost as our nameserver 
     2445        ns = "127.0.0.1" 
     2446    else: 
     2447        ns = rl_masterip 
     2448 
     2449    # Check that resolv.conf is correct 
     2450    fp = open("/etc/resolv.conf", "r") 
     2451    lines = fp.readlines() 
     2452    fp.close() 
     2453     
     2454    update = False 
     2455    for line in lines: 
     2456        parts = line.split() 
     2457        if line.startswith("search"): 
     2458            if parts[1].strip() != "rurallink.co.nz": 
     2459                update=True 
     2460                break 
     2461        elif line.startswith("nameserver"): 
     2462            if parts[1].strip() != ns: 
     2463                update=True 
     2464                break 
     2465    if update: 
     2466        try: 
     2467            remountrw("updateDNS") 
     2468            fp = open("/etc/resolv.conf", "w") 
     2469            fp.write("search rurallink.co.nz\n") 
     2470            fp.write("nameserver %s\n" % ns) 
     2471            fp.close() 
     2472            remountro("updateDNS") 
     2473        except: 
     2474            log_error("Could not write resolv.conf!", sys.exc_info()) 
     2475            remountro("updateDNS") 
     2476  
    23812477############################################################################## 
    23822478# Initialisation 
     
    24972593        httpd = AsyncHTTPServer(('', 81), CaptivePortalHandler) 
    24982594        log_info("Captive Portal Initialised. Traffic management in place.") 
     2595     
     2596    # Make sure DNS is correctly setup 
     2597    updateDNS() 
    24992598 
    25002599@catchEvent("statusMapRequested") 
Note: See TracChangeset for help on using the changeset viewer.