From 92c3627f333a90f17d3a5792f5553db37c891986 Mon Sep 17 00:00:00 2001 From: Shaswat Date: Mon, 13 Oct 2025 02:41:46 +0530 Subject: [PATCH] Fix pre-commit formatting issues --- nettacker/api/engine.py | 6 +++--- nettacker/core/app.py | 33 ++++++++++++++++++--------------- nettacker/core/arg_parser.py | 16 ++++++++-------- nettacker/core/template.py | 6 ++++-- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/nettacker/api/engine.py b/nettacker/api/engine.py index dc336424..4bf6a535 100644 --- a/nettacker/api/engine.py +++ b/nettacker/api/engine.py @@ -5,9 +5,9 @@ import os import random import string import time +from pathlib import Path from threading import Thread from types import SimpleNamespace -from pathlib import Path from flask import Flask, jsonify from flask import request as flask_request @@ -384,12 +384,12 @@ def get_result_content(): scan_id = get_value(flask_request, "id") if not scan_id: return jsonify(structure(status="error", msg=_("invalid_scan_id"))), 400 - + try: filename, file_content = get_scan_result(scan_id) except Exception: return jsonify(structure(status="error", msg="database error!")), 500 - + return Response( file_content, mimetype=mime_types().get(os.path.splitext(filename)[1], "text/plain"), diff --git a/nettacker/core/app.py b/nettacker/core/app.py index c45d4f24..397f9851 100644 --- a/nettacker/core/app.py +++ b/nettacker/core/app.py @@ -36,21 +36,24 @@ from nettacker.logger import TerminalCodes log = logger.get_logger() + def is_running_with_privileges(): - """ - Check if running with elevated privileges (root/admin) - - Returns: - bool: True if running as root (Unix) or Administrator (Windows) - """ - if sys.platform == "win32": - try: - import ctypes - return ctypes.windll.shell32.IsUserAnAdmin() != 0 - except Exception: - return False - else: - return os.geteuid() == 0 + """ + Check if running with elevated privileges (root/admin) + + Returns: + bool: True if running as root (Unix) or Administrator (Windows) + """ + if sys.platform == "win32": + try: + import ctypes + + return ctypes.windll.shell32.IsUserAnAdmin() != 0 + except Exception: + return False + else: + return os.geteuid() == 0 + class Nettacker(ArgParser): def __init__(self, api_arguments=None): @@ -180,7 +183,7 @@ class Nettacker(ArgParser): self.arguments.targets.append(sub_domain) # icmp_scan if self.arguments.ping_before_scan: - if is_running_with_privileges(): + if is_running_with_privileges(): selected_modules = self.arguments.selected_modules self.arguments.selected_modules = ["icmp_scan"] self.start_scan(scan_id) diff --git a/nettacker/core/arg_parser.py b/nettacker/core/arg_parser.py index 769c0cf1..9240eec2 100644 --- a/nettacker/core/arg_parser.py +++ b/nettacker/core/arg_parser.py @@ -1,7 +1,7 @@ import json import sys -from pathlib import Path from argparse import ArgumentParser +from pathlib import Path import yaml @@ -61,13 +61,13 @@ class ArgParser(ArgumentParser): Returns: an array of languages - """ + """ languages_list = [] for language in Config.path.locale_dir.glob("*.yaml"): - languages_list.append(Path(language).stem) + languages_list.append(Path(language).stem) return list(set(languages_list)) - + @staticmethod def load_modules(limit=-1, full_details=False): """ @@ -78,13 +78,13 @@ class ArgParser(ArgumentParser): Returns: an array of all module names - """ + """ # Search for Modules module_names = {} for module_name in sorted(Config.path.modules_dir.glob("**/*.yaml")): module_path = Path(module_name) - library = module_path.stem - category = module_path.parent.name + library = module_path.stem + category = module_path.parent.name module = f"{library}_{category}" contents = yaml.safe_load(TemplateLoader(module).open().split("payload:")[0]) module_names[module] = contents["info"] if full_details else None @@ -100,7 +100,7 @@ class ArgParser(ArgumentParser): module_names["all"] = {} return module_names - + @staticmethod def load_profiles(limit=-1): """ diff --git a/nettacker/core/template.py b/nettacker/core/template.py index ba165eb3..d88bc2bf 100644 --- a/nettacker/core/template.py +++ b/nettacker/core/template.py @@ -31,8 +31,10 @@ class TemplateLoader: module_name_parts = self.name.split("_") action = module_name_parts[-1] library = "_".join(module_name_parts[:-1]) - - with open(Config.path.modules_dir / action / f"{library}.yaml", encoding='utf-8') as yaml_file: + + with open( + Config.path.modules_dir / action / f"{library}.yaml", encoding="utf-8" + ) as yaml_file: return yaml_file.read() def format(self):