def get(self, request): user = request.user # ss node ss_node_list = [ node.to_dict_with_extra_info(user) for node in SSNode.get_active_nodes() ] # vmess node vmess_node_list = [ node.to_dict_with_extra_info(user) for node in VmessNode.get_active_nodes() ] # trojan node trojan_node_list = [ node.to_dict_with_extra_info(user) for node in TrojanNode.get_active_nodes() ] context = { "ss_node_list": ss_node_list, "vmess_node_list": vmess_node_list, "trojan_node_list": trojan_node_list, "user": user, } Announcement.send_first_visit_msg(request) return render(request, "sspanel/nodeinfo.html", context=context)
def get(self, request): user_status = [ NodeOnlineLog.get_all_node_online_user_count(), User.get_today_register_user().count(), UserCheckInLog.get_today_checkin_user_count(), User.get_never_used_user_count(), ] donate_status = [ Donate.get_donate_count_by_date(), Donate.get_donate_money_by_date(), Donate.get_donate_count_by_date(date=pendulum.today()), Donate.get_donate_money_by_date(date=pendulum.today()), ] active_nodes = SSNode.get_active_nodes() + VmessNode.get_active_nodes() node_status = { "names": [node.name for node in active_nodes], "traffics": [ round(node.used_traffic / settings.GB, 2) for node in active_nodes ], } data = { "user_status": user_status, "donate_status": donate_status, "node_status": node_status, } return JsonResponse(data)
def get(self, request): user = request.user user_ss_config = user.user_ss_config configs = [ node.to_dict_with_user_ss_config(user_ss_config) for node in SSNode.get_user_active_nodes(user) ] return JsonResponse({"configs": configs})
def get(self, request, node_id): node_type = self.request.GET.get("node_type") if node_type == "ss": node = SSNode.get_or_none_by_node_id(node_id) else: node = VmessNode.get_or_none_by_node_id(node_id) if not node: return HttpResponseNotFound() return JsonResponse(node.get_ehco_server_config())
def get(self, request): data = [] for node in SSNode.get_active_nodes(): data.extend(UserOnLineIpLog.get_recent_log_by_node_id( node.node_id)) context = PageListView(request, data).get_page_context() return render(request, "my_admin/user_online_ip_log.html", context=context)
def get(self, request): ss_node_list = SSNode.get_active_nodes() vmess_node_list = VmessNode.get_active_nodes() context = { "user": request.user, "ss_node_list": ss_node_list, "vmess_node_list": vmess_node_list, } return render(request, "sspanel/user_traffic_log.html", context=context)
def get(self, request): user = request.user user_ss_config = user.user_ss_config node_list = [ node.to_dict_with_extra_info(user_ss_config) for node in SSNode.get_active_nodes() ] context = { "node_list": node_list, "user": user, "sub_link": user.sub_link } return render(request, "sspanel/nodeinfo.html", context=context)
def get(self, request): user = request.user user_ss_config = user.user_ss_config # ss node ss_node_list = [ node.to_dict_with_extra_info(user_ss_config) for node in SSNode.get_active_nodes() ] # vmess node vmess_node_list = [ node.to_dict_with_extra_info(user) for node in VmessNode.get_active_nodes() ] context = { "ss_node_list": ss_node_list, "vmess_node_list": vmess_node_list, "user": user, "sub_link": user.sub_link, } Announcement.send_first_visit_msg(request) return render(request, "sspanel/nodeinfo.html", context=context)
def post(self, request, node_id): """ 这个接口操作比较重,所以为了避免发信号 所有写操作都需要用BULK的方式 1 更新节点流量 2 更新用户流量 3 记录节点在线IP 4 关闭超出流量的节点 """ ss_node = SSNode.get_or_none_by_node_id(node_id) if not ss_node: return HttpResponseNotFound() data = request.json["data"] node_total_traffic = 0 log_time = get_current_datetime() active_tcp_connections = 0 need_clear_cache = False user_model_list = [] trafficlog_model_list = [] online_ip_log_model_list = [] for user_data in data: user_id = user_data["user_id"] u = int(user_data["upload_traffic"] * ss_node.enlarge_scale) d = int(user_data["download_traffic"] * ss_node.enlarge_scale) # 个人流量增量 user = User.get_by_pk(user_id) user.download_traffic += d user.upload_traffic += u user.last_use_time = log_time user_model_list.append(user) if user.overflow: need_clear_cache = True # 个人流量记录 trafficlog_model_list.append( UserTrafficLog( node_type=UserTrafficLog.NODE_TYPE_SS, node_id=node_id, user_id=user_id, download_traffic=u, upload_traffic=d, ) ) # 节点流量增量 node_total_traffic += u + d # active_tcp_connections active_tcp_connections += user_data["tcp_conn_num"] # online ip log for ip in user_data.get("ip_list", []): online_ip_log_model_list.append( UserOnLineIpLog(user_id=user_id, node_id=node_id, ip=ip) ) # 用户流量 User.objects.bulk_update( user_model_list, ["download_traffic", "upload_traffic", "last_use_time"], ) # 节点流量记录 SSNode.increase_used_traffic(node_id, node_total_traffic) # 流量记录 UserTrafficLog.objects.bulk_create(trafficlog_model_list) # 在线IP UserOnLineIpLog.objects.bulk_create(online_ip_log_model_list) # 节点在线人数 NodeOnlineLog.add_log( NodeOnlineLog.NODE_TYPE_SS, node_id, len(data), active_tcp_connections ) # check node && user traffic if ss_node.overflow: ss_node.enable = False if need_clear_cache or ss_node.overflow: ss_node.save() return JsonResponse(data={})
def get(self, request, node_id): configs = SSNode.get_user_ss_configs_by_node_id(node_id) return JsonResponse(configs)
def post(self, request, node_id): node = SSNode.get_or_none_by_node_id(node_id) if not node: return HttpResponseNotFound() tasks.sync_user_ss_traffic_task.delay(node_id, request.json["data"]) return JsonResponse(data={})
def get(self, request, node_id): ss_node = SSNode.get_or_none_by_node_id(node_id) node_id and ss_node.delete() messages.success(request, "成功啦", extra_tags="删除节点") return HttpResponseRedirect(reverse("sspanel:backend_ss_node_list"))
def post(self, request, node_id): """ 这个接口操作比较重,所以为了避免发信号 所有写操作都需要用BULK的方式 1 更新节点流量 2 更新用户流量 3 记录节点在线IP 4 关闭超出流量的用户 5 关闭超出流量的节点 """ data = request.json["data"] log_time = pendulum.now() node_total_traffic = 0 trafficlog_model_list = [] user_traffic_model_list = [] online_ip_log_model_list = [] user_ss_config_model_list = [] for user_data in data: user_id = user_data["user_id"] u = user_data["upload_traffic"] d = user_data["download_traffic"] # 个人流量增量 user_traffic = UserTraffic.get_by_user_id(user_id) user_traffic.download_traffic += d user_traffic.upload_traffic += u user_traffic.last_use_time = log_time user_traffic_model_list.append(user_traffic) if user_traffic.overflow: user_ss_config = UserSSConfig.get_by_user_id(user_id) user_ss_config.enable = False user_ss_config_model_list.append(user_ss_config) # 个人流量记录 trafficlog_model_list.append( UserTrafficLog( node_id=node_id, user_id=user_id, download_traffic=u, upload_traffic=d, ) ) # 节点流量增量 node_total_traffic += u + d # online ip log for ip in user_data.get("ip_list", []): online_ip_log_model_list.append( UserOnLineIpLog(user_id=user_id, node_id=node_id, ip=ip) ) # 节点流量记录 SSNode.increase_used_traffic(node_id, node_total_traffic) # 流量记录 UserTrafficLog.objects.bulk_create(trafficlog_model_list) # 在线IP UserOnLineIpLog.objects.bulk_create(online_ip_log_model_list) # 个人流量记录 UserTraffic.objects.bulk_update( user_traffic_model_list, ["download_traffic", "upload_traffic", "last_use_time"], ) # 用户开关 UserSSConfig.objects.bulk_update(user_ss_config_model_list, ["enable"]) # 节点在线人数 SSNodeOnlineLog.add_log(node_id, len(data)) # check node && user traffic ss_node = SSNode.get_or_none_by_node_id(node_id) if ss_node.overflow: ss_node.enable = False if user_ss_config_model_list or ss_node.overflow: # NOTE save for clear cache ss_node.save() return JsonResponse({"ret": 1, "data": []})