Exemple #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)
Exemple #2
0
def domain_json_update_record(req, id):
    if req.method != 'POST':
        return JsonResponse(data={'error': "Invalid request method."}, status=500)

    try:
        domain = Domains.objects.get(pk=id)

        if not domain.check_user_access(req.user):
            return JsonResponse(data={'error': "You don't have access to that domain."}, status=500)

        json_record = json.loads(req.body)

        if isBlank(json_record['content']):
            return JsonResponse(data={'error': "Content is required"}, status=500)

        name = domain.name
        if not isBlank(json_record['name']):
            # return JsonResponse(data={'error': "Name is required"}, status=500)
            name = json_record['name'] + "." + domain.name

        print "name: " + name

        if json_record['type'] not in settings.PDNS_ENABLED_RR_TYPES:
            return JsonResponse(data={'error': "Invalid Type"}, status=500)

        # Validate A record
        if json_record['type'] == "A" and not is_valid_ipv4_address(json_record['content']):
            return JsonResponse(data={'error': "{0} is not a valid IPv4 address.".format(json_record['content'])}, status=500)

        # Validate AAAA record
        if json_record['type'] == "AAAA" and not is_valid_ipv6_address(json_record['content']):
            return JsonResponse(data={'error': "{0} is not a valid IPv6 address.".format(json_record['content'])}, status=500)


        try:
            # try to update existing record
            record = Records.objects.get(pk=json_record['id'])
            record.name = name
            record.type = json_record['type']
            record.content = json_record['content']
            record.prio = json_record['prio']
            record.ttl = json_record['ttl']
            record.save()
            domain.update_soa_serial()
            return JsonResponse({'success': "Updated record.", 'id': record.id})
        except Records.DoesNotExist:
            # create new record
            new_record = Records(domain=domain, name=name, type=json_record['type'], content=json_record['content'], prio=json_record['prio'], ttl=json_record['ttl'])
            new_record.save()
            domain.update_soa_serial()
            return JsonResponse({'success': "Created new record.", 'id': new_record.id})
        except ValueError:
            return JsonResponse(data={'error': "Internal Servererror."}, status=500)

    except Domains.DoesNotExist:
        return JsonResponse(data={'error': "Error viewing domain."}, status=500)
Exemple #3
0
def records(request):

    if request.POST:
        text = request.POST.get('records', None)
        records = Records(user=request.display_user, text=text)
        records.save()
        saved = True

        # send signal to specify this user as editing their data
        edit_logbook.send(sender=request.display_user, touch_cache=False)

    else:
        records, c = Records.objects.get_or_create(user=request.display_user)

    return locals()
Exemple #4
0
def records(request):
      
    if request.POST:
        text = request.POST.get('records', None)
        records = Records(user=request.display_user, text=text)
        records.save()
        saved=True
        
        # send signal to specify this user as editing their data
        edit_logbook.send(sender=request.display_user, touch_cache=False)
    
    else:
        records,c = Records.objects.get_or_create(user=request.display_user)
            
    return locals()
def add_records(clients):
    records = [
        Records(client_id=client.id) for client in clients for _ in range(3)
    ]
    db_session.bulk_save_objects(records, return_defaults=True)
    db_session.flush()
    return records
Exemple #6
0
    def addRecordToDB(self, url: str, timestamp: str, host: str, ip: str,
                      rtt: str, http_code: int) -> None:
        ''' Supportive method to add handled URL to DB along with attributes '''

        newRecord = Records(url, timestamp, host, ip, rtt, http_code)

        db.session.add(newRecord)
        db.session.commit()
