214 lines
6.0 KiB
Bash
Executable File
214 lines
6.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Complete Network Mapping Workflow
|
|
# This script runs the full network discovery and diagram generation process
|
|
|
|
set -e # Exit on any error
|
|
|
|
echo "=========================================="
|
|
echo "COMPREHENSIVE NETWORK MAPPING WORKFLOW"
|
|
echo "=========================================="
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
print_step() {
|
|
echo -e "${BLUE}[STEP]${NC} $1"
|
|
}
|
|
|
|
# Check if required files exist
|
|
check_requirements() {
|
|
print_step "Checking requirements..."
|
|
|
|
if [ ! -f "network_scanner.py" ]; then
|
|
print_error "network_scanner.py not found!"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "pfsense_xml_parser.py" ]; then
|
|
print_error "pfsense_xml_parser.py not found!"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "comprehensive_mapper.py" ]; then
|
|
print_error "comprehensive_mapper.py not found!"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "svg_generator.py" ]; then
|
|
print_error "svg_generator.py not found!"
|
|
exit 1
|
|
fi
|
|
|
|
print_status "All required scripts found"
|
|
}
|
|
|
|
# Find pfSense XML files
|
|
find_pfsense_files() {
|
|
print_step "Looking for pfSense XML configuration files..."
|
|
|
|
PFSENSE_FILES=$(ls config-*.xml 2>/dev/null || true)
|
|
|
|
if [ -z "$PFSENSE_FILES" ]; then
|
|
print_warning "No pfSense XML files found in current directory"
|
|
print_warning "Please place your pfSense backup XML files here"
|
|
echo "Expected format: config-hostname-timestamp.xml"
|
|
return 1
|
|
fi
|
|
|
|
print_status "Found pfSense XML files:"
|
|
echo "$PFSENSE_FILES" | while read -r file; do
|
|
echo " - $file"
|
|
done
|
|
|
|
# Export for use in other functions
|
|
export PFSENSE_FILES
|
|
return 0
|
|
}
|
|
|
|
# Run network scan (optional)
|
|
run_network_scan() {
|
|
print_step "Running network scan..."
|
|
|
|
if [ -f "config.json" ]; then
|
|
print_status "Using existing config.json for network scan"
|
|
python3 network_scanner.py -c config.json -o network_scan.json
|
|
else
|
|
print_warning "No config.json found - skipping network scan"
|
|
print_warning "Create config.json to enable live network scanning"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Run comprehensive mapping
|
|
run_comprehensive_mapping() {
|
|
print_step "Running comprehensive network mapping..."
|
|
|
|
# Build command with pfSense files
|
|
CMD="./comprehensive_mapper.py -o comprehensive_network.json --svg comprehensive_network.svg -v"
|
|
|
|
if [ -n "$PFSENSE_FILES" ]; then
|
|
CMD="$CMD -p $PFSENSE_FILES"
|
|
fi
|
|
|
|
if [ -f "network_scan.json" ]; then
|
|
CMD="$CMD -s network_scan.json"
|
|
fi
|
|
|
|
print_status "Executing: $CMD"
|
|
eval $CMD
|
|
}
|
|
|
|
# Generate summary report
|
|
generate_report() {
|
|
print_step "Generating summary report..."
|
|
|
|
if [ -f "comprehensive_network.json" ]; then
|
|
echo "# Network Mapping Report" > network_report.md
|
|
echo "Generated on: $(date)" >> network_report.md
|
|
echo "" >> network_report.md
|
|
|
|
# Extract key statistics
|
|
SEGMENTS=$(jq '.segments | length' comprehensive_network.json)
|
|
PFSENSE_COUNT=$(jq '.pfsense_firewalls | length' comprehensive_network.json)
|
|
WG_NETWORKS=$(jq '.wireguard_networks | length' comprehensive_network.json)
|
|
STATIC_ROUTES=$(jq '.routing_table | length' comprehensive_network.json)
|
|
DHCP_MAPPINGS=$(jq '.static_mappings | length' comprehensive_network.json)
|
|
|
|
echo "## Network Statistics" >> network_report.md
|
|
echo "- Network Segments: $SEGMENTS" >> network_report.md
|
|
echo "- pfSense Firewalls: $PFSENSE_COUNT" >> network_report.md
|
|
echo "- WireGuard Networks: $WG_NETWORKS" >> network_report.md
|
|
echo "- Static Routes: $STATIC_ROUTES" >> network_report.md
|
|
echo "- DHCP Static Mappings: $DHCP_MAPPINGS" >> network_report.md
|
|
echo "" >> network_report.md
|
|
|
|
echo "## Generated Files" >> network_report.md
|
|
echo "- comprehensive_network.json - Complete network data" >> network_report.md
|
|
echo "- comprehensive_network.svg - Network topology diagram" >> network_report.md
|
|
echo "- network_report.md - This summary report" >> network_report.md
|
|
|
|
print_status "Report generated: network_report.md"
|
|
else
|
|
print_error "No comprehensive network data found"
|
|
fi
|
|
}
|
|
|
|
# Main workflow
|
|
main() {
|
|
echo "Starting comprehensive network mapping workflow..."
|
|
echo ""
|
|
|
|
check_requirements
|
|
|
|
if ! find_pfsense_files; then
|
|
print_error "Cannot proceed without pfSense XML files"
|
|
exit 1
|
|
fi
|
|
|
|
# Optional network scan
|
|
if [ -f "config.json" ]; then
|
|
run_network_scan
|
|
fi
|
|
|
|
# Comprehensive mapping (required)
|
|
run_comprehensive_mapping
|
|
|
|
# Generate report
|
|
generate_report
|
|
|
|
echo ""
|
|
print_status "Workflow completed successfully!"
|
|
echo ""
|
|
echo "Generated files:"
|
|
echo " 📊 comprehensive_network.json - Complete network data"
|
|
echo " 🖼️ comprehensive_network.svg - Network topology diagram"
|
|
echo " 📋 network_report.md - Summary report"
|
|
echo ""
|
|
echo "Open comprehensive_network.svg in your browser to view the network diagram"
|
|
}
|
|
|
|
# Handle command line arguments
|
|
case "${1:-}" in
|
|
"scan-only")
|
|
check_requirements
|
|
run_network_scan
|
|
;;
|
|
"map-only")
|
|
check_requirements
|
|
find_pfsense_files
|
|
run_comprehensive_mapping
|
|
;;
|
|
"report-only")
|
|
generate_report
|
|
;;
|
|
"help"|"-h"|"--help")
|
|
echo "Usage: $0 [command]"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " (no command) - Run full workflow"
|
|
echo " scan-only - Run only network scan"
|
|
echo " map-only - Run only comprehensive mapping"
|
|
echo " report-only - Generate only summary report"
|
|
echo " help - Show this help"
|
|
;;
|
|
*)
|
|
main
|
|
;;
|
|
esac |