mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-06-12 09:03:12 +03:00
minor enhancements - #311
This commit is contained in:
parent
0953ce5b08
commit
a73aa422fc
|
@ -8,33 +8,65 @@ import os
|
||||||
import re
|
import re
|
||||||
import smtplib
|
import smtplib
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from email.mime.text import MIMEText
|
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
|
||||||
|
sys.path.append("../../")
|
||||||
|
|
||||||
|
from lib.core.revision import getRevisionNumber
|
||||||
|
|
||||||
TIME = time.strftime("%H:%M:%S %d-%m-%Y", time.gmtime())
|
TIME = time.strftime("%H:%M:%S %d-%m-%Y", time.gmtime())
|
||||||
SQLMAP_HOME = "/opt/sqlmap"
|
SQLMAP_HOME = "/opt/sqlmap"
|
||||||
|
REVISION = getRevisionNumber()
|
||||||
|
|
||||||
SMTP_SERVER = "127.0.0.1"
|
SMTP_SERVER = "127.0.0.1"
|
||||||
SMTP_PORT = 25
|
SMTP_PORT = 25
|
||||||
SMTP_TIMEOUT = 30
|
SMTP_TIMEOUT = 30
|
||||||
FROM = "regressiontest@sqlmap.org"
|
FROM = "regressiontest@sqlmap.org"
|
||||||
TO = "dev@sqlmap.org"
|
TO = "dev@sqlmap.org"
|
||||||
SUBJECT = "Regression test results on %s" % TIME
|
SUBJECT = "Regression test results on %s using revision %s" % (TIME, REVISION)
|
||||||
CONTENT = ""
|
CONTENT = ""
|
||||||
TEST_COUNTS = []
|
TEST_COUNTS = []
|
||||||
ATTACHMENTS = {}
|
ATTACHMENTS = {}
|
||||||
|
|
||||||
command_line = "cd %s && python sqlmap.py --live-test" % SQLMAP_HOME
|
def prepare_email(content):
|
||||||
proc = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
msg = MIMEMultipart()
|
||||||
|
msg["Subject"] = SUBJECT
|
||||||
|
msg["From"] = FROM
|
||||||
|
msg["To"] = TO
|
||||||
|
|
||||||
proc.wait()
|
msg.attach(MIMEText(content))
|
||||||
stdout, stderr = proc.communicate()
|
|
||||||
|
|
||||||
failed_tests = re.findall("running live test case: (.+?) \((\d+)\/\d+\)[\r]*\n.+test failed (at parsing item \"(.+)\" )?\- scan folder: (\/.+) \- traceback: (.*?)( - SQL injection not detected)?[\r]*\n", stdout, re.M)
|
return msg
|
||||||
|
|
||||||
for failed_test in failed_tests:
|
def send_email(msg):
|
||||||
|
try:
|
||||||
|
s = smtplib.SMTP(host=SMTP_SERVER, port=SMTP_PORT, timeout=SMTP_TIMEOUT)
|
||||||
|
#s.set_debuglevel(1)
|
||||||
|
s.sendmail(FROM, TO, msg.as_string())
|
||||||
|
s.quit()
|
||||||
|
# Catch all for SMTP exceptions
|
||||||
|
except smtplib.SMTPException, e:
|
||||||
|
print "Failure to send email: %s" % str(e)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
command_line = "cd %s && python sqlmap.py --live-test" % SQLMAP_HOME
|
||||||
|
proc = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
|
||||||
|
proc.wait()
|
||||||
|
stdout, stderr = proc.communicate()
|
||||||
|
|
||||||
|
if stderr:
|
||||||
|
msg = prepare_email("Execution of regression test failed with error: %s" % stderr)
|
||||||
|
send_email(msg)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
failed_tests = re.findall("running live test case: (.+?) \((\d+)\/\d+\)[\r]*\n.+test failed (at parsing item \"(.+)\" )?\- scan folder: (\/.+) \- traceback: (.*?)( - SQL injection not detected)?[\r]*\n", stdout, re.M)
|
||||||
|
|
||||||
|
for failed_test in failed_tests:
|
||||||
title = failed_test[0]
|
title = failed_test[0]
|
||||||
test_count = int(failed_test[1])
|
test_count = int(failed_test[1])
|
||||||
parse = failed_test[3] if failed_test[3] else None
|
parse = failed_test[3] if failed_test[3] else None
|
||||||
|
@ -74,27 +106,19 @@ for failed_test in failed_tests:
|
||||||
|
|
||||||
CONTENT += "#######################################################################\n\n"
|
CONTENT += "#######################################################################\n\n"
|
||||||
|
|
||||||
if CONTENT:
|
if CONTENT:
|
||||||
SUBJECT += " (%s)" % ", ".join("#%d" % count for count in TEST_COUNTS)
|
SUBJECT += " (%s)" % ", ".join("#%d" % count for count in TEST_COUNTS)
|
||||||
CONTENT += "\n\nRegression test finished at %s" % time.strftime("%H:%M:%S %d-%m-%Y", time.gmtime())
|
CONTENT += "\n\nRegression test finished at %s" % time.strftime("%H:%M:%S %d-%m-%Y", time.gmtime())
|
||||||
|
|
||||||
msg = MIMEMultipart()
|
msg = prepare_email(CONTENT)
|
||||||
msg["Subject"] = SUBJECT
|
|
||||||
msg["From"] = FROM
|
|
||||||
msg["To"] = TO
|
|
||||||
|
|
||||||
msg.attach(MIMEText(CONTENT))
|
|
||||||
|
|
||||||
for test_count, attachment in ATTACHMENTS.items():
|
for test_count, attachment in ATTACHMENTS.items():
|
||||||
attachment = MIMEText(attachment)
|
attachment = MIMEText(attachment)
|
||||||
attachment.add_header("Content-Disposition", "attachment", filename="test_case_%d_console_output.txt" % test_count)
|
attachment.add_header("Content-Disposition", "attachment", filename="test_case_%d_console_output.txt" % test_count)
|
||||||
msg.attach(attachment)
|
msg.attach(attachment)
|
||||||
|
|
||||||
try:
|
send_email(msg)
|
||||||
s = smtplib.SMTP(host=SMTP_SERVER, port=SMTP_PORT, timeout=SMTP_TIMEOUT)
|
|
||||||
#s.set_debuglevel(1)
|
if __name__ == "__main__":
|
||||||
s.sendmail(FROM, TO, msg.as_string())
|
main()
|
||||||
s.quit()
|
|
||||||
# Catch all for SMTP exceptions
|
|
||||||
except smtplib.SMTPException, e:
|
|
||||||
print "Failure to send email: %s" % str(e)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user