import sys, csv, json, os, re def emit_header(browser, exporter, data_time): str_s = '
' str_s += 'Date:
' str_s += data_time + '\n' str_s += '
\n' str_s += 'Browser:
' str_s += browser['name']+ '-' + browser['version'] + '\n' str_s += '
\n' str_s += 'Exporter:
' str_s += exporter['name']+ '-' + exporter['version'] + '\n' str_s += '
\n' str_s += '
\n' return str_s def emit_bug(b): bug = b['bug'] str_s = '
' # bug str_s += 'Bug' str_s += '
' str_s += '
\n' str_s += 'type: ' + bug['type'] + '
' + 'property: ' + bug['name'] str_s += '
' str_s += '
' # request req = b['request'] str_s += 'Request' str_s += '
' str_s += '
\n' str_s += req['method'] + '
' + req['url'] + '
' + req['user_agent'] str_s += '
' if 'referer' in req: str_s += '
' str_s += 'Ref: ' + req['referer'] str_s += '
' str_s += '
' str_s += '
' # response res = b['response'] str_s += 'Response' str_s += '
' str_s += '
\n' if 'server_agent' in res: str_s += str(res['status']) + '
' + str(res['server_ip']) + '
' + res['server_agent'] + '
' else: str_s += str(res['status']) + '
' + str(res['server_ip']) + '
' str_s += '
' str_s += '
' # content c = b['content'] str_s += 'Content' str_s += '
' str_s += '
\n' str_s += 'mime type: ' + c['mime_type'] + '
' str_s += 'size: ' + str(c['size']) + '
' if len(c['data']) > 500: str_s += '
\n' str_s += html_escape(c['data']) + '\n' str_s += '
\n' str_s += '
' str_s += '
' return str_s def html_escape(text): html_escape_table = { "&": "&", '"': """, "'": "'", ">": ">", "<": "<", "[": "[", "]": "]" } return "".join(html_escape_table.get(c,c) for c in text) if __name__ == '__main__': fp = sys.stdin try: data = json.loads(fp.read()) except Exception, ee: sys.exit('Error loading data... Aborting.') try: template = open(os.path.join('.', 'index_template.html'), 'r+'); except: print('error opening template file. aborting...'); sys.exit(0); content = "" content += emit_header(data['browser'], data['exporter'], data['date_time']) bugs = data['data'] for b in bugs: card = "
\n" card += emit_bug(b) card += "
\n" content += card html = template.read().replace('[[content]]', content); print (html).encode("utf-8")