예제 #1
0
파일: views.py 프로젝트: jwasinger/cyder
def build_debug_soa(request, soa_pk):
    soa = get_object_or_404(SOA, pk=soa_pk)
    #DEBUG_BUILD_STRING = build_zone(soa, root_domain)
    # Figure out what sort of domains are in this zone.

    try:
        public_view = View.objects.get(name='public')
        public_data = build_zone_data(public_view, soa.root_domain, soa)

        try:
            private_view = View.objects.get(name='private')
            private_data = build_zone_data(private_view, soa.root_domain, soa)
        except ObjectDoesNotExist:
            private_data = ''

        output = _("""
;======= Private Data =======
{0}

;======= Public Data =======
{1}
                   """.format(private_data, public_data))

        return render(request, 'cybind/sample_build.html', {
            'data': output,
            'soa': soa
        })

    except Exception, e:
        return HttpResponse(
            json.dumps({"error": "Could not build bind file: %s" % e}))
예제 #2
0
파일: views.py 프로젝트: church29/cyder
def build_debug_soa(request, soa_pk):
    soa = get_object_or_404(SOA, pk=soa_pk)
    #DEBUG_BUILD_STRING = build_zone(soa, root_domain)
    # Figure out what sort of domains are in this zone.

    try:
        public_view = View.objects.get(name='public')
        public_data = build_zone_data(public_view, soa.root_domain, soa)

        try:
            private_view = View.objects.get(name='private')
            private_data = build_zone_data(private_view, soa.root_domain, soa)
        except ObjectDoesNotExist:
            private_data = ''

        output = _("""
;======= Private Data =======
{0}

;======= Public Data =======
{1}
                   """.format(private_data, public_data))

        return render(request, 'cybind/sample_build.html',
                      {'data': output, 'soa': soa})

    except Exception, e:
        return HttpResponse(
            json.dumps({"error": "Could not build bind file: %s" % e}))
예제 #3
0
파일: builder.py 프로젝트: OSU-Net/cyder
 def get_view_data(view):
     self.log_debug("++++++ Looking at < {0} > view ++++++"
                    .format(view.name), root_domain=root_domain)
     t_start = time.time()  # tic
     view_data = build_zone_data(view, root_domain, soa,
                                 logf=self.log_notice)
     build_time = time.time() - t_start  # toc
     self.log_debug('< {0} > Built {1} data in {2} seconds'
                    .format(view.name, soa, build_time),
                    root_domain=root_domain)
     if not view_data:
         # Though there is no zone file, we keep it in the
         # config to claim authority (for DNS poison, etc.)
         self.log_debug(
             '< {0} > No data found in this view. '
             'No zone file will be made, but it will be '
             'included in the config for '
             'this view.'.format(view.name),
             root_domain=root_domain)
         return None
     self.log_debug(
         '< {0} > Non-empty data set for this '
         'view. Its zone file will be included in the '
         'config.'.format(view.name), root_domain=root_domain)
     return view_data
예제 #4
0
파일: builder.py 프로젝트: murrown/cyder
 def get_view_data(view):
     self.log_debug(
         "++++++ Looking at < {0} > view ++++++".format(
             view.name),
         root_domain=root_domain)
     t_start = time.time()  # tic
     view_data = build_zone_data(view,
                                 root_domain,
                                 soa,
                                 logf=self.log_notice)
     build_time = time.time() - t_start  # toc
     self.log_debug(
         '< {0} > Built {1} data in {2} seconds'.format(
             view.name, soa, build_time),
         root_domain=root_domain)
     if not view_data:
         # Though there is no zone file, we keep it in the
         # config to claim authority (for DNS poison, etc.)
         self.log_debug(
             '< {0} > No data found in this view. '
             'No zone file will be made, but it will be '
             'included in the config for '
             'this view.'.format(view.name),
             root_domain=root_domain)
         return None
     self.log_debug(
         '< {0} > Non-empty data set for this '
         'view. Its zone file will be included in the '
         'config.'.format(view.name),
         root_domain=root_domain)
     return view_data
예제 #5
0
파일: views.py 프로젝트: alecdhuse/cyder
def build_debug_soa(request, soa_pk):
    soa = get_object_or_404(SOA, pk=soa_pk)
    #DEBUG_BUILD_STRING = build_zone(soa, root_domain)
    # Figure out what sort of domains are in this zone.
    try:
        private_data, public_data = build_zone_data(soa.root_domain, soa)
        output = _("""
;======= Private Data =======
{0}

;======= Private Data =======
{1}
                   """.format(private_data, public_data))
    except Exception:
        return HttpResponse(json.dumps(
                            {"error": "HOLY SHIT SOMETHING WENT WRONG!!!"}))
    return render(request, 'cybind/sample_build.html',
                  {'data': output, 'soa': soa})
