def merge_logs(domain, slavelist): logmergelist = ['/var/log/nginx/' + domain] for server in slavelist: logmergelist.append('/var/log/nginx-' + server + '/' + domain) subprocess.call( '/usr/local/cpanel/3rdparty/bin/logresolvemerge.pl -ignoremissing ' + ' '.join(logmergelist) + ' > /etc/apache2/logs/domlogs/' + domain, shell=True) for file in logmergelist: silentremove(file) logmergelist_ssl = ['/var/log/nginx/' + domain + '-ssl_log'] for server in slavelist: logmergelist_ssl.append('/var/log/nginx-' + server + '/' + domain + '-ssl_log') subprocess.call( '/usr/local/cpanel/3rdparty/bin/logresolvemerge.pl -ignoremissing ' + ' '.join(logmergelist) + ' > /etc/apache2/logs/domlogs/' + domain + '-ssl_log', shell=True) for file in logmergelist_ssl: silentremove(file) logmergelist_bytes = ['/var/log/nginx/' + domain + '-bytes_log'] for server in slavelist: logmergelist_bytes.append('/var/log/nginx-' + server + '/' + domain + '-bytes_log') subprocess.call( '/usr/local/cpanel/3rdparty/bin/logresolvemerge.pl -ignoremissing ' + ' '.join(logmergelist) + ' > /etc/apache2/logs/domlogs/' + domain + '-bytes_log', shell=True) for file in logmergelist_bytes: silentremove(file)
cluster_config_file = installation_path+"/conf/ndeploy_cluster.yaml" cpjson = json.load(sys.stdin) mydict = cpjson["data"] cpaneluser = mydict["user"] hook_output = mydict["output"] hook_output_dict = hook_output[0] status = hook_output_dict["result"] if status == 1: hookargs = mydict["args"] hookargs_domain = hookargs["domain"] conf_sub_domain = hookargs_domain.replace("_", ".", 1) if conf_sub_domain.startswith("*"): conf_sub_domain = "_wildcard_."+conf_sub_domain.replace('*.', '') silentremove(installation_path+"/domain-data/"+conf_sub_domain) silentremove(nginx_dir+conf_sub_domain+".conf") silentremove(nginx_dir+conf_sub_domain+".include") if os.path.isfile(cluster_config_file): with open(cluster_config_file, 'r') as cluster_data_yaml: cluster_data_yaml_parsed = yaml.safe_load(cluster_data_yaml) for server in cluster_data_yaml_parsed.keys(): silentremove("/etc/nginx/"+server+"/"+conf_sub_domain+".conf") silentremove("/etc/nginx/"+server+"/"+conf_sub_domain+".include") if os.path.exists('/var/resin/hosts/'+conf_sub_domain): shutil.rmtree('/var/resin/hosts/'+conf_sub_domain) sighupnginx() print(("1 nDeploy:cPaneltrigger:RemoveSubdom:"+conf_sub_domain)) else: print(("0 nDeploy:cPaneltrigger:SkipHook"))
if os.path.isfile(installation_path + "/hhvm.d/" + cpaneluser + ".ini"): subprocess.call(['systemctl', 'stop', 'ndeploy_hhvm@'+cpaneluser+'.service']) subprocess.call(['systemctl', 'disable', 'ndeploy_hhvm@'+cpaneluser+'.service']) if os.path.isfile(installation_path+"/conf/ndeploy_cluster.yaml"): subprocess.call('ansible -i /opt/nDeploy/conf/nDeploy-cluster/hosts ndeployslaves -m systemd -a "name=ndeploy_hhvm@'+cpaneluser+'.service state=stopped enabled=no"', shell=True) if os.path.isfile(installation_path + "/secure-php-fpm.d/" + cpaneluser + ".conf"): backend_config_file = installation_path+"/conf/backends.yaml" with open(backend_config_file, 'r') as backend_data_yaml: backend_data_yaml_parsed = yaml.safe_load(backend_data_yaml) if "PHP" in backend_data_yaml_parsed: php_backends_dict = backend_data_yaml_parsed["PHP"] for backend_name in list(php_backends_dict.keys()): subprocess.call(['systemctl', 'stop', backend_name+'@'+cpaneluser+'.service']) if os.path.isfile(installation_path+"/conf/ndeploy_cluster.yaml"): subprocess.call('ansible -i /opt/nDeploy/conf/nDeploy-cluster/hosts ndeployslaves -m systemd -a "name='+backend_name+'@'+cpaneluser+'.service state=stopped"', shell=True) silentremove(installation_path + "/php-fpm.d/" + cpaneluser + ".conf") silentremove(installation_path + "/secure-php-fpm.d/" + cpaneluser + ".conf") silentremove(installation_path + "/hhvm.d/" + cpaneluser + ".ini") silentremove(installation_path + "/hhvm.slave.d/" + cpaneluser + ".ini") subprocess.Popen(installation_path+"/scripts/init_backends.py reload", shell=True) cpuserdatajson = installation_path+"/lock/"+cpaneluser+".userdata" if os.path.exists(cpuserdatajson): with open(cpuserdatajson, 'r') as cpaneluser_data_stream: json_parsed_cpaneluser = json.load(cpaneluser_data_stream) main_domain = json_parsed_cpaneluser.get('main_domain') sub_domains = json_parsed_cpaneluser.get('sub_domains') silentremove(installation_path+"/domain-data/"+main_domain) silentremove(nginx_dir+main_domain+".conf") silentremove(nginx_dir+main_domain+".include") if os.path.isfile(cluster_config_file): with open(cluster_config_file, 'r') as cluster_data_yaml:
shutil.copyfile(TEMPLATE_FILE, main_domain_data_file) cpuser_uid = pwd.getpwnam(cpaneluser).pw_uid cpuser_gid = grp.getgrnam(cpaneluser).gr_gid os.chown(main_domain_data_file, cpuser_uid, cpuser_gid) os.chmod(main_domain_data_file, 0o660) sub_domains = json_parsed_cpaneluser.get('sub_domains') for the_sub_domain in sub_domains: if the_sub_domain.startswith("*"): sub_domain_data_file = installation_path + "/domain-data/_wildcard_." + the_sub_domain.replace( '*.', '') else: sub_domain_data_file = installation_path + "/domain-data/" + the_sub_domain shutil.copyfile(TEMPLATE_FILE, sub_domain_data_file) cpuser_uid = pwd.getpwnam(cpaneluser).pw_uid cpuser_gid = grp.getgrnam(cpaneluser).gr_gid os.chown(sub_domain_data_file, cpuser_uid, cpuser_gid) os.chmod(sub_domain_data_file, 0o660) if os.path.isfile(installation_path + '/php-fpm.d/' + cpaneluser + '.conf'): silentremove(installation_path + '/php-fpm.d/' + cpaneluser + '.conf') if os.path.isfile(installation_path + '/secure-php-fpm.d/' + cpaneluser + '.conf'): silentremove(installation_path + '/secure-php-fpm.d/' + cpaneluser + '.conf') subprocess.call(installation_path + "/scripts/generate_config.py " + cpaneluser, shell=True) sighupnginx() print("1 nDeploy:account_change_package:" + cpaneluser)
import sys try: import simplejson as json except ImportError: import json from commoninclude import silentremove __author__ = "Anoop P Alias" __copyright__ = "Copyright Anoop P Alias" __license__ = "GPL" __email__ = "*****@*****.**" installation_path = "/opt/nDeploy" # Absolute Installation Path nginx_dir = "/etc/nginx/sites-enabled/" cpjson = json.load(sys.stdin) mydict = cpjson["data"] cpaneluser = mydict["user"] # we copy the associated userdata file for the user for post hook stage with open("/var/cpanel/userdata/" + cpaneluser + "/main.cache", 'r') as userdata: userdata_json = json.load(userdata) # remove any stale userdata tmp files silentremove(installation_path+"/lock/"+cpaneluser+".userdata") with open(installation_path+"/lock/"+cpaneluser+".userdata", 'w') as tempuserdata: json.dump(userdata_json, tempuserdata) print(("1 nDeploy:remove:pre:"+cpaneluser))
installation_path = "/opt/nDeploy" # Absolute Installation Path nginx_dir = "/etc/nginx/sites-enabled/" cluster_config_file = installation_path + "/conf/ndeploy_cluster.yaml" cpjson = json.load(sys.stdin) mydict = cpjson["data"] theaddon = mydict["domain"] conversionstatus = mydict["status"] if conversionstatus == 1: # we find the associated subdomain from /etc/userdatadomains.json copied in pre script with open(installation_path + "/lock/" + theaddon, 'r') as userdatadomains: userdatadom = json.load(userdatadomains) addondata = userdatadom.get(theaddon) addonconfigdom = addondata[3] silentremove(installation_path + "/domain-data/" + addonconfigdom) silentremove(nginx_dir + addonconfigdom + ".conf") silentremove(nginx_dir + addonconfigdom + ".include") if os.path.isfile(cluster_config_file): with open(cluster_config_file, 'r') as cluster_data_yaml: cluster_data_yaml_parsed = yaml.safe_load(cluster_data_yaml) for server in cluster_data_yaml_parsed.keys(): silentremove("/etc/nginx/" + server + "/" + addonconfigdom + ".conf") silentremove("/etc/nginx/" + server + "/" + addonconfigdom + ".include") if os.path.exists('/var/resin/hosts/' + addonconfigdom): shutil.rmtree('/var/resin/hosts/' + addonconfigdom) sighupnginx() silentremove(installation_path + "/lock/" + theaddon) print(("1 nDeploy:cPaneltrigger:ConevrtAddon:" + addonconfigdom))