forked from IDeletedSystem64/iptables-deploy
major rewrite
This commit is contained in:
parent
9f73b02517
commit
75b143a06a
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,2 +1,5 @@
|
||||
conf.json
|
||||
.vscode
|
||||
.vscode
|
||||
|
||||
# Ignore anything in the payload, this is downloaded from a url internally on a timely basis.
|
||||
payload/
|
@ -1,8 +1,9 @@
|
||||
{
|
||||
"chkinterval": "",
|
||||
"filepath": "",
|
||||
"server": "",
|
||||
"port": "",
|
||||
"payload": "payload/payload.sh",
|
||||
"ssh-user": "",
|
||||
"ssh-password": "",
|
||||
"ssh-pw": "",
|
||||
"ssh-key": ""
|
||||
}
|
42
deploy.py
42
deploy.py
@ -1,7 +1,8 @@
|
||||
import paramiko
|
||||
import paramiko # this sounds like an anime
|
||||
import json
|
||||
import os
|
||||
import time # i need time to get this done
|
||||
import requests # for getting the commands to run on client
|
||||
|
||||
# import modules
|
||||
|
||||
@ -11,7 +12,8 @@ with open("conf.json", "r") as file:
|
||||
|
||||
sshc = paramiko.client.SSHClient()
|
||||
healthstatus = "" # possible values: "ok", "err"
|
||||
healthpassing = True
|
||||
healthpassing = True
|
||||
shcommands = []
|
||||
# set our variables
|
||||
|
||||
def healthcheck():
|
||||
@ -22,16 +24,32 @@ def healthcheck():
|
||||
else:
|
||||
healthstatus = "ok"
|
||||
|
||||
def downloadLatestCommands(url):
|
||||
r = requests.get(f'{url}')
|
||||
open(cfg["filepath"], 'wb').write(r.content)
|
||||
|
||||
def commandList():
|
||||
global shcommands
|
||||
cmdtxt = open(cfg["filepath"], "r")
|
||||
cmddata = cmdtxt.read()
|
||||
shcommands = cmddata.split("\n")
|
||||
cmdtxt.close()
|
||||
|
||||
def deploy():
|
||||
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"],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", "/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.connect(cfg["server"],port=cfg["port"],username=cfg["ssh-user"],password=cfg["ssh-pw"],pkey=cfg["ssh-key"])
|
||||
|
||||
for command in shcommands:
|
||||
sshc.exec_command(command)
|
||||
print(f'{command} was executed')
|
||||
|
||||
print("All commands were executed, now disconnecting...")
|
||||
sshc.close # close the connection.
|
||||
|
||||
# sshc.exec_command("chmod +x $HOME/payload.sh") # make it executable
|
||||
# sshc.exec_command("./payload.sh") # and finally, run the payload.
|
||||
|
||||
|
||||
while True:
|
||||
healthcheck()
|
||||
|
||||
@ -43,10 +61,10 @@ while True:
|
||||
healthcheck()
|
||||
|
||||
if healthstatus == "ok":
|
||||
print("ONT responded, deploying payload!")
|
||||
healthpassing == True;
|
||||
print("ONT responded after a fail, deploying payload!")
|
||||
healthpassing == True
|
||||
deploy()
|
||||
break
|
||||
else:
|
||||
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.
|
||||
time.sleep(cfg["chkinterval"]) # we will run this loop every X seconds, defined by checkinterval
|
||||
|
@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
wall "it works!!"
|
@ -1,93 +1,2 @@
|
||||
appdirs==1.4.4
|
||||
argcomplete==2.0.0
|
||||
bcrypt==4.1.2
|
||||
beautifulsoup4==4.12.2
|
||||
blivet==3.7.1
|
||||
blivet-gui==2.4.2
|
||||
Brlapi==0.8.4
|
||||
Brotli==1.0.9
|
||||
certifi==2022.9.24
|
||||
cffi==1.15.1
|
||||
chardet==5.2.0
|
||||
charset-normalizer==3.1.0
|
||||
click==8.1.3
|
||||
cryptography==41.0.7
|
||||
cssselect==1.1.0
|
||||
cupshelpers==1.0
|
||||
dasbus==1.7
|
||||
dbus-python==1.3.2
|
||||
decorator==5.1.1
|
||||
Deprecated==1.2.14
|
||||
distro==1.8.0
|
||||
dnf==4.18.2
|
||||
docopt==0.6.2
|
||||
evdev==1.6.1
|
||||
fedora-third-party==0.10
|
||||
file-magic==0.4.0
|
||||
gpg==1.17.1
|
||||
humanize==3.13.1
|
||||
idna==3.4
|
||||
initial-setup==0.3.97
|
||||
invoke==2.2.0
|
||||
Jinja2==3.0.3
|
||||
langtable==0.0.64
|
||||
libcomps==0.1.20
|
||||
libdnf==0.72.0
|
||||
libvirt-python==9.0.0
|
||||
lxml==4.9.2
|
||||
MarkupSafe==2.1.2
|
||||
mutagen==1.46.0
|
||||
nftables==0.1
|
||||
numpy==1.24.4
|
||||
olefile==0.46
|
||||
packaging==23.0
|
||||
paramiko==3.4.0
|
||||
pexpect==4.8.0
|
||||
pid==2.2.3
|
||||
Pillow==9.5.0
|
||||
ply==3.11
|
||||
productmd==1.37
|
||||
protonvpn-cli==2.2.11
|
||||
ptyprocess==0.7.0
|
||||
pwquality==1.4.5
|
||||
pycairo==1.23.0
|
||||
pycparser==2.20
|
||||
pycryptodomex==3.19.0
|
||||
pycups==2.0.1
|
||||
pycurl==7.45.2
|
||||
pyenchant==3.2.2
|
||||
PyGObject==3.44.2
|
||||
pykickstart==3.47
|
||||
PyNaCl==1.5.0
|
||||
pyparted==3.12.0
|
||||
PyQt5==5.15.9
|
||||
PyQt5-sip==12.11.1
|
||||
PySocks==1.7.1
|
||||
python-augeas==1.1.0
|
||||
python-dateutil==2.8.2
|
||||
python-gettext==4.0
|
||||
python-manatools==0.0.4
|
||||
python-meh==0.51
|
||||
pythondialog==3.5.3
|
||||
pyudev==0.24.0
|
||||
pyxdg==0.27
|
||||
PyYAML==6.0
|
||||
regex==2023.10.3
|
||||
requests==2.28.2
|
||||
requests-file==1.5.1
|
||||
requests-ftp==0.3.1
|
||||
rpm==4.18.2
|
||||
scour==0.38.2
|
||||
selinux==3.5
|
||||
sepolicy==3.5
|
||||
setools==4.4.3
|
||||
simpleaudio==1.0.4
|
||||
simpleline==1.9.0
|
||||
six==1.16.0
|
||||
sos==4.5.1
|
||||
soupsieve==2.4.1
|
||||
systemd-python==235
|
||||
urllib3==1.26.18
|
||||
websockets==10.4
|
||||
wrapt==1.16.0
|
||||
yt-dlp==2023.10.7
|
||||
paramiko
|
||||
requests
|
Loading…
x
Reference in New Issue
Block a user