Project

General

Profile

9709.patch

Sergey Ivanovskiy, 07/03/2025 10:28 AM

Download (4.23 KB)

View differences:

new/src/com/goldencode/p2j/main/WebClientSpawner.java 2025-07-03 14:17:42 +0000
437 437
         {
438 438
            String forwardedProto = config.getString(ConfigItem.PROXY_PROTOCOL, null);
439 439
            String webRoot = config.getString(ConfigItem.WEB_ROOT, null);
440
            uri = getForwardedUri(forwardedProto, forwardedHost, webRoot);
440
            uri = getForwardedUri(forwardedProto, forwardedHost, webRoot, port);
441 441
         }
442 442

  
443 443
         if (uri == null)
......
548 548
   /**
549 549
    * Get the external web client uri assigned by the reverse proxy server.
550 550
    * 
551
    * @param    forwardedProto
552
    *           The forwarded protocol of the reverse proxy server, this value must be https. 
553
    * @param    forwardedHost
554
    *           The reverse proxy server host address
555
    * @param    webRoot
556
    *           The assigned web root to the web client
557
    * @param    port
558
    *           The embedded web server port that started by the web client
559
    * 
551 560
    * @return   The external uri of this web client
552 561
    */
553
   private static String getForwardedUri(String forwardedProto, String forwardedHost, String webRoot)
562
   private static String getForwardedUri(String forwardedProto, String forwardedHost, String webRoot, int port)
554 563
   {
564
      if (webRoot != null && webRoot.isEmpty())
565
      {
566
         //the case of direct port mapping
567
         webRoot = new StringBuilder().append(":").append(port).toString();
568
      }
569

  
555 570
      URI uri = URI.create(forwardedProto + "://" + forwardedHost +  webRoot + "/");
556 571
      //rewrite uri
557 572
      return uri.toString();
new/src/com/goldencode/p2j/main/WebClientsManager.java 2025-07-03 13:07:47 +0000
210 210
    * it must be completed.
211 211
    */
212 212
   private final int connectionTestTimeout;
213
   
214
   /** Indicates that the host ports are mapped directly to the corresponding forwarded host */
215
   private final boolean directPortMapping;
216
   
213 217
   /**
214 218
    * Creates a unique instance per a standard P2J server.
215 219
    * 
......
232 236
      
233 237
      prefix = ConfigItem.PROXY_CLIENT_NAME_PREFIX.read("client");
234 238
      
239
      directPortMapping = ConfigItem.DIRECT_PORT_MAPPING.read(Boolean.FALSE);
240
      
235 241
      portsRestricted =  (to > from) && (from > 0);
236 242
      
237 243
      webClientSessions = new ConcurrentHashMap<Integer, WebAllocatedResources>();
......
541 547
      if (viaProxyServer)
542 548
      {
543 549
         StringBuilder webRootBuilder = new StringBuilder();
544
         webRootBuilder.append("/");
545
         webRootBuilder.append(proxyPathSegment);
546
         webRootBuilder.append("/").append(
547
                  hostsManager.getPortName(prefix, from, host, webClientConfig.getPort()));
550
         if (!directPortMapping)
551
         {
552
            webRootBuilder.append("/");
553
            webRootBuilder.append(proxyPathSegment);
554
            webRootBuilder.append("/").append(
555
                     hostsManager.getPortName(prefix, from, host, webClientConfig.getPort()));
556
         }
548 557
         webRoot = webRootBuilder.toString();
549 558
      }
550 559
      webClientConfig.setNewClient(uuid, webRoot, osUser, forwardedProto, forwardedHost);
new/src/com/goldencode/p2j/util/ConfigItem.java 2025-07-03 13:18:14 +0000
312 312
   public static final ConfigItem<String> PROXY_CLIENT_NAME_PREFIX = 
313 313
      new ConfigItem<>(String.class, "portsRange/namePrefix", "", "", "", Type.WEB_CLIENT);
314 314
   
315
   /** Indicates that the host ports are mapped directly to the corresponding forwarded host */
316
   public static final ConfigItem<Boolean> DIRECT_PORT_MAPPING =
317
      new ConfigItem<>(Boolean.class, "portsRange/directPortMapping", "client", "web", "directPortMapping", Type.WEB_CLIENT);
318
   
315 319
   public static final ConfigItem<String> PROXY_CLIENT_PATH_SEGMENT =
316 320
      new ConfigItem<>(String.class, "proxyPathSegment", "", "", "", Type.WEB_CLIENT);
317 321