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() diff --git a/TGServerService/Config.cs b/TGServerService/Config.cs index 11d0f5c2ce..55e34fd90e 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..6af5f6c675 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 /// 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(); }