boB Rudis 1 год назад
Родитель
Сommit
cf3da3e06b
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 1D7529BE14E2BBA9
10 измененных файлов: 278 добавлений и 9 удалений
  1. +4
    -3
      DESCRIPTION
  2. +2
    -0
      NAMESPACE
  3. +69
    -0
      R/doh-post.R
  4. +52
    -0
      R/globals.R
  5. +5
    -4
      R/playdoh-package.R
  6. +29
    -0
      R/zzz.R
  7. +16
    -1
      README.Rmd
  8. +77
    -0
      README.md
  9. +22
    -0
      man/doh_post.Rd
  10. +2
    -1
      man/playdoh.Rd

+ 4
- 3
DESCRIPTION Просмотреть файл

@@ -1,6 +1,6 @@
Package: playdoh
Type: Package
Title: playdoh title goes here otherwise CRAN checks fail
Title: Make 'DNS over HTTPS' Queries
Version: 0.1.0
Date: 2019-05-25
Authors@R: c(
@@ -8,7 +8,7 @@ Authors@R: c(
comment = c(ORCID = "0000-0001-5670-2640"))
)
Maintainer: Bob Rudis <bob@rud.is>
Description: A good description goes here otherwise CRAN checks fail.
Description: Make 'DNS over HTTPS' queries.
URL: https://gitlab.com/hrbrmstr/playdoh
BugReports: https://gitlab.com/hrbrmstr/playdoh/issues
Encoding: UTF-8
@@ -20,6 +20,7 @@ Depends:
R (>= 3.2.0)
Imports:
httr,
jsonlite
jsonlite,
reticulate
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1

+ 2
- 0
NAMESPACE Просмотреть файл

@@ -1,4 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(doh_post)
import(httr)
import(reticulate)
importFrom(jsonlite,fromJSON)

+ 69
- 0
R/doh-post.R Просмотреть файл

@@ -0,0 +1,69 @@
#' Make a POST DoH Request (wireformat)
#'
#' Issue the query of type `type` for `name` to the DoH endpoint specified at `server_path`.
#'
#' @param name name to query for
#' @param type DNS query type (defaults to "`A`")
#' @param server_path full URL path to the DoH server quer endpoint (defaults to Quad9).
#' @return `NULL` (if the query failed) or a `data.frame` (tibble)
#' @export
doh_post <- function(name, type = "A", server_path = "https://dns.quad9.net/dns-query") {

# for now, use python's {dnslib} as a crutch to
# encode/decode wireformat DNS questions and answers

.dns$DNSRecord$question(
qname = tolower(name[1]),
qtype = toupper(type[1]),
qclass = "IN"
) -> q

qpak <- q$pack()

# now, send it off to the server

httr::POST(
url = server_path[1],
httr::add_headers(
`Content-Type` = "application/dns-message",
`Accept` = "application/dns-message"
),
encode = "raw",
body = qpak
) -> res

httr::warn_for_status(res)

# if the response is OK, make it a data frame

if (httr::status_code(res) == 200) {

r <- .dns$DNSRecord$parse(httr::content(res))

q <- r$get_q()

do.call(
rbind.data.frame,
lapply(r$rr, function(.x) {
data.frame(
query = py_str(q$qname),
qtype = q$qtype,
rname = py_str(.x$rname),
rtype = .x$rtype,
rdata = py_str(.x$rdata),
ttl = .x$ttl,
stringsAsFactors = FALSE
)
})

) -> xdf

class(xdf) <- c("tbl_df", "tbl", "data.frame")

xdf

} else {
NULL
}

}

+ 52
- 0
R/globals.R Просмотреть файл

