def crisis_handler(filename):
- # Setup for permission error test
- if filename == "classified_vault.txt":
- try:
- with open(filename, "w") as f:
- f.write("TOP SECRET")
- os.chmod(filename, 0o000) # Make unreadable
- except OSError as e:
- print(f"Setup error for {filename}: {e}")
-
# Determine log prefix
if filename == "standard_archive.txt":
print(f"ROUTINE ACCESS: Attempting access to '{filename}'...")
try:
with open(filename, "r") as f:
content = f.read().strip()
- print(
- f'SUCCESS: Archive recovered - "{content}"'
- ) # Note: escaped quote here is intentional
+ print(f'SUCCESS: Archive recovered - "{content}"')
print("STATUS: Normal operations resumed")
except FileNotFoundError:
print("RESPONSE: Archive not found in storage matrix")
except Exception as e:
print(f"RESPONSE: Unexpected error: {e}")
print("STATUS: Crisis handled")
- finally:
- # Cleanup for permission error test
- if filename == "classified_vault.txt" and os.path.exists(filename):
- try:
- os.chmod(filename, 0o666) # Restore permissions
- os.remove(filename)
- except OSError:
- pass
def main():
print("=== CYBER ARCHIVES - CRISIS RESPONSE SYSTEM ===")
- test_files = [
- "lost_archive.txt",
- "classified_vault.txt",
- "standard_archive.txt",
- ]
+ # Scenario 1: Missing Archive
+ crisis_handler("lost_archive.txt")
+
+ # Scenario 2: Security Violation (Simulated)
+ vault_filename = "classified_vault.txt"
+ try:
+ # Setup: Create and lock the vault
+ with open(vault_filename, "w") as f:
+ f.write("TOP SECRET")
+ os.chmod(vault_filename, 0o000) # Make unreadable
+
+ crisis_handler(vault_filename)
+
+ except OSError as e:
+ print(f"Test setup failed: {e}")
+ finally:
+ # Cleanup: Unlock and remove
+ if os.path.exists(vault_filename):
+ try:
+ os.chmod(vault_filename, 0o666)
+ os.remove(vault_filename)
+ except OSError:
+ pass
- for filename in test_files:
- crisis_handler(filename)
+ # Scenario 3: Standard Access
+ crisis_handler("standard_archive.txt")
print("All crisis scenarios handled successfully. Archives secure.")