Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions routeros_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def __init__(self, host, username='admin', password='', port=None, plaintext_log
self.host = host
self.username = username
self.password = password

self.plaintext_login = plaintext_login

self.ssl_context = ssl_context
# Use SSL? Ignored when using a context, so we will set it for simple reference when port-switching:
if ssl_context is not None:
Expand Down Expand Up @@ -83,24 +81,24 @@ def __init__(self, communicator):
self.communicator = communicator

def login(self, login, password, plaintext_login):
if isinstance(login, str):
login = login.encode()
if isinstance(password, str):
password = password.encode()
response = None
if plaintext_login:
if isinstance(login, str):
login = login.encode()
if isinstance(password, str):
password = password.encode()
response = self.get_binary_resource('/').call('login', {'name': login, 'password': password})
else:
response = self.get_binary_resource('/').call('login')
if 'ret' in response.done_message:
token = binascii.unhexlify(response.done_message['ret'])
hasher = hashlib.md5()
hasher.update(b'\x00')
hasher.update(password.encode())
hasher.update(password)
hasher.update(token)
hashed = b'00' + hasher.hexdigest().encode('ascii')
self.get_binary_resource('/').call(
'login', {'name': login.encode(), 'response': hashed})
'login', {'name': login, 'response': hashed})

def get_resource(self, path, structure=None):
if structure is None:
Expand Down