|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) |
| 4 | +# See the file 'doc/COPYING' for copying permission |
| 5 | + |
| 6 | +# Removes duplicate entries in wordlist like files |
| 7 | +import codecs |
| 8 | +import os |
| 9 | +import re |
| 10 | +import smtplib |
| 11 | +import subprocess |
| 12 | +import time |
| 13 | + |
| 14 | +from email.mime.text import MIMEText |
| 15 | + |
| 16 | +TIME = time.strftime("%H:%M:%S", time.gmtime()) |
| 17 | +DATE = time.strftime("%d-%m-%Y", time.gmtime()) |
| 18 | + |
| 19 | +SMTP_SERVER = "10.129.121.194" |
| 20 | +SMTP_PORT = 25 |
| 21 | +SMTP_TIMEOUT = 30 |
| 22 | + |
| 23 | + |
| 24 | +SUBJECT = "Regression test results - started at %s on %s" % (TIME, DATE) |
| 25 | +CONTENT = "" |
| 26 | + |
| 27 | +command_line = "cd ../../ ; rm -f $REGRESSION_FILE ; python sqlmap.py --live-test --run-case 'Invalid logic'" |
| 28 | +proc = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 29 | +proc.wait() |
| 30 | +stdout, stderr = proc.communicate() |
| 31 | +failed_tests = re.findall("running live test case: (.+?) \(\d+\/\d+\)[\r]*\n.+test failed (.*?)at parsing item: (.+) \- scan folder is (\/.+)[\r]*\n", stdout, re.I | re.M) |
| 32 | + |
| 33 | +for failed_test in failed_tests: |
| 34 | + title = failed_test[0] |
| 35 | + traceback = failed_test[1] or None |
| 36 | + parse = failed_test[2] |
| 37 | + output_folder = failed_test[3] |
| 38 | + |
| 39 | + console_output_fd = codecs.open(os.path.join(output_folder, "console_output"), "rb", "utf8") |
| 40 | + console_output = console_output_fd.read() |
| 41 | + console_output_fd.close() |
| 42 | + |
| 43 | + log_fd = codecs.open(os.path.join(output_folder, "debiandev", "log"), "rb", "utf8") |
| 44 | + log = log_fd.read() |
| 45 | + log_fd.close() |
| 46 | + |
| 47 | + if traceback: |
| 48 | + traceback_fd = codecs.open(os.path.join(output_folder, "traceback"), "rb", "utf8") |
| 49 | + traceback = traceback_fd.read() |
| 50 | + traceback_fd.close() |
| 51 | + |
| 52 | + CONTENT += "Failed test case '%s' at parsing: %s:\n\n" % (title, parse) |
| 53 | + CONTENT += "### LOG FILE:\n\n" |
| 54 | + CONTENT += "%s\n" % log |
| 55 | + CONTENT += "### CONSOLE OUTPUT\n\n" |
| 56 | + CONTENT += "%s\n" % str(console_output) |
| 57 | + |
| 58 | + if traceback: |
| 59 | + CONTENT += "### TRACEBACK:\n" |
| 60 | + CONTENT += "%s\n" % str(traceback) |
| 61 | + |
| 62 | + CONTENT += "\n#######################################\n\n" |
| 63 | + |
| 64 | +if CONTENT: |
| 65 | + msg = MIMEText(CONTENT) |
| 66 | + msg["Subject"] = SUBJECT |
| 67 | + msg["From"] = FROM |
| 68 | + msg["To"] = TO |
| 69 | + |
| 70 | + s = smtplib.SMTP(host=SMTP_SERVER, port=SMTP_PORT, timeout=SMTP_TIMEOUT) |
| 71 | + #s.set_debuglevel(1) |
| 72 | + s.sendmail(FROM, TO, msg) |
| 73 | + s.quit() |
0 commit comments