Exemplo n.º 1
0
  /** Runs commands across sessions */
  @Action(value = "/terms/runCmd")
  public String runCmd() {
    Long userId = AuthUtil.getUserId(servletRequest.getSession());
    if (userId != null) {
      try {
        // if id then write to single system output buffer
        if (idList != null && idList.size() > 0) {
          for (Long id : idList) {
            // get servletRequest.getSession() for user
            UserSchSessions userSchSessions = userSchSessionMap.get(userId);
            if (userSchSessions != null) {
              SchSession schSession = userSchSessions.getSchSessionMap().get(id);
              if (keyCode != null) {
                if (keyMap.containsKey(keyCode)) {
                  schSession.getCommander().write(keyMap.get(keyCode));
                }
              } else {
                schSession.getCommander().print(command);
              }
            }
          }
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } else {
      AuthUtil.deleteAllSession(servletRequest.getSession());
    }

    return null;
  }
Exemplo n.º 2
0
  @Action(
      value = "/admin/exitTerms",
      results = {@Result(name = "success", location = "/admin/menu.action", type = "redirect")})
  public String exitTerms() {

    Long userId = AuthUtil.getUserId(servletRequest.getSession());
    // check user map
    if (userSchSessionMap != null && !userSchSessionMap.isEmpty()) {

      // get user servletRequest.getSession()s
      for (Long userKey : userSchSessionMap.keySet()) {
        UserSchSessions userSchSessions = userSchSessionMap.get(userKey);

        // get current time and subtract number of hours set to determine expire time
        Calendar expireTime = Calendar.getInstance();
        expireTime.add(
            Calendar.HOUR,
            (-1
                * Integer.parseInt(
                    AppConfigLkup.getProperty(
                        "timeoutSshAfter")))); // subtract hours to get expire time

        // if current user or session has timed out remove ssh session
        if (userId.equals(userKey) || userSchSessions.getStartTime().before(expireTime.getTime())) {
          Map<Long, SchSession> schSessionMap = userSchSessionMap.get(userKey).getSchSessionMap();

          for (Long sessionKey : schSessionMap.keySet()) {

            SchSession schSession = schSessionMap.get(sessionKey);

            // disconnect ssh session
            schSession.getChannel().disconnect();
            schSession.getSession().disconnect();
            schSession.setChannel(null);
            schSession.setSession(null);
            schSession.setInputToChannel(null);
            schSession.setCommander(null);
            schSession.setOutFromChannel(null);
            schSession = null;
            // remove from map
            schSessionMap.remove(sessionKey);
          }

          // clear and remove session map for user
          schSessionMap.clear();
          userSchSessionMap.remove(userKey);
          SessionOutputUtil.removeUserSession(userKey);
        }
      }
    }

    return SUCCESS;
  }