[Rt-commit] rtir branch 5.0/fix-external-tools-iframe created. 5.0.4-2-gf89ab600

BPS Git Server git at git.bestpractical.com
Mon Jul 3 20:43:36 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rtir".

The branch, 5.0/fix-external-tools-iframe has been created
        at  f89ab60063aefad3a20d023bcf9638e4bff5907e (commit)

- Log -----------------------------------------------------------------
commit f89ab60063aefad3a20d023bcf9638e4bff5907e
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Mon Jul 3 17:40:56 2023 -0300

    Remove Iframe research tools and add them as External tools
    
    Iframe research tools are not supported by modern browsers. We are
    replacing them with External tools, which will call the research tools
    from the RT server.

diff --git a/Makefile.PL b/Makefile.PL
index d86f3b28..3631ecdd 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -30,6 +30,8 @@ requires('DBIx::SearchBuilder', 1.61);
 requires('Regexp::Common');
 # queries parsing
 requires('Parse::BooleanLogic');
+# Parse websites with External Tools
+requires('HTML::TreeBuilder::XPath');
 
 # Domain searching
 requires('Net::Domain::TLD');
diff --git a/etc/RTIR_Config.pm b/etc/RTIR_Config.pm
index be018fe0..5c8e10d5 100644
--- a/etc/RTIR_Config.pm
+++ b/etc/RTIR_Config.pm
@@ -795,23 +795,17 @@ using the following mason components:
 
 =cut
 
-Set( @RTIRResearchTools, (qw(Traceroute Whois Iframe)));
+Set( @RTIRResearchTools, (qw(Traceroute Whois External)));
 
-=item C<$RTIRIframeResearchToolConfig>
+=item C<$RTIRExternalResearchToolConfig>
 
 One of the research tools available in RTIR allows you to
 configure a set of search URLs that incident handlers
-can use to open searches in IFRAMES.
-
-Entries are keyed by integer in the order you'd like to see
-them in the dropdown on the research page. Each entry consists
-of a hashref containing "FriendlyName" and "URL". The URLs will
-be evaluated to replace __SearchTerm__ with the user's current
-search term.
+can use to open searches in external tools.
 
 =cut
 
