Zar-Branch #5
@@ -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__":
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
"""
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user