Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
mod_perl hacks PHP
Search
OGATA Tetsuji
December 10, 2011
Technology
0
5
mod_perl hacks PHP
2011/12/10 に Hokkaido.pm#6 で発表したスライドです。
OGATA Tetsuji
December 10, 2011
Tweet
Share
More Decks by OGATA Tetsuji
See All by OGATA Tetsuji
Hokkaido.pmがあって YAPCでトークできた
xtetsuji
0
17
モダンmod_perl入門 #yapcasia
xtetsuji
0
11
札幌でテンプレート #hokkaidopm
xtetsuji
0
18
すごいmod_perl
xtetsuji
0
8
Perl WAF Overview, with mod_perl - Hokkaido.pm#7 #hokkaidopm
xtetsuji
0
8
PerlのTwitterモジュールの紹介
xtetsuji
0
11
文字化け2011〜まだまだ化けます〜
xtetsuji
0
11
mod_perl温故知新 〜Perl CGIの高速化からメールサーバまで〜
xtetsuji
0
7
Other Decks in Technology
See All in Technology
いざ、BSC討伐の旅
nikinusu
2
780
The Role of Developer Relations in AI Product Success.
giftojabu1
0
120
複雑なState管理からの脱却
sansantech
PRO
1
140
OTelCol_TailSampling_and_SpanMetrics
gumamon
1
130
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
130
アジャイルでの品質の進化 Agile in Motion vol.1/20241118 Hiroyuki Sato
shift_evolve
0
110
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
520
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
870
Platform Engineering for Software Developers and Architects
syntasso
1
520
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
TypeScript、上達の瞬間
sadnessojisan
46
13k
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
What's in a price? How to price your products and services
michaelherold
243
12k
Being A Developer After 40
akosma
86
590k
Music & Morning Musume
bryan
46
6.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
A Modern Web Designer's Workflow
chriscoyier
693
190k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Gamification - CAS2011
davidbonilla
80
5k
Designing for Performance
lara
604
68k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Transcript
mod_perl hacks PHP גࣜձࣾfonfun ඌܗ మ࣍ (OGATA Tetsuji) Twitter: @xtetsuji
2011/12/10
ࣗݾհ
ࣗݾհ • ඌܗ మ࣍ (OGATA Tetsuji) • Twitter: @xtetsuji •
Blog: http://post.tetsuji.jp/ • ग़ւಓՏ౦܊Իߋொ(ଳࢢͷྡ) • େֶͰ্ژͯ͠ݱࡏ౦ژͷձࣾʹۈ
ࣗݾհ • Hokkaido.pm#5Ͱʮmod_perlԹނ৽ʯ ͱ͍͏τʔΫΛਓੜॳ൸࿐ • ެͷͰͷτʔΫࠓճͰ3ճ • ϞμϯPerlʹΕ͍ͯͳ͍30 • झຯ:
ΫϥγοΫԻָɺΧϑΣࢄࡦɺ ࿏ઢόε
ॴଐհ • גࣜձࣾfonfun(ϑΥϯϑΝϯ) http://www.fonfun.co.jp/ • ओྗɿϦϞʔτϝʔϧ http://rmail.jp/ • ҙஂମg15ΞιγΤʔγϣϯ http://g15.jp/
ॴଐհ • גࣜձࣾfonfun(چ໊ࣾ:ωοτϏϨοδ) • 1999͔ΒΣϒϝʔϧ (໊:ϦϞʔτϝʔϧ)Λӡ༻ • 2003ʹୈ4ੈγεςϜ(Perl + Apache/
mod_perl + Oracle + Post fi x)Λ։ൃ • ࠷ۙ৽͍ٕ͠ज़తͳࢼΈʹνϟϨϯδத
Hokkaido.pm++ • ւಓ(ຊʹ)ࢲͷނڷͰ͢ʂ • ॳεϐʔΧʔͷػձΛ༩͍͍͑ͯͨͩͯ ͋Γ͕ͱ͏͍͟͝·͢ʂ
Agenda
Agenda • mod_perlৼΓฦΓ • PHPৼΓฦΓ • mod_perl Hacks PHP •
Authen/Authz Hacks • Output Filter Hacks
Agenda • લճɺ༁͔ΒͣΓࠐΈ͗ͨ͢ͷͰ • 20ͰεϥΠυ90ຕ࡞ͬͨˠແཧ • ࠓճܰ͘ߦ͖·͢ • ʮmod_perlͱ͔Φϫίϯʯൃݴېࢭ
mod_perlৼΓฦΓ
mod_perlৼΓฦΓ • mod_perlPerl CGIͷߴԽͰ͖Δ • mod_perlͷਅApacheϞδϡʔϧͰ ग़དྷΔ༷ʑͳ͜ͱΛPerlͰॻ͚Δ͜ͱ • લճ(#5)ൃදͨ͠ʮmod_perlԹނ৽ʯ SlideshareͰެ։͍ͯ͠·͢
mod_perlৼΓฦΓ • ࠓճmod_perl2ͷΈͷ͓ • mod_perl1(Apache1.x)ͰωΠςΟϒͷ ϑΟϧλؔ࿈͕·ͩొલͳͷͰ… • ࠓճϑΟϧλؔ࿈ͷ͓͠·͢
PHPৼΓฦΓ
PHPৼΓฦΓ http://ja.wikipedia.org/wiki/PHP:_Hypertext_Preprocessor
PHPৼΓฦΓ • ITۀքͰجຊతͳ • ࢲୡPerl Monger!! ͜͜Hokkaido.pm!! • PHPιϑτΛ͏ͷߏΘͳ͍͚Ͳɺ தΛ͍͡Δ·Ͱ༨Γͨ͘͠ͳ͍
PHP͋Δ͋Δʁ • ൃͨ͠ΣϒΞϓϦ͕PHPͰɺطʹ ୭͔͕উखʹೲͪ͠Ό͍ͬͯΔ • ֖Λ։͚Δͱ࣮ͱ͔͕ςΩτա͗ • ͰɺPerl MongerͷԶ͕मਖ਼͢Μͷʁ •
PHPσόοάͱ͔Ϛδצ(ry
PHP͋Δ͋Δʁ •※ࠓͷ͓ϑΟΫγϣϯͰ͢(ͨͿΜ)
PHP͋Δ͋Δʁ •※େਓͷੈքͷḨࡧ͓߇͍͑ͩ͘͞
େͳࣄͳͷͰ • PHPͱ͍͏ݴޠΛdisͬͯΔ༁Ͱͳ͍ • ྑ͍ιϑτΣΞͨ͘͞Μ͋Γ·͢
PHPͷྑ࣭ιϑτ ͦͷଞ͍Ζ͍Ζʂ
ຊ • PHPͷએஔ͍ͱ͍ͯ… • PHPʹͳΔ͘खΛՃ͑ͣɺػೳΛՃ ͨ͠Γ͢ΔʹͲ͏͢Ε͍͍͔ • Ͱ͖ΕPerlͰग़དྷΕخ͍͠ • ͦ͜Ͱ…
mod_perl hacks PHP
mod_perl hacks PHP • PHP͕࣮ߦ͞ΕΔલޙʹmod_perlͰԿ͔ ϑοΫΛࠩ͠ࠐΊͳ͍͔ • PHPॲཧલʹೝূɾڐՄॲཧ • PHPॲཧޙʹग़ྗΛϑΟϧλ…ʑ
ॲཧϑΣʔζ:mod_perl2 PerlChildInitHandler PerlPostReadRequestHandler PerlInitHandler PerlTransHandler PerlMapToStorageHandler PerlHeaderParserHandler PerlAccessHandler PerlAuthenHandler PerlAuthzHandler
PerlTypeHandler PerlFixupHandler PerlFixupHandler PerlResponseHandler PerlLogHandler PerlCleanupHandler PerlChildExitHandler ※Apache2ʹݩʑରԠ͢ΔϑΣʔζ͕͋Γ·͢ / ※݁ߏলུ͕͋Γ·͢ɻҎԼΛࢀর http://perl.apache.org/docs/2.0/user/con fi g/con fi g.html
Apache2 / mod_perl2 ॲཧϑΣʔζ ※ʮPractical mod_perlʯΑΓൈਮ
Apache2 / mod_perl2 ॲཧϑΣʔζ
͜͜Ͱٙ • Q: PHPPerlResponseHandler͕ର Ԡ͢ΔApache2ϨεϙϯεϑΣʔζҎ֎ ͰԿ͔ົͳ͜ͱΛ͍ͯ͠ͳ͍ͷ͔ • A:͍ͯ͠ͳ͍Β͍͠(͠ͳ͍ͷ͕ϙϦγʔ) • PHPίΞͷ։ൃऀͷ୭͔͕ݴ͍ͬͯͨ
※ιʔεݟ͚ͭΒΕͳͯ͘͢Έ·ͤΜ
ͦΕͰຊ… • ͜ͷଞͷApache্Ͱಈ࡞͢ΔLL ϓϩάϥϜͰ௨༻͢Δ͔…Ͱ… • TomcatͷίωΫλͱ͔ṖͩΒ͚ • FastCGI / mod_{ଞͷݴޠ}
• ͳͷͰࠓճPHPʹݶ͓ͬͨʹ
Authen/Authz Hacks
Authen/Authz Hacks • PHPͷೝূ͕Ϛζ͍έʔε • php.iniͷઃఆ͕Ϛζ͍ • PHPͷsession_start()ͷҰ࿈ͷηο γϣϯؔ࿈ؔͷ͍ํ͕Ϛζ͍ •
ԿϚζ͘ͳͯ͘طଘͷೝূ͕͋Δ
Authen/Authz Hacks • php.inisession_*()ؔͷॾʑͷॲཧΛ σόοά͢Δ͘Β͍ͳΒ… • طʹଞαΠτͰPerlͰ࡞ͬͨطଘͷೝূ ͖αΠτ͕͋ΔͳΒ… • →PHPଆͷηογϣϯཧΛࣺͯͯɺ
γϯάϧαΠϯΦϯ(SSO)Մೳʹ
CookieͷಡΈॻ͖
CookieͷಡΈॻ͖ • sub handler { my $r = shift; ...
} આ໌লུ • Raw Cookie ΛಡΈॻ͖͢ΔϞδϡʔϧ HTTP::Cookies ͍Ζ͍Ζ͋Γ·͢ • Apache2 (libapreq) ʹ Apache2::Cookie APR::Request::Cookie ͷϞδϡʔϧ ͋Γ
AAA • ΞΫηείϯτϩʔϧɾೝূɾڐՄ • 3ͭͷσΟϨΫςΟϒ • PerlAccessHandler • PerlAuthenHandler •
PerlAuthzHandler
CPAN Module of Apache2::AuthCookie*
CPAN Module of Apache2::AuthCookie* • Apache2::AuthCookie ࠓͳ͓ਫ਼ྗత ʹϝϯςφϯε͞Ε͍ͯΔ • ࠓճApache2::AuthCookie
ͰσϞΛ࡞ͬ ͯΈΑ͏ͱࢥ͕ͬͨؒʹ߹Θͳ͔ͬͨ • ͢Έ·ͤΜ
Output Filter Hacks
Output Filter Hacks • PHPͷग़ྗͷॻ͖͑ • ApacheͷωΠςΟϒϑΟϧλͳͷͰɺ PHPͷob_*ܥઃఆҰؔແ͠
Output Filter Hacks • ߟ͑ΒΕΔ༻్ɿ • PHPͰॻ͖͖Εͳ͍ॲཧΛಠࣗϚʔΫ Ξοϓͷܗʹ͓͍ͯͯ͠PerlͰஔ • i-modeֆจࣈͷSoftbank͚ม
(Perlͷֆจࣈมٕज़๛Ͱߴ)
Output Filterͷॻ͖ํ • Filter ͷ߹ sub handler { ... }
$r (Request Object)Ͱͳ͘ɺ $f (Filter Object) ΛୈҰҾʹड͚औΔ • PerlOutputFilterHandler σΟϨΫςΟϒ
Output Filterͷॻ͖ํ <VirtualHost *:80> <FilesMatch “.*(html?|php)$”> PerlOutputFilterHandler \ MyApache2::FilterObfuscate </FilesMatch>
</VirtualHost>
Output Filterͷॻ͖ํ
DEMO
Filter͋Ε͜Ε • ύϑΥʔϚϯεೋͷ࣍ͱͯ͠ɺpipeత ͳॲཧͰྑ͍ͳΒApache2.1͔Βͷඪ४ Ϟδϡʔϧmod_ fi lter͕͋Γ·͢ • ݴޠΘͳ͍ɺͱ͍͏͔ ”*.html”
Λ pipeͰw3mʹͯ͠text/plainʹܗͯ͠ ฦ͢ͷܳͰ͖·͢
Filter͋Ε͜Ε
·ͱΊ
·ͱΊ • Apache্ͷPHPͰ͋Εɺॲཧͷલޙʹ mod_perlͰॲཧΛڬΉ͜ͱ͕Ͱ͖Δ • PHPϨεϙϯεϑΣʔζҎ֎Ͱ߇͑ ͳͷͰɺmod_perlΛࢥ͏ଘ͑Δ
࠷ޙʹ
࠷ޙʹ • Webʹmod_perlͷใຊʹগͳ͍ • mod_perl2ͱͳΔͱյ໓త • APR:: Apache2:: ModPerl:: ·ΘΓ
• ଞͷLLΑΓྺ࢙ͷݹ͍Perlݻ༗ͷʁ
ຊPerlվܭը • ʮຊPerlվܭըʯͱ͍͏ϨΨγʔ ͕͔࣌ͬͨPerlͷใݯΛ৽ͯ͠ ͍͘ࢼΈ͕͋ΔΑ͏Ͱ͢
ຊPerlվܭը http://d.hatena.ne.jp/syohex/20111110/1320938963
ຊPerlվܭը • WAFશظͰApache݈ࡏ • ࠓճͷΑ͏ͳγνϡΤʔγϣϯ͋Δ • ͍͟ͱ͍͏࣌ͷͨΊͷmod_perlใΛ ఏڙ͍ͨ͠
ຊPerlվܭը • ʮຊmod_perlվܭըʯΛ͍ͨ͠ • ຊޠͰmod_perl(1 and 2)ͷใΛൃ৴ ͍ͯ͘͠ϙʔλϧαΠτ࡞Λܭըத • τʔΫͰͤͳ͍ྔͷωλެ։
• ࢼΈϒϩάTwitterͰใࠂ͠·͢
ࢀߟจݙ • mod_perl2 User’s Guide (Onyx Neon 2007; http://modperl2book.org/)
͝ਗ਼ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