feat: ASW-64 新增 api acl 接口
This commit is contained in:
@@ -189,4 +189,61 @@ public class APIController {
|
||||
Integer timeout = T.MapUtil.getInt(requestBody, "timeout", 10);
|
||||
return R.ok().putData("result", adbUtil.execShellCommand(cmd, timeout));
|
||||
}
|
||||
|
||||
@GetMapping("/acl")
|
||||
public R listAcl() {
|
||||
return R.ok().putData("records", adbUtil.listAcl());
|
||||
}
|
||||
|
||||
@PostMapping("/acl")
|
||||
public R addAcl(@RequestBody Map<String, Object> requestBody) {
|
||||
String ip = T.MapUtil.getStr(requestBody, "ip");
|
||||
String port = T.MapUtil.getStr(requestBody, "port");
|
||||
if (T.StrUtil.isAllEmpty(ip, port)) {
|
||||
return R.error(RCode.BAD_REQUEST);
|
||||
}
|
||||
|
||||
String protocol = T.MapUtil.getStr(requestBody, "protocol", "all");
|
||||
if (!T.StrUtil.equalsAny(protocol, "tcp", "udp", "all")) {
|
||||
return R.error(RCode.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ("all".equals(protocol) && T.StrUtil.isEmpty(ip)) {
|
||||
return R.error(RCode.BAD_REQUEST);
|
||||
}
|
||||
|
||||
adbUtil.addAcl(protocol, ip, port);
|
||||
return R.ok().putData("records", adbUtil.listAcl());
|
||||
}
|
||||
|
||||
@DeleteMapping("/acl")
|
||||
public R deleteAcl(@RequestBody Map<String, Object> requestBody) {
|
||||
String ip = T.MapUtil.getStr(requestBody, "ip");
|
||||
String port = T.MapUtil.getStr(requestBody, "port");
|
||||
if (T.StrUtil.isAllEmpty(ip, port)) {
|
||||
return R.error(RCode.BAD_REQUEST);
|
||||
}
|
||||
|
||||
String protocol = T.MapUtil.getStr(requestBody, "protocol", "all");
|
||||
if (!T.StrUtil.equalsAny(protocol, "tcp", "udp", "all")) {
|
||||
return R.error(RCode.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ("all".equals(protocol) && T.StrUtil.isEmpty(ip)) {
|
||||
return R.error(RCode.BAD_REQUEST);
|
||||
}
|
||||
|
||||
adbUtil.deleteAcl(protocol, ip, port);
|
||||
return R.ok().putData("records", adbUtil.listAcl());
|
||||
}
|
||||
|
||||
@DeleteMapping("/acl/flush")
|
||||
public R flushAcl() {
|
||||
AdbUtil.CommandResult result = adbUtil.flushAcl();
|
||||
if (0 != result.exitCode()) {
|
||||
return R.error(result.output());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user