fedi-who 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env ruby
  2. # Copyright © 2021 sev, p
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or (at
  7. # your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. %w(
  17. json
  18. openssl
  19. net/http
  20. uri
  21. ).each &method(:require)
  22. ARGV.each { |host|
  23. data = JSON.parse(Net::HTTP.get(URI("https://#{host}/api/v1/instance")))
  24. admin = begin
  25. "#{data['contact_account']['url']}"
  26. rescue NoMethodError
  27. end
  28. if !admin
  29. begin
  30. suppl = JSON.parse(Net::HTTP.get(URI("https://#{host}/nodeinfo/2.0.json")))
  31. admin = suppl.dig('metadata', 'staffAccounts').inspect
  32. rescue
  33. end
  34. end
  35. puts "- #{data['uri']} — #{(data['title'] || data['description']).inspect}",
  36. "\temail: #{data['email']}",
  37. "\tadmin: #{admin}",
  38. "\tstats: #{data['stats'].to_json}",
  39. ''
  40. }