예제 #6
0
파일: views.py 프로젝트: jirwin/cyder
def build_debug_soa(request, soa_pk):
    soa = get_object_or_404(SOA, pk=soa_pk)
    #DEBUG_BUILD_STRING = build_zone(soa, root_domain)
    # Figure out what sort of domains are in this zone.
    try:
        private_data, public_data = build_zone_data(soa.root_domain, soa)
        output = _("""
;======= Private Data =======
{0}

;======= Private Data =======
{1}
                   """.format(private_data, public_data))
    except Exception:
        return HttpResponse(
            json.dumps({"error": "HOLY SHIT SOMETHING WENT WRONG!!!"}))
    return render(request, 'cybind/sample_build.html', {
        'data': output,
        'soa': soa
    })
예제 #7
0
파일: builder.py 프로젝트: alecdhuse/cyder
    def build_zone_files(self, soa_pks_to_rebuild):
        zone_stmts = {}

        for soa in SOA.objects.all():
            # If anything happens during this soa's build we need to mark
            # it as dirty so it can be rebuild
            try:
                root_domain = soa.root_domain  # This is an expensive lookup

                if not root_domain:
                    continue

                # General order of things:
                # * Find which views should have a zone file built and add them
                # to a list.
                # * If any of the view's zone file have been tampered with or
                # the zone is new, trigger the rebuilding of all the zone's
                # view files. (rebuil all views in a zone keeps the serial
                # synced across all views)
                # * Either rebuild all of a zone's view files because one view
                # needed to be rebuilt due to tampering or the zone was dirty
                # (again, this is to keep their serial synced) or just call
                # named-checkzone on the existing zone files for good measure.
                # Also generate a zone statement and add it to a dictionary for
                # later use during BIND configuration generation.

                force_rebuild = soa.pk in soa_pks_to_rebuild or soa.dirty
                if force_rebuild:
                    soa.dirty = False
                    soa.save()

                self.log('====== Processing {0} {1} ======'.format(
                    root_domain, soa.serial)
                )
                views_to_build = []
                self.log(
                    "SOA was seen with dirty == {0}".format(force_rebuild),
                    root_domain=root_domain
                )

                # This for loop decides which views will be canidates for
                # rebuilding.
                for view in View.objects.all():
                    self.log("++++++ Looking at < {0} > view ++++++".
                             format(view.name), root_domain=root_domain)
                    t_start = time.time()  # tic
                    view_data = build_zone_data(view, root_domain, soa,
                                                logf=self.log)
                    build_time = time.time() - t_start  # toc
                    self.log('< {0} > Built {1} data in {2} seconds'
                             .format(view.name, soa, build_time),
                             root_domain=root_domain, build_time=build_time)
                    if not view_data:
                        self.log('< {0} > No data found in this view. '
                                 'No zone file will be made or included in any'
                                 ' config for this view.'.format(view.name),
                                 root_domain=root_domain)
                        continue
                    self.log('< {0} > Non-empty data set for this '
                             'view. Its zone file will be included in the '
                             'config.'.format(view.name),
                             root_domain=root_domain)
                    file_meta = self.get_file_meta(view, root_domain, soa)
                    was_bad_prev, new_serial = self.verify_previous_build(
                        file_meta, view, root_domain, soa
                    )

                    if was_bad_prev:
                        soa.serial = new_serial
                        force_rebuild = True

                    views_to_build.append(
                        (view, file_meta, view_data)
                    )

                self.log(
                    '----- Building < {0} > ------'.format(
                        ' | '.join([v.name for v, _, _ in views_to_build])
                    ), root_domain=root_domain
                )

                if force_rebuild:
                    # Bypass save so we don't have to save a possible stale
                    # 'dirty' value to the db.
                    SOA.objects.filter(pk=soa.pk).update(serial=soa.serial + 1)
                    self.log('Zone will be rebuilt at serial {0}'
                             .format(soa.serial + 1), root_domain=root_domain)
                else:
                    self.log('Zone is stable at serial {0}'
                             .format(soa.serial), root_domain=root_domain)

                for view, file_meta, view_data in views_to_build:
                    view_zone_stmts = zone_stmts.setdefault(view.name, [])
                    # If we see a view in this loop it's going to end up in the
                    # config
                    view_zone_stmts.append(
                        self.render_zone_stmt(soa, root_domain, file_meta)
                    )
                    # If it's dirty or we are rebuilding another view, rebuild
                    # the zone
                    if force_rebuild:
                        self.log(
                            'Rebuilding < {0} > view file {1}'
                            .format(view.name, file_meta['prod_fname']),
                            root_domain=root_domain)
                        prod_fname = self.build_zone(
                            view, file_meta,
                            # Lazy string evaluation
                            view_data.format(serial=soa.serial + 1),
                            root_domain
                        )
                        assert prod_fname == file_meta['prod_fname']
                    else:
                        self.log(
                            'NO REBUILD needed for < {0} > view file {1}'
                            .format(view.name, file_meta['prod_fname']),
                            root_domain=root_domain
                        )
                        # Run named-checkzone for good measure.
                        if self.STAGE_ONLY:
                            self.log("Not calling named-checkconf.",
                                     root_domain=root_domain)
                        else:
                            self.named_checkzone(
                                file_meta['prod_fname'], root_domain
                            )
            except Exception:
                soa.schedule_rebuild()
                raise

        return zone_stmts
