Changeset 712
- Timestamp:
- 06/01/06 04:34:21 (7 years ago)
- File:
-
- 1 edited
-
ccsd/private/modules/ccs_monitor_rurallink.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ccsd/private/modules/ccs_monitor_rurallink.py
r710 r712 67 67 DSL_NETMASK = "8" 68 68 DSL_TELNET_TIMEOUT = 2 69 70 # How often (seconds) to check DNS settings 71 DNS_UPDATE_INTERVAL = 60 69 72 70 73 ISP_IF_DISCONNECT = """<a href="/rladmin/isp-disconnect">[Disconnect]</a>""" … … 2016 2019 return "<i>No username configured</i>" 2017 2020 2021 def 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 2018 2058 def connectDSL(): 2019 2059 """Tells the modem to connect""" … … 2379 2419 raise ccs_rurallink_error("Unknown ISP type passed to ISPDisconnect!") 2380 2420 2421 @registerRecurring(DNS_UPDATE_INTERVAL) 2422 def 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 2381 2477 ############################################################################## 2382 2478 # Initialisation … … 2497 2593 httpd = AsyncHTTPServer(('', 81), CaptivePortalHandler) 2498 2594 log_info("Captive Portal Initialised. Traffic management in place.") 2595 2596 # Make sure DNS is correctly setup 2597 updateDNS() 2499 2598 2500 2599 @catchEvent("statusMapRequested")
Note: See TracChangeset
for help on using the changeset viewer.
