????

Your IP : 3.142.210.226


Current Path : /scripts/
Upload File :
Current File : //scripts/selectorunparkhook.py

#!/opt/cloudlinux/venv/bin/python3 -bb
# -*- coding: utf-8 -*-

# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import simplejson as json
import sys

from clcommon.clpwd import drop_privileges

from clselect.clselectnodejs.apps_manager import ApplicationsManager as NodeJsAppsManager
from clselect.clselectpython.apps_manager import ApplicationsManager as PythonAppsManager


def main():
    lines = sys.stdin.read()
    json_decode = json.loads(lines)
    hook_data = json_decode['data']
    user = hook_data['user']
    unparked_domain = hook_data['domain']
    parent_domain = hook_data['parent_domain']
    change_domain_in_config(user, unparked_domain, parent_domain, 'nodejs')
    change_domain_in_config(user, unparked_domain, parent_domain, 'python')
    print(1, 'Ok')


def change_domain_in_config(user, unparked_domain, parent_domain, interpreter):
    """
    Changes domain in selector json config
    :param user: username
    :param unparked_domain: domain that was unparked
    :param parent_domain: primary user domain
    :param interpreter: selector interpreter
    """
    if interpreter == 'nodejs':
        apps_manager = NodeJsAppsManager()
    elif interpreter == 'python':
        apps_manager = PythonAppsManager()
    else:
        raise NotImplementedError()

    with drop_privileges(user):
        apps_manager.replace_domain_in_configs(
            user, unparked_domain, parent_domain,
            include_subdomains=True)


if "__main__" == __name__:
    main()