Exemple #7
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)
    def test_polymorphic_generator_relationships(self):
        db.create_all()

        dealer1 = Dealer(1)
        dealer2 = Dealer(2)

        org1 = Org(id=1)
        org2 = Org(id=2)
        company1 = Company(id=1, dealer=dealer1)

        rec1 = Records(buyer=org1, seller=dealer2, id=1)
        rec2 = Records(buyer=org1, seller=org2, id=2)
        rec3 = Records(buyer=dealer1, seller=dealer2, id=3)
        rec4 = Records(buyer=dealer1, seller=org1, id=4)
        rec5 = Records(buyer=org1, seller=company1, id=5)

        assert rec1.buyer_type == 'org'
        assert rec1.buyer_id == 1
        assert rec1.buyer is org1
        assert org1.buyer_records == [rec1, rec2, rec5]
        assert org1.seller_records == [rec4]
        assert rec5.seller is company1

        # The cache for Network backed model is properly invalidated
        assert rec3.buyer is dealer1
        rec3.buyer_id = 2
        assert rec3.buyer is not dealer2  # It is a new object so the identity check fails
        assert rec3.buyer == dealer2

        rec1.buyer_id = 2
        # NOTE: This is a bug. A solution might be to use SQLAlchemy events to update the object.
        # The problem is that setting the object will again update the fields which causes an infinite loop.
        assert rec1.buyer is org1

        # The opposite of it is true too and is a bug.
        # If the reference object gets modified and it is already set in the data model,
        # the values do not update.
        org1.id = 20
        assert rec2.buyer is org1
        assert rec2.buyer_id != org1.id

        db.session.add(org1)
        db.session.add(rec1)
        db.session.add(rec2)
        db.session.add(rec3)
        db.session.add(rec4)
        db.session.add(rec5)
        db.session.flush()  # Making sure that DB does not complain.
        db.session.rollback()
Exemple #9
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)
Exemple #10
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']

            DNS.dnsTemplate(domainForNS, admin)

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

            ## NS1

            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=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)
Exemple #11
0
async def api_create_record(id, request, *, major_class, app_name, rule,
                            type_of_change, platform, test_env, recognition,
                            block_from_beginning, block_at_midway, bug,
                            remarks):
    logging.info('---------------api create record------------------')
    user = request.__user__
    if user is None:
        raise APIPermissionError('Please signin first.')

    args = [
        major_class, app_name, rule, type_of_change, platform, test_env,
        recognition, block_from_beginning, block_at_midway, bug, remarks
    ]
    for arg in args:
        if not arg or not arg.strip():
            raise APIValueError('%s' % arg, 'empty!')

    report = await Reports.find(id)
    if report is None:
        raise APIResourceNotFoundError('Report')

    record = Records(report_id=report.id,
                     major_class=major_class.strip(),
                     app_name=app_name.strip(),
                     rule=rule.strip(),
                     type_of_change=type_of_change.strip(),
                     platform=platform.strip(),
                     test_env=test_env.strip(),
                     recognition=recognition.strip(),
                     block_from_beginning=block_from_beginning.strip(),
                     block_at_midway=block_at_midway.strip(),
                     bug=bug.strip(),
                     user_name=user.name,
                     remarks=remarks.strip())
    await record.save()
    return record
Exemple #12
0
    def push_sql(self, dictionary):
        '''
        Exports to alchemy
        '''
        new_record = Records()
        if "year_pub" in dictionary:
            new_record.year_pub = dictionary["year_pub"]

        if "country_code" in dictionary:
            new_record.country_code = dictionary["country_code"]

        if "language" in dictionary:
            new_record.language = dictionary["language"]

        if "key_term" in dictionary:
            new_record.key_term = dictionary["key_term"]

        if "region" in dictionary:
            new_record.region = dictionary["region"]

        session.add(new_record)
        if (self.numPushed % 500) == 0:
            session.commit()
        self.numPushed += 1
Exemple #13
0
    pw=POSTGRESQL_PASSWORD,
    url=POSTGRESQL_URL,
    db=POSTGRESQL_DATABASE)
db = create_engine(db_string)
base = declarative_base()
print("db_string", db_string)
Session = sessionmaker(db)
session = Session()

countries = list(master_data_json.keys())

with open('/Users/sai/workspace/work/covid-api/data/country_name_to_iso.json',
          'r') as fp:
    country_name_to_code = json.loads(fp.read())

for country in countries:
    for everyday in master_data_json[country]:
        record = Records()
        record.uuid = uuid.uuid4()
        record.country_name = country
        record.country_iso = country_name_to_code.get(country)
        record.date = everyday["date"]
        record.confirmed = everyday["confirmed"]
        record.deaths = everyday["deaths"]
        record.recovered = everyday["recovered"]
        session.add(record)
        print("Record Object", record)
        session.commit()
        print(record)
        print(f"Successfully added record for {country}")
