[or-cvs] r13145: Lots new today: Use the properly named subscribe.template, r (weather/trunk)

ioerror at seul.org ioerror at seul.org
Wed Jan 16 02:48:14 UTC 2008


Author: ioerror
Date: 2008-01-15 21:48:13 -0500 (Tue, 15 Jan 2008)
New Revision: 13145

Modified:
   weather/trunk/config.py
   weather/trunk/poll.py
   weather/trunk/tor-weather-apache2.conf
   weather/trunk/weather.py
Log:
Lots new today:
    Use the properly named subscribe.template, rather than subscribe.html.
    Send the proper http headers.
    Fix the way the authenticator is parsed.
    Traceback exception imports changed.
    General code cleanups.
-jake


Modified: weather/trunk/config.py
===================================================================
--- weather/trunk/config.py	2008-01-16 02:35:14 UTC (rev 13144)
+++ weather/trunk/config.py	2008-01-16 02:48:13 UTC (rev 13145)
@@ -1,11 +1,10 @@
 #!/usr/bin/env python2.5
 
-
 URLbase = "http://weather.torproject.org"
 
 weather_storage = "/var/lib/torweather/"
 
-authenticator = open(weather_storage + "auth_token").read()  
+authenticator = open(weather_storage + "auth_token").read().strip()
 
 weather_email = "tor-ops at torproject.org"
 

Modified: weather/trunk/poll.py
===================================================================
--- weather/trunk/poll.py	2008-01-16 02:35:14 UTC (rev 13144)
+++ weather/trunk/poll.py	2008-01-16 02:48:13 UTC (rev 13145)
@@ -7,7 +7,7 @@
 import time
 import threading
 from datetime import datetime
-from traceback import format_exc
+from traceback import print_exception
 from subprocess import Popen, PIPE
 import TorCtl.TorCtl as TorCtl
 
@@ -17,8 +17,6 @@
 
 debug = 0
 
-class NodePollFailure(Exception):
-  pass
 
 debugfile = open(weather_storage + "/torctl-debug","w")
 class TorPing:
@@ -53,17 +51,11 @@
     info = self.control.get_info(string)
     # info looks like this:
     # {'ns/id/FFCB46DB1339DA84674C70D7CB586434C4370441': 'r moria1 /8tG2xM52oRnTHDXy1hkNMQ3BEE pavoLDqxMvw+T1VHR5hmmgpr9self 2007-10-10 21:12:08 128.31.0.34 9001 9031\ns Authority Fast Named Running Valid V2Dir\n'}
-    try:
-      ip,port = info[string].split()[6:8]
-    except:
-      raise NodePollFailure, "Could not extract port and IP from tor client"
+    ip,port = info[string].split()[6:8]
     # throw exceptions like confetti if this isn't legit
-    try:
-      socket.inet_aton(ip)
-      # ensure port is a kosher string
-      assert 0 < int(port) < 65536
-    except:
-      raise NodePollFailure, "Tor client getinfo gave a non-kosher ip:port!"
+    socket.inet_aton(ip)
+    # ensure port is a kosher string
+    assert 0 < int(port) < 65536
 
     if debug: print "contacting node at %s:%s" % (ip,port)
 
@@ -79,8 +71,7 @@
     if n > 0:
       return True
     else:
-      raise NodePollFailure, "Cannot SSL handshake to node."
-      #return False
+      return False
 
   def test(self):
     "Check that the connection to the Tor Control port is still okay."
@@ -162,12 +153,10 @@
       node = self.subscriptions.nextkey(node)
     self.gdbm_lock.release()
     #del self.tp   # this minimises the chance of confusion a local tor control
-                   # port crash with a remote node being down
+                  # port crash with a remote node being down
     if debug: print "Ping_all finished"
-
  
   def ping(self, node):
-    "Is this node there and, to the best of our knowledge, being a tor node?"
     if debug: print "pinging", node
     try: 
       assert self.tp.ping(node)
@@ -180,10 +169,10 @@
         pass
     except:
       # for /some/ reason, we can't contact this tor node
-      #ex1,ex2,ex3 = sys.exc_info()
+      ex1,ex2,ex3 = sys.exc_info()
       if self.internet_looks_okay():
         # But we can ping the net.  That's bad.
-        reason = format_exc(500)    # limit to 500 stack levels in emails!
+        reason = print_exception(ex1,ex2,ex3)
         if (debug):
           print "logging a strike against node", node, "because of:"
           print reason
@@ -191,13 +180,12 @@
       else:
         print "I would have concluded that tor node", node, "was down;"
         print "The problem looked like this:"
-        print format_exc()
+        print print_exception(ex1,ex2,ex3)
         print "But I couldn't ping %s!" % (self.ping_failure)
  
   good_ping = re.compile("0% packet loss")
 
   def internet_looks_okay(self):
-    "If none of the ping targets are dropping packets, the Internet looks okay."
     cmd = ["ping", "-c", "3", "x"]
     pings = []
     for host in ping_targets:

Modified: weather/trunk/tor-weather-apache2.conf
===================================================================
--- weather/trunk/tor-weather-apache2.conf	2008-01-16 02:35:14 UTC (rev 13144)
+++ weather/trunk/tor-weather-apache2.conf	2008-01-16 02:48:13 UTC (rev 13145)
@@ -31,9 +31,8 @@
 	# Possible values include: debug, info, notice, warn, error, crit,
 	# alert, emerg.
 	LogLevel warn
- 
- 	# Don't log unless you're debugging!
-	#CustomLog /var/log/apache2/tor-weather-access.log combined
+
+	CustomLog /var/log/apache2/tor-weather-access.log combined
 	ServerSignature Off
 
 </VirtualHost>

Modified: weather/trunk/weather.py
===================================================================
--- weather/trunk/weather.py	2008-01-16 02:35:14 UTC (rev 13144)
+++ weather/trunk/weather.py	2008-01-16 02:48:13 UTC (rev 13145)
@@ -102,10 +102,12 @@
 class subscribe:
   
   def GET(self):
-    print open("subscribe.html").read()
+    web.header('content-type', 'text/html')
+    print open("subscribe.template").read()
 
   whitespace = re.compile("\s*")
   def POST(self):
+    web.header('content-type', 'text/html')
     i = web.input(node="none",email="none")
     if not self.check_email(i.email):
       print 'That email address looks fishy to our refined sensibilities!'
@@ -264,6 +266,7 @@
 class confirm:
   def GET(self,authstring):
     
+    web.header('content-type', 'text/html')
     print "<html>"
     if debug: print "checking confirmation..."
     gdbm_lock.acquire()
@@ -308,6 +311,7 @@
 class unsubscribe:
   def GET(self,authstring):
 
+    web.header('content-type', 'text/html')
     gdbm_lock.acquire()
     if not unsubscriptions.has_key(authstring):
       print "Invalid unsubscription request!"



More information about the tor-commits mailing list