#!/bin/bash

set -e

IFACE=$(ip route | awk '/default/ {print $5; exit}')

echo "[+] Network Interface: $IFACE"

apt update
apt install -y dante-server curl

cat > /etc/danted.conf << EOF
logoutput: syslog

internal: 0.0.0.0 port = 1080
external: $IFACE

socksmethod: username
clientmethod: none

user.privileged: root
user.unprivileged: nobody

client pass {
    from: 0.0.0.0/0 to: 0.0.0.0/0
}

socks pass {
    from: 0.0.0.0/0 to: 0.0.0.0/0
    protocol: tcp udp
    command: bind connect udpassociate
}

socks pass {
    from: 0.0.0.0/0 to: 0.0.0.0/0
    command: bindreply udpreply
}
EOF

if ! id mcproxy >/dev/null 2>&1; then
    useradd -M -s /usr/sbin/nologin mcproxy
fi

echo 'mcproxy:124578asdE' | chpasswd

systemctl daemon-reload
systemctl enable danted
systemctl restart danted

if command -v ufw >/dev/null 2>&1; then
    ufw allow 1080/tcp || true
    ufw allow 1080/udp || true
fi

sleep 2

echo
echo "========================================"
echo "SOCKS5 PROXY HAZIR"
echo "========================================"
echo "IP   : $(curl -4 -s ifconfig.me)"
echo "PORT : 1080"
echo "USER : mcproxy"
echo "PASS : 124578asdE"
echo "IFACE: $IFACE"
echo "STATUS: $(systemctl is-active danted)"
echo "========================================"