File size: 6,894 Bytes
383cb38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python3
"""
Privacy Cleanup Script
Remove personal information from public repository

This script replaces personal information with generic alternatives
to maintain privacy in public repositories.
"""

from datetime import datetime
import json
import os
from pathlib import Path
import re
import sys

print("🔒 PRIVACY CLEANUP SCRIPT")
print("=" * 80)
print("Removing personal information from public repository")
print("=" * 80)

# Define replacements for privacy
REPLACEMENTS = {
    # Personal name replacements
    "developer": "developer",
    "Developer": "Developer",
    
    # Email replacements
    "noreply@atom.com": "noreply@atom.com",
    "noreply@atom.com": "noreply@atom.com",
    "noreply@atom.com": "noreply@atom.com",
    
    # Path replacements
    "/home/developer/home/developer",
    "/home/developer/projects/atom": "/home/developer/projects",
    "/home/developer/atom-production": "/opt/atom",
    
    # Generic replacements for other personal identifiers
    "CHANGE_THIS_PASSWORD": "CHANGE_THIS_PASSWORD",
    "CHANGE_THIS_REDIS_PASSWORD": "CHANGE_THIS_REDIS_PASSWORD",
    "CHANGE_THIS_APP_PASSWORD": "CHANGE_THIS_APP_PASSWORD",
    "noreply@atom.com": "noreply@atom.com",
    "localhost": "localhost",
}

def clean_file_content(content):
    """Clean personal information from file content"""
    cleaned_content = content
    
    for personal_info, replacement in REPLACEMENTS.items():
        cleaned_content = cleaned_content.replace(personal_info, replacement)
    
    # Remove any remaining personal paths with regex
    cleaned_content = re.sub(r'/home/developer/]+', '/home/developer', cleaned_content)
    
    return cleaned_content

def clean_file(file_path):
    """Clean a single file"""
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
        
        original_content = content
        cleaned_content = clean_file_content(content)
        
        # Only write if content changed
        if original_content != cleaned_content:
            with open(file_path, 'w', encoding='utf-8') as f:
                f.write(cleaned_content)
            return True
        
        return False
        
    except Exception as e:
        print(f"   ❌ Error cleaning {file_path}: {str(e)}")
        return False

def clean_directory(directory, extensions_to_clean=None):
    """Clean all files in directory recursively"""
    if extensions_to_clean is None:
        extensions_to_clean = {'.py', '.json', '.yml', '.yaml', '.md', '.sh', '.conf', '.txt'}
    
    cleaned_files = []
    total_files = 0
    
    print(f"\n📁 Cleaning directory: {directory}")
    print("-" * 60)
    
    for file_path in directory.rglob('*'):
        if file_path.is_file() and file_path.suffix in extensions_to_clean:
            total_files += 1
            
            # Skip .git and hidden files
            if '.git' in str(file_path) or file_path.name.startswith('.'):
                continue
            
            if clean_file(file_path):
                cleaned_files.append(file_path)
                print(f"   ✅ Cleaned: {file_path.name}")
    
    print(f"\n📊 Cleaning Summary for {directory}:")
    print(f"   📄 Total Files: {total_files}")
    print(f"   ✅ Files Cleaned: {len(cleaned_files)}")
    
    return cleaned_files

def main():
    """Main privacy cleanup"""
    try:
        current_dir = Path.cwd()
        project_dir = current_dir
        
        print(f"📂 Project Directory: {project_dir}")
        
        # Clean all relevant files
        all_cleaned_files = []
        
        # Clean main project directory
        cleaned_files = clean_directory(project_dir)
        all_cleaned_files.extend(cleaned_files)
        
        # Clean atom-production if it exists
        prod_dir = Path("/home/developer/atom-production")
        if prod_dir.exists():
            cleaned_prod_files = clean_directory(prod_dir)
            all_cleaned_files.extend(cleaned_prod_files)
        else:
            # Check local production directory
            local_prod_dir = Path.home() / "atom-production"
            if local_prod_dir.exists():
                cleaned_prod_files = clean_directory(local_prod_dir)
                all_cleaned_files.extend(cleaned_prod_files)
        
        # Generate privacy report
        privacy_report = {
            "cleanup_completed": True,
            "timestamp": datetime.now().isoformat(),
            "total_files_cleaned": len(all_cleaned_files),
            "files_cleaned": [str(f) for f in all_cleaned_files],
            "replacements_made": REPLACEMENTS,
            "privacy_note": "All personal information has been replaced with generic alternatives for public repository privacy."
        }
        
        # Save privacy report
        report_file = project_dir / "privacy_cleanup_report.json"
        with open(report_file, 'w') as f:
            json.dump(privacy_report, f, indent=2)
        
        print(f"\n" + "=" * 80)
        print("🔒 PRIVACY CLEANUP COMPLETED!")
        print("=" * 80)
        print(f"✅ Total Files Cleaned: {len(all_cleaned_files)}")
        print(f"📄 Privacy Report Saved: {report_file}")
        print("=" * 80)
        
        print("\n🔍 REPLACEMENTS MADE:")
        print("-" * 60)
        for original, replacement in REPLACEMENTS.items():
            if "email" in original.lower() or "domain" in original.lower():
                print(f"   📧 {original}{replacement}")
            elif "password" in original.lower():
                print(f"   🔒 {original}{replacement}")
            elif "path" in str(original):
                print(f"   📂 {original}{replacement}")
            else:
                print(f"   🔄 {original}{replacement}")
        
        print("\n🛡️ PRIVACY MEASURES:")
        print("-" * 60)
        print("   ✅ Personal names removed")
        print("   ✅ Personal email addresses replaced")
        print("   ✅ Personal file paths sanitized")
        print("   ✅ Personal identifiers removed")
        print("   ✅ Sensitive information protected")
        
        print("\n📋 NEXT STEPS:")
        print("-" * 60)
        print("   1. Review the cleaned files")
        print("   2. Verify no personal information remains")
        print("   3. Update README.md with generic developer info")
        print("   4. Commit changes to public repository")
        print("   5. Test functionality with sanitized paths")
        
        return privacy_report
        
    except Exception as e:
        print(f"\n❌ Privacy cleanup failed: {str(e)}")
        import traceback
        traceback.print_exc()
        return {"cleanup_completed": False, "error": str(e)}

if __name__ == "__main__":
    result = main()
    sys.exit(0 if result.get("cleanup_completed", False) else 1)