-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_sample.py
More file actions
68 lines (56 loc) · 2.33 KB
/
Copy pathgen_sample.py
File metadata and controls
68 lines (56 loc) · 2.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Generate the sample report HTML for the README screenshots."""
import sys, os, shutil
from datetime import datetime
sys.path.insert(0, '.')
os.environ['GITHUB_TOKEN'] = os.environ.get('GITHUB_TOKEN', '')
from analyzer import analyze
from ui.github_info import fetch_repo_info
from flask import Flask, render_template
app = Flask(__name__, template_folder='ui/templates')
REPO_URL = 'https://github.com/OmarRao/analyzer'
print('[1/3] Fetching GitHub repository info...')
gh_info = fetch_repo_info(REPO_URL)
print(f" {gh_info.get('full_name')} | Stars: {gh_info.get('stars')} | Lang: {gh_info.get('language')}")
print('[2/3] Running Semgrep analysis...')
result = analyze(REPO_URL)
findings = [f.__dict__ for f in result.findings]
print(f" {len(findings)} findings | {len(result.dependency_vulns)} CVEs")
ts = datetime.now().strftime('%Y%m%d_%H%M%S')
score_raw = (
len([f for f in findings if f.get('severity') == 'ERROR']) * 10 +
len([f for f in findings if f.get('severity') == 'WARNING']) * 3 +
len(result.dependency_vulns) * 8
)
score = min(score_raw, 100)
if score >= 70: grade, gcolor = 'CRITICAL', '#f25757'
elif score >= 45: grade, gcolor = 'HIGH', '#e6a817'
elif score >= 20: grade, gcolor = 'MEDIUM', '#4f8ef7'
else: grade, gcolor = 'LOW', '#3ecf79'
print('[3/4] Running ransomware intelligence analysis...')
from ransomware import detect as ransomware_detect
rw_report = ransomware_detect(findings)
print(f' score={rw_report.ransomware_score} blast={rw_report.blast_label} behaviors={rw_report.behavior_count} families={len(rw_report.family_matches)}')
print(f'[4/4] Building HTML report (score={score}, grade={grade})...')
with app.app_context():
html = render_template(
'report.html',
generated_at=datetime.now().strftime('%Y-%m-%d %H:%M UTC'),
repo_url=REPO_URL,
repo_slug='analyzer',
ts=ts,
gh_info=gh_info,
summary=result.summary(),
findings=findings,
dependency_vulns=result.dependency_vulns,
ransomware=rw_report,
runtime=None,
score=score,
grade=grade,
gcolor=gcolor,
)
out_path = 'reports/sample_report_ui.html'
with open(out_path, 'w', encoding='utf-8') as f:
f.write(html)
print(f' Saved: {out_path}')
shutil.rmtree(result.repo_path, ignore_errors=True)
print('Done.')