Changeset 5052
- Timestamp:
- 01/20/08 16:10:01 (5 years ago)
- Location:
- lang/perl/Moxy/trunk
- Files:
-
- 1 added
- 3 modified
-
lib/Moxy/Plugin/Server.pm (added)
-
lib/Moxy/Plugin/Server/HTTPProxy.pm (modified) (7 diffs)
-
t/plugin-application.t (modified) (1 diff)
-
t/xss.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Moxy/trunk/lib/Moxy/Plugin/Server/HTTPProxy.pm
r5046 r5052 3 3 use warnings; 4 4 use utf8; 5 use Moxy::Plugin::Server; 5 6 use Encode; 6 7 use HTTP::Proxy ':log'; … … 10 11 use LWP::UserAgent; 11 12 use URI; 12 use HTML::Parser;13 13 use HTML::Entities; 14 14 use URI::Escape; … … 24 24 my $base = URI->new($args->{response}->request->uri); 25 25 $base->query_form({}); 26 return $class->_render_control_panel($base, $args->{response}->request->uri);26 return render_control_panel($base, $args->{response}->request->uri); 27 27 }, 28 28 run_server => sub { $class->run_server($context, $config) }, … … 90 90 } 91 91 92 sub _render_control_panel {93 my ($class, $base, $current_url) = @_;94 95 return sprintf(<<"...", encode_entities($current_url));96 <form method="get" action="$base">97 <input type="text" name="q" value="\%s" size="40" />98 <input type="submit" value="go" />99 </form>100 ...101 }102 103 92 sub _ua { 104 93 my ($class, $config) = @_; … … 126 115 my $content_type = $res->header('Content-Type'); 127 116 if ($content_type =~ /html/i) { 128 $res->content( _rewrite($base, $res->content, $url) );117 $res->content( rewrite($base, $res->content, $url) ); 129 118 } 130 119 } … … 134 123 my $res = HTTP::Response->new(200, 'about:blank'); 135 124 $res->header('Content-Type' => 'text/html; charset=utf8'); 136 my $panel = $class->_render_control_panel($base, '');125 my $panel = render_control_panel($base, ''); 137 126 $res->content(qq{<html><head></head><body>$panel</body></html>}); 138 127 return $res; … … 188 177 } 189 178 190 sub _rewrite {191 my ($base, $html, $url) = @_;192 193 my $output = '';194 my $base_url = URI->new($url);195 my $parser = HTML::Parser->new(196 api_version => 3,197 start_h => [ sub {198 my ($tagname, $attr, $orig) = @_;199 200 if ($tagname eq 'a' || $tagname eq 'A') {201 $output .= "<$tagname";202 my @parts;203 my $href = delete $attr->{href};204 if ($href) {205 $output .= " ";206 push @parts,207 sprintf( qq{href="$base?q=%s"},208 uri_escape(URI->new($href)->abs($base_url)) );209 }210 push @parts, map { sprintf qq{%s="%s"}, encode_entities($_), encode_entities($attr->{$_}) } keys %$attr;211 $output .= join " ", @parts;212 $output .= ">";213 } elsif ($tagname =~ /form/i) {214 $output .= "<$tagname";215 my @parts;216 my $action = delete $attr->{action};217 if ($action) {218 $output .= " ";219 push @parts, sprintf(qq{action="$base?q=%s"},220 uri_escape(URI->new($action)->abs($base_url))221 );222 }223 push @parts, map { sprintf qq{$_="%s"}, encode_entities($attr->{$_}) } keys %$attr;224 $output .= join " ", @parts;225 $output .= ">";226 } elsif ($tagname =~ /img/i) {227 $output .= "<$tagname";228 my @parts;229 my $src = delete $attr->{src};230 if ($src) {231 $output .= " ";232 push @parts, sprintf(qq{src="$base?q=%s"},233 uri_escape(URI->new($src)->abs($base_url))234 );235 }236 push @parts, map { sprintf qq{%s="%s"}, encode_entities($_), encode_entities($attr->{$_}) } grep !/^\/$/, keys %$attr;237 $output .= join " ", @parts;238 $output .= ">";239 } else {240 $output .= $orig;241 return;242 }243 }, "tagname, attr, text" ],244 end_h => [ sub { $output .= shift }, "text"],245 text_h => [ sub { $output .= shift }, "text"],246 );247 248 $parser->boolean_attribute_value('__BOOLEAN__');249 $parser->parse($html);250 $output;251 }252 253 179 1; 254 180 __END__ -
lang/perl/Moxy/trunk/t/plugin-application.t
r3016 r5052 2 2 use warnings; 3 3 use Test::Base; 4 use Moxy::Plugin:: Application;4 use Moxy::Plugin::Server; 5 5 6 6 sub rewrite { 7 Moxy::Plugin:: Application::_rewrite('http://localhost:9999/', shift, 'http://relative.example.jp/');7 Moxy::Plugin::Server::rewrite('http://localhost:9999/', shift, 'http://relative.example.jp/'); 8 8 } 9 9 -
lang/perl/Moxy/trunk/t/xss.t
r3026 r5052 1 use strict;use warnings; 2 use Moxy::Plugin::Application; 1 use strict; 2 use warnings; 3 use Moxy::Plugin::Server; 3 4 use Test::More tests => 1; 4 5 5 unlike(Moxy::Plugin:: Application->_render_control_panel('http://example.com/', '<script>alert("FOO");</script>'), qr{<script>});6 unlike(Moxy::Plugin::Server::render_control_panel('http://example.com/', '<script>alert("FOO");</script>'), qr{<script>});
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)