HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //opt/Autom8Redis/autom8redis_wrapper.py
#!/usr/bin/env python3

import argparse
import json
import os
import subprocess

import yaml


__author__ = "Anoop P Alias"
__copyright__ = "Copyright Anoop P Alias"
__license__ = "GPL"
__email__ = "[email protected]"


installation_path = "/opt/Autom8Redis"  # Absolute Installation Path
autom8n_installation_path = "/opt/nDeploy"  # Absolute Installation Path
cluster_config_file = autom8n_installation_path+"/conf/ndeploy_cluster.yaml"

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Autom8Redis wrapper script for Ansible playbook run")
    parser.add_argument("CPUSER")
    parser.add_argument("CPHOME")
    parser.add_argument("STATUS")
    args = parser.parse_args()
    cpaneluser = args.CPUSER
    cpanelhome = args.CPHOME
    status = args.STATUS

    # get current hosting plan for the cPanel user
    if os.path.exists("/var/cpanel/users.cache/" + cpaneluser):
        with open("/var/cpanel/users.cache/" + cpaneluser, encoding='utf-8') as users_file:
            json_parsed_cpusersfile = json.load(users_file)
        myplan = json_parsed_cpusersfile.get('PLAN', 'default')
    else:
        # If cpanel users file is not present set plan to default
        myplan = 'default'
    # get maxmemory setting for the hosting PLAN
    if os.path.isfile(installation_path+"/plan_memory.yaml"):
        plan_memory_file = installation_path+"/plan_memory.yaml"
        plan_memory = open(plan_memory_file, 'r')
        plan_memory_yaml = yaml.safe_load(plan_memory)
        plan_memory.close()
        plan_memory_default = plan_memory_yaml.get('default', '32mb')
        plan_memory_user = plan_memory_yaml.get(myplan, plan_memory_default)
    else:
        plan_memory_user = '32mb'
    # Run Playbook with the data we have now
    extravars = 'CPANELUSER='+cpaneluser+' CPANELHOME='+cpanelhome+' MAXMEMORY='+plan_memory_user
    if status == "ON":
        subprocess.call('ansible-playbook -i /opt/Autom8Redis/redissetup/hosts /opt/Autom8Redis/redissetup/redis_init.yml --extra-vars "'+extravars+'"', shell=True)
        if os.path.exists(cluster_config_file):
            the_raw_cmd_slave='ansible -i /opt/nDeploy/conf/nDeploy-cluster/hosts ndeployslaves -m shell -a \'ansible-playbook -i /opt/Autom8Redis/redissetup/hosts /opt/Autom8Redis/redissetup/redis_init.yml --extra-vars \"'+extravars+'\"\''
            subprocess.call(the_raw_cmd_slave, shell=True)
    else:
        subprocess.call('ansible-playbook -i /opt/Autom8Redis/redissetup/hosts /opt/Autom8Redis/redissetup/redis_del.yml --extra-vars "'+extravars+'"', shell=True)
        if os.path.exists(cluster_config_file):
            the_raw_cmd_slave='ansible -i /opt/nDeploy/conf/nDeploy-cluster/hosts ndeployslaves -m shell -a \'ansible-playbook -i /opt/Autom8Redis/redissetup/hosts /opt/Autom8Redis/redissetup/redis_del.yml --extra-vars \"'+extravars+'\"\''
            subprocess.call(the_raw_cmd_slave, shell=True)