예제 #1
0
  private void processLogout(
      String aConnectorId, HttpServletRequest aReq, HttpServletResponse aResp) throws IOException {
    try {
      // building logout request
      Token lReqToken = TokenFactory.createToken(SystemPlugIn.NS_SYSTEM, "logout");
      lReqToken.setInteger("utid", getUTID(aReq));
      final WebSocketPacket lPacket = JSONProcessor.tokenToPacket(lReqToken);

      send(aConnectorId, lPacket.getString(), aReq, aResp);
    } catch (Exception lEx) {
      sendMessage(500, lEx.getLocalizedMessage(), aResp);
    }
  }
예제 #2
0
  private void processDownload(
      String aConnectorId, HttpServletRequest aReq, HttpServletResponse aResp) throws IOException {
    String lFilename = aReq.getParameter("filename");
    String lAlias = aReq.getParameter("alias");

    if (null == lFilename) {
      sendMessage(400, "Missing filename parameter!", aResp);
      return;
    }

    // building login request
    Token lReqToken =
        TokenFactory.createToken(JWebSocketServerConstants.NS_BASE + ".plugins.filesystem", "load");
    lReqToken.setString("filename", lFilename);
    lReqToken.setString("alias", lAlias);
    final WebSocketPacket lPacket = JSONProcessor.tokenToPacket(lReqToken);

    send(aConnectorId, lPacket.getString(), aReq, aResp);
  }
예제 #3
0
  private void processLogin(String aConnectorId, HttpServletRequest aReq, HttpServletResponse aResp)
      throws IOException {
    String lUsername = aReq.getParameter("username");
    String lPassword = aReq.getParameter("password");

    if (null == lUsername || null == lPassword) {
      sendMessage(400, "Invalid request parameters!", aResp);
      return;
    }

    // building login request
    Token lReqToken = TokenFactory.createToken(SystemPlugIn.NS_SYSTEM, "login");
    lReqToken.setString("username", lUsername);
    lReqToken.setString("password", lPassword);
    lReqToken.setInteger("utid", getUTID(aReq));
    final WebSocketPacket lPacket = JSONProcessor.tokenToPacket(lReqToken);

    send(aConnectorId, lPacket.getString(), aReq, aResp);
  }
예제 #4
0
  private void call(WebSocketConnector aConnector, Token aToken) {
    TokenServer lServer = getServer();

    Token lResponse = createResponse(aToken);

    // check if user is allowed to run 'exists' command
    /*
    if (!hasAuthority(aConnector, NS_EXTPROCESS + ".call")) {
    if (mLog.isDebugEnabled()) {
    mLog.debug("Returning 'Access denied'...");
    }
    lServer.sendToken(aConnector, lServer.createAccessDenied(aToken));
    return;
    }
    */

    String lAlias = aToken.getString("alias");
    if (null == lAlias) {
      lResponse.setInteger("code", -1);
      lResponse.setString("msg", "No alias passed.");
      lServer.sendToken(aConnector, lResponse);
      return;
    }
    String lCmdLine = mSettings.getAllowedProgs().get(lAlias);
    if (null == lCmdLine) {
      lResponse.setInteger("code", -1);
      lResponse.setString("msg", "Alias '" + lAlias + "' not found.");
      lServer.sendToken(aConnector, lResponse);
      return;
    }
    List<?> lArgs = aToken.getList("args");

    if (mLog.isDebugEnabled()) {
      mLog.debug(
          "Processing 'call'"
              + " (alias: "
              + lAlias
              + ", args: "
              + StringUtils.collectionToDelimitedString(lArgs, ", ")
              + ")...");
    }
    String[] lCmdTokens = StringUtils.tokenizeToStringArray(lCmdLine, " ", true, false);
    List<String> lCmd = new ArrayList<String>();
    for (String lCmdToken : lCmdTokens) {
      for (int lArgIdx = 0; lArgIdx < lArgs.size(); lArgIdx++) {
        lCmdToken = lCmdToken.replace("${" + (lArgIdx + 1) + "}", lArgs.get(lArgIdx).toString());
      }
      lCmd.add(lCmdToken);
    }

    ProcessBuilder lProcBuilder = new ProcessBuilder(lCmd);
    // Map<String, String> lEnv = lProcBuilder.environment();
    lProcBuilder.directory(new File(System.getenv("temp")));

    try {
      if (mLog.isDebugEnabled()) {
        mLog.debug("Directory: " + System.getenv("temp"));
      }
      final Process process = lProcBuilder.start();
      InputStream lIS = process.getInputStream();
      InputStreamReader lISR = new InputStreamReader(lIS);
      BufferedReader lBR = new BufferedReader(lISR);
      String lLine;
      StringBuilder lStrBuf = new StringBuilder();
      while ((lLine = lBR.readLine()) != null) {
        Token lEventToken = TokenFactory.createToken(getNamespace(), "event");
        lEventToken.setString("line", lLine);
        lStrBuf.append(lLine).append("\n");
        lServer.sendToken(aConnector, lEventToken);
      }
      lResponse.setInteger("exitCode", process.exitValue());
      if (mLog.isDebugEnabled()) {
        mLog.debug("Sent '" + lStrBuf.toString().replace("\n", "\\n") + "'.");
      }
    } catch (IOException lEx) {
      lResponse.setInteger("code", -1);
      String lMsg = Logging.getSimpleExceptionMessage(lEx, "calling external process");
      lResponse.setString("msg", lMsg);
      mLog.error(lMsg);
    }

    lServer.sendToken(aConnector, lResponse);
  }