From e780aea11e85c74a7bff3ac7da8134edb348c6db Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 11:57:33 -0400 Subject: [PATCH 1/4] Adds an interface to list files in the static directories --- TGServerService/Config.cs | 21 +++++++++++++++++++++ TGServiceInterface/Config.cs | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/TGServerService/Config.cs b/TGServerService/Config.cs index 11d0f5c2ce..52553c70e2 100644 --- a/TGServerService/Config.cs +++ b/TGServerService/Config.cs @@ -119,5 +119,26 @@ namespace TGServerService return e.ToString(); } } + + [OperationBehavior(Impersonation = ImpersonationOption.Required)] + public IList ListStaticDirectory(string subDir, out string error) + { + try + { + DirectoryInfo dirToEnum = new DirectoryInfo(Path.Combine(StaticDirs, subDir ?? "")); + var result = new List(); + foreach (var I in dirToEnum.GetFiles()) + result.Add(I.Name); + foreach (var I in dirToEnum.GetDirectories()) + result.Add("@" + I.Name); + error = null; + return result; + } + catch (Exception e) + { + error = e.ToString(); + return null; + } + } } } diff --git a/TGServiceInterface/Config.cs b/TGServiceInterface/Config.cs index a06dcdaec3..c0a58ecde3 100644 --- a/TGServiceInterface/Config.cs +++ b/TGServiceInterface/Config.cs @@ -18,6 +18,16 @@ namespace TGServiceInterface [OperationContract] string ServerDirectory(); + /// + /// Returns the file contents of the specified server directory + /// Subdirectories will be prefixed with '@' + /// + /// Subdirectory to enumerate, enumerates the root directory if null + /// null on success, error message on failure + /// A list of files in the enumerated static directory on success, null on failure + [OperationContract] + IList ListStaticDirectory(string subpath, out string error); + /// /// For when you really just need to see the raw data of the config /// From 9f8e829b0031cc1f184d9972326d45fb29a9a700 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 12:13:28 -0400 Subject: [PATCH 2/4] Fixed local connections not allowing user impersonation --- TGServiceInterface/Server.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Server.cs index 0d735c161c..31c01b92ec 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Server.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Net; using System.Net.Security; +using System.Security.Principal; using System.ServiceModel; namespace TGServiceInterface { @@ -107,6 +108,7 @@ namespace TGServiceInterface if (HTTPSURL == null) { outChannel = new ChannelFactory(new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 10, 0) }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))); + outChannel.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; return outChannel.CreateChannel(); } From 23311358604cef8b5cfc953c20d7dd669d2daae5 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 12:19:47 -0400 Subject: [PATCH 3/4] Use / instead of @ --- TGServerService/Config.cs | 2 +- TGServiceInterface/Config.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TGServerService/Config.cs b/TGServerService/Config.cs index 52553c70e2..55e34fd90e 100644 --- a/TGServerService/Config.cs +++ b/TGServerService/Config.cs @@ -130,7 +130,7 @@ namespace TGServerService foreach (var I in dirToEnum.GetFiles()) result.Add(I.Name); foreach (var I in dirToEnum.GetDirectories()) - result.Add("@" + I.Name); + result.Add('/' + I.Name); error = null; return result; } diff --git a/TGServiceInterface/Config.cs b/TGServiceInterface/Config.cs index c0a58ecde3..6af5f6c675 100644 --- a/TGServiceInterface/Config.cs +++ b/TGServiceInterface/Config.cs @@ -20,7 +20,7 @@ namespace TGServiceInterface /// /// Returns the file contents of the specified server directory - /// Subdirectories will be prefixed with '@' + /// Subdirectories will be prefixed with '/' /// /// Subdirectory to enumerate, enumerates the root directory if null /// null on success, error message on failure From 951eb57ee4d24dc7b7be8481478cf2760e4a9f1d Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 21 Sep 2017 12:20:11 -0400 Subject: [PATCH 4/4] Console command to enumerate static dir --- TGCommandLine/ConfigCommands.cs | 35 ++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/TGCommandLine/ConfigCommands.cs b/TGCommandLine/ConfigCommands.cs index e95c7d482a..2d1b4e0a22 100644 --- a/TGCommandLine/ConfigCommands.cs +++ b/TGCommandLine/ConfigCommands.cs @@ -10,7 +10,7 @@ namespace TGCommandLine public ConfigCommand() { Keyword = "config"; - Children = new Command[] { new ConfigServerDirectoryCommand(), new ConfigDownloadCommand(), new ConfigUploadCommand() }; + Children = new Command[] { new ConfigServerDirectoryCommand(), new ConfigDownloadCommand(), new ConfigUploadCommand(), new ConfigListCommand() }; } public override string GetHelpText() { @@ -18,6 +18,39 @@ namespace TGCommandLine } } + class ConfigListCommand : Command + { + public ConfigListCommand() + { + Keyword = "list"; + } + + public override string GetHelpText() + { + return "Lists the contents of the server's static directory, optionally specifying a subdirectory"; + } + + public override string GetArgumentString() + { + return "[path to subdirectory]"; + } + protected override ExitCode Run(IList parameters) + { + var list = Server.GetComponent().ListStaticDirectory(parameters.Count > 0 ? parameters[0] : null, out string error); + if(list == null) + { + OutputProc(error); + return ExitCode.ServerError; + } + if (list.Count == 0) + OutputProc("The static directory is empty!"); + else + foreach (var I in list) + OutputProc(I); + return ExitCode.Normal; + } + } + class ConfigServerDirectoryCommand : Command { public ConfigServerDirectoryCommand()