25 lines
1.2 KiB
Bash
Executable File
25 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# V84 daily WTP integrity scan - run at 3am
|
|
cd /var/www/html
|
|
python3 <<PYEOF > /opt/weval-l99/kpi-cache/wtp-integrity.json
|
|
import subprocess, json, re, time
|
|
wtp_c = open("/var/www/html/weval-technology-platform.html").read()
|
|
links = set(re.findall(r'href=["\']([^"\'#?]+\.html)', wtp_c))
|
|
apis = set(re.findall(r"['\"](/api/[a-z0-9_\-]+\.php)", wtp_c))
|
|
results = {"ts": time.strftime("%Y-%m-%dT%H:%M:%S"), "tested": 0, "pass": 0, "fail": 0, "fails": []}
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
def t(url):
|
|
r = subprocess.run(["curl","-sk","-o","/dev/null","-w","%{http_code}","--max-time","5",url],capture_output=True,text=True,timeout=8)
|
|
return r.stdout.strip()
|
|
items = [("html", l) for l in links] + [("api", a) for a in apis]
|
|
with ThreadPoolExecutor(max_workers=10) as ex:
|
|
for (typ, name), code in zip(items, ex.map(lambda it: t(f"https://weval-consulting.com/{it[1].lstrip('/')}"), items)):
|
|
results["tested"] += 1
|
|
if code in ("200","302"): results["pass"] += 1
|
|
else:
|
|
results["fail"] += 1
|
|
results["fails"].append({"type":typ,"name":name,"http":code})
|
|
results["pass_rate"] = round(results["pass"]/max(1,results["tested"])*100, 1)
|
|
print(json.dumps(results, indent=2))
|
|
PYEOF
|