public JsonResult IgnoreError(string dp) { try { if (!dp.IsBlank()) { _systemContext.DispatchStore.Ignored(dp); Context.UserLog.LogEntry(new RFUserLogEntry { Action = "Ignore Error", Area = "Error Queue", Description = String.Format("Ignored error on processor {0}", dp), IsUserAction = true, IsWarning = false, Timestamp = DateTimeOffset.Now, Username = Username, }); return(GetErrorQueue()); } return(Json(JsonError.Throw("IgnoreError", "System error: blank key"))); } catch (Exception ex) { return(Json(JsonError.Throw("IgnoreError", ex))); } }
public JsonResult RemoveMember(FormCollection collection) { try { var rolename = collection["RoleName"]; var username = collection["Username"]; if (!string.IsNullOrWhiteSpace(rolename) && !string.IsNullOrWhiteSpace(username)) { Context.UserLog.LogEntry(new RFUserLogEntry { Action = "RemoveMember", Area = "Role", IsUserAction = true, IsWarning = false, Username = Username, Description = String.Format("Removed user {0} from role {1}", username, rolename) }); return(Json(Context.UserRole.RemoveMember(rolename, username))); } } catch (Exception ex) { return(Json(JsonError.Throw("RemoveMember", ex))); } return(Json(JsonError.Throw("RemoveMember", "Internal system error."))); }
public JsonResult ChangePassword(string old_p, string new_p) { try { if (!string.IsNullOrWhiteSpace(old_p) && !string.IsNullOrWhiteSpace(new_p)) { RFLoginCache.Login(LoginUsername, old_p); var oldPasswordHash = RFLoginCache.GetPasswordHash(LoginUsername); RFLoginCache.Login(LoginUsername, new_p); var newPasswordHash = RFLoginCache.GetPasswordHash(LoginUsername); var vaults = Context.GetKeysByType <RFKeyVaultKey>(); if (vaults.Any()) { foreach (var vaultKey in vaults.Values) { using (var secure = new RFSecureActivity(Context, LoginUsername, new RFSimpleKeyDomain(vaultKey.Root), vaultKey.Enum)) { var vault = secure.OpenKeyVault(oldPasswordHash); vault.ResetUser(LoginUsername, newPasswordHash); secure.SaveKeyVault(); } } } } Context.UserLog.LogEntry(new RFUserLogEntry { Action = "ChangePassword", Area = "Encryption", Description = "Changed password.", IsUserAction = true, IsWarning = false, Username = Username, Timestamp = DateTimeOffset.Now }); return(Json(true)); } catch (Exception ex) { RFLoginCache.Logout(LoginUsername); return(Json(JsonError.Throw("ChangePassword", ex))); } }
public JsonResult UpdateDocument(string type, long keyReference, string data) { if (!string.IsNullOrWhiteSpace(type) && keyReference > 0 && !string.IsNullOrWhiteSpace(data)) { try { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { return(Json(dataEditor.UpdateDocument(type, keyReference, data))); } } catch (Exception ex) { return(Json(JsonError.Throw("UpdateDocument", ex))); } } return(Json(JsonError.Throw("UpdateDocument", "Internal system error."))); }
public JsonResult SaveDocument(string keyType, string contentType, string keyData, string contentData) { if (!string.IsNullOrWhiteSpace(keyType) && !string.IsNullOrWhiteSpace(keyData) && !string.IsNullOrWhiteSpace(contentType) && !string.IsNullOrWhiteSpace(contentData)) { try { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { return(Json(dataEditor.SaveDocument(keyType, contentType, keyData, contentData))); } } catch (Exception ex) { return(Json(JsonError.Throw("SaveDocument", ex))); } } return(Json(JsonError.Throw("SaveDocument", "Internal system error."))); }
public JsonResult Restart() { try { var status = RFServiceMaintainer.Restart(Username); if (status == RFServiceMaintainer.SUCCESS) { return(Json(true)); } else { throw new RFSystemException(this, status); } } catch (Exception ex) { return(Json(JsonError.Throw("Restart", "Error restarting service: {0}", ex.Message))); } }
public JsonResult ReportProcessingError(string action, RFProcessingTracker status) { if (status != null) { if (!status.IsComplete) { return(Json(JsonError.Throw(action, "Operation timeout - please contact support."))); } else if (status.IsError()) { return(Json(JsonError.Throw(action, status.Error))); } else { return(Json(true)); } } return(Json(JsonError.Throw(action, "Unknown error - please contact support."))); }
public JsonResult GetKeys(string p) { try { var keys = new List <object>(); RFLoginCache.Login(LoginUsername, p); // find all vaults var vaults = Context.GetKeysByType <RFKeyVaultKey>(); if (vaults.Any()) { foreach (var vaultKey in vaults.Values) { using (var secure = new RFSecureActivity(Context, LoginUsername, new RFSimpleKeyDomain(vaultKey.Root), vaultKey.Enum)) { var vault = secure.OpenKeyVault(RFLoginCache.GetPasswordHash(LoginUsername)); foreach (var key in vault.Rows) { keys.Add(new { Vault = vaultKey.Enum.ToString(), KeyID = key.Key.KeyID, SecuredByKeyID = key.Key.SecuredByKeyID, SecuredByUsername = key.Key.SecuredByUsername, CipherStream = key.CipherStream, Accessible = vault.GetKey(key.Key.KeyID) != null && (string.IsNullOrWhiteSpace(key.Key.SecuredByUsername) || key.Key.SecuredByUsername.Equals(LoginUsername, StringComparison.InvariantCultureIgnoreCase)) }); } } } } return(Json(new { Keys = keys })); } catch (Exception ex) { return(Json(JsonError.Throw("GetKeys", ex))); } }
public JsonResult ResetMaster(string p) { try { var passwordHash = RFLoginCache.Login(LoginUsername, p); var vaults = Context.GetKeysByType <RFKeyVaultKey>(); if (vaults.Any()) { foreach (var vaultKey in vaults.Values) { using (var secure = new RFSecureActivity(Context, LoginUsername, new RFSimpleKeyDomain(vaultKey.Root), vaultKey.Enum)) { var vault = secure.OpenKeyVault(passwordHash); var newKey = RFSecure.GenerateNewKey(); vault.ChangeMasterKey(newKey); secure.SaveKeyVault(); } } } Context.UserLog.LogEntry(new RFUserLogEntry { Action = "ResetMaster", Area = "Encryption", Description = "Reset Master Key.", IsUserAction = true, IsWarning = false, Username = Username, Timestamp = DateTimeOffset.Now }); return(Json(true)); } catch (Exception ex) { RFLoginCache.Logout(LoginUsername); return(Json(JsonError.Throw("ResetMaster", ex))); } }
public JsonResult Update(RFDate valueDate, FormCollection collection) { try { using (var activity = _activityFunc(Context, Username)) { var row = ExtractRow(collection); if (row != null && row.IsValid()) { return(Json(activity.Replace(valueDate, row))); } else { return(Json(JsonError.Throw("Update", "Internal system error: invalid update."))); } } } catch (Exception ex) { return(Json(JsonError.Throw("Update", ex))); } }
public JsonResult UpdateConfig(FormCollection collection) { try { if (collection.GetValue("UserConfigKeyID") != null) { using (var configActivity = new RFConfigActivity(Context, Username)) { var userConfigKeyID = Int32.Parse(collection["UserConfigKeyID"]); string environment = collection["Environment"]; string value = collection["Value"]; string section = collection["Section"]; string item = collection["Item"]; string key = collection["Key"]; var path = string.Format("{0}/{1}/{2}", section, item, key); var update = configActivity.UpdateValue(userConfigKeyID, environment, value, Username, path); if (update && section == RFSchedulerTaskDefinition.CONFIG_SECTION) { // force reload scheduler config using (var rfService = new RFServiceClient()) { rfService.RFService.ServiceCommand(RFSchedulerService.SERVICE_NAME, RFSchedulerService.RELOAD_COMMAND, null); } } return(Json(update)); } } } catch (Exception ex) { return(Json(JsonError.Throw("UpdateConfig", ex))); } return(Json(JsonError.Throw("UpdateConfig", "Internal system error."))); }
public JsonResult GetTasks(string instanceName, DateTime?instanceDate) { try { using (var activity = new RFEngineActivity(Context, EngineConfig)) { var engineConfig = activity.GetEngineConfig(); var graphInstance = new RFGraphInstance { Name = string.IsNullOrWhiteSpace(instanceName) ? RFGraphInstance.DEFAULT_INSTANCE : instanceName, ValueDate = instanceDate.HasValue ? new RFDate(instanceDate.Value.Date) : RFDate.NullDate }; var engineStats = activity.GetEngineStats(graphInstance); var errors = _systemContext.DispatchStore.GetErrorQueue(0); var tasks = new List <object>(); foreach (var t in EngineConfig.Tasks) { var stat = engineStats?.GetStat(t.ProcessName); var dispatchKey = new RFParamProcessInstruction(t.ProcessName, null).DispatchKey(); var error = dispatchKey.NotBlank() ? errors.Where(e => e.DispatchKey == dispatchKey).FirstOrDefault() : null; var schedule = t.SchedulerConfig(Context); tasks.Add(new { t.TaskName, t.Description, t.GraphName, Schedule = String.Join(", ", new string[] { t.Trigger, schedule?.SchedulerScheduleString, schedule?.SchedulerRangeString }.Where(s => s.NotBlank())), IsEnabled = schedule?.IsEnabled ?? true, t.IsSystem, Status = error?.DispatchState.ToString() ?? "OK", Message = error?.Message, LastRun = stat?.LastRun ?? error?.LastStart, LastDuration = stat?.LastDuration, IsGraph = false, FullName = t.ProcessName }); } foreach (var g in EngineConfig.Graphs.Where(g => g.Value.GraphTasks.Any())) { var graphStats = activity.GetGraphStats(g.Value.GraphName, graphInstance); foreach (var t in g.Value.GraphTasks) { var processName = RFGraphDefinition.GetFullName(t.GraphName, t.ProcessName); var stat = graphStats?.GetStat(t.ProcessName); var dispatchKey = new RFGraphProcessInstruction(graphInstance, processName)?.DispatchKey(); var error = dispatchKey.NotBlank() ? errors.Where(e => e.DispatchKey == dispatchKey).FirstOrDefault() : null; var schedule = t.SchedulerConfig(Context); tasks.Add(new { t.TaskName, t.Description, t.GraphName, Schedule = String.Join(", ", new string[] { t.Trigger, schedule?.SchedulerScheduleString, schedule?.SchedulerRangeString }.Where(s => s.NotBlank())), //t.SchedulerRange, //t.SchedulerSchedule, //t.Trigger, IsEnabled = schedule?.IsEnabled ?? true, t.IsSystem, Status = error?.DispatchState.ToString() ?? ((stat?.CalculationOK ?? false) ? "OK" : String.Empty), Message = error?.Message ?? stat?.Message, LastRun = stat?.LastRun ?? error?.LastStart, IsGraph = true, FullName = processName }); } } return(Json(tasks)); } } catch (Exception ex) { return(Json(JsonError.Throw("GetTasks", ex))); } }
public JsonResult RefreshProcessingStatus(string processKey) { try { if (processKey == "test") { var r = new Random(); var f = r.Next(0, 10) + 4; var p = r.Next(0, 10) + 4; return(Json(new { IsComplete = true, CurrentProcess = "test", FinishedCycles = f, ProcessingCycles = p, RemainingCycles = 300 - f - p, Messages = new string[] { "Message 1", "Message 2" }, Keys = 5, Time = "01:01", IsValid = true, IsError = false })); } Log.Info(this, "RefreshProcessingStatus {0}", processKey); var model = GetModelFromCache(processKey); RFProcessingTrackerHandle handle = null; if (model != null) { handle = model.Tracker; } else { handle = new RFProcessingTrackerHandle { TrackerCode = processKey }; } RFProcessingTracker trackerObject = null; using (var rfService = new RFServiceClient()) { Log.Info(this, "Asking RF service for status on {0}", processKey); trackerObject = rfService.RFService.GetProcessStatus(handle); } if (trackerObject != null) { return(Json(new { IsComplete = trackerObject.IsComplete, CurrentProcess = trackerObject.CurrentProcess, FinishedCycles = trackerObject.FinishedCycles, ProcessingCycles = trackerObject.ProcessingCycles, RemainingCycles = trackerObject.RemainingCycles, Messages = ExtractMessages(trackerObject.Messages), Keys = trackerObject.KeyCount, Time = trackerObject.GetDuration().ToString(@"m'm 's's'"), IsValid = true, IsError = trackerObject.IsError() })); } return(Json(JsonError.Throw("ProcessingStatus", "Unable to retrieve information about request {0}", processKey))); } catch (Exception ex) { if (ex.Message.Contains("no endpoint listening")) { // fatal error return(Json(JsonError.Throw("ProcessingStatus", "System is offline - {0}", processKey))); } else { // recoverable error return(Json(new { IsValid = false, Error = ex.Message })); } } }