77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""V117 - Add HTTP status to dashboards registry (show which are live 200 vs auth 302)"""
|
|
# Patch dashboards-registry.php to optionally include http_status
|
|
# Use curl local check
|
|
path = "/var/www/html/api/dashboards-registry.php"
|
|
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
c = f.read()
|
|
|
|
if "V117-HTTP-STATUS" in c:
|
|
print("ALREADY")
|
|
exit(0)
|
|
|
|
# Add optional http_status via curl (only when ?check=1 to avoid slowing default)
|
|
old = """foreach ($files as $f) {
|
|
$name = basename($f);
|
|
$size = filesize($f);
|
|
list($cat, $icon, $color) = categorize($name);"""
|
|
|
|
new = """$checkStatus = isset($_GET['check']) && $_GET['check'] === '1';
|
|
// V117-HTTP-STATUS: optional live HTTP status via local curl
|
|
function checkHttp($name) {
|
|
$ch = curl_init("http://127.0.0.1/$name");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_NOBODY => true,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 2,
|
|
CURLOPT_FOLLOWLOCATION => false,
|
|
CURLOPT_HTTPHEADER => ['Host: weval-consulting.com']
|
|
]);
|
|
curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
return $code;
|
|
}
|
|
|
|
foreach ($files as $f) {
|
|
$name = basename($f);
|
|
$size = filesize($f);
|
|
list($cat, $icon, $color) = categorize($name);"""
|
|
|
|
if old not in c:
|
|
print("anchor missing")
|
|
exit(1)
|
|
c = c.replace(old, new, 1)
|
|
|
|
# Add http_status to entry if checked
|
|
old2 = """ $entry = [
|
|
'name' => $name,
|
|
'display' => $display,
|
|
'url' => '/' . $name,
|
|
'category' => $cat,
|
|
'icon' => $icon,
|
|
'color' => $color,
|
|
'size_kb' => round($size/1024, 1),
|
|
'mtime' => date('c', filemtime($f))
|
|
];"""
|
|
|
|
new2 = """ $entry = [
|
|
'name' => $name,
|
|
'display' => $display,
|
|
'url' => '/' . $name,
|
|
'category' => $cat,
|
|
'icon' => $icon,
|
|
'color' => $color,
|
|
'size_kb' => round($size/1024, 1),
|
|
'mtime' => date('c', filemtime($f))
|
|
];
|
|
if ($checkStatus) $entry['http_status'] = checkHttp($name);"""
|
|
|
|
if old2 in c:
|
|
c = c.replace(old2, new2, 1)
|
|
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(c)
|
|
print(f"PATCHED size={len(c)}")
|