forked from Lozy/danted
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Danted Sock5 Install for CentOS/Debian
1. Include Debian/CentOS.
- Loading branch information
Showing
1 changed file
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,277 @@ | ||
#!/bin/sh | ||
#For Centos | ||
DEFAULT_PORT="2014" | ||
DEFAULT_USER="sock5" | ||
DEFAULT_PAWD="sock5" | ||
VERSION="v1.4.0" | ||
|
||
genconfig(){ | ||
# CONFIGFILE $IP $PORT $N | ||
CONFIGFILE=$1 | ||
IP=$2 | ||
PORT=$3 | ||
num=$4 | ||
cat >$CONFIGFILE<<EOF | ||
internal: ${IP} port = ${PORT} | ||
external: ${IP} | ||
#socksmethod: username none | ||
user.notprivileged: sock | ||
socksmethod: pam.username | ||
logoutput: /var/log/danted.${num}.log | ||
client pass { | ||
from: 0.0.0.0/0 to: 0.0.0.0/0 | ||
log: connect disconnect | ||
} | ||
socks pass { | ||
from: 0.0.0.0/0 to: 0.0.0.0/0 port gt 1023 | ||
command: bind | ||
log: connect disconnect | ||
} | ||
socks pass { | ||
from: 0.0.0.0/0 to: 0.0.0.0/0 | ||
command: connect udpassociate | ||
log: connect disconnect | ||
} | ||
socks pass { | ||
from: 0.0.0.0/0 to: 0.0.0.0/0 | ||
command: bindreply udpreply | ||
log: connect error | ||
} | ||
socks block { | ||
from: 0.0.0.0/0 to: 0.0.0.0/0 | ||
log: connect error | ||
} | ||
EOF | ||
} | ||
|
||
( [ -n "$(grep CentOS /etc/issue)" ] \ | ||
&& ( yum install gcc g++ make vim pam-devel tcp_wrappers-devel unzip httpd-tools -y ) ) \ | ||
|| ( [ -n "$(grep -E 'Debian|Ubuntu' /etc/issue)" ] \ | ||
&& ( apt-get install gcc g++ make vim libpam-dev libwrap0-dev unzip apache2-utils -y ) )\ | ||
|| exit 0 | ||
|
||
useradd sock -s /bin/false > /dev/null 2>&1 | ||
#echo sock:sock | chpasswd | ||
mkdir -p /etc/danted/conf | ||
|
||
Getserverip_n=$(ifconfig | grep 'inet addr' | grep -Ev 'inet addr:127.0.0|inet addr:192.168.0|inet addr:10.0.0' | sed -n 's/.*inet addr:\([^ ]*\) .*/\1/p' | wc -l) | ||
Getserverip=$(ifconfig | grep 'inet addr' | grep -Ev 'inet addr:127.0.0|inet addr:192.168.0|inet addr:10.0.0' | sed -n 's/.*inet addr:\([^ ]*\) .*/\1/p') | ||
|
||
serverip=$Getserverip | ||
( [ -z "$serverip" ] || [ -z "$(echo $Getserverip | grep "$serverip" )" ] ) && echo 'Get IP address Error.Try again OR report bug.' && exit | ||
[ $Getserverip_n -gt 1 ] && echo "$Getserverip" && read -p "Server IP > 1, Please Input Taget Danted Server IP OR Enter to config all " serverip | ||
|
||
if [ -z "$serverip" ];then | ||
i=0 | ||
echo "$Getserverip" | while read theip;do | ||
port=$DEFAULT_PORT | ||
configfile="/etc/danted/conf/sockd-"$(echo $Getserverip | sed 's/.*\.\(.*\)/\1/g')"${i}.conf" | ||
genconfig $configfile $theip $port $i | ||
i=$((i+1)) | ||
done | ||
else | ||
port=$DEFAULT_PORT | ||
configfile="/etc/danted/conf/sockd-"$(echo $serverip | sed 's/.*\.\(.*\)/\1/g')"${i}.conf" | ||
genconfig $configfile $serverip $port 0 | ||
fi | ||
|
||
mkdir -p /tmp | ||
cd /tmp | ||
|
||
#start-stop-daemon | ||
if [ -z "$(command -v start-stop-daemon)" ];then | ||
wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz | ||
tar zxvf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz | ||
gcc apps/sys-utils/start-stop-daemon-IR1_9_18-2/start-stop-daemon.c -o start-stop-daemon -o /usr/local/sbin/start-stop-daemon | ||
fi | ||
#libpam-pwdfile | ||
if [ ! -s /lib/security/pam_pwdfile.so ] || [ ! -s /lib/i386-linux-gnu/security/pam_pwdfile.so ];then | ||
wget https://github.com/tiwe-de/libpam-pwdfile/archive/master.zip -O master.zip | ||
unzip master.zip | ||
cd libpam-pwdfile-master/ | ||
make && make install | ||
cd ../ | ||
fi | ||
|
||
if [ ! -s /etc/danted/sbin/sockd ] || [ -z "$(/etc/danted/sbin/sockd -v | grep '$VERSION')" ];then | ||
wget http://www.inet.no/dante/files/dante-1.4.0.tar.gz | ||
tar zxvf dante* | ||
cd dante* | ||
./configure --with-sockd-conf=/etc/danted/conf/sockd.conf --prefix=/etc/danted | ||
make && make install | ||
cd ../../ | ||
fi | ||
#Complile Done | ||
rm /tmp/* -rf | ||
|
||
cat > /etc/pam.d/sockd <<EOF | ||
auth required pam_pwdfile.so pwdfile /etc/danted/socks.passwd | ||
account required pam_permit.so | ||
EOF | ||
/usr/bin/htpasswd -c -d -b /etc/danted/socks.passwd ${DEFAULT_USER} ${DEFAULT_PAWD} | ||
|
||
cat > /etc/init.d/danted <<'EOF' | ||
#! /bin/sh | ||
### BEGIN INIT INFO | ||
# Provides: danted | ||
# Reprogarm: airski | ||
# Required-Start: $remote_fs $syslog | ||
# Required-Stop: $remote_fs $syslog | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: SOCKS (v4 and v5) proxy daemon (danted) | ||
### END INIT INFO | ||
# | ||
# dante socks5 daemon for Debian/Centos | ||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | ||
DAEMON=/etc/danted/sbin/sockd | ||
DESC="Dante SOCKS daemon" | ||
CONFIGDIR=/etc/danted/conf | ||
test -f $DAEMON || exit 0 | ||
set -e | ||
start_daemon_all(){ | ||
ls ${CONFIGDIR}/*.conf | while read configed;do | ||
NAME=$(echo $configed | sed 's/.*\/\(.*\)\.conf/\1/g') | ||
PIDFILE=/var/run/$NAME.pid | ||
LOGFILE=$(cat $configed | grep '^logoutput' | sed 's/.*logoutput: \(.*\).*/\1/g') | ||
echo -n " config $NAME " | ||
if [ -s $PIDFILE ] && [ -n "$( ps aux | awk '{print $2}'| grep "^$(cat $PIDFILE)$" )" ];then | ||
echo " [ Runing;Failed ] " | ||
continue | ||
fi | ||
echo >$PIDFILE | ||
cp /dev/null $LOGFILE | ||
if ! egrep -cve '^ *(#|$)' \ | ||
-e '^(logoutput|user\.((not)?privileged|libwrap)):' $configed > /dev/null | ||
then | ||
echo " [ not configured ]" | ||
continue | ||
fi | ||
start-stop-daemon --start --quiet --background --oknodo --pidfile $PIDFILE \ | ||
--exec $DAEMON -- -f $configed -p $PIDFILE | ||
( [ -s $PIDFILE ] && echo " [ Runing ]" ) || echo " [ Faild ]" | ||
done | ||
} | ||
stop_daemon_all(){ | ||
ls ${CONFIGDIR}/*.conf | while read configed;do | ||
NAME=$(echo $configed | sed 's/.*\/\(.*\)\.conf/\1/g') | ||
PIDFILE=/var/run/$NAME.pid | ||
echo -n " config $NAME " | ||
if [[ ! -s $PIDFILE ]];then | ||
echo " [ PID.LOST;Unable ]" | ||
continue | ||
fi | ||
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \ | ||
--exec $DAEMON -- -f $configed -p $PIDFILE | ||
( [ -n "$( ps aux | awk '{print $2}'| grep "^$(cat $PIDFILE)$" )" ] && \ | ||
echo " [ Failed ]" ) || echo " [ Stop ]" | ||
done | ||
} | ||
reload_daemon_all(){ | ||
ls ${CONFIGDIR}/*.conf | while read configed;do | ||
NAME=$(echo $configed | sed 's/.*\/\(.*\)\.conf/\1/g') | ||
PIDFILE=/var/run/$NAME.pid | ||
echo -n " config $NAME " | ||
if [ -s $PIDFILE ];then | ||
if [ -z "$( ps aux | awk '{print $2}'| grep "^$(cat $PIDFILE)$" )" ];then | ||
echo " [ PID.DIE;Unable ]" | ||
continue | ||
fi | ||
else | ||
echo " [ PID.LOST;Unable ]" | ||
continue | ||
fi | ||
start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile $PIDFILE \ | ||
--exec $DAEMON -- -f $configed -p $PIDFILE | ||
( [ -n "$( ps aux | awk '{print $2}'| grep "^$(cat $PIDFILE)$" )" ] && echo " [ Runing ]" ) || echo " [ Failed ]" | ||
done | ||
} | ||
status_daemon_all(){ | ||
ls ${CONFIGDIR}/*.conf | while read configed;do | ||
NAME=$(echo $configed | sed 's/.*\/\(.*\)\.conf/\1/g') | ||
PIDFILE=/var/run/$NAME.pid | ||
echo -n " config $NAME " $(cat $configed | grep '^internal' | sed 's/internal:\(.*\)port.*=\(.*\)/\1:\2/g' | sed 's/ //g')" " | ||
if [[ ! -s $PIDFILE ]];then | ||
echo " [ Stop ]" | ||
continue | ||
fi | ||
( [ -n "$( ps aux | awk '{print $2}'| grep "^$(cat $PIDFILE)$" )" ] && echo " [ Runing ]" ) || echo " [ PID.DIE;Unable ]" | ||
done | ||
echo ">>>>>>>>>>>>>>>>>>>>>>>>" | ||
echo " Active User:" $(cat /etc/danted/socks.passwd | while read line;do echo $line| sed 's/\(.*\):.*/\1/';done) | ||
} | ||
add_user(){ | ||
User=$1 | ||
Passwd=$2 | ||
( [ -z "$User" ] || [ -z "$Passwd" ] ) && echo " Error: User or password can't be blank" && return 0 | ||
/usr/bin/htpasswd -d -b /etc/danted/socks.passwd ${User} ${Passwd} | ||
} | ||
del_uer(){ | ||
User=$1 | ||
[ -z "$User" ] && echo " Error: User Name can't be blank" && return 0 | ||
/usr/bin/htpasswd -D /etc/danted/socks.passwd ${User} | ||
} | ||
case "$1" in | ||
start) | ||
echo "Starting $DESC: " | ||
start_daemon_all | ||
;; | ||
stop) | ||
echo "Stopping $DESC: " | ||
stop_daemon_all | ||
;; | ||
reload) | ||
echo "Reloading $DESC configuration files." | ||
reload_daemon_all | ||
;; | ||
restart) | ||
echo "Restarting $DESC: " | ||
stop_daemon_all | ||
sleep 1 | ||
start_daemon_all | ||
;; | ||
status) | ||
echo "Curent Status Of $DESC: " | ||
status_daemon_all | ||
;; | ||
add) | ||
echo "Adding User For $DESC: " | ||
add_user "$2" "$3" | ||
;; | ||
del) | ||
echo "Clearing User For $DESC: " | ||
del_user "$2" | ||
;; | ||
*) | ||
N=/etc/init.d/danted | ||
echo "Usage: $N {start|stop|restart|status|add|del}" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
exit 0 | ||
EOF | ||
chmod +x /etc/init.d/danted | ||
[ -n "$(grep CentOS /etc/issue)" ] && chkconfig --add danted | ||
[ -n "$(grep -E 'Debian|Ubuntu' /etc/issue)" ] && update-rc.d danted defaults | ||
ln -s /etc/danted/sbin/sockd /usr/bin/danted | ||
service danted start | ||
clear | ||
cat <<EOF | ||
Danted Auto Config | ||
************************************* | ||
SOCK5 ${Getserverip} | ||
PORT ${DEFAULT_PORT} | ||
Auth ${DEFAULT_USER}:${DEFAULT_PAWD} | ||
************************************* | ||
EOF | ||
exit 0 |