updated checkcreds output

This commit is contained in:
pepper 2021-01-27 07:42:30 -05:00
parent 69805247bf
commit 23028e13e6
2 changed files with 15 additions and 2 deletions

View File

@ -13,7 +13,7 @@ class cPanelAccount():
def checkCreds(self):
try:
resp = requests.get(f"{self.baseURL}/Themes/list", headers=self.headers).json()
except json.decoder.JSONDecodeError as e:
except Exception as e:
return False
return True

View File

@ -51,6 +51,15 @@ def buildDictFromTimeslot(slot):
slotDict["3days"] = getMigCount(3, slot)
return slotDict
def buildList(originalList, listToAdd):
for x in listToAdd:
originalList.append(x)
return originalList
def buildStringFromList(list):
s = ''.join(x + ',' for x in list)
return s
def getAllMigrations(limit):
return Migration.objects.all()[:limit]
@ -208,7 +217,11 @@ class checkCpanelDetails(APIView):
print(request.data['hostname'], request.data['username'], request.data['password'])
acc = cPanelAccount(request.data['hostname'], request.data['username'], request.data['password'])
if acc.checkCreds():
return Response(acc.getDomains())
domains = acc.getDomains()
mainDomain = domains['data']['main_domain']
otherDomains = domains['data']['addon_domains']
otherDomains = buildList(otherDomains, domains['data']['sub_domains'])
return Response({"main_domain": mainDomain, "other_domains": buildStringFromList(otherDomains)})
else:
return Response({'Error': 'Please check the credentials'})