install.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/sh
  2. random() {
  3. tr </dev/urandom -dc A-Za-z0-9 | head -c5
  4. echo
  5. }
  6. array=(1 2 3 4 5 6 7 8 9 0 a b c d e f)
  7. gen64() {
  8. ip64() {
  9. echo "${array[$RANDOM % 16]}${array[$RANDOM % 16]}${array[$RANDOM % 16]}${array[$RANDOM % 16]}"
  10. }
  11. echo "$1:$(ip64):$(ip64):$(ip64):$(ip64)"
  12. }
  13. install_3proxy() {
  14. echo "installing 3proxy"
  15. URL="https://github.com/z3APA3A/3proxy/archive/3proxy-0.8.6.tar.gz"
  16. wget -qO- $URL | bsdtar -xvf-
  17. cd 3proxy-3proxy-0.8.6
  18. make -f Makefile.Linux
  19. mkdir -p /usr/local/etc/3proxy/{bin,logs,stat}
  20. cp src/3proxy /usr/local/etc/3proxy/bin/
  21. cp ./scripts/rc.d/proxy.sh /etc/init.d/3proxy
  22. chmod +x /etc/init.d/3proxy
  23. chkconfig 3proxy on
  24. cd $WORKDIR
  25. }
  26. gen_3proxy() {
  27. cat <<EOF
  28. daemon
  29. maxconn 1000
  30. nscache 65536
  31. timeouts 1 5 30 60 180 1800 15 60
  32. setgid 65535
  33. setuid 65535
  34. flush
  35. auth strong
  36. users $(awk -F "/" 'BEGIN{ORS="";} {print $1 ":CL:" $2 " "}' ${WORKDATA})
  37. $(awk -F "/" '{print "auth strong\n" \
  38. "allow " $1 "\n" \
  39. "proxy -6 -n -a -p" $4 " -i" $3 " -e"$5"\n" \
  40. "flush\n"}' ${WORKDATA})
  41. EOF
  42. }
  43. gen_proxy_file_for_user() {
  44. cat >proxy.txt <<EOF
  45. $(awk -F "/" '{print $3 ":" $4 ":" $1 ":" $2 }' ${WORKDATA})
  46. EOF
  47. }
  48. upload_proxy() {
  49. local PASS=$(random)
  50. zip --password $PASS proxy.zip proxy.txt
  51. URL=$(curl -s --upload-file proxy.zip https://transfer.sh/proxy.zip)
  52. echo "Proxy is ready! Format IP:PORT:LOGIN:PASS"
  53. echo "Download zip archive from: ${URL}"
  54. echo "Password: ${PASS}"
  55. }
  56. gen_data() {
  57. seq $FIRST_PORT $LAST_PORT | while read port; do
  58. echo "usr$(random)/pass$(random)/$IP4/$port/$(gen64 $IP6)"
  59. done
  60. }
  61. gen_iptables() {
  62. cat <<EOF
  63. $(awk -F "/" '{print "iptables -I INPUT -p tcp --dport " $4 " -m state --state NEW -j ACCEPT"}' ${WORKDATA})
  64. EOF
  65. }
  66. # run `ifconifg -a` to get eth device name to replace ens3
  67. # or https://superuser.com/questions/203272/list-only-the-device-names-of-all-available-network-interfaces
  68. gen_ifconfig() {
  69. cat <<EOF
  70. $(awk -F "/" '{print "ifconfig ens3 inet6 add " $5 "/64"}' ${WORKDATA})
  71. EOF
  72. }
  73. echo "installing apps"
  74. yum -y install gcc net-tools bsdtar zip >/dev/null
  75. install_3proxy
  76. echo "working folder = /home/proxy-installer"
  77. WORKDIR="/home/proxy-installer"
  78. WORKDATA="${WORKDIR}/data.txt"
  79. mkdir $WORKDIR && cd $_
  80. IP4=$(curl -4 -s icanhazip.com)
  81. IP6=$(curl -6 -s icanhazip.com | cut -f1-4 -d':')
  82. echo "Internal ip = ${IP4}. Exteranl sub for ip6 = ${IP6}"
  83. echo "How many proxy do you want to create? Example 500"
  84. read COUNT
  85. FIRST_PORT=10000
  86. LAST_PORT=$(($FIRST_PORT + $COUNT))
  87. gen_data >$WORKDIR/data.txt
  88. gen_iptables >$WORKDIR/boot_iptables.sh
  89. gen_ifconfig >$WORKDIR/boot_ifconfig.sh
  90. chmod +x ${WORKDIR}/boot_*.sh /etc/rc.local
  91. gen_3proxy >/usr/local/etc/3proxy/3proxy.cfg
  92. cat >>/etc/rc.local <<EOF
  93. bash ${WORKDIR}/boot_iptables.sh
  94. bash ${WORKDIR}/boot_ifconfig.sh
  95. ulimit -n 10048
  96. service 3proxy start
  97. EOF
  98. chmod +x ${WORKDIR}/boot_*.sh /etc/rc.local
  99. bash /etc/rc.local
  100. gen_proxy_file_for_user
  101. upload_proxy