@@ -15,12 +15,24 @@ public static class Instance
1515
1616 public static string WebDataWithTemplatedStrings = @"" ;
1717
18- public static string WebData =>
19- WebDataWithTemplatedStrings
20- . Replace ( @"$WEBSOCKET_URL" ,
21- $@ "ws://{ ConfigManager . authUsername } :{ ConfigManager . authPassword } @$HTTP_HOST:{ ConfigManager . svwsPort } /")
22- . Replace ( @"$CREDENTIAL_INJECT" ,
23- $@ "{ ConfigManager . authUsername } :{ ConfigManager . authPassword } ") ;
18+ public static string WebData
19+ {
20+ get
21+ {
22+ if ( ConfigManager . authEnable )
23+ {
24+ return WebDataWithTemplatedStrings
25+ . Replace ( @"$WEBSOCKET_URL" ,
26+ $@ "ws://{ ConfigManager . authUsername } :{ ConfigManager . authPassword } @$HTTP_HOST:{ ConfigManager . svwsPort } /")
27+ . Replace ( @"$CREDENTIAL_INJECT" ,
28+ $@ "{ ConfigManager . authUsername } :{ ConfigManager . authPassword } @") ;
29+ }
30+ return WebDataWithTemplatedStrings . Replace ( @"WEBSOCKET_URL" , $@ "ws://$HTTP_HOST:{ ConfigManager . svwsPort } ")
31+ . Replace ( $@ "$CREDENTIAL_INJECT", @"" ) ;
32+ }
33+ set { }
34+ }
35+
2436 public static void WebServerThread ( EventWaitHandle handle )
2537 {
2638 var assembly = Assembly . GetExecutingAssembly ( ) ;
@@ -40,7 +52,8 @@ public static void WebServerThread(EventWaitHandle handle)
4052 // Create a Http server and start listening for incoming connections
4153 listener = new HttpListener ( ) ;
4254 listener . Prefixes . Add ( url ) ;
43- listener . AuthenticationSchemes = AuthenticationSchemes . Basic ;
55+ if ( ConfigManager . authEnable )
56+ listener . AuthenticationSchemes = AuthenticationSchemes . Basic ;
4457 listener . Start ( ) ;
4558 Console . WriteLine ( "Listening for connections on {0}" , url ) ;
4659
@@ -72,13 +85,20 @@ public static async Task HandleIncomingConnections()
7285 if ( req . Url != null ) Console . WriteLine ( req . Url . ToString ( ) ) ;
7386
7487 bool isAuthenticated = false ;
75-
76- HttpListenerBasicIdentity ? identity = ( HttpListenerBasicIdentity ) ctx . User ! . Identity ! ;
77- if ( identity == null )
78- isAuthenticated = false ;
88+
89+ if ( ConfigManager . authEnable )
90+ {
91+ HttpListenerBasicIdentity ? identity = ( HttpListenerBasicIdentity ) ctx . User ! . Identity ! ;
92+ if ( identity == null )
93+ isAuthenticated = false ;
94+ else
95+ isAuthenticated = identity . Name == ConfigManager . authUsername &&
96+ identity . Password == ConfigManager . authPassword ;
97+ }
7998 else
80- isAuthenticated = identity . Name == ConfigManager . authUsername &&
81- identity . Password == ConfigManager . authPassword ;
99+ {
100+ isAuthenticated = true ;
101+ }
82102
83103 // Write the response info
84104 string disableSubmit = ! runServer ? "disabled" : "" ;
0 commit comments