"""Deploy fixed chatwoot_proxy.py (safe polishQuickQuestions) to guest-chat.""" import os import sys from pathlib import Path import paramiko pw = os.environ["DEPLOY_PASSWORD"] local = Path(r"F:/AI/guest-cs-stack/flask/chatwoot_proxy.py") remote_sh = "/home/wakka/_deploy_proxy_fix.sh" c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("20.191.152.26", username="wakka", password=pw, timeout=30) sftp = c.open_sftp() with sftp.file("/home/wakka/chatwoot_proxy.py.patch", "wb") as rf: rf.write(local.read_bytes().replace(b"\r\n", b"\n")) script = b"""#!/bin/bash set -e sudo docker cp /home/wakka/chatwoot_proxy.py.patch guest-chat:/opt/guest-cs/chatwoot_proxy.py sudo docker restart guest-chat sleep 14 curl -s -o /dev/null -w "guest:%{http_code}\\n" http://127.0.0.1:7777/guest-customer-service html=$(curl -s "http://127.0.0.1:7777/cw/widget?website_token=j1UAjqBgZMWQ8WfczgJSymQx" -H "Host: 20.191.152.26:7777") echo "has_pullTags=$(printf '%s' "$html" | grep -c 'function pullTags' || true)" echo "has_bad_escape=$(printf '%s' "$html" | grep -c 'tagOpen.replace' || true)" echo "has_qq=$(printf '%s' "$html" | grep -c 'polishQuickQuestions' || true)" printf '%s' "$html" | grep -n 'pullTags\\|data-yd-qq\\|PROMO_SRC' | head -20 """ with sftp.file(remote_sh, "wb") as rf: rf.write(script) sftp.close() _, o, e = c.exec_command(f"bash {remote_sh}", timeout=120) sys.stdout.write(o.read().decode("utf-8", "replace")) err = e.read().decode("utf-8", "replace") if err: sys.stderr.write(err) code = o.channel.recv_exit_status() c.close() sys.exit(code)