def admin_cms_details_views(request, user_id): """管理员cms客户绑定关系详情""" res = { 'property': 'is_details' } client = UserProfile.objects.filter(id=user_id).first() if client: username = client.username body = { 'username_list': [username], } api_res = APIUrl.post_link('user_query', body) user_query = api_res.get('user_query', {}) cms_username = user_query.get(username, {}).get('cms_username', '') contract = user_query.get(username, {}).get('contract', '') client.cms_username = cms_username client.user_id = str(user_id) client.company = '' if not client.company else client.company res['client'] = client res['contract'] = contract return render(request, 'user_accounts/create_binding.html', res)
def user_domain_preload(request, user): """用户刷新""" urls = request.POST.get('urls', '[]') user_id = user.id msg = '' try: urls = handle_list(urls) if urls: urls = detect_domain(user_id, urls) if not urls: msg = af.URL_FORMAT_ERROR assert False body = { 'user_id': user.id, 'urls': urls, } print(body) api_res = APIUrl.post_link('cdn_domain_preload', body) print(api_res) return_code = api_res.get('return_code', 0) if return_code != 0: msg = af.SEND_ERROR assert False except AssertionError: pass return msg
def admin_user_relieve_binding(request): """管理员解除绑定用户cms关系""" msg = '' status = False res = {'status': status, 'msg': msg} username = request.POST.get('username', '') try: user = UserProfile.objects.filter(username=username).first() if not user: msg = af.USER_NOT_EXIST assert False body = { 'username': username, } res = APIUrl.post_link('user_relieve_cms_binding', body) result = res.get('result', False) if result: status = True except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)
def admin_cdn_domain_conf(request): """ 修改cdn域名 """ msg = '' status = False res = {'status': status, 'msg': msg} user_id = request.POST.get('user_id', '') domain = request.POST.get('domain', '') provider = request.POST.get('provider', 'CC') # user_id = '93' # domain = 'itestxz0021.chinacache.com' user_id = int_check(user_id) try: domain_obj_list = Domain.objects.filter(domain=domain) if not domain_obj_list: assert False msg = af.DOMAIN_EXIST protocol = CDNConf.HTTP_TYPE for domain_obj in domain_obj_list: if domain_obj.protocol == CDNConf.HTTPS_TYPE: protocol = CDNConf.HTTPS_TYPE break user_id = int_check(user_id) if user_id is None: msg = af.PARAME_ERROR assert False body = { 'user_id': user_id, 'protocol': protocol, 'domain': domain, 'provider': provider } api_res = APIUrl.post_link('cdn_domain_sync_conf', body) return_code = api_res.get('return_code', 0) if return_code != 0: assert False res['domain_conf'] = api_res['domain_conf'] status = True except Exception as e: print(e) res['msg'] = _(msg) res['status'] = status return json_response(res)
def admin_cdn_edit_domain_views(request, domain_id): """管理员修改域名配置""" res = {} body = { 'status': [CertConf.CERT_SUCCESS], } api_res = APIUrl.post_link('ssl_cert_query', body) return_code = api_res.get('return_code', 0) cert_name_list = [] if return_code == 0: cert_info_list = api_res.get('cert_list', []) for cert in cert_info_list: cert_name_list.append(cert.get('cert_name', '')) domain_obj = Domain.objects.filter(id=domain_id).first() if domain_obj: domain_obj = get_domain_conf(domain_obj) res['domain'] = domain_obj res['src_type'] = CDNConf.SRC_TYPE res['src_back_type'] = CDNConf.SRC_BACK_TYPE res['cache_type'] = CDNConf.CACHE_TYPE res['cert_status'] = CertConf.CERT_STATUS res['cert_from'] = CertConf.CERT_FROM res['cert_list'] = cert_name_list return render(request, 'cdn/modify_admin_domain_configure.html', res)
def set_user_api_status(request, user): """用户设置api状态""" msg = '' try: api_status = request.POST.get('status', '') api_status = int_check(api_status) if api_status is None: af.PARAME_ERROR assert False body = { 'username': user.username, 'status': api_status } api_res = APIUrl.post_link('set_api_status', body) result = api_res.get('return_code', 0) if result != 0: msg = af.SEND_ERROR assert False except AssertionError: pass return msg
def user_open_parent_api(user): """用户设置api状态""" msg = '' res = {} try: body = { 'username': user.username, } api_res = APIUrl.post_link('user_open_api', body) result = api_res.get('return_code', 0) if result != 0: msg = af.SEND_ERROR assert False res['secret_id'] = api_res.get('secret_id', '') res['secret_key'] = api_res.get('secret_key', '') res['create_time'] = api_res.get('create_time', '') res['api_open'] = api_res.get('api_open', 0) except AssertionError: pass return msg, res
def admin_cert_edit_views(request, cert_name, user_id): """管理端证书修改页面""" try: if user_id: user_id = int_check(user_id) if user_id is None: msg = af.PARAME_ERROR assert False body = {'cert_name': cert_name, 'user_id': user_id} api_res = APIUrl.post_link('ssl_cert_detail', body) return_code = api_res.get('return_code', 0) if return_code != 0: assert False cert_detail = api_res.get('cert_detail', {}) except AssertionError: pass res = {'cert_detail': cert_detail, 'remind_time': CertConf.REMIND_TIME} return render(request, 'cert/admin_cert_create.html', res)
def parent_set_defense_mode(request): """父账号自己设置规则防御模式""" msg = '' status = False res = {'status': status, 'msg': msg} provider = 'QINGSONG' domain_id = request.POST.get('domain_id', '') default_waf_mode = request.POST.get('default_waf_mode', '') self_waf_mode = request.POST.get('self_waf_mode', '') try: domain_obj = Domain.objects.filter(id=domain_id).first() if not domain_obj: msg = af.DOMAIN_NOT_EXIST assert False body = { 'channel': '%s://%s' % (domain_obj.protocol, domain_obj.domain), } if default_waf_mode: default_waf_mode = int_check(default_waf_mode) if default_waf_mode is None: msg = af.PARAME_ERROR assert False body['default'] = 1 body['switch'] = default_waf_mode log_msg = om.SET_DEFAULT_RULE_MODE % ( request.user.username, domain_obj.domain, default_waf_mode) elif self_waf_mode: self_waf_mode = int_check(self_waf_mode) if self_waf_mode is None: msg = af.PARAME_ERROR assert False body['default'] = 0 body['switch'] = self_waf_mode log_msg = om.SET_SELF_RULE_MODE % ( request.user.username, domain_obj.domain, self_waf_mode) api_res = APIUrl.post_link('set_defense_mode', body) if api_res[provider]['return_code'] == 0: status = True OperateLog.write_operate_log(request, om.SECURITY, log_msg) except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)
def admin_statistics_views(request): """管理员统计""" cdn_product = Product.objects.filter(code='CDN').first() cdn_user = cdn_product.user_product.all() user_list = [] body = { 'username_list': [u.username for u in cdn_user], } res = APIUrl.post_link('user_query', body) user_query = res.get('user_query', {}) for u in cdn_user: username = u.username domain_query = Domain.objects.filter(user=u) user_info = user_query.get(username, {}) if not user_info: continue cdn_opt = user_info.get('cdn_opt', []) check_domain = [] domain_list = [] for i in domain_query: domain_dict = { 'id': i.id, 'domain': i.domain, } if i.domain not in check_domain: domain_list.append(domain_dict) check_domain.append(i.domain) user_dict = { 'id': u.id, 'username': u.username, 'domain_list': domain_list, 'cdn_opt': cdn_opt } user_list.append(user_dict) provider_query = Provider.objects.all() provider_info = [] for i in provider_query: provider_dict = { 'id': i.code, 'name': i.name } provider_info.append(provider_dict) res = { 'user_list': user_list, 'provider_info': provider_info } return render(request, 'cdn/admin_statistics.html', res)
def admin_parent_details_views(request, user_id): """管理员获取父账号用户详情""" client = UserProfile.objects.filter(id=user_id).first() group = client.groups.first() client.group_name = group user_perm_code_list = PermUser.user_perm(client) user_perm_list = Perm.objects.filter(code__in=user_perm_code_list) user_perm, user_perm_type = handle_perm(user_perm_list) all_perm = Perm.objects.filter(content_type__contains='CLIENT') all_perm, all_perm_type = handle_perm(all_perm) client.company = client.company if client.company else '' client.mobile = client.mobile if client.mobile else '' client.active_type = af.IS_ACTIVE if client.is_active else af.IS_NOT_ACTIVE body = { 'username_list': [client.username] } res = APIUrl.post_link('user_query', body) user_query = res.get('user_query', {}) user_info = user_query.get(client.username, {}) secret_id = user_info.get('api_secret_id', '') secret_key = user_info.get('api_secret_key', '') api_create_time = user_info.get('api_create_time', '') if api_create_time: api_create_time = timestamp_to_str(api_create_time) api_open = user_info.get('api_open', 0) api_info = list() if secret_id and secret_key: api_info_dict = { 'secret_id': secret_id, 'secret_key': secret_key, 'create_time': api_create_time, 'status': api_open, 'type': _(af.COMMON) } api_info.append(api_info_dict) client.api_info = api_info res = { 'client': client, 'user_perm': user_perm, 'user_perm_type': user_perm_type, 'all_perm': all_perm, 'all_perm_type': all_perm_type } return render(request, 'user_accounts/admin_parent_details_views.html', res)
def get_domain_log(request, user): """获取域名日志""" start_time = request.POST.get('start_time', 0) end_time = request.POST.get('end_time', 0) domain = request.POST.get('domain', '') msg = '' result_list = [] pagination = {} try: msg, start_time, end_time = handle_req_time(start_time, end_time) if msg: assert False body = { 'user_id': user.id, 'start_time': start_time, 'end_time': end_time, 'domain': domain, } api_res = APIUrl.post_link('cdn_domain_log', body) return_code = api_res.get('return_code', 0) if return_code != 0: msg = af.PARAME_ERROR assert False result_list = api_res.get('result', []) all_log_list = [] for channel in result_list: url_info = urlparse(channel) protocol = url_info.scheme log_list = result_list[channel] for log in log_list: # print(log['time']) """2019 10 14 20""" time_str = '%s-%s-%s %s:%s' % ( log['time'][:4], log['time'][4:6], log['time'][6:8], log['time'][8:10], '00') log['time'] = time_str log['protocol'] = protocol all_log_list.append(log) result_list = sorted(all_log_list, key=lambda x: (x['time'], x['protocol'])) msg, result_list, pagination = data_pagination(request, result_list) except AssertionError: pass return msg, result_list, pagination
def parent_get_waf_base_conf(request): """父账号获取waf基本配置""" msg = '' status = False res = {'status': status, 'msg': msg} provider = 'QINGSONG' domain_id = request.POST.get('domain_id', '') try: if not domain_id: msg = af.DOMAIN_NOT_EXIST assert False domain_obj = Domain.objects.filter(id=domain_id).first() if not domain_obj: msg = af.DOMAIN_NOT_EXIST assert False body = { 'channel': '%s://%s' % (domain_obj.protocol, domain_obj.domain), } api_res = APIUrl.post_link('get_waf_base_info', body) if api_res[provider]['return_code'] == 0: api_res = api_res[provider] try: default_waf_mode = int(api_res.get('default_waf_mode', 0)) except Exception as e: print(e) default_waf_mode = 0 try: self_waf_mode = int(api_res.get('self_waf_mode', 0)) except Exception as e: print(e) self_waf_mode = 0 base_conf = { 'is_https': int(api_res.get('is_https', False)), 'default_waf_mode': default_waf_mode, 'self_waf_mode': self_waf_mode } res['base_conf'] = base_conf status = True except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)
def foo2(): body = { 'cert_name': 'xz_test_0009', 'user_id': 93, } api_res = APIUrl.post_link('ssl_cert_detail', body) print(api_res)
def admin_get_cms_channel_list(request): """管理员获取cms频道""" msg = '' status = False res = { 'status': status, 'msg': msg } cms_username = request.POST.get('cms_username', '') user_id = request.POST.get('user_id', '') try: user_id = int_check(user_id) if user_id is None: assert False msg = af.USER_NOT_EXIST body = { 'user_id_list': [int(user_id)], 'return_type': 'is_list' } api_res = APIUrl.post_link('domain_query', body) domain_query = api_res.get('domain_query', []) url_list = [ '%s://%s' % (i['protocol'], i['domain']) for i in domain_query] cms_channel_list = ChinaCacheAPI.get_channel_by_cms(cms_username) channel_list = [] for i in cms_channel_list: channel_name = i.get('channel_name', '') channel_info = copy.deepcopy(i) has_create = True if channel_name in url_list else False channel_info['has_create'] = has_create channel_list.append(channel_info) channel_list = sorted( channel_list, key=lambda x: urlparse(x['channel_name']).netloc) res['cms_channel_list'] = channel_list status = True except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)
def admin_binding_user_contract(request): """管理员绑定合同""" msg = '' status = False res = {'status': status, 'msg': msg} contract_name = request.POST.get('contract_name', '') start_time = request.POST.get('start_time', '') end_time = request.POST.get('end_time', '') product_list = request.POST.getlist('product_list[]', []) username = request.POST.get('username', '') # contract_name = 'Microsoft-azure-1510(重录)-2' # contract_name = 'jwcm-CC-201907' # username = '******' # start_time = "2019-08-09" # end_time = "2019-10-08" # product_list = [{ # "product_name" : "http视频点播加速服务", # "product_code" : "9010300000432" # }] try: user = UserProfile.objects.filter(username=username).first() if not user: msg = af.USER_NOT_EXIST assert False body = { 'username': user.username, 'contract': { contract_name: { 'start_time': start_time, 'end_time': end_time, 'product': product_list, } } } res = APIUrl.post_link('binding_user_contract', body) if res.get('return_code', 0) == 0: status = True log_msg = om.BINDING_USER_CONTRACT % (request.user.username, username, contract_name) OperateLog.write_operate_log(request, om.ACCOUNTS, log_msg) except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)
def user_enable_self_rule(request): msg = '' status = False res = { 'status': status, 'msg': msg } provider = 'QINGSONG' domain_id = request.POST.get('domain_id', '') rule_id = request.POST.get('rule_id', 0) enable = request.POST.get('enable', 0) try: domain_obj = Domain.objects.filter(id=domain_id).first() if not domain_obj: msg = af.DOMAIN_NOT_EXIST assert False enable = int_check(enable) if enable is None: msg = af.PARAME_ERROR assert False rule_id = int(rule_id) if rule_id is None: msg = af.PARAME_ERROR assert False body = { 'channel': '%s://%s' % (domain_obj.protocol, domain_obj.domain), 'enable': enable, 'rule_id': rule_id } api_res = APIUrl.post_link('enable_self_rule', body) print(api_res) if api_res[provider]['return_code'] == 0: status = True opt_msg = '开启' if enable else '关闭' log_msg = om.ENABLE_SELF_RULE % ( request.user.username, rule_id, opt_msg) OperateLog.write_operate_log(request, om.SECURITY, log_msg) except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)
def get_waf_defense_statistics(channel, flag_time): """获取waf数据""" body = { 'channel': channel, 'flag_time': flag_time } api_res = APIUrl.post_link('waf_defense_statistics', body) return api_res.get('data')
def admin_user_binding(request): """管理员绑定用户cms关系""" msg = '' status = False res = {'status': status, 'msg': msg} username = request.POST.get('username', '') cms_username = request.POST.get('cms_username', '') contract_list = request.POST.get('contract_list', '[]') contract_list = json.loads(contract_list) try: user = UserProfile.objects.filter(username=username).first() if not user: msg = af.USER_NOT_EXIST assert False contract_info_list = [] for c in contract_list: contract_info = { 'contract_name': c['contract_name'], 'start_time': c['start_time'], 'end_time': c['end_time'], 'product_list': c['product_list'] } contract_info_list.append(contract_info) cms_password = ChinaCacheAPI.get_cms_password(cms_username) body = { 'user_id': user.id, 'username': username, 'cms_username': cms_username, 'cms_password': cms_password, 'contract_info': contract_info_list } res = APIUrl.post_link('user_binding_cms', body) result = res.get('result', False) if result: status = True except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)
def admin_domain_set_waf(request): """管理员启用waf""" msg = '' status = False res = { 'status': status, 'msg': msg } provider = 'QINGSONG' domain_id = request.POST.get('domain_id', '') switch = request.POST.get('switch', '') try: domain_obj = Domain.objects.filter(id=domain_id).first() if not domain_obj: msg = af.DOMAIN_NOT_EXIST assert False domain = domain_obj.domain switch = int_check(switch) if switch is None: msg = af.PARAME_ERROR assert False body = { 'channel': '%s://%s' % (domain_obj.protocol, domain), "switch": switch } api_res = APIUrl.post_link('domain_waf_opt_waf', body) message = api_res[provider].get('message', 'success') msg = '' if message == 'success' else message if api_res[provider]['return_code'] == 0: status = True switch_name = '开启' if switch else '关闭' log_msg = om.SET_WAF_STATUS % ( request.user.username, domain, switch_name) OperateLog.write_operate_log( request, om.SECURITY, log_msg) except Exception as e: print(traceback.format_exc()) res['msg'] = _(msg) res['msg'] = msg res['status'] = status return json_response(res)
def admin_cdn_base_conf_views(request, user_id): """管理员配置cdn基础信息配置页面""" edit_user = UserProfile.objects.filter(id=user_id).first() username = edit_user.username body = { 'username_list': [username] } res = APIUrl.post_link('user_query', body) user_query = res.get('user_query', {}) edit_user.opt_name = [] edit_user.template_name = '' edit_user.cc_icp_check = False try: cdn_opt = user_query[username]['cdn_opt'] cc_cms_template_type = user_query[username]['cc_cms_template_type'] cc_cms_template_type = int(cc_cms_template_type) cc_icp_check = user_query[username]['cc_icp_check'] opt_name = [] for i in cdn_opt: for j in CDNConf.OPT_CONF: if j['id'] == i: opt_name.append(j['name']) template_name = '' for i in CDNConf.CMS_ANA_TEMPLATE: if i['id'] == cc_cms_template_type: template_name = i['name'] break edit_user.cc_cms_template_type = cc_cms_template_type edit_user.opt_name = opt_name edit_user.template_name = template_name edit_user.cc_icp_check = True if cc_icp_check else False except Exception as e: print(e) print(edit_user.opt_name) print(edit_user.template_name) print(edit_user.cc_icp_check) res = { 'edit_user': edit_user, 'opt_conf': CDNConf.OPT_CONF, 'cms_ana_template': CDNConf.CMS_ANA_TEMPLATE } return render(request, 'cdn/admin_cdn_base_conf.html', res)
def admin_cdn_domain_active(request): """管理员域名激活""" msg = '' status = False res = {'status': status, 'msg': msg} user = request.user user_id = request.POST.get('user_id', '') domain_list = request.POST.get('domain', '[]') # user_id = 93 # domain = '[itestxz0018.chinacache.com]' domain_list = json.loads(domain_list) try: user_id = int_check(user_id) if user_id is None: msg = af.PARAME_ERROR assert False edit_user = UserProfile.objects.filter(id=user_id).first() body = { 'domain': domain_list, 'user_id': user_id, } api_res = APIUrl.post_link('cdn_domain_active', body) assert api_res return_code = api_res.get('return_code', 0) if return_code != 0: assert False status = True domain_str = ','.join(domain_list) log_msg = om.ACTIVE_CDN_DOMAIN % (user.username, edit_user.username, domain_str) OperateLog.write_operate_log(request, om.ACCOUNTS, log_msg) except Exception as e: print(e) res['msg'] = _(msg) res['status'] = status return json_response(res)
def user_get_log_detail(request): """父账号查看日志详情""" msg = '' status = False res = { 'status': status, 'msg': msg } provider = 'QINGSONG' domain_id = request.POST.get('domain_id', '') log_id = request.POST.get('log_id', 0) log_time = request.POST.get('log_time', '') try: domain_obj = Domain.objects.filter(id=domain_id).first() if not domain_obj: msg = af.DOMAIN_NOT_EXIST assert False log_id = int_check(log_id) if log_id is None: msg = af.PARAME_ERROR assert False body = { 'channel': '%s://%s' % (domain_obj.protocol, domain_obj.domain), 'log_id': log_id, 'log_time': log_time } api_res = APIUrl.post_link('waf_log_detail', body) if api_res[provider]['return_code'] == 0: api_res = api_res[provider] status = True detail_data = api_res.get('data', {}) res['detail_data'] = detail_data except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)
def client_cdn_get_cert(request): """客户端获取证书列表""" msg = '' status = False res = {'status': status, 'msg': msg} user_id = request.POST.get('user_id', '') # user_id = 93 try: user_id = int_check(user_id) if user_id is None: msg = af.PARAME_ERROR assert False body = {'user_id': user_id, 'status': [CertConf.CERT_SUCCESS]} api_res = APIUrl.post_link('ssl_cert_query', body) return_code = api_res.get('return_code', 0) if return_code != 0: assert False cert_list = api_res.get('cert_list', []) result_list = [] for i in cert_list: cert_dict = { 'create_time': i.get('create_time', ''), 'cert_name': i.get('cert_name', ''), 'issued_to': i.get('issued_to', '') } result_list.append(cert_dict) result_list = sorted(result_list, key=lambda x: x['create_time'], reverse=True) res['cert_list'] = result_list status = True except Exception as e: print(e) res['msg'] = _(msg) res['status'] = status return json_response(res)
def user_domain_refresh_status(request, user): """用户刷新查询""" start_time = request.POST.get('start_time', 0) end_time = request.POST.get('end_time', 0) url = request.POST.get('url', '') refresh_type = request.POST.get('refresh_type', '') refresh_status = request.POST.get('refresh_status', '') msg = '' result_list = [] pagination = {} try: start_time = int_check(start_time) if start_time is None: msg = af.PARAME_ERROR assert False end_time = int_check(end_time) if end_time is None: msg = af.PARAME_ERROR assert False body = { 'username': user.username, 'start_time': start_time, 'end_time': end_time, 'url': url, 'type': refresh_type, 'status': refresh_status, } api_res = APIUrl.post_link('cdn_domain_refresh_status', body) return_code = api_res.get('return_code', 0) if return_code != 0: assert False result_list = api_res.get('result_list', []) check_msg, result_list, pagination = data_pagination( request, result_list) if check_msg: msg = check_msg assert False except AssertionError: pass return msg, result_list, pagination
def client_statistics_views(request): """客户端统计""" user_list = [] user = request.user cdn_user = [user] body = { 'username_list': [user.username], } res = APIUrl.post_link('user_query', body) user_query = res.get('user_query', {}) for u in cdn_user: username = u.username domain_query = Domain.objects.filter(user=u) user_info = user_query.get(username, {}) if not user_info: continue cdn_opt = user_info.get('cdn_opt', []) check_domain = [] domain_list = [] for i in domain_query: domain_dict = { 'id': i.id, 'domain': i.domain, } if i.domain not in check_domain: domain_list.append(domain_dict) check_domain.append(i.domain) user_dict = { 'id': u.id, 'username': u.username, 'domain_list': domain_list, 'cdn_opt': cdn_opt } user_list.append(user_dict) res = { 'user_list': user_list, } return render(request, 'cdn/admin_statistics.html', res)
def user_reset_default_rule(request): msg = '' status = False res = { 'status': status, 'msg': msg } provider = 'QINGSONG' domain_id = request.POST.get('domain_id', '') enable = request.POST.get('enable', 0) try: domain_obj = Domain.objects.filter(id=domain_id).first() if not domain_obj: msg = af.DOMAIN_NOT_EXIST assert False body = { 'channel': '%s://%s' % (domain_obj.protocol, domain_obj.domain), } enable = int_check(enable) if enable is None: msg = af.PARAME_ERROR assert False body['enable'] = enable api_res = APIUrl.post_link('reset_default_rule', body) if api_res[provider]['return_code'] == 0: status = True opt_msg = '全部开启' if enable else '全部关闭' log_msg = om.RESET_DEFAULT_RULE % ( request.user.username, domain_obj.domain, opt_msg) OperateLog.write_operate_log(request, om.SECURITY, log_msg) except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)
def set_user_api_remove(user): """用户设置api状态""" msg = '' try: body = { 'username': user.username, } api_res = APIUrl.post_link('set_api_remove', body) result = api_res.get('return_code', 0) if result != 0: msg = af.SEND_ERROR assert False except AssertionError: pass return msg
def user_domain_refresh(request, user): """用户刷新""" print(request.POST) urls = request.POST.get('urls', '[]') dirs = request.POST.get('dirs', '[]') user_id = user.id body = { 'user_id': user_id, } msg = '' try: urls = handle_list(urls) if urls: urls = detect_domain(user_id, urls) if not urls: msg = af.URL_FORMAT_ERROR assert False body['urls'] = urls dirs = handle_list(dirs) if dirs: dirs = detect_domain(user_id, dirs) if not dirs: msg = af.URL_FORMAT_ERROR assert False body['dirs'] = dirs api_res = APIUrl.post_link('cdn_domain_refresh', body) return_code = api_res.get('return_code', 0) if return_code != 0: msg = af.SEND_ERROR assert False except AssertionError: pass return msg
def admin_set_user_strategy_conf(request): """管理员绑定设置用户三方平台基础信息""" msg = '' status = False res = {'status': status, 'msg': msg} username = request.POST.get('username', '') provider = request.POST.get('provider', 'QINGSONG') product = request.POST.get('product', 'SECURITY') service = request.POST.get('service', 'WAF') value = request.POST.get('value', sf.BASE_TOKEN) try: user = UserProfile.objects.filter(username=username).first() if not user: msg = af.USER_NOT_EXIST assert False strategy = Strategy.get_obj_from_property(provider, product, service) key = strategy.code.lower() body = { 'user_id': user.id, 'username': username, 'fields': { key: value }, } res = APIUrl.post_link('update_user', body) return_code = res.get('return_code', 0) if return_code != 0: assert False status = True except AssertionError: res['msg'] = _(msg) res['status'] = status return json_response(res)