Skip to content

Commit

Permalink
Restore fixed issue #41
Browse files Browse the repository at this point in the history
And show the scan datetime to be able to copy/paste s and search older emails
  • Loading branch information
tristanlatr committed Oct 13, 2020
1 parent 91442c1 commit e6c75a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
12 changes: 8 additions & 4 deletions wpwatcher/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from wpscan_out_parse.formatter import format_results
from wpscan_out_parse.formatter import format_results, format_issues
from wpwatcher import log
from wpwatcher.__version__ import __version__
from wpwatcher.utils import get_valid_filename
Expand Down Expand Up @@ -92,7 +92,7 @@ def send_report(self, wp_report, email_to):

# Email body
body = self.build_message(
wp_report, warnings=self.send_warnings, infos=self.send_infos
wp_report
)
if self.use_monospace_font:
body = (
Expand Down Expand Up @@ -214,7 +214,7 @@ def _notify(self, wp_site, wp_report):
return True

@staticmethod
def build_message(wp_report, warnings=True, infos=False):
def build_message(wp_report):
"""Build mail message text base on report and warnngs and info switch"""

message = "<p>WordPress security scan report for site: %s<br />\n" % (
Expand All @@ -224,8 +224,12 @@ def build_message(wp_report, warnings=True, infos=False):

message += format_results(wp_report, format="html")

if wp_report["fixed"]:
message += "<br/>\n"
message += format_issues("Fixed", wp_report["fixed"], format="html")

message += "<br />\n<br />\n--"
message += "<br />\nWPWatcher - Automating WPscan to scan and report vulnerable Wordpress sites"
message += '<br />\n<a href="https://github.com/tristanlatr/WPWatcher">WPWatcher</a> - Automating WPscan to scan and report vulnerable Wordpress sites'
message += "<br />\nServer: %s - Version: %s<br />\n" % (
socket.gethostname(),
__version__,
Expand Down
26 changes: 15 additions & 11 deletions wpwatcher/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,22 @@ def update_report(self, wp_report, last_wp_report, wp_site):
if last_wp_report:
# Save already fixed issues but not reported yet
wp_report["fixed"] = last_wp_report["fixed"]
# Fill out fixed issues
wp_report["fixed"].extend(
self.get_fixed_issues(
wp_report, last_wp_report, wp_site, issue_type="alerts"
)
)
if self.mail.send_warnings:

# Fill out fixed issues if the scan is not an error
if wp_report['status'] != 'ERROR':

wp_report["fixed"].extend(
self.get_fixed_issues(
wp_report, last_wp_report, wp_site, issue_type="warnings"
wp_report, last_wp_report, wp_site, issue_type="alerts"
)
)
if self.mail.send_warnings:
wp_report["fixed"].extend(
self.get_fixed_issues(
wp_report, last_wp_report, wp_site, issue_type="warnings"
)
)

# Fill out last_email datetime if any
if last_wp_report["last_email"]:
wp_report["last_email"] = last_wp_report["last_email"]
Expand Down Expand Up @@ -172,7 +176,7 @@ def get_fixed_issues(self, wp_report, last_wp_report, wp_site, issue_type="alert
a.splitlines()[0] for a in wp_report[issue_type]
]:
issues.append(
'%s regarding component "%s" has been fixed since last report.\nLast report sent the %s'
'%s regarding component "%s" has been fixed since last report.\nLast report datetime is: %s'
% (
"Alert" if issue_type == "alerts" else "Issue",
last_alert.splitlines()[0],
Expand Down Expand Up @@ -459,15 +463,15 @@ def scan_site(self, wp_site, last_wp_report=None):
"%s\n"
% (
WPWatcherNotification.build_message(
wp_report, warnings=True, infos=True
wp_report
)
)
)

# Notify recepients if match triggers
if self.mail.notify(wp_site, wp_report, last_wp_report):
# Store report time
wp_report["last_email"] = datetime.now().strftime(DATE_FORMAT)
wp_report["last_email"] = wp_report["datetime"]
# Discard fixed items because infos have been sent
wp_report["fixed"] = []

Expand Down

0 comments on commit e6c75a3

Please sign in to comment.