#!/opt/cppython/bin/python3 -B
"""
copyright(c) cpnginx.com
Hook for creating the new cpanel user 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)
    cpuser=cpdata["data"]["user"]
    #with open('/var/log/hook.txt', 'w+') as a:
    #    a.write(cpuser)
    cmd="/usr/local/cpanel/scripts/nginxctl rebuilduservhost "+cpuser
    process = subprocess.run(cmd, shell=True,check=True,stdout=subprocess.PIPE)
    out=process.stdout
    return(1)

if __name__ == "__main__":
    main()