Exemple #14
0
def addDNSRecord(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

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



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

                zone = Domains.objects.get(name=zoneDomain)
                value = recordName+"."+zoneDomain

                if recordType == "A":
                    recordContentA = data['recordContentA']  ## IP or ponting value
                    if recordName == "@":
                        value = zoneDomain
                    record = Records(   domainOwner=zone,
                                        domain_id=zone.id,
                                        name=value,
                                        type="A",
                                        content=recordContentA,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1  )
                    record.save()
                elif recordType == "MX":
                    recordContentMX = recordType = data['recordContentMX']
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=zoneDomain,
                                     type="MX",
                                     content=value,
                                     ttl=3600,
                                     prio=recordContentMX,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "AAAA":
                    recordContentAAAA = data['recordContentAAAA']  ## IP or ponting value
                    if recordName == "@":
                        value = zoneDomain
                    record = Records(   domainOwner=zone,
                                        domain_id=zone.id,
                                        name=value,
                                        type="AAAA",
                                        content=recordContentAAAA,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1  )
                    record.save()

                elif recordType == "CNAME":
                    recordName = data['recordName']
                    recordContentCNAME = data['recordContentCNAME']  ## IP or ponting value
                    record = Records(   domainOwner=zone,
                                        domain_id=zone.id,
                                        name=value,
                                        type="CNAME",
                                        content=recordContentCNAME,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1  )
                    record.save()


                elif recordType == "SPF":
                    if recordName == "@":
                        value = zoneDomain
                    recordContentSPF = data['recordContentSPF']  ## IP or ponting value
                    record = Records(   domainOwner=zone,
                                        domain_id=zone.id,
                                        name=value,
                                        type="SPF",
                                        content=recordContentSPF,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1  )
                    record.save()


                elif recordType == "TXT":
                    if recordName == "@":
                        value = zoneDomain
                    recordContentTXT = data['recordContentTXT']  ## IP or ponting value
                    record = Records(   domainOwner=zone,
                                        domain_id=zone.id,
                                        name=value,
                                        type="TXT",
                                        content=recordContentTXT,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1  )
                    record.save()


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



        except BaseException,msg:
            final_dic = {'add_status': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)
    except KeyError,msg:
        final_dic = {'add_status': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)
Exemple #15
0
def addDNSRecord(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

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

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

                zone = Domains.objects.get(name=zoneDomain)
                value = recordName + "." + zoneDomain

                if recordType == "A":
                    recordContentA = data[
                        'recordContentA']  ## IP or ponting value
                    if recordName == "@":
                        value = zoneDomain
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="A",
                                     content=recordContentA,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "MX":
                    recordContentMX = recordType = data['recordContentMX']
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=zoneDomain,
                                     type="MX",
                                     content=value,
                                     ttl=3600,
                                     prio=recordContentMX,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "AAAA":
                    recordContentAAAA = data[
                        'recordContentAAAA']  ## IP or ponting value
                    if recordName == "@":
                        value = zoneDomain
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="AAAA",
                                     content=recordContentAAAA,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                elif recordType == "CNAME":
                    recordName = data['recordName']
                    recordContentCNAME = data[
                        'recordContentCNAME']  ## IP or ponting value
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="CNAME",
                                     content=recordContentCNAME,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                elif recordType == "SPF":
                    if recordName == "@":
                        value = zoneDomain
                    recordContentSPF = data[
                        'recordContentSPF']  ## IP or ponting value
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="SPF",
                                     content=recordContentSPF,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                elif recordType == "TXT":
                    if recordName == "@":
                        value = zoneDomain
                    recordContentTXT = data[
                        'recordContentTXT']  ## IP or ponting value
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="TXT",
                                     content=recordContentTXT,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

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

        except BaseException, msg:
            final_dic = {'add_status': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)
    except KeyError, msg:
        final_dic = {
            'add_status':
            0,
            'error_message':
            "Not Logged In, please refresh the page or login again."
        }
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)
Exemple #16
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)
    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)
Exemple #18
0
def add_record(value,filename,user):
    _obj = Records()
    _obj.check_sum =value
    _obj.file_name =filename
    _obj.modified_by = user
    _obj.save()
