Skip to content

tietjen/CIS-Migration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

XML Control Merger

A Python-based text processing tool that merges missing CONTROL structures between XML files while preserving original formatting and CDATA sections.

Overview

This script processes XML files as plain text and intelligently copies missing CONTROL elements from a source (ORIG) file into a target file, creating a complete output file. It's particularly useful for CIS benchmark migrations and policy structure management.

Features

  • Text-based Processing: Preserves original XML formatting and CDATA sections
  • Smart Merging: Identifies and copies only missing CONTROL elements
  • Position Preservation: Maintains the original position of CONTROL elements from the source file
  • Auto-disable: Automatically sets IS_CONTROL_DISABLE to 1 for copied controls
  • Section Tracking: Updates CONTROLS total count per section automatically
  • Verbose Mode: Optional detailed reporting of inserted elements

Requirements

  • Python 3.6+
  • No external dependencies (uses standard library only)

Installation

  1. Clone this repository:
git clone <repository-url>
cd CIS-Migration
  1. Create a virtual environment (optional but recommended):
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

Usage

Basic Usage

python xml_control_merger.py <ORIG_FILE> <TARGET_FILE> <OUT_FILE>

With Verbose Output

python xml_control_merger.py --verbose <ORIG_FILE> <TARGET_FILE> <OUT_FILE>

Example

python xml_control_merger.py CIS_W2022.xml TEST_W2022.xml output.xml

With detailed reporting:

python xml_control_merger.py --verbose CIS_W2022.xml TEST_W2022.xml output.xml

How It Works

  1. Load Files: Reads both ORIG and TARGET XML files as text
  2. Identify Sections: Extracts all SECTION numbers from the TARGET file
  3. Compare Controls: For each section, identifies missing CONTROL elements by comparing IDs
  4. Insert Missing Controls: Copies missing controls from ORIG to TARGET at their original positions
  5. Modify Attributes: Sets IS_CONTROL_DISABLE to 1 for all copied controls
  6. Update Counts: Updates the CONTROLS total attribute for each modified section
  7. Save Output: Writes the merged result to the output file

Output

The script provides real-time feedback during processing:

  • Section-by-section progress
  • Number of missing controls found per section
  • Insertion confirmation with position information
  • Final summary (in verbose mode)

Example Output

Loading ORIG file: CIS_W2022.xml
Loading TARGET file: TEST_W2022.xml
Creating 1:1 copy of the TARGET file as OUT file...
Performing CONTROL merge...
Processing section 1...
  3 missing CONTROL elements found: {'12345', '12346', '12347'}
  CONTROL 12345 was copied and inserted at position 0
  CONTROL 12346 was copied and inserted at position 1
  CONTROL 12347 was copied and inserted at position 2
  CONTROLS total updated to 15
Processing completed successfully!

Use Cases

  • CIS Benchmark policy migrations
  • XML configuration file merging
  • Policy structure synchronization
  • Control element management across environments

License

This project is available for use in accordance with your organization's policies.

Contributing

Contributions, issues, and feature requests are welcome.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages