Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create website alias feature on API #1339

Open
MarkosTech opened this issue Oct 18, 2024 · 0 comments
Open

Create website alias feature on API #1339

MarkosTech opened this issue Oct 18, 2024 · 0 comments

Comments

@MarkosTech
Copy link

MarkosTech commented Oct 18, 2024

Hi, I would like the api function create website alias.

view

@csrf_exempt
def createWebsiteAlias(request):
    data = json.loads(request.body)
    adminUser = data['adminUser']
    admin = Administrator.objects.get(userName=adminUser)
    if os.path.exists(ProcessUtilities.debugPath):
        logging.writeToFile(f'Create website alias payload in API {str(data)}')
    
    if admin.api == 0:
        data_ret = {"existsStatus": 0, 'createParkedDomainStatus': 0,
                    'error_message': "API Access Disabled."}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
    wm = WebsiteManager()
    return wm.createWebsiteAliasAPI(json.loads(request.body))

websiteManager

def createWebsiteAliasAPI(self, data=None):
        try:
            adminUser = data['adminUser']
            adminPass = data['adminPass']
            adminEmail = data['ownerEmail']
            websiteOwner = data['websiteOwner']
            ownerPassword = data['ownerPassword']
            # data['ssl'] = 1
            # data['masterDomain'] = data['masterDomain']
            # aliasDomain = data['aliasDomain']
            # ssl = data['ssl']
            try :
                data['ssl'] = data['ssl']
            except:
                data['ssl'] = 1
            try:
                websitesLimit = data['websitesLimit']
            except:
                websitesLimit = 1
            try:
                apiACL = data['acl']
            except:
                apiACL = 'user'
            admin = Administrator.objects.get(userName=adminUser)
            if hashPassword.check_password(admin.password, adminPass):
                if adminEmail is None:
                    data['adminEmail'] = "[email protected]"
                try:
                    acl = ACL.objects.get(name=apiACL)
                    websiteOwn = Administrator(userName=websiteOwner,
                                               password=hashPassword.hash_password(ownerPassword),
                                               email=adminEmail, type=3, owner=admin.pk,
                                               initWebsitesLimit=websitesLimit, acl=acl, api=1)
                    websiteOwn.save()
                except BaseException:
                    pass
            else:
                data_ret = {"existsStatus": 0, 'createWebSiteAliasStatus': 0, 'error_message': "Could not authorize access to API"}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)
            return self.submitAliasCreation(admin.pk, data)
        except BaseException as msg:
            data_ret = {'createWebSiteAliasStatus': 0, 'error_message': str(msg), "existsStatus": 0}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)

Thanks and hope the feature can be added soon upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant