51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
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() |