예제 #8
0
    def build_zone_files(self, soa_pks_to_rebuild, force=False):
        zone_stmts = {}

        for soa in SOA.objects.filter(dns_enabled=True):
            # If anything happens during this soa's build we need to mark
            # it as dirty so it can be rebuild
            try:
                root_domain = soa.root_domain  # This is an expensive lookup

                if not root_domain:
                    continue

                # General order of things:
                # * Find which views should have a zone file built and add them
                # to a list.
                # * If any of the view's zone file have been tampered with or
                # the zone is new, trigger the rebuilding of all the zone's
                # view files. (Rebuilding all views in a zone keeps the serial
                # synced across all views.)
                # * Either rebuild all of a zone's view files because one view
                # needed to be rebuilt due to tampering or the zone was dirty
                # (again, this is to keep their serial synced) or just call
                # named-checkzone on the existing zone files for good measure.
                # Also generate a zone statement and add it to a dictionary for
                # later use during BIND configuration generation.

                force_rebuild = (soa.pk in soa_pks_to_rebuild or soa.dirty
                                 or force)
                if force_rebuild:
                    soa.dirty = False
                    soa.save()

                self.log_debug('====== Processing {0} {1} ======'.format(
                    root_domain, soa.serial))
                views_to_build = []
                self.log_debug(
                    "SOA was seen with dirty == {0}".format(force_rebuild),
                    root_domain=root_domain)

                # This for loop decides which views will be canidates for
                # rebuilding.
                for view in View.objects.all():
                    self.log_debug(
                        "++++++ Looking at < {0} > view ++++++".format(
                            view.name),
                        root_domain=root_domain)
                    t_start = time.time()  # tic
                    view_data = build_zone_data(view,
                                                root_domain,
                                                soa,
                                                logf=self.log_notice)
                    build_time = time.time() - t_start  # toc
                    self.log_debug(
                        '< {0} > Built {1} data in {2} seconds'.format(
                            view.name, soa, build_time),
                        root_domain=root_domain)
                    if not view_data:
                        self.log_debug(
                            '< {0} > No data found in this view. '
                            'No zone file will be made or included in any'
                            ' config for this view.'.format(view.name),
                            root_domain=root_domain)
                        continue
                    self.log_debug(
                        '< {0} > Non-empty data set for this '
                        'view. Its zone file will be included in the '
                        'config.'.format(view.name),
                        root_domain=root_domain)
                    file_meta = self.get_file_meta(view, root_domain, soa)

                    if force:
                        was_bad_prev = True
                        new_serial = int(time.time())
                    else:
                        was_bad_prev, new_serial = self.verify_previous_build(
                            file_meta, view, root_domain, soa)

                    if was_bad_prev:
                        soa.serial = new_serial
                        force_rebuild = True

                    views_to_build.append((view, file_meta, view_data))

                self.log_debug('----- Building < {0} > ------'.format(
                    ' | '.join([v.name for v, _, _ in views_to_build])),
                               root_domain=root_domain)

                if force_rebuild:
                    # Bypass save so we don't have to save a possible stale
                    # 'dirty' value to the db.
                    SOA.objects.filter(pk=soa.pk).update(serial=soa.serial + 1)
                    self.log_debug('Zone will be rebuilt at serial {0}'.format(
                        soa.serial + 1),
                                   root_domain=root_domain)
                else:
                    self.log_debug('Zone is stable at serial {0}'.format(
                        soa.serial),
                                   root_domain=root_domain)

                for view, file_meta, view_data in views_to_build:
                    if (root_domain.name, view.name) in ZONES_WITH_NO_CONFIG:
                        self.log_notice(
                            '!!! Not going to emit zone statements for {0}\n'.
                            format(root_domain.name),
                            root_domain=root_domain)
                    else:
                        view_zone_stmts = zone_stmts.setdefault(view.name, [])
                        # If we see a view in this loop it's going to end up in
                        # the config
                        view_zone_stmts.append(
                            self.render_zone_stmt(soa, root_domain, file_meta))

                    # If it's dirty or we are rebuilding another view, rebuild
                    # the zone
                    if force_rebuild:
                        self.log_debug(
                            'Rebuilding < {0} > view file {1}'.format(
                                view.name, file_meta['prod_fname']),
                            root_domain=root_domain)
                        self.build_zone(
                            view,
                            file_meta,
                            # Lazy string evaluation
                            view_data.format(serial=soa.serial + 1),
                            root_domain)
                        self.run_checkzone(
                            os.path.join(self.stage_dir,
                                         file_meta['rel_fname']), root_domain)
                    else:
                        self.log_debug(
                            'NO REBUILD needed for < {0} > view file {1}'.
                            format(view.name, file_meta['prod_fname']),
                            root_domain=root_domain)
            except Exception:
                soa.schedule_rebuild()
                raise

        return zone_stmts