Merge pull request #198 from Cyberboss/ConfigACLImpersonation

Adds an interface to list files in the static directories. Fixes local connection config management
This commit is contained in:
Jordan Brown
2017-09-21 12:27:12 -04:00
committed by GitHub
4 changed files with 67 additions and 1 deletions
+34 -1
View File
@@ -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<string> parameters)
{
var list = Server.GetComponent<ITGConfig>().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()
+21
View File
@@ -119,5 +119,26 @@ namespace TGServerService
return e.ToString();
}
}
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public IList<string> ListStaticDirectory(string subDir, out string error)
{
try
{
DirectoryInfo dirToEnum = new DirectoryInfo(Path.Combine(StaticDirs, subDir ?? ""));
var result = new List<string>();
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;
}
}
}
}
+10
View File
@@ -18,6 +18,16 @@ namespace TGServiceInterface
[OperationContract]
string ServerDirectory();
/// <summary>
/// Returns the file contents of the specified server directory
/// Subdirectories will be prefixed with '/'
/// </summary>
/// <param name="subpath">Subdirectory to enumerate, enumerates the root directory if null</param>
/// <param name="error">null on success, error message on failure</param>
/// <returns>A list of files in the enumerated static directory on success, null on failure</returns>
[OperationContract]
IList<string> ListStaticDirectory(string subpath, out string error);
/// <summary>
/// For when you really just need to see the raw data of the config
/// </summary>
+2
View File
@@ -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<T>(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();
}