daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Jun 18th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/ruby
  2.  
  3. require 'net/http'
  4.  
  5. # connectivity information
  6. SERVER = 'localhost'
  7. PORT = 8080
  8. PATH = '/dev/'
  9. USER = 'admin'
  10. PASS = 'admin'
  11.  
  12. # processing information
  13. MAX_RUNS = 10
  14.  
  15. # make a call to the server to have the cookie set
  16. res = Net::HTTP.get_response(SERVER, PATH, PORT)
  17.  
  18. if res.code == '200'
  19.     cookie_header = res['Set-Cookie']
  20.     eq_pos = cookie_header.index '='
  21.     sc_pos = cookie_header.index ';'
  22.     cookie_val = cookie_header[eq_pos + 1..sc_pos - 1]
  23.  
  24.     code = res.code
  25.     count = 0
  26.     while code == '200' and count < MAX_RUNS
  27.        
  28.         sleep(1)
  29.         p count
  30.        
  31.         Net::HTTP.start(SERVER, PORT) do |http|
  32.             headers = {'Cookie' => cookie_header}
  33.             req = Net::HTTP::Head.new(PATH, headers)
  34.             req.basic_auth(USER, PASS)
  35.             res = http.request(req)
  36.  
  37.             if res.code == '200'
  38.                 req = Net::HTTP::Head.new('/var/cluster/user.cookie.json?c=' + cookie_val, headers)
  39.                 req.basic_auth(USER, PASS)
  40.                 res = http.request(req)
  41.                 code = res.code
  42.                 count += 1
  43.             end
  44.         end
  45.     end
  46. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top