Пример #1
0
  /**
   * Change forward configuration.
   *
   * @param req HTTP request
   * @param id forward id to change
   * @return service response.
   */
  @POST
  @Path("forward/update/{id}")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public ServiceResponse updateForward(
      @Context HttpServletRequest req, @PathParam("id") String id, Forward forwardReq) {

    Configuration cfg = getEditConfiguration(req);
    for (SshSession sshClient : cfg.getSshSession()) {
      Iterator<Forward> iter = sshClient.getForward().iterator();
      while (iter.hasNext()) {
        Forward fwd = iter.next();
        if (fwd.getId().equals(id)) {

          Connection mAccount = getConnectionById((String) forwardReq.getConnection(), cfg);
          if (mAccount != null) {
            fwd.setDescription(forwardReq.getDescription());
            fwd.setEnabled(forwardReq.isEnabled());
            fwd.setType(forwardReq.getType());
            fwd.setRHost(forwardReq.getRHost());
            fwd.setSHost(forwardReq.getSHost());
            fwd.setRPort(forwardReq.getRPort());
            fwd.setSPort(forwardReq.getSPort());
            fwd.setConnection(mAccount);
            fwd.setFilter(forwardReq.getFilter());

            return ServiceUtils.createOKResponse("Forward changed");
          }

          return ServiceUtils.createNOKResponse("Connection not found");
        }
      }
    }
    return ServiceUtils.createOKResponse("Forward not found: " + id);
  }
Пример #2
0
  /**
   * Delete forward from configuration.
   *
   * @param req HTTP request
   * @param id forward id to delete
   * @return service response.
   */
  @DELETE
  @Path("forward/delete/{id}")
  @Produces(MediaType.APPLICATION_JSON)
  public ServiceResponse deleteForward(
      @Context HttpServletRequest req, @PathParam("id") String id) {

    Configuration cfg = getEditConfiguration(req);
    for (SshSession sshClient : cfg.getSshSession()) {
      Iterator<Forward> iter = sshClient.getForward().iterator();
      while (iter.hasNext()) {
        Forward fwd = iter.next();
        if (fwd.getId().equals(id)) {
          iter.remove();
          return ServiceUtils.createOKResponse("Forward removed");
        }
      }
    }
    return ServiceUtils.createOKResponse("Forward not found: " + id);
  }