diff --git a/app/controllers/ip_addresses_controller.rb b/app/controllers/ip_addresses_controller.rb index 357b32b58..98c070278 100644 --- a/app/controllers/ip_addresses_controller.rb +++ b/app/controllers/ip_addresses_controller.rb @@ -14,4 +14,10 @@ class IpAddressesController < ApplicationController respond_with(@ip_addresses) end + + def show + @ip_address = IpAddress.new(ip_addr: params[:id]) + @ip_info = @ip_address.lookup.info + respond_with(@ip_info) + end end diff --git a/app/helpers/ip_addresses_helper.rb b/app/helpers/ip_addresses_helper.rb new file mode 100644 index 000000000..61a833f22 --- /dev/null +++ b/app/helpers/ip_addresses_helper.rb @@ -0,0 +1,11 @@ +module IpAddressesHelper + def embedded_google_map(location, width, height, api_key: Danbooru.config.google_maps_api_key) + tag.iframe( + width: width, + height: height, + frameborder: 0, + allowfullscreen: true, + src: "https://www.google.com/maps/embed/v1/search?q=#{location}&key=#{api_key}" + ) + end +end diff --git a/app/javascript/src/styles/specific/ip_addresses.scss b/app/javascript/src/styles/specific/ip_addresses.scss new file mode 100644 index 000000000..5bb7c0ca0 --- /dev/null +++ b/app/javascript/src/styles/specific/ip_addresses.scss @@ -0,0 +1,7 @@ +#c-ip-addresses { + .ip-address-details, .ip-address-map { + display: inline-block; + margin-right: 2em; + vertical-align: top; + } +} diff --git a/app/views/ip_addresses/_index.html.erb b/app/views/ip_addresses/_index.html.erb index 2466a3885..cb7179777 100644 --- a/app/views/ip_addresses/_index.html.erb +++ b/app/views/ip_addresses/_index.html.erb @@ -1,14 +1,14 @@ <%= table_for @ip_addresses, {class: "striped autofit"} do |t| %> + <% t.column "IP Address" do |ip| %> + <%= link_to ip.ip_addr, ip_addresses_path(search: { ip_addr: ip.ip_addr }) %> + <%= link_to "»", ip_addresses_path(search: { ip_addr: ip.ip_addr, group_by: "user" }) %> + <% end %> <% t.column "Source" do |ip| %> <%= link_to ip.model_type.underscore.humanize, ip_addresses_path(search: { model_type: ip.model_type }) %> <% end %> <% t.column "ID" do |ip| %> <%= link_to "##{ip.model_id}", ip.model %> <% end %> - <% t.column "IP Address" do |ip| %> - <%= link_to ip.ip_addr, ip_addresses_path(search: { ip_addr: ip.ip_addr }) %> - <%= link_to "»", ip_addresses_path(search: { ip_addr: ip.ip_addr, group_by: "user" }) %> - <% end %> <% t.column "User" do |ip| %> <%= link_to_user ip.user %> <%= link_to "»", ip_addresses_path(search: { user_id: ip.user_id, group_by: "ip_addr" }) %> @@ -17,6 +17,8 @@ <%= time_ago_in_words_tagged ip.created_at %> <% end %> <% t.column column: "ip-info" do |ip| %> - <%= link_to "IP info", "https://ipinfo.io/#{ip.ip_addr}" %> + <%= link_to "Details", ip_address_path(ip.ip_addr.to_s) %> + | <%= link_to "Ban IP", new_ip_ban_path(ip_ban: { ip_addr: ip.ip_addr.to_s }) %> + | <%= link_to "Ban User", new_ban_path(ban: { user_name: ip.user.name, duration: 999999 }) %> <% end %> <% end %> diff --git a/app/views/ip_addresses/_index_by_ip_addr.html.erb b/app/views/ip_addresses/_index_by_ip_addr.html.erb index a51822654..5c827a60d 100644 --- a/app/views/ip_addresses/_index_by_ip_addr.html.erb +++ b/app/views/ip_addresses/_index_by_ip_addr.html.erb @@ -11,6 +11,6 @@ <%= link_to ip.count_all, ip_addresses_path(search: { ip_addr: ip.to_s }) %> <% end %> <% t.column column: "ip-info" do |ip| %> - <%= link_to "IP info", "https://ipinfo.io/#{ip.ip_addr}" %> + <%= link_to "Details", ip_address_path(ip.ip_addr.to_s) %> <% end %> <% end %> diff --git a/app/views/ip_addresses/_info.html.erb b/app/views/ip_addresses/_info.html.erb new file mode 100644 index 000000000..adf31775f --- /dev/null +++ b/app/views/ip_addresses/_info.html.erb @@ -0,0 +1,75 @@ +
| Location | ++ <% if ip_info.dig(:location, :city) %> + <%= ip_info.dig(:location, :city) %>, + <% end %> + <% if ip_info.dig(:location, :region, :name).present? %> + <%= ip_info.dig(:location, :region, :name) %>, + <% end %> + <%= ip_info.dig(:location, :country, :name) %> + | +
|---|---|
| Network | ++ <%= link_to ip_info.dig(:connection, :route), ip_addresses_path(search: { ip_addr: ip_info.dig(:connection, :route) }) %> + (<%= link_to "info", "https://ipinfo.io/AS#{ip_info.dig(:connection, :asn)}/#{ip_info.dig(:connection, :route)}" %>) + | +
| Proxy | +<%= ip_address.lookup.is_proxy? ? "yes" : "no" %> | +
| IP Banned | ++ <% if IpBan.is_banned?(ip_address.ip_addr.to_s) %> + yes (<%= link_to "info", ip_bans_path(search: { ip_addr: ip_address.to_s }) %>) + <% else %> + no + <% end %> + | +
| Type | +<%= ip_info.dig(:connection, :type) %> | +
| ASN | ++ <%= link_to "AS#{ip_info.dig(:connection, :asn)}", "https://ipinfo.io/AS#{ip_info.dig(:connection, :asn)}" %> + | +
| Organization | ++ <%= ip_info.dig(:connection, :organization) %> + | +
| Mobile Carrier | +<%= ip_info.dig(:carrier, :name) %> | +
| Website | +<%= external_link_to("http://#{ip_info.dig(:connection, :domain)}") %> | +
| Details | +
+
+
+ <%= JSON.pretty_generate(ip_info) %>+ |
+