using System.Collections.Generic; using TGServiceInterface; using TGServiceInterface.Components; namespace TGCommandLine { class AdminCommand : InstanceRootCommand { public AdminCommand() { Keyword = "admin"; Children = new Command[] { new AdminViewGroupCommand(), new AdminSetGroupCommand(), new AdminClearGroupCommand(), new AdminRecreateStaticCommand() }; } public override string GetHelpText() { return "Manage instance authentication"; } } class AdminRecreateStaticCommand : ConsoleCommand { public AdminRecreateStaticCommand() { Keyword = "recreate-static-directory"; } protected override ExitCode Run(IList parameters) { var res = Interface.GetComponent().RecreateStaticFolder(); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } public override string GetHelpText() { return "Backup the current static directory and repopulate it from the TGS3.json in the repository"; } } class AdminViewGroupCommand : ConsoleCommand { public AdminViewGroupCommand() { Keyword = "view-group"; } public override string GetHelpText() { return "Print the name of the windows group that is allowed to use the service"; } protected override ExitCode Run(IList parameters) { var group = Interface.GetComponent().GetCurrentAuthorizedGroup(); OutputProc(group ?? "ERROR"); return group != null ? ExitCode.Normal : ExitCode.ServerError; } } class AdminSetGroupCommand : ConsoleCommand { public AdminSetGroupCommand() { Keyword = "set-group"; RequiredParameters = 1; } public override string GetHelpText() { return "Set the windows group allowed to use the service"; } public override string GetArgumentString() { return ""; } protected override ExitCode Run(IList parameters) { var result = Interface.GetComponent().SetAuthorizedGroup(parameters[0]); if(result != null) { OutputProc("Group set to: " + result); return ExitCode.Normal; } else { OutputProc("Failed to find a group named: " + parameters[0]); return ExitCode.ServerError; } } } class AdminClearGroupCommand : ConsoleCommand { public AdminClearGroupCommand() { Keyword = "clear-group"; } public override string GetHelpText() { return "Clears the groups allowed to use the service, leaving only windows administrators"; } protected override ExitCode Run(IList parameters) { var res = Interface.GetComponent().SetAuthorizedGroup(null); if(res != "ADMIN") { OutputProc("Failed to clear the group??? We are currently set to: " + res); return ExitCode.ServerError; } return ExitCode.Normal; } } }