mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-30 16:39:21 +01:00
Merge pull request #156 from Cyberboss/WhoCapitalizesIRCChannels
Adds HTTPS interface and makes the GUI/CLI work remotely
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceProcess;
|
||||
using System.Threading;
|
||||
using TGServiceInterface;
|
||||
|
||||
namespace TGServerService
|
||||
@@ -13,6 +14,7 @@ namespace TGServerService
|
||||
//only deprecate events, do not reuse them
|
||||
public enum EventID
|
||||
{
|
||||
Authentication = 1,
|
||||
ChatCommand = 100,
|
||||
ChatConnectFail = 200,
|
||||
ChatProviderStartFail = 300,
|
||||
@@ -95,6 +97,11 @@ namespace TGServerService
|
||||
ActiveService.EventLog.WriteEntry(message, EventLogEntryType.Warning, (int)id);
|
||||
}
|
||||
|
||||
public static void WriteAccess(string username, bool authSuccess)
|
||||
{
|
||||
ActiveService.EventLog.WriteEntry(String.Format("Access from: {0}", username), authSuccess ? EventLogEntryType.SuccessAudit : EventLogEntryType.FailureAudit, (int)EventID.Authentication);
|
||||
}
|
||||
|
||||
ServiceHost host; //the WCF host
|
||||
|
||||
void MigrateSettings(int oldVersion, int newVersion)
|
||||
@@ -142,21 +149,32 @@ namespace TGServerService
|
||||
}
|
||||
Environment.CurrentDirectory = Config.ServerDirectory;
|
||||
|
||||
host = new ServiceHost(typeof(TGStationServer), new Uri[] { new Uri("net.pipe://localhost") })
|
||||
var instance = new TGStationServer();
|
||||
|
||||
host = new ServiceHost(instance, new Uri[] { new Uri("net.pipe://localhost"), new Uri(String.Format("https://localhost:{0}", Server.HTTPSPort)) })
|
||||
{
|
||||
CloseTimeout = new TimeSpan(0, 0, 5)
|
||||
}; //construction runs here
|
||||
};
|
||||
|
||||
foreach (var I in Server.ValidInterfaces)
|
||||
AddEndpoint(I);
|
||||
|
||||
host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, Config.CertificateURL);
|
||||
host.Authorization.ServiceAuthorizationManager = instance;
|
||||
|
||||
host.Open(); //...or maybe here, doesn't really matter
|
||||
}
|
||||
|
||||
//shorthand for adding the WCF endpoint
|
||||
void AddEndpoint(Type typetype)
|
||||
{
|
||||
host.AddServiceEndpoint(typetype, new NetNamedPipeBinding(), Server.MasterPipeName + "/" + typetype.Name);
|
||||
var bindingName = Server.MasterInterfaceName + "/" + typetype.Name;
|
||||
host.AddServiceEndpoint(typetype, new NetNamedPipeBinding(), bindingName);
|
||||
var httpsBinding = new WSHttpBinding();
|
||||
var requireAuth = typetype.Name != typeof(ITGConnectivity).Name;
|
||||
httpsBinding.Security.Mode = requireAuth ? SecurityMode.TransportWithMessageCredential : SecurityMode.Transport; //do not require auth for a connectivity check
|
||||
httpsBinding.Security.Message.ClientCredentialType = requireAuth ? MessageCredentialType.UserName : MessageCredentialType.None;
|
||||
host.AddServiceEndpoint(typetype, httpsBinding, bindingName);
|
||||
}
|
||||
|
||||
//when we is kill
|
||||
|
||||
Reference in New Issue
Block a user