예제 #1
0
    def zoneCreation(self, userID=None, data=None):
        try:
            admin = Administrator.objects.get(pk=userID)

            currentACL = ACLManager.loadedACL(userID)
            if ACLManager.currentContextPermission(currentACL,
                                                   'createDNSZone') == 0:
                return ACLManager.loadErrorJson('zoneCreation', 0)

            zoneDomain = data['zoneDomain']

            newZone = Domains(admin=admin, name=zoneDomain, type="NATIVE")
            newZone.save()

            content = "ns1." + zoneDomain + " hostmaster." + zoneDomain + " 1 10800 3600 604800 3600"

            soaRecord = Records(domainOwner=newZone,
                                domain_id=newZone.id,
                                name=zoneDomain,
                                type="SOA",
                                content=content,
                                ttl=3600,
                                prio=0,
                                disabled=0,
                                auth=1)
            soaRecord.save()

            final_dic = {'zoneCreation': 1}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)

        except BaseException, msg:
            final_dic = {'zoneCreation': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)
예제 #2
0
def submitPasswordChange(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':
                data = json.loads(request.body)

                domain = data['domain']
                email = data['email']
                password = data['password']

                dom = Domains(domain=domain)

                emailAcct = EUsers(email=email)
                emailAcct.delete()

                emailAcct = EUsers(emailOwner=dom,
                                   email=email,
                                   password=password)
                emailAcct.save()

                data_ret = {'passChangeStatus': 1, 'error_message': "None"}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

        except BaseException, msg:
            data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
    except KeyError, msg:
        data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
예제 #3
0
def zoneCreation(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

                admin = Administrator.objects.get(pk=val)

                data = json.loads(request.body)
                zoneDomain = data['zoneDomain']

                newZone = Domains(admin=admin, name=zoneDomain, type="NATIVE")
                newZone.save()

                content = "ns1." + zoneDomain + " hostmaster." + zoneDomain + " 1 10800 3600 604800 3600"

                soaRecord = Records(domainOwner=newZone,
                                    domain_id=newZone.id,
                                    name=zoneDomain,
                                    type="SOA",
                                    content=content,
                                    ttl=3600,
                                    prio=0,
                                    disabled=0,
                                    auth=1)
                soaRecord.save()


                final_dic = {'zoneCreation': 1}
                final_json = json.dumps(final_dic)

                return HttpResponse(final_json)



        except BaseException,msg:

            final_dic = {'zoneCreation': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)

            return HttpResponse(final_json)

    except KeyError,msg:
        final_dic = {'zoneCreation': 0, 'error_message': str(msg)}
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)
예제 #4
0
def zoneCreation(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

                admin = Administrator.objects.get(pk=val)

                data = json.loads(request.body)
                zoneDomain = data['zoneDomain']

                newZone = Domains(admin=admin, name=zoneDomain, type="NATIVE")
                newZone.save()

                content = "ns1." + zoneDomain + " hostmaster." + zoneDomain + " 1 10800 3600 604800 3600"

                soaRecord = Records(domainOwner=newZone,
                                    domain_id=newZone.id,
                                    name=zoneDomain,
                                    type="SOA",
                                    content=content,
                                    ttl=3600,
                                    prio=0,
                                    disabled=0,
                                    auth=1)
                soaRecord.save()

                final_dic = {'zoneCreation': 1}
                final_json = json.dumps(final_dic)

                return HttpResponse(final_json)

        except BaseException, msg:

            final_dic = {'zoneCreation': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)

            return HttpResponse(final_json)

    except KeyError, msg:
        final_dic = {'zoneCreation': 0, 'error_message': str(msg)}
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)
예제 #5
0
def domain_test_db_init():
    db.init_app(app)
    with app.app_context():
        org = Organizations(
            id=6,
            organization='BOC',
            description='BOC - Bank of Canada',
        )
        db.session.add(org)
        db.session.commit()

        domain = Domains(id=15, domain='bankofcanada.ca', organization_id=6)
        db.session.add(domain)
        db.session.commit()

    yield

    with app.app_context():
        Domains.query.delete()
        Organizations.query.delete()
        db.session.commit()
예제 #6
0
def submitPasswordChange(request):
    try:
        val = request.session['userID']
        admin = Administrator.objects.get(pk=val)
        try:
            if request.method == 'POST':
                data = json.loads(request.body)

                domain = data['domain']
                email = data['email']
                password = data['password']

                emailDB = EUsers.objects.get(email=email)

                if admin.type != 1:
                    if emailDB.emailOwner.domainOwner.admin != admin:
                        final_dic = {'passChangeStatus': 0, 'error_message': "Not enough privileges." }
                        final_json = json.dumps(final_dic)
                        return HttpResponse(final_json)

                emailDB.delete()

                dom = Domains(domain=domain)

                emailAcct = EUsers(emailOwner=dom, email=email, password=password)
                emailAcct.save()

                data_ret = {'passChangeStatus': 1, 'error_message': "None"}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)


        except BaseException,msg:
            data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
    except KeyError,msg:
        data_ret = {'passChangeStatus': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
예제 #7
0
def submitEmailCreation(request):
    try:
        if request.method == 'POST':

            data = json.loads(request.body)
            domain = data['domain']
            userName = data['username']
            password = data['password']

            ## Check if already exists

            finalEmailUsername = userName + "@" + domain

            if EUsers.objects.filter(email=finalEmailUsername).exists():
                data_ret = {
                    'createEmailStatus': 0,
                    'error_message': "This account already exists!"
                }
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

            ## Check for email limits.

            website = Websites.objects.get(domain=domain)

            try:

                newEmailDomain = Domains(domainOwner=website, domain=domain)
                newEmailDomain.save()

                if website.package.emailAccounts == 0 or (
                        newEmailDomain.eusers_set.all().count() <
                        website.package.emailAccounts):
                    pass
                else:
                    data_ret = {
                        'createEmailStatus':
                        0,
                        'error_message':
                        "Exceeded maximum amount of email accounts allowed for the package."
                    }
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

            except:

                emailDomain = Domains.objects.get(domain=domain)

                if website.package.emailAccounts == 0 or (
                        emailDomain.eusers_set.all().count() <
                        website.package.emailAccounts):
                    pass
                else:
                    data_ret = {
                        'createEmailStatus':
                        0,
                        'error_message':
                        "Exceeded maximum amount of email accounts allowed for the package."
                    }
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

            ## Create email entry

            execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"

            execPath = execPath + " createEmailAccount --domain " + domain

            output = subprocess.check_output(shlex.split(execPath))

            if output.find("1,None") > -1:

                emailDomain = Domains.objects.get(domain=domain)

                emailAcct = EUsers(emailOwner=emailDomain,
                                   email=finalEmailUsername,
                                   password=password)
                emailAcct.save()

                data_ret = {'createEmailStatus': 1, 'error_message': "None"}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

            else:
                data_ret = {'createEmailStatus': 0, 'error_message': output}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

            ## create email entry ends

    except BaseException, msg:
        data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
예제 #8
0
def submitEmailCreation(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

                data = json.loads(request.body)
                domain = data['domain']
                userName = data['username']
                password = data['password']

                ## create email entry

                execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"

                execPath = execPath + " createEmailAccount --domain " + domain



                output = subprocess.check_output(shlex.split(execPath))

                if output.find("1,None") > -1:
                    pass
                else:
                    data_ret = {'createEmailStatus': 0, 'error_message': output}
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

                ## create email entry ends

                finalEmailUsername = userName+"@"+domain

                website = Websites.objects.get(domain=domain)

                if EUsers.objects.filter(email=finalEmailUsername).exists():
                    data_ret = {'createEmailStatus': 0, 'error_message': "This account already exists"}
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)


                if not Domains.objects.filter(domain=domain).exists():
                    newEmailDomain = Domains(domainOwner=website,domain=domain)
                    newEmailDomain.save()

                    emailAcct = EUsers(emailOwner=newEmailDomain,email=finalEmailUsername,password=password)
                    emailAcct.save()

                    data_ret = {'createEmailStatus': 1, 'error_message': "None"}
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

                else:
                    emailDomain = Domains.objects.get(domain=domain)
                    emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password)
                    emailAcct.save()

                    data_ret = {'createEmailStatus': 1, 'error_message': "None"}
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)


        except BaseException,msg:
            data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
    except KeyError,msg:
        data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
