- GRAYBYTE UNDETECTABLE CODES -

403Webshell
Server IP : 184.154.167.98  /  Your IP : 3.17.174.204
Web Server : Apache
System : Linux pink.dnsnetservice.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
User : puertode ( 1767)
PHP Version : 7.2.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/l.v.e-manager/hooks/plesk/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/l.v.e-manager/hooks/plesk/PHP_settings_update.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
#modification, are permitted provided that the following conditions
#are met:
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * The names of its contributors may not be used to endorse or
#    promote products derived from this software without specific
#    prior written permission.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
#LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
#ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#POSSIBILITY OF SUCH DAMAGE.
#

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import sys
import os
import shutil
import subprocess

import cldetectlib
import clcommon.cpapi
from clcommon import ClPwd, mysql_lib


def print_error_and_exit(*args):
    """
    Print error and exit
    :param args:
    :return:
    """
    print("Error:", end=' ', file=sys.stderr)
    for a in args:
        print(a, end=' ', file=sys.stderr)
    print(file=sys.stderr)
    sys.exit(1)


def get_user_prefix(username):
    """
    Get user prefix
    :param username: User name
    :return: User's prefix
    """
    try:
        clpwd = ClPwd()
        uid = clpwd.get_uid(username)
    except ClPwd.NoSuchUserException:
        print_error_and_exit('user %s not found' % username)
    b = uid % 100
    prefix = "%02d" % b
    return prefix


def exec_cagefsctl(cagefsctl_args):
    """
    Executes cagefsctl with supplied arguments
    :param cagefsctl_args: cagefsctl arguments
    :return: None
    """
    args = list()
    args.append('/usr/sbin/cagefsctl')
    args.extend(cagefsctl_args)
    process = subprocess.Popen(args)
    process.communicate()
    retcode = process.returncode
    if retcode != 0:
        # cagefsctl error
        sys.exit(1)


def get_user_by_domain(domain_name):
    """
    Retrieves user name by domain from Plesk DB
    :param domain_name: Domain name
    :return: User name
    """
    # Get Plesk DB access
    db_access = clcommon.cpapi.db_access()
    db_name = "psa"
    s_query = "SELECT su.login FROM sys_users su, hosting h, domains d, domains sd " \
              "WHERE h.sys_user_id=su.id AND h.dom_id=d.id AND (d.name='%s' OR d.id=sd.webspace_id AND " \
              "sd.name='%s') LIMIT 1" % (domain_name, domain_name)

    connector = mysql_lib.MySQLConnector(host='localhost', user=db_access['login'],
                                         passwd=db_access['pass'], db=db_name)
    with connector.connect() as db:
        data = db.execute_query(s_query)
    try:
        return data[0][0]
    except IndexError:
        print_error_and_exit("No domain '%s' found in Plesk DB" % domain_name)


def main():
    # Only for Plesk 12.5+
    if not cldetectlib.is_plesk():
        return
    if len(sys.argv) != 2:
        print_error_and_exit("Invalid arguments in call")
    domain_name = sys.argv[1]
    username = get_user_by_domain(domain_name)
    # Terminate if CageFs absent
    if not os.path.exists('/usr/share/cagefs-skeleton/bin'):
        # CageFs not installed or not initialized
        print("Warning: CageFs is absent, can't restore alt-php settings")
        sys.exit(0)
    # Determine user's prefix
    user_prefix = get_user_prefix(username)
    try:
        # 1. Remove existing dirs, if they present
        dir_name = '/var/cagefs/%s/%s/etc/cl.selector' % (str(user_prefix), username)
        shutil.rmtree(dir_name, ignore_errors=True)
        dir_name = '/var/cagefs/%s/%s/etc/cl.php.d' % (str(user_prefix), username)
        shutil.rmtree(dir_name, ignore_errors=True)
        # 2. Call cagefsctl to restore alt-php settings
        exec_cagefsctl(['--force-update-etc', username])
        exec_cagefsctl(['--rebuild-alt-php-ini', username])
    except Exception as e:
        print_error_and_exit("Error: " + str(e))
    # successful end
    sys.exit(0)


if __name__ == "__main__":
    main()

Youez - 2016 - github.com/yon3zu
LinuXploit