Major refactor: security enhancements, modularization, config integration, reduced Parquet reliance
- Migrated codebase to class-based architecture for better modularity and maintainability - Introduced system_config.json for centralized configuration (required for runtime) - Added structured working directories for improved file organization - Significantly reduced reliance on Parquet; replaced with alternative data handling - Implemented security improvements across modules - Several TODOs remain in the main script for future enhancements - Linter formatting affected readability in some files (e.g., utils); cleanup is on the agenda
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
# Copyright (C) 2025 James Brotosky, Brandon Wickline
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import ClassVar, Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class Agent:
|
||||
agentid: str
|
||||
clientversion: str
|
||||
domain: str
|
||||
freespace: int
|
||||
groupid: int
|
||||
hostname: str
|
||||
ip: str
|
||||
localip: str
|
||||
lastcheckin: str
|
||||
os: str
|
||||
policyversion: str
|
||||
status: int # raw status code
|
||||
username: str
|
||||
groupname: Optional[str] = field(default=None)
|
||||
status_text: Optional[str] = field(default=None)
|
||||
|
||||
# Class-level status map
|
||||
status_map: ClassVar[dict] = {0: "Offline", 1: "Online", 2: "Hidden", 3: "Safemode"}
|
||||
|
||||
def enrich(self, groupid_to_name: dict):
|
||||
"""Enrich the agent with groupname and human-readable status."""
|
||||
self.groupname = groupid_to_name.get(self.groupid, None)
|
||||
self.status_text = self.status_map.get(self.status, "Unknown")
|
||||
|
||||
|
||||
"""
|
||||
|
||||
from models.agent import Agent
|
||||
from modesls.policy
|
||||
|
||||
# Step 1: Load data from API
|
||||
policies = [Policy(**row['data']) for _, row in api.policy_find_all().iterrows()]
|
||||
agents = [Agent(**row['data']) for _, row in api.agent_find_all().iterrows()]
|
||||
|
||||
# Step 2: Create groupid → groupname map
|
||||
groupid_to_name = {policy.groupid: policy.name for policy in policies}
|
||||
|
||||
# Step 3: Enrich agents
|
||||
for agent in agents:
|
||||
agent.enrich(groupid_to_name)
|
||||
|
||||
|
||||
"""
|
||||
Reference in New Issue
Block a user