예제 #9
0
def NSCreation(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':
                admin = Administrator.objects.get(pk=val)

                if admin.type != 1:
                    dic = {
                        'NSCreation': 0,
                        'error_message':
                        "Only administrator can view this page."
                    }
                    json_data = json.dumps(dic)
                    return HttpResponse(json_data)

                data = json.loads(request.body)
                domainForNS = data['domainForNS']
                ns1 = data['ns1']
                ns2 = data['ns2']
                firstNSIP = data['firstNSIP']
                secondNSIP = data['secondNSIP']

                if Domains.objects.filter(name=domainForNS).count() == 0:
                    newZone = Domains(admin=admin,
                                      name=domainForNS,
                                      type="NATIVE")
                    newZone.save()

                    content = "ns1." + domainForNS + " hostmaster." + domainForNS + " 1 10800 3600 604800 3600"

                    soaRecord = Records(domainOwner=newZone,
                                        domain_id=newZone.id,
                                        name=domainForNS,
                                        type="SOA",
                                        content=content,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1)
                    soaRecord.save()

                    ## NS1

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=domainForNS,
                                     type="NS",
                                     content=ns1,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=ns1,
                                     type="A",
                                     content=firstNSIP,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    ## NS2

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=domainForNS,
                                     type="NS",
                                     content=ns2,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=ns2,
                                     type="A",
                                     content=secondNSIP,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    final_dic = {'NSCreation': 1, 'error_message': "None"}
                    final_json = json.dumps(final_dic)
                    return HttpResponse(final_json)

                else:

                    newZone = Domains.objects.get(name=domainForNS)

                    ## NS1

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=domainForNS,
                                     type="NS",
                                     content=ns1,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=ns1,
                                     type="A",
                                     content=firstNSIP,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    ## NS2

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=domainForNS,
                                     type="NS",
                                     content=ns2,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=ns2,
                                     type="A",
                                     content=secondNSIP,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    final_dic = {'NSCreation': 1, 'error_message': "None"}
                    final_json = json.dumps(final_dic)
                    return HttpResponse(final_json)

        except BaseException, msg:
            final_dic = {'NSCreation': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)

    except KeyError, msg:
        final_dic = {'NSCreation': 0, 'error_message': str(msg)}
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)
예제 #10
0
def seed_domains(db, app):
    domain = Domains(id=15, domain='bankofcanada.ca', organization_id=6)
    with app.app_context():
        db.session.add(domain)
        db.session.commit()
