From efb58d4f016f5455d7013c2077f68af2aa55ce3d Mon Sep 17 00:00:00 2001
From: "gioacchino.vino" <gioacchino.vino@infn.it>
Date: Tue, 5 Dec 2023 18:16:57 +0100
Subject: [PATCH] Python script: argparse and modules

---
 files/scan.py      |  4 ++--
 files/script.py    |  5 -----
 files/utilities.py | 11 ++++++++---
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/files/scan.py b/files/scan.py
index 859ca06..36394a5 100644
--- a/files/scan.py
+++ b/files/scan.py
@@ -9,7 +9,7 @@ import utilities
 import argparse
 
 ### GVM Options ###
-wait_timeout = 3600 #1h
+WAIT_TIMEOUT = 3600 #1h
 
 parser = argparse.ArgumentParser(
     description='Scan endpoints and machines')
@@ -87,7 +87,7 @@ for host,ports in endpoints.items():
     
     if task['status'] == 'New':
         task = gvm_library.start_task(task)
-    if gvm_library.wait_for_task_ending(task,wait_timeout):
+    if gvm_library.wait_for_task_ending(task, WAIT_TIMEOUT):
         gvm_library.save_report(task,gvm_library.report_formats.txt, report_filename)
         reports[host] = gvm_library.get_report_info(task)
     else:
diff --git a/files/script.py b/files/script.py
index c61e6d4..bc94f06 100644
--- a/files/script.py
+++ b/files/script.py
@@ -9,7 +9,6 @@ import logging
 import json
 import base64
 from sys import argv, exit
-import socket
 import os
 
 def get_version_old():
@@ -425,7 +424,6 @@ def import_dep_info(file_path, endpoints_to_scan):
     return endpoints
                 
 ################ MAIN #######################################
-import argparse
 
 logging.basicConfig(
     filename='scans.log', 
@@ -457,9 +455,6 @@ scanner = {'id': "08b69003-5fc2-4037-a479-93b440211c73"}
 ovs_ssh_credential = {'id': "b9af5845-8b87-4378-bca4-cee39a894c17"}
 wait_timeout = 3600 #1h
 
-
-
-
 if len(argv) != 4:
     print("Please pass three parameters:")
     print("- endpoints to scans [endpoints1,endpoint2,endpoint3,...]")
diff --git a/files/utilities.py b/files/utilities.py
index abbb337..ed3270b 100644
--- a/files/utilities.py
+++ b/files/utilities.py
@@ -1,6 +1,10 @@
 import json
 import logging
 
+SSH_PORT = '22'
+HTTP_PORT = '80'
+HTTPS_PORT = '443'
+
 def pretty_json(j):
     return json.dumps(j,sort_keys=True,indent=4)
         
@@ -13,7 +17,8 @@ def import_dep_info(file_path, endpoint_keys):
     for key,value in data['output'].items():
         if "_ip" in key:
             if isinstance(value, str):
-                endpoints[value] = {22}
+                logging.info(f"Endpoint: {value}:{SSH_PORT}")
+                endpoints[value] = {SSH_PORT}
     
     if endpoint_keys != "None":
         list_endpoints = endpoint_keys.split(',')
@@ -26,9 +31,9 @@ def import_dep_info(file_path, endpoint_keys):
                 else:
                     host = url
                     if prefix == "https":
-                        port = '443'
+                        port = HTTPS_PORT
                     elif prefix == 'http':
-                        port = '80'
+                        port = HTTP_PORT
                     else:
                         raise Exception(f"Impossible to parse the endpoint port. Endpoint: {endpoint}")
                 logging.info(f"Endpoint: {host}:{port}")
-- 
GitLab