@@ -26,22 +26,37 @@ def special_login_handler(self, delay_factor: float = 1.0) -> None:
2626 Special cases:
2727 Mikrotik might prompt to read software licenses before displaying the initial prompt.
2828 Mikrotik might also prompt for acknowledging no software key message if unlicensed.
29+ Mikrotik might present a "default config" screen.
30+ Mikrotik might ask for a new password.
2931 """
3032 no_license_message = 'Please press "Enter" to continue!'
3133 license_prompt = "Do you want to see the software license"
34+ new_password_promt = "new password>"
35+ default_config_prompt = 'remove this default configuration type "r"'
3236 combined_pattern = (
33- rf"(?:{ self .prompt_pattern } |{ no_license_message } |{ license_prompt } )"
37+ rf"(?:{ self .prompt_pattern } |{ no_license_message } |{ license_prompt } | { new_password_promt } | { default_config_prompt } )"
3438 )
3539
3640 data = self .read_until_pattern (pattern = combined_pattern , re_flags = re .I )
37- if no_license_message in data :
38- # Handle "no license" message
39- self .write_channel (self .RETURN )
40- self .read_until_pattern (pattern = self .prompt_pattern )
41- elif license_prompt in data :
42- # Handle software license prompt
43- self .write_channel ("n" )
44- self .read_until_pattern (pattern = self .prompt_pattern )
41+ for i in range (1 ,15 ):
42+ if no_license_message in data :
43+ # Handle "no license" message
44+ self .write_channel (self .RETURN )
45+ data = self .read_until_pattern (pattern = combined_pattern , re_flags = re .I )
46+ elif license_prompt in data :
47+ # Handle software license prompt
48+ self .write_channel ("n" )
49+ data = self .read_until_pattern (pattern = combined_pattern , re_flags = re .I )
50+ elif default_config_prompt in data :
51+ # Handle default config notice
52+ self .write_channel ("\n " )
53+ data = self .read_until_pattern (pattern = combined_pattern , re_flags = re .I )
54+ elif new_password_promt in data :
55+ # Handle new password request
56+ self .write_channel ('\x03 ' )
57+ data = self .read_until_pattern (pattern = combined_pattern , re_flags = re .I )
58+ else : # must have matched the regular promt
59+ break
4560
4661 def session_preparation (self , * args : Any , ** kwargs : Any ) -> None :
4762 """Prepare the session after the connection has been established."""
0 commit comments