Skip to content

Commit e9d52ee

Browse files
committed
Merge branch 'main' of https://github.com/sixgrid/BuildService into main
2 parents 194bfd3 + 6ecd9b8 commit e9d52ee

4 files changed

Lines changed: 41 additions & 16 deletions

File tree

BuildService.Shared/Configuration/ConfigManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static class ConfigManager
2222

2323
public static Bindable<string> authUsername;
2424
public static Bindable<string> authPassword;
25+
public static BindableBool authEnable;
2526

2627
public static Bindable<string> sysRootDataLocation;
2728

@@ -45,6 +46,7 @@ public static void Initialize()
4546

4647
authUsername = ReadString(@"authUsername", @"admin");
4748
authPassword = ReadString(@"authPassword", @"password");
49+
authEnable = ReadBool(@"authEnable", true);
4850

4951
sysRootDataLocation = ReadString(@"sysRootDataLocation", Path.Combine(ApplicationDirectory, @"build_data"));
5052

BuildService.Shared/Server.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ public void Thread_WebSocketServer(EventWaitHandle handle)
8282
WebSocketServer.AddWebSocketService<WebSocket.Root>(@"/");
8383
WebSocketServer.Realm = String.Format(@"BuildService");
8484

85-
WebSocketServer.UserCredentialsFinder = WebSocketServerCredentialHandle;
86-
WebSocketServer.AuthenticationSchemes = AuthenticationSchemes.Basic;
85+
if (ConfigManager.authEnable)
86+
{
87+
WebSocketServer.UserCredentialsFinder = WebSocketServerCredentialHandle;
88+
WebSocketServer.AuthenticationSchemes = AuthenticationSchemes.Basic;
89+
}
8790

8891
WebSocketServer.Start();
8992

BuildService.Shared/WebServer/Instance.cs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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" : "";

BuildService/websocket.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
buttonConnect = document.querySelector("button[action=connect]"),
143143
output = document.querySelector("#output"),
144144
textarea = document.querySelector("textarea"),
145-
wsUri = `ws${window.location.protocol.replace('http', '')}//$CREDENTIAL_INJECT@${window.location.host}/socket/`,
145+
wsUri = `ws${window.location.protocol.replace('http', '')}//$CREDENTIAL_INJECT${window.location.host}/socket/`,
146146
websocket = null;
147147
// button.addEventListener("click", onClickButton);
148148
buttonConnect.addEventListener("click", onClickButtonConnect);

0 commit comments

Comments
 (0)