config_relay.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/bash
  2. echo "Autonconfigure relay v1.0"
  3. if (( $EUID != 0 )); then
  4. echo "This must be run as root. Try 'sudo bash $0'."
  5. exit 1
  6. fi
  7. function hotspot_(){
  8. echo -e "$(tput setaf 6)flush iptables:$(tput sgr0)"
  9. iptables -F
  10. iptables -S
  11. cp iptables/iptables.ipv4.nat_hotspot /etc/iptables.ipv4.nat
  12. echo -e "$(tput setaf 6)\nactivate rules:$(tput sgr0)"
  13. iptables-restore </etc/iptables.ipv4.nat
  14. iptables -S
  15. echo -e "$(tput setaf 6)\nDone !$(tput sgr0)\n"
  16. exit
  17. }
  18. function openvpn_(){
  19. echo -e -n "Check openVPN installed : "
  20. if ! [ -x "$(command -v openvpn)" ]
  21. then
  22. echo -e "[\e[91m NO \e[0m]" && apt-get install openvpn -y
  23. update-rc.d -f openvpn remove
  24. else
  25. echo -e "[\e[92m OK \e[0m]"
  26. fi
  27. echo -e "$(tput setaf 6)\nflush iptables:$(tput sgr0)"
  28. iptables -F
  29. iptables -S
  30. cp iptables/iptables.ipv4.nat_openvpn /etc/iptables.ipv4.nat
  31. echo -e "$(tput setaf 6)\nactivate rules:$(tput sgr0)"
  32. iptables-restore </etc/iptables.ipv4.nat
  33. iptables -S
  34. ME=$(who -m | awk '{print $1;}')
  35. echo -e "$(tput setaf 6)\ndo not forget to copy your openvpn config ! (copy to /home/$ME/)$(tput sgr0)"
  36. sleep 2
  37. if [ -f /home/$ME/config.ovpn ]
  38. then
  39. echo -e "$(tput setaf 6)\nFile exist we can start openvpn ! $(tput sgr0)"
  40. echo -e "sudo openvpn --config /home/$ME/config.ovpn --daemon"
  41. STATUS="$(systemctl is-active --quiet openvpn)"
  42. if [ "${STATUS}" = "active" ]; then killall -9 openvpn ;fi
  43. sudo openvpn --config /home/$ME/config.ovpn --daemon
  44. fi
  45. echo -e "$(tput setaf 6)\nDone !$(tput sgr0)\n"
  46. exit
  47. }
  48. function tor_(){
  49. echo -e -n "Check if Tor isinstalled : "
  50. if ! [ -x "$(command -v tor)" ]
  51. then
  52. echo -e "[\e[91m NO \e[0m]" && apt-get install tor -y
  53. else
  54. echo -e "[\e[92m OK \e[0m]"
  55. fi
  56. if ! [ -f /etc/tor/torrc.bak ]
  57. then
  58. cp /etc/tor/torrc /etc/tor/torrc.bak
  59. fi
  60. cp /etc/tor/torrc.bak /etc/tor/torrc
  61. echo "Log notice file /var/log/tor/notices.log
  62. VirtualAddrNetwork 10.192.0.0/10
  63. AutomapHostsSuffixes .onion,.exit
  64. AutomapHostsOnResolve 1
  65. TransPort 192.168.4.1:9040
  66. DNSPort 192.168.4.1:53" >> /etc/tor/torrc
  67. echo "$(tput setaf 6)Setting up logging in /var/log/tor/notices.log...$(tput sgr0)"
  68. touch /var/log/tor/notices.log
  69. chown debian-tor /var/log/tor/notices.log
  70. chmod 644 /var/log/tor/notices.log
  71. echo -e "$(tput setaf 6)\nflush iptables:$(tput sgr0)"
  72. iptables -F
  73. iptables -t nat -F
  74. iptables -S
  75. echo -e "$(tput setaf 6)\nactivate rules:$(tput sgr0)"
  76. iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 22 -j REDIRECT --to-ports 22
  77. iptables -t nat -A PREROUTING -i wlan0 -p udp --dport 53 -j REDIRECT --to-ports 53
  78. iptables -t nat -A PREROUTING -i wlan0 -p tcp --syn -j REDIRECT --to-ports 9040
  79. sh -c "iptables-save > /etc/iptables.ipv4.nat"
  80. update-rc.d tor remove
  81. service tor start
  82. echo -e "$(tput setaf 6)\nDone !$(tput sgr0)\n"
  83. exit
  84. }
  85. function wireguard_(){
  86. echo -e -n "Check Wireguard is installed : "
  87. if ! [ -x "$(command -v wg)" ]
  88. then
  89. echo -e "[\e[91m NO \e[0m]" && apt-get install wirehuard -y
  90. update-rc.d -f wg remove
  91. else
  92. echo -e "[\e[92m OK \e[0m]"
  93. fi
  94. iptables -A FORWARD -i wlan0 -o wg0 -j ACCEPT
  95. iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
  96. iptables -A FORWARD -i wg0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  97. echo -e "$(tput setaf 6)\ndo not forget to copy your Wireguard config ! (copy to /etc/wireguard/wg0.conf)$(tput sgr0)"
  98. if [ /etc/wireguard/wg0.conf ]
  99. then
  100. echo -e "$(tput setaf 6)\nFile exist we can start wireguard ! $(tput sgr0)"
  101. wg-quick up wg0
  102. wg
  103. fi
  104. exit
  105. }
  106. PS3='Please enter your choice: '
  107. select item in "Hotspot" "OpenVPN" "Wireguard" "Tor" "quit"
  108. do
  109. case $REPLY in
  110. 1)
  111. echo -e "$(tput setaf 1)\nHotspot:$(tput sgr0)"
  112. hotspot_
  113. ;;
  114. 2)
  115. echo -e "$(tput setaf 1)\nOpenVPN:$(tput sgr0)"
  116. openvpn_
  117. ;;
  118. 3)
  119. echo -e "$(tput setaf 1)\nWireguard:$(tput sgr0)"
  120. wireguard_
  121. ;;
  122. 4)
  123. echo -e "$(tput setaf 1)\nTor:$(tput sgr0)"
  124. tor_
  125. ;;
  126. 5)
  127. break
  128. ;;
  129. *) echo "invalid option $REPLY";;
  130. esac
  131. done