Ejemplo n.º 1
0
 /** @see SSICommand */
 @Override
 public long process(
     SSIMediator ssiMediator,
     String commandName,
     String[] paramNames,
     String[] paramValues,
     PrintWriter writer)
     throws SSIStopProcessingException {
   long lastModified = 0;
   String errorMessage = ssiMediator.getConfigErrMsg();
   String variableName = null;
   for (int i = 0; i < paramNames.length; i++) {
     String paramName = paramNames[i];
     String paramValue = paramValues[i];
     if (paramName.equalsIgnoreCase("var")) {
       variableName = paramValue;
     } else if (paramName.equalsIgnoreCase("value")) {
       if (variableName != null) {
         String substitutedValue = ssiMediator.substituteVariables(paramValue);
         ssiMediator.setVariableValue(variableName, substitutedValue);
         lastModified = System.currentTimeMillis();
       } else {
         ssiMediator.log("#set--no variable specified");
         writer.write(errorMessage);
         throw new SSIStopProcessingException();
       }
     } else {
       ssiMediator.log("#set--Invalid attribute: " + paramName);
       writer.write(errorMessage);
       throw new SSIStopProcessingException();
     }
   }
   return lastModified;
 }
Ejemplo n.º 2
0
  /** @see SSICommand */
  public void process(
      SSIMediator ssiMediator, String[] paramNames, String[] paramValues, PrintWriter writer) {

    String configErrMsg = ssiMediator.getConfigErrMsg();
    String paramName = paramNames[0];
    String paramValue = paramValues[0];

    if (paramName.equalsIgnoreCase("cgi")) {
      ssiInclude.process(ssiMediator, new String[] {"virtual"}, new String[] {paramValue}, writer);
    } else if (paramName.equalsIgnoreCase("cmd")) {
      boolean foundProgram = false;
      try {
        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec(paramValue);
        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();
      } catch (InterruptedException e) {
        ssiMediator.log("Couldn't exec file: " + paramValue, 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: " + paramValue, e);
      }
    }
  }