diff --git a/migratorapi/api/cpanel.py b/migratorapi/api/cpanel.py index 87fb02d..0ce926c 100644 --- a/migratorapi/api/cpanel.py +++ b/migratorapi/api/cpanel.py @@ -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 diff --git a/migratorapi/api/views.py b/migratorapi/api/views.py index 1a11bf9..9af15eb 100644 --- a/migratorapi/api/views.py +++ b/migratorapi/api/views.py @@ -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'}) \ No newline at end of file