Class: RemoteHost
- Inherits:
-
Object
- Object
- RemoteHost
- Defined in:
- lib/remotehost.rb
Overview
TODO: replace RemoteHost class in SimpleHostsMonitoring library by this code
Instance Attribute Summary collapse
-
#cpu_architecture ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#cpu_load_average ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#cpu_model ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#cpu_number ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#cpu_speed ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#cpu_type ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#disk_free ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#disk_total ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#ipv6_subnet_48 ⇒ Object
Returns the value of attribute ipv6_subnet_48.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#mem_free ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#mem_total ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#net_hostname ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#net_mac_address ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#net_remote_ip ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library.
-
#ssh ⇒ Object
this is the ssh connection.
-
#ssh_password ⇒ Object
Returns the value of attribute ssh_password.
-
#ssh_port ⇒ Object
Returns the value of attribute ssh_port.
-
#ssh_username ⇒ Object
Returns the value of attribute ssh_username.
-
#stealth_browser_technology_code ⇒ Object
Returns the value of attribute stealth_browser_technology_code.
Class Method Summary collapse
- .parse(h, logger = nil) ⇒ Object
-
.valid_port_number?(n) ⇒ Boolean
TODO: mover esto al modulo BaseHost de SimpleHostMonitoring.
Instance Method Summary collapse
-
#check_all_ipv4_proxies ⇒ Object
check a list of port numbers and return the list of ports that are missconfigured return an array of errors.
-
#check_all_ipv6_proxies(proxy_port_from = DEFAULT_PROXY_PORT_FROM, proxy_port_to = DEFAULT_PROXY_PORT_TO) ⇒ Object
check a list of port numbers and return the list of ports that are missconfigured return an array of errors.
-
#get_interface_name ⇒ Object
run linux command to get the interface name TODO: validate outout.
-
#get_ipv4_proxies ⇒ Object
Parse the file /usr/local/etc/3proxy/cfg/3proxy.cfg Return an array of hash descriptors like this: :external_ip=>“185.165.34.31”.
-
#get_ipv6_proxies ⇒ Object
Parse the file /usr/local/etc/3proxy/cfg/3proxy.cfg Return an array of hash descriptors like this: :external_ip=>“2602:fed2:770f:df10:8dc9:556f:dfba:8ee3”, :subnet64=>“2602:fed2:770f:df10”.
- #get_ssh_port ⇒ Object
-
#initialize(the_logger = nil) ⇒ RemoteHost
constructor
A new instance of RemoteHost.
-
#install4(username, password, port = 3130) ⇒ Object
install ipv4 proxies.
-
#install6(proxy_port_from = DEFAULT_PROXY_PORT_FROM, proxy_port_to = DEFAULT_PROXY_PORT_TO) ⇒ Object
install ipv6 proxies raise an exception proxy_port_to is not higher than proxy_port_from.
-
#parse(h) ⇒ Object
TODO: this must be defined at module BaseHost in the SimpleHostMonitoring library.
-
#poll_thru_ssh ⇒ Object
return the same hash as the class poll() method, but connecting the server via SSH.
-
#setup_custom_ip_auth(port) ⇒ Object
setup custom IP authorization for a proxy.
-
#setup_custom_pass_auth(port) ⇒ Object
setup custom user/pass authorization for a proxy.
- #ssh_connect ⇒ Object
- #ssh_disconnect ⇒ Object
- #ssh_parameters? ⇒ Boolean
-
#start_proxies ⇒ Object
run linux command to stop the proxy server TODO: get this working TODO: validate outout.
-
#stop_proxies ⇒ Object
run linux command to stop the proxy server TODO: validate outout.
-
#to_hash ⇒ Object
TODO: this must be defined at module BaseHost in the SimpleHostMonitoring library.
Constructor Details
#initialize(the_logger = nil) ⇒ RemoteHost
Returns a new instance of RemoteHost.
9 10 11 12 |
# File 'lib/remotehost.rb', line 9 def initialize(the_logger=nil) self.logger=the_logger self.logger = BlackStack::DummyLogger.new(nil) if self.logger.nil? # assign a dummy logger that just generate output on the screen end |
Instance Attribute Details
#cpu_architecture ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def cpu_architecture @cpu_architecture end |
#cpu_load_average ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def cpu_load_average @cpu_load_average end |
#cpu_model ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def cpu_model @cpu_model end |
#cpu_number ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def cpu_number @cpu_number end |
#cpu_speed ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def cpu_speed @cpu_speed end |
#cpu_type ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def cpu_type @cpu_type end |
#disk_free ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def disk_free @disk_free end |
#disk_total ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def disk_total @disk_total end |
#ipv6_subnet_48 ⇒ Object
Returns the value of attribute ipv6_subnet_48.
5 6 7 |
# File 'lib/remotehost.rb', line 5 def ipv6_subnet_48 @ipv6_subnet_48 end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/remotehost.rb', line 7 def logger @logger end |
#mem_free ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def mem_free @mem_free end |
#mem_total ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def mem_total @mem_total end |
#net_hostname ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def net_hostname @net_hostname end |
#net_mac_address ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def net_mac_address @net_mac_address end |
#net_remote_ip ⇒ Object
TODO: this must be defined at class RemoteHost in the SimpleHostMonitoring library
4 5 6 |
# File 'lib/remotehost.rb', line 4 def net_remote_ip @net_remote_ip end |
#ssh ⇒ Object
this is the ssh connection
6 7 8 |
# File 'lib/remotehost.rb', line 6 def ssh @ssh end |
#ssh_password ⇒ Object
Returns the value of attribute ssh_password.
5 6 7 |
# File 'lib/remotehost.rb', line 5 def ssh_password @ssh_password end |
#ssh_port ⇒ Object
Returns the value of attribute ssh_port.
5 6 7 |
# File 'lib/remotehost.rb', line 5 def ssh_port @ssh_port end |
#ssh_username ⇒ Object
Returns the value of attribute ssh_username.
5 6 7 |
# File 'lib/remotehost.rb', line 5 def ssh_username @ssh_username end |
#stealth_browser_technology_code ⇒ Object
Returns the value of attribute stealth_browser_technology_code.
5 6 7 |
# File 'lib/remotehost.rb', line 5 def stealth_browser_technology_code @stealth_browser_technology_code end |
Class Method Details
.parse(h, logger = nil) ⇒ Object
57 58 59 60 61 |
# File 'lib/remotehost.rb', line 57 def self.parse(h, logger=nil) o = RemoteHost.new(logger) o.parse(h) o end |
.valid_port_number?(n) ⇒ Boolean
TODO: mover esto al modulo BaseHost de SimpleHostMonitoring
15 16 17 18 19 |
# File 'lib/remotehost.rb', line 15 def self.valid_port_number?(n) return false if !n.is_a?(Numeric) return false if n < 1 || n > 65535 true end |
Instance Method Details
#check_all_ipv4_proxies ⇒ Object
check a list of port numbers and return the list of ports that are missconfigured return an array of errors.
148 149 150 |
# File 'lib/remotehost.rb', line 148 def check_all_ipv4_proxies() # TODO: Code Me! end |
#check_all_ipv6_proxies(proxy_port_from = DEFAULT_PROXY_PORT_FROM, proxy_port_to = DEFAULT_PROXY_PORT_TO) ⇒ Object
check a list of port numbers and return the list of ports that are missconfigured return an array of errors. validate if there is more than one external ip address belonging the same /64 subnet. validate that each batch of 50 ports is all configured. raise an exception if there are ports outside the range raise an exception proxy_port_to is not higher than proxy_port_from.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/remotehost.rb', line 158 def check_all_ipv6_proxies(proxy_port_from=DEFAULT_PROXY_PORT_FROM, proxy_port_to=DEFAULT_PROXY_PORT_TO) #raise SimpleProxiesDeployingException.new(9, "#{proxy_port_from}") if proxy_port_from != DEFAULT_PROXY_PORT_FROM raise SimpleProxiesDeployingException.new(10, "#{proxy_port_from} and #{proxy_port_to}") if proxy_port_from > proxy_port_to #raise SimpleProxiesDeployingException.new(11, "from #{proxy_port_from} to #{proxy_port_to}") if (proxy_port_to-proxy_port_from+1) % DEFAULT_PROXY_PORTS_BATCH_SIZE != 0 # return this array with the list of glitches found errors = [] # record all the /64 subnets of each external ip address, to check if there is more than one external ip address belonging the same /64 subnet # records all the extenral ips of each port, to check that each batch of 50 ports is all configured, or it is empty results = self.get_ipv6_proxies # validate there is not ports outside the range a = results.select { |x| x[:port]<proxy_port_from || x[:port]>proxy_port_to }.map { |x| x[:port] } raise SimpleProxiesDeployingException.new(14, a.join(', ')) if a.size > 1 port = proxy_port_from while port <= proxy_port_to # map the external IPs to the port a = results.select { |x| x[:port] == port }.map { |x| x[:external_ip] } # validation: there is no extenral IP defined for this port # raise SimpleProxiesDeployingException.new(8) if a.size == 0 if a.size > 0 # validation: there is no more than 1 extenral IP defined for this host if a.size > 1 e = SimpleProxiesDeployingException.new(7, "#{port.to_s} - #{a.join(', ')}") errors << { :proxy_port=>port, :code=>e.code, :description=>e.description, :simple_description=>e.simple_description } end # validation: the external ip must be belonging the subnet defined at ipv6 subnet 48 if !a[0].include?(self.ipv6_subnet_48) e = SimpleProxiesDeployingException.new(6, "#{a[0]} and #{self.ipv6_subnet_48}") errors << { :proxy_port=>port, :code=>e.code, :description=>e.description, :simple_description=>e.simple_description } end end # if a.size > 0 port += 1 end # validation: there is more than one external ip address belonging the same /64 subnet. self.logger.logs 'Check duplicated /64 subnets... ' i = 0 results.each { |r| if !r[:external_ip].nil? b = results.select { |s| s[:port]!=r[:port] && s[:subnet64]==r[:subnet64] } if b.size > 1 e = SimpleProxiesDeployingException.new(12, b.join(', ')) errors << { :proxy_port=>r[:port], :code=>e.code, :description=>e.description, :simple_description=>e.simple_description } i += 1 end end # if !r[:external_ip].nil? } self.logger.logf "done (#{i.to_s} errors)" # return errors end |
#get_interface_name ⇒ Object
run linux command to get the interface name TODO: validate outout
225 226 227 228 229 |
# File 'lib/remotehost.rb', line 225 def get_interface_name() # validation: this host must have ssh connection raise SimpleProxiesDeployingException.new(3) if !self.ssh ssh.exec!("ip -o -4 route show to default | awk '{print $5}' | sed 1'!d'").strip end |
#get_ipv4_proxies ⇒ Object
Parse the file /usr/local/etc/3proxy/cfg/3proxy.cfg Return an array of hash descriptors like this: :external_ip=>“185.165.34.31”
116 117 118 |
# File 'lib/remotehost.rb', line 116 def get_ipv4_proxies() # TODO: Code Me! end |
#get_ipv6_proxies ⇒ Object
Parse the file /usr/local/etc/3proxy/cfg/3proxy.cfg Return an array of hash descriptors like this: :external_ip=>“2602:fed2:770f:df10:8dc9:556f:dfba:8ee3”, :subnet64=>“2602:fed2:770f:df10”
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/remotehost.rb', line 122 def get_ipv6_proxies() # validation: this host must have defined an ipv6 subnet 48 raise SimpleProxiesDeployingException.new(5) if !self.ipv6_subnet_48 # validation: this host must have ssh connection raise SimpleProxiesDeployingException.new(3) if !self.ssh results = [] stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'grep \"proxy -p\" /usr/local/etc/3proxy/cfg/3proxy.cfg'") a = stdout.split("\n") # stdout.scan(MATCH_IPV6_STANDARD) a.select { |x| # filter all the IPv6 proxies x.include?('-6') }.each { |x| # example: proxy -p4245 -6 -a -n -i0.0.0.0 -e2602:fed2:770f:e75c:dc88:fab6:7623:1f47 port = x.scan(MATCH_PORT_IN_3PROXY_CONF)[0].gsub(/\-p/, '') external_ip = x.scan(MATCH_IPV6_STANDARD)[0] subnet64 = external_ip.scan(MATCH_IPV6_64_SUBNET_STANDARD)[0] results << { :port => port.to_i, :external_ip => external_ip.to_s, :subnet64 => subnet64.to_s } } results end |
#get_ssh_port ⇒ Object
99 100 101 |
# File 'lib/remotehost.rb', line 99 def get_ssh_port() self.ssh_port.nil? ? 22 : self.ssh_port end |
#install4(username, password, port = 3130) ⇒ Object
install ipv4 proxies
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/remotehost.rb', line 261 def install4(username, password, port=3130) #raise SimpleProxiesDeployingException.new(9, "#{proxy_port_from}") if proxy_port_from != DEFAULT_PROXY_PORT_FROM #raise SimpleProxiesDeployingException.new(10, "#{proxy_port_from} and #{proxy_port_to}") if proxy_port_from > proxy_port_to #raise SimpleProxiesDeployingException.new(11, "from #{proxy_port_from} to #{proxy_port_to}") if (proxy_port_to-proxy_port_from+1) % DEFAULT_PROXY_PORTS_BATCH_SIZE != 0 # TODO: validate the output logger.logs "Get interface name... " interface = self.get_interface_name logger.done #logf "done (#{interface})" logger.logs "Get server main ip from configuration... " mainip = self.net_remote_ip logger.done #logf "done (#{mainip})" # TODO: validate the output logger.logs "Install packages... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c ' apt-get install nano apt-get update apt-get autoremove -y apt-get autoclean -y apt-get clean -y apt-get install fail2ban software-properties-common -y apt-get install build-essential libevent-dev libssl-dev -y apt-get install ethtool -y apt-get install curl -y '") logger.done #logf "done (#{stdout})" # TODO: validate the output logger.logs "Install 3proxy... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c ' cd /usr/local/etc wget https://github.com/z3APA3A/3proxy/archive/0.8.12.tar.gz tar zxvf 0.8.12.tar.gz rm 0.8.12.tar.gz mv 3proxy-0.8.12 3proxy cd 3proxy make -f Makefile.Linux make -f Makefile.Linux install mkdir log cd cfg '") logger.done #logf "done (#{stdout})" # TODO: validate the output logger.logs "Setup 3proxy.cfg... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c ' echo \"#!/usr/local/bin/3proxy daemon pidfile /usr/local/etc/3proxy/3proxy.pid nserver 1.1.1.1 nserver 1.0.0.1 nscache 65536 timeouts 1 5 30 60 180 1800 15 60 log /usr/local/etc/3proxy/log/3proxy.log D logformat \\\"- +_L%t.%. %N.%p %E %U %C:%c %R:%r %O %I %h %T\\\" archiver rar rar a -df -inul %A %F rotate 30 internal 0.0.0.0 external 0.0.0.0 authcache ip 60 users #{username}:CL:#{password} auth strong allow #{username} proxy -p#{port} -a -n \" > /usr/local/etc/3proxy/cfg/3proxy.cfg'") logger.done #logf "done (#{stdout})" logger.logs "Start proxy service... " self.start_proxies logger.done end |
#install6(proxy_port_from = DEFAULT_PROXY_PORT_FROM, proxy_port_to = DEFAULT_PROXY_PORT_TO) ⇒ Object
install ipv6 proxies raise an exception proxy_port_to is not higher than proxy_port_from.
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/remotehost.rb', line 339 def install6(proxy_port_from=DEFAULT_PROXY_PORT_FROM, proxy_port_to=DEFAULT_PROXY_PORT_TO) #raise SimpleProxiesDeployingException.new(9, "#{proxy_port_from}") if proxy_port_from != DEFAULT_PROXY_PORT_FROM raise SimpleProxiesDeployingException.new(10, "#{proxy_port_from} and #{proxy_port_to}") if proxy_port_from > proxy_port_to #raise SimpleProxiesDeployingException.new(11, "from #{proxy_port_from} to #{proxy_port_to}") if (proxy_port_to-proxy_port_from+1) % DEFAULT_PROXY_PORTS_BATCH_SIZE != 0 # TODO: validate the output logger.logs "Get interface name... " interface = self.get_interface_name logger.logf "done (#{interface})" logger.logs "Get server main ip from configuration... " mainip = self.net_remote_ip logger.logf "done (#{mainip})" logger.logs "Install ethtool... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'apt-get install ethtool'") logger.done # get list of 4-hex-digits subnets logger.logs "Initialize list of 4-hex-digit numbers... " hex4digits = [] "123456789ABCDEF".split('').each { |a| # don't inclulude codes with leading 0, in order to get codes that are 4 digits even in STANDARD notation "0123456789ABCDEF".split('').each { |b| "0123456789ABCDEF".split('').each { |c| "0123456789ABCDEF".split('').each { |d| hex4digits << "#{a}#{b}#{c}#{d}".downcase } } } } logger.logf "done (#{hex4digits.size} numbers)" logger.logs "Shuffle list of 4-hex-digit numbers... " hex4digits.shuffle! logger.logf "done (#{hex4digits[0]}, #{hex4digits[1]}, #{hex4digits[2]}, ...)" logger.logs "Initialize list proxies... " results = get_ipv6_proxies logger.logf "done (#{results.size} ports)" # TODO: validate the output logger.logs "Install ethtool... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'apt-get install ethtool'") logger.done # TODO: validate the output logger.logs "Install curl... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'apt-get install curl'") logger.done logger.logs "Stop proxy server... " stdout = self.stop_proxies logger.done #logf "done (#{stdout})" # TODO: validate this output logger.logs "Add /48 subnet to interface... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'ifconfig #{interface} add #{self.ipv6_subnet_48}::/48'") logger.done #logf "done (#{stdout})" # TODO: validate this output logger.logs "Add default route for IPv6... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'ip -6 route add default via #{self.ipv6_subnet_48}::1'") logger.done #logf "done (#{stdout})" # TODO: validate this output logger.logs "Setup /etc/network.conf... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'echo \"ifconfig #{interface} add #{self.ipv6_subnet_48}::/48 ip -6 route add default via #{self.ipv6_subnet_48}::1\" >> /etc/network.conf'") logger.done #.logf "done (#{stdout})" # TODO: validate this output logger.logs "Remove exit 0 FROM rc.local... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c \"sed -i '/exit 0/d' /etc/rc.local\"") logger.done #.logf "done (#{stdout})" # TODO: validate this output logger.logs "Remove exit 0 FROM rc.local... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'echo \"bash /etc/network.conf\" >> /etc/rc.local'") logger.done #.logf "done (#{stdout})" logger.logs "Remove not available /64 subnets... " available_hex4digits = hex4digits.reject { |hex| results.map { |result| result[:subnet64] }.include?("#{self.ipv6_subnet_48}:#{hex}") } logger.logf("done (#{available_hex4digits.size})") logger.logs "Iterate ports... " port = proxy_port_from while port<=proxy_port_to logger.logs "Checking port #{port}... " if results.map { |result| result[:port].to_i }.include?(port) logger.logf "done (already installed)" else #logger.logs "Get an available subnet64... " hex = available_hex4digits[0] subnet64 = "#{self.ipv6_subnet_48}:#{hex}" #logger.logf "done (#{subnet64})" #logger.logs "Remove #{subnet64} from list of available subnets64... " available_hex4digits.reject! { |x| x == hex } #logger.logf("done (#{available_hex4digits.size})") #logger.logs "Build random IPv6... " ipv6 = "#{subnet64}:#{hex4digits.shuffle[0]}:#{hex4digits.shuffle[0]}:#{hex4digits.shuffle[0]}:#{hex4digits.shuffle[0]}" #logger.logf("done (#{ipv6})") #logger.logs "Add record to configuration file... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'echo proxy -p#{port} -6 -a -n -i0.0.0.0 -e#{ipv6} >> /usr/local/etc/3proxy/cfg/3proxy.cfg'") #logger.logf("done (#{stdout})") #logger.logs "Add IPv6 address... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'ip address add #{ipv6} dev #{interface} > /dev/null 2>&1'") #logger.logf("done (#{stdout})") logger.logf('done (installed)') end port += 1 end # TODO: validate this output logger.logs "Start proxy server... " stdout = self.start_proxies logger.done #logf "done (#{stdout})" # TODO: validate this output logger.logs "Add exit 0 TO rc.local... " stdout = ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'echo \"exit 0\" >> /etc/rc.local'") logger.logf "done (#{stdout})" end |
#parse(h) ⇒ Object
TODO: this must be defined at module BaseHost in the SimpleHostMonitoring library
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/remotehost.rb', line 29 def parse(h) # parameters regarding the current status of the host self.cpu_architecture = h[:cpu_architecture] self.cpu_speed = h[:cpu_speed] self.cpu_load_average = h[:cpu_load_average] self.cpu_model = h[:cpu_model] self.cpu_type = h[:cpu_type] self.cpu_number = h[:cpu_number] self.mem_total = h[:mem_total] self.mem_free = h[:mem_free] self.disk_total = h[:disk_total] self.disk_free = h[:disk_free] self.net_hostname = h[:net_hostname] self.net_mac_address = h[:net_mac_address] # parameters regarding the remote controling of the server self.net_remote_ip = h[:net_remote_ip] self.ssh_username = h[:ssh_username] self.ssh_password = h[:ssh_password] self.ssh_port = h[:ssh_port] # StealthBrowserAutomation monkey-patch add-on: parameters regarding the usage of stealth browser for automation self.stealth_browser_technology_code = h[:stealth_browser_technology_code] # SimpleProxyServer monkey-patch add-on: paremeters regarding the installation of proxies self.ipv6_subnet_48 = h[:ipv6_subnet_48] end |
#poll_thru_ssh ⇒ Object
return the same hash as the class poll() method, but connecting the server via SSH. we are assuming the server is a Linux server. TODO: write the list of software packages that server must have installed.
24 25 26 |
# File 'lib/remotehost.rb', line 24 def poll_thru_ssh() # TODO: code me! end |
#setup_custom_ip_auth(port) ⇒ Object
setup custom IP authorization for a proxy
250 251 252 |
# File 'lib/remotehost.rb', line 250 def setup_custom_ip_auth(port) # TODO: Code Me! end |
#setup_custom_pass_auth(port) ⇒ Object
setup custom user/pass authorization for a proxy
255 256 257 |
# File 'lib/remotehost.rb', line 255 def setup_custom_pass_auth(port) # TODO: Code Me! end |
#ssh_connect ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/remotehost.rb', line 103 def ssh_connect() # validation: this host must have ssh parameters raise SimpleProxiesDeployingException.new(1) if !self.ssh_parameters? # connect self.ssh = Net::SSH.start(self.net_remote_ip, self.ssh_username, :password => self.ssh_password, :port => self.get_ssh_port) # validation: the connection must be established raise SimpleProxiesDeployingException.new(4) if !self.ssh end |
#ssh_disconnect ⇒ Object
472 473 474 |
# File 'lib/remotehost.rb', line 472 def ssh_disconnect() self.ssh.close end |
#ssh_parameters? ⇒ Boolean
95 96 97 |
# File 'lib/remotehost.rb', line 95 def ssh_parameters? self.net_remote_ip && self.ssh_username && self.ssh_password end |
#start_proxies ⇒ Object
run linux command to stop the proxy server TODO: get this working TODO: validate outout
242 243 244 245 246 |
# File 'lib/remotehost.rb', line 242 def start_proxies() # validation: this host must have ssh connection raise SimpleProxiesDeployingException.new(3) if !self.ssh ssh.exec!("echo '#{self.ssh_password.gsub("'", "\\'")}' | sudo -S su root -c 'sh /usr/local/etc/3proxy/scripts/rc.d/proxy.sh start > /dev/null 2>&1'") end |
#stop_proxies ⇒ Object
run linux command to stop the proxy server TODO: validate outout
233 234 235 236 237 |
# File 'lib/remotehost.rb', line 233 def stop_proxies() # validation: this host must have ssh connection raise SimpleProxiesDeployingException.new(3) if !self.ssh ssh.exec!("sh /usr/local/etc/3proxy/scripts/rc.d/proxy.sh stop > /dev/null 2>&1") end |
#to_hash ⇒ Object
TODO: this must be defined at module BaseHost in the SimpleHostMonitoring library
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 89 90 91 92 |
# File 'lib/remotehost.rb', line 64 def to_hash { # parameters regarding the current status of the host :cpu_architecture => self.cpu_architecture, :cpu_speed => self.cpu_speed, :cpu_load_average => self.cpu_load_average, :cpu_model => self.cpu_model, :cpu_type => self.cpu_type, :cpu_number => self.cpu_number, :mem_total => self.mem_total, :mem_free => self.mem_free, :disk_total => self.disk_total, :disk_free => self.disk_free, :net_hostname => self.net_hostname, :net_remote_ip => self.net_remote_ip, :net_mac_address => self.net_mac_address, # parameters regarding the remote controling of the server :ssh_username => self.ssh_username, :ssh_password => self.ssh_password, :ssh_port => self.ssh_port, # StealthBrowserAutomation monkey-patch add-on: parameters regarding the usage of stealth browser for automation :stealth_browser_technology_code => self.stealth_browser_technology_code, # SimpleProxyServer monkey-patch add-on: paremeters regarding the installation of proxies :ipv6_subnet_48 => self.ipv6_subnet_48, } end |