/FalconOrchestrator.Web/Models/ViewModels/IndicatorViewModel.cs

https://github.com/CrowdStrike/falcon-orchestrator · C# · 98 lines · 70 code · 16 blank · 12 comment · 14 complexity · 0c4be8890e486d4d91596b678f1cbe95 MD5 · raw file

  1. //<Falcon Orchestrator provides automated workflow and response capabilities>
  2. // Copyright(C) 2016 CrowdStrike
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as
  5. // published by the Free Software Foundation, either version 3 of the
  6. // License, or(at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
  10. // GNU Affero General Public License for more details.
  11. // You should have received a copy of the GNU Affero General Public License
  12. // along with this program.If not, see<http://www.gnu.org/licenses/>.
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Web.Mvc;
  16. using System.Text.RegularExpressions;
  17. using System.ComponentModel.DataAnnotations;
  18. namespace FalconOrchestratorWeb.Models.ViewModels
  19. {
  20. public class IndicatorViewModel : IValidatableObject
  21. {
  22. [Required]
  23. public String Type { get; set; }
  24. [Required]
  25. public String Value { get; set; }
  26. public String Description { get; set; }
  27. public String ShareLevel { get; set; }
  28. public String Source { get; set; }
  29. [Required]
  30. public String Policy { get; set; }
  31. public DateTime? CreatedTimestamp { get; set; }
  32. public DateTime? ExpirationTimestamp { get; set; }
  33. public int ExpirationDays { get; set; }
  34. public List<SelectListItem> TypeList
  35. {
  36. get
  37. {
  38. List<SelectListItem> items = new List<SelectListItem>();
  39. items.Add(new SelectListItem() { Text = "DOMAIN", Value = "DOMAIN" });
  40. items.Add(new SelectListItem() { Text = "SHA256", Value = "SHA256" });
  41. items.Add(new SelectListItem() { Text = "SHA1", Value = "SHA1" });
  42. items.Add(new SelectListItem() { Text = "MD5", Value = "MD5" });
  43. items.Add(new SelectListItem() { Text = "IPV4", Value = "IPV4" });
  44. items.Add(new SelectListItem() { Text = "IPV6", Value = "IPV6" });
  45. return items;
  46. }
  47. }
  48. public List<SelectListItem> PolicyList
  49. {
  50. get
  51. {
  52. List<SelectListItem> items = new List<SelectListItem>();
  53. items.Add(new SelectListItem() { Text = "DETECT", Value = "DETECT" });
  54. items.Add(new SelectListItem() { Text = "NONE", Value = "NONE" });
  55. return items;
  56. }
  57. }
  58. public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
  59. {
  60. if (this.Type.ToUpper().Equals("DOMAIN") && (this.Value.Length < 1 || this.Value.Length > 200))
  61. {
  62. yield return new ValidationResult("Domain must be at least 1 character and no more than 200", new[] { "Value" });
  63. }
  64. if (this.Type.ToUpper().Equals("SHA256") && this.Value.Length != 64)
  65. {
  66. yield return new ValidationResult("Not a valid SHA256, must be 64 characters", new[] { "Value" });
  67. }
  68. if (this.Type.ToUpper().Equals("SHA1") && this.Value.Length != 40)
  69. {
  70. yield return new ValidationResult("Not a valid SHA1, must be 40 characters", new[] { "Value" });
  71. }
  72. if (this.Type.ToUpper().Equals("MD5") && this.Value.Length != 32)
  73. {
  74. yield return new ValidationResult("Not a valid MD5, must be 32 characters", new[] { "Value" });
  75. }
  76. if (this.Type.ToUpper().Equals("IPV4") && !Regex.IsMatch(this.Value,@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"))
  77. {
  78. yield return new ValidationResult("Not a valid IPv4 address", new[] { "Value" });
  79. }
  80. }
  81. }
  82. }