Skip to content

Commit

Permalink
Added support for RouterOS 6.43+ API login method
Browse files Browse the repository at this point in the history
  • Loading branch information
Chupaka authored Jun 4, 2018
1 parent f5972c9 commit 717fc26
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions RouterOSAPI.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Author: Pavel Skuratovich (aka Chupaka), Minsk, Belarus
Description: Implementation of MikroTik RouterOS API Client
Version: 1.2
Version: 1.3
E-Mail: [email protected]
Support: http://forum.mikrotik.com/viewtopic.php?t=31555
Dependencies: Uses Ararat Synapse Library (http://synapse.ararat.cz/)
Legal issues: Copyright © by Pavel Skuratovich
Legal issues: Copyright © by Pavel Skuratovich
This source code is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
Expand Down Expand Up @@ -41,6 +41,9 @@
********************************************************************************
Version history:
1.3 June 04, 2018
Added support for RouterOS 6.43+ API login method
1.2 June 12, 2013
Added basic support for API over TLS
Expand Down Expand Up @@ -257,19 +260,31 @@ function TRosApiClient.DoLogin(const Username, Password: AnsiString): Boolean;
begin
Result := False;

Res := Query(['/login'], True);
if Res.Values[0].Name = '!done' then
begin
Res2 := Query(['/login', '=name=' + Username, '=response=00' +
StrToHex(MD5(#0 + Password + HexToStr(Res['=ret'])))], True);
if Res2.Trap then
FSock.CloseSocket
else
Result := True;
Res2.Free;
end
// post-6.43 login method
Res := Query(['/login', '=name=' + Username, '=password=' + Password], True);
if Res.Trap then
// login error
FSock.CloseSocket
else
raise Exception.Create('Invalid response: ''' + Res.Values[0].Name + ''', expected ''!done''');
if Res.Done then
begin
if High(Res.Sentences) <> -1 then
begin
// fallback to pre-6.43 login method
Res2 := Query(['/login', '=name=' + Username, '=response=00' +
StrToHex(MD5(#0 + Password + HexToStr(Res['=ret'])))], True);
if Res2.Trap then
FSock.CloseSocket
else
Result := True;
Res2.Free;
end
else
Result := True;
end
else
raise Exception.Create('Invalid response: ''' + Res.Values[0].Name + ''', expected ''!done''');

Res.Free;
end;

Expand Down

0 comments on commit 717fc26

Please sign in to comment.