4:46 #ˆl–Ðz¾”Ëm q@=q¦nõ1hßÈ ƒuÖÅÇ¿ÊH# -*- coding: utf-8 -*- # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2018 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT """ Library to work with plug-ins """ import os import py_compile import subprocess import sys import pwd import glob import shutil import syslog from importlib import import_module from configparser import ConfigParser from clcommon.clcustomscript import lvectl_custompanel_script, CLSYSCONFIG from .const import CACHE_CPNAME, UNKNOWN_CP_NAME, UNKNOWN_CP_IMPORT from .cpapiexceptions import PluginImportError clsysconfig = ConfigParser(interpolation=None, strict=False) clsysconfig.read(CLSYSCONFIG) CONTROLPANELNAME_VAR = '__cpname__' DETECTFUNCNAME_VAR = 'detect' PLUGINS_PKG_PREFIX = 'clcommon.cpapi' PLUGINS_DIR = None if clsysconfig.has_option(section='cpapi', option='plugindir'): PLUGINS_DIR = clsysconfig.get(section='cpapi', option='plugindir') if not os.path.exists(PLUGINS_DIR): print("WARNING: plugindir is configured, but doesn't exists!") API_LINK_PATH = os.path.join(os.path.dirname(__file__), 'apilink.py') CPANEL_NAME = 'cPanel' DIRECTADMIN_NAME = 'DirectAdmin' PLESK_NAME = 'Plesk' ISPMANAGER_NAME = 'ISPManager' INTERWORX_NAME = 'InterWorx' UNKNOWN_NAME = 'Unknown' INTEGRATED_NAME = 'Integrated' OFFICIAL_PLUGINS = { CPANEL_NAME: 'cpanel', DIRECTADMIN_NAME: 'directadmin', PLESK_NAME: 'plesk', ISPMANAGER_NAME: 'ispmanager', INTERWORX_NAME: 'interworx', UNKNOWN_NAME: 'backward_plugin', INTEGRATED_NAME: 'vendors' } def detect_panel_fast(): """ This function will try to detect our officially supported control panels :return: tuple of CP name and CP plugin name to import """ panel_name, official_plugin_name = None, None if os.path.isfile('/opt/cpvendor/etc/integration.ini'): panel_name, official_plugin_name = INTEGRATED_NAME, OFFICIAL_PLUGINS[INTEGRATED_NAME] elif os.path.isfile('/usr/local/cpanel/cpanel'): panel_name, official_plugin_name = CPANEL_NAME, OFFICIAL_PLUGINS[CPANEL_NAME] elif os.path.isfile('/usr/local/directadmin/directadmin') or\ os.path.isfile('/usr/local/directadmin/custombuild/build'): panel_name, official_plugin_name = DIRECTADMIN_NAME, OFFICIAL_PLUGINS[DIRECTADMIN_NAME] elif os.path.isfile('/usr/local/psa/version'): panel_name, official_plugin_name = PLESK_NAME, OFFICIAL_PLUGINS[PLESK_NAME] # ispmanager must have: # v5: /usr/local/mgr5/ directory, # v4: /usr/local/ispmgr/bin/ispmgr file elif os.path.isfile('/usr/local/ispmgr/bin/ispmgr') or os.path.isdir('/usr/local/mgr5'): panel_name, official_plugin_name = ISPMANAGER_NAME, OFFICIAL_PLUGINS[ISPMANAGER_NAME] elif os.path.isdir('/usr/local/interworx'): panel_name, official_plugin_name = INTERWORX_NAME, OFFICIAL_PLUGINS[INTERWORX_NAME] elif lvectl_custompanel_script() is not None: # Check custom panel script to use backward plugin panel_name, official_plugin_name = UNKNOWN_NAME, OFFICIAL_PLUGINS[UNKNOWN_NAME] return panel_name, official_plugin_name def get_cp_plugin_module(plugin_name=None): if plugin_name: # Case when some "official" plugin was already detected return import_module(f'{PLUGINS_PKG_PREFIX}.plugins.{plugin_name}') # Use cached module if detect_panel_fast() can't detect anything # Actual import statement in file is updated on each rebuild_cache() from .apilink import api as _apiplugin # pylint: disable=import-outside-toplevel return _apiplugin def detectplugin(plugin_pack, ignore_errors=False): """ Scan directory for presence of plugins. Plugin is a file that has the extension ".py" and a non-empty variable "__cpname__" (the name of the control panel). The file must contain a function "detect" which returns True in case of presence of the corresponding control panel. >>> detectplugin('plugins') ('from .plugins import cp