Mini Shell
"""backwards compat for rads.reseller"""
from cpapis import whmapi1
import rads
from . import OUR_RESELLERS
from .common import is_cpanel_user # pylint: disable=unused-import
from .compat import deprecated
APIPA = '169.254.100.100'
@deprecated('rads.get_owner')
def get_owner(user):
"""deprecated"""
try:
return rads.get_owner(user)
except rads.CpuserError:
return None # mimic old behavior
@deprecated('rads.is_child')
def is_child(user, *_, **__):
"""deprecated"""
try:
return rads.is_child(user)
except rads.CpuserError:
return None # mimic old behavior
@deprecated('cpapis.whmapi1')
def all_resellers():
"""deprecated"""
try:
return whmapi1('listresellers')['data']['reseller']
except Exception as exc:
print(exc)
return None
@deprecated('rads.all_cpusers')
def all_main_users(res_bool=False, skip=None):
"""deprecated"""
to_skip = {'system', 'root'}
to_skip.update(OUR_RESELLERS)
if skip:
to_skip.update(skip)
users = rads.all_cpusers(owners=False)
if res_bool:
res = all_resellers()
return {
user: user in res
for user in users
if user not in to_skip and not is_child(user)
}
return [x for x in users if x not in to_skip and not is_child(x)]
@deprecated('cpapis.whmapi1')
def is_reseller(user):
"""deprecated"""
resellers = all_resellers()
if resellers is None:
return None
return user in resellers
@deprecated('rads.get_children')
def get_children(owner):
"""deprecated"""
return rads.get_children(owner)
@deprecated('uapis.whmapi1')
def set_owner(user, reseller):
"""deprecated"""
if is_cpanel_user(reseller):
if is_cpanel_user(user):
try:
result = whmapi1(
'modifyacct', args={'user': user, 'owner': reseller}
)
return result['metadata']['result'] == 1
except Exception as exc:
print(exc)
print("Failed to set %s as owner of %s" % (reseller, user))
return False
else:
print("%s is not a cPanel user" % user)
return False
else:
print("%s is not a cPanel user" % reseller)
return False
@deprecated('uapis.whmapi1')
def set_reseller_acl(user, package):
"""deprecated"""
if is_cpanel_user(user):
try:
result = whmapi1(
'setacls', args=dict({'reseller': user, 'acllist': package})
)
return result['metadata']['result'] == 1
except Exception as exc:
print(exc)
print("Failed to set %s as acllist or %s" % (package, user))
return False
else:
print("%s is not a cPanel user" % user)
return False
Zerion Mini Shell 1.0