0
  "   	ˆl–Ým_J*j"Tâ€fà\¸ØÅ£¿ƒh¹ÃÂ      	0
  #   ˆl–ßi~”JClÊqA
ã`¸)‹FÿÀ„d@?ÄÃ ?÷     #!/usr/bin/python3

#%copyright%

import os
import sys
import getopt
import shutil
import hashlib
import time
import shlex
from packaging.version import Version

# pylint: disable=wrong-import-position
sys.path.append(os.path.abspath("/usr/share/lve/modlscapi/user"))
import mod_lsapi_stat
from stat_utils import plesk_bin_php_handler
from lve_diagnostic import  get_cp
from exec_command import exec_command, exec_command_out
def is_ubuntu():
    return False

SOURCE = "/usr/share/lve/modlscapi/user"
ENABLED_FILE = "/usr/share/lve/modlscapi/global.enabled"
CUSTOM_PANEL_SRC = "/usr/share/lve/modlscapi/custom/"


def touch(fname):
    if os.path.islink(fname):
        return
    try:
        os.utime(fname, None)
    except OSError:
        fd = os.open(fname, os.O_CREAT | os.O_WRONLY | os.O_NOFOLLOW, 0o644)
        os.close(fd)


def get_cl_num():
    result = exec_command("rpm -q --qf \"%{version}\n\" `rpm -q --whatprovides /etc/redhat-release`")
    return result[0] if result else '8'

def add_one_item_to_php_handler(path, needle):
    """
    Add one configuration string to php.handler
    """
    with open(path, "a+") as file:
        for line in file:
            if needle in line:
                break
        else:  # not found, we are at the eof
            file.write("%s\n" % needle)  # append missing data


def add_lines(path, lines):
    """
    Add lines to file
    """
    for line in lines:
        add_one_item_to_php_handler(path, line.strip())


def remove_all_lines(path, lines):
    """
    Remove lines from file
    """
    safe_path = shlex.quote(path)
    for line in lines:
        exec_command_out(
            """sed -i -e '/^[[:space:]]*%s[[:space:]]*$/d' %s""" % (line.strip().replace("/", "\\/"), safe_path))


def getItem(txt1, txt2, op):
    try:
        i1 = int(txt1)
    except ValueError:
        i1 = -1
    try:
        i2 = int(txt2)
    except ValueError:
        i2 = -1
    if i1 == -1 or i2 == -1:
        if op == 0:
            return txt1 > txt2
        else:
            return txt1 < txt2
    else:
        if op == 0:
            return i1 > i2
        else:
            return i1 < i2


# Compare version of types xx.xx.xxx... and yyy.yy.yy.y..
# if xxx and yyy is numbers, than comapre as numbers
# else - comapre as strings
def verCompare(base, test):
    base = base.split(".")
    test = test.split(".")
    if (len(base) > len(test)):
        ln = len(test)
    else:
        ln = len(base)
    for i in range(ln):
        if getItem(base[i], test[i], 0):
            return 1
        if getItem(base[i], test[i], 1):
            return -1
    if len(base) == len(test):
        return 0
    elif len(base) > len(test):
        return 1
    else:
        return 0


def usage():
    print('')
    print('Use the following syntax to manage the mod_lsapi install tool:')
    print(sys.argv[0] + " [OPTIONS]")
    print('Options:')
    print("--setup - setup mod_lsapi configurations for Apache")
    print("--setup-light - only setup the EasyApache 4 feature")
    print("--uninstall - uninstall mod_lsapi from Apache")
    print("--enable-domain - enable mod_lsapi for an individual domain")
    print("--disable-domain - disable mod_lsapi for an individual domain")
    print("--enable-global - sets up mod_lsapi as a default way to serve PHP, making it enabled for all domains. Once that mode is enabled, you cannot disable mod_lsapi for individual domains")
    print("--disable-global - disable mod_lsapi as a default way to serve PHP, disabling mod_lsapi for all domains, including those selected previously using --enable-domain")
    print("--build-native-lsphp - build native lsphp for cPanel")
    print("--build-native-lsphp-cust - build native lsphp for cPanel (with custom PHP source path)")
    print("--check-php - check PHP configuration")
    print("--verbose - switch verbose logging on")
    print("--force - only with setup option (EA4)")
    print("--stat - return statistics in JSON")


PLESK_PH