From 4ea83f60256a21c5c42b690f80fd27b496b10a67 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Fri, 30 Jun 2023 00:26:07 -0400 Subject: [PATCH] allnet: add handler for LoaderStateRecorder --- core/allnet.py | 18 +++++++++++++++++- index.py | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/allnet.py b/core/allnet.py index 8af120b..00303f5 100644 --- a/core/allnet.py +++ b/core/allnet.py @@ -1,4 +1,4 @@ -from typing import Dict, List, Any, Optional, Tuple +from typing import Dict, List, Any, Optional, Tuple, Union import logging, coloredlogs from logging.handlers import TimedRotatingFileHandler from twisted.web.http import Request @@ -241,6 +241,22 @@ class AllnetServlet: ) return b"" + def handle_loaderstaterecorder(self, request: Request, match: Dict) -> bytes: + req_data = request.content.getvalue() + req_dict = self.kvp_to_dict([req_data.decode()])[0] + + serial: Union[str, None] = req_dict.get("serial", None) + num_files_to_dl: Union[str, None] = req_dict.get("nb_ftd", None) + num_files_dld: Union[str, None] = req_dict.get("nb_dld", None) + dl_state: Union[str, None] = req_dict.get("dld_st", None) + ip = Utils.get_ip_addr(request) + + if serial is None or num_files_dld is None or num_files_to_dl is None or dl_state is None: + return "NG".encode() + + self.logger.info(f"LoaderStateRecorder Request from {ip} {serial}: {num_files_dld}/{num_files_to_dl} Files download (State: {dl_state})") + return "OK".encode() + def handle_billing_request(self, request: Request, _: Dict): req_dict = self.billing_req_to_dict(request.content.getvalue()) request_ip = Utils.get_ip_addr(request) diff --git a/index.py b/index.py index 7199dbe..265bded 100644 --- a/index.py +++ b/index.py @@ -63,6 +63,13 @@ class HttpDispatcher(resource.Resource): action="handle_dlorder", conditions=dict(method=["POST"]), ) + self.map_post.connect( + "allnet_loaderstaterecorder", + "/sys/servlet/LoaderStateRecorder", + controller="allnet", + action="handle_loaderstaterecorder", + conditions=dict(method=["POST"]), + ) self.map_post.connect( "allnet_billing", "/request",