Ejemplo n.º 1
0
	def start(self):
		
		# check if we already have a thread initialised
		# if we do, make sure the websocket is closed so the thread joins the main thread
		if self.wst != None:
			while self.wst.isAlive():
				self.ws.close()
		
		# set up the websocket
		self.ws = websocket.WebSocketApp(self.ws_url,
										 on_message=self._on_message_,
										 on_open=self._on_open_,
										 on_close=self._on_close_,
										 on_error=self._on_error_,
										 header={})
		
		# start the websocket running in a thread
		self.wst = threading.Thread(target=lambda: self.ws.run_forever())
		self.wst.daemon = True
		self.wst.start()
		
		# wait for the websocket to connect
		while self.ws.sock.connected == False:
			time.sleep(0.01)
		
		# subscribe and authenticate
		all_params = copy.copy(self.ws_params)
		if self.api_key != "" and self.api_secret != "" and self.api_passphrase != "":
			all_params.update(utils.generate_auth_headers(
			                      "GET/users/self/verify",
			                      self.api_key,
			                      self.api_secret,
			                      self.api_passphrase))
		self.ws.send(json.dumps(all_params))
Ejemplo n.º 2
0
def delete_channel(username, password, apiUrl, rejectUnauthorized, channelId):
    uri = '{}/channels/{}'.format(apiUrl, channelId)
    utils.authenticate(username, apiUrl, rejectUnauthorized)
    headers = utils.generate_auth_headers(username, password)
    response = requests.delete(uri, headers=headers, verify=rejectUnauthorized)
    if (response.status_code == 200):
        print("Deleted channel {}.".format(channelId))
    else:
        print('Received a non-201 response code, the response body was:{}'.format(response.text))
Ejemplo n.º 3
0
def install_passthrough_channel(username, password, apiUrl, rejectUnauthorized, channel):    
    uri = '{}/channels'.format(apiUrl)
    utils.authenticate(username, apiUrl, rejectUnauthorized)
    headers = utils.generate_auth_headers(username, password)
    response = requests.post(uri, headers=headers, json=channel, verify=rejectUnauthorized)
    
    if (response.status_code == 201):
        print("Channel successfully installed.")
    else:
        print('Received a non-201 response code, the response body was:{}'.format(response.text))
Ejemplo n.º 4
0
def get_all_channels(username, password, apiUrl, rejectUnauthorized):
    uri = '{}/channels'.format(apiUrl)
    utils.authenticate(username, apiUrl, rejectUnauthorized)
    headers = utils.generate_auth_headers(username, password)
    response = requests.get(uri, headers=headers, verify=rejectUnauthorized)
    if (response.status_code == 200):
        print("Retrieved all channels.")
        return response.json()
    else:
        print('Received a non-201 response code, the response body was:{}'.format(response.text))
    return {}
Ejemplo n.º 5
0
        print(response.content)
        raise Exception('Password token not updated! {}'.format(
            response.status_code))


apiURL = 'https://10.147.72.11:8080'
username = '******'
old_password = '******'
new_password = '******'
rejectUnauthorized = False

with warnings.catch_warnings():
    warnings.simplefilter("ignore")

    utils.authenticate(username, apiURL, rejectUnauthorized)
    auth_headers = utils.generate_auth_headers(username, old_password)

    username = auth_headers['auth-username']
    timestamp = auth_headers['auth-ts']
    salt = auth_headers['auth-salt']
    token = auth_headers['auth-token']
    # print(timestamp)

    password_object = utils.create_password_object(new_password)
    pass_salt = password_object['userPasswordSalt']
    pass_hash = password_object['userPasswordHash']

    changePassword(username, timestamp, salt, token, password_object,
                   rejectUnauthorized)

# shasum = hashlib.sha512()