SSIExecpublic class SSIExec extends Object implements SSICommandImplements the Server-side #exec command |
Fields Summary |
---|
protected SSIInclude | ssiInclude | protected static final int | BUFFER_SIZE |
Methods Summary |
---|
public long | process(SSIMediator ssiMediator, java.lang.String commandName, java.lang.String[] paramNames, java.lang.String[] paramValues, java.io.PrintWriter writer)
long lastModified = 0;
String configErrMsg = ssiMediator.getConfigErrMsg();
String paramName = paramNames[0];
String paramValue = paramValues[0];
String substitutedValue = ssiMediator.substituteVariables(paramValue);
if (paramName.equalsIgnoreCase("cgi")) {
lastModified = ssiInclude.process(ssiMediator, "include",
new String[]{"virtual"}, new String[]{substitutedValue},
writer);
} else if (paramName.equalsIgnoreCase("cmd")) {
boolean foundProgram = false;
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(substitutedValue);
foundProgram = true;
BufferedReader stdOutReader = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
BufferedReader stdErrReader = new BufferedReader(
new InputStreamReader(proc.getErrorStream()));
char[] buf = new char[BUFFER_SIZE];
IOTools.flow(stdErrReader, writer, buf);
IOTools.flow(stdOutReader, writer, buf);
proc.waitFor();
lastModified = System.currentTimeMillis();
} catch (InterruptedException e) {
ssiMediator.log("Couldn't exec file: " + substitutedValue, e);
writer.write(configErrMsg);
} catch (IOException e) {
if (!foundProgram) {
//apache doesn't output an error message if it can't find
// a program
}
ssiMediator.log("Couldn't exec file: " + substitutedValue, e);
}
}
return lastModified;
|
|