@@ -0,0 +1,52 @@
list(
google = list(
url = "https://dns.google.com/experimental",
extra_params = list()
),
cloudflare = list(
url = "https://cloudflare-dns.com/dns-query",
extra_params = list(
cd = "false",
do = "true",
ct = "application/dns-json"
)
),
quad9 = list(
url = "https://dns.quad9.net/dns-query",
extra_params = list()
),
securedns_eu = list(
url = "https://doh.securedns.eu/dns-query",
extra_params = list(
edns_client_subnet = NULL
)
),
dnswarden_adblock = list(
url = "https://doh.dnswarden.com/adblock",
extra_params = list()
),
dnswarden_uncensored = list(
url = "https://doh.dnswarden.com/uncensored",
extra_params = list()
),
cleanbrowsing_security = list(
url = "https://doh.cleanbrowsing.org/doh/security-filter/",
extra_params = list(cd = "false")
),
cleanbrowsing_family = list(
url = "https://doh.cleanbrowsing.org/doh/family-filter/",
extra_params = list()
),
cleanbrowsing_adult = list(
url = "https://doh.cleanbrowsing.org/doh/adult-filter/",
extra_params = list()
),
power_dns = list(
url = "https://doh.powerdns.org",
extra_params = list()
),
appliedprivacy = list(
url = "https://doh.appliedprivacy.net/query",
extra_params = list()
)
) -> doh_servers

+ 5
- 4
R/playdoh-package.R Просмотреть файл

@@ -1,12 +1,13 @@
#' ...
#'
#' Make 'DNS over HTTPS' Queries
#'
#' - URL: <https://gitlab.com/hrbrmstr/playdoh>
#' - BugReports: <https://gitlab.com/hrbrmstr/playdoh/issues>
#'
#'
#' @md
#' @name playdoh
#' @docType package
#' @keywords internal
#' @author Bob Rudis (bob@@rud.is)
#' @import httr
#' @import httr reticulate
#' @importFrom jsonlite fromJSON
NULL

+ 29
- 0
R/zzz.R Просмотреть файл

@@ -0,0 +1,29 @@
py_c <- reticulate::py_config()

.dns <- NULL

.onLoad <- function(libname, pkgname) {

if (utils::compareVersion(py_c$version, "3.5") < 0) {
stop(
paste0(
c(
"Python 3.5+ is required. If this is installed please set RETICULATE_PYTHON ",
"to the path to the Python 3 binary on your system and try re-installing/",
"re-loading the package."
),
collapse = ""
)
)
return()
}

if (!reticulate::py_module_available("dnslib")) {
packageStartupMessage(
"The 'dnslib' Python module must be installed."
)
} else {
.dns <<- reticulate::import("dnslib", delay_load = TRUE)
}

}

+ 16
- 1
README.Rmd Просмотреть файл

@@ -14,18 +14,24 @@ options(width=120)

# playdoh

Make 'DNS over HTTPS' Queries

## Description

Make 'DNS over HTTPS' Queries

## What's Inside The Tin

The following functions are implemented:

- `doh_post`: Make a POST DoH Request (wireformat)

## Installation

```{r install-ex, eval=FALSE}
devtools::install_git("https://sr.ht.com/~hrbrmstr/playdoh.git")
# or
devtools::install_git("https://gitlab.com/hrbrmstr/playdoh.git")
devtools::install_gitlab("hrbrmstr/playdoh.git")
# or (if you must)
devtools::install_github("hrbrmstr/playdoh")
```
@@ -34,12 +40,21 @@ devtools::install_github("hrbrmstr/playdoh")

```{r lib-ex}
library(playdoh)
library(tidyverse) # for printing

# current version
packageVersion("playdoh")

```

### Basic functionality

```{r}
doh_post("rud.is")

doh_post("lenovo.com", "txt")
```

## playdoh Metrics

```{r cloc, echo=FALSE}


+ 77
- 0
README.md Просмотреть файл

@@ -1,2 +1,79 @@

[![Travis-CI Build
Status](https://travis-ci.org/hrbrmstr/playdoh.svg?branch=master)](https://travis-ci.org/hrbrmstr/playdoh)
[![Coverage
Status](https://codecov.io/gh/hrbrmstr/playdoh/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/playdoh)
[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/playdoh)](https://cran.r-project.org/package=playdoh)

# playdoh

Make ‘DNS over HTTPS’ Queries

## Description

Make ‘DNS over HTTPS’ Queries

## What’s Inside The Tin

The following functions are implemented:

- `doh_post`: Make a POST DoH Request (wireformat)

## Installation

``` r
devtools::install_git("https://sr.ht.com/~hrbrmstr/playdoh.git")
# or
devtools::install_gitlab("hrbrmstr/playdoh.git")
# or (if you must)
devtools::install_github("hrbrmstr/playdoh")
```

## Usage

``` r
library(playdoh)
library(tidyverse) # for printing

