Skip to content

Commit

Permalink
Template report as parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
atao committed Feb 5, 2024
1 parent f834bcd commit 30634a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ Usage: shodan2db.py export [OPTIONS]
Generate an HTML report from the data in the database.
Options:
-d, --database PATH Path to the SQLite database file. [required]
-o, --report-file PATH Output path for the HTML report file. [default:
shodan.html]
-v, --verbose Verbose mode.
-h, --help Show this message and exit.
-d, --database PATH Path to the SQLite database file. [required]
-o, --report-file PATH Output path for the HTML report file. [default:
shodan.html]
-t, --template-file PATH Template used for the report. [default:
report.html]
-v, --verbose Verbose mode.
-h, --help Show this message and exit.
```

## Quickstart
Expand Down
10 changes: 6 additions & 4 deletions shodan2db.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def parser(verbose, inputfile, database):

# Static method to generate an HTML report from the database data
@staticmethod
def export(verbose, exportfile, database):
def export(verbose, exportfile, database, template_file):
if not exportfile.endswith(".html"):
exportfile = "{}.html".format(exportfile)
if not database.endswith(".db"):
Expand Down Expand Up @@ -192,7 +192,7 @@ def export(verbose, exportfile, database):
cves_data.append(cves)

environment = Environment(loader=FileSystemLoader("templates/"))
template = environment.get_template("report.html")
template = environment.get_template(template_file)
filename = exportfile
content = template.render(
hosts=hosts_data,
Expand Down Expand Up @@ -240,13 +240,15 @@ def validate_database(ctx, param, value):
type=click.Path(exists=True), required=True)
@click.option('--report-file', '-o', default='shodan.html', help='Output path for the HTML report file.',
show_default=True, type=click.Path(writable=True))
@click.option('--template-file', '-t', default='report.html', help='Template used for the report.',
show_default=True, type=click.Path(exists=True))
@click.option('--verbose', '-v', is_flag=True, help="Verbose mode.")
def export(verbose, database, report_file):
def export(verbose, database, report_file, template_file):
"""
Generate an HTML report from the data in the database.
"""
# With the callback validation, no need for an explicit check here
Shodan2DB.export(verbose=verbose, database=database, exportfile=report_file)
Shodan2DB.export(verbose=verbose, database=database, exportfile=report_file, template_file=template_file)


# Add the parse and export commands to the CLI group
Expand Down

0 comments on commit 30634a8

Please sign in to comment.