feat: 请求 API 添加 token 认证;调整 tcpdump 执行逻辑;新增 execShellCmd 接口
This commit is contained in:
@@ -127,6 +127,11 @@ public class APIController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/pcap")
|
||||
public R listTcpdump() {
|
||||
return R.ok().putData("records", adbUtil.listTcpdump());
|
||||
}
|
||||
|
||||
@PostMapping("/pcap")
|
||||
public R startTcpdump(@RequestParam(required = false, defaultValue = "") String packageName) {
|
||||
AdbUtil.CommandResult result = adbUtil.startTcpdump(packageName);
|
||||
@@ -149,7 +154,10 @@ public class APIController {
|
||||
// response pcap file
|
||||
File tempFile = T.FileUtil.file(Constant.TEMP_PATH, id + ".pcap");
|
||||
try {
|
||||
String filePath = "/data/local/tmp/" + id + ".pcap";
|
||||
String filePath = result.output();
|
||||
if (T.StrUtil.isEmpty(filePath)) {
|
||||
throw new APIException(RCode.NOT_EXISTS);
|
||||
}
|
||||
AdbUtil.CommandResult pulled = adbUtil.pull(filePath, tempFile.getAbsolutePath());
|
||||
if (0 != pulled.exitCode()) {
|
||||
throw new APIException(pulled.output());
|
||||
@@ -163,4 +171,15 @@ public class APIController {
|
||||
response.getWriter().write(T.JSONUtil.toJsonStr(R.ok().putData("id", id)));
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/shell")
|
||||
public R execShellCmd(@RequestBody Map<String, Object> requestBody) {
|
||||
String cmd = T.MapUtil.getStr(requestBody, "cmd", "");
|
||||
if (T.StrUtil.isEmpty(cmd)) {
|
||||
return R.error(RCode.BAD_REQUEST);
|
||||
}
|
||||
|
||||
Integer timeout = T.MapUtil.getInt(requestBody, "timeout", 10);
|
||||
return R.ok().putData("result", adbUtil.execShellCommand(cmd, timeout));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user