Example #1
0
    def get(self):
        self.auth.account.load_domains()

        domain_id_list = []
        requested_domain_ids = []
        domain_ids = request.args.get(
            "domain_ids",
            None
        )

        # check for provided list of domain ids
        if domain_ids is not None:
            requested_domain_ids = domain_ids.replace(" ", "").split(",")

            if self.auth.account.account_type != "senior_admin":
                # check read permissions
                for d in requested_domain_ids:
                    if not str.isdigit(str(d)):
                        abort(400, message="invalid domain_ids value")
                    if self.auth.account.can_read_domain(d):
                        domain_id_list.append(d)
            else:
                for d in requested_domain_ids:
                    if not str.isdigit(str(d)):
                        abort(400, message="invalid domain_ids value")
                domain_id_list = requested_domain_ids
        else:
            # only build list for non-senior_admin users
            if self.auth.account.account_type != "senior_admin":
                for d in self.auth.account.domains:
                    domain_id_list.append(d)

        # get audit logs
        if self.auth.account.account_type == "senior_admin":
            if len(domain_id_list) == 0:
                logs = ModelAuditLog.select()
            else:
                logs = ModelAuditLog.select().where(
                    ModelAuditLog.domain_id << domain_id_list
                )
        else:
            logs = ModelAuditLog.select().where(
                ModelAuditLog.domain_id << domain_id_list
            )

        total_logs = logs.count()
        logs = self.paginate_query(logs, request.args)
        logs = self.sort_query(logs, request.args)

        audit_logs = []
        for l in logs:
            audit_logs.append(l.to_clean_dict())

        return {
            'status': 'ok',
            'audit_logs': audit_logs,
            'total_audit_logs': total_logs
        }
Example #2
0
    def get(self):
        self.auth.account.load_domains()

        domain_id_list = []
        requested_domain_ids = []
        domain_ids = request.args.get("domain_ids", None)
        search = request.args.get("search", "")

        # check for provided list of domain ids
        if domain_ids is not None:
            requested_domain_ids = domain_ids.replace(" ", "").split(",")

            if self.auth.account.account_type != "senior_admin":
                # check read permissions
                for d in requested_domain_ids:
                    if not str.isdigit(str(d)):
                        abort(400, message="invalid domain_ids value")
                    if self.auth.account.can_read_domain(d):
                        domain_id_list.append(d)
            else:
                for d in requested_domain_ids:
                    if not str.isdigit(str(d)):
                        abort(400, message="invalid domain_ids value")
                domain_id_list = requested_domain_ids
        else:
            # only build list for non-senior_admin users
            if self.auth.account.account_type != "senior_admin":
                for d in self.auth.account.domains:
                    domain_id_list.append(d)

        # get audit logs
        if self.auth.account.account_type == "senior_admin":
            if len(domain_id_list) == 0:
                logs = ModelAuditLog.select().where(
                    ModelAuditLog.entry**('%' + search + '%'))
            else:
                logs = ModelAuditLog.select().where(
                    ModelAuditLog.domain_id << domain_id_list,
                    ModelAuditLog.entry**('%' + search + '%'))
        else:
            logs = ModelAuditLog.select().where(
                ModelAuditLog.domain_id << domain_id_list,
                ModelAuditLog.entry**('%' + search + '%'))

        total_logs = logs.count()
        logs = self.paginate_query(logs, request.args)
        logs = self.sort_query(logs, request.args)

        audit_logs = []
        for l in logs:
            audit_logs.append(l.to_clean_dict())

        return {
            'status': 'ok',
            'audit_logs': audit_logs,
            'total_audit_logs': total_logs
        }
Example #3
0
    def get_latest_log_timestamp(self):
        result = ModelAuditLog.select(
            ModelAuditLog.time).order_by(-ModelAuditLog.time).limit(1)

        if result:
            return result[0].time
        else:
            return 0
Example #4
0
    def dns_log(self, domain_id, entry):
        log = ModelAuditLog()
        log.name = (self.auth.account.first_name + " " +
                    self.auth.account.last_name)
        log.email = self.auth.account.email
        log.domain_id = domain_id
        log.account_id = self.auth.account.account_id
        log.entry = entry
        log.time = int(time.time())

        try:
            log.save()
            return log
        except:
            # FIXME log error
            pass
Example #5
0
    def get_latest_log_timestamp(self):
        result = ModelAuditLog.select(
            ModelAuditLog.time
        ).order_by(
            -ModelAuditLog.time
        ).limit(1)

        if result:
            return result[0].time
        else:
            return 0
Example #6
0
    def dns_log(self, domain_id, entry):
        log = ModelAuditLog()
        log.name = (self.auth.account.first_name +
                    " " +
                    self.auth.account.last_name)
        log.email = self.auth.account.email
        log.domain_id = domain_id
        log.account_id = self.auth.account.account_id
        log.entry = entry
        log.time = int(time.time())

        try:
            log.save()
            return log
        except:
            # FIXME log error
            pass