init scripts
This commit is contained in:
71
update-nord.py
Normal file
71
update-nord.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import psycopg2
|
||||
from datetime import datetime
|
||||
|
||||
# Read database connection details from psql.creds
|
||||
db_config = {}
|
||||
try:
|
||||
with open('psql.creds', 'r') as f:
|
||||
for line in f:
|
||||
if '=' not in line:
|
||||
continue
|
||||
|
||||
key, value = line.strip().split('=')
|
||||
db_config[key.strip()] = value.strip()
|
||||
|
||||
except FileNotFoundError:
|
||||
print("Error: psql.creds file not found. Please make sure it exists in the same directory as the script.")
|
||||
exit(1)
|
||||
|
||||
# Initialize counters for the summary
|
||||
total_processed = 0
|
||||
successful_updates = 0
|
||||
|
||||
try:
|
||||
# Connect to the PostgreSQL database using the config
|
||||
conn = psycopg2.connect(
|
||||
dbname=db_config['db_name'],
|
||||
user=db_config['db_user'],
|
||||
password=db_config['db_password'],
|
||||
host=db_config['db_host'],
|
||||
port=db_config['db_port']
|
||||
)
|
||||
cur = conn.cursor()
|
||||
|
||||
# Read the file line by line
|
||||
with open('vpnlist.txt', 'r') as f:
|
||||
for line in f:
|
||||
if line.startswith('#'):
|
||||
continue
|
||||
|
||||
parts = line.strip().split(' # ')
|
||||
exit_ip = parts[0]
|
||||
file_name = parts[1].strip()
|
||||
|
||||
total_processed += 1
|
||||
|
||||
# Update the database
|
||||
current_timestamp = datetime.now()
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE ovpn_files
|
||||
SET exit_ip = %s, last_exit_ip_check = %s
|
||||
WHERE file_name = %s
|
||||
""",
|
||||
(exit_ip, current_timestamp, file_name)
|
||||
)
|
||||
|
||||
successful_updates += cur.rowcount
|
||||
|
||||
# Commit the changes to the database
|
||||
conn.commit()
|
||||
|
||||
# Print the summary
|
||||
print(f"Processed {total_processed} files. Successfully updated {successful_updates} rows in the database.")
|
||||
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
print(f"Error connecting to the database: {error}")
|
||||
|
||||
finally:
|
||||
if conn is not None:
|
||||
cur.close()
|
||||
conn.close()
|
||||
51
update-rbl.py
Normal file
51
update-rbl.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import shutil
|
||||
import subprocess
|
||||
import signal
|
||||
import os
|
||||
|
||||
def update_and_reload():
|
||||
"""Copies the VPN list, restarts rbldnsd (finding PID using ps aux), and logs the process."""
|
||||
|
||||
# Copy the VPN list
|
||||
try:
|
||||
shutil.copy('/root/vpnlist.txt', '/etc/vpnlist.txt')
|
||||
print("VPN list copied successfully.")
|
||||
except shutil.Error as e:
|
||||
print(f"Error copying VPN list: {e}")
|
||||
return # Exit if copy fails
|
||||
|
||||
# Find the PID of rbldnsd using ps aux
|
||||
try:
|
||||
output = subprocess.check_output(["ps", "aux"]).decode()
|
||||
for line in output.splitlines():
|
||||
if "rbldnsd" in line:
|
||||
pid = int(line.split()[1])
|
||||
break
|
||||
else:
|
||||
raise ValueError("rbldnsd process not found in ps aux output.")
|
||||
print(f"Found rbldnsd process with PID: {pid}")
|
||||
except (subprocess.CalledProcessError, ValueError) as e:
|
||||
print(f"Error finding rbldnsd PID: {e}")
|
||||
return
|
||||
|
||||
# Stop rbldnsd
|
||||
try:
|
||||
os.kill(pid, signal.SIGTERM) # Send a termination signal
|
||||
print("Sent termination signal to rbldnsd.")
|
||||
except ProcessLookupError:
|
||||
print("Error: rbldnsd process not found (might have already stopped).")
|
||||
return
|
||||
|
||||
# Start rbldnsd (make sure this matches your actual rbldnsd command)
|
||||
try:
|
||||
subprocess.run(["rbldnsd", "-4", "-b", "0.0.0.0/5553", "-l", "/var/log/rbldnsd.log",
|
||||
"dnsbl.rizon.net:ip4set:/etc/rbldnsd.db",
|
||||
"dnsbl.rizon.net:ip4set:/etc/vpnlist.txt"], check=True)
|
||||
print("rbldnsd restarted successfully.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error restarting rbldnsd: {e}")
|
||||
|
||||
print("VPN list updated and rbldnsd restarted successfully.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
update_and_reload()
|
||||
Reference in New Issue
Block a user