Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.51 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ############################################################################
  4. # Squid Proxy Installer (SPI) #
  5. # Version: 2.0 Build 2017 #
  6. # Branch: Stable #
  7. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  8. # Author: Hidden Refuge (© 2014 - 2016) #
  9. # License: MIT License #
  10. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  11. # GitHub Repo: https://github.com/hidden-refuge/spi/ #
  12. # SPI Wiki: https://github.com/hidden-refuge/spi/wiki #
  13. ############################################################################
  14.  
  15. # Declaring a few misc variables
  16. vspiversion=2.0 # SPI version
  17. vspibuild=2017 # SPI build number
  18. vbranch=Stable # SPI build branch
  19. vsysarch=$(getconf LONG_BIT) # System architecture
  20.  
  21. # Function for iptables rules (CentOS 5 & 6)
  22. firew1 () {
  23. # Opening default Squid port 3128 for clients to connect
  24. iptables -I INPUT -p tcp --dport 3128 -j ACCEPT
  25. # Saving firewall rules
  26. service iptables save
  27. }
  28.  
  29. # Function for iptables rules (CentOS 7, Debian, Ubuntu, Fedora)
  30. firew2 () {
  31. # Opening default Squid port 3128 for clients to connect
  32. iptables -I INPUT -p tcp --dport 3128 -j ACCEPT
  33. # Saving firewall rules
  34. iptables-save
  35. }
  36.  
  37. # Function for RHEL 5 Linux distributions
  38. rhel5 () {
  39. # Downloading and installing necessary repo for newer Squid 3 versions for CentOS 5
  40. rpm -Uvh http://flexbox.sourceforge.net/centos/5/i386/flexbox-release-1-4.3.noarch.rpm
  41. # Installing necessary packages (Squid, httpd for htpasswd and dependencies)
  42. yum install perl-DBI libecap squid httpd -y
  43. # Asking user to set a username via read and writing it into $usrn
  44. read -e -p "Your desired username: " usrn
  45. # Creating user with username from $usrn and asking user to set a password
  46. htpasswd -c /etc/squid/passwd $usrn
  47. # Downloading necessary Squid.conf for the corresponding OS & system architecture
  48. case $vsysarch in
  49. 32) # 32 bit Squid configuration
  50. wget -O /etc/squid/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-rhel5632.conf --no-check-certificate;;
  51. 64) # 64 bit Squid configuration
  52. wget -O /etc/squid/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-rhel5664.conf --no-check-certificate;;
  53. esac
  54. # Creating empty blacklist.acl file for further blacklisting entries
  55. touch /etc/squid/blacklist.acl
  56. # Restarting Squid and enabling its service
  57. service squid restart && chkconfig squid on
  58. # Turning off httpd and removing it from services (post installation of yum enabled it but we don't need it)
  59. service httpd stop && chkconfig httpd off
  60. # Running function firew1
  61. firew1
  62. }
  63.  
  64. # Function for RHEL 6 Linux distributions
  65. rhel6 () {
  66. # Installing necessary packages (Squid, httpd-tools for htpasswd and dependencies)
  67. yum install squid httpd-tools -y
  68. # Asking user to set a username via read and writing it into $usrn
  69. read -e -p "Your desired username: " usrn
  70. # Creating user with username from $usrn and asking user to set a password
  71. htpasswd -c /etc/squid/passwd $usrn
  72. # Downloading necessary Squid.conf for the corresponding OS & system architecture
  73. case $vsysarch in
  74. 32) # 32 bit Squid configuration
  75. wget -O /etc/squid/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-rhel5632.conf --no-check-certificate;;
  76. 64) # 64 bit Squid configuration
  77. wget -O /etc/squid/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-rhel5664.conf --no-check-certificate;;
  78. esac
  79. # Creating empty blacklist.acl file for further blacklisting entries
  80. touch /etc/squid/blacklist.acl
  81. # Restarting Squid and enabling its service
  82. service squid restart && chkconfig squid on
  83. # Running function firew1
  84. firew1
  85. }
  86.  
  87. # Function for RHEL 7 Linux distributions
  88. rhel7 () {
  89. # Installing necessary packages (Squid, httpd-tools for htpasswd and dependencies)
  90. yum install squid httpd-tools -y
  91. # Asking user to set a username via read and writing it into $usrn
  92. read -e -p "Your desired username: " usrn
  93. # Creating user with username from $usrn and asking user to set a password
  94. htpasswd -c /etc/squid/passwd $usrn
  95. # Downloading Squid configuration
  96. wget -O /etc/squid/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-rhel7.conf --no-check-certificate
  97. # Creating empty blacklist.acl file for further blacklisting entries
  98. touch /etc/squid/blacklist.acl
  99. # Restarting Squid and enabling its service
  100. systemctl restart squid.service && systemctl enable squid.service
  101. # Running function firew2
  102. firew2
  103. }
  104.  
  105. # Function for Debian "Squeeze" 6 and Debian "Wheezy" 7
  106. deb () {
  107. # Updating package database
  108. apt-get update
  109. # Installing necessary packages (Squid, apache2-utils for htpassword and dependencies)
  110. apt-get install apache2-utils squid3 -y
  111. # Asking user to set a username via read and writing it into $usrn
  112. read -e -p "Your desired username: " usrn
  113. # Creating user with username from $usrn and asking user to set a password
  114. htpasswd -c /etc/squid3/passwd $usrn
  115. # Downloading Squid configuration
  116. wget -O /etc/squid3/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-debian.conf --no-check-certificate
  117. # Creating empty blacklist.acl file for further blacklisting entries
  118. touch /etc/squid3/blacklist.acl
  119. # Restarting Squid and enabling its service
  120. service squid3 restart && update-rc.d squid3 defaults
  121. # Running function firew2
  122. firew2
  123. }
  124.  
  125. # Function for Debian "Jessie" 8
  126. deb8 () {
  127. # Updating package database
  128. apt-get update
  129. # Installing necessary packages (Squid, apache2-utils for htpassword and dependencies)
  130. apt-get install apache2-utils squid3 -y
  131. # Asking user to set a username via read and writing it into $usrn
  132. usrn=tommy
  133. usrp=tommy
  134. # Creating user with username from $usrn and asking user to set a password
  135. htpasswd -b -c /etc/squid3/passwd $usrn $usrp
  136. # Downloading Squid configuration
  137. wget -O /etc/squid3/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-jessie.conf --no-check-certificate
  138. # Creating empty blacklist.acl file for further blacklisting entries
  139. touch /etc/squid3/blacklist.acl
  140. # Restarting Squid and enabling its service
  141. service squid3 restart && update-rc.d squid3 defaults
  142. # Running function firew2
  143. firew2
  144. }
  145.  
  146. # Function for Ubuntu
  147. ubt () {
  148. # Updating package database
  149. apt-get update
  150. # Installing necessary packages (Squid, apache2-utils for htpassword and dependencies)
  151. apt-get install apache2-utils squid3 -y
  152. # Asking user to set a username via read and writing it into $usrn
  153. read -e -p "Your desired username: " usrn
  154. # Creating user with username from $usrn and asking user to set a password
  155. htpasswd -c /etc/squid3/passwd $usrn
  156. # Downloading Squid configuration
  157. wget -O /etc/squid3/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-ubuntu.conf --no-check-certificate
  158. # Copying squid3.conf from init to init.d for startup script
  159. cp /etc/init/squid3.conf /etc/init.d/squid3
  160. # Creating empty blacklist.acl file for further blacklisting entries
  161. touch /etc/squid3/blacklist.acl
  162. # Restarting Squid and enabling its service
  163. service squid3 restart && update-rc.d squid3 defaults
  164. # Running function firew2
  165. firew2
  166. }
  167.  
  168. # Function for Fedora
  169. fed () {
  170. # Installing necessary packages (Squid, httpd-tools for htpasswd and dependencies)
  171. yum install squid httpd-tools -y
  172. # Asking user to set a username via read and writing it into $usrn
  173. read -e -p "Your desired username: " usrn
  174. # Creating user with username from $usrn and asking user to set a password
  175. htpasswd -c /etc/squid/passwd $usrn
  176. # Downloading necessary Squid.conf for the corresponding OS & system architecture
  177. case $vsysarch in
  178. 32) # 32 bit Squid configuration
  179. wget -O /etc/squid/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-fedora32.conf --no-check-certificate;;
  180. 64) # 64 bit Squid configuration
  181. wget -O /etc/squid/squid.conf https://raw.githubusercontent.com/hidden-refuge/squid-proxy-installer/master/spi-rhel7.conf --no-check-certificate;;
  182. esac
  183. # Creating empty blacklist.acl file for further blacklisting entries
  184. touch /etc/squid/blacklist.acl
  185. # Restarting Squid and enabling its service
  186. systemctl restart squid && systemctl enable squid
  187. # Running function firew2
  188. firew2
  189. }
  190.  
  191. # Default function with information
  192. dinfo () {
  193. echo "Squid Proxy Installer $vspiversion Build $vspibuild"
  194. echo "You are using builds from the $vbranch branch"
  195. echo ""
  196. echo "Usage: bash spi <option>"
  197. echo "Example (Debian 8): bash spi -jessie"
  198. echo ""
  199. echo "Options:"
  200. echo "-rhel5 -- RHEL 5 Linux distributions"
  201. echo "-rhel6 -- RHEL 6 Linux distributions"
  202. echo "-rhel7 -- RHEL 7 Linux distributions"
  203. echo "-debian -- Debian Squeeze 6 & Wheezy 7"
  204. echo "-jessie -- Debian Jessie 8"
  205. echo "-ubuntu -- Ubuntu"
  206. echo "-fedora -- Fedora"
  207. echo ""
  208. echo "How to add more users:"
  209. echo "https://github.com/hidden-refuge/spi/wiki/User-management"
  210. echo ""
  211. echo "How to blacklist domains:"
  212. echo "https://github.com/hidden-refuge/spi/wiki/Domain-blacklist"
  213. echo ""
  214. echo ""
  215. echo "(C) 2014 - 2016 by Hidden Refuge"
  216. echo "GitHub Repo: https://github.com/hidden-refuge/spi"
  217. echo "SPI Wiki: https://github.com/hidden-refuge/spi/wiki"
  218. }
  219.  
  220. # Checking $1 and running corresponding function
  221. case $1 in
  222. '-rhel5') # If option "-rhel5" run function rhel5
  223. rhel5;; # RHEL 5 Linux distributions such as Red Hat 5, CentOS 5 and et cetera
  224. '-rhel6') # If option "-rhel6" run function rhel6
  225. rhel6;; # RHEL 6 Linux distributions such as Red Hat 6, CentOS 6 and et cetera
  226. '-rhel7') # If option "-rhel7" run function rhel7
  227. rhel7;; # RHEL 7 Linux distributions such as Red Hat 7, CentOS 7 and et cetera
  228. '-debian') # If option "-debian" run fuction deb
  229. deb;; # Debian "Squeeze" 6 and Debian "Wheezy" 7
  230. '-jessie') # If option "-jessie" run function deb8
  231. deb8;; # Debian "Jessie" 8
  232. '-ubuntu') # If option "-ubuntu" run function ubt
  233. ubt;; # Ubuntu
  234. '-fedora') # If option "fedora" run function fed
  235. fed;; # Fedora
  236. *) # If option empty or non existing run function info
  237. dinfo;; # Default, information about available options and et cetera
  238. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement