Пример #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;
  }
Пример #2
0
  @Action(
      value = "/admin/selectSystemsForCompositeTerms",
      results = {@Result(name = "success", location = "/admin/secure_shell.jsp")})
  public String selectSystemsForCompositeTerms() {

    Long userId = AuthUtil.getUserId(servletRequest.getSession());
    // exit any previous terms
    exitTerms();
    if (systemSelectId != null && !systemSelectId.isEmpty()) {

      SystemStatusDB.setInitialSystemStatus(systemSelectId, userId);
      pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);

      AuthUtil.setSessionId(servletRequest.getSession(), SessionAuditDB.createSessionLog(userId));
    }
    return SUCCESS;
  }
Пример #3
0
  /** creates composite terminals if there are errors or authentication issues. */
  @Action(
      value = "/admin/createTerms",
      results = {@Result(name = "success", location = "/admin/secure_shell.jsp")})
  public String createTerms() {

    Long userId = AuthUtil.getUserId(servletRequest.getSession());
    Long sessionId = AuthUtil.getSessionId(servletRequest.getSession());

    if (pendingSystemStatus != null && pendingSystemStatus.getId() != null) {

      // get status
      currentSystemStatus = SystemStatusDB.getSystemStatus(pendingSystemStatus.getId(), userId);
      // if initial status run script
      if (currentSystemStatus != null
          && (HostSystem.INITIAL_STATUS.equals(currentSystemStatus.getStatusCd())
              || HostSystem.AUTH_FAIL_STATUS.equals(currentSystemStatus.getStatusCd())
              || HostSystem.PUBLIC_KEY_FAIL_STATUS.equals(currentSystemStatus.getStatusCd()))) {

        // set current servletRequest.getSession()
        currentSystemStatus =
            SSHUtil.openSSHTermOnSystem(
                passphrase, password, userId, sessionId, currentSystemStatus, userSchSessionMap);
      }
      if (currentSystemStatus != null
          && (HostSystem.AUTH_FAIL_STATUS.equals(currentSystemStatus.getStatusCd())
              || HostSystem.PUBLIC_KEY_FAIL_STATUS.equals(currentSystemStatus.getStatusCd()))) {

        pendingSystemStatus = currentSystemStatus;

      } else {

        pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
        // if success loop through systems until finished or need password
        while (pendingSystemStatus != null
            && currentSystemStatus != null
            && HostSystem.SUCCESS_STATUS.equals(currentSystemStatus.getStatusCd())) {
          currentSystemStatus =
              SSHUtil.openSSHTermOnSystem(
                  passphrase, password, userId, sessionId, pendingSystemStatus, userSchSessionMap);
          pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
        }
      }
    }
    if (SystemStatusDB.getNextPendingSystem(userId) == null) {
      // check user map
      if (userSchSessionMap != null && !userSchSessionMap.isEmpty()) {

        // get user servletRequest.getSession()s
        Map<Long, SchSession> schSessionMap = userSchSessionMap.get(userId).getSchSessionMap();

        for (SchSession schSession : schSessionMap.values()) {
          // add to host system list
          systemList.add(schSession.getHostSystem());
          // run script it exists
          if (script != null && script.getId() != null && script.getId() > 0) {
            script = ScriptDB.getScript(script.getId(), userId);
            BufferedReader reader = new BufferedReader(new StringReader(script.getScript()));
            String line;
            try {
              while ((line = reader.readLine()) != null) {
                schSession.getCommander().println(line);
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
      }
    }

    return SUCCESS;
  }