Mini Shell
# 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 json
import os
import sys
import subprocess
from clcommon.utils import exec_utility
from dynamicui_base import DynamicUIBase
class DynamicUICpanel(DynamicUIBase):
WHMAPI1 = '/usr/sbin/whmapi1'
RESELLER_CONFIG_FILE = '/var/cpanel/resellers'
resellers = None
def show_for_reseller(self, reseller_name):
acls = self.__getacls(reseller_name)
acls.append('software-lvemanager')
acls = list(sorted(set(acls)))
self.__setacls(reseller_name, acls)
def hide_for_reseller(self, reseller_name):
acls = self.__getacls(reseller_name)
if 'software-lvemanager' in acls:
acls.remove('software-lvemanager')
self.__setacls(reseller_name, acls)
def __getacls(self, reseller_name):
if not os.path.exists(self.RESELLER_CONFIG_FILE):
return []
with open(self.RESELLER_CONFIG_FILE) as f:
for line in f:
data = line.strip().split(':')
if len(data) == 2:
(name, permissions) = data
if name == reseller_name:
return permissions.split(',')
return []
def __setacls(self, reseller_name, acls):
params = ['setacls', 'reseller={}'.format(reseller_name)]
for acl in acls:
params.append('acl-{}=1'.format(acl))
try:
retcode, out = exec_utility(self.WHMAPI1, params)
except OSError:
self.print_message("Can't run {}".format(self.WHMAPI1))
sys.exit(1)
def fix_display_plugin(self):
if not os.path.exists(self.RESELLER_CONFIG_FILE):
return
with open(self.RESELLER_CONFIG_FILE) as f:
resellers_list = [line.strip().split(':', 1)[0] for line in f if line.strip()]
for reseller_name in resellers_list:
if self.is_activated_reseller(reseller_name):
self.show_for_reseller(reseller_name)
else:
self.hide_for_reseller(reseller_name)
def is_activated_reseller(self, reseller_name):
if self.resellers is None:
p = subprocess.Popen(
['lvectl', 'list-reseller', '--with-name', '--json'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(res_in_json, err) = p.communicate()
if err:
self.print_message("Can't run lvectl")
try:
self.resellers = [reseller.get('ID', '').split(':')[-1] \
for reseller in json.loads(res_in_json)['data']]
except:
self.resellers = []
return reseller_name in self.resellers
Zerion Mini Shell 1.0