|
|
@ -76,21 +76,35 @@ public class LoggerRequestProcessor implements NettyRequestProcessor { |
|
|
|
case GET_LOG_BYTES_REQUEST: |
|
|
|
case GET_LOG_BYTES_REQUEST: |
|
|
|
GetLogBytesRequestCommand getLogRequest = JSONUtils.parseObject( |
|
|
|
GetLogBytesRequestCommand getLogRequest = JSONUtils.parseObject( |
|
|
|
command.getBody(), GetLogBytesRequestCommand.class); |
|
|
|
command.getBody(), GetLogBytesRequestCommand.class); |
|
|
|
byte[] bytes = getFileContentBytes(getLogRequest.getPath()); |
|
|
|
String path = getLogRequest.getPath(); |
|
|
|
|
|
|
|
if (!checkPathSecurity(path)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("Illegal path"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
byte[] bytes = getFileContentBytes(path); |
|
|
|
GetLogBytesResponseCommand getLogResponse = new GetLogBytesResponseCommand(bytes); |
|
|
|
GetLogBytesResponseCommand getLogResponse = new GetLogBytesResponseCommand(bytes); |
|
|
|
channel.writeAndFlush(getLogResponse.convert2Command(command.getOpaque())); |
|
|
|
channel.writeAndFlush(getLogResponse.convert2Command(command.getOpaque())); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case VIEW_WHOLE_LOG_REQUEST: |
|
|
|
case VIEW_WHOLE_LOG_REQUEST: |
|
|
|
ViewLogRequestCommand viewLogRequest = JSONUtils.parseObject( |
|
|
|
ViewLogRequestCommand viewLogRequest = JSONUtils.parseObject( |
|
|
|
command.getBody(), ViewLogRequestCommand.class); |
|
|
|
command.getBody(), ViewLogRequestCommand.class); |
|
|
|
String msg = LoggerUtils.readWholeFileContent(viewLogRequest.getPath()); |
|
|
|
String viewLogPath = viewLogRequest.getPath(); |
|
|
|
|
|
|
|
if (!checkPathSecurity(viewLogPath)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("Illegal path"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String msg = LoggerUtils.readWholeFileContent(viewLogPath); |
|
|
|
ViewLogResponseCommand viewLogResponse = new ViewLogResponseCommand(msg); |
|
|
|
ViewLogResponseCommand viewLogResponse = new ViewLogResponseCommand(msg); |
|
|
|
channel.writeAndFlush(viewLogResponse.convert2Command(command.getOpaque())); |
|
|
|
channel.writeAndFlush(viewLogResponse.convert2Command(command.getOpaque())); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ROLL_VIEW_LOG_REQUEST: |
|
|
|
case ROLL_VIEW_LOG_REQUEST: |
|
|
|
RollViewLogRequestCommand rollViewLogRequest = JSONUtils.parseObject( |
|
|
|
RollViewLogRequestCommand rollViewLogRequest = JSONUtils.parseObject( |
|
|
|
command.getBody(), RollViewLogRequestCommand.class); |
|
|
|
command.getBody(), RollViewLogRequestCommand.class); |
|
|
|
List<String> lines = readPartFileContent(rollViewLogRequest.getPath(), |
|
|
|
|
|
|
|
|
|
|
|
String rollViewLogPath = rollViewLogRequest.getPath(); |
|
|
|
|
|
|
|
if (!checkPathSecurity(rollViewLogPath)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("Illegal path"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> lines = readPartFileContent(rollViewLogPath, |
|
|
|
rollViewLogRequest.getSkipLineNum(), rollViewLogRequest.getLimit()); |
|
|
|
rollViewLogRequest.getSkipLineNum(), rollViewLogRequest.getLimit()); |
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
for (String line : lines) { |
|
|
|
for (String line : lines) { |
|
|
@ -104,7 +118,9 @@ public class LoggerRequestProcessor implements NettyRequestProcessor { |
|
|
|
command.getBody(), RemoveTaskLogRequestCommand.class); |
|
|
|
command.getBody(), RemoveTaskLogRequestCommand.class); |
|
|
|
|
|
|
|
|
|
|
|
String taskLogPath = removeTaskLogRequest.getPath(); |
|
|
|
String taskLogPath = removeTaskLogRequest.getPath(); |
|
|
|
|
|
|
|
if (!checkPathSecurity(taskLogPath)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("Illegal path"); |
|
|
|
|
|
|
|
} |
|
|
|
File taskLogFile = new File(taskLogPath); |
|
|
|
File taskLogFile = new File(taskLogPath); |
|
|
|
boolean status = true; |
|
|
|
boolean status = true; |
|
|
|
try { |
|
|
|
try { |
|
|
@ -123,6 +139,20 @@ public class LoggerRequestProcessor implements NettyRequestProcessor { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* LogServer only can read the logs dir. |
|
|
|
|
|
|
|
* @param path |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean checkPathSecurity(String path) { |
|
|
|
|
|
|
|
String dsHome = System.getProperty("DOLPHINSCHEDULER_WORKER_HOME"); |
|
|
|
|
|
|
|
if (path.startsWith(dsHome) && !path.contains("../") && path.endsWith(".log")) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ExecutorService getExecutor() { |
|
|
|
public ExecutorService getExecutor() { |
|
|
|
return this.executor; |
|
|
|
return this.executor; |
|
|
|
} |
|
|
|
} |
|
|
|