100 lines
2.2 KiB
Bash
100 lines
2.2 KiB
Bash
#!/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
|
|
|
|
DANTE_CONF="/etc/danted.conf"
|
|
DANTE_USER="usrsocks"
|
|
DANTE_PASSWORD=$1
|
|
|
|
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' ERR
|
|
set -e
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
# 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
|
|
}
|
|
|
|
|
|
echo "Find active network interface..."
|
|
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"
|
|
|
|
echo "Install dante-server..."
|
|
wait_for_lock
|
|
apt-get update
|
|
wait_for_lock
|
|
apt-get install -y dante-server
|
|
|
|
echo "Backup existing configuration file $DANTE_CONF..."
|
|
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
|
|
)
|
|
|
|
echo "Write configuration file $DANTE_CONF..."
|
|
echo "$NEW_CONFIG" > "$DANTE_CONF"
|
|
|
|
echo "Create user $DANTE_USER for SOCKS5 auth..."
|
|
useradd -s /bin/false $DANTE_USER
|
|
echo "$DANTE_USER:$DANTE_PASSWORD" | chpasswd
|
|
|
|
echo "restart danted service..."
|
|
systemctl restart danted
|
|
systemctl enable danted
|
|
|
|
trap - ERR
|
|
echo -e "\033[32mDante SOCKS5 proxy has been installed and configured with authentication\033[0m" |