Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

hubic-webdav-credentials

By: a guest on Nov 30th, 2012  |  syntax: Python  |  size: 2.48 KB  |  views: 406  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import httplib, urllib
  5.  
  6. class config:
  7.     ovh_host = "ws.ovh.com"
  8.  
  9. def get_webdav_info(login, password):
  10.    
  11.     ws_info={}
  12.     null = None
  13.  
  14.     # Log into CloudNAS with nasLogin and retrieve a session ID
  15.     print 'Logging into CloudNAS to retrieve a session ID...'
  16.     params = 'session=&params={"email":"%s","password":"%s"}' % (urllib.quote(login), urllib.quote(password))
  17.     headers = {"Content-type": 'application/x-www-form-urlencoded',
  18.                "User-Agent": 'hubiC/0.4.8 beta (Windows NT 6.1; fr_FR)'}
  19.     conn = httplib.HTTPSConnection(config.ovh_host)
  20.     conn.request("POST", "/cloudnas/r3/ws.dispatcher/nasLogin", params, headers)
  21.     resp = conn.getresponse()
  22.     s = resp.status
  23.     r = resp.reason
  24.     data = resp.read()
  25.     try:
  26.         d = eval(data)
  27.         sid = d['answer']['id']
  28.     except KeyError:
  29.         return ws_info
  30.     finally:
  31.         conn.close()
  32.     print '# SID:', sid
  33.    
  34.  
  35.     # POST on getNas using session ID to get URL
  36.     print 'Retrieving user-specific URL for WebDAV...'
  37.     params = 'session=%s' % sid
  38.     conn = httplib.HTTPSConnection(config.ovh_host)
  39.     conn.request("POST", "/cloudnas/r3/ws.dispatcher/getNas", params, headers)
  40.     resp = conn.getresponse()
  41.     s = resp.status
  42.     r = resp.reason
  43.     data = resp.read()
  44.     try:
  45.         d = eval(data)
  46.         ws_info['url'] = d['answer'][0]['url']
  47.     except KeyError :
  48.         return ws_info
  49.     finally:
  50.         conn.close()
  51.     print '# URL:', ws_info['url']
  52.  
  53.     # POST on getCredentials using session ID to get credentials
  54.     print 'Retrieving user-specific credentials for WebDAV...'
  55.     params = 'session=%s' % sid
  56.     conn = httplib.HTTPSConnection(config.ovh_host)
  57.     conn.request("POST", "/cloudnas/r3/ws.dispatcher/getCredentials", params, headers)
  58.     resp = conn.getresponse()
  59.     s = resp.status
  60.     r = resp.reason
  61.     data = resp.read()
  62.     try:
  63.         d = eval(data)
  64.         ws_info['login'] = d['answer']['username']
  65.         ws_info['passwd'] = d['answer']['secret']
  66.     except KeyError:
  67.         return ws_info
  68.     finally:
  69.         conn.close()
  70.     print '# Ok'
  71.  
  72.     return ws_info
  73.  
  74. if __name__ == '__main__':
  75.     import sys
  76.     import getpass
  77.     import os.path
  78.    
  79.     login = raw_input("Login: ")
  80.     password = getpass.getpass()
  81.  
  82.     ws_info = get_webdav_info(login, password)
  83.     print '''
  84.  
  85.        URL: %(url)s
  86.      login: %(login)s
  87.   password: %(passwd)s
  88.  
  89. ''' % ws_info