diff --git a/AirlockTools.py b/AirlockTools.py index 4bb59a5..db86f5f 100644 --- a/AirlockTools.py +++ b/AirlockTools.py @@ -3,6 +3,7 @@ import os import utils.getdeviceevents import utils.allowlist import utils.hashfunctions +import utils.pathfunctions import urllib3 import pandas as pd @@ -46,6 +47,15 @@ def menu(): categorized[0].to_html("needsreview.html", index=False) categorized[1].to_html("approved.html", index=False) categorized[2].to_html("remaining.html", index=False) + if choice == '4': + html_file = "augmentedlist.html" + augmented_df = pd.read_html(html_file) + print(augmented_df) + + combined_df = pd.concat(augmented_df, ignore_index=True) + test = utils.pathfunctions.filepathInitalGroup(combined_df) + test.to_html("testgroup2.html", index=False) + if __name__ == "__main__": diff --git a/utils/__pycache__/allowlist.cpython-313.pyc b/utils/__pycache__/allowlist.cpython-313.pyc index b9c9af8..52a66d4 100644 Binary files a/utils/__pycache__/allowlist.cpython-313.pyc and b/utils/__pycache__/allowlist.cpython-313.pyc differ diff --git a/utils/__pycache__/getdeviceevents.cpython-313.pyc b/utils/__pycache__/getdeviceevents.cpython-313.pyc index 6613a36..f6c0a32 100644 Binary files a/utils/__pycache__/getdeviceevents.cpython-313.pyc and b/utils/__pycache__/getdeviceevents.cpython-313.pyc differ diff --git a/utils/__pycache__/hashfunctions.cpython-313.pyc b/utils/__pycache__/hashfunctions.cpython-313.pyc index 0bcb08c..1f2c5c2 100644 Binary files a/utils/__pycache__/hashfunctions.cpython-313.pyc and b/utils/__pycache__/hashfunctions.cpython-313.pyc differ diff --git a/utils/__pycache__/pathfunctions.cpython-313.pyc b/utils/__pycache__/pathfunctions.cpython-313.pyc new file mode 100644 index 0000000..c645a86 Binary files /dev/null and b/utils/__pycache__/pathfunctions.cpython-313.pyc differ diff --git a/utils/hashfunctions.py b/utils/hashfunctions.py index 65a7150..7ab2d8d 100644 --- a/utils/hashfunctions.py +++ b/utils/hashfunctions.py @@ -91,43 +91,3 @@ def categorizeHashes(aug_df: pd.DataFrame, threat_tolerance: int, untrusted_publ remaining_df = df[~(mask_needsreview | mask_approved)] return needsreview_df, approved_df, remaining_df - - -""" -def categorizeHashes(aug_df: pd.DataFrame, threat_tolerance: int, untrusted_publishers: list): - - Categorize hashes into needsreview, approved, and remaining based on publisher and threat level. - - - if untrusted_publishers is None: - untrusted_publishers = [] - - # Flatten threatlevel from nested reputation dict - df = aug_df.copy() - - # Masks for each category - mask_needsreview = ((df["publisher_y"] == "Not Signed") & reputationtool(df)) - - print(mask_needsreview) - - mask_approved = (df["publisher_y"] != "Not Signed") & (~df["publisher_y"].isin(untrusted_publishers)) - - print(mask_approved) - - # Create DataFrames for each category - needsreview_df = df[mask_needsreview] - approved_df = df[mask_approved] - remaining_df = df[~(mask_needsreview | mask_approved)] - - return needsreview_df, approved_df, remaining_df - -def approvehashes(approved_df: pd.DataFrame): - pass - -def reputationtool(df): - if df["reputation_scannermatch"] == "N/A": - return True - if df["reputation_scannermatch"].astype(int) > 3: - return True - return False - """ \ No newline at end of file diff --git a/utils/pathfunctions.py b/utils/pathfunctions.py new file mode 100644 index 0000000..ec618e5 --- /dev/null +++ b/utils/pathfunctions.py @@ -0,0 +1,39 @@ +import pandas as pd +import os + + +def filepathInitalGroup(df: pd.DataFrame) -> pd.DataFrame: + import os + import pandas as pd + from itertools import chain + + # 1. Split comma-separated filenames into lists + df["filename_x"] = df["filename_x"].str.split(",") + + # 2. Explode so each filename has its own row + df = df.explode("filename_x", ignore_index=True) + + # 3. Strip whitespace from filenames + df["filename_x"] = df["filename_x"].str.strip() + + # 4. Split into directory and filename + df["directory"] = df["filename_x"].apply(lambda x: os.path.dirname(x) if pd.notna(x) else "") + df["filename"] = df["filename_x"].apply(lambda x: os.path.basename(x) if pd.notna(x) else "") + + # 5. Drop the original column + df = df.drop(columns=["filename_x"]) + + # 6. Ensure all columns are lists (except directory, which is the key) + for col in df.columns: + if col != "directory": + df[col] = df[col].apply(lambda x: x if isinstance(x, list) else [x]) + + # 7. Combine rows with the same directory, flatten lists, deduplicate + def combine_lists(series): + flat = list(chain.from_iterable(series)) + # deduplicate while preserving order + return list(dict.fromkeys(flat)) + + df = df.groupby("directory", as_index=False).agg(combine_lists) + + return df