diff --git a/docs/upgrades/upgrade_5.4.3-5.5.0.sql b/docs/upgrades/upgrade_5.4.3-5.5.0.sql index 9e6b78b84..9937a3338 100644 --- a/docs/upgrades/upgrade_5.4.3-5.5.0.sql +++ b/docs/upgrades/upgrade_5.4.3-5.5.0.sql @@ -131,4 +131,9 @@ delete from international where languageId=1 and namespace='WebGUI' and internat insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1013,1,'WebGUI','Make sticky?', 1060434033,'A message indicating whether the moderator wants to make this message stay at the top of the discussion.'); delete from international where languageId=1 and namespace='WebGUI' and internationalId=1012; insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1012,1,'WebGUI','Lock this thread?', 1060433963,'A message indicating whether the moderator wants to lock the thread as he posts.'); - +alter table HttpProxy add column searchFor varchar(255); +alter table HttpProxy add column stopAt varchar(255); +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (13,1,'HttpProxy','Search for', 1060433963,'A string used as starting point when proxying parts of remote content.'); +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (14,1,'HttpProxy','Stop at', 1060433963,'A string used as ending point when proxying parts of remote content.'); +INSERT INTO template VALUES (1,'Default HTTP Proxy','\r\n

\r\n
\r\n\r\n\r\n

\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n Error: Search string not found in content.\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n Warning: Ending search point not found in content.\r\n \r\n','HttpProxy'); +UPDATE international set message = 'The HTTP Proxy wobject is a very powerful tool. It enables you to embed external sites and applications into your site. For example, if you have a web mail system that you wish your staff could access through the intranet, then you could use the HTTP Proxy to accomplish that.\r\n\r\n

\r\n\r\nURL
\r\nThe starting URL for the proxy.\r\n

\r\n\r\nFollow redirects?
\r\nSometimes the URL to a page, is actually a redirection to another page. Do you wish to follow those redirections when they occur?\r\n

\r\n\r\nRewrite urls?
\r\nSwitch this to No if you want to deeplink an external page.\r\n

\r\n\r\nTimeout
\r\nThe amount of time (in seconds) that WebGUI should wait for a connection before giving up on an external page.\r\n

\r\n\r\nRemove style?
\r\nDo you wish to remove the stylesheet from the proxied content in favor of the stylesheet from your site?\r\n

\r\n\r\nFilter Content
\r\nChoose the level of HTML filtering you wish to apply to the proxied content.\r\n

\r\n\r\nSearch for
\r\nA search string used as starting point. Use this when you want to display only a part of the proxied content. Content before this point is not displayed\r\n

\r\n\r\nStop at
\r\nA search string used as ending point. Content after this point is not displayed.\r\n

\r\nNote: The Search for and Stop at strings are included in the content. You can change this by editing the template for HttpProxy.\r\n

\r\n\r\nAllow proxying of other domains?
\r\nIf you proxy a site like Yahoo! that links to other domains, do you wish to allow the user to follow the links to those other domains, or should the proxy stop them as they try to leave the original site you specified?\r\n

\r\n' where internationalId = 11 and namespace = 'HttpProxy' and languageId = 1; diff --git a/lib/WebGUI/Wobject/HttpProxy.pm b/lib/WebGUI/Wobject/HttpProxy.pm index f760eb5de..00679f7af 100644 --- a/lib/WebGUI/Wobject/HttpProxy.pm +++ b/lib/WebGUI/Wobject/HttpProxy.pm @@ -60,8 +60,15 @@ sub new { }, followRedirect=>{ defaultValue=>0 - } - } + }, + searchFor=>{ + defaultValue=>'' + }, + stopAt=>{ + defaultValue=>'' + }, + }, + -useTemplate=>1 ); bless $self, $class; } @@ -114,6 +121,16 @@ sub www_edit { -label=>WebGUI::International::get(4,$_[0]->get("namespace")), -value=>[$_[0]->getValue("timeout")] ); + $layout->text( + -name=>"searchFor", + -label=>WebGUI::International::get(13,$_[0]->get("namespace")), + -value=>$_[0]->getValue("searchFor") + ); + $layout->text( + -name=>"stopAt", + -label=>WebGUI::International::get(14,$_[0]->get("namespace")), + -value=>$_[0]->getValue("stopAt") + ); return $_[0]->SUPER::www_edit( -properties=>$properties->printRowsOnly, -layout=>$layout->printRowsOnly, @@ -126,11 +143,7 @@ sub www_edit { #------------------------------------------------------------------- sub www_view { - my (%formdata, @formUpload, $redirect, $response, $header, - $userAgent, $proxiedUrl, $request, $content, $ttl); - - my $output = $_[0]->displayTitle; - $output .= $_[0]->description; + my (%var, %formdata, @formUpload, $redirect, $response, $header, $userAgent, $proxiedUrl, $request, $ttl); my $node = WebGUI::Node->new("temp",$_[0]->get("namespace")."_cookies"); $node->create; @@ -149,13 +162,13 @@ sub www_view { $redirect=0; - return $output unless ($proxiedUrl ne ""); + ssTemplate($_[0]->get("templateId"),{}) unless ($proxiedUrl ne ""); my $cachedContent = WebGUI::Cache->new($proxiedUrl,"URL"); my $cachedHeader = WebGUI::Cache->new($proxiedUrl,"HEADER"); - $header = $cachedHeader->get; - $content = $cachedContent->get; - unless ($content && $session{env}{REQUEST_METHOD}=~/GET/i) { + $var{header} = $cachedHeader->get; + $var{content} = $cachedContent->get; + unless ($var{content} && $session{env}{REQUEST_METHOD}=~/GET/i) { $redirect=0; until($redirect == 5) { # We follow max 5 redirects to prevent bouncing/flapping $userAgent = new LWP::UserAgent; @@ -236,26 +249,38 @@ sub www_view { } if($response->is_success) { - $content = $response->content; - $header = $response->content_type; + $var{content} = $response->content; + $var{header} = $response->content_type; if($response->content_type eq "text/html" || - ($response->content_type eq "" && $content=~/new($proxiedUrl, $content, $_[0]->get("wobjectId"),$_[0]->get("rewriteUrls")); - $content = $p->filter; # Rewrite content. (let forms/links return to us). + ($response->content_type eq "" && $var{content}=~/getValue("searchFor"); + $var{"stop.at"} = $_[0]->getValue("stopAt"); + if ($var{"search.for"}) { + $var{content} =~ /^(.*?)\Q$var{"search.for"}\E(.*)$/gis; + $var{"content.leading"} = $1 || $var{content}; + $var{content} = $2; + } + if ($var{"stop.at"}) { + $var{content} =~ /(.*?)\Q$var{"stop.at"}\E(.*)$/gis; + $var{content} = $1 || $var{content}; + $var{"content.trailing"} = $2; + } + my $p = WebGUI::Wobject::HttpProxy::Parse->new($proxiedUrl, $var{content}, $_[0]->get("wobjectId"),$_[0]->get("rewriteUrls")); + $var{content} = $p->filter; # Rewrite content. (let forms/links return to us). $p->DESTROY; - if ($content =~ /HttpProxy: Can't display frames Try fetching it directly here."; } else { - $content =~ s/\//isg if ($_[0]->get("removeStyle")); - $content = WebGUI::HTML::cleanSegment($content); - $content = WebGUI::HTML::filter($content, $_[0]->get("filterHtml")); + $var{content} =~ s/\//isg if ($_[0]->get("removeStyle")); + $var{content} = WebGUI::HTML::cleanSegment($var{content}); + $var{content} = WebGUI::HTML::filter($var{content}, $_[0]->get("filterHtml")); } } } else { # Fetching page failed... - $content = "Getting $proxiedUrl failed". + $var{content} = "Getting $proxiedUrl failed". "

GET status line: ".$response->status_line.""; } if ($session{user}{userId} == 1) { @@ -264,15 +289,15 @@ sub www_view { $ttl = $session{page}{cacheTimeout}; } - $cachedContent->set($content,$ttl); - $cachedHeader->set($header,$ttl); + $cachedContent->set($var{content},$ttl); + $cachedHeader->set($var{header},$ttl); } - if($header ne "text/html") { - $session{header}{mimetype} = $header; - return $content; + if($var{header} ne "text/html") { + $session{header}{mimetype} = $var{header}; + return $var{content}; } else { - return $output.$content; + return $_[0]->processTemplate($_[0]->get("templateId"),\%var); } } 1;