feat: add various infrastructure check and automation scripts
This commit is contained in:
47
scripts/revert_npm_heimdall.py
Normal file
47
scripts/revert_npm_heimdall.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import paramiko
|
||||
import sys
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect('140.44.4.71', username='snarf', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
||||
|
||||
remote_code = '''
|
||||
import sqlite3
|
||||
import json
|
||||
|
||||
db_path = '/var/lib/docker/volumes/nginx-proxy-manager_nginx-data/_data/database.sqlite'
|
||||
conn = sqlite3.connect(db_path)
|
||||
cur = conn.cursor()
|
||||
domains = json.dumps(["portal.snarfnet.net"])
|
||||
cur.execute("UPDATE proxy_host SET domain_names = ? WHERE id = 4", (domains,))
|
||||
conn.commit()
|
||||
print("Updated DB row:", cur.execute("SELECT id, domain_names, forward_host, forward_port FROM proxy_host WHERE id=4").fetchone())
|
||||
conn.close()
|
||||
|
||||
conf_path = '/var/lib/docker/volumes/nginx-proxy-manager_nginx-data/_data/nginx/proxy_host/4.conf'
|
||||
with open(conf_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
new_content = content.replace("server_name portal.snarfnet.net heimdall.snarfnet.net;", "server_name portal.snarfnet.net;")
|
||||
with open(conf_path, 'w') as f:
|
||||
f.write(new_content)
|
||||
print("Updated 4.conf successfully!")
|
||||
'''
|
||||
|
||||
# Write script to remote /tmp/revert_npm_4.py
|
||||
sftp = c.open_sftp()
|
||||
with sftp.file('/tmp/revert_npm_4.py', 'w') as f:
|
||||
f.write(remote_code)
|
||||
sftp.close()
|
||||
|
||||
# Run script with sudo
|
||||
stdin, stdout, stderr = c.exec_command("echo 'Katzir476!' | sudo -S python3 /tmp/revert_npm_4.py")
|
||||
print("Script output:\n", stdout.read().decode().strip())
|
||||
print("Script err:\n", stderr.read().decode().strip())
|
||||
|
||||
# Reload Nginx
|
||||
_, o, _ = c.exec_command("echo 'Katzir476!' | sudo -S docker exec $(echo 'Katzir476!' | sudo -S docker ps -qf name=nginx-proxy-manager_app) nginx -s reload")
|
||||
print("Reload Nginx:\n", o.read().decode().strip())
|
||||
|
||||
c.close()
|
||||
Reference in New Issue
Block a user