public async Task <IHttpActionResult> PutAlertsModel(long id, AlertsModel alertsModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != alertsModel.Id) { return(BadRequest()); } db.Entry(alertsModel).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AlertsModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult Index(AlertsModel alertsModel) { if (HttpContext.Session.Get("CustomerID") == null) { return(RedirectToAction("Index", "Login")); } return(View(generateAlertsModel(alertsModel.curAccount))); }
public static void IWantToUpdateAlert(AlertsModel Alert) { LastAlert = new AlertsModel(); LastAlert.Activity = Alert.Activity; LastAlert.Time = Alert.Time; LastAlert.Date = Alert.Date; LastAlert.Information = Alert.Information; LastAlert.No = Alert.No; UpdateAlert?.Invoke(typeof(GlobalResources), EventArgs.Empty); }
public async Task <IHttpActionResult> GetAlertsModel(long id) { AlertsModel alertsModel = await db.Alerts.FindAsync(id); if (alertsModel == null) { return(NotFound()); } return(Ok(alertsModel)); }
public async Task <IHttpActionResult> PostAlertsModel(AlertsModel alertsModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Alerts.Add(alertsModel); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = alertsModel.Id }, alertsModel)); }
public async Task <IHttpActionResult> DeleteAlertsModel(long id) { AlertsModel alertsModel = await db.Alerts.FindAsync(id); if (alertsModel == null) { return(NotFound()); } db.Alerts.Remove(alertsModel); await db.SaveChangesAsync(); return(Ok(alertsModel)); }
private AlertsModel generateAlertsModel(int account = 0) { AlertsModel alertsModel = new AlertsModel(); Int32 customerID = (Int32)HttpContext.Session.GetInt32("CustomerID"); List <Int32> accountIDs = DatabaseHandler.getAccounts(customerID); alertsModel.accounts = accountIDs; if (accountIDs.Count > 0) { if (account > 0) { alertsModel.curAccount = account; alertsModel.alerts = DatabaseHandler.getAlerts(customerID, account); } else { alertsModel.curAccount = accountIDs[0]; alertsModel.alerts = DatabaseHandler.getAlerts(customerID, accountIDs[0]); } } return(alertsModel); }
public static void Analyse(string FS_Activity, string Author) { foreach (FSC_Restrictions FS_Restriction in Restrictions.AllFSC_Restritions) { //Variable Declaration string _File = FS_Restriction.File; string _Directory = FS_Restriction.Directory; //To remove extra \ in C - paths char[] Temp = FS_Activity.ToCharArray(); if (Temp[3] == '\\') { FS_Activity = FS_Activity.Remove(3, 1); } //Checking Whether the Change is in the file or directory //For a File #region 1.File if (Path.HasExtension(FS_Activity)) { bool AddAlert = true; //Check whether the change is done by owner or not if (!string.Equals(Author, GlobalResources.CurrentUser.UserName)) { //Direct Changes to the File being locked if (!string.Equals(_File, "null") & string.Equals(_File, FS_Activity)) { foreach (AlertsModel AM in GlobalAlerts.AllAlerts) { if (string.Equals(AM.Activity, FS_Activity)) { AddAlert = false; AlertsModel Alert = new AlertsModel { No = GlobalAlerts.No, Time = DateTime.Now.ToShortTimeString(), Date = DateTime.Now.ToShortDateString(), Information = "File System Restriction Violation", Activity = FS_Restriction.File, Type = "File" }; GlobalResources.IWantToUpdateAlert(Alert); } } if (AddAlert) { GlobalAlerts.No++; AlertsModel Alert = new AlertsModel { No = GlobalAlerts.No, Time = DateTime.Now.ToShortTimeString(), Date = DateTime.Now.ToShortDateString(), Information = "File System Restriction Violation", Activity = FS_Restriction.File, Type = "File" }; Application.Current.Dispatcher.Invoke(delegate { GlobalAlerts.AllAlerts.Add(Alert); }); MailingSystem.Mdata.Alert = Alert; MailingSystem.Mdata.CompromisedUser = Author; GlobalResources.IWantToSendMail(); GlobalResources.IWantToUpdateAlert(Alert); } GlobalResources.IGeneratedAlert(); if (GlobalResources.IsNotificationWindowShown == false) { Notify(); } } } } #endregion //For a Directory #region 2. Directory else { if (!string.Equals(Author, GlobalResources.CurrentUser.UserName)) { //Changes to the contents inside the root folder being locked if (!string.Equals(_Directory, "null") & string.Equals(Directory.GetParent(FS_Activity).ToString(), _Directory)) { bool AddAlert = true; FS_Activity = Directory.GetParent(FS_Activity).ToString(); AlertsModel Alert = new AlertsModel { No = GlobalAlerts.No, Time = DateTime.Now.ToShortTimeString(), Date = DateTime.Now.ToShortDateString(), Information = "File System Restriction Violation", Activity = _Directory, Type = "Directory" }; if (string.Equals(_Directory, FS_Activity)) { foreach (AlertsModel AM in GlobalAlerts.AllAlerts) { if (string.Equals(AM.Activity, FS_Activity)) { AddAlert = false; GlobalResources.IWantToUpdateAlert(Alert); } } if (AddAlert) { GlobalAlerts.No++; Application.Current.Dispatcher.Invoke(delegate { GlobalAlerts.AllAlerts.Add(Alert); }); GlobalResources.IWantToUpdateAlert(Alert); MailingSystem.Mdata.Alert = Alert; MailingSystem.Mdata.CompromisedUser = Author; GlobalResources.IWantToSendMail(); } GlobalResources.IGeneratedAlert(); if (GlobalResources.IsNotificationWindowShown == false) { Notify(); } } } //Direct changes to the root folder being locked else { if (string.Equals(_Directory, FS_Activity)) { bool AddAlert = true; AlertsModel Alert = new AlertsModel { No = GlobalAlerts.No, Time = DateTime.Now.ToShortTimeString(), Date = DateTime.Now.ToShortDateString(), Information = "File System Restriction Violation", Activity = _Directory, Type = "Directory" }; foreach (AlertsModel AM in GlobalAlerts.AllAlerts) { if (string.Equals(AM.Activity, FS_Activity)) { AddAlert = false; GlobalResources.IWantToUpdateAlert(Alert); } } if (AddAlert) { GlobalAlerts.No++; App.Current.Dispatcher.Invoke((Action) delegate { GlobalAlerts.AllAlerts.Add(Alert); }); GlobalResources.IWantToUpdateAlert(Alert); MailingSystem.Mdata.Alert = Alert; MailingSystem.Mdata.CompromisedUser = Author; GlobalResources.IWantToSendMail(); } GlobalResources.IGeneratedAlert(); if (GlobalResources.IsNotificationWindowShown == false) { Notify(); } } } } } #endregion } }
public static void ProcessAnalyse(ProcessReportsModel Process) { bool AuthorizeProcessAnalyse = true; bool IsProcessUnwanted = true; bool IsProcessBlacklisted = false; bool AddAlert_W = true; bool AddAlert_B = true; foreach (ProcessReportsModel EProcess in GlobalResources.ProcessList) { if (string.Equals(EProcess.Name, Process.Name)) { AuthorizeProcessAnalyse = false; } } if (AuthorizeProcessAnalyse) { if (GlobalResources.SelectedProcessRestrictionType == 0) { //Checks whether a process is there in the whitelist, if not triggers an alert foreach (ProcessReportsModel _Process in Restrictions.AllProcess_Restrictions) { if (string.Equals(_Process.Name, Process.Name) & string.Equals(_Process.ExecutionPath, Process.ExecutionPath)) { IsProcessUnwanted = false; } } if (IsProcessUnwanted) { foreach (AlertsModel AM in GlobalAlerts.AllAlerts) { if (string.Equals(AM.Activity, Process.Name)) { AddAlert_W = false; AlertsModel Alert = new AlertsModel { No = GlobalAlerts.No, Time = DateTime.Now.ToShortTimeString(), Date = DateTime.Now.ToShortDateString(), Type = "UnWanted Process", Activity = Process.Name, Information = "Process Restriction Violation " }; GlobalResources.IWantToUpdateAlert(Alert); } } if (AddAlert_W) { GlobalAlerts.No++; AlertsModel Alert = new AlertsModel { No = GlobalAlerts.No, Time = DateTime.Now.ToShortTimeString(), Date = DateTime.Now.ToShortDateString(), Type = "UnWanted Process", Activity = Process.Name, Information = "Process Restriction Violation " }; Application.Current.Dispatcher.Invoke(delegate { GlobalAlerts.AllAlerts.Add(Alert); }); GlobalResources.IWantToUpdateAlert(Alert); } GlobalResources.IGeneratedAlert(); if (!GlobalResources.IsNotificationWindowShown) { Notify(); } } } else { //Checks whether a process is there in the Blacklist, if not triggers an alert foreach (ProcessReportsModel _Process in Restrictions.AllProcess_Restrictions) { if (string.Equals(_Process.Name, Process.Name) & string.Equals(_Process.ExecutionPath, Process.ExecutionPath)) { IsProcessBlacklisted = true; } if (IsProcessBlacklisted) { foreach (AlertsModel AM in GlobalAlerts.AllAlerts) { if (string.Equals(AM.Activity, Process.Name)) { AddAlert_B = false; AlertsModel Alert = new AlertsModel { No = GlobalAlerts.No, Time = DateTime.Now.ToShortTimeString(), Date = DateTime.Now.ToShortDateString(), Type = "Blacklisted Process", Activity = Process.Name, Information = "Process Restriction Violation" }; GlobalResources.IWantToUpdateAlert(Alert); } } if (AddAlert_B) { GlobalAlerts.No++; AlertsModel Alert = new AlertsModel { No = GlobalAlerts.No, Time = DateTime.Now.ToShortTimeString(), Date = DateTime.Now.ToShortDateString(), Type = "Blacklisted Process", Activity = Process.Name, Information = "Process Restriction Violation" }; App.Current.Dispatcher.Invoke((Action) delegate { GlobalAlerts.AllAlerts.Add(Alert); }); GlobalResources.IGeneratedAlert(); GlobalResources.IWantToUpdateAlert(Alert); } if (!GlobalResources.IsNotificationWindowShown) { Notify(); } } } } } }
private async void AppInisialSetupAsync() { ApplicationDbContext context = new ApplicationDbContext(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); //setting up the app if (context.Settings.Count() == 0) { var settings = new SettingsViewModels(); settings.MaxPeopleAllowed = 3; string json; using (StreamReader r = new StreamReader(@"D:\Projects\FinalProject\CSA_Project\CSA_Project\CSA_Config\config.json")) { json = r.ReadToEnd(); } JObject jObject = JObject.Parse(json); JToken euclid = jObject["euclid"]; JToken server = jObject["server"]; JToken net = jObject["neural_net"]; JToken db = jObject["db_name"]; JToken connection = jObject["connection_string"]; settings.DB_Name = (string)db; settings.ConnectionString = (string)connection; settings.EuclidIP = (string)euclid["ip"]; settings.EuclidMAC = (string)euclid["mac"]; settings.EuclidPort = (string)euclid["stream_port"]; settings.CameraTopic = (string)euclid["cam_topic"]; settings.ServerIP = (string)server["ip"]; settings.ServerMAC = (string)server["mac"]; settings.ServerPort = (string)euclid["stream_port"]; context.Settings.Add(settings); await context.SaveChangesAsync(); } // In Startup iam creating first Admin Role and creating a default Admin User if (!roleManager.RoleExists("Master")) { // first we create Admin rool var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Master"; roleManager.Create(role); } if (!roleManager.RoleExists("Admin")) { // first we create Admin rool var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Admin"; roleManager.Create(role); } // creating Creating Employee role if (!roleManager.RoleExists("Viewer")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Viewer"; roleManager.Create(role); } if (context.SelectorModels.Count() == 0) { var selector = new SelectorModel(); selector.SelectedValue = "People"; context.SelectorModels.Add(selector); await context.SaveChangesAsync(); } //create a default alert if (context.Alerts.Count() == 0) { var alert = new AlertsModel(); alert.AlertType = "OK"; alert.Code = 200; alert.Message = "OK"; context.Alerts.Add(alert); await context.SaveChangesAsync(); } }