From c87b9ad9af28a299a45675adf55038fd4a92eb26 Mon Sep 17 00:00:00 2001 From: Dylan Bickerstaff Date: Sun, 5 Jan 2020 23:05:27 -0500 Subject: [PATCH] Added comments to Misc.cs --- SuperGrate/Classes/Misc.cs | 95 ++++++++++++++++++++++++++++++++++++-- SuperGrate/Main.cs | 2 +- SuperGrate/Main.resx | 3 -- 3 files changed, 91 insertions(+), 9 deletions(-) diff --git a/SuperGrate/Classes/Misc.cs b/SuperGrate/Classes/Misc.cs index ecd8730..43789da 100644 --- a/SuperGrate/Classes/Misc.cs +++ b/SuperGrate/Classes/Misc.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Microsoft.Win32; using System.IO; -using System.Net.NetworkInformation; using System.Security.Principal; using System.Management; using SuperGrate.UserList; @@ -13,8 +12,19 @@ namespace SuperGrate { class Misc { + /// + /// A list of Local, Non-Domain SIDs on a host set by: GetLocalUsersSIDsFromHost(). + /// public static Dictionary LocalSIDToUser = new Dictionary(); + /// + /// If true, will cancel any task pertaining to Remote Profile Deletions. + /// private static bool ShouldCancelRemoteProfileDelete = false; + /// + /// Checks if the host provided is the current machine running Super Grate. + /// + /// Hostname to check against. + /// True if is this machine, false if otherwise. public static bool IsHostThisMachine(string Host) { if(Host.ToLower() == Environment.MachineName.ToLower()) @@ -27,6 +37,11 @@ public static bool IsHostThisMachine(string Host) } return false; } + /// + /// Returns the best path to "ManagementScope" based on the host provided. (If the host provided is the current host then the best path is "\root\cimv2" otherwise it is "\\HOST\root\cimv2".) + /// + /// Host to check against. + /// Either "\root\cimv2" or "\\HOST\root\cimv2". public static string GetBestManagementScope(string Host) { if (IsHostThisMachine(Host)) @@ -38,6 +53,11 @@ public static string GetBestManagementScope(string Host) return @"\\" + Host + @"\root\cimv2"; } } + /// + /// Returns the best path to C:\ based on the host provided. (If the host provided is the current host then the best path is "C:\" otherwise it is "\\HOST\C$\".) + /// + /// Host to check against. + /// Either "C:\" or "\\HOST\C$\". public static string GetBestPathToC(string Host) { if(IsHostThisMachine(Host)) @@ -49,6 +69,10 @@ public static string GetBestPathToC(string Host) return @"\\" + Host + @"\C$\"; } } + /// + /// Fills the LocalSIDToUser property for other methods in this class with a list of SIDs (Security Identifiers / Local User Profiles (Non-Domain)) from a host. + /// + /// Host to get SIDs from. public static void GetLocalUsersSIDsFromHost(string Host) { LocalSIDToUser.Clear(); @@ -69,6 +93,11 @@ public static void GetLocalUsersSIDsFromHost(string Host) Logger.Exception(e, "Failed to get a list of Local Users' SIDs from host: " + Host + "."); } } + /// + /// Attempts to resolve an identity (Store ID / Security ID) to a DOMAIN\USERNAME string. If failed, returns the given identity string. + /// + /// A Store ID or SID (Security Identifier) to resolve. + /// DOMAIN\USERNAME. public static string GetUserByIdentity(string Identity) { try @@ -95,6 +124,13 @@ public static string GetUserByIdentity(string Identity) return Identity; } } + /// + /// Retrieves a single users properties from a Host. + /// + /// A template row to fill in with information from the host. + /// A host computer to get the information from. + /// An SID (Security Identifier) of the user profile on the host. + /// Filled in UserRow. public static Task GetUserFromHost(UserRow TemplateRow, string Host, string SID) { return Task.Run(() => @@ -150,6 +186,11 @@ public static Task GetUserFromHost(UserRow TemplateRow, string Host, st return row; }); } + /// + /// Retrieves users' properties from host based on the ULControl.CurrentHeaderRow property. + /// + /// Host to get information from. + /// UserRows. public static Task GetUsersFromHost(string Host) { return Task.Run(async () => @@ -196,6 +237,11 @@ public static Task GetUsersFromHost(string Host) } }); } + /// + /// Gets SID string from an Object in the Store. + /// + /// ID of the Store Object. + /// String of SID. static public Task GetSIDFromStore(string ID) { return Task.Run(() => { @@ -218,6 +264,12 @@ static public Task GetSIDFromStore(string ID) } }); } + /// + /// Gets a single user from the Backup Store and returns the information in a UserRow object. + /// + /// A template UserRow to fill the values of. + /// Backup Store ID to retrieve. + /// UserRow object. static public Task GetUserFromStore(UserRow TemplateRow, string ID) { Dictionary Files = new Dictionary @@ -267,6 +319,10 @@ static public Task GetUserFromStore(UserRow TemplateRow, string ID) } }); } + /// + /// Retrieves users from the Backup Store in a UserRows object. (UserRows are based off of the ULControl.CurrentHeaderRow property.) + /// + /// A UserRow object. static public Task GetUsersFromStore() { return Task.Run(async () => @@ -297,6 +353,11 @@ static public Task GetUsersFromStore() } }); } + /// + /// Deletes store items based on their ID. + /// + /// List of IDs (Profile Backups) to delete from the store. + /// Awaitable Task. public static Task DeleteFromStore(string[] IDs) { return Task.Run(() => @@ -317,6 +378,12 @@ public static Task DeleteFromStore(string[] IDs) } }); } + /// + /// Deletes a list of SIDs (Security Identifiers (User Profiles)) from a host. + /// + /// Host to delete profiles from. + /// List of SIDs that identify the profiles that need to be deleted. + /// Awaitable Task. public static Task DeleteFromSource(string Host, string[] SIDs) { ShouldCancelRemoteProfileDelete = false; @@ -357,11 +424,15 @@ await Remote.StartProcess( } }); } - public static async void CancelRemoteProfileDelete(string Target) + /// + /// Cancels the agent on the remote computer running the profile delete command. + /// + /// Hostname to cancel profile delete agent on. + public static async void CancelRemoteProfileDelete(string Host) { ShouldCancelRemoteProfileDelete = true; Logger.Information("Sending KILL command to remote target..."); - if (await Remote.KillProcess(Target, "SuperGratePD.exe")) + if (await Remote.KillProcess(Host, "SuperGratePD.exe")) { Logger.Success("KILL command sent."); } @@ -370,6 +441,11 @@ public static async void CancelRemoteProfileDelete(string Target) Logger.Error("Failed to send KILL command."); } } + /// + /// Gets the CPU architecture from a remote host. + /// + /// Host to get the architecture information from. + /// CPU architecture. public static Task GetRemoteArch(string Host) { Logger.Information("Reading OS Architecture..."); @@ -395,10 +471,19 @@ public static Task GetRemoteArch(string Host) return null; }); } - public static void MainMenuSetState(MainMenu Menu, bool Enabled) + /// + /// Enables or disables top level menu items in a MainMenu object. + /// + /// The MainMenu object. + /// Enable or disable the menu items? + /// An array of top level menu items' "text" properties to affect. + public static void MainMenuSetState(MainMenu Menu, bool Enabled, string[] Menus = null) { - foreach(MenuItem mi in Menu.MenuItems) + List lMenus = new List(); + if (Menus != null) lMenus.AddRange(Menus); + foreach (MenuItem mi in Menu.MenuItems) { + if (Menus != null && !lMenus.Contains(mi.Text)) continue; mi.Enabled = Enabled; } } diff --git a/SuperGrate/Main.cs b/SuperGrate/Main.cs index c11715d..87cb490 100644 --- a/SuperGrate/Main.cs +++ b/SuperGrate/Main.cs @@ -89,7 +89,7 @@ private RunningTask Running { btnStartStop.Text = "Stop"; Cursor = Cursors.AppStarting; Logger.UpdateProgress(true); - Misc.MainMenuSetState(MainMenu, false); + Misc.MainMenuSetState(MainMenu, false, new string[] { "&Settings", "&View" }); storeRunningTask = value; imgLoadLogo.Enabled = btnStartStop.Enabled = diff --git a/SuperGrate/Main.resx b/SuperGrate/Main.resx index 4af5d68..947d8a2 100644 --- a/SuperGrate/Main.resx +++ b/SuperGrate/Main.resx @@ -126,7 +126,4 @@ 127, 17 - - 258, 17 - \ No newline at end of file