forked from IDeletedSystem64/iptables-deploy
finally, we finished it :)
This commit is contained in:
parent
b43f1ad1dd
commit
f005974117
37
deploy.py
37
deploy.py
@ -1,43 +1,52 @@
|
|||||||
import paramiko
|
import paramiko
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import time # i need time to get this done
|
||||||
|
|
||||||
# import modules
|
# import modules
|
||||||
|
|
||||||
with open("conf.json", "r") as file:
|
with open("conf.json", "r") as file:
|
||||||
cfg = json.load(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()
|
sshc = paramiko.client.SSHClient()
|
||||||
healthstatus = ""
|
healthstatus = "" # possible values: "ok", "err"
|
||||||
healthpassing = True
|
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
|
# set our variables
|
||||||
|
|
||||||
def healthcheck():
|
def healthcheck():
|
||||||
global healthstatus
|
global healthstatus
|
||||||
response = os.system("ping -c 2 " + cfg["server"])
|
response = os.system("ping -c 2 " + cfg["server"] + ">> /dev/null")
|
||||||
if response != 0:
|
if response != 0:
|
||||||
healthstatus = "err"
|
healthstatus = "err"
|
||||||
else:
|
else:
|
||||||
healthstatus = "ok"
|
healthstatus = "ok"
|
||||||
|
|
||||||
def deploy():
|
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.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:
|
while True:
|
||||||
healthcheck()
|
healthcheck()
|
||||||
|
|
||||||
if healthstatus != "ok":
|
if healthstatus != "ok":
|
||||||
print(healthstatus)
|
print("ONT is not responding!! Did we lose network connection, or is the ONT rebooting? waiting for ONT to respond, then deploying payload!")
|
||||||
print("ONT is not responding!! Did we lose network connection, or is the ONT rebooting? Waiting for a successful ping then deploying!")
|
|
||||||
healthpassing = False
|
healthpassing = False
|
||||||
while healthpassing == False:
|
while healthpassing == False:
|
||||||
if healthcheck() == "ok":
|
print("Checking for a response...")
|
||||||
|
healthcheck()
|
||||||
|
|
||||||
|
if healthstatus == "ok":
|
||||||
print("ONT responded, deploying payload!")
|
print("ONT responded, deploying payload!")
|
||||||
healthpassing == True;
|
healthpassing == True;
|
||||||
|
deploy()
|
||||||
|
break
|
||||||
else:
|
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.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user