LVES-742: Fix incorrect obtain database access from ISP Manager 5 use: curl -s http://repo.cloudlinux.com/cloudlinux/sources/lve-stats/LVES_742.patch | patch -F3 -p0 -d / -N =================================================================== --- /opt/alt/python27/lib/python2.7/site-packages/clcommon/cpapi/plugins/ispmanager.py +++ /opt/alt/python27/lib/python2.7/site-packages/clcommon/cpapi/plugins/ispmanager.py @@ -16,12 +16,16 @@ # WARN: Probably will be deprecated for our "official" plugins. # See pluginlib.detect_panel_fast() +def _is_5_version(): + return os.path.isfile('/usr/local/mgr5/sbin/mgrctl') + + def detect(): - return os.path.isfile('/usr/local/ispmgr/bin/ispmgr') or os.path.isfile('/usr/local/mgr5/sbin/mgrctl') + return os.path.isfile('/usr/local/ispmgr/bin/ispmgr') or _is_5_version() ISP_DB_CONF = '/usr/local/ispmgr/etc/ispmgr.conf' - +ISP5_DB_CONF = '/usr/local/mgr5/etc/ispmgr.conf.d/db.conf' SECTION_PATTERN = r'(\S+) "([^"]+)" {([^}]+)}' KEYWORDS_PATTERN = r'(\S+)\s+(\S+)' @@ -62,7 +66,20 @@ return result_list +def _db_access_5(): + try: + with open(ISP5_DB_CONF) as db_conf: + cnf = dict(re.findall(KEYWORDS_PATTERN, db_conf.read())) + return {'pass': cnf['DBPassword'], 'login': cnf['DBUser'], 'host': cnf['DBHost'], 'db': 'mysql'} + except IOError: + raise NoDBAccessData('Can not open config file %s' % (KEYWORDS_PATTERN,)) + except IndexError: + raise NoDBAccessData('Can not find database access data in config file %s' % (KEYWORDS_PATTERN,)) + + def db_access(_conf_path=ISP_DB_CONF): + if _is_5_version(): + return _db_access_5() access = dict() access_list = conf_pars(sectype='DbServer', seckeys=('Hostname', 'Password', 'Type mysql', 'User'), path=_conf_path) for access_from_conf in access_list: