Merge pull request #60 from GideonLeGrange/login-change

Updated login code to support RouterOS 6.43+
This commit is contained in:
Gideon le Grange 2018-11-08 06:35:57 +02:00 committed by GitHub
commit 8cba90814f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

3
.gitignore vendored
View File

@ -22,3 +22,6 @@ nbactions.xml
# Maven # Maven
pom.xml.versionsBackup pom.xml.versionsBackup
# MacOS
.DS_Store

View File

@ -55,12 +55,16 @@ public final class ApiConnectionImpl extends ApiConnection {
if (username.trim().isEmpty()) { if (username.trim().isEmpty()) {
throw new ApiConnectionException("API username cannot be empty"); throw new ApiConnectionException("API username cannot be empty");
} }
List<Map<String, String>> list = execute("/login"); List<Map<String, String>> list = execute("/login name=" + username + " password=" + password);
Map<String, String> res = list.get(0); if (!list.isEmpty()) {
String hash = res.get("ret"); Map<String, String> res = list.get(0);
String chal = Util.hexStrToStr("00") + new String(password.toCharArray()) + Util.hexStrToStr(hash); if (res.containsKey("ret")) {
chal = Util.hashMD5(chal); String hash = res.get("ret");
execute("/login name=" + username + " response=00" + chal); String chal = Util.hexStrToStr("00") + new String(password.toCharArray()) + Util.hexStrToStr(hash);
chal = Util.hashMD5(chal);
execute("/login name=" + username + " response=00" + chal);
}
}
} }
@Override @Override