Skip to content

Commit

Permalink
Add options to keep_report and report_path (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyJiao authored and nwalsh-lnk committed Apr 5, 2019
1 parent 2f7eb7e commit ba1b265
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions qark/qark.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@
help="Type of report to generate along with terminal output.", default="html", show_default=True)
@click.option("--exploit-apk/--no-exploit-apk", default=False,
help="Create an exploit APK targetting a few vulnerabilities.", show_default=True)
@click.option("--report-path", type=click.Path(resolve_path=True, file_okay=False), default=None,
help="report output path.", show_default=True)
@click.option("--keep-report/--no-keep-report", default=False,
help="Append to final report file.", show_default=True)
@click.version_option()
@click.pass_context
def cli(ctx, sdk_path, build_path, debug, source, report_type, exploit_apk):
def cli(ctx, sdk_path, build_path, debug, source, report_type, exploit_apk, report_path, keep_report):
if not source:
click.secho("Please pass a source for scanning through either --java or --apk")
click.secho(ctx.get_help())
Expand Down Expand Up @@ -91,7 +95,7 @@ def cli(ctx, sdk_path, build_path, debug, source, report_type, exploit_apk):
click.secho("Finish scans...")

click.secho("Writing report...")
report = Report(issues=set(scanner.issues))
report = Report(issues=set(scanner.issues), report_path=report_path, keep_report=keep_report)
report_path = report.generate(file_type=report_type)
click.secho("Finish writing report to {report_path} ...".format(report_path=report_path))

Expand Down
11 changes: 8 additions & 3 deletions qark/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class Report(object):
# http://python-3-patterns-idioms-test.readthedocs.io/en/latest/Singleton.html#the-singleton
__instance = None

def __new__(cls, issues=None, report_path=None):
def __new__(cls, issues=None, report_path=None, keep_report=False):
if Report.__instance is None:
Report.__instance = object.__new__(cls)

return Report.__instance

def __init__(self, issues=None, report_path=None):
def __init__(self, issues=None, report_path=None, keep_report=False):
"""This will give you an instance of a report, with a default report path which is local
to where QARK is on the file system.
Expand All @@ -45,6 +45,7 @@ def __init__(self, issues=None, report_path=None):
"""
self.issues = issues if issues else []
self.report_path = report_path or DEFAULT_REPORT_PATH
self.keep_report = keep_report

def generate(self, file_type='html', template_file=None):
"""This method uses Jinja2 to generate a standalone HTML version of the report.
Expand All @@ -58,11 +59,15 @@ def generate(self, file_type='html', template_file=None):

full_report_path = path.join(self.report_path, 'report.{file_type}'.format(file_type=file_type))

with open(full_report_path, mode='w') as report_file:
open_flag = 'w'
if self.keep_report:
open_flag = 'a'
with open(full_report_path, mode=open_flag) as report_file:
if not template_file:
template = jinja_env.get_template('{file_type}_report.jinja'.format(file_type=file_type))
else:
template = Template(template_file)
report_file.write(template.render(issues=list(self.issues)))
report_file.write('\n')

return full_report_path

0 comments on commit ba1b265

Please sign in to comment.