예제 #1
0
  /**
   * Add new session to configuration.
   *
   * @param req HTTP request
   * @param forwardReq forward data
   * @return service response.
   */
  @POST
  @Path("session/add")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public ServiceResponse addSession(@Context HttpServletRequest req, SshSession sessionCfg) {
    Configuration cfg = getEditConfiguration(req);

    sessionCfg.setId(StringUtils.createUUID());
    cfg.getSshSession().add(sessionCfg);

    return ServiceUtils.createOKResponse("SSH client session added");
  }
예제 #2
0
  /**
   * Add new connection to configuration.
   *
   * @param req HTTP request
   * @param connectionCfg forward data
   * @return service response.
   */
  @POST
  @Path("connection/add")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public ServiceResponse addConnection(@Context HttpServletRequest req, Connection connectionCfg) {
    Configuration cfg = getEditConfiguration(req);

    connectionCfg.setId(StringUtils.createUUID());
    connectionCfg.setPassword(DrillServer.getEncDecorder().encrypt(connectionCfg.getPassword()));
    cfg.getConnection().add(connectionCfg);

    return ServiceUtils.createOKResponse("Connection added");
  }
예제 #3
0
  /**
   * Add new forward to configuration.
   *
   * @param req HTTP request
   * @param forwardReq forward data
   * @return service response.
   */
  @POST
  @Path("forward/add/{id}")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public ServiceResponse addForward(
      @Context HttpServletRequest req, @PathParam("id") String sessionId, Forward forwardReq) {
    Configuration cfg = getEditConfiguration(req);

    for (SshSession sshClient : cfg.getSshSession()) {
      if (sshClient.getId().equals(sessionId)) {

        Connection mAccount = getConnectionById((String) forwardReq.getConnection(), cfg);
        if (mAccount != null) {

          Forward fwd = new Forward();
          fwd.setConnection(mAccount);

          fwd.setId(StringUtils.createUUID());
          fwd.setDescription(forwardReq.getDescription());
          fwd.setEnabled(forwardReq.isEnabled());
          fwd.setSHost(forwardReq.getSHost());
          fwd.setSPort(forwardReq.getSPort());
          fwd.setRHost(forwardReq.getRHost());
          fwd.setRPort(forwardReq.getRPort());
          fwd.setType(forwardReq.getType());
          sshClient.getForward().add(fwd);

          return ServiceUtils.createOKResponse("SSH forward added");
        }

        return ServiceUtils.createNOKResponse("SSH connection not found");
      }
    }

    return ServiceUtils.createNOKResponse("SSH client not found");
  }