Exemple #19
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)
Exemple #20
0
def addDNSRecord(request):
    try:
        val = request.session['userID']
        try:
            if request.method == 'POST':

                data = json.loads(request.body)
                zoneDomain = data['selectedZone']
                recordType = data['recordType']
                recordName = data['recordName']
                ttl = int(data['ttl'])

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

                zone = Domains.objects.get(name=zoneDomain)
                value = ""

                if recordType == "A":

                    recordContentA = data[
                        'recordContentA']  ## IP or ponting value

                    if recordName == "@":
                        value = zoneDomain
                    ## re.match
                    elif match(
                            r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?',
                            recordName, M | I):
                        value = recordName
                    else:
                        value = recordName + "." + zoneDomain

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="A",
                                     content=recordContentA,
                                     ttl=ttl,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "MX":

                    if recordName == "@":
                        value = zoneDomain
                    ## re.match
                    elif match(
                            r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?',
                            recordName, M | I):
                        value = recordName
                    else:
                        value = recordName + "." + zoneDomain

                    recordContentMX = data['recordContentMX']
                    priority = data['priority']
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="MX",
                                     content=recordContentMX,
                                     ttl=ttl,
                                     prio=priority,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "AAAA":

                    recordContentAAAA = data[
                        'recordContentAAAA']  ## IP or ponting value

                    if recordName == "@":
                        value = zoneDomain
                    ## re.match
                    elif match(
                            r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?',
                            recordName, M | I):
                        value = recordName
                    else:
                        value = recordName + "." + zoneDomain

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="AAAA",
                                     content=recordContentAAAA,
                                     ttl=ttl,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "CNAME":

                    if recordName == "@":
                        value = zoneDomain
                    ## re.match
                    elif match(
                            r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?',
                            recordName, M | I):
                        value = recordName
                    else:
                        value = recordName + "." + zoneDomain

                    recordContentCNAME = data[
                        'recordContentCNAME']  ## IP or ponting value
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="CNAME",
                                     content=recordContentCNAME,
                                     ttl=ttl,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "SPF":

                    if recordName == "@":
                        value = zoneDomain
                    ## re.match
                    elif match(
                            r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?',
                            recordName, M | I):
                        value = recordName
                    else:
                        value = recordName + "." + zoneDomain

                    recordContentSPF = data[
                        'recordContentSPF']  ## IP or ponting value
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="SPF",
                                     content=recordContentSPF,
                                     ttl=ttl,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "TXT":

                    if recordName == "@":
                        value = zoneDomain
                    ## re.match
                    elif match(
                            r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?',
                            recordName, M | I):
                        value = recordName
                    else:
                        value = recordName + "." + zoneDomain

                    recordContentTXT = data[
                        'recordContentTXT']  ## IP or ponting value
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="TXT",
                                     content=recordContentTXT,
                                     ttl=ttl,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "SOA":

                    recordContentSOA = data['recordContentSOA']

                    records = Records(domainOwner=zone,
                                      domain_id=zone.id,
                                      name=zoneDomain,
                                      type="SOA",
                                      content=recordContentSOA,
                                      ttl=ttl,
                                      prio=0,
                                      disabled=0,
                                      auth=1)
                    records.save()
                elif recordType == "NS":

                    recordContentNS = data['recordContentNS']

                    if recordContentNS == "@":
                        recordContentNS = "ns1." + zoneDomain
                    ## re.match
                    elif match(
                            r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?',
                            recordContentNS, M | I):
                        recordContentNS = recordContentNS
                    else:
                        recordContentNS = recordContentNS + "." + zoneDomain

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=zoneDomain,
                                     type="NS",
                                     content=recordContentNS,
                                     ttl=ttl,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()
                elif recordType == "SRV":

                    if recordName == "@":
                        value = zoneDomain
                    ## re.match
                    elif match(
                            r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?',
                            recordName, M | I):
                        value = recordName
                    else:
                        value = recordName + "." + zoneDomain

                    recordContentSRV = data['recordContentSRV']
                    priority = data['priority']

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=value,
                                     type="SRV",
                                     content=recordContentSRV,
                                     ttl=ttl,
                                     prio=priority,
                                     disabled=0,
                                     auth=1)
                    record.save()

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

        except BaseException, msg:
            final_dic = {'add_status': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)
    except KeyError, msg:
        final_dic = {
            'add_status':
            0,
            'error_message':
            "Not Logged In, please refresh the page or login again."
        }
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)