Advertisement
Guest User

Untitled

a guest
Dec 31st, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. PROXY_USER=secure
  4. PROXY_PASS=test
  5. PROXY_PORT=3128
  6.  
  7. # Clear the repository index caches
  8. yum clean all
  9.  
  10. # Update the operating system
  11. yum update -y
  12.  
  13. # Install httpd-tools to get htpasswd
  14. yum install httpd-tools -y
  15.  
  16. # Install squid
  17. yum install squid -y
  18.  
  19. # Create the htpasswd file
  20. htpasswd -c -b /etc/squid/passwords $PROXY_USER $PROXY_PASS
  21.  
  22. # Backup the original squid config
  23. cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
  24.  
  25. # Set up the squid config
  26. cat << EOF > /etc/squid/squid.conf
  27. auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/passwords
  28. auth_param basic realm proxy
  29. acl authenticated proxy_auth REQUIRED
  30. http_access allow authenticated
  31. forwarded_for delete
  32. http_port 0.0.0.0:$PROXY_PORT
  33. EOF
  34.  
  35. # Set squid to start on boot
  36. chkconfig squid on
  37.  
  38. # Start squid
  39. /etc/init.d/squid start
  40.  
  41. # Set up the iptables config
  42. cat << EOF > /etc/sysconfig/iptables
  43. *filter
  44. :INPUT ACCEPT [0:0]
  45. :FORWARD ACCEPT [0:0]
  46. :OUTPUT ACCEPT [0:0]
  47. -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  48. -A INPUT -p icmp -j ACCEPT
  49. -A INPUT -i lo -j ACCEPT
  50.  
  51. #######################################################
  52. # BEGIN CUSTOM RULES
  53. #######################################################
  54.  
  55. # Allow SSH from anywhere
  56. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
  57.  
  58. # Allow squid access from anywhere
  59. -A INPUT -m state --state NEW -m tcp -p tcp --dport $PROXY_PORT -j ACCEPT
  60.  
  61. #######################################################
  62. # END CUSTOM RULES
  63. #######################################################
  64.  
  65. -A INPUT -j REJECT --reject-with icmp-host-prohibited
  66. -A FORWARD -j REJECT --reject-with icmp-host-prohibited
  67. COMMIT
  68. EOF
  69.  
  70. # Restart iptables
  71. /etc/init.d/iptables restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement