diff --git a/deploy.py b/deploy.py index 3ee8dfe..aafdd01 100644 --- a/deploy.py +++ b/deploy.py @@ -1,43 +1,52 @@ import paramiko import json import os +import time # i need time to get this done # import modules with open("conf.json", "r") as file: cfg = json.load(file) -# yeah yeah i should probably use YAML but i don't really want to fool with it rn lol -64 +# open the config file and make it accessible via "cfg" sshc = paramiko.client.SSHClient() -healthstatus = "" -healthpassing = True -# define sshc so we don't have to type the whole thing every time we want a client as well as set our healthpassing variable +healthstatus = "" # possible values: "ok", "err" +healthpassing = True +# set our variables def healthcheck(): global healthstatus - response = os.system("ping -c 2 " + cfg["server"]) + response = os.system("ping -c 2 " + cfg["server"] + ">> /dev/null") if response != 0: healthstatus = "err" else: healthstatus = "ok" def deploy(): - # deployment shit here sshc.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # so we don't get whined at and crash over a unrecognized host-key - sshc.connect(cfg["server"],port=cfg["port"],password=cfg["ssh-password"]) - + sshc.connect(cfg["server"],port=cfg["port"],key_filename=cfg["ssh-key"]) + + sftp = sshc.open_sftp() # after opening the ssh connection, we'll open a sftp connection. + sftp.put("./payload/payload.sh", "/home/system64/payload.sh") # upload the payload via SFTP. + + sshc.exec_command("chmod +x $HOME/payload.sh") # make it executable + sshc.exec_command("./payload.sh") # and finally, run the payload. + sshc.close # close the connection. while True: healthcheck() if healthstatus != "ok": - print(healthstatus) - print("ONT is not responding!! Did we lose network connection, or is the ONT rebooting? Waiting for a successful ping then deploying!") + print("ONT is not responding!! Did we lose network connection, or is the ONT rebooting? waiting for ONT to respond, then deploying payload!") healthpassing = False while healthpassing == False: - if healthcheck() == "ok": + print("Checking for a response...") + healthcheck() + + if healthstatus == "ok": print("ONT responded, deploying payload!") healthpassing == True; + deploy() + break else: - print(healthstatus) - - + print("Got a response! health status is ok.") + time.sleep(30) # we will run this loop every 30 seconds so we don't pelt the poor thing in pings.