From 510bd1b795a177c73c9f8ccb6066f91c9d70af66 Mon Sep 17 00:00:00 2001 From: ugomeguerditchian Date: Sat, 5 Aug 2023 00:25:18 +0200 Subject: [PATCH] better update motor for external files --- .gitignore | 2 +- lib/generics.py | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 254abb3..9a468a9 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ nuclei/ screenshots/ OrgASM/ configuration.yaml -manifest_tools.json \ No newline at end of file +manifest_update.json \ No newline at end of file diff --git a/lib/generics.py b/lib/generics.py index 81dbb8f..86f45a9 100644 --- a/lib/generics.py +++ b/lib/generics.py @@ -221,7 +221,7 @@ def check_update(config: configuration): response = requests.get(url).json() if response["version"] == version: logger.info("You are up to date") - else: + elif response["version"] > version: logger.warning("Update available") if git.cmd.Git().version() and not config.config.get("dev_mode", False): answer = input("Do you want to update? (y/n) : ") @@ -256,6 +256,9 @@ def check_update(config: configuration): zf.extractall() os.remove("new_version.zip") logger.info("Update successful") + exit(1) + elif response["version"] < version: + logger.info("Wtf bro, you are in the future") except: logger.error("Impossible to get url to check for update") pass @@ -265,17 +268,17 @@ def check_update(config: configuration): # now update file in config to_update = config.config["UPDATE"] - if not os.path.isfile("manifest_tools.json"): - #create manifest_tools.json + if not os.path.isfile("manifest_update.json"): + #create manifest_update.json manifest_tools = {} for line in to_update: # format : path_to_file : url path = list(line.keys())[0] manifest_tools[path] = "01/01/2020 00:00:00" - with open("manifest_tools.json", "w") as f: + with open("manifest_update.json", "w") as f: json.dump(manifest_tools, f) #reset cursor - mamnifest_tools = json.loads(open("manifest_tools.json", "r").read()) + manifest_update = json.loads(open("manifest_update.json", "r").read()) for line in to_update: # format : path_to_file : url path = list(line.keys())[0] @@ -284,7 +287,7 @@ def check_update(config: configuration): 1 ] # can contains "secondes", "minutes", "hours", "days" how_often = line[path][1].split(":")[0] # can contains a number - if is_to_update(mamnifest_tools[path], recurence, how_often): + if is_to_update(manifest_update[path], recurence, how_often): try: response = requests.get(url) except: @@ -293,7 +296,7 @@ def check_update(config: configuration): with open(path, "w") as f: f.write(response.text) logger.info(f"Update {path} successful") - mamnifest_tools[path] = time.strftime("%d/%m/%Y %H:%M:%S") - with open("manifest_tools.json", "w") as f: - json.dump(mamnifest_tools, f) + manifest_update[path] = time.strftime("%d/%m/%Y %H:%M:%S") + with open("manifest_update.json", "w") as f: + json.dump(manifest_update, f) \ No newline at end of file