Skip to content

Commit

Permalink
add ping to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Hachard authored and hezanathos committed Apr 3, 2024
1 parent fe02ee7 commit 2a37307
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cli/bin/airgap/download_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def help():
print("Download airgap scripts.\n")
print("{: >23} \t {: >20} \t{}".format("ARGS", "DEFAULT", "DESCRIPTION"))
print("{: >23} \t {: >20} \t{}".format("---", "---", "---"))
print("{: >23} \t {: >20} \t{}".format("--no-attachment", "False", "-"))
print("{: >23} \t {: >20} \t{}".format("--add-attachment", "False", "Download the Windows cab file"))
print("{: >23} \t {: >20} \t{}".format("--dest-dir", "cyberwatch-airgap", "Destination folder where to put the downloaded scripts"))
print("\n")

Expand Down Expand Up @@ -95,12 +95,12 @@ def download_individual_script(scriptID, base_dir, CBW_API, with_attachment=Fals
def manager(arguments, CBW_API, verify_ssl=False):

parser = argparse.ArgumentParser()
parser.add_argument("--no-attachment", action="store_false")
parser.add_argument("--add-attachment", action="store_false")
parser.add_argument("--dest-dir", default="cyberwatch-airgap")
parser.add_argument("help", nargs="?")
options = parser.parse_args(arguments)

if arguments and arguments[0] == "help":
help()
else:
download_scripts(options.dest_dir, CBW_API, verify_ssl, options.no_attachment)
download_scripts(options.dest_dir, CBW_API, verify_ssl, options.add_attachment)
18 changes: 18 additions & 0 deletions cli/cyberwatch-cli
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,22 @@ def help():
print("{: >15} \t {}".format("---", "---"))
print("{: >15} \t {}".format("os", "Manage cyberwatch operating systems"))
print("{: >15} \t {}".format("airgap", "Interact with the airgap interface"))
print("{: >15} \t {}".format("ping", "Ping the Cyberwatch API to validate the connexion"))
print("\n")

def ping(CBW_API, verify_ssl=False):
apiResponse = CBW_API.request(
method="GET",
endpoint="/api/v3/ping",
verify_ssl=verify_ssl
)
print("Trying to ping Cyberwatch API...")
response = next(apiResponse).json()
print(response)
if response.get("error") is not None:
print("Failed ping to Cyberwatch API, exiting...")
sys.exit(1)

arguments = sys.argv[1:]

try:
Expand Down Expand Up @@ -54,9 +68,13 @@ try:

if not arguments or arguments[0] == "help":
help()
elif arguments[0] == "ping":
ping(CBW_API, VERIFY_SSL)
elif arguments[0] == "os":
ping(CBW_API, VERIFY_SSL)
os.manager(arguments[1:], CBW_API, VERIFY_SSL)
elif arguments[0] == "airgap":
ping(CBW_API, VERIFY_SSL)
airgap.manager(arguments[1:], CBW_API, VERIFY_SSL)
else:
print("ERROR : '" + str(arguments[0]) + "' is not a valid command\n---", file=sys.stderr)
Expand Down

0 comments on commit 2a37307

Please sign in to comment.