def idc_list(request): """ IDC list view """ header_title, path1, path2 = '查看IDC', '资产管理', '查看IDC' posts = IDC.objects.all() keyword = request.GET.get('keyword', '') if keyword: posts = IDC.objects.filter( Q(name__contains=keyword) | Q(comment__contains=keyword)) else: posts = IDC.objects.exclude(name='ALL').order_by('id') contact_list, p, contacts, page_range, current_page, show_first, show_end = pages( posts, request) return my_render('jasset/idc_list.html', locals(), request)
def user_list(request): header_title, path1, path2 = u'查看用户', u'用户管理', u'编辑用户组' user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'} keyword = request.GET.get('keyword', '') gid = request.GET.get('gid', '') users_list = User.objects.all().order_by('name') if gid: user_group = UserGroup.objects.filter(id=gid) if user_group: user_group = user_group.first() users_list = user_group.user_set.all() if keyword: users_list = users_list.filter(Q(name__icontains=keyword)).order_by('name') users_list, p, users, page_range, current_page, show_first, show_end = pages(users_list, request) return render(request, 'juser/user_list.html', context=locals())
def perm_sudo_list(request): """ list sudo commands alias :param request: :return: """ # 渲染数据 header_title, path1, path2 = "Sudo命令", "别名管理", "查看别名" # 获取所有sudo 命令别名 sudos_list = PermSudo.objects.all() # TODO: 搜索和分页 keyword = request.GET.get('search', '') if keyword: sudos_list = sudos_list.filter(Q(name=keyword)) sudos_list, p, sudos, page_range, current_page, show_first, show_end = pages( sudos_list, request) return my_render('jperm/perm_sudo_list.html', locals(), request)
def user_list(request): user_role = {'SU': '超级管理员', 'GA': '组管理员', 'CU': '普通用户'} header_title, path1, path2 = '查看用户', '用户管理', '用户列表' keyword = request.GET.get('keyword', '') gid = request.GET.get('gid', '') users_list = User.objects.all().order_by('username') if gid: user_group = UserGroup.objects.filter(id=gid) if user_group: user_group = user_group[0] users_list = user_group.user_set.all() if keyword: users_list = users_list.filter( Q(username__icontains=keyword) | Q(name__icontains=keyword)).order_by('username') users_list, p, users, page_range, current_page, show_first, show_end = pages( users_list, request) return my_render('juser/user_list.html', locals(), request)
def perm_role_list(request): """ list role page """ # 渲染数据 header_title, path1, path2 = "系统用户", "系统用户管理", "查看系统用户" # 获取所有系统角色 roles_list = PermRole.objects.all() role_id = request.GET.get('id') # TODO: 搜索和分页 keyword = request.GET.get('search', '') if keyword: roles_list = roles_list.filter(Q(name=keyword)) if role_id: roles_list = roles_list.filter(id=role_id) roles_list, p, roles, page_range, current_page, show_first, show_end = pages( roles_list, request) return my_render('jperm/perm_role_list.html', locals(), request)
def perm_rule_list(request): """ list rule page 授权规则列表 """ # 渲染数据 header_title, path1, path2 = "授权规则", "规则管理", "查看规则" # 获取所有规则 rules_list = PermRule.objects.all() rule_id = request.GET.get('id') # TODO: 搜索和分页 keyword = request.GET.get('search', '') if rule_id: rules_list = rules_list.filter(id=rule_id) if keyword: rules_list = rules_list.filter(Q(name__icontains=keyword)) rules_list, p, rules, page_range, current_page, show_first, show_end = pages( rules_list, request) return my_render('jperm/perm_rule_list.html', locals(), request)
def group_list(request): """ list user group 用户组列表 """ header_title, path1, path2 = '查看用户组', '用户管理', '查看用户组' keyword = request.GET.get('search', '') user_group_list = UserGroup.objects.all().order_by('name') group_id = request.GET.get('id', '') if keyword: user_group_list = user_group_list.filter( Q(name__icontains=keyword) | Q(comment__icontains=keyword)) if group_id: user_group_list = user_group_list.filter(id=int(group_id)) user_group_list, p, user_groups, page_range, current_page, show_first, show_end = pages( user_group_list, request) return my_render('juser/group_list.html', locals(), request)
def asset_list(request): """ asset list view """ user_assets = Rule(request.user) header_title, path1, path2 = u'查看资产', u'资产管理', u'查看资产' username = request.user.username user_perm = request.session['role_id'] idc_all = [] asset_group_all = user_assets.asset_group asset_types = "server" asset_status = "active" idc_name = request.GET.get('idc', '') group_name = request.GET.get('group', '') asset_type = request.GET.get('asset_type', '') status = request.GET.get('status', '') keyword = request.GET.get('keyword', '') export = request.GET.get("export", False) group_id = request.GET.get("group_id", '') idc_id = request.GET.get("idc_id", '') asset_id_all = request.GET.getlist("id", '') asset_find = user_assets.assets if group_id: group_id = int(group_id) for x in user_assets.asset_group: if x.id == group_id: asset_find = x.asset_set if idc_id: pass if idc_name: asset_find = asset_find.filter(idc__name__contains=idc_name) if group_name: for x in user_assets.asset_group: if x.name == group_name: asset_find = x.asset_set if asset_type: asset_find = asset_find.filter(asset_type__contains=asset_type) if status: asset_find = asset_find.filter(status__contains=status) if keyword: asset_find = [ asset for asset in asset_find if keyword in asset.ip or keyword in asset.hostname or keyword in asset.role or keyword in asset.comment or keyword in asset.group ] if export: if asset_id_all: asset_find = [] for asset in user.assets: if asset: asset_find.append(asset) s = write_excel(asset_find) if s[0]: file_name = s[1] smg = u'excel文件已生成,请点击下载!' return my_render('jasset/asset_excel_download.html', locals(), request) assets_list, p, assets, page_range, current_page, show_first, show_end = pages( asset_find, request) if user_perm != 0: return my_render('jasset/asset_list.html', locals(), request) else: return my_render('jasset/asset_cu_list.html', locals(), request)
def group_list(request): """ list asset group 列出资产组 """ header_title, path1, path2 = u'查看资产组', u'资产管理', u'查看资产组' keyword = request.GET.get('keyword', '') user_assets = Rule(request.user) asset_group_list = user_assets.asset_group group_id = request.GET.get('id') if group_id: group_id = int(group_id) asset_group_list = [ x for x in user_assets.asset_group if x.id == group_id ] if keyword: asset_group_list = [ x for x in user_assets.asset_group if keyword in x.name ] asset_group_list, p, asset_groups, page_range, current_page, show_first, show_end = pages( asset_group_list, request) return my_render('jasset/group_list.html', locals(), request)
def log_list(request, offset): """ 显示日志 """ header_title, path1 = '审计', '操作审计' date_seven_day = request.GET.get('start', '') date_now_str = request.GET.get('end', '') username_list = request.GET.getlist('username', []) host_list = request.GET.getlist('host', []) cmd = request.GET.get('cmd', '') if offset == 'online': keyword = request.GET.get('keyword', '') posts = Log.objects.filter(is_finished=False).order_by('-start_time') if keyword: posts = posts.filter( Q(user__icontains=keyword) | Q(host__icontains=keyword) | Q(login_type__icontains=keyword)) elif offset == 'exec': posts = ExecLog.objects.all().order_by('-id') keyword = request.GET.get('keyword', '') if keyword: posts = posts.filter( Q(user__icontains=keyword) | Q(host__icontains=keyword) | Q(cmd__icontains=keyword)) elif offset == 'file': posts = FileLog.objects.all().order_by('-id') keyword = request.GET.get('keyword', '') if keyword: posts = posts.filter( Q(user__icontains=keyword) | Q(host__icontains=keyword) | Q(filename__icontains=keyword)) else: posts = Log.objects.filter(is_finished=True).order_by('-start_time') username_all = set([log.user for log in Log.objects.all()]) ip_all = set([log.host for log in Log.objects.all()]) if date_seven_day and date_now_str: datetime_start = datetime.datetime.strptime( date_seven_day + ' 00:00:01', '%m/%d/%Y %H:%M:%S') datetime_end = datetime.datetime.strptime( date_now_str + ' 23:59:59', '%m/%d/%Y %H:%M:%S') posts = posts.filter(start_time__gte=datetime_start).filter( start_time__lte=datetime_end) if username_list: posts = posts.filter(user__in=username_list) if host_list: posts = posts.filter(host__in=host_list) if cmd: log_id_list = set([ log.log_id for log in TtyLog.objects.filter(cmd__contains=cmd) ]) posts = posts.filter(id__in=log_id_list) if not date_seven_day: date_now = datetime.datetime.now() date_now_str = date_now.strftime('%m/%d/%Y') date_seven_day = (date_now + datetime.timedelta(days=-7)).strftime('%m/%d/%Y') contact_list, p, contacts, page_range, current_page, show_first, show_end = pages( posts, request) session_id = request.session.session_key return render(request, 'jlog/log_%s.html' % offset, locals())
def group_list(request): header_title, path1, path2 = u'查看用户组', u'用户管理', u'查看用户组' keyword = request.GET.get('search', '') user_group_list = UserGroup.objects.all().order_by('name') group_id = request.GET.get('id','') if keyword: user_group_list = user_group_list.filter(Q(name__icontains=keyword) | Q(comment__icontains=keyword)) if group_id: user_group_list = user_group_list.filter(id=int(group_id)) user_group_list, p, user_groups, page_range, current_page, show_first, show_end = pages(user_group_list, request) return render(request, 'juser/group_list.html', context=locals())
def group_list(request): """ list asset group 列出资产组 """ header_title, path1, path2 = '查看资产组', '资产管理', '查看资产组' keyword = request.GET.get('keyword', '') asset_group_list = AssetGroup.objects.all() group_id = request.GET.get('id') if group_id: asset_group_list = asset_group_list.filter(id=group_id) if keyword: asset_group_list = asset_group_list.filter( Q(name__contains=keyword) | Q(comment__contains=keyword)) asset_group_list, p, asset_groups, page_range, current_page, show_first, show_end = pages( asset_group_list, request) return my_render('jasset/group_list.html', locals(), request)
def asset_list(request): """ asset list view """ header_title, path1, path2 = '查看资产', '资产管理', '查看资产' username = request.user.username user_perm = request.session['role_id'] idc_all = IDC.objects.filter() asset_group_all = AssetGroup.objects.all() asset_types = ASSET_TYPE asset_status = ASSET_STATUS idc_name = request.GET.get('idc', '') group_name = request.GET.get('group', '') asset_type = request.GET.get('asset_type', '') status = request.GET.get('status', '') keyword = request.GET.get('keyword', '') export = request.GET.get("export", False) group_id = request.GET.get("group_id", '') idc_id = request.GET.get("idc_id", '') asset_id_all = request.GET.getlist("id", '') if group_id: group = get_object(AssetGroup, id=group_id) if group: asset_find = Asset.objects.filter(group=group) elif idc_id: idc = get_object(IDC, id=idc_id) if idc: asset_find = Asset.objects.filter(idc=idc) else: if user_perm != 0: asset_find = Asset.objects.all() else: asset_id_all = [] asset_find = get_assets_by_username(username) user = get_object(User, username=username) asset_perm = get_group_user_perm(user) if user else {'asset': ''} asset_group_all = list(asset_perm['asset_group']) if idc_name: asset_find = asset_find.filter(idc__name__contains=idc_name) if group_name: asset_find = asset_find.filter(group__name__contains=group_name) if asset_type: asset_find = asset_find.filter(asset_type__contains=asset_type) if status: asset_find = asset_find.filter(status__contains=status) if keyword: asset_find = asset_find.filter( Q(hostname__contains=keyword) | Q(other_ip__contains=keyword) | Q(ip__contains=keyword) | Q(remote_ip__contains=keyword) | Q(comment__contains=keyword) | Q(username__contains=keyword) | Q(group__name__contains=keyword) | Q(cpu__contains=keyword) | Q(memory__contains=keyword) | Q(disk__contains=keyword) | Q(brand__contains=keyword) | Q(cabinet__contains=keyword) | Q(sn__contains=keyword) | Q(system_type__contains=keyword) | Q(system_version__contains=keyword)) if export: if asset_id_all: asset_find = [] for asset_id in asset_id_all: asset = get_object(Asset, id=asset_id) if asset: asset_find.append(asset) s = write_excel(asset_find) if s[0]: file_name = s[1] smg = 'excel文件已生成,请点击下载!' return my_render('jasset/asset_excel_download.html', locals(), request) assets_list, p, assets, page_range, current_page, show_first, show_end = pages( asset_find, request) if user_perm != 0: return my_render('jasset/asset_list.html', locals(), request) else: return my_render('jasset/asset_cu_list.html', locals(), request)