]> git.mxchange.org Git - fba.git/blobdiff - fba/models/instances.py
Continued:
[fba.git] / fba / models / instances.py
index 36260132ab5ac063c2119712dce8d10cea7642f0..e86128181f8dd487a299d40412f6a4502e9c039b 100644 (file)
@@ -70,7 +70,9 @@ _pending = {
     "last_error_details" : {},
     # Wether obfuscation has been used
     "has_obfuscation"    : {},
-    # Determined software
+    # Original software
+    "original_software"  : {},
+    # Aliased software
     "software"           : {},
 }
 
@@ -220,13 +222,14 @@ def add(domain: str, origin: str, command: str, path: str = None, software: str
 
     logger.info("Adding instance domain='%s',origin='%s',software='%s',command='%s' ...", domain, origin, software, command)
     database.cursor.execute(
-        "INSERT INTO instances (domain, origin, command, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)",
+        "INSERT INTO instances (domain, origin, command, hash, software, original_software, first_seen) VALUES (?, ?, ?, ?, ?, ?, ?)",
         (
            domain,
            origin,
            command,
            utils.get_hash(domain),
            software,
+           software,
            time.time()
         ),
     )
@@ -273,6 +276,10 @@ def set_last_error(domain: str, error: dict):
         logger.debug("Setting last_error_details='%s' (error_message)", error['error_message'])
         _set_data("last_status_code"  , domain, error["status_code"])
         _set_data("last_error_details", domain, error["error_message"] if error["error_message"] != "" else None)
+    elif "json" in error and "error" in error["json"] and "msg" in error["json"]:
+        logger.debug("Setting last_error_details='%s' (json,error)", error["json"]["msg"])
+        _set_data("last_status_code"  , domain, error["status_code"])
+        _set_data("last_error_details", domain, error["json"]["msg"] if error["json"]["msg"] != "" else None)
     elif "json" in error and "error" in error["json"] and "message" in error["json"]["error"]:
         logger.debug("Setting last_error_details='%s' (json,error)", error["json"]["error"]["message"])
         _set_data("last_status_code"  , domain, error["status_code"])
@@ -301,7 +308,9 @@ def is_registered(domain: str, skip_raise = False) -> bool:
     logger.debug("domain='%s',skip_raise='%s' - CALLED!", domain, skip_raise)
     domain_helper.raise_on(domain)
 
-    if not isinstance(skip_raise, bool):
+    if blacklist.is_blacklisted(domain):
+        raise Exception(f"domain='{domain}' is blacklisted but function has been invoked")
+    elif not isinstance(skip_raise, bool):
         raise ValueError(f"skip_raise[]='{type(skip_raise)}' is not type of 'bool'")
 
     if not skip_raise:
@@ -477,6 +486,8 @@ def set_nodeinfo_url(domain: str, url: str):
         raise ValueError(f"Parameter url[]='{type(url)}' is not of type 'str'")
     elif url == "":
         raise ValueError("Parameter 'url' is empty")
+    elif url is not None and not validators.url(url):
+        raise ValueError(f"Parameter url='{url}' is not a valid URL")
 
     # Set timestamp
     _set_data("nodeinfo_url", domain, url)
@@ -506,6 +517,20 @@ def set_has_obfuscation(domain: str, status: bool):
     _set_data("has_obfuscation", domain, status)
     logger.debug("EXIT!")
 
+def set_original_software(domain: str, software: str):
+    logger.debug("domain='%s',software='%s' - CALLED!", domain, software)
+    domain_helper.raise_on(domain)
+
+    if not isinstance(software, str) and software is not None:
+        raise ValueError(f"Parameter software[]='{type(software)}' is not of type 'str'")
+    elif software == "":
+        raise ValueError("Parameter 'software' is empty")
+
+    # Set original software
+    _set_data("original_software", domain, software)
+    logger.debug("EXIT!")
+
+
 def set_software(domain: str, software: str):
     logger.debug("domain='%s',software='%s' - CALLED!", domain, software)
     domain_helper.raise_on(domain)
@@ -515,7 +540,7 @@ def set_software(domain: str, software: str):
     elif software == "":
         raise ValueError("Parameter 'software' is empty")
 
-    # Set timestamp
+    # Set software (maybe aliased to generic name)
     _set_data("software", domain, software)
     logger.debug("EXIT!")