import paramiko

c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('160.187.143.253', username='root', password=';ur7n)LC1BQ;')

def r(cmd):
    print(f"Executing: {cmd}")
    _, so, se = c.exec_command(cmd)
    stdout = so.read().decode('utf-8', 'replace').strip()
    stderr = se.read().decode('utf-8', 'replace').strip()
    if stdout: print(f"STDOUT:\n{stdout}")
    if stderr: print(f"STDERR:\n{stderr}")
    return stdout

print("--- FIXING NGINX PROXY BUFFERS ---")
# Create a conf file for global proxy buffers
buffer_conf = """
proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;
large_client_header_buffers 4 16k;
"""
cmd = f"echo '{buffer_conf}' > /etc/nginx/conf.d/proxy_buffers.conf"
r(cmd)
r("nginx -t")
r("systemctl restart nginx")

c.close()