-Set($RTIRIframeResearchToolConfig, {
+Set($RTIRExternalResearchToolConfig, {
     1 => { FriendlyName => 'Google', URL => 'https://encrypted.google.com/search?q=__SearchTerm__' },
     2 => { FriendlyName => 'CVE', URL => 'http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=__SearchTerm__'},
     3 => { FriendlyName => 'McAfee SiteAdvisor', URL => 'http://www.siteadvisor.com/sites/__SearchTerm__'}
diff --git a/html/RTIR/Tools/Elements/ToolFormIframe b/html/RTIR/Tools/Elements/ToolFormExternal
similarity index 96%
rename from html/RTIR/Tools/Elements/ToolFormIframe
rename to html/RTIR/Tools/Elements/ToolFormExternal
index 6b5326cb..a774ae3b 100644
--- a/html/RTIR/Tools/Elements/ToolFormIframe
+++ b/html/RTIR/Tools/Elements/ToolFormExternal
@@ -78,6 +78,6 @@ $ResearchTool => ''
 </%args>
 <%INIT>
 my $unique_id = time().rand();
-$m->notes(rtir_research_iframe_id => $unique_id);
-my $research_tools = RT->Config->Get('RTIRIframeResearchToolConfig');
+$m->notes(rtir_research_external_id => $unique_id);
+my $research_tools = RT->Config->Get('RTIRExternalResearchToolConfig');
 </%INIT>
diff --git a/html/RTIR/Tools/Elements/ToolResultsIframe b/html/RTIR/Tools/Elements/ToolResultsExternal
similarity index 66%
rename from html/RTIR/Tools/Elements/ToolResultsIframe
rename to html/RTIR/Tools/Elements/ToolResultsExternal
index 323f11c0..e13db1fc 100644
--- a/html/RTIR/Tools/Elements/ToolResultsIframe
+++ b/html/RTIR/Tools/Elements/ToolResultsExternal
@@ -45,20 +45,19 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<h2><%loc($research_tools->{$ResearchTool}->{FriendlyName})%></h2>
-<iframe 
-    src="<%$url%>" 
-    name="rtir_research_<%$m->notes('rtir_research_iframe_id')%>" 
-    style="width: 100%; height: 70%;"></iframe>
+<h2><a href="<% $url %>" target="_blank"><%loc($research_tools->{$ResearchTool}->{FriendlyName})%></a></h2>
+% if ($q) {
+    <% $out |n %>
+% } else {
+    <% loc("No value informed") %>
+%}
 <%args>
 $q =>  undef
-$TicketType => undef
-$TicketObj => undef
 $ResearchTool => undef
 </%args>
 <%init>
 return unless ($ResearchTool);
-my $research_tools = RT->Config->Get('RTIRIframeResearchToolConfig');
+my $research_tools = RT->Config->Get('RTIRExternalResearchToolConfig');
 if (!$research_tools->{$ResearchTool}->{URL}) {
     $RT::Logger->error(
         "Couldn't find a URL for RTIR research tool $ResearchTool. You should check your RTIRIframeResearchToolConfig");
@@ -66,4 +65,38 @@ if (!$research_tools->{$ResearchTool}->{URL}) {
 }
 my $url = $research_tools->{$ResearchTool}->{URL};
 $url =~ s/__SearchTerm__/$q/g;
+
+my $out;
+
+if ($q) {
+    use LWP::UserAgent;
+    use HTML::TreeBuilder::XPath;
+
+    my $ua = LWP::UserAgent->new(env_proxy => 1);
+    my $response = $ua->get($url);
+
+    # Check if there is content
+    if ($response->is_success) {
+        my $tree = HTML::TreeBuilder::XPath->new_from_content($response->content);
+        # For SiteAdvisor
+        # my @contents = $tree->findnodes(qw{//div[@class='content']});
+        # For CVE
+        my @contents = $tree->findnodes(qw{//div[@id='CenterPane']/div[@class='smaller']|}.
+                                        qw{//div[@id='CenterPane']/h2|}.
+                                        qw{//div[@id='CenterPane']/div[@id='TableWithRules']/table}
+                                        );
+        foreach my $content (@contents) {
+            $out .= $content->as_HTML('<>&');
+        }
+        $out = RT::IR::Web::ScrubHtmlExternalTools($out);
+    } else {
+        $out = 'Error: ' . $response->status_line;
+    }
+
+
+
+
+
+    
+}
 </%init>
diff --git a/lib/RT/IR/Web.pm b/lib/RT/IR/Web.pm
index 6f0e10b7..9a96e665 100644
--- a/lib/RT/IR/Web.pm
+++ b/lib/RT/IR/Web.pm
@@ -94,5 +94,32 @@ sub RTIRDefaultSearchParams {
 }
 
 package RT::IR::Web;
+
+sub ScrubHtmlExternalTools {
+    my ($html) = @_;
+    # $html = Encode::decode("UTF-8",($html));
+    my $scrubber = HTML::Scrubber->new( script => 0,
+        allow => [ qw[ table tr td span ol ul li h1 h2 h3 ] ] );
+    $scrubber->rules(
+        a => {
+            'href' => sub {
+                my ($obj, $tag, $attr, $value) = @_;
+                if ($value =~ m{^/cgi-bin/cvename.cgi\?name\=}) {
+                    return 'https://cve.mitre.org'.$value;
+                }
+                return;
+            },
+        },
+        '*' =>  {
+            style => 1,
+            width => 1,
+            cellpadding => 1,
+            cellspacing => 1,
+        }
+    );
+    my $scrubbed_html = $scrubber->scrub($html);
+    return $scrubbed_html;
+}
+
 RT::Base->_ImportOverlays();
 1;

-----------------------------------------------------------------------


hooks/post-receive
-- 
rtir


More information about the rt-commit mailing list