|
| 1 | +from __future__ import print_function |
| 2 | + |
| 3 | +# A package for reading passwords without displaying them on the console. |
| 4 | +import argparse |
| 5 | +import getpass |
| 6 | + |
| 7 | +import sys, os |
| 8 | +import time |
| 9 | + |
| 10 | +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) |
| 11 | + |
| 12 | +# cpapi is a library that handles the communication with the Check Point management server. |
| 13 | +from cpapi import APIClient, APIClientArgs, APIResponse |
| 14 | + |
| 15 | + |
| 16 | +def main(usera="python-api-wrapper"): |
| 17 | + |
| 18 | + client_args = APIClientArgs(server="172.23.3.10", port=443, user_agent=usera) |
| 19 | + |
| 20 | + with APIClient(client_args) as client: |
| 21 | + |
| 22 | + if client.check_fingerprint() is False: |
| 23 | + print("Could not get the server's fingerprint - Check connectivity with the server.") |
| 24 | + exit(1) |
| 25 | + |
| 26 | + # login to server: |
| 27 | + login_res = client.login_as_root() |
| 28 | + |
| 29 | + if login_res.success is False: |
| 30 | + print("Login failed:\n{}".format(login_res.error_message)) |
| 31 | + exit(1) |
| 32 | + else: |
| 33 | + print("Logged in kululu") |
| 34 | + start = time.time() |
| 35 | + res = client.api_call("show-session") |
| 36 | + end = time.time() - start |
| 37 | + if res.success is True: |
| 38 | + |
| 39 | + print("The script has been executed successfully in "+ str(end)+"seconds") |
| 40 | + |
| 41 | + # publish the result |
| 42 | + publish_res = client.api_call("publish", {}) |
| 43 | + if publish_res.success: |
| 44 | + for call in client_args.api_calls: |
| 45 | + print(call) |
| 46 | + else: |
| 47 | + print("Failed to publish the changes.") |
| 48 | + else: |
| 49 | + print("Failed to run: Error:\n{}".format(res.error_message)) |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + if len(sys.argv)>1: |
| 54 | + usera = sys.argv[1] |
| 55 | + main(usera) |
| 56 | + else: |
| 57 | + main() |
0 commit comments