remove legacy file based, bash based checking.

This commit is contained in:
2024-09-04 15:54:35 -05:00
parent bbe92e766d
commit 0f1d56aa40
2 changed files with 0 additions and 172 deletions

93
nord.sh
View File

@@ -1,93 +0,0 @@
#!/bin/bash
# Variables
CREDENTIAL_FILE="nord.creds"
OVPN_DIR="ovpn_tcp"
LOG_FILE="/root/openvpn.log"
RESULT_FILE="vpnlist.txt"
OVPN_ZIP_URL="https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip"
# Get current IP before starting
CURRENT_IP=$(curl -s ifconfig.me)
echo "$(date) [Main Script]: Current IP before VPN connections: $CURRENT_IP"
# Terminate any existing OpenVPN connections
PIDS=$(pgrep openvpn)
if [ -n "$PIDS" ]; then
kill $PIDS
echo "$(date) [Main Script]: Existing OpenVPN connections terminated."
fi
# Download and extract OVPN configurations
if [ ! -d "$OVPN_DIR" ]; then
mkdir "$OVPN_DIR"
fi
curl -s -L -o "$OVPN_DIR/ovpn.zip" "$OVPN_ZIP_URL"
unzip -q -o "$OVPN_DIR/ovpn.zip" -d "$OVPN_DIR"
rm "$OVPN_DIR/ovpn.zip"
# Find all OVPN files except those starting with "us", "del", or "uk"
OVPN_FILES=$(find "$OVPN_DIR" -name "*.ovpn" ! -name "us*.ovpn" ! -name "del*.ovpn" ! -name "uk*.ovpn")
# Get the total number of OVPN files
TOTAL_FILES=$(echo "$OVPN_FILES" | wc -l)
# Process each OVPN file
FILE_NUM=1
for OVPN_FILE in $OVPN_FILES; do
OVPN_FILENAME=$(basename "$OVPN_FILE")
# Read credentials
USERNAME=$(head -n 1 "$CREDENTIAL_FILE")
PASSWORD=$(tail -n 1 "$CREDENTIAL_FILE")
# Establish VPN connection
echo "$PASSWORD" | openvpn --config "$OVPN_FILE" --auth-user-pass "$CREDENTIAL_FILE" --daemon --log-append "$LOG_FILE"
# Wait for connection to establish
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: Waiting for VPN connection to establish..."
sleep 10
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: VPN connection established."
# Check external IP (with validation and retries)
EXTERNAL_IP=$(curl -s ifconfig.me)
if ! [[ $EXTERNAL_IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: Invalid response from ifconfig.me, retrying with ifconfig.co"
EXTERNAL_IP=$(curl -s ifconfig.co)
if ! [[ $EXTERNAL_IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: Invalid response from ifconfig.co, retrying with ipinfo.io/ip"
EXTERNAL_IP=$(curl -s ipinfo.io/ip)
if ! [[ $EXTERNAL_IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: Unable to get external IP. Skipping this OVPN file."
continue # Skip to the next OVPN file
fi
fi
fi
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: External IP via VPN: $EXTERNAL_IP"
# Append result to file
echo "$EXTERNAL_IP # $OVPN_FILENAME" >> "$RESULT_FILE"
# Disconnect VPN
PIDS=$(pgrep openvpn)
if [ -n "$PIDS" ]; then
kill $PIDS
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: VPN disconnected."
else
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: No openvpn process found."
fi
# Wait for a random time between 8 and 30 seconds
SLEEP_TIME=$(((RANDOM % 23) + 8))
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: Waiting for $SLEEP_TIME seconds before the next connection..."
sleep $SLEEP_TIME
echo "$(date) [$FILE_NUM/$TOTAL_FILES] [$OVPN_FILENAME]: Resuming..."
# Increment file number
FILE_NUM=$((FILE_NUM + 1))
done

View File

@@ -1,79 +0,0 @@
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_number, line in enumerate(f, start=1):
if line.startswith('#'):
continue
if ' # ' not in line:
print(f"Skipping invalid line {line_number}: {line}")
continue
try:
parts = line.strip().split(' # ')
exit_ip = parts[0]
file_name = parts[1].strip()
except IndexError:
print(f"Error parsing line {line_number}: {line}")
continue
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()