-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_sync.py
More file actions
85 lines (68 loc) · 2.56 KB
/
full_sync.py
File metadata and controls
85 lines (68 loc) · 2.56 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
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
#!/usr/bin/env python3
"""
Full CVE synchronization script
Downloads ALL historical CVEs from the NVD database
"""
import os
import sys
import sqlite3
from datetime import datetime
# Import the main module
from app import CVEMonitor, DB_NAME
def main():
print("="*60)
print("CVE FULL SYNCHRONIZATION SCRIPT")
print("="*60)
# Check for the API key
api_key = os.environ.get('NVD_API_KEY', '')
if not api_key:
print("\nWARNING: No NVD API key found!")
print("To configure:")
print(" Linux/Mac: export NVD_API_KEY='your_api_key_here'")
print(" Windows: set NVD_API_KEY=your_api_key_here")
print("\nWithout an API key, the synchronization will be VERY slow (5 req/30s)")
response = input("\nContinue without an API key? (y/n): ")
if response.lower() != 'y':
sys.exit(0)
else:
print("API key detected")
# Create an instance of the monitor
monitor = CVEMonitor()
# Check the current state
conn = sqlite3.connect(DB_NAME)
cursor = conn.cursor()
cursor.execute("SELECT COUNT(*) FROM cves")
current_count = cursor.fetchone()[0]
conn.close()
print(f"\nCurrent state: {current_count} CVEs in the database")
# Estimate the time
if api_key:
estimated_time = "2-4 hours"
else:
estimated_time = "12-24 hours"
print(f"\nEstimated time: {estimated_time}")
print("This synchronization will download ALL CVEs since 1999")
print("You can interrupt and resume later")
response = input("\nStart the full synchronization? (y/n): ")
if response.lower() != 'y':
print("Synchronization cancelled.")
sys.exit(0)
# Start the synchronization
start_time = datetime.now()
print(f"\nStart: {start_time.strftime('%Y-%m-%d %H:%M:%S')}")
try:
total = monitor.fetch_all_cves_historical()
end_time = datetime.now()
duration = end_time - start_time
print(f"\nSYNCHRONIZATION COMPLETE!")
print(f"Total CVEs downloaded: {total}")
print(f"Duration: {duration}")
print(f"End: {end_time.strftime('%Y-%m-%d %H:%M:%S')}")
except KeyboardInterrupt:
print("\n\nWARNING: Synchronization interrupted by the user")
print("You can relaunch the script to continue")
except Exception as e:
print(f"\nERROR during synchronization: {e}")
sys.exit(1)
if __name__ == "__main__":
main()