예제 #11
0
    def NSCreation(self, userID=None, data=None):
        try:
            admin = Administrator.objects.get(pk=userID)
            currentACL = ACLManager.loadedACL(userID)

            if ACLManager.currentContextPermission(currentACL,
                                                   'createNameServer') == 0:
                return ACLManager.loadErrorJson('NSCreation', 0)

            domainForNS = data['domainForNS']
            ns1 = data['ns1']
            ns2 = data['ns2']
            firstNSIP = data['firstNSIP']
            secondNSIP = data['secondNSIP']

            if Domains.objects.filter(name=domainForNS).count() == 0:
                newZone = Domains(admin=admin, name=domainForNS, type="NATIVE")
                newZone.save()

                content = "ns1." + domainForNS + " hostmaster." + domainForNS + " 1 10800 3600 604800 3600"

                soaRecord = Records(domainOwner=newZone,
                                    domain_id=newZone.id,
                                    name=domainForNS,
                                    type="SOA",
                                    content=content,
                                    ttl=3600,
                                    prio=0,
                                    disabled=0,
                                    auth=1)
                soaRecord.save()

                ## NS1

                record = Records(domainOwner=newZone,
                                 domain_id=newZone.id,
                                 name=domainForNS,
                                 type="NS",
                                 content=ns1,
                                 ttl=3600,
                                 prio=0,
                                 disabled=0,
                                 auth=1)
                record.save()

                record = Records(domainOwner=newZone,
                                 domain_id=newZone.id,
                                 name=ns1,
                                 type="A",
                                 content=firstNSIP,
                                 ttl=3600,
                                 prio=0,
                                 disabled=0,
                                 auth=1)
                record.save()

                ## NS2

                record = Records(domainOwner=newZone,
                                 domain_id=newZone.id,
                                 name=domainForNS,
                                 type="NS",
                                 content=ns2,
                                 ttl=3600,
                                 prio=0,
                                 disabled=0,
                                 auth=1)
                record.save()

                record = Records(domainOwner=newZone,
                                 domain_id=newZone.id,
                                 name=ns2,
                                 type="A",
                                 content=secondNSIP,
                                 ttl=3600,
                                 prio=0,
                                 disabled=0,
                                 auth=1)
                record.save()

                final_dic = {'NSCreation': 1, 'error_message': "None"}
                final_json = json.dumps(final_dic)
                return HttpResponse(final_json)
            else:

                newZone = Domains.objects.get(name=domainForNS)

                ## NS1

                record = Records(domainOwner=newZone,
                                 domain_id=newZone.id,
                                 name=domainForNS,
                                 type="NS",
                                 content=ns1,
                                 ttl=3600,
                                 prio=0,
                                 disabled=0,
                                 auth=1)
                record.save()

                record = Records(domainOwner=newZone,
                                 domain_id=newZone.id,
                                 name=ns1,
                                 type="A",
                                 content=firstNSIP,
                                 ttl=3600,
                                 prio=0,
                                 disabled=0,
                                 auth=1)
                record.save()

                ## NS2

                record = Records(domainOwner=newZone,
                                 domain_id=newZone.id,
                                 name=domainForNS,
                                 type="NS",
                                 content=ns2,
                                 ttl=3600,
                                 prio=0,
                                 disabled=0,
                                 auth=1)
                record.save()

                record = Records(domainOwner=newZone,
                                 domain_id=newZone.id,
                                 name=ns2,
                                 type="A",
                                 content=secondNSIP,
                                 ttl=3600,
                                 prio=0,
                                 disabled=0,
                                 auth=1)
                record.save()

                final_dic = {'NSCreation': 1, 'error_message': "None"}
                final_json = json.dumps(final_dic)
                return HttpResponse(final_json)
        except BaseException, msg:
            final_dic = {'NSCreation': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)
