Your IP : 216.73.216.247


Current Path : /opt/cpanel/
Upload File :
Current File : //opt/cpanel/zarc_renew_domain.py

import socket
import ssl
import struct
import uuid
import sys
from datetime import datetime

# ----- Config -----
EPP_HOST = "196.29.59.153"
EPP_PORT = 700
EPP_USER = "enetworks"
EPP_PASS = "36ancerg9a2"

# ----- EPP Helpers -----
def frame(xml_string):
    xml_bytes = xml_string.encode('utf-8')
    return struct.pack("!I", len(xml_bytes) + 4) + xml_bytes

def read_response(sock):
    header = sock.recv(4)
    if not header:
        return None
    total_length = struct.unpack("!I", header)[0]
    data = b''
    while len(data) < total_length - 4:
        chunk = sock.recv(total_length - 4 - len(data))
        if not chunk:
            break
        data += chunk
    return data.decode('utf-8')

def build_login_xml():
    return f"""<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  <command>
    <login>
      <clID>{EPP_USER}</clID>
      <pw>{EPP_PASS}</pw>
      <options>
        <version>1.0</version>
        <lang>en</lang>
      </options>
      <svcs>
        <objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
        <objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
        <objURI>http://co.za/epp/extensions/cozadomain-1-0</objURI>
        <objURI>http://co.za/epp/extensions/cozacontact-1-0</objURI>
      </svcs>
    </login>
    <clTRID>{uuid.uuid4()}</clTRID>
  </command>
</epp>"""

def build_renew_xml(domain, cur_exp_date, period=1):
    return f"""<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  <command>
    <renew>
      <domain:renew xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
        <domain:name>{domain}</domain:name>
        <domain:curExpDate>{cur_exp_date}</domain:curExpDate>
        <domain:period unit="y">{period}</domain:period>
      </domain:renew>
    </renew>
    <clTRID>{uuid.uuid4()}</clTRID>
  </command>
</epp>"""

# ----- Main -----
def main():
    if len(sys.argv) != 3:
        print("Usage: python zarc_renew_domain.py <domain.co.za> <current-expiry-date:YYYY-MM-DD>")
        sys.exit(1)

    domain = sys.argv[1]
    cur_exp_date = sys.argv[2]
    try:
        datetime.strptime(cur_exp_date, "%Y-%m-%d")
    except ValueError:
        print("Invalid expiry date format. Use YYYY-MM-DD.")
        sys.exit(1)

    context = ssl.create_default_context()
    with socket.create_connection((EPP_HOST, EPP_PORT)) as tcp_sock:
        with context.wrap_socket(tcp_sock, server_hostname=EPP_HOST) as epp_sock:
            print("[+] Connected to ZARC via TLS")

            # Greeting
            greeting = read_response(epp_sock)
            print("[i] Greeting:\n", greeting)

            # Login
            print("[*] Logging in...")
            epp_sock.sendall(frame(build_login_xml()))
            login_response = read_response(epp_sock)
            print("[i] Login Response:\n", login_response)

            # Send renew
            print(f"[*] Renewing domain: {domain}")
            renew_xml = build_renew_xml(domain, cur_exp_date)
            epp_sock.sendall(frame(renew_xml))
            renew_response = read_response(epp_sock)
            print("[+] Renew Response:\n", renew_response)

if __name__ == "__main__":
    main()