public void RunOperation(ISofOperation operation) { RaSofOperation raOperation = new RaSofOperation(operation.RawOperation); try { switch (operation.Type) { case RaValue.StartRemoteDesktop: raOperation = StartRemoteDesktop(raOperation); break; case RaValue.StopRemoteDesktop: raOperation = StopRemoteDesktop(raOperation); break; case RaValue.RemoteDesktopPassword: raOperation = SetRemoteDesktopPassword(raOperation); break; default: throw new Exception(String.Format("Unknown operation `{0}` for Remote Assistance. Ignoring.", operation.Type)); } } catch (Exception e) { Logger.Error("Error running RA operation."); Logger.Exception(e); } SendResults(raOperation); }
public void ProcessAfterRebootResults(ISofOperation operation) { if (operation != null) { SaveAndSendResults(operation); } }
public void RunOperation(ISofOperation operation) { RaSofOperation raOperation = new RaSofOperation(operation.RawOperation); try { switch (operation.Type) { case RaValue.StartRemoteDesktop: raOperation = StartRemoteDesktop(raOperation); break; case RaValue.StopRemoteDesktop: raOperation = StopRemoteDesktop(raOperation); break; case RaValue.RemoteDesktopPassword: raOperation = SetRemoteDesktopPassword(raOperation); break; default: throw new Exception(String.Format("Unknown operation `{0}` for Remote Assistance. Ignoring.", operation.Type)); } } catch (Exception e) { Logger.Error("Error running RA operation."); Logger.Exception(e); } SendResults(raOperation); }
private void MajorFailure(ISofOperation operation, Exception e) { var json = new JObject(); json.Add(OperationKey.OperationId, operation.Id); json.Add(OperationKey.AgentId, Settings.AgentId); json.Add(OperationKey.Plugin, operation.Plugin); json.Add(OperationKey.Success, false.ToString().ToLower()); json.Add("app_id", String.Empty); json.Add("error", "Exception: " + e.Message + ". Please refer to agent logs for more specific details."); json.Add("apps_to_delete", new JArray()); json.Add("apps_to_add", new JArray()); json.Add("reboot_required", false.ToString().ToLower()); json.Add("data", "{\r\n \"name\": \"\",\r\n \"description\": \"\",\r\n \"kb\": \"\",\r\n \"vendor_severity\": \"\",\r\n \"rv_severity\": \"\",\r\n \"support_url\": \"\",\r\n \"release_date\": 0.0,\r\n \"vendor_id\": \"\",\r\n \"vendor_name\": \"\",\r\n \"repo\": \"\",\r\n \"version\": \"\",\r\n \"file_data\": []\r\n}"); var results = SendResults(json.ToString(), operation.Api); //TODO: THIS DOESNT WORK, I BELIEVE ITS DUE TO APP_ID NOT BEING POPULATED.. DISCUSS WITH ALLEN, WE NEED TO BE ABLE TO SEND ERROR AT OPERATION_ID LEVEL!. double temp; var isHttpCode = double.TryParse(results, out temp); if (!String.IsNullOrEmpty(results) && !isHttpCode) { Logger.Log("Received response from server after sending Failure results operation: {0} ", LogLevel.Warning, results); } }
private void MajorFailure(ISofOperation operation, Exception e) { var json = new JObject(); json.Add(OperationKey.OperationId, operation.Id); json.Add(OperationKey.AgentId, Settings.AgentId); json.Add(OperationKey.Plugin, operation.Plugin); json.Add(OperationKey.Success, false.ToString().ToLower()); json.Add("app_id", String.Empty); json.Add("error", "Exception: " + e.Message + ". Please refer to agent logs for more specific details."); json.Add("apps_to_delete", new JArray()); json.Add("apps_to_add", new JArray()); json.Add("reboot_required", false.ToString().ToLower()); //TODO need to change string into jsonobject, crashing agent sever communication json.Add("data", emptyData()); //"{\r\n \"name\": \"\",\r\n \"description\": \"\",\r\n \"kb\": \"\",\r\n " + //" \"vendor_severity\": \"\",\r\n \"rv_severity\": \"\",\r\n \"support_url\": \"\",\r\n " + //"\"release_date\": 0.0,\r\n \"vendor_id\": \"\",\r\n \"vendor_name\": \"\",\r\n \"repo\": \"\",\r\n " + //"\"version\": \"\",\r\n \"file_data\": []\r\n}"); var results = SendResults(json.ToString(), operation.Api); double temp; var isHttpCode = double.TryParse(results, out temp); if (!String.IsNullOrEmpty(results) && !isHttpCode) { Logger.Log("Received response from server after sending Failure results operation: {0} ", LogLevel.Warning, results); } }
private void PluginNotFound(ISofOperation operation) { Logger.Log("Plugin {0} not found.", LogLevel.Error, operation.Plugin); var e = new Exception(String.Format("Plugin {0} not found.", operation.Plugin)); MajorFailure(operation, e); }
/// <summary> /// This takes care of executing any operation received by the server. /// </summary> /// <param name="operation"></param> public void RunOperation(ISofOperation operation) { var rvOperation = new RvSofOperation(operation.RawOperation); switch (rvOperation.Type) { case OperationValue.InstallWindowsUpdate: rvOperation.Api = ApiCalls.RvInstallWinUpdateResults(); rvOperation.Type = OperationValue.InstallWindowsUpdate; InstallWindowsUpdate(rvOperation); break; case OperationValue.InstallSupportedApp: rvOperation.Api = ApiCalls.RvInstallSupportedAppsResults(); rvOperation.Type = OperationValue.InstallSupportedApp; InstallSupportedApplication(rvOperation); break; case OperationValue.InstallCustomApp: rvOperation.Api = ApiCalls.RvInstallCustomAppsResults(); rvOperation.Type = OperationValue.InstallCustomApp; InstallCustomApplication(rvOperation); break; case OperationValue.InstallAgentUpdate: rvOperation.Api = ApiCalls.RvInstallAgentUpdateResults(); rvOperation.Type = OperationValue.InstallAgentUpdate; InstallAgentUpdate(rvOperation); break; case OperationValue.Uninstall: rvOperation.Api = ApiCalls.RvUninstallOperation(); rvOperation.Type = OperationValue.Uninstall; UninstallOperation(rvOperation); break; case OperationValue.AgentUninstall: rvOperation.Type = OperationValue.AgentUninstall; UninstallRvAgentOperation(); break; case RvOperationValue.UpdatesAndApplications: rvOperation.Type = RvOperationValue.UpdatesAndApplications; rvOperation = UpdatesApplicationsOperation(rvOperation); rvOperation.RawResult = RvFormatter.Applications(rvOperation); rvOperation.Api = ApiCalls.RvUpdatesApplications(); SendResults(rvOperation); break; case OperationValue.ResumeOp: ResumeOperations(); break; default: Logger.Log("Received unrecognized operation. Ignoring."); break; } }
/// <summary> /// This takes care of executing any operation received by the server. /// </summary> /// <param name="operation"></param> public void RunOperation(ISofOperation operation) { var rvOperation = new RvSofOperation(operation.RawOperation); switch (rvOperation.Type) { case OperationValue.InstallWindowsUpdate: rvOperation.Api = ApiCalls.RvInstallWinUpdateResults(); rvOperation.Type = OperationValue.InstallWindowsUpdate; InstallWindowsUpdate(rvOperation); break; case OperationValue.InstallSupportedApp: rvOperation.Api = ApiCalls.RvInstallSupportedAppsResults(); rvOperation.Type = OperationValue.InstallSupportedApp; InstallSupportedApplication(rvOperation); break; case OperationValue.InstallCustomApp: rvOperation.Api = ApiCalls.RvInstallCustomAppsResults(); rvOperation.Type = OperationValue.InstallCustomApp; InstallCustomApplication(rvOperation); break; case OperationValue.InstallAgentUpdate: rvOperation.Api = ApiCalls.RvInstallAgentUpdateResults(); rvOperation.Type = OperationValue.InstallAgentUpdate; InstallAgentUpdate(rvOperation); break; case OperationValue.Uninstall: rvOperation.Api = ApiCalls.RvUninstallOperation(); rvOperation.Type = OperationValue.Uninstall; UninstallOperation(rvOperation); break; case OperationValue.AgentUninstall: rvOperation.Type = OperationValue.AgentUninstall; UninstallRvAgentOperation(); break; case RvOperationValue.UpdatesAndApplications: rvOperation.Type = RvOperationValue.UpdatesAndApplications; rvOperation = UpdatesApplicationsOperation(rvOperation); rvOperation.RawResult = RvFormatter.Applications(rvOperation); rvOperation.Api = ApiCalls.RvUpdatesApplications(); SendResults(rvOperation); break; case OperationValue.ResumeOp: ResumeOperations(); break; default: Logger.Log("Received unrecognized operation. Ignoring."); break; } }
public static MonSofOperation ConvertMonSofOperation(ISofOperation operation) { var tempOp = new MonSofOperation(); tempOp.Id = operation.Id; tempOp.Plugin = operation.Plugin; tempOp.Type = operation.Type; tempOp.RawOperation = operation.RawOperation; tempOp.RawResult = operation.RawResult; tempOp.JsonMessage = operation.JsonMessage; return tempOp; }
/// <summary> /// Converts the json message from the server for response uri into a jtoken. /// </summary> /// <param name="jmsg">Json messega from the sever containing response uris.</param> public static void RefreshUris(ISofOperation jmsg) { try { string json = jmsg.RawOperation; JObject parjson = JObject.Parse(json); responseUri = parjson["data"]; } catch (Exception e) { Logger.Log("Error while processing \"refresh_uri\".", LogLevel.Error); Logger.Log(e.Message); } }
public static MonSofOperation ConvertMonSofOperation(ISofOperation operation) { var tempOp = new MonSofOperation(); tempOp.Id = operation.Id; tempOp.Plugin = operation.Plugin; tempOp.Type = operation.Type; tempOp.RawOperation = operation.RawOperation; tempOp.RawResult = operation.RawResult; tempOp.JsonMessage = operation.JsonMessage; return(tempOp); }
public static void SaveRebootOperationId(ISofOperation operation) { try { var location = Path.Combine(Settings.AgentDirectory, "rebootoperation.data"); if (File.Exists(location)) { File.Delete(location); } File.WriteAllText(location, operation.Id); } catch (Exception e) { Logger.Log("Unable to save Reboot operation id to disk. Error: {0} ", LogLevel.Error, e.Message); } }
/// <summary> /// Gets the systems information and formats it as to the servers requiremtns. /// Uses current operation for details. /// Example: /// { /// "operation": "new_agent", /// "customer_name": "default", /// "rebooted": "no", /// "system_info": { /// "os_code": "windows", /// "os_string": "Windows 7 Professional N", /// "version": "6.1.7601", /// "bit_type": "64", /// "computer_name": "DISCIPLINE-1", /// "host_name": "discipline-1", /// } /// "hardware": { /// "cpu": [ /// { /// "cpu_id": 1, /// "name": "Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz", /// "bit_type": 64, /// "speed_mhz": 2401, /// "cores": 4, /// "cache_kb": 1024 /// } /// ], /// "memory": 25165824, /// "display": [ /// { /// "name": "NVIDIA GeForce GTX 660M ", /// "speed_mhz": "GeForce GTX 660M", /// "ram_kb": 0 /// } /// ], /// "nic": [ /// { /// "name": "Local Area Connection", /// "ip_address": "10.0.0.2", /// "mac": "3085A925BFD6" /// } /// { /// "name": "VMware Network Adapter VMnet1", /// "ip_address": "192.168.110.1", /// "mac": "005056C00001" /// }, /// { /// "name": "VMware Network Adapter VMnet8", /// "ip_address": "192.168.252.1", /// "mac": "005056C00008" /// } /// ], /// "storage": [ /// { /// "free_size_kb": 155600024, /// "name": "C:", /// "size_kb": 499872764, /// "file_system": "NTFS" /// } /// ] /// } /// }, /// "plugins": { /// "monitor": { /// "data": { /// "memory": { /// "used_percent": 55.66, /// "free_percent": 44.34, /// "used": 13980004, /// "free": 11138036 /// }, /// "file_system": [ /// { /// "used_percent": 68.87, /// "free_percent": 31.13, /// "used": 352535285760, /// "free": 159334424576, /// "name": "C:\\", /// "mount": "C:\\" /// } /// ], /// "cpu": { /// "idle": 99, /// "user": 0, /// "system": 1 /// } /// } /// }, /// "ra": { /// "public_key": "pubic_key_here", /// }, /// "rv": { /// "data": [all apps in here] /// } /// } /// </summary> /// <param name="operation">Current operations that the agent is working on.</param> /// <returns>Returns the JObect with the gathered information and formated for the servers requiremnts.</returns> private static string InitialDataFormatter(ISofOperation operation) { var json = new JObject(); json[OperationKey.Operation] = operation.Type; json[OperationKey.Customer] = Settings.Customer; json[OperationKey.Rebooted] = Tools.IsBootUp(); json[OperationKey.SystemInfo] = JObject.Parse(GetSystemInfo()); json[OperationKey.HardwareInfo] = JObject.Parse(GetHardwareInfo()); var plugins = new JObject(); foreach (var pluginData in operation.PluginData) { plugins[pluginData.Key] = JObject.Parse(pluginData.Value.RawResult); } json[OperationKey.PluginData] = plugins; return(json.ToString()); }
/// <summary> /// Stores the results of an operation and wheather they were sent successfully to the server. /// </summary> /// <param name="operation">The operation</param> /// <returns></returns> private bool SaveAndSendResults(ISofOperation operation) { const string resultOK = "OK"; try { var result = SendResults(operation.RawResult, operation.Api); switch (operation.Type) { case OperationValue.CheckIn: case OperationValue.NewAgent: case OperationValue.NewAgentId: case OperationValue.Reboot: case OperationValue.Shutdown: case OperationValue.SystemInfo: return(result == resultOK); case OperationValue.Uninstall: case OperationValue.InstallAgentUpdate: case OperationValue.InstallCustomApp: case OperationValue.InstallSupportedApp: case OperationValue.InstallWindowsUpdate: if (result != resultOK) { Logger.Log("Results were not successfully received by server, storing in results queue and will re-send in 10 seconds. "); AddToOperationResultsQueue(operation.RawResult, operation.Api); return(false); } return(true); default: return(result == resultOK); } } catch { return(false); } }
private ISofOperation PluginsInitialDataOperation(ISofOperation operation) { foreach (var plugin in _plugins.Values) { try { var initialPluginData = plugin.InitialData(); if (initialPluginData == null) { continue; } operation.PluginData[plugin.Name] = initialPluginData; } catch (Exception e) { Logger.Log("Could not collect initial data for plugin {0}. Skipping", LogLevel.Error, plugin.Name); Logger.LogException(e); } } return(operation); }
public void ProcessAfterRebootResults(ISofOperation operation) { if (operation != null) SaveAndSendResults(operation); }
/// <summary> /// Stores the results of an operation and wheather they were sent successfully to the server. /// </summary> /// <param name="operation">The operation</param> /// <returns></returns> private bool SaveAndSendResults(ISofOperation operation) { const string resultOK = "OK"; try { var result = SendResults(operation.RawResult, operation.Api); switch (operation.Type) { case OperationValue.CheckIn: case OperationValue.NewAgent: case OperationValue.NewAgentId: case OperationValue.Reboot: case OperationValue.Shutdown: case OperationValue.SystemInfo: return result == resultOK; case OperationValue.Uninstall: case OperationValue.InstallAgentUpdate: case OperationValue.InstallCustomApp: case OperationValue.InstallSupportedApp: case OperationValue.InstallWindowsUpdate: if (result != resultOK) { Logger.Log("Results were not successfully received by server, storing in results queue and will re-send in 10 seconds. "); AddToOperationResultsQueue(operation.RawResult, operation.Api); return false; } return true; default: return result == resultOK; } } catch { return false; } }
/// <summary> /// Provides a way for plugins to store their custom made operations with the agent. /// </summary> /// <param name="operation">Operation to be saved.</param> /// <returns></returns> private bool RegisterPluginOperation(ISofOperation operation) { AddToOperationQueue(operation.ToJson()); return true; }
private ISofOperation PluginsInitialDataOperation(ISofOperation operation) { foreach (var plugin in _plugins.Values) { try { var initialPluginData = plugin.InitialData(); if (initialPluginData == null) continue; operation.PluginData[plugin.Name] = initialPluginData; } catch (Exception e) { Logger.Log("Could not collect initial data for plugin {0}. Skipping", LogLevel.Error, plugin.Name); Logger.LogException(e); } } return operation; }
private void PluginNotFound(ISofOperation operation) { Logger.Log("Plugin {0} not found.", LogLevel.Error, operation.Plugin); var e = new Exception(String.Format("Plugin {0} not found.", operation.Plugin)); MajorFailure(operation, e); }
private void MajorFailure(ISofOperation operation, Exception e) { var json = new JObject(); json.Add(OperationKey.OperationId, operation.Id); json.Add(OperationKey.AgentId, Settings.AgentId); json.Add(OperationKey.Plugin, operation.Plugin); json.Add(OperationKey.Success, false.ToString().ToLower()); json.Add("app_id", String.Empty); json.Add("error", "Exception: " + e.Message + ". Please refer to agent logs for more specific details."); json.Add("apps_to_delete", new JArray()); json.Add("apps_to_add", new JArray()); json.Add("reboot_required", false.ToString().ToLower()); json.Add("data", "{\r\n \"name\": \"\",\r\n \"description\": \"\",\r\n \"kb\": \"\",\r\n \"vendor_severity\": \"\",\r\n \"rv_severity\": \"\",\r\n \"support_url\": \"\",\r\n \"release_date\": 0.0,\r\n \"vendor_id\": \"\",\r\n \"vendor_name\": \"\",\r\n \"repo\": \"\",\r\n \"version\": \"\",\r\n \"file_data\": []\r\n}"); var results = SendResults(json.ToString(), operation.Api); //TODO: THIS DOESNT WORK, I BELIEVE ITS DUE TO APP_ID NOT BEING POPULATED.. DISCUSS WITH ALLEN, WE NEED TO BE ABLE TO SEND ERROR AT OPERATION_ID LEVEL!. double temp; var isHttpCode = double.TryParse(results, out temp); if (!String.IsNullOrEmpty(results) && !isHttpCode ) { Logger.Log("Received response from server after sending Failure results operation: {0} ", LogLevel.Warning, results); } }
private static string InitialDataFormatter(ISofOperation operation) { var json = new JObject(); json[OperationKey.Operation] = operation.Type; json[OperationKey.Customer] = Settings.Customer; json[OperationKey.Rebooted] = Tools.IsBootUp(); json[OperationKey.SystemInfo] = JObject.Parse(GetSystemInfo()); json[OperationKey.HardwareInfo] = JObject.Parse(SystemInfo.Hardware); var plugins = new JObject(); foreach (var pluginData in operation.PluginData) { plugins[pluginData.Key] = JObject.Parse(pluginData.Value.RawResult); } json[OperationKey.PluginData] = plugins; return json.ToString(); }
public void RunOperation(ISofOperation operation) { }
/// <summary> /// Converts the json message from the server for response uri into a jtoken. /// </summary> /// <param name="jmsg">Json messega from the sever containing response uris.</param> public static void RefreshUris(ISofOperation jmsg) { try { string json = jmsg.RawOperation; JObject parjson = JObject.Parse(json); responseUri = parjson["data"]; } catch (Exception e) { Logger.Log("Error while processing \"refresh_uri\".", LogLevel.Error); Logger.Log(e.Message); } }
public void RunOperation(ISofOperation operation) { }
/// <summary> /// Provides a way for plugins to store their custom made operations with the agent. /// </summary> /// <param name="operation">Operation to be saved.</param> /// <returns></returns> private bool RegisterPluginOperation(ISofOperation operation) { AddToOperationQueue(operation.ToJson()); return(true); }
public static void SaveRebootOperationId(ISofOperation operation) { try { var location = Path.Combine(Settings.AgentDirectory, "rebootoperation.data"); if (File.Exists(location)) File.Delete(location); File.WriteAllText(location, operation.Id); } catch (Exception e) { Logger.Log("Unable to save Reboot operation id to disk. Error: {0} ", LogLevel.Error, e.Message); } }
private void MajorFailure(ISofOperation operation, Exception e) { var json = new JObject(); json.Add(OperationKey.OperationId, operation.Id); json.Add(OperationKey.AgentId, Settings.AgentId); json.Add(OperationKey.Plugin, operation.Plugin); json.Add(OperationKey.Success, false.ToString().ToLower()); json.Add("app_id", String.Empty); json.Add("error", "Exception: " + e.Message + ". Please refer to agent logs for more specific details."); json.Add("apps_to_delete", new JArray()); json.Add("apps_to_add", new JArray()); json.Add("reboot_required", false.ToString().ToLower()); //TODO need to change string into jsonobject, crashing agent sever communication json.Add("data", emptyData()); //"{\r\n \"name\": \"\",\r\n \"description\": \"\",\r\n \"kb\": \"\",\r\n " + //" \"vendor_severity\": \"\",\r\n \"rv_severity\": \"\",\r\n \"support_url\": \"\",\r\n " + //"\"release_date\": 0.0,\r\n \"vendor_id\": \"\",\r\n \"vendor_name\": \"\",\r\n \"repo\": \"\",\r\n " + //"\"version\": \"\",\r\n \"file_data\": []\r\n}"); var results = SendResults(json.ToString(), operation.Api); double temp; var isHttpCode = double.TryParse(results, out temp); if (!String.IsNullOrEmpty(results) && !isHttpCode ) { Logger.Log("Received response from server after sending Failure results operation: {0} ", LogLevel.Warning, results); } }