36 lines
1016 B
Python
36 lines
1016 B
Python
#!/usr/bin/env python3
|
|
path = "/var/www/html/api/searxng-proxy.php"
|
|
with open(path, "rb") as f:
|
|
raw = f.read()
|
|
|
|
if b"V88 hardened" in raw:
|
|
print("ALREADY")
|
|
exit(0)
|
|
|
|
# After <?php tag - add safety limits
|
|
old = b"<?php"
|
|
new = b"""<?php
|
|
// V88 hardened: limits + error handling
|
|
@set_time_limit(20);
|
|
@ini_set('memory_limit', '128M');
|
|
@ini_set('max_execution_time', 20);
|
|
"""
|
|
if old in raw and raw.count(b"V88 hardened") == 0:
|
|
idx = raw.find(old)
|
|
raw = raw[:idx] + new + raw[idx+len(old):]
|
|
|
|
# Also wrap curl_exec with error capture
|
|
old2 = b"$r = curl_exec($ch);\ncurl_close($ch);\necho $r ?: '{\"error\":\"searxng down\"}';"
|
|
new2 = b"""$r = curl_exec($ch);
|
|
$err = curl_error($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
if ($r === false || $err) { echo json_encode(['error'=>'searxng down', 'curl_err'=>$err, 'http_code'=>$code]); exit; }
|
|
echo $r;"""
|
|
if old2 in raw:
|
|
raw = raw.replace(old2, new2, 1)
|
|
|
|
with open(path, "wb") as f:
|
|
f.write(raw)
|
|
print(f"Size: {len(raw)}")
|