public void getResources(int resourceType, String menu) {
   try {
     ByteArrayWriter baw = new ByteArrayWriter();
     baw.writeInt(resourceType);
     Request request = new Request("getResources", baw.toByteArray());
     if (agent.getConnection().sendRequest(request, true)) {
       if (request.getRequestData() != null) {
         ByteArrayReader reader = new ByteArrayReader(request.getRequestData());
         int count = (int) reader.readInt();
         if (count > 0) {
           if (agent.getGUI().isMenuExists(menu)) agent.getGUI().clearMenu(menu);
           else agent.getGUI().addMenu(menu);
           for (int i = 0; i < count; i++) {
             int resourceId = (int) reader.readInt();
             agent
                 .getGUI()
                 .addMenuItem(menu, new ResourceLaunchAction(resourceId, reader.readString()));
           }
         } else {
           if (agent.getGUI().isMenuExists(menu)) agent.getGUI().removeMenu(menu);
         }
       }
     }
   } catch (IOException e) {
     // #ifdef DEBUG
     log.error("Failed to get resources.", e);
     // #endif
   }
 }
示例#2
0
  /**
   * Get a set of the resource ids of all active tunnels (local and remote).
   *
   * @param session
   * @return resource IDs of active tunnels
   */
  public Set<Integer> getActiveTunnels(SessionInfo session) {

    try {
      MultiplexedConnection tunnel = DefaultAgentManager.getInstance().getAgentBySession(session);

      if (tunnel == null) return null;

      HashSet<Integer> activeTunnelIds = new HashSet<Integer>();

      // The agent keeps track of 'local' tunnels

      Request request = new Request(ACTIVE_LOCAL_TUNNELS);
      if (tunnel.sendRequest(request, true) && request.getRequestData() != null) {

        ByteArrayReader reader = new ByteArrayReader(request.getRequestData());
        int count = (int) reader.readInt();
        for (int i = 0; i < count; i++) {
          activeTunnelIds.add(new Integer((int) reader.readInt()));
        }
      }

      // The server keeps track of 'remote' tunnels
      Collection<RemoteTunnel> activeRemoteTunnels =
          RemoteTunnelManagerFactory.getInstance().getRemoteTunnels(session);
      if (activeRemoteTunnels != null) {
        synchronized (activeRemoteTunnels) {
          for (RemoteTunnel r : activeRemoteTunnels) {
            activeTunnelIds.add(r.getTunnel().getResourceId());
          }
        }
      }

      return activeTunnelIds;
    } catch (IOException e) {
      log.error("Failed to get active tunnel list from agent", e);
      return null;
    }
  }
示例#3
0
 public boolean processRequest(Request request, MultiplexedConnection connection) {
   AgentTunnel agent = (AgentTunnel) connection;
   if (request.getRequestName().equals(SETUP_AND_LAUNCH_TUNNEL)
       && request.getRequestData() != null) {
     try {
       ByteArrayReader reader = new ByteArrayReader(request.getRequestData());
       int id = (int) reader.readInt();
       Tunnel resource = (Tunnel) TunnelPlugin.SSL_TUNNEL_RESOURCE_TYPE.getResourceById(id);
       if (resource == null) {
         throw new Exception("No resource with ID " + id);
       }
       Policy policy =
           LaunchSessionManager.getLaunchRequestPolicy(null, agent.getSession(), resource);
       if (resource.sessionPasswordRequired(agent.getSession())) {
         // TODO: prompt user for credentials through agent!
         return true;
       } else {
         LaunchSession launchSession =
             LaunchSessionFactory.getInstance()
                 .createLaunchSession(agent.getSession(), resource, policy);
         launchSession.checkAccessRights(null, agent.getSession());
         if (resource.getType() == TransportType.LOCAL_TUNNEL_ID) {
           try {
             Request req = buildLocalTunnel(resource, launchSession);
             request.setRequestData(req.getRequestData());
             return true;
           } catch (IOException ioe) {
             throw new TunnelException(TunnelException.INTERNAL_ERROR, ioe);
           }
         } else if (resource.getType() == TransportType.REMOTE_TUNNEL_ID) {
           startRemoteTunnel(agent, resource, launchSession);
           request.setRequestData(null);
           return true;
         } else {
           throw new TunnelException(
               TunnelException.INTERNAL_ERROR,
               (Throwable) null,
               "Unknown tunnel type " + resource.getType());
         }
       }
     } catch (Exception e) {
       log.error("Failed to start tunnel.", e);
       return false;
     }
   }
   return false;
 }