Exemple #1
0
 def get_webclient(self):
     cv = self.ipmicmd.certverify
     wc = webclient.SecureHTTPConnection(self.imm, 443, verifycallback=cv)
     try:
         wc.connect()
     except Exception:
         return None
     adata = json.dumps({
         'username': self.username,
         'password': self.password
     })
     headers = {
         'Connection': 'keep-alive',
         'Content-Type': 'application/json'
     }
     wc.request('POST', '/api/login', adata, headers)
     rsp = wc.getresponse()
     if rsp.status == 200:
         rspdata = json.loads(rsp.read())
         wc.set_header('Content-Type', 'application/json')
         wc.set_header('Authorization', 'Bearer ' + rspdata['access_token'])
         if '_csrf_token' in wc.cookies:
             wc.set_header('X-XSRF-TOKEN', wc.cookies['_csrf_token'])
         return wc
Exemple #2
0
 def get_webclient(self):
     cv = self.ipmicmd.certverify
     wc = webclient.SecureHTTPConnection(self.imm, 443, verifycallback=cv)
     try:
         wc.connect()
     except Exception:
         return None
     adata = urllib.urlencode({'user': self.username,
                               'password': self.password,
                               'SessionTimeout': 60
                               })
     headers = {'Connection': 'keep-alive',
                'Referer': 'https://{0}/designs/imm/index.php'.format(
                    self.imm),
                'Content-Type': 'application/x-www-form-urlencoded'}
     wc.request('POST', '/data/login', adata, headers)
     rsp = wc.getresponse()
     if rsp.status == 200:
         rspdata = json.loads(rsp.read())
         if rspdata['authResult'] == '0' and rspdata['status'] == 'ok':
             if 'token2_name' in rspdata and 'token2_value' in rspdata:
                 wc.set_header(rspdata['token2_name'],
                               rspdata['token2_value'])
             return wc
Exemple #3
0
import json
import os
import sys

missingargs = False
if 'XCCUSER' not in os.environ:
    print('Must set XCCUSER environment variable')
    missingargs = True
if 'XCCPASS' not in os.environ:
    print('Must set XCCPASS environment variable')
    missingargs = True
if missingargs:
    sys.exit(1)

w = webclient.SecureHTTPConnection(sys.argv[1],
                                   443,
                                   verifycallback=lambda x: True)
w.connect()
adata = json.dumps({
    'username': os.environ['XCCUSER'],
    'password': os.environ['XCCPASS']
})
headers = {'Connection': 'keep-alive', 'Content-Type': 'application/json'}
w.request('POST', '/api/login', adata, headers)
rsp = w.getresponse()
if rsp.status == 200:
    rspdata = json.loads(rsp.read())
    w.set_header('Content-Type', 'application/json')
    w.set_header('Authorization', 'Bearer ' + rspdata['access_token'])
    if '_csrf_token' in w.cookies:
        w.set_header('X-XSRF-TOKEN', w.cookies['_csrf_token'])