A shiny app to explore nginx access logs and geolocate the connections
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
857B

  1. library(tidyverse)
  2. library(RSQLite)
  3. library(ipapi)
  4. # sqlite3 access.db
  5. # create table access(ip, null1, user, timestamp, zone, req, status, size, referer, agent, null2);
  6. # .separator " "
  7. # .import access.log access
  8. dbConnect(SQLite(), "access.db") %>%
  9. dbGetQuery("delete from access where ip = '192.168.0.254' or user = 'maxx' or agent like '%bot%' or ip = '164.2.255.244';")
  10. dbConnect(SQLite(), "access.db") %>%
  11. dbGetQuery("vacuum;")
  12. known_ips <- character(0)
  13. src_sqlite("access.db") %>%
  14. tbl("geoip") %>%
  15. select(query) %>%
  16. collect %>%
  17. pull(query) -> known_ips
  18. src_sqlite("access.db") %>%
  19. tbl("access") %>%
  20. select(ip) %>%
  21. collect %>%
  22. pull(ip) %>%
  23. unique %>%
  24. setdiff(known_ips) -> ips
  25. if (length(ips) > 0)
  26. {
  27. ips %>%
  28. geolocate -> geoip
  29. dbConnect(SQLite(), "access.db") %>%
  30. dbWriteTable("geoip", geoip, append = T)
  31. }