Package Halberd :: Module reportlib
[hide private]
[frames] | no frames]

Source Code for Module Halberd.reportlib

 1  # -*- coding: iso-8859-1 -*- 
 2   
 3  """Output module. 
 4  """ 
 5   
 6  # Copyright (C) 2004, 2005, 2006, 2010  Juan M. Bello Rivas <jmbr@superadditive.com> 
 7  # 
 8  # This program is free software; you can redistribute it and/or modify 
 9  # it under the terms of the GNU General Public License as published by 
10  # the Free Software Foundation; either version 2 of the License, or 
11  # (at your option) any later version. 
12  # 
13  # This program is distributed in the hope that it will be useful, 
14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  # GNU General Public License for more details. 
17  # 
18  # You should have received a copy of the GNU General Public License 
19  # along with this program; if not, write to the Free Software 
20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
21   
22   
23  import sys 
24   
25  import Halberd.logger 
26  import Halberd.clues.analysis as analysis 
27   
28   
29 -def report(scantask):
30 """Displays detailed report information to the user. 31 """ 32 if scantask.out: 33 out = open(scantask.out, 'a') 34 else: 35 out = sys.stdout 36 37 clues = scantask.analyzed 38 hits = analysis.hits(clues) 39 logger = Halberd.logger.getLogger() 40 41 # xxx This could be passed by the caller in order to avoid recomputation in 42 # case the clues needed a re-analysis. 43 diff_fields = analysis.diff_fields(clues) 44 45 out.write('=' * 70 + '\n') 46 out.write('%s' % scantask.url) 47 if scantask.addr: 48 out.write(' (%s)' % scantask.addr) 49 out.write(': %d real server(s)\n' % len(clues)) 50 out.write('=' * 70 + '\n') 51 52 for num, clue in enumerate(clues): 53 assert hits > 0 54 info = clue.info 55 56 out.write('\n') 57 # out.write('-' * 70 + '\n') 58 out.write('server %d: %s\n' % (num + 1, info['server'].lstrip())) 59 out.write('-' * 70 + '\n\n') 60 61 out.write('difference: %d seconds\n' % clue.diff) 62 63 out.write('successful requests: %d hits (%.2f%%)\n' \ 64 % (clue.getCount(), clue.getCount() * 100 / float(hits))) 65 66 if info['contloc']: 67 out.write('content-location: %s\n' % info['contloc'].lstrip()) 68 69 if len(info['cookies']) > 0: 70 out.write('cookie(s):\n') 71 for cookie in info['cookies']: 72 out.write(' %s\n' % cookie.lstrip()) 73 74 out.write('header fingerprint: %s\n' % info['digest']) 75 76 different = [(field, value) for field, value in clue.headers \ 77 if field in diff_fields] 78 if different: 79 out.write('different headers:\n') 80 idx = 1 81 for field, value in different: 82 out.write(' %d. %s:%s\n' % (idx, field, value)) 83 idx += 1 84 85 if scantask.debug: 86 import pprint 87 out.write('headers:\n') 88 pprint.pprint(clue.headers, out)
89 90 91 # vim: ts=4 sw=4 et 92