mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-19 18:25:26 +02:00
included librouteros library to avoid conflicts with other integrations #2
This commit is contained in:
parent
c58184b0f7
commit
b70bb9db92
9 changed files with 590 additions and 4 deletions
26
custom_components/mikrotik_router/librouteros/login.py
Normal file
26
custom_components/mikrotik_router/librouteros/login.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from binascii import unhexlify, hexlify
|
||||
from hashlib import md5
|
||||
|
||||
|
||||
def encode_password(token, password):
|
||||
#pylint: disable=redefined-outer-name
|
||||
token = token.encode('ascii', 'strict')
|
||||
token = unhexlify(token)
|
||||
password = password.encode('ascii', 'strict')
|
||||
hasher = md5()
|
||||
hasher.update(b'\x00' + password + token)
|
||||
password = hexlify(hasher.digest())
|
||||
return '00' + password.decode('ascii', 'strict')
|
||||
|
||||
|
||||
def token(api, username, password):
|
||||
"""Login using pre routeros 6.43 authorization method."""
|
||||
sentence = api('/login')
|
||||
tok = tuple(sentence)[0]['ret']
|
||||
encoded = encode_password(tok, password)
|
||||
tuple(api('/login', **{'name': username, 'response': encoded}))
|
||||
|
||||
|
||||
def plain(api, username, password):
|
||||
"""Login using post routeros 6.43 authorization method."""
|
||||
tuple(api('/login', **{'name': username, 'password': password}))
|
Loading…
Add table
Add a link
Reference in a new issue