Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Perl WAF Overview, with mod_perl - Hokkaido.pm#...

Perl WAF Overview, with mod_perl - Hokkaido.pm#7 #hokkaidopm

2012/05/13 に Hokkaido.pm#7 で発表したスライドです。

OGATA Tetsuji

May 13, 2012
Tweet

More Decks by OGATA Tetsuji

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ඌܗ మ࣍ (OGATA Tetsuji) • Twitter: @xtetsuji •

    Blog: http://post.tetsuji.jp/ • ग़਎͸๺ւಓՏ౦܊Իߋொ(ଳ޿ࢢͷྡ) • େֶͰ্ژͯ͠ݱࡏ͸౦ژͷձࣾʹۈ຿
  2. What is WAF? • ʮMVC෼཭ʯΛଅਐ͢Δ΋ͷʁ • ҧ͏ • Catalystͷࣦഊྫʁ •

    ModelΛWAFʹີணͤ͞Δͱɺ֎ଆͷ ؅ཧπʔϧ౳͔Β࢖͍ͮΒ͘ͳΔ
  3. Latest Perl WAF fashion • Sinatra (WAF, powered by Ruby)

    Like • Perl post-modern WAFs almost have Sinatratic syntax • Lightweight • Controller oriented
  4. package MyApache2::Hello; use strict; use warnings; use Apache2::RequestRec; use Apache2::RequestIO;

    use Apache2::Const -compile => qw(OK); sub handler { my $r = shift; $r->content_type("text/plain"); $r->print("Hello, world"); return Apache2::Const::OK; } 1; __END__ <Location /> PerlResponseHandler MyApache2::Hello </Location>
  5. package MyApache2::Sinatratic; use strict; use warnings; # $CALLBACK->{$handler_package}->{$http_method} = [

    [$url, $handler], ... ]; my $CALLBACK = {}; sub import { my $pkg = shift; my @args = @_; my $callpkg = caller(0); for my $method (qw(get post put del)) { $CALLBACK->{$callpkg}->{$method} = []; } # sub handler definition require Apache2::RequestRec; require Apache2::RequestUtil; require APR::Table; no strict 'refs'; *{"$callpkg\::handler"} = \&import_handler; for my $method (qw(get post put del)) { *{"$callpkg\::$method"} = sub { my ($url, $handler) = @_; push @{$CALLBACK->{$callpkg}->{$method}}, [$url, $handler]; }; } *{"$callpkg\::default"} = sub { my $handler = shift; $CALLBACK->{$callpkg} ||= {}; $CALLBACK->{$callpkg}->{default} = $handler; }; }
  6. package MyApache2::Hello2; use strict; use warnings; use Apache2::RequestRec; use Apache2::RequestIO;

    use Apache2::Const -compile => qw(OK); use MyApache2::Sinatratic; get '/' => sub { my $r = shift; $r->content_type("text/plain"); $r->print("Hello, world"); return Apache2::Const::OK; }; 1; __END__ <Location /> PerlResponseHandler MyApache2::Hello2 </Location>