Skip to content

Commit

Permalink
login support for legacy RouterOS versions below 6.43
Browse files Browse the repository at this point in the history
  • Loading branch information
akpw committed Apr 23, 2024
1 parent e473d1e commit 42a8d44
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The default configuration file comes with a sample configuration, making it easy
use_ssl = False # enables connection via API-SSL servis
no_ssl_certificate = False # enables API_SSL connect without router SSL certificate
ssl_certificate_verify = False # turns SSL certificate verification on / off
plaintext_login = True # for legacy RouterOS versions below 6.43 use False
installed_packages = True # Installed packages
dhcp = True # DHCP general metrics
Expand Down
7 changes: 4 additions & 3 deletions mktxp/cli/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MKTXPConfigKeys:
SSL_KEY = 'use_ssl'
NO_SSL_CERTIFICATE = 'no_ssl_certificate'
SSL_CERTIFICATE_VERIFY = 'ssl_certificate_verify'
PLAINTEXT_LOGIN_KEY = 'plaintext_login'

FE_PACKAGE_KEY = 'installed_packages'
FE_DHCP_KEY = 'dhcp'
Expand Down Expand Up @@ -145,8 +146,8 @@ class MKTXPConfigKeys:
SSL_CERTIFICATE_VERIFY, FE_IPV6_FIREWALL_KEY, FE_IPV6_NEIGHBOR_KEY, FE_CONNECTION_STATS_KEY, FE_BGP_KEY}

# Feature keys enabled by default
BOOLEAN_KEYS_YES = {FE_DHCP_KEY, FE_PACKAGE_KEY, FE_DHCP_LEASE_KEY, FE_DHCP_POOL_KEY, FE_IP_CONNECTIONS_KEY, FE_INTERFACE_KEY, FE_FIREWALL_KEY,
FE_MONITOR_KEY, FE_ROUTE_KEY, MKTXP_USE_COMMENTS_OVER_NAMES,
BOOLEAN_KEYS_YES = {PLAINTEXT_LOGIN_KEY, FE_DHCP_KEY, FE_PACKAGE_KEY, FE_DHCP_LEASE_KEY, FE_DHCP_POOL_KEY, FE_IP_CONNECTIONS_KEY, FE_INTERFACE_KEY,
FE_FIREWALL_KEY, FE_MONITOR_KEY, FE_ROUTE_KEY, MKTXP_USE_COMMENTS_OVER_NAMES,
FE_WIRELESS_KEY, FE_WIRELESS_CLIENTS_KEY, FE_CAPSMAN_KEY, FE_CAPSMAN_CLIENTS_KEY, FE_POE_KEY,
FE_NETWATCH_KEY, FE_PUBLIC_IP_KEY, FE_USER_KEY, FE_QUEUE_KEY}

Expand All @@ -167,7 +168,7 @@ class MKTXPConfigKeys:
class ConfigEntry:
MKTXPConfigEntry = namedtuple('MKTXPConfigEntry', [MKTXPConfigKeys.ENABLED_KEY, MKTXPConfigKeys.HOST_KEY, MKTXPConfigKeys.PORT_KEY,
MKTXPConfigKeys.USER_KEY, MKTXPConfigKeys.PASSWD_KEY,
MKTXPConfigKeys.SSL_KEY, MKTXPConfigKeys.NO_SSL_CERTIFICATE, MKTXPConfigKeys.SSL_CERTIFICATE_VERIFY,
MKTXPConfigKeys.SSL_KEY, MKTXPConfigKeys.NO_SSL_CERTIFICATE, MKTXPConfigKeys.SSL_CERTIFICATE_VERIFY, MKTXPConfigKeys.PLAINTEXT_LOGIN_KEY,
MKTXPConfigKeys.FE_DHCP_KEY, MKTXPConfigKeys.FE_PACKAGE_KEY, MKTXPConfigKeys.FE_DHCP_LEASE_KEY, MKTXPConfigKeys.FE_DHCP_POOL_KEY, MKTXPConfigKeys.FE_INTERFACE_KEY,
MKTXPConfigKeys.FE_FIREWALL_KEY, MKTXPConfigKeys.FE_MONITOR_KEY, MKTXPConfigKeys.FE_ROUTE_KEY, MKTXPConfigKeys.FE_WIRELESS_KEY, MKTXPConfigKeys.FE_WIRELESS_CLIENTS_KEY,
MKTXPConfigKeys.FE_IP_CONNECTIONS_KEY, MKTXPConfigKeys.FE_CONNECTION_STATS_KEY, MKTXPConfigKeys.FE_CAPSMAN_KEY, MKTXPConfigKeys.FE_CAPSMAN_CLIENTS_KEY, MKTXPConfigKeys.FE_POE_KEY,
Expand Down
1 change: 1 addition & 0 deletions mktxp/cli/config/mktxp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use_ssl = False # enables connection via API-SSL servis
no_ssl_certificate = False # enables API_SSL connect without router SSL certificate
ssl_certificate_verify = False # turns SSL certificate verification on / off
plaintext_login = True # for legacy RouterOS versions below 6.43 use False

installed_packages = True # Installed packages
dhcp = True # DHCP general metrics
Expand Down
8 changes: 2 additions & 6 deletions mktxp/flow/router_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ def connect(self):
return
try:
print(f'Connecting to router {self.router_name}@{self.config_entry.hostname}')
try:
self.api = self.connection.get_api()
except:
self.connection.plaintext_login = False
self.api = self.connection.get_api()

self.connection.plaintext_login = self.config_entry.plaintext_login
self.api = self.connection.get_api()
self._set_connect_state(success = True, connect_time = connect_time)
except (socket.error, socket.timeout, Exception) as exc:
self._set_connect_state(success = False, connect_time = connect_time, exc = exc)
Expand Down

0 comments on commit 42a8d44

Please sign in to comment.