Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/1032
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Oct 3, 2024
1 parent 70a41ad commit 5ea276a
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 46 deletions.
136 changes: 95 additions & 41 deletions lib/components/links/link_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Bonfire.UI.Common.LinkLive do
"""

use Bonfire.UI.Common.Web, :stateless_component
# import Phoenix.Component

@doc "The required path or URL to link to"
prop to, :string, required: true
Expand Down Expand Up @@ -75,7 +76,9 @@ defmodule Bonfire.UI.Common.LinkLive do

def render(%{to: "http" <> _, external_link_warnings: true} = assigns) do
~F"""
<p class="mb-4">This is an external link, please check where it leads before following it. If you have concerns it may be malicious you can check one of the URL reputation services below, or copy and paste the URL into a tool of your choice.</p>
<p class="mb-4">{l(
"This is an external link, please check where it leads before following it. If you have concerns it may be malicious you can check one of the URL or IP address reputation services below, or copy and paste the URL into the reputation tool of your choice."
)}</p>
<a
phx-hook="Copy"
Expand All @@ -95,53 +98,104 @@ defmodule Bonfire.UI.Common.LinkLive do
<#slot>{@label}</#slot>
</Link>
<p class="mt-4">
{#case URI.encode_www_form(@to)}
{#match url_encoded}
{!-- TODO: make these configurable --}
<Link
to={"https://transparencyreport.google.com/safe-browsing/search?url=#{url_encoded}"}
opts={@opts |> Keyword.merge("aria-label": @label, target: @target)}
class="btn btn-xs"
>{l("Google Safe Browsing")}</Link>
{!-- TODO: make these configurable --}
{#case Unfurl.uri_host(@to)}
{#match domain}
<p class="mt-4 text-xs">
{#case URI.encode_www_form(domain)}
{#match url_encoded}
Check URL:
<Link
to={"https://transparencyreport.google.com/safe-browsing/search?url=#{url_encoded}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("Google Safe Browsing")}</Link>
<Link
<Link
to={"https://urlscan.io/search/#page.url.keyword:#{url_encoded}*"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("URLscan")}</Link>
{!--
<Link
to={"https://www.urlvoid.com/scan/#{url_encoded}"}
opts={@opts |> Keyword.merge("aria-label": @label, target: @target)}
class="btn btn-xs"
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("URLvoid")}</Link>
<Link
to={"https://urlscan.io/search/#page.url.keyword:#{url_encoded}*"}
opts={@opts |> Keyword.merge("aria-label": @label, target: @target)}
class="btn btn-xs"
>{l("URLscan")}</Link>
--}
<Link
to={"https://www.virustotal.com/gui/search/#{url_encoded}"}
opts={@opts |> Keyword.merge("aria-label": @label, target: @target)}
class="btn btn-xs"
>{l("VirusTotal")}</Link>
<Link
to={"https://otx.alienvault.com/indicator/domain/#{url_encoded}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("AlienVault OTX")}</Link>
<Link
to={"https://sitecheck.sucuri.net/results/#{url_encoded}"}
opts={@opts |> Keyword.merge("aria-label": @label, target: @target)}
class="btn btn-xs"
>{l("Sucuri")}</Link>
<Link
to={"https://www.virustotal.com/gui/search/#{url_encoded}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("VirusTotal")}</Link>
<Link
to={"https://safeweb.norton.com/report?url=#{url_encoded}"}
opts={@opts |> Keyword.merge("aria-label": @label, target: @target)}
class="btn btn-xs"
>{l("Norton")}</Link>
<Link
to={"https://sitecheck.sucuri.net/results/#{url_encoded}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("Sucuri")}</Link>
<Link
to={"https://safeweb.norton.com/report?url=#{url_encoded}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("Norton")}</Link>
<Link
to={"https://check.spamhaus.org/results/?query=#{url_encoded}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("SpamHaus")}</Link>
<Link
to={"https://mxtoolbox.com/SuperTool.aspx?action=blacklist:#{url_encoded}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("MX Toolbox")}</Link>
{/case}
</p>
<p class="mt-4 text-xs">
{#case Cache.maybe_apply_cached({Unfurl, :domain_ip_address}, domain, fallback_return: nil)
~> debug("IPadr")}
{#match ip}
Check IP:
<Link
to={"https://www.abuseipdb.com/check/#{ip}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("AbuseIPDB")}</Link>
<Link
to={"https://otx.alienvault.com/indicator/ip/#{ip}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("AlienVault OTX")}</Link>
<Link
to={"https://www.projecthoneypot.org/ip_#{ip}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("Project Honeypot")}</Link>
{!--
<Link
to="https://www.abuseipdb.com"
opts={@opts |> Keyword.merge("aria-label": @label, target: @target)}
class="btn btn-xs"
>{l("AbuseIPDB")}</Link>
{/case}
</p>
to={"https://www.fortiguard.com/search?q=#{ip}"}
opts={@opts |> Keyword.merge(target: "_blank")}
class="btn btn-xs"
>{l("FortiGuard")}</Link>
--}
{/case}
</p>
{/case}
"""
end

Expand Down Expand Up @@ -184,7 +238,7 @@ defmodule Bonfire.UI.Common.LinkLive do

def render(%{to: to} = assigns) when is_binary(to) and to != "" do
~F"""
<Phoenix.Component.link
<.link
navigate={@to}
class={@class}
replace={@replace}
Expand All @@ -194,7 +248,7 @@ defmodule Bonfire.UI.Common.LinkLive do
>
{!-- FIXME: do not generate random ID to avoid re-rendering --}
<#slot>{@label}</#slot>
</Phoenix.Component.link>
</.link>
"""
end

Expand Down
45 changes: 40 additions & 5 deletions lib/components/modals/reusable_modal_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ defmodule Bonfire.UI.Common.ReusableModalLive do
)
end

def set(assigns, reusable_modal_id \\ nil) do
def set(assigns, reusable_modal_id \\ nil, opts \\ []) do
maybe_set_assigns(
e(
assigns,
:reusable_modal_component,
ReusableModalLive
),
reusable_modal_id || modal_id(assigns),
assigns
assigns,
opts
)

# case assigns[:root_assigns] do
Expand All @@ -128,18 +129,22 @@ defmodule Bonfire.UI.Common.ReusableModalLive do
# end
end

defp maybe_set_assigns(_component, "media_player_modal", assigns) do
defp maybe_set_assigns(component, reusable_modal_id, assigns, opts \\ [])

defp maybe_set_assigns(_component, "media_player_modal", assigns, opts) do
# TODO: forward opts (eg for PID)
# TODO: detect if we're already in the sticky view
# debug(assigns, "try sending to media player")
Bonfire.UI.Common.PersistentLive.maybe_send(assigns, {:media_player, assigns})
end

defp maybe_set_assigns(component, reusable_modal_id, assigns) do
defp maybe_set_assigns(component, reusable_modal_id, assigns, opts) do
# debug(assigns, "try sending to reusable modal")
maybe_send_update(
component,
reusable_modal_id,
assigns
assigns,
opts
)
end

Expand All @@ -156,6 +161,36 @@ defmodule Bonfire.UI.Common.ReusableModalLive do
sticky: e(assigns(socket), :__context__, :sticky, nil)
)

pid = self()

apply_task(:start_link, fn ->
debug("attempt to unshorten")

final_url =
Cache.maybe_apply_cached({Unfurl.Unshortener, :unshorten!}, url, fallback_return: nil)
|> debug("final_url")

if final_url != url do
debug(final_url, "urls are different")

set(
[
show: true,
modal_assigns: [
modal_component: LinkLive,
to: final_url,
label: "#{url} (redirects to #{final_url})",
external_link_warnings: true,
class: "link font-mono"
],
sticky: e(assigns(socket), :__context__, :sticky, nil)
],
nil,
pid: pid
)
end
end)

{:noreply, socket}
end

Expand Down

0 comments on commit 5ea276a

Please sign in to comment.