#!/opt/cppython/bin/python3 -B
"""
copyright(c) cpnginx.com
Hook for rebuilding domain vhosts
"""
import os
import sys
import json
import subprocess

def read_in():
    lines = sys.stdin.readlines()
    for i in range(len(lines)):
        lines[i] = lines[i].replace('\n','')
    return lines

def main():
    lines = read_in()
    data=lines[0]
    cpdata = json.loads(data)
    sub=cpdata['data']['args']['domain']
    root=cpdata['data']['args']['rootdomain']
    domain=sub+"."+root
    cmd="/usr/local/cpanel/scripts/nginxctl rebuildvhost "+domain
    process = subprocess.run(cmd, shell=True,check=True,stdout=subprocess.PIPE)
    out=process.stdout
    return(1)

if __name__ == "__main__":
    main()
