From f43ebbb6fae2afbf8b206adfe96714b47636d67e Mon Sep 17 00:00:00 2001 From: overcuriousity Date: Fri, 13 Dec 2024 10:59:01 +0100 Subject: [PATCH] update webinterface --- .gitignore | 3 +++ maigret/maigret.py | 12 +++++++++ maigret/resources/settings.json | 3 ++- maigret/settings.py | 1 + app.py => maigret/web/app.py | 25 ++++++++----------- .../web/templates}/base.html | 0 .../web/templates}/index.html | 0 .../web/templates}/results.html | 0 pyproject.toml | 2 ++ 9 files changed, 31 insertions(+), 15 deletions(-) rename app.py => maigret/web/app.py (91%) rename {templates => maigret/web/templates}/base.html (100%) rename {templates => maigret/web/templates}/index.html (100%) rename {templates => maigret/web/templates}/results.html (100%) diff --git a/.gitignore b/.gitignore index 0cd418f..76a6d4a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ lib/bindings/utils.js lib/tom-select/tom-select.complete.min.js lib/tom-select/tom-select.css lib/vis-9.1.2/vis-network.css +poetry.lock +filetree.sh +poetry.lock diff --git a/maigret/maigret.py b/maigret/maigret.py index eb1b8a9..6d5d205 100755 --- a/maigret/maigret.py +++ b/maigret/maigret.py @@ -324,6 +324,14 @@ def setup_arguments_parser(settings: Settings): default=False, help="Show database statistics (most frequent sites engines and tags).", ) + modes_group.add_argument( + "--web", + action="store", + metavar='PORT', + type=int, + default=settings.web_interface_port, + help="Launches the web interface on the specified port (Default: 5000).", + ) output_group = parser.add_argument_group( 'Output options', 'Options to change verbosity and view of the console output' @@ -484,6 +492,10 @@ async def main(): elif args.verbose: log_level = logging.WARNING logger.setLevel(log_level) + + if args.web: + from maigret.web.app import app + app.run(port=args.web) # Use the port from arguments # Usernames initial list usernames = { diff --git a/maigret/resources/settings.json b/maigret/resources/settings.json index 656f358..82f90f7 100644 --- a/maigret/resources/settings.json +++ b/maigret/resources/settings.json @@ -53,5 +53,6 @@ "xmind_report": false, "graph_report": false, "pdf_report": false, - "html_report": false + "html_report": false, + "web_interface_port": 5000 } \ No newline at end of file diff --git a/maigret/settings.py b/maigret/settings.py index 31b9ca5..a355d39 100644 --- a/maigret/settings.py +++ b/maigret/settings.py @@ -42,6 +42,7 @@ class Settings: pdf_report: bool html_report: bool graph_report: bool + web_interface_port: int # submit mode settings presence_strings: list diff --git a/app.py b/maigret/web/app.py similarity index 91% rename from app.py rename to maigret/web/app.py index 9a33116..672d7aa 100644 --- a/app.py +++ b/maigret/web/app.py @@ -151,20 +151,17 @@ def download_report(filename): logging.error(f"Error serving file {filename}: {str(e)}") return "File not found", 404 -@app.route('/view_graph/') -def view_graph(graph_path): - """Serve the graph HTML directly""" - graph_file = os.path.join(REPORTS_FOLDER, graph_path) - try: - with open(graph_file, 'r', encoding='utf-8') as f: - content = f.read() - return content - except FileNotFoundError: - logging.error(f"Graph file not found: {graph_file}") - return "Graph not found", 404 - except Exception as e: - logging.error(f"Error serving graph {graph_file}: {str(e)}") - return "Error loading graph", 500 +#@app.route('/view_graph/') +#def view_graph(graph_path): +# """Serve the graph HTML directly""" +# graph_file = os.path.join(REPORTS_FOLDER, graph_path) +# try: +# with open(graph_file, 'r', encoding='utf-8') as f: +# content = f.read() +# return content +# except Exception as e: +# logging.error(f"Error serving graph {graph_file}: {str(e)}") +# return "Error loading graph", 500 if __name__ == '__main__': logging.basicConfig( diff --git a/templates/base.html b/maigret/web/templates/base.html similarity index 100% rename from templates/base.html rename to maigret/web/templates/base.html diff --git a/templates/index.html b/maigret/web/templates/index.html similarity index 100% rename from templates/index.html rename to maigret/web/templates/index.html diff --git a/templates/results.html b/maigret/web/templates/results.html similarity index 100% rename from templates/results.html rename to maigret/web/templates/results.html diff --git a/pyproject.toml b/pyproject.toml index 19e1633..b6c6f0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,8 @@ networkx = "^2.6.3" pyvis = "^0.3.2" reportlab = "^4.2.0" cloudscraper = "^1.2.71" +flask = {extras = ["async"], version = "^3.1.0"} +asgiref = "^3.8.1" [tool.poetry.group.dev.dependencies]