Class: Proproxy::Server
Instance Method Summary collapse
- #clear_squid_cache ⇒ Object
- #configure_ip_table ⇒ Object
-
#initialize(os_name, ip, port, options = {}) ⇒ Server
constructor
A new instance of Server.
- #provision ⇒ Object
- #restart_squid ⇒ Object
- #start_squid ⇒ Object
- #stop_squid ⇒ Object
- #update_ip_table(ip_v4, port, with_ssh_port: true) ⇒ Object
Constructor Details
#initialize(os_name, ip, port, options = {}) ⇒ Server
Returns a new instance of Server.
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 |
# File 'lib/proproxy.rb', line 17 def initialize(os_name, ip, port, ={}) # TODO: enable to choose even if the server is not ubuntu # unless AVAILABLE_OS_NAME.include? os_name # raise InvalidServerNameError.new 'invalid os name' # end ssh_path = if [:ssh_path].nil? '~/.ssh/id_rsa' else [:ssh_path] end username = if [:username].nil? 'root' else [:username] end SSHKit.config.output_verbosity = Logger::DEBUG @remote_host = SSHKit::Host.new(ip) @remote_host.user = username @remote_host. = { keys: [ ssh_path ], auth_methods: %w(publickey) } end |
Instance Method Details
#clear_squid_cache ⇒ Object
108 109 110 111 112 |
# File 'lib/proproxy.rb', line 108 def clear_squid_cache on @remote_host do execute 'squid -z' end end |
#configure_ip_table ⇒ Object
90 91 92 93 94 |
# File 'lib/proproxy.rb', line 90 def configure_ip_table on @remote_host do execute 'iptables-restore < /etc/sysconfig/iptables' end end |
#provision ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/proproxy.rb', line 45 def provision on @remote_host do execute 'sudo apt-get update -y' execute 'sudo apt-get install squid -y' execute 'mkdir /etc/sysconfig/' execute 'touch /etc/sysconfig/iptables' end copy_template end |
#restart_squid ⇒ Object
55 56 57 58 |
# File 'lib/proproxy.rb', line 55 def restart_squid stop_squid start_squid end |
#start_squid ⇒ Object
102 103 104 105 106 |
# File 'lib/proproxy.rb', line 102 def start_squid on @remote_host do execute 'service squid start' end end |
#stop_squid ⇒ Object
96 97 98 99 100 |
# File 'lib/proproxy.rb', line 96 def stop_squid on @remote_host do execute 'service squid stop' end end |
#update_ip_table(ip_v4, port, with_ssh_port: true) ⇒ Object
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 |
# File 'lib/proproxy.rb', line 60 def update_ip_table(ip_v4, port, with_ssh_port: true) new_tonnel = "-A FWINPUT -p tcp -m tcp --dport #{port} -s #{ip_v4} -j ACCEPT" new_port = "http_port #{port}" new_src = "acl myacl src #{ip_v4}/255.255.255.255" remove_last_2_line on @remote_host do execute "echo #{new_tonnel} >> /etc/sysconfig/iptables" execute "echo #{new_port} >> /etc/squid/squid.conf" execute "echo #{new_src} >> /etc/squid/squid.conf" end add_icmp_host_prohibited_line add_last_commit_line_command if with_ssh_port ssh_tonnel = "-A FWINPUT -p tcp -m tcp --dport 22 -s #{ip_v4} -j ACCEPT" ssh_port = "http_port 22" remove_last_2_line on @remote_host do execute "echo #{ssh_tonnel} >> /etc/sysconfig/iptables" execute "echo #{ssh_port} >> /etc/squid/squid.conf" end add_icmp_host_prohibited_line add_last_commit_line_command end allow_specified_src configure_ip_table restart_squid end |