Skip to content

junque1r4/Audit-Checker

Repository files navigation

Audit File Manager

A comprehensive tool for managing and manipulating audit files with both CLI and web-based interfaces. This tool allows you to view, search, compare, and remove items from audit files efficiently.

Features

Core Functionality

  • Parse audit files - Extract and analyze custom items and reports from .audit files
  • Remove items - Selectively remove items by ID or description
  • Automatic backups - Creates timestamped backups before modifications
  • Smart parsing - Handles complex audit file structures including conditional blocks (if/then/else)

Web Interface

  • File upload and management - Upload and manage multiple audit files through a modern web interface
  • Search and filter - Search items by ID or description with real-time filtering
  • Bulk operations - Remove multiple items at once using various input formats
  • File comparison (diff) - Compare two audit files side-by-side and merge differences
  • Statistics dashboard - View detailed statistics about your audit files
  • Visual feedback - Interactive UI with real-time updates and notifications

REST API

  • Full-featured REST API for programmatic access
  • Upload, parse, search, and modify audit files
  • Compare files and merge differences
  • Bulk operations support

Installation

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)

Setup

  1. Clone the repository:
git clone <repository-url>
cd Audit-Checker
  1. Create a virtual environment (recommended):
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt

Usage

Command Line Interface (CLI)

Basic Usage

from main import find_and_remove_items, print_all_items

# List all items in an audit file
print_all_items("your_file.audit")

# Remove items by description
find_and_remove_items(
    "your_file.audit",
    descriptions_to_remove=["Ensure no duplicate user names exist"],
    remove_reports=True
)

Using the AuditManager Class

from audit_manager import AuditManager

# Initialize manager
manager = AuditManager()

# Load an audit file
manager.load_file("your_file.audit")

# Get all items
items = manager.get_all_elements()

# Search for specific items
results = manager.search_elements("ssh")

# Remove items by ID
manager.remove_elements(["1.1.1", "2.3.4"], remove_reports=True)

# Get statistics
stats = manager.get_statistics()
print(f"Total items: {stats['total_items']}")
print(f"Total reports: {stats['total_reports']}")

Web Interface

  1. Start the web server:
python app.py
  1. Open your browser and navigate to:
http://localhost:5333
  1. Main Interface - Upload and manage audit files:

    • Click "Upload File" to load an audit file
    • Use the search bar to find specific items
    • Select items to remove using checkboxes
    • Use "Bulk Removal" for removing multiple items at once
    • Download the modified file when done
  2. File Comparison - Compare two audit files:

    • Navigate to the "Compare Files" page
    • Select two files to compare
    • View differences side-by-side
    • Merge items between files
    • Export comparison reports

REST API Endpoints

File Management

  • POST /api/upload - Upload an audit file
  • GET /api/files - List available files
  • POST /api/load/<filename> - Load a specific file
  • GET /api/download - Download current file

Items and Search

  • GET /api/items - Get all items from loaded file
  • GET /api/search?q=<query> - Search items
  • GET /api/item/<item_id> - Get item details
  • GET /api/statistics - Get file statistics

Removal Operations

  • POST /api/remove - Remove selected items
    {
      "ids": ["1.1.1", "2.3.4"],
      "remove_reports": true
    }
  • POST /api/bulk-search - Search for multiple items
  • POST /api/bulk-remove - Remove multiple items

File Comparison (Diff)

  • POST /api/diff/load - Load two files for comparison
    {
      "file_a": "file1.audit",
      "file_b": "file2.audit"
    }
  • GET /api/diff/compare - Get comparison results
  • POST /api/diff/merge - Merge element from one file to another
  • POST /api/diff/remove - Remove element during comparison
  • POST /api/diff/batch-merge - Merge multiple elements

Project Structure

Audit-Checker/
├── app.py                 # Flask web application
├── main.py               # CLI script with core functionality
├── audit_manager.py      # AuditManager class for file operations
├── requirements.txt      # Python dependencies
├── templates/
│   ├── index.html       # Main web interface
│   └── diff.html        # File comparison interface
├── static/
│   ├── css/             # Stylesheets
│   └── js/              # JavaScript files
├── uploads/             # Uploaded audit files
└── backups/             # Automatic backups

