def userData(request): ''' 返回用户信息: 在线人数、今日签到、从未签到、从未使用 ''' data = [NodeOnlineLog.totalOnlineUser(), len(User.todayRegister()), SSUser.userTodyChecked(), SSUser.userNeverChecked(), SSUser.userNeverUsed(), ] return JsonResponse({'data': data})
def userData(request): ''' 返回用户信息: 在线人数、今日签到、从未签到、从未使用 ''' data = [ NodeOnlineLog.totalOnlineUser(), len(User.todayRegister()), SSUser.userTodyChecked(), SSUser.userNeverChecked(), SSUser.userNeverUsed(), ] return JsonResponse({'data': data})
def get_node_user(node_id): ''' 返回所有当前节点可以使用的用户信息 ''' from apps.ssserver.models import Node, SSUser node = Node.objects.filter(node_id=node_id).first() if node: data = [] level = node.level user_list = SSUser.get_vaild_user(level) for user in user_list: cfg = { 'port': user.port, 'u': user.upload_traffic, 'd': user.download_traffic, 'transfer_enable': user.transfer_enable, 'passwd': user.password, 'enable': user.enable, 'id': user.pk, 'method': user.method, 'obfs': user.obfs, 'obfs_param': user.obfs_param, 'protocol': user.protocol, 'protocol_param': user.protocol_param, } data.append(cfg) return data
def user_status(request): '''站内用户分析''' # 查询今日注册的用户 todayRegistered = User.todayRegister().values() for t in todayRegistered: try: t['inviter'] = User.objects.get(pk=t['invited_by']) except: t['inviter'] = 'ehco' todayRegisteredNum = len(todayRegistered) # 查询消费水平前十的用户 richUser = Donate.richPeople() # 查询流量用的最多的用户 coreUser = SSUser.coreUser() context = { 'userNum': User.userNum(), 'todayChecked': SSUser.userTodyChecked(), 'aliveUser': NodeOnlineLog.totalOnlineUser(), 'todayRegistered': todayRegistered[:10], 'todayRegisteredNum': todayRegisteredNum, 'richUser': richUser, 'coreUser': coreUser, } return render(request, 'backend/userstatus.html', context=context)
def change_ss_port(request): ''' 随机重置用户用端口 返回是否成功 ''' user = request.user.ss_user # 找到端口池中最大的端口 port = SSUser.randomPord() user.port = port user.save() registerinfo = { 'title': '修改成功!', 'subtitle': '端口修改为:{}!'.format(port), 'status': 'success', } return JsonResponse(registerinfo)
def change_ss_port(request): ''' 随机重置用户用端口 返回是否成功 ''' user = request.user.ss_user # 找到端口池中最大的端口 port = SSUser.randomPord() user.port = port user.save() registerinfo = { 'title': '修改成功!', 'subtitle': '端口修改为:{}!'.format(port), 'status': 'success', } return JsonResponse(registerinfo)
def traffic_api(request): ''' 接受服务端的用户流量上报 ''' data = request.json node_id = data['node_id'] traffic_list = data['data'] log_time = int(time.time()) node_total_traffic = 0 trafficlog_model_list = [] ssuer_model_list = [] for rec in traffic_list: # 个人流量增量 ssuer_model_list.append( SSUser(pk=rec['user_id'], upload_traffic=(F('upload_traffic') + rec['u']), download_traffic=(F('download_traffic') + rec['d']), last_use_time=log_time)) # 个人流量记录 trafficlog_model_list.append( TrafficLog(node_id=node_id, user_id=rec['user_id'], traffic=traffic_format(rec['u'] + rec['d']), download_traffic=rec['d'], upload_traffic=rec['u'], log_time=log_time)) # 节点流量增量 node_incr = rec['u'] + rec['d'] node_total_traffic += node_incr # 节点流量记录 Node.objects.filter(node_id=node_id).update( used_traffic=F('used_traffic') + node_total_traffic) # 流量记录 TrafficLog.objects.bulk_create(trafficlog_model_list) SSUser.objects.bulk_update( ssuer_model_list, update_fields=['upload_traffic', 'download_traffic', 'last_use_time']) return JsonResponse({'ret': 1, 'data': []})