Class: TplinkAdmin::Client
- Inherits:
-
Object
- Object
- TplinkAdmin::Client
- Defined in:
- lib/tplink-admin/helpers/client.rb
Class Method Summary collapse
- .get(path) ⇒ Object
- .host ⇒ Object
- .password ⇒ Object
- .post(path, binary: nil) ⇒ Object
- .username ⇒ Object
Class Method Details
.get(path) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tplink-admin/helpers/client.rb', line 37 def self.get(path) uri = URI("http://#{host}/userRpm/#{path}") # Redirecionamento de portas: http://192.168.1.1/userRpm/VirtualServerRpm.htm?Port=3383&Ip=192.168.1.104&Protocol=1&State=1&Commonport=0&Changed=0&SelIndex=0&Save=Save # Reboot: http://192.168.0.2/userRpm/SysRebootRpm.htm?Reboot=Reboot req = Net::HTTP::Get.new(uri) req.basic_auth username, password res = Net::HTTP.start(uri.hostname, uri.port) {|http| http.request(req) } res end |
.host ⇒ Object
14 15 16 |
# File 'lib/tplink-admin/helpers/client.rb', line 14 def self.host Configuration.instance.url end |
.password ⇒ Object
10 11 12 |
# File 'lib/tplink-admin/helpers/client.rb', line 10 def self.password Configuration.instance.password end |
.post(path, binary: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tplink-admin/helpers/client.rb', line 18 def self.post(path, binary: nil) # curl 'http://192.168.178.1/cgi?1&5' -H 'Referer: http://192.168.178.1/' -H 'Cookie: Authorization=Basic cmVuc2hhbnJlbmhhaQ==' --data-binary $'[STAT_CFG#0,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n[STAT_ENTRY#0,0,0,0,0,0#0,0,0,0,0,0]1,0\r\n' --compressed --verbose http = Net::HTTP.new(host, 80) request = Net::HTTP::Post.new(path) request.basic_auth username, password request.body = binary request.content_type = 'text/plain' request.add_field 'Referer', "http://#{host}/" request.add_field 'Cookie', "Authorization=Basic #{password}" res = http.request(request) if res.code.to_i > 399 $stderr.puts "Invalid status code: #{res.code}" $stderr.puts res.body exit 1 end res.body end |
.username ⇒ Object
6 7 8 |
# File 'lib/tplink-admin/helpers/client.rb', line 6 def self.username Configuration.instance.username end |