def configs(request, **kwargs): my_auth = MyBasicAuthentication() is_login = my_auth.is_authenticated(request, **kwargs) if is_login: visit_permit = BackendRequest.can_visit({ "token": is_login['t'], "operator": is_login['u'], "requestUrl": request.path[1:] }) if visit_permit['result'] and visit_permit['can_visit']: with_sg = 'no' sg_param = { 'account': is_login['i'], 'token': is_login['t'], 'operator': is_login['u'] } sg_res = BackendRequest.get_source_group(sg_param) if sg_res['result']: item = sg_res.get('items', []) if item: with_sg = 'yes' cf_per = check_with_permission(is_login) page_data = {"active": "source", "subnav": "configs", "user": is_login["u"], "email": is_login["e"], "role": is_login["r"], "userid": is_login["i"], "with_sg": with_sg, "cf_per": cf_per, "rgid": request.GET.get("rgid", "") } return render(request, 'extract/list.html', {"page_data": json.dumps(page_data)}) else: raise PermissionDenied else: return HttpResponseRedirect('/auth/login/')
def download(request, **kwargs): my_auth = MyBasicAuthentication() is_login = my_auth.is_authenticated(request, **kwargs) if is_login: with_sg = 'no' config_permission = "no" sg_param = { 'account': is_login['i'], 'token': is_login['t'], 'operator': is_login['u'] } sg_res = BackendRequest.get_source_group(sg_param) if sg_res['result']: item = sg_res.get('items', []) if item: with_sg = 'yes' func_auth_res = BackendRequest.get_func_auth({'token': is_login['t']}) if func_auth_res['result']: if func_auth_res["results"]["parser_conf"]: config_permission = "yes" return render( request, 'download/download.html', { "active": "download", "subnav": "download", "user": is_login["u"], "email": is_login["e"], "cf_per": config_permission, "role": is_login["r"], "userid": is_login["i"], "with_sg": with_sg, "rgid": request.GET.get('rgid', "") }) else: return HttpResponseRedirect('/auth/login/')
def check_with_sourcegroup(login): with_sg = 'no' if login['r'] == "user": sg_param = {'account': login['i'], 'token': login['t']} sg_res = BackendRequest.get_source_group(sg_param) if sg_res['result']: item = sg_res.get('items', []) if item: with_sg = 'yes' return with_sg
def source_sourcegroups_update(request, offset, **kwargs): source_group_name = offset my_auth = MyBasicAuthentication() is_login = my_auth.is_authenticated(request, **kwargs) if is_login: visit_permit = BackendRequest.can_visit({ "token": is_login['t'], "operator": is_login['u'], "requestUrl": request.path[1:] }) if visit_permit['result'] and visit_permit['can_visit']: sourcegroup = { "id": "", "name": source_group_name, "description": "", "host": "", "application": "", "tag": "" } res = BackendRequest.get_source_group({ "token": is_login["t"], "name": source_group_name, "operator": is_login["u"] }) if res["result"]: a_sg = res["items"][0] sourcegroup["id"] = a_sg.get("id", "").encode('utf-8') sourcegroup["name"] = a_sg.get("name", "").encode('UTF-8') sourcegroup["description"] = a_sg.get("description", "").encode('utf-8') sourcegroup["host"] = a_sg.get("hostname", "").encode('utf-8') sourcegroup["application"] = a_sg.get("appname", "").encode('utf-8') sourcegroup["tag"] = a_sg.get("tag", "").encode('utf-8') with_sg = check_with_sourcegroup(is_login) cf_per = check_with_permission(is_login) page_data = { "sourcegroup": sourcegroup, "active": "source", "subnav": "sourcegroups", "email": is_login["e"], "user": is_login["u"], "userid": is_login["i"], "role": is_login["r"], "with_sg": with_sg, "cf_per": cf_per } return render(request, 'source/sourcegroups-new.html', {"page_data": json.dumps(page_data)}) else: raise PermissionDenied else: return HttpResponseRedirect('/auth/login/')
def sourcegroups_delete(self, request, **kwargs): self.method_check(request, allowed=['post']) source_group_id = kwargs["sgid"] dummy_data = {} my_auth = MyBasicAuthentication() es_check = my_auth.is_authenticated(request, **kwargs) if es_check: res = BackendRequest.delete_source_group({ "token": es_check["t"], "id": source_group_id, 'operator': es_check['u'] }) if res["result"]: res_list = BackendRequest.get_source_group({ "token": es_check["t"], "id": source_group_id, 'operator': es_check['u'] }) source_group = [] if res_list['result']: for i in res_list['items']: group_list = filter(lambda x: not x == '' and x is not None, i.get('user_groups', [])) source_group.append({ 'sourcegroup_id': i['id'].encode('utf-8'), 'sGroup': i['name'].encode('utf-8'), "description": i.get('description', "").encode('utf-8'), "activity": [], "created": i.get('owner_name', "").encode('utf-8'), "edit": i.get('edit', "false").encode('utf-8'), "contents": i.get('contents', "").encode('utf-8'), "restricted": ','.join(group_list) }) dummy_data["status"] = "1" dummy_data["totle"] = len(source_group) dummy_data["list"] = source_group else: dummy_data = err_data.build_error(res) else: data = err_data.build_error({}, "auth error!") data["location"] = "/auth/login/" dummy_data = data bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request) response_data = bundle resp = self.create_response(request, response_data) return resp
def lists(request, **kwargs): my_auth = MyBasicAuthentication() is_login = my_auth.is_authenticated(request, **kwargs) if is_login: visit_permit = BackendRequest.can_visit({ "token": is_login['t'], "operator": is_login['u'], "requestUrl": request.path[1:] }) if visit_permit['result'] and visit_permit['can_visit']: with_sg = 'no' config_permission = "no" sg_param = { 'account': is_login['i'], 'token': is_login['t'], 'operator': is_login['u'] } sg_res = BackendRequest.get_source_group(sg_param) if sg_res['result']: item = sg_res.get('items', []) if item: with_sg = 'yes' func_auth_res = BackendRequest.get_func_auth( {'token': is_login['t']}) if func_auth_res['result']: if func_auth_res["results"]["parser_conf"]: config_permission = "yes" page_data = { "active": "dictionary", "subnav": "dictionary", "user": is_login["u"], "email": is_login["e"], "cf_per": config_permission, "role": is_login["r"], "userid": is_login["i"], "with_sg": with_sg, "rgid": request.GET.get('rgid', "") } return render(request, 'dictionary/list.html', {"page_data": json.dumps(page_data)}) else: raise PermissionDenied else: return HttpResponseRedirect('/auth/login/')
def search(request, **kwargs): my_auth = MyBasicAuthentication() is_login = my_auth.is_authenticated(request, **kwargs) if is_login: visit_permit = BackendRequest.can_visit({ "token": is_login['t'], "operator": is_login['u'], "requestUrl": request.path[1:] }) if visit_permit['result'] and visit_permit['can_visit']: with_sg = 'no' sg_param = { 'account': is_login['i'], 'token': is_login['t'], 'operator': is_login['u'] } sg_res = BackendRequest.get_source_group(sg_param) if sg_res['result']: item = sg_res.get('items', []) if item: with_sg = 'yes' page_data = { "active": "search", "user": is_login["u"], "email": is_login["e"], "role": is_login["r"], "userid": is_login["i"], "timeline_color": timeline_color, "syslog": syslog, "with_sg": with_sg, "fields_limit": fields_limit, 'ri': is_login["ri"], 'loading_auto_search': loading_auto_search, 'auto_search': auto_search } return render(request, 'search/search.html', {"page_data": json.dumps(page_data)}) else: raise PermissionDenied else: return HttpResponseRedirect('/auth/login/')
def sourcegroups_list_simple(self, request, **kwargs): self.method_check(request, allowed=['get']) my_auth = MyBasicAuthentication() es_check = my_auth.is_authenticated(request, **kwargs) data = [ {"id": "11", "name": "Moroni"}, {"id": "12", "name": "测试"}, {"id": "13", "name": "dd"}, {"id": "14", "name": "bb"} ] dummy_data = {} if es_check: res = BackendRequest.get_source_group({ "token": es_check["t"], 'operator': es_check['u'] }) source_group = [] if res['result']: for i in res['items']: source_group.append({ 'id': i['id'].encode('utf-8'), 'name': i['name'].encode('utf-8') }) else: dummy_data = err_data.build_error(res) dummy_data["status"] = "1" dummy_data["totle"] = len(source_group) dummy_data["list"] = source_group else: data = err_data.build_error({}, "auth error!") data["location"] = "/auth/login/" dummy_data = data bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request) response_data = bundle resp = self.create_response(request, response_data) return resp
def sourcegroups_list(self, request, **kwargs): ''' {"sourcegroup_id": "11", "sGroup": "Moroni", "description": "afdds", "contents": "fff", "created": "wangqiushi", "activity": [12, 23, 12, 14, 53, 24, 45, 2, 4, 5, 3, 55], "restricted": "aa", "edit": "false"} :param request: :param kwargs: :return: ''' self.method_check(request, allowed=['get']) dummy_data = {} my_auth = MyBasicAuthentication() es_check = my_auth.is_authenticated(request, **kwargs) if es_check: source_group = [] permits = [] res = BackendRequest.get_source_group({ "token": es_check["t"], 'operator': es_check['u'] }) if res['result']: for i in res['items']: group_list = filter(lambda x: not x == '' and x is not None, i.get('user_groups', [])) source_group.append({ 'sourcegroup_id': i['id'].encode('utf-8'), 'sGroup': i['name'].encode('utf-8'), "description": i.get('description', "").encode('utf-8'), "activity": [], "created": i.get('owner_name', "").encode('utf-8'), "edit": i.get('edit', "false").encode('utf-8'), "contents": i.get('contents', "").encode('utf-8'), "restricted": ','.join(group_list) }) permits.append({ "resource_id": int(i['id']), "target": "SourceGroup", "action": "Update" }) permits.append({ "resource_id": int(i['id']), "target": "SourceGroup", "action": "Delete" }) permits.append({ "target": "SourceGroup", "action": "Create" }) permits.append({ "target": "DerelictResource", "action": "Possess" }) dummy_data["status"] = "1" dummy_data["totle"] = len(source_group) dummy_data["list"] = source_group param = { 'token': es_check['t'], 'operator': es_check['u'] } permit_param = { 'permits': permits } permit_res = BackendRequest.batch_permit_can(param, permit_param) if permit_res['result']: dummy_data["permit_list"] = permit_res["short_permits"] else: dummy_data["permit_list"] = [] else: dummy_data = err_data.build_error(res) else: data = err_data.build_error({}, "auth error!") data["location"] = "/auth/login/" dummy_data = data bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request) response_data = bundle resp = self.create_response(request, response_data) return resp