-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_engine.py
More file actions
executable file
·51 lines (42 loc) · 1.33 KB
/
Copy pathverify_engine.py
File metadata and controls
executable file
·51 lines (42 loc) · 1.33 KB
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
import os
import hashlib
import json
from datetime import datetime
WATCH_PATHS = ['/opt/SELFIX']
CRITICAL_FILES = [
'yang_engine.py',
'entropy_resolver.py',
'healing_manager.py',
'karma_guard.py'
]
LOG_PATH = '/opt/SELFIX/logs/verify_log.json'
def compute_sha256(file_path):
with open(file_path, 'rb') as f:
return hashlib.sha256(f.read()).hexdigest()
def verify_files():
report = {
"verified_on": datetime.utcnow().isoformat(),
"results": []
}
for root, _, files in os.walk('/opt/SELFIX'):
for file in files:
full_path = os.path.join(root, file)
rel_path = os.path.relpath(full_path, '/opt/SELFIX')
status = {
"file": rel_path,
"exists": True,
"hash": None,
"critical": file in CRITICAL_FILES
}
try:
status["hash"] = compute_sha256(full_path)
except Exception as e:
status["exists"] = False
status["error"] = str(e)
report["results"].append(status)
os.makedirs(os.path.dirname(LOG_PATH), exist_ok=True)
with open(LOG_PATH, 'w') as f:
json.dump(report, f, indent=4)
print(f"✅ Verification completed. Report saved to {LOG_PATH}")
if __name__ == "__main__":
verify_files()