records.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:oniongate-web 作者: DonnchaC 项目源码 文件源码
def post(self, domain_name):
        """
        Create a new DNS record on this domain

        The request must be validated with the domain token.
        """
        probable_onion_mapping = None
        args = new_record_parser.parse_args()
        num_records = Record.query.filter_by(domain=g.domain).count()

        if num_records >= current_app.config["MAX_RECORDS"]:
            return abort(403, message="This domain has had reach the DNS record limit. You cannot "
                         "add more without removing some existing records")

        # Record address on domain if this looks like an onion mapping
        if is_onion_record(args.value) and args.type == "TXT":
            probable_onion_mapping = args.value.split("=")[1]

        try:
            record = Record.create(domain=g.domain,
                                   label=args.label,
                                   ttl=args.ttl or current_app.config["TXT_RECORD_TTL"],
                                   record_type=args.type,
                                   value=args.value,
                                   is_onion_mapping=probable_onion_mapping)
        except exc.IntegrityError:
            return abort(422, message="An unknown error occurred when trying to create "
                         "this record")

        # Guess that the user is updating their onion address if its a valid
        # onion=theonionaddress.onion type TXT record
        if probable_onion_mapping:
            # Update the convenience onion_address wrapper on the domain
            g.domain.update(onion_address=probable_onion_mapping,
                            date_updated=datetime.datetime.utcnow(),
                            service_online=True,
                            updated_since_synced=True)

        return record
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号