Esempio n. 1
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;
  }
Esempio n. 2
0
  /** returns terminal output as a json string */
  @Action(value = "/terms/getOutputJSON")
  public String getOutputJSON() {
    Connection con = DBUtils.getConn();
    // this checks to see if session is valid
    Long userId =
        AuthDB.getUserIdByAuthToken(con, AuthUtil.getAuthToken(servletRequest.getSession()));
    if (userId != null) {
      // update timeout
      AuthUtil.setTimeout(servletRequest.getSession());
      List<SessionOutput> outputList = SessionOutputUtil.getOutput(con, userId);
      String json = new Gson().toJson(outputList);
      try {
        servletResponse.getOutputStream().write(json.getBytes());
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } else {
      AuthUtil.deleteAllSession(servletRequest.getSession());
    }

    DBUtils.closeConn(con);
    return null;
  }