forked from Lozy/danted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
325 lines (301 loc) · 9.63 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/bash
DEFAULT_PORT="2014"
DEFAULT_USER="sock"
DEFAULT_PAWD="sock"
MASTER_IP="buyvm.info"
VERSION="v1.4.0"
genconfig(){
# CONFIGFILE $IP $PORT $N
CONFIGFILE=$1
IP=$2
PORT=$3
TAG=$4
cat >$CONFIGFILE<<EOF
#### Danted Sock5 Config For: ${TAG} ${IP} #####
internal: ${IP} port = ${PORT}
external: ${IP}
#socksmethod: none
#socksmethod: username
socksmethod: pam.username none
user.notprivileged: sock
logoutput: /var/log/danted.${TAG}.log
##### Master Config ##############
client pass {
from: ${MASTER_IP} to: 0.0.0.0/0
socksmethod: none
log: connect disconnect
}
#################################
client pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
socksmethod: pam.username
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
}
path=$(cd `dirname $0`;pwd )
( [ -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 update ) \
&& ( apt-get purge dante-server -y ) \
&& ( 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
rm -rf /etc/danted
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
echo "$Getserverip" | while read theip;do
port=$DEFAULT_PORT
intface=$(ifconfig | grep "$Getserverip" -1 | sed -n 1p | awk '{print $1}' )
configfile="/etc/danted/conf/sockd-${intface}.conf"
genconfig $configfile $theip $port $Intface
i=$((i+1))
done
else
port=$DEFAULT_PORT
intface=$(grep "$serverip" -1 | sed -n 1p | awk '{print $1}')
configfile="/etc/danted/conf/sockd-${intface}.conf"
genconfig $configfile $serverip $port $intface
fi
mkdir -p /tmp/danted
cd /tmp/danted
#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 ];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/danted -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/bash
### 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 -e "\033[1;31m [ Runing;Failed ] \033[0m"
continue
fi
echo >$PIDFILE
cp /dev/null $LOGFILE
if ! egrep -cve '^ *(#|$)' \
-e '^(logoutput|user\.((not)?privileged|libwrap)):' $configed > /dev/null
then
echo -e "\033[1;31m [ not configured ] \033[0m"
continue
fi
start-stop-daemon --start --quiet --background --oknodo --pidfile $PIDFILE \
--exec $DAEMON -- -f $configed -p $PIDFILE
( [ -s $PIDFILE ] && echo -e "\033[32m [ Runing ] \033[0m" ) || echo -e "\033[1;31m [ Faild ] \033[0m"
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 -e "\033[1;31m [ PID.LOST;Unable ] \033[0m"
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 -e "\033[1;31m [ Failed ] \033[0m" ) || echo -e "\033[32m [ Stop ] \033[0m"
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 -e "\033[1;31m [ PID.DIE;Unable ] \033[0m"
continue
fi
else
echo -e "\033[1;31m [ PID.LOST;Unable ] \033[0m"
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 -e "\033[32m [ Runing ] \033[0m" ) || echo -e "\033[1;31m [ Failed ] \033[0m"
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 -e "\033[1;31m [ Stop ] \033[0m"
continue
fi
( [ -n "$( ps aux | awk '{print $2}'| grep "^$(cat $PIDFILE)$" )" ] \
&& echo -e "\033[32m [ Runing ] \033[0m" ) || echo -e "\033[1;31m [ PID.DIE;Unable ] \033[0m"
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 restart
clear
#Color Variable
CSI=$(echo -e "\033[")
CEND="${CSI}0m"
CDGREEN="${CSI}32m"
CRED="${CSI}1;31m"
CGREEN="${CSI}1;32m"
CYELLOW="${CSI}1;33m"
CBLUE="${CSI}1;34m"
CMAGENTA="${CSI}1;35m"
CCYAN="${CSI}1;36m"
CQUESTION="$CMAGENTA"
CWARNING="$CRED"
CMSG="$CCYAN"
#Color Variable
if [ -n "$(netstat -atn | grep "$DEFAULT_PORT")" ];then
cat <<EOF
${CCYAN}+-----------------------------------------+$CEND
${CGREEN} Dante Socks5 Install Done. $CEND
${CCYAN}+-----------------------------------------+$CEND
${CGREEN} Dante Version: $CMAGENTA 1.4.0$CEND
${CGREEN} Socks5 Info: $CMAGENTA$CEND
EOF
echo "${Getserverip}" | while read theip;do
echo "${CGREEN} $CMAGENTA ${theip}:${DEFAULT_PORT}$CEND"
done
cat <<EOF
${CGREEN} Socks5 User&Passwd: $CMAGENTA ${DEFAULT_USER}:${DEFAULT_PAWD}$CEND
${CCYAN}+_________________________________________+$CEND
EOF
echo -e "\033[32m Dante Server Install Successfuly! \033[0m"
else
echo -e "\033[1;31m Dante Server Install Failed! \033[0m"
exit
fi
cd $path
rm -rf $0
exit