|
2 | 2 |
|
3 | 3 | Author: Pavel Skuratovich (aka Chupaka), Minsk, Belarus |
4 | 4 | Description: Implementation of MikroTik RouterOS API Client |
5 | | -Version: 1.2 |
| 5 | +Version: 1.3 |
6 | 6 | E-Mail: chupaka@gmail.com |
7 | 7 | Support: http://forum.mikrotik.com/viewtopic.php?t=31555 |
8 | 8 | Dependencies: Uses Ararat Synapse Library (http://synapse.ararat.cz/) |
9 | | -Legal issues: Copyright © by Pavel Skuratovich |
| 9 | +Legal issues: Copyright © by Pavel Skuratovich |
10 | 10 |
|
11 | 11 | This source code is provided 'as-is', without any express or |
12 | 12 | implied warranty. In no event will the author be held liable |
|
41 | 41 | ******************************************************************************** |
42 | 42 |
|
43 | 43 | Version history: |
| 44 | +1.3 June 04, 2018 |
| 45 | + Added support for RouterOS 6.43+ API login method |
| 46 | +
|
44 | 47 | 1.2 June 12, 2013 |
45 | 48 | Added basic support for API over TLS |
46 | 49 |
|
@@ -257,19 +260,31 @@ function TRosApiClient.DoLogin(const Username, Password: AnsiString): Boolean; |
257 | 260 | begin |
258 | 261 | Result := False; |
259 | 262 |
|
260 | | - Res := Query(['/login'], True); |
261 | | - if Res.Values[0].Name = '!done' then |
262 | | - begin |
263 | | - Res2 := Query(['/login', '=name=' + Username, '=response=00' + |
264 | | - StrToHex(MD5(#0 + Password + HexToStr(Res['=ret'])))], True); |
265 | | - if Res2.Trap then |
266 | | - FSock.CloseSocket |
267 | | - else |
268 | | - Result := True; |
269 | | - Res2.Free; |
270 | | - end |
| 263 | + // post-6.43 login method |
| 264 | + Res := Query(['/login', '=name=' + Username, '=password=' + Password], True); |
| 265 | + if Res.Trap then |
| 266 | + // login error |
| 267 | + FSock.CloseSocket |
271 | 268 | else |
272 | | - raise Exception.Create('Invalid response: ''' + Res.Values[0].Name + ''', expected ''!done'''); |
| 269 | + if Res.Done then |
| 270 | + begin |
| 271 | + if High(Res.Sentences) <> -1 then |
| 272 | + begin |
| 273 | + // fallback to pre-6.43 login method |
| 274 | + Res2 := Query(['/login', '=name=' + Username, '=response=00' + |
| 275 | + StrToHex(MD5(#0 + Password + HexToStr(Res['=ret'])))], True); |
| 276 | + if Res2.Trap then |
| 277 | + FSock.CloseSocket |
| 278 | + else |
| 279 | + Result := True; |
| 280 | + Res2.Free; |
| 281 | + end |
| 282 | + else |
| 283 | + Result := True; |
| 284 | + end |
| 285 | + else |
| 286 | + raise Exception.Create('Invalid response: ''' + Res.Values[0].Name + ''', expected ''!done'''); |
| 287 | + |
273 | 288 | Res.Free; |
274 | 289 | end; |
275 | 290 |
|
|
0 commit comments