changeset 4378:9e2fc6911ac8 varian

adding option to disable orthance explorer when http server is enabled
author Andrew Wallis <andrew.wallis@varian.com>>
date Fri, 11 Dec 2020 14:57:31 -0500
parents b002f9abe802
children 85b5b0e1bac9
files OrthancServer/Resources/Configuration.json OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestApi.h OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp OrthancServer/Sources/main.cpp
diffstat 5 files changed, 34 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Resources/Configuration.json	Thu Dec 17 11:27:37 2020 +0100
+++ b/OrthancServer/Resources/Configuration.json	Fri Dec 11 14:57:31 2020 -0500
@@ -71,6 +71,12 @@
   // Explorer will not be available.
   "HttpServerEnabled" : true,
 
+  // Enable/Disable the Orthanc Explorer UI.  This option is only
+  // meaningful if the HttpServerEnabled is set to true 
+  /**
+  "OrthancExplorerEnabled" : true,
+  **/
+
   // HTTP port for the REST services and for the GUI
   "HttpPort" : 8042,
 
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Thu Dec 17 11:27:37 2020 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Fri Dec 11 14:57:31 2020 -0500
@@ -205,7 +205,8 @@
 
   // Registration of the various REST handlers --------------------------------
 
-  OrthancRestApi::OrthancRestApi(ServerContext& context) : 
+  OrthancRestApi::OrthancRestApi(ServerContext& context, 
+                                 bool orthancExplorerEnabled) : 
     context_(context),
     leaveBarrier_(false),
     resetRequestReceived_(false),
@@ -213,7 +214,7 @@
                     "orthanc_rest_api_active_requests", 
                     MetricsType_MaxOver10Seconds)
   {
-    RegisterSystem();
+    RegisterSystem(orthancExplorerEnabled);
 
     RegisterChanges();
     RegisterResources();
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.h	Thu Dec 17 11:27:37 2020 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.h	Fri Dec 11 14:57:31 2020 -0500
@@ -58,7 +58,7 @@
     bool                            resetRequestReceived_;
     MetricsRegistry::SharedMetrics  activeRequests_;
 
-    void RegisterSystem();
+    void RegisterSystem(bool orthancExplorerEnabled);
 
     void RegisterChanges();
 
@@ -75,7 +75,8 @@
     static void ShutdownOrthanc(RestApiPostCall& call);
 
   public:
-    explicit OrthancRestApi(ServerContext& context);
+    explicit OrthancRestApi(ServerContext& context,
+                            bool orthancExplorerEnabled);
 
     virtual bool Handle(HttpOutput& output,
                         RequestOrigin origin,
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Thu Dec 17 11:27:37 2020 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp	Fri Dec 11 14:57:31 2020 -0500
@@ -556,9 +556,12 @@
   }
 
 
-  void OrthancRestApi::RegisterSystem()
+  void OrthancRestApi::RegisterSystem(bool orthancExplorerEnabled)
   {
-    Register("/", ServeRoot);
+    if (orthancExplorerEnabled)
+    {
+      Register("/", ServeRoot);
+    }
     Register("/system", GetSystemInformation);
     Register("/statistics", GetStatistics);
     Register("/tools/generate-uid", GenerateUid);
--- a/OrthancServer/Sources/main.cpp	Thu Dec 17 11:27:37 2020 +0100
+++ b/OrthancServer/Sources/main.cpp	Fri Dec 11 14:57:31 2020 -0500
@@ -1229,10 +1229,25 @@
   FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer");
 #endif
 
-  context.GetHttpHandler().Register(staticResources, false);
+  // Do not register static resources if orthanc explorer is disabled
+  bool orthancExplorerEnabled = false;
+  {
+    OrthancConfiguration::ReaderLock lock;
+    orthancExplorerEnabled = lock.GetConfiguration().GetBooleanParameter(
+        "OrthancExplorerEnabled", true);
+  }
+
+  if (orthancExplorerEnabled)
+  {
+    context.GetHttpHandler().Register(staticResources, false);
+  }
+  else
+  {
+    LOG(WARNING) << "Orthanc Explorer UI is disabled";
+  }
 
   // Thirdly, consider the built-in REST API of Orthanc
-  OrthancRestApi restApi(context);
+  OrthancRestApi restApi(context, orthancExplorerEnabled);
   context.GetHttpHandler().Register(restApi, true);
 
   context.SetupJobsEngine(false /* not running unit tests */, loadJobsFromDatabase);