Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义规则管理问题 #35

Closed
ChinaSrc opened this issue Dec 4, 2020 · 1 comment
Closed

自定义规则管理问题 #35

ChinaSrc opened this issue Dec 4, 2020 · 1 comment

Comments

@ChinaSrc
Copy link

ChinaSrc commented Dec 4, 2020

请问自定义规则是否有全局管理的地方,目前后台功能了解到似乎只能针对指定站点配置自定义规则。
如果有新加站点想复用其他站点的规则应该怎么操作呢?

@sss56
Copy link

sss56 commented Jul 13, 2021

过度方案,修改jxwaf/waf_domain.py中的waf_copy_domain方法函数,在复制网站的时候同时复制自定义规则,代码如下:

def waf_copy_domain(request):
return_result = {}
try:
user_id = request.session['user_id']
json_data = json.loads(request.body)
old_domain = json_data['old_domain']
new_domain = json_data['new_domain']
waf_domain_result = waf_domain.objects.get(Q(domain=old_domain) & Q(user_id=user_id))
waf_custom_rule_result = waf_custom_rule.objects.filter(Q(domain=old_domain) & Q(user_id=user_id))
try:
waf_domain.objects.get(Q(domain=new_domain) & Q(user_id=user_id))
return_result['result'] = False
return_result['errCode'] = 409
return_result['message'] = "domain exist"
return JsonResponse(return_result, safe=False)
except:
pass
if waf_domain_result.https == 'true':
waf_domain.objects.create(user_id=user_id, email=waf_domain_result.email, domain=new_domain,
http=waf_domain_result.http, https=waf_domain_result.https,
source_ip=waf_domain_result.source_ip,
source_http_port=waf_domain_result.source_http_port,
public_key=waf_domain_result.public_key,
private_key=waf_domain_result.private_key,
redirect_https=waf_domain_result.redirect_https,
proxy=waf_domain_result.proxy, proxy_ip=waf_domain_result.proxy_ip,
proxy_pass_https=waf_domain_result.proxy_pass_https)
else:
waf_domain.objects.create(user_id=user_id, email=waf_domain_result.email, domain=new_domain,
http=waf_domain_result.http, https=waf_domain_result.https,
source_ip=waf_domain_result.source_ip,
source_http_port=waf_domain_result.source_http_port,
proxy=waf_domain_result.proxy, proxy_ip=waf_domain_result.proxy_ip,
proxy_pass_https=waf_domain_result.proxy_pass_https)
for i in range(len(waf_custom_rule_result)):
# print waf_custom_rule_result[i]
if waf_custom_rule_result[i].rule_action == 'deny':
waf_custom_rule.objects.create(user_id=user_id, domain=new_domain,
rule_id=int(time.time()) + i,
rule_action=waf_custom_rule_result[i].rule_action,
rule_level=waf_custom_rule_result[i].rule_level,
rule_name=waf_custom_rule_result[i].rule_name,
rule_log=waf_custom_rule_result[i].rule_log,
rule_matchs=waf_custom_rule_result[i].rule_matchs)
else:
waf_custom_rule.objects.create(user_id=user_id, domain=new_domain,
rule_id=int(time.time()) + i,
rule_action=waf_custom_rule_result[i].rule_action,
rule_level=waf_custom_rule_result[i].rule_level,
rule_name=waf_custom_rule_result[i].rule_name,
rule_log=waf_custom_rule_result[i].rule_log,
rule_matchs=waf_custom_rule_result[i].rule_matchs)

    waf_protection.objects.create(user_id=user_id, domain=new_domain, email=waf_domain_result.email)
    waf_cc_protection.objects.create(user_id=user_id, domain=new_domain)
    waf_cc_attack_ip_conf.objects.create(user_id=user_id, domain=new_domain)
    waf_owasp_check.objects.create(user_id=user_id, domain=new_domain)
    waf_page_custom.objects.create(user_id=user_id, domain=new_domain)
    waf_evil_ip_conf.objects.create(user_id=user_id, domain=new_domain)
    return_result['result'] = True
    return_result['message'] = "success"
    return JsonResponse(return_result, safe=False)
except Exception, e:
    return_result['result'] = False
    return_result['message'] = str(e)
    return_result['errCode'] = 400
    return JsonResponse(return_result, safe=False)

@jx-sec jx-sec closed this as completed Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants