Tools to work with the Google DNS over HTTPS API in R https://cinc.rud.is/web/packages/gdns/
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #' Split out all SPF records in a domain's TXT record
  2. #'
  3. #' Given a vector of TXT records, this function will return a list of vectors
  4. #' of all the SPF records for each. If the given TXT record is not an SPF
  5. #' record, \code{NA} is returned (which makes it easy to skip with \code{purrr}
  6. #' functions).
  7. #'
  8. #' @param spf_rec a character vector of DNS TXT records
  9. #' @export
  10. split_spf <- function(spf_rec) {
  11. map(spf_rec, .split_spf)
  12. }
  13. .split_spf <- function(spf_rec) {
  14. if (has_spf(spf_rec)) {
  15. spf_rec <- stringi::stri_trim(stringi::stri_replace_all_regex(spf_rec, '"', ""))
  16. recs <- stri_trim(unlist(stringi::stri_split_regex(spf_rec, "\ +")))
  17. grep("v=spf1", recs, invert=TRUE, value=TRUE)
  18. } else {
  19. NA_character_
  20. }
  21. }
  22. #' Test for whether a DNS TXT record is an SPF record
  23. #'
  24. #' @param spf_rec a character vector of DNS TXT records
  25. #' @export
  26. has_spf <- function(spf_rec) {
  27. grepl("v=spf1", spf_rec)
  28. }
  29. #' SPF "all" type test
  30. #'
  31. #' @param spf_rec a character vector of DNS TXT records
  32. #' @export
  33. is_soft_fail <- function(spf_rec) {
  34. ret <- vector("logical", length(spf_rec))
  35. spf_rec <- stringi::stri_trim(stringi::stri_replace_all_regex(spf_rec, '"', ""))
  36. SPF <- which(has_spf(spf_rec))
  37. ret[SPF] <- grepl("~all$", stringi::stri_trim(spf_rec[SPF]))
  38. ret[!SPF] <- NA
  39. ret
  40. }
  41. #' @rdname is_soft_fail
  42. #' @export
  43. is_hard_fail <- function(spf_rec) {
  44. ret <- vector("logical", length(spf_rec))
  45. spf_rec <- stringi::stri_trim(stringi::stri_replace_all_regex(spf_rec, '"', ""))
  46. SPF <- which(has_spf(spf_rec))
  47. ret[SPF] <- grepl("\\-all$", stringi::stri_trim(spf_rec[SPF]))
  48. ret[!SPF] <- NA
  49. ret
  50. }
  51. #' @rdname is_soft_fail
  52. #' @export
  53. passes_all <- function(spf_rec) {
  54. ret <- vector("logical", length(spf_rec))
  55. spf_rec <- stringi::stri_trim(stringi::stri_replace_all_regex(spf_rec, '"', ""))
  56. SPF <- which(has_spf(spf_rec))
  57. ret[SPF] <- grepl("[\\+ ]all$", stringi::stri_trim(spf_rec[SPF]))
  58. ret[!SPF] <- NA
  59. ret
  60. }
  61. #' SPF field extraction functions
  62. #'
  63. #' Various helper functions to extract SPF record components.
  64. #'
  65. #' @param spf_rec a character vector of DNS TXT records
  66. #' @export
  67. spf_ipv4s <- function(spf_rec) {
  68. map(split_spf(spf_rec), function(x) {
  69. stringi::stri_replace_all_regex(grep("ip4", x, value=TRUE), "^ip4:", "")
  70. })
  71. }
  72. #' @rdname spf_ipv4s
  73. #' @export
  74. spf_ipv6s <- function(spf_rec) {
  75. map(split_spf(spf_rec), function(x) {
  76. stringi::stri_replace_all_regex(grep("ip6", x, value=TRUE), "^ip6:", "")
  77. })
  78. }
  79. #' @rdname spf_ipv4s
  80. #' @export
  81. spf_includes <- function(spf_rec) {
  82. map(split_spf(spf_rec), function(x) {
  83. stringi::stri_replace_all_regex(grep("include", x, value=TRUE), "^include:", "")
  84. })
  85. }
  86. #' @rdname spf_ipv4s
  87. #' @export
  88. spf_ptrs <- function(spf_rec) {
  89. map(split_spf(spf_rec), function(x) {
  90. stringi::stri_replace_all_regex(grep("ptr", x, value=TRUE), "^ptr[:]", "")
  91. })
  92. }
  93. #' @rdname spf_ipv4s
  94. #' @export
  95. spf_exists <- function(spf_rec) {
  96. map(split_spf(spf_rec), function(x) {
  97. stringi::stri_replace_all_regex(grep("exists", x, value=TRUE), "^exists:", "")
  98. })
  99. }