Esempio n. 1
0
  @Action(
      value = "/admin/getNextPendingSystemForTerms",
      results = {@Result(name = "success", location = "/admin/secure_shell.jsp")})
  public String getNextPendingSystemForTerms() {
    Long userId = AuthUtil.getUserId(servletRequest.getSession());
    currentSystemStatus = SystemStatusDB.getSystemStatus(pendingSystemStatus.getId(), userId);
    currentSystemStatus.setErrorMsg("Auth fail");
    currentSystemStatus.setStatusCd(HostSystem.GENERIC_FAIL_STATUS);

    SystemStatusDB.updateSystemStatus(currentSystemStatus, userId);
    pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);

    return SUCCESS;
  }
Esempio n. 2
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;
  }