[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r16798: {torflow} Modified soatstats to reflect changes in soat (torflow/branches/gsoc2008)



Author: aleksei
Date: 2008-09-08 14:46:22 -0400 (Mon, 08 Sep 2008)
New Revision: 16798

Modified:
   torflow/branches/gsoc2008/soat.py
   torflow/branches/gsoc2008/soatstats.py
Log:
Modified soatstats to reflect changes in soat

Modified: torflow/branches/gsoc2008/soat.py
===================================================================
--- torflow/branches/gsoc2008/soat.py	2008-09-08 06:19:45 UTC (rev 16797)
+++ torflow/branches/gsoc2008/soat.py	2008-09-08 18:46:22 UTC (rev 16798)
@@ -1004,6 +1004,9 @@
         except (ValueError, urllib2.URLError):
             plog('ERROR', 'The http-request address ' + address + ' is malformed')
             return 0
+        except (IndexError, TypeError):
+            plog('ERROR', 'An error occured while negotiating socks5 with Tor')
+            return 0
 
         return content
 

Modified: torflow/branches/gsoc2008/soatstats.py
===================================================================
--- torflow/branches/gsoc2008/soatstats.py	2008-09-08 06:19:45 UTC (rev 16797)
+++ torflow/branches/gsoc2008/soatstats.py	2008-09-08 18:46:22 UTC (rev 16798)
@@ -1,4 +1,7 @@
 #!/usr/bin/python
+#
+# 2008 Aleksei Gorny, mentored by Mike Perry
+
 import dircache
 import operator
 import os
@@ -79,33 +82,29 @@
 
 class DataHandler:
     ''' Class for saving and managing test result data '''
-    def filterResults(self, results, 
-            show_ssh=False, show_http=False, show_ssl=False, 
-            show_good=False, show_bad=False, show_unsure=False):
+    def filterResults(self, results, protocols=[], show_good=False, 
+            show_bad=False, show_inconclusive=False):
         ''' filter results based on protocol and success level ''' 
 
-        filters = []
-        if not show_ssh:
-            filters.append(lambda x: not x.__class__.__name__ == 'SSHTestResult')
-        if not show_ssl:
-            filters.append(lambda x: not x.__class__.__name__ == 'SSLTestResult')
-        if not show_http:
-            filters.append(lambda x: not x.__class__.__name__ == 'TestResult')
-        if not show_good:
-            filters.append(lambda x: not x.status == TEST_SUCCESS)
-        if not show_bad:
-            filters.append(lambda x: not x.status == TEST_FAILURE)
-        if not show_unsure:
-            filters.append(lambda x: not x.status == TEST_INCONCLUSIVE) 
+        protocol_filters = []
+        status_filters = []
 
-        filtered = []
-        if len(filters) > 0:
-            filter = lambda x: reduce(operator.__and__, [f(x) for f in filters]) 
-            filtered = [x for x in results if filter(x)]
-        else:
-            filtered = list(results)
+        for protocol in protocols:
+            protocol_filters.append(lambda x, p=protocol: x.__class__.__name__.lower()[:-10].endswith(p))
+        if show_good:
+            status_filters.append(lambda x: x.status == TEST_SUCCESS)
+        if show_bad:
+            status_filters.append(lambda x: x.status == TEST_FAILURE)
+        if show_inconclusive:
+            status_filters.append(lambda x: x.status == TEST_INCONCLUSIVE)
 
-        return filtered
+        if len(protocol_filters) == 0 or len(status_filters) == 0:
+            return []
+       
+        protocol_filter = lambda x: reduce(operator.__or__, [f(x) for f in protocol_filters])
+        status_filter = lambda x: reduce(operator.__or__, [f(x) for f in status_filters])
+
+        return [x for x in results if (protocol_filter(x) and status_filter(x))]
         
     def filterByNode(self, results, id):
         ''' filter by node'''
@@ -139,6 +138,14 @@
         ''' get results of imap tests '''
         return self.__getResults(data_dir + 'imap/')
 
+    def getDns(self):
+        ''' get results of basic dns tests '''
+        return self.__getResults(data_dir + 'dns')
+
+    def getDnsRebind(self):
+        ''' get results of dns rebind tests '''
+        return self.__getResults(data_dir + 'dnsbrebind/')
+
     def __getResults(self, dir):
         ''' 
         recursively traverse the directory tree starting with dir
@@ -215,14 +222,15 @@
         sshSet = Set([])
         sslSet = Set([])
         httpSet = Set([])
+        smtpSet = Set([])
+        popSet = Set([])
+        imapSet = Set([])
+        dnsSet = Set([])
+        dnsrebindSet = Set([])
 
         total = len(data)
-        good = 0
-        bad = 0
-        inconclusive = 0
-        ssh = 0
-        http = 0
-        ssl = 0
+        good = bad = inconclusive = 0
+        ssh = http = ssl = pop = imap = smtp = dns = dnsrebind = 0
 
         for result in data:
             nodeSet.add(result.exit_node)
@@ -243,6 +251,21 @@
             elif result.__class__.__name__ == 'SSLTestResult':
                 sslSet.add(result.exit_node)
                 ssl += 1
+            elif result.__class__.__name__ == 'IMAPTestResult':
+                imapSet.add(result.exit_node)
+                imap += 1
+            elif result.__class__.__name__ == 'POPTestResult':
+                popSet.add(result.exit_node)
+                pop += 1
+            elif result.__class__.__name__ == 'SMTPTestResult':
+                smtpSet.add(result.exit_node)
+                smtp += 1
+            elif result.__class__.__name__ == 'DNSTestResult':
+                dnsSet.add(result.exit_node)
+                dns += 1
+            elif result.__class__.__name__ == 'DNSRebindTestResult':
+                dnsrebindSet.add(result.exit_node)
+                dnsrebind += 1
 
         swidth = 25
         nwidth = 10
@@ -255,48 +278,67 @@
         print header_format % (swidth, 'Parameter', nwidth, 'Count')
         print '-' * width
 
-        print format % (swidth, 'Tests completed', nwidth, total)
-        print format % (swidth, 'Nodes tested', nwidth, len(nodeSet))
-        print format % (swidth, 'Nodes SSL-tested', nwidth, len(sslSet))
-        print format % (swidth, 'Nodes HTTP-tested', nwidth, len(httpSet))
-        print format % (swidth, 'Nodes SSH-tested', nwidth, len(sshSet))
-        print format % (swidth, 'Failed tests', nwidth, bad)
-        print format % (swidth, 'Succeeded tests', nwidth, good)
-        print format % (swidth, 'Inconclusive tests', nwidth, inconclusive)
-        print format % (swidth, 'SSH tests', nwidth, ssh)
-        print format % (swidth, 'HTTP tests', nwidth, http)
-        print format % (swidth, 'SSL tests', nwidth, ssl)
+        stats = [
+            ('Tests completed', total),
+            ('Nodes tested', len(nodeSet)),
+            ('Nodes SSL-tested', len(sslSet)),
+            ('Nodes HTTP-tested', len(httpSet)),
+            ('Nodes SSH-tested', len(sshSet)),
+            ('Nodes POP-tested', len(popSet)),
+            ('Nodes IMAP-tested', len(imapSet)),
+            ('Nodes SMTP-tested', len(smtpSet)),
+            ('Nodes DNS-tested', len(dnsSet)),
+            ('Nodes DNSRebind-tested', len(dnsrebindSet)),
+            ('Failed tests', bad),
+            ('Succeeded tests', good),
+            ('Inconclusive tests', inconclusive),
+            ('SSH tests', ssh),
+            ('HTTP tests', http),
+            ('SSL tests', ssl),
+            ('POP tests', pop),
+            ('IMAP tests', imap),
+            ('SMTP tests', smtp),
+            ('DNS tests', dns),
+            ('DNS rebind tests', dnsrebind)
+        ]
 
+        for (k,v) in stats:
+            print format % (swidth, k, nwidth, v)
         print '=' * width
 
     def Reply(self, input):
 
-        ssh = False 
-        http = False 
-        ssl = False 
-        good = False 
-        bad = False
-        inconclusive = False
+        good = bad = inconclusive = False
+        protocols = []
 
         if 'a' in input:
-            ssh = http = ssl = good = bad = inconclusive = True
+            good = bad = inconclusive = True
+            protocols.extend(["ssh", "http", "ssl", "imap", "pop", "smtp"])
         else:
+            good = 'g' in input
+            bad = 'b' in input
+            inconclusive = 'i' in input
+
             if 's' in input:
-                ssh = True
+                protocols.append("ssh")
             if 'h' in input:
-                http = True
+                protocols.append("http")
             if 'l' in input:
-                ssl = True
-            if 'g' in input:
-                good = True
-            if 'b' in input:
-                bad = True
-            if 'i' in input:
-                inconclusive = True
+                protocols.append("ssl")
+            if 'p' in input:
+                protocols.append("imap")
+            if 'o' in input:
+                protocols.append("pop")
+            if 't' in input:
+                protocols.append("smtp")
+            if 'd' in input:
+                protocols.append("dns")
+            if 'r' in input:
+                protocols.append("dnsrebind")
 
         dh = DataHandler()
         data = dh.getAll()
-        filtered = dh.filterResults(data, ssh, http, ssl, good, bad, inconclusive)
+        filtered = dh.filterResults(data, protocols, good, bad, inconclusive)
 
         nodewidth = 45
         typewidth = 10
@@ -333,6 +375,11 @@
         print '  g - show good results'
         print '  b - show bad results'
         print '  i - show inconclusive results'
+        print '  p - show imap results'
+        print '  o - show pop results'
+        print '  t - show smtp results'
+        print '  d - show dns results'
+        print '  r - show dnsrebind results'
         print ''
 
 #
@@ -368,6 +415,11 @@
     ID_SHOW_SSL = 21
     ID_SHOW_HTTP = 22
     ID_SHOW_SSH = 23
+    ID_SHOW_SMTP = 24
+    ID_SHOW_IMAP = 25
+    ID_SHOW_POP = 26
+    ID_SHOW_DNS = 27
+    ID_SHOW_DNSREBIND = 28
 
     ID_NODE = 31
 
@@ -404,15 +456,15 @@
             self.showHTTP = viewMenu.Append(ID_SHOW_HTTP, 'Show &HTTP', 'Show HTTP test results', kind=wx.ITEM_CHECK)
             self.showSSH = viewMenu.Append(ID_SHOW_SSH, 'Show &SSH', 'Show SSH test results', kind=wx.ITEM_CHECK)
             viewMenu.AppendSeparator()
+            self.showSMTP = viewMenu.Append(ID_SHOW_SMTP, 'Show SMTP', 'Show SMTP test results', kind=wx.ITEM_CHECK)
+            self.showIMAP = viewMenu.Append(ID_SHOW_IMAP, 'Show IMAP', 'Show IMAP test results', kind=wx.ITEM_CHECK)
+            self.showPOP = viewMenu.Append(ID_SHOW_POP, 'Show POP', 'Show POP test results', kind=wx.ITEM_CHECK)
+            viewMenu.AppendSeparator()
+            self.showDNS = viewMenu.Append(ID_SHOW_DNS, 'Show DNS', 'Show DNS test results', kind=wx.ITEM_CHECK)
+            self.showDNSRebind = viewMenu.Append(ID_SHOW_DNSREBIND, 'Show DNSRebind', 'Show DNS rebind test results', kind=wx.ITEM_CHECK)
+            viewMenu.AppendSeparator()
             viewMenu.Append(ID_NODE, '&Find node...', 'View test results for a given node [NOT IMPLEMENTED]')
     
-            viewMenu.Check(ID_SHOW_GOOD, True)
-            viewMenu.Check(ID_SHOW_BAD, True)
-            viewMenu.Check(ID_SHOW_UNSURE, True)
-            viewMenu.Check(ID_SHOW_SSL, True)
-            viewMenu.Check(ID_SHOW_HTTP, True)
-            viewMenu.Check(ID_SHOW_SSH, True)
-
             menuBar = wx.MenuBar()
             menuBar.Append(fileMenu,"&File")
             menuBar.Append(viewMenu,"&View")
@@ -424,9 +476,13 @@
             wx.EVT_MENU(self, ID_SHOW_GOOD, self.GenerateFilteredList)
             wx.EVT_MENU(self, ID_SHOW_BAD, self.GenerateFilteredList)
             wx.EVT_MENU(self, ID_SHOW_UNSURE, self.GenerateFilteredList)
-            wx.EVT_MENU(self, ID_SHOW_SSL, self.GenerateFilteredList)
-            wx.EVT_MENU(self, ID_SHOW_HTTP, self.GenerateFilteredList)
-            wx.EVT_MENU(self, ID_SHOW_SSH, self.GenerateFilteredList)
+            viewMenu.Check(ID_SHOW_GOOD, True)
+            viewMenu.Check(ID_SHOW_BAD, True)
+            viewMenu.Check(ID_SHOW_UNSURE, True)
+            
+            for i in range(ID_SHOW_SSL, ID_SHOW_DNSREBIND + 1):
+                viewMenu.Check(i, True)
+                wx.EVT_MENU(self, i, self.GenerateFilteredList)
 
         def initContent(self): 
             base = wx.Panel(self, -1)
@@ -493,10 +549,28 @@
         def OnExit(self,e):
             self.Close(True)
 
-        def GenerateFilteredList(self, e):
-            self.filteredList = list(self.dataHandler.filterResults(self.dataList, 
-                self.showSSH.IsChecked(), self.showHTTP.IsChecked(), self.showSSL.IsChecked(), 
+        def GenerateFilteredList(self, e): 
+            protocols = []
+            if self.showSSH.IsChecked():
+                protocols.append("ssh") 
+            if self.showHTTP.IsChecked():
+                protocols.append("http")
+            if self.showSSL.IsChecked():
+                protocols.append("ssl")
+            if self.showIMAP.IsChecked():
+                protocols.append("imap")
+            if self.showPOP.IsChecked():
+                protocols.append("pop")
+            if self.showSMTP.IsChecked():
+                protocols.append("smtp")
+            if self.showDNS.IsChecked():
+                protocols.append("dns")
+            if self.showDNSRebind.IsChecked():
+                protocols.append("dnsrebind")
+
+            self.filteredList = list(self.dataHandler.filterResults(self.dataList, protocols, 
                 self.showGood.IsChecked(), self.showBad.IsChecked(), self.showUnsure.IsChecked()))
+
             dataMap = {}
             self.fillDataMap(dataMap)
             self.fillListCtrl(dataMap)