# current version
packageVersion("playdoh")
## [1] '0.1.0'
```

### Basic functionality

``` r
doh_post("rud.is")
## # A tibble: 1 x 6
## query qtype rname rtype rdata ttl
## <chr> <int> <chr> <int> <chr> <int>
## 1 rud.is. 1 rud.is. 1 172.93.49.183 3572

doh_post("lenovo.com", "txt")
## # A tibble: 10 x 6
## query qtype rname rtype rdata ttl
## <chr> <int> <chr> <int> <chr> <int>
## 1 lenovo.co… 16 lenovo.co… 16 "\"google-site-verification=nGgukcp60rC-gFxMOJw1NHH0B4VnSchRrlfWV-He_tE\"" 7173
## 2 lenovo.co… 16 lenovo.co… 16 "\"a82c74b37aa84e7c8580f0e32f4d795d\"" 7173
## 3 lenovo.co… 16 lenovo.co… 16 "\"google-site-verification=sHIlSlj0U6UnCDkfHp1AolWgVEvDjWvc0TR4KaysD2c\"" 7173
## 4 lenovo.co… 16 lenovo.co… 16 "\"v=spf1 include:spf.messagelabs.com include:_netblocks.eloqua.com ~all\"" 7173
## 5 lenovo.co… 16 lenovo.co… 16 "\"qh7hdmqm4lzs85p704d6wsybgrpsly0j\"" 7173
## 6 lenovo.co… 16 lenovo.co… 16 "\"ece42d7743c84d6889abda7011fe6f53\"" 7173
## 7 lenovo.co… 16 lenovo.co… 16 "\"iHzQJvsKnyGP2Nm2qBgL3fyBJ0CC9z4GkY/flfk4EzLP8lPxWHDDPKqZWm1TkeF5kEIL+NotY… 7173
## 8 lenovo.co… 16 lenovo.co… 16 "\"Visit www.lenovo.com/think for information about Lenovo products and serv… 7173
## 9 lenovo.co… 16 lenovo.co… 16 "\"google-site-verification=VxW_e6r_Ka7A518qfX2MmIMHGnkpGbnACsjSxKFCBw0\"" 7173
## 10 lenovo.co… 16 lenovo.co… 16 "\"facebook-domain-verification=1r2am7c2bhzrxpqyt0mda0djoquqsi\"" 7173
```

## playdoh Metrics

| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 6 | 0.86 | 122 | 0.92 | 23 | 0.52 | 26 | 0.43 |
| Rmd | 1 | 0.14 | 11 | 0.08 | 21 | 0.48 | 35 | 0.57 |

## Code of Conduct

Please note that this project is released with a [Contributor Code of
Conduct](CONDUCT.md). By participating in this project you agree to
abide by its terms.

+ 22
- 0
man/doh_post.Rd Просмотреть файл

@@ -0,0 +1,22 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/doh-post.R
\name{doh_post}
\alias{doh_post}
\title{Make a POST DoH Request (wireformat)}
\usage{
doh_post(name, type = "A",
server_path = "https://dns.quad9.net/dns-query")
}
\arguments{
\item{name}{name to query for}

\item{type}{DNS query type (defaults to "\code{A}")}

\item{server_path}{full URL path to the DoH server quer endpoint (defaults to Quad9).}
}
\value{
\code{NULL} (if the query failed) or a \code{data.frame} (tibble)
}
\description{
Issue the query of type \code{type} for \code{name} to the DoH endpoint specified at \code{server_path}.
}

+ 2
- 1
man/playdoh.Rd Просмотреть файл

@@ -4,7 +4,7 @@
\name{playdoh}
\alias{playdoh}
\alias{playdoh-package}
\title{...}
\title{Make 'DNS over HTTPS' Queries}
\description{
\itemize{
\item URL: \url{https://gitlab.com/hrbrmstr/playdoh}
@@ -14,3 +14,4 @@
\author{
Bob Rudis (bob@rud.is)
}
\keyword{internal}

Загрузка…
Отмена
Сохранить