22 lines
927 B
Python
22 lines
927 B
Python
#!/usr/bin/env python3
|
|
"""Relay email through OVH server via SSH. Usage: python3 ovh_relay_send.py <json_file>"""
|
|
import sys,json,subprocess,tempfile,os
|
|
|
|
json_file = sys.argv[1]
|
|
with open(json_file) as f:
|
|
data = json.load(f)
|
|
|
|
# Write JSON to temp, SCP to OVH, execute there
|
|
json_str = json.dumps(data)
|
|
b64 = subprocess.run(["base64","-w0"], input=json_str.encode(), capture_output=True).stdout.decode()
|
|
|
|
ssh_cmd = f'echo {b64} | base64 -d > /tmp/relay_email.json && python3 /home/ubuntu/wevads/ovh_dkim_send.py /tmp/relay_email.json 2>&1 && rm -f /tmp/relay_email.json'
|
|
|
|
result = subprocess.run(
|
|
["sshpass","-p","MX8D3zSAty7k3243242","ssh","-o","StrictHostKeyChecking=no","-o","ConnectTimeout=10","ubuntu@151.80.235.110", ssh_cmd],
|
|
capture_output=True, text=True, timeout=30
|
|
)
|
|
output = result.stdout.strip()
|
|
print(output if output else f"FAIL:{result.stderr.strip()}")
|
|
sys.exit(0 if output.startswith("OK") else 1)
|