SHARE
TWEET

Untitled

a guest Jun 18th, 2017 58 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.    
  27.     while code == '200' and count < MAX_RUNS
  28.        
  29.         sleep(1)
  30.         p count
  31.  
  32.         # call the server with the cookie in the request to set it in the user cache on the server
  33.         Net::HTTP.start(SERVER, PORT) do |http|
  34.             headers = {'Cookie' => cookie_header}
  35.             req = Net::HTTP::Head.new(PATH, headers)
  36.             req.basic_auth(USER, PASS)
  37.             res = http.request(req)
  38.  
  39.             # call the server to verify the cookie is valid
  40.             if res.code == '200'
  41.                 req = Net::HTTP::Head.new('/var/cluster/user.cookie.json?c=' + cookie_val, headers)
  42.                 req.basic_auth(USER, PASS)
  43.                 res = http.request(req)
  44.                 code = res.code
  45.                 count += 1
  46.             end
  47.         end
  48.     end
  49. 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