Пример #1
0
    def post(self):
        """
        添加站点到资产组中
        """
        args = self.parse_args(add_site_fields)
        site = args.pop("site")
        scope_id = args.pop("scope_id")
        url = utils.normal_url(site).strip("/")
        if not url:
            return utils.build_ret(ErrorMsg.DomainInvalid, {"site": site})

        scope_data = utils.conn_db('asset_scope').find_one(
            {"_id": ObjectId(scope_id)})
        if not scope_data:
            return utils.build_ret(ErrorMsg.NotFoundScopeID,
                                   {"scope_id": scope_id})

        fld = utils.get_fld(url)
        if not fld:
            return utils.build_ret(ErrorMsg.SiteURLNotDomain, {"site": url})

        if fld not in scope_data["scope"]:
            return utils.build_ret(ErrorMsg.DomainNotFoundViaScope,
                                   {"site": url})

        site_data = utils.conn_db('asset_site').find_one({
            "site": url,
            "scope_id": scope_id
        })
        if site_data:
            return utils.build_ret(ErrorMsg.SiteInScope, {"site": url})

        add_site_to_scope(url, scope_id)

        return utils.build_ret(ErrorMsg.Success, {"site": url})
Пример #2
0
def is_in_scope(src_domain, target_domain):
    from app.utils import get_fld

    fld1 = get_fld(src_domain)
    fld2 = get_fld(target_domain)

    if not fld1 or not fld2:
        return False

    if fld1 != fld2:
        return False

    if src_domain == target_domain:
        return True

    return src_domain.endswith("." + target_domain)
Пример #3
0
    def post(self):
        """
        添加域名到资产组中
        """
        args = self.parse_args(add_domain_fields)
        domain = args.pop("domain")
        scope_id = args.pop("scope_id")
        if not utils.is_valid_domain(domain):
            return utils.build_ret(ErrorMsg.DomainInvalid, {"domain": domain})

        scope_data = utils.conn_db('asset_scope').find_one({"_id": ObjectId(scope_id)})
        if not scope_data:
            return utils.build_ret(ErrorMsg.NotFoundScopeID, {"scope_id": scope_id})

        if utils.get_fld(domain) not in scope_data["scope"]:
            return utils.build_ret(ErrorMsg.DomainNotFoundViaScope, {"domain": domain})

        domain_data = utils.conn_db("asset_domain").find_one({"domain": domain, "scope_id": scope_id})
        if domain_data:
            return utils.build_ret(ErrorMsg.DomainInScope, {"domain": domain})

        options = {
            "celery_action": CeleryAction.ADD_DOMAIN_TO_SCOPE,
            "data": {
                "domain": domain,
                "scope_id": scope_id
            }
        }
        celerytask.arl_task.delay(options=options)
        return utils.build_ret(ErrorMsg.Success, options["data"])
Пример #4
0
    def post(self):
        """
        添加域名到资产组中
        """
        args = self.parse_args(add_domain_fields)
        raw_domain = args.pop("domain")
        domain_list = re.split(r",|\s", raw_domain)
        domain_list = list(set(filter(None, domain_list)))
        scope_id = args.pop("scope_id")

        scope_data = utils.conn_db('asset_scope').find_one(
            {"_id": ObjectId(scope_id)})
        if not scope_data:
            return utils.build_ret(ErrorMsg.NotFoundScopeID,
                                   {"scope_id": scope_id})

        domain_in_scope_list = []
        add_domain_list = []
        for domain in domain_list:
            if not utils.is_valid_domain(domain):
                return utils.build_ret(ErrorMsg.DomainInvalid,
                                       {"domain": domain})

            if utils.get_fld(domain) not in scope_data["scope"]:
                return utils.build_ret(ErrorMsg.DomainNotFoundViaScope,
                                       {"domain": domain})

            domain_data = utils.conn_db("asset_domain").find_one({
                "domain":
                domain,
                "scope_id":
                scope_id
            })
            if domain_data:
                domain_in_scope_list.append(domain)
                continue
            add_domain_list.append(domain)

        for domain in add_domain_list:
            options = {
                "celery_action": CeleryAction.ADD_DOMAIN_TO_SCOPE,
                "data": {
                    "domain": domain,
                    "scope_id": scope_id
                }
            }
            celerytask.arl_task.delay(options=options)

        ret_data = {
            "domain": ",".join(add_domain_list),
            "scope_id": scope_id,
            "domain_in_scope": ",".join(domain_in_scope_list)
        }
        if len(add_domain_list) == 0:
            return utils.build_ret(ErrorMsg.DomainNotFoundNotInScope, ret_data)

        return utils.build_ret(ErrorMsg.Success, ret_data)
Пример #5
0
    def get(self):
        """
        任务同步资产组查询
        """
        args = self.parser.parse_args()
        target = args.pop("target")
        if not utils.is_valid_domain(target):
            return utils.build_ret(ErrorMsg.DomainInvalid, {"target": target})

        args["scope_array"] = utils.get_fld(target)
        args["size"] = 100
        args["order"] = "_id"

        data = self.build_data(args=args, collection='asset_scope')
        ret = []
        for item in data["items"]:
            if utils.is_in_scopes(target, item["scope_array"]):
                ret.append(item)

        data["items"] = ret
        data["total"] = len(ret)
        return data