How It Works

Parsing Mechanism

The tool parses audit files by:

  1. Identifying <custom_item> and <report> blocks
  2. Extracting IDs and descriptions using regex patterns
  3. Handling conditional blocks (<if>, <then>, <else>)
  4. Distinguishing between main items and condition items
  5. Tracking absolute positions for precise removal

Item Identification

Items are identified by:

  • ID: Numeric pattern (e.g., 1.2.3, 4.5.6.7)
  • Description: Text following the ID
  • Context: Location within the file structure (main vs condition)

Only items in main contexts (top-level, <then>, <else>) with numeric IDs are considered valid audit items.

Backup System

  • Automatic timestamped backups are created before any modification
  • Backups are stored in the backups/ directory
  • Format: filename.audit.YYYYMMDD_HHMMSS.backup

Bulk Removal

The bulk removal feature accepts multiple input formats:

# By ID only
1.1.1
2.3.4
5.6.7.8

# By ID with description
1.1.1 Ensure filesystem is mounted
2.3.4 Ensure permissions are set

# By partial description
Ensure SSH is configured
Configure firewall rules

# Mixed formats with various separators
1.1.1, 2.3.4; 3.4.5
Ensure no duplicate user names exist
Configure password policies

The system will:

  1. Parse your input list
  2. Search for matching items
  3. Display preview with match status
  4. Allow selective confirmation
  5. Create backup and remove selected items

File Comparison

The diff feature allows you to:

  • Compare two audit files side-by-side
  • Identify items unique to each file
  • Find modified items with detailed field-level differences
  • Merge items from one file to another
  • Remove unwanted items
  • Export comparison reports

Comparison categories:

  • Unique in A: Items only in first file
  • Unique in B: Items only in second file
  • Modified: Items present in both but with differences
  • Identical: Items that are exactly the same

Tips and Best Practices

  1. Review before removing - Always use the preview feature to verify items before removal
  2. Use backups - Backups are created automatically, but keep original files safe
  3. Bulk removal efficiency - Use the bulk removal feature for large-scale operations
  4. File comparison - Use diff to track changes between audit file versions
  5. Search functionality - Leverage search to quickly locate items in large files
  6. ID-based operations - Prefer ID-based operations for precision

Troubleshooting

Common Issues

File not loading:

  • Verify the file is a valid .audit file
  • Check file permissions
  • Ensure file encoding is UTF-8

Items not found during search:

  • Check if the item ID matches exactly
  • Verify the item is in a main context (not in <condition>)
  • Ensure the description contains the numeric ID prefix

Backup not created:

  • Check write permissions in the directory
  • Verify the backups/ directory exists
  • Ensure sufficient disk space

Debug Mode

Run the Flask app in debug mode for detailed error messages:

app.run(debug=True, host='0.0.0.0', port=5333)

Configuration

Web Server Settings

Edit app.py to modify:

  • Upload folder location (UPLOAD_FOLDER)
  • Maximum file size (MAX_CONTENT_LENGTH)
  • Allowed extensions (ALLOWED_EXTENSIONS)
  • Server host and port

Default Values

UPLOAD_FOLDER = 'uploads'
MAX_CONTENT_LENGTH = 16 * 1024 * 1024  # 16MB
ALLOWED_EXTENSIONS = {'audit'}
DEFAULT_PORT = 5333

Security Considerations

  • File uploads are restricted to .audit extensions only
  • Filenames are sanitized using secure_filename()
  • CORS is enabled for API access
  • Files are stored in a dedicated upload directory
  • Maximum file size is enforced (16MB default)

Contributing

Contributions are welcome. Please ensure:

  • Code follows existing style conventions
  • New features include appropriate documentation
  • API changes are backward compatible when possible

License

This project is provided as-is for audit file management purposes.

Support

For issues, questions, or feature requests, please refer to the project repository.


Note: Always maintain backups of your original audit files. While this tool creates automatic backups, it's best practice to keep separate copies of important files.

About

A simple audit file item remover.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published