Start Tor with an ephemeral hidden service and set TOR_ONION. This fixes common issues with a static HiddenServiceDir (stale keys/permissions), by using a fresh directory each run (logic adapted from Connections.py).
(port: int)
| 16907 | while True: |
| 16908 | cand = os.path.join(out_dir, f"Profiler-{n}.zip") |
| 16909 | if not os.path.exists(cand): |
| 16910 | out_zip = cand |
| 16911 | break |
| 16912 | n += 1 |
| 16913 | |
| 16914 | with zipfile.ZipFile(out_zip, "w", compression=zipfile.ZIP_DEFLATED) as z: |
| 16915 | z.write(os.path.join(tmp_dir, "profiles.json"), arcname="profiles.json") |
| 16916 | for root, _, files in os.walk(att_out_root): |
| 16917 | for fn in files: |
| 16918 | full = os.path.join(root, fn) |
| 16919 | arc = os.path.relpath(full, tmp_dir) |
| 16920 | z.write(full, arcname=arc) |
| 16921 | |
| 16922 | shutil.rmtree(tmp_dir, ignore_errors=True) |
| 16923 | flash(f"Exported to: {out_zip}") |
| 16924 | except Exception as e: |
| 16925 | log.exception("Profiler export failed: %s", e) |
| 16926 | flash("Export failed.") |
| 16927 | return redirect(url_for("profiler")) |
| 16928 | |
| 16929 | @app.route("/profiler/combine", methods=["POST"]) |
| 16930 | @login_required |
| 16931 | def profiler_combine(): |
| 16932 | """profiler_combine. |
| 16933 | |
| 16934 | Route handler or application helper. |
| 16935 | |
| 16936 | This docstring was expanded to make future maintenance easier. |
| 16937 | |
| 16938 | Returns: |
| 16939 | Varies. |
| 16940 | """ |
| 16941 | owner = current_user() |
| 16942 | try: |
| 16943 | ddir = downloads_dir() |
| 16944 | # Pick latest Profiler*.zip by mtime |
| 16945 | zips = sorted(glob.glob(os.path.join(ddir, "Profiler*.zip")), key=lambda p: os.path.getmtime(p)) |
| 16946 | if not zips: |
| 16947 | flash("No Profiler.zip found in Downloads.") |
| 16948 | return redirect(url_for("profiler")) |
| 16949 | latest = zips[-1] |
| 16950 | |
| 16951 | tmp_dir = os.path.join(BASE_DIR, "_tmp_profiler_import") |
| 16952 | if os.path.isdir(tmp_dir): |
| 16953 | shutil.rmtree(tmp_dir, ignore_errors=True) |
| 16954 | os.makedirs(tmp_dir, exist_ok=True) |
| 16955 | |
| 16956 | with zipfile.ZipFile(latest, "r") as z: |
| 16957 | z.extractall(tmp_dir) |
| 16958 | |
| 16959 | meta_path = os.path.join(tmp_dir, "profiles.json") |
| 16960 | if not os.path.isfile(meta_path): |
| 16961 | shutil.rmtree(tmp_dir, ignore_errors=True) |
| 16962 | flash("Invalid zip: missing profiles.json") |
| 16963 | return redirect(url_for("profiler")) |
| 16964 | |
| 16965 | meta = json.load(open(meta_path, "r", encoding="utf-8")) |
| 16966 | profiles = meta.get("profiles") or [] |
nothing calls this directly
no test coverage detected