#!/usr/bin/env python3 path = "/etc/nginx/sites-enabled/weval-consulting" with open(path, "rb") as f: raw = f.read() # Check if server 1 has @api_error location # Server 1 goes from line 7 to first "}" after line 33 lines = raw.split(b"\n") # Line 6 = index 6 (0-indexed line 7) # Find server 1 close - first standalone "}" after line 33 close_line = None for i in range(33, 80): # Look between line 33 and ~80 if i < len(lines) and lines[i].strip() == b"}": close_line = i break print(f"Server 1 close at line: {close_line+1}") # Check if @api_error is already in server 1 (between lines 7-close_line) server1 = b"\n".join(lines[6:close_line+1]) if b"location @api_error" in server1: print("Server 1 already has @api_error") exit(0) # Insert location @api_error BEFORE close_line insert = [ b"", b" # V88: named location @api_error for server 1 (HTTP)", b" location @api_error {", b" default_type application/json;", b" return 503 '{\"ok\":false,\"error\":\"api_error\",\"msg\":\"service temporarily unavailable\"}';", b" }", b"", ] lines = lines[:close_line] + insert + lines[close_line:] new_raw = b"\n".join(lines) with open(path, "wb") as f: f.write(new_raw) print(f"Inserted @api_error at line {close_line+1}") print(f"Size: {len(raw)} → {len(new_raw)}")