socks5/socks5.sh

100 lines
2.2 KiB
Bash
Raw Normal View History

2024-07-27 04:26:48 +05:00
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo -e "\033[31mThis script requires superuser rights.\033[0m"
exit 1
fi
if [ -z "$1" ]; then
echo "Please provide socks5 password as argument"
exit 1
fi
2024-08-05 07:24:59 +05:00
DANTE_CONF="/etc/danted.conf"
DANTE_USER="usrsocks"
DANTE_PASSWORD=$1
2024-07-27 04:26:48 +05:00
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' ERR
set -e
export DEBIAN_FRONTEND=noninteractive
2024-08-06 21:47:44 +05:00
# Wait for unlocking:
wait_for_lock() {
while fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do
echo "Waiting for /var/lib/dpkg/lock-frontend to be unlocked..."
sleep 5
done
}
2024-08-05 07:24:59 +05:00
echo "Find active network interface..."
2024-07-27 04:26:48 +05:00
INTERFACE=$(ip -o -4 route show to default | awk '{print $5}')
if [ -z "$INTERFACE" ]; then
echo "Failed to find active network interface"
exit 1
fi
echo "Active network interface found: $INTERFACE"
2024-08-05 07:24:59 +05:00
echo "Install dante-server..."
2024-08-06 21:47:44 +05:00
wait_for_lock
2024-08-05 07:24:59 +05:00
apt-get update
2024-08-06 21:47:44 +05:00
wait_for_lock
2024-08-05 07:24:59 +05:00
apt-get install -y dante-server
2024-07-27 04:26:48 +05:00
2024-08-05 07:24:59 +05:00
echo "Backup existing configuration file $DANTE_CONF..."
2024-07-27 04:26:48 +05:00
if [ -f "${DANTE_CONF}" ]; then
cp "$DANTE_CONF" "${DANTE_CONF}.bak"
echo -e "\033[32mBackup existing configuration file\033[0m"
fi
NEW_CONFIG=$(cat <<-EOM
logoutput: syslog stdout /data/logs/danted.log
internal: $INTERFACE port = 1080
external: $INTERFACE
socksmethod: username
user.privileged: root
user.unprivileged: nobody
user.libwrap: nobody
client pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error connect disconnect
}
client block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect error
}
socks pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error connect disconnect
}
socks block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect error
}
EOM
)
2024-08-05 07:24:59 +05:00
echo "Write configuration file $DANTE_CONF..."
2024-07-27 04:26:48 +05:00
echo "$NEW_CONFIG" > "$DANTE_CONF"
2024-08-05 07:24:59 +05:00
echo "Create user $DANTE_USER for SOCKS5 auth..."
2024-07-27 04:26:48 +05:00
useradd -s /bin/false $DANTE_USER
echo "$DANTE_USER:$DANTE_PASSWORD" | chpasswd
2024-08-05 07:24:59 +05:00
echo "restart danted service..."
2024-07-27 04:26:48 +05:00
systemctl restart danted
systemctl enable danted
trap - ERR
echo -e "\033[32mDante SOCKS5 proxy has been installed and configured with authentication\033[0m"