예제 #12
0
def submitEmailCreation(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

                data = json.loads(request.body)
                domain = data['domain']
                userName = data['username']
                password = data['password']

                path = "/usr/local/CyberCP/install/rainloop/cyberpanel.net.ini"

                if not os.path.exists(
                        "/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/"
                ):
                    command = 'sudo mkdir -p /usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains'
                    cmd = shlex.split(command)
                    res = subprocess.call(cmd)

                finalPath = "/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/" + domain + ".ini"

                if not os.path.exists(finalPath):
                    command = 'sudo cp ' + path + " " + finalPath

                    cmd = shlex.split(command)

                    res = subprocess.call(cmd)

                command = 'sudo chown -R nobody:nobody /usr/local/lscp/rainloop'

                cmd = shlex.split(command)

                res = subprocess.call(cmd)

                command = 'sudo chown -R nobody:nobody /usr/local/lscp/cyberpanel/rainloop/data/_data_'

                cmd = shlex.split(command)

                res = subprocess.call(cmd)

                command = 'sudo chown -R vmail:vmail /home/vmail'

                cmd = shlex.split(command)

                res = subprocess.call(cmd)

                finalEmailUsername = userName + "@" + domain

                website = Websites.objects.get(domain=domain)

                if EUsers.objects.filter(email=finalEmailUsername).exists():
                    data_ret = {
                        'createEmailStatus': 0,
                        'error_message': "This account already exists"
                    }
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

                if not Domains.objects.filter(domain=domain).exists():
                    newEmailDomain = Domains(domainOwner=website,
                                             domain=domain)
                    newEmailDomain.save()

                    emailAcct = EUsers(emailOwner=newEmailDomain,
                                       email=finalEmailUsername,
                                       password=password)
                    emailAcct.save()

                    data_ret = {
                        'createEmailStatus': 1,
                        'error_message': "None"
                    }
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

                else:
                    emailDomain = Domains.objects.get(domain=domain)
                    emailAcct = EUsers(emailOwner=emailDomain,
                                       email=finalEmailUsername,
                                       password=password)
                    emailAcct.save()

                    data_ret = {
                        'createEmailStatus': 1,
                        'error_message': "None"
                    }
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

        except BaseException, msg:
            data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
    except KeyError, msg:
        data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
예제 #13
0
def submitEmailCreation(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

                data = json.loads(request.body)
                domain = data['domain']
                userName = data['username']
                password = data['password']

                ## create email entry

                execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"

                execPath = execPath + " createEmailAccount --domain " + domain

                output = subprocess.check_output(shlex.split(execPath))

                if output.find("1,None") > -1:
                    pass
                else:
                    data_ret = {
                        'createEmailStatus': 0,
                        'error_message': output
                    }
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

                ## create email entry ends

                finalEmailUsername = userName + "@" + domain

                website = Websites.objects.get(domain=domain)

                if EUsers.objects.filter(email=finalEmailUsername).exists():
                    data_ret = {
                        'createEmailStatus': 0,
                        'error_message': "This account already exists"
                    }
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

                if not Domains.objects.filter(domain=domain).exists():
                    newEmailDomain = Domains(domainOwner=website,
                                             domain=domain)
                    newEmailDomain.save()

                    emailAcct = EUsers(emailOwner=newEmailDomain,
                                       email=finalEmailUsername,
                                       password=password)
                    emailAcct.save()

                    data_ret = {
                        'createEmailStatus': 1,
                        'error_message': "None"
                    }
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

                else:
                    emailDomain = Domains.objects.get(domain=domain)
                    emailAcct = EUsers(emailOwner=emailDomain,
                                       email=finalEmailUsername,
                                       password=password)
                    emailAcct.save()

                    data_ret = {
                        'createEmailStatus': 1,
                        'error_message': "None"
                    }
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)

        except BaseException, msg:
            data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
    except KeyError, msg:
        data_ret = {'createEmailStatus': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
예제 #14
0
def NSCreation(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':
                admin = Administrator.objects.get(pk=val)

                data = json.loads(request.body)
                domainForNS = data['domainForNS']
                ns1 = data['ns1']
                ns2 = data['ns2']
                firstNSIP = data['firstNSIP']
                secondNSIP = data['secondNSIP']

                if Domains.objects.filter(name=domainForNS).count() == 0:
                    newZone = Domains(admin=admin,name=domainForNS, type="NATIVE")
                    newZone.save()

                    content = "ns1." + domainForNS + " hostmaster." + domainForNS + " 1 10800 3600 604800 3600"

                    soaRecord = Records(domainOwner=newZone,
                                        domain_id=newZone.id,
                                        name=domainForNS,
                                        type="SOA",
                                        content=content,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1)
                    soaRecord.save()

                    ## NS1

                    record = Records(domainOwner=newZone,
                                        domain_id=newZone.id,
                                        name=domainForNS,
                                        type="NS",
                                        content=ns1,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1)
                    record.save()



                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=ns1,
                                     type="A",
                                     content=firstNSIP,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    ## NS2


                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=domainForNS,
                                     type="NS",
                                     content=ns2,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()


                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=ns2,
                                     type="A",
                                     content=secondNSIP,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    final_dic = {'NSCreation': 1, 'error_message': "None"}
                    final_json = json.dumps(final_dic)
                    return HttpResponse(final_json)

                else:

                    newZone = Domains.objects.get(name=domainForNS)

                    ## NS1

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=domainForNS,
                                     type="NS",
                                     content=ns1,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=domainForNS,
                                     type="A",
                                     content=firstNSIP,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    ## NS2


                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=domainForNS,
                                     type="NS",
                                     content=ns2,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=newZone,
                                     domain_id=newZone.id,
                                     name=domainForNS,
                                     type="A",
                                     content=secondNSIP,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    final_dic = {'NSCreation': 1, 'error_message': "None"}
                    final_json = json.dumps(final_dic)
                    return HttpResponse(final_json)



        except BaseException, msg:
            final_dic = {'NSCreation': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)

    except KeyError, msg:
        final_dic = {'NSCreation': 0, 'error_message': str(msg)}
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)