perlfaq9 >
5.6.1
との差分
perlfaq9 5.6.1 と 5.14.1 の差分
| 1 | 1 | |
| 2 | 2 | =encoding euc-jp |
| 3 | 3 | |
| 4 | 4 | =head1 NAME |
| 5 | 5 | |
| 6 | 6 | =begin original |
| 7 | 7 | |
| 8 | perlfaq9 - Networking | |
| 8 | perlfaq9 - Networking | |
| 9 | 9 | |
| 10 | 10 | =end original |
| 11 | 11 | |
| 12 | perlfaq9 - ネットワーク | |
| 12 | perlfaq9 - ネットワーク | |
| 13 | 13 | |
| 14 | 14 | =head1 DESCRIPTION |
| 15 | 15 | |
| 16 | =begin original | |
| 17 | ||
| 18 | This section deals with questions related to networking, the internet, | |
| 19 | and a few on the web. | |
| 20 | ||
| 21 | =end original | |
| 22 | ||
| 16 | 23 | このセクションでは、ネットワーク、インターネット、web に関する |
| 17 | 24 | 質問を扱っています。 |
| 18 | 25 | |
| 19 | =head2 | |
| 26 | =head2 What is the correct form of response from a CGI script? | |
| 20 | 27 | |
| 21 | ( | |
| 28 | (CGI スクリプトからの返答の正しい形は?) | |
| 22 | (500 Server Errorになります)) | |
| 23 | 29 | |
| 24 | 30 | =begin original |
| 25 | 31 | |
| 26 | ||
| 32 | (Alan Flavell <flavell+www@a5.ph.gla.ac.uk> answers...) | |
| 27 | your problem isn't something simple that can be easily answered, you'll | |
| 28 | probably receive a courteous and useful reply to your question if you | |
| 29 | post it on comp.infosystems.www.authoring.cgi (if it's something to do | |
| 30 | with HTTP, HTML, or the CGI protocols). Questions that appear to be Perl | |
| 31 | questions but are really CGI ones that are posted to comp.lang.perl.misc | |
| 32 | may not be so well received. | |
| 33 | 33 | |
| 34 | 34 | =end original |
| 35 | 35 | |
| 36 | ||
| 36 | (Alan Flavell <flavell+www@a5.ph.gla.ac.uk> が答えます...) | |
| 37 | わかったのなら、(HTTP、HTMLやCGIプロトコルに関するものなら) | |
| 38 | comp.infosystems.www.authoring.cgiにポストすれば | |
| 39 | 有用なリプライが得られるでしょう。 | |
| 40 | Perlに関する質問のように見えていても、実はCGIに関するものだというものが | |
| 41 | comp.lang.perl.miscに投稿されることがありますが、回答はついていません。 | |
| 42 | 37 | |
| 43 | ||
| 38 | =begin original | |
| 44 | 39 | |
| 45 | CGI | |
| 40 | The Common Gateway Interface (CGI) specifies a software interface between | |
| 46 | | |
| 41 | a program ("CGI script") and a web server (HTTPD). It is not specific | |
| 42 | to Perl, and has its own FAQs and tutorials, and usenet group, | |
| 43 | comp.infosystems.www.authoring.cgi | |
| 47 | 44 | |
| 48 | ||
| 45 | =end original | |
| 49 | http://www.boutell.com/faq/ | |
| 50 | 46 | |
| 51 | | |
| 47 | The Common Gateway Interface (CGI) はプログラム("CGI スクリプト")と | |
| 52 | | |
| 48 | web サーバ (HTTPD) の間のソフトウェアインターフェースを定めています。 | |
| 49 | これは Perl 固有のものではないので、独自の FAQと独自のチュートリアル、 | |
| 50 | そして独自の usenet group である comp.infosystems.www.authoring.cgi が | |
| 51 | あります。 | |
| 53 | 52 | |
| 54 | ||
| 53 | =begin original | |
| 55 | http://www.w3.org/pub/WWW/Protocols/HTTP/ | |
| 56 | 54 | |
| 57 | ||
| 55 | The CGI specification is outlined in an informational RFC: | |
| 58 | ||
| 56 | http://www.ietf.org/rfc/rfc3875 | |
| 59 | http://www.w3.org/pub/WWW/MarkUp/ | |
| 60 | 57 | |
| 61 | ||
| 58 | =end original | |
| 62 | http://www.w3.org/CGI/ | |
| 63 | 59 | |
| 64 | ||
| 60 | CGI 仕様は RFC に概要が述べられています: | |
| 65 | ||
| 61 | http://www.ietf.org/rfc/rfc3875 | |
| 66 | 62 | |
| 63 | =begin original | |
| 64 | ||
| 65 | These Perl FAQs very selectively cover some CGI issues. However, Perl | |
| 66 | programmers are strongly advised to use the C<CGI.pm> module, to take care | |
| 67 | of the details for them. | |
| 68 | ||
| 69 | =end original | |
| 70 | ||
| 71 | これらの Perl FAQ はいくつかの CGI の問題についてとても抜粋して | |
| 72 | カバーしています。 | |
| 73 | しかし、これらの詳細に用心するために、Perl プログラマは C<CGI> モジュールを | |
| 74 | 使うことを強く忠告されます。 | |
| 75 | ||
| 76 | =begin original | |
| 77 | ||
| 78 | The similarity between CGI response headers (defined in the CGI | |
| 79 | specification) and HTTP response headers (defined in the HTTP | |
| 80 | specification, RFC2616) is intentional, but can sometimes be confusing. | |
| 81 | ||
| 82 | =end original | |
| 83 | ||
| 84 | (CGI 仕様に定義されている) CGI レスポンスヘッダと、(RFC2616 の HTTP 仕様で | |
| 85 | 定義されている) HTTP レスポンスヘッダの類似性は意図的なものですが、 | |
| 86 | 時々混乱を引き起こします。 | |
| 87 | ||
| 88 | =begin original | |
| 89 | ||
| 90 | The CGI specification defines two kinds of script: the "Parsed Header" | |
| 91 | script, and the "Non Parsed Header" (NPH) script. Check your server | |
| 92 | documentation to see what it supports. "Parsed Header" scripts are | |
| 93 | simpler in various respects. The CGI specification allows any of the | |
| 94 | usual newline representations in the CGI response (it's the server's | |
| 95 | job to create an accurate HTTP response based on it). So "\n" written in | |
| 96 | text mode is technically correct, and recommended. NPH scripts are more | |
| 97 | tricky: they must put out a complete and accurate set of HTTP | |
| 98 | transaction response headers; the HTTP specification calls for records | |
| 99 | to be terminated with carriage-return and line-feed; i.e., ASCII \015\012 | |
| 100 | written in binary mode. | |
| 101 | ||
| 102 | =end original | |
| 103 | ||
| 104 | CGI 仕様は 2 種類のスクリプトを定義しています: | |
| 105 | "Parsed Header" スクリプトと、"Non Parsed Header" (NPH) スクリプト。 | |
| 106 | 何をサポートしているかについてはサーバーのドキュメントをチェックして | |
| 107 | ください。 | |
| 108 | "Parsed Header" スクリプトは色々な側面においてより単純です。 | |
| 109 | CGI 仕様は CGI レスポンスとして一般的な改行表現のどれを使ってもよいことに | |
| 110 | なっています(そこから正確な HTTP レスポンスを作成するのはサーバの仕事です)。 | |
| 111 | 従って "\n" をテキストモードで書くのは技術的に正しく、推奨されています。 | |
| 112 | NPH スクリプトではより微妙です: ここでは完全に正確な HTTP トランザクション | |
| 113 | レスポンスヘッダを出力しなければなりません; HTTP 仕様はレコードが復帰と | |
| 114 | 改行(つまりバイナリモードで ASCII コードの \015\012 が書かれる)で | |
| 115 | 終端されていることを要求します。 | |
| 116 | ||
| 117 | =begin original | |
| 118 | ||
| 119 | Using C<CGI.pm> gives excellent platform independence, including EBCDIC | |
| 120 | systems. C<CGI.pm> selects an appropriate newline representation | |
| 121 | (C<$CGI::CRLF>) and sets binmode as appropriate. | |
| 122 | ||
| 123 | =end original | |
| 124 | ||
| 125 | C<CGI.pm> を使うことで、EBCDIC システムを含むすばらしいプラットフォーム | |
| 126 | 独立性が得られます。 | |
| 127 | C<CGI.pm> は適切な改行表現を選択し(C<$CGI::CRLF>)、binmode を適切にセットします。 | |
| 128 | ||
| 129 | =head2 My CGI script runs from the command line but not the browser. (500 Server Error) | |
| 130 | ||
| 131 | (私の CGI スクリプトはコマンドラインでは動くのだけど、ブラウザ上では動きません (500 Server Error になります)) | |
| 132 | ||
| 133 | =begin original | |
| 134 | ||
| 135 | (contributed by brian d foy) | |
| 136 | ||
| 137 | =end original | |
| 138 | ||
| 139 | (brian d foy によって寄贈されました) | |
| 140 | ||
| 141 | =begin original | |
| 142 | ||
| 143 | There are many things that might be wrong with your CGI program, and only | |
| 144 | some of them might be related to Perl. Try going through the troubleshooting | |
| 145 | guide on Perlmonks: | |
| 146 | ||
| 147 | =end original | |
| 148 | ||
| 149 | CGI プログラムが悪いかもしれないいくつかのことがあり、その一部だけが | |
| 150 | Perl に関連します。 | |
| 151 | Perlmonks によるトラブルシューティングを確認してみてください: | |
| 152 | ||
| 153 | http://www.perlmonks.org/?node_id=380424 | |
| 154 | ||
| 67 | 155 | =head2 How can I get better error messages from a CGI program? |
| 68 | 156 | |
| 69 | (CGIプログラムから、もっとまともなエラーメッセージを得るには?) | |
| 157 | (CGI プログラムから、もっとまともなエラーメッセージを得るには?) | |
| 70 | 158 | |
| 71 | 159 | =begin original |
| 72 | 160 | |
| 73 | Use the CGI::Carp module. It replaces C<warn> and C<die>, plus the | |
| 161 | Use the C<CGI::Carp> module. It replaces C<warn> and C<die>, plus the | |
| 74 | normal Carp modules C<carp>, C<croak>, and C<confess> functions with | |
| 162 | normal C<Carp> module's C<carp>, C<croak>, and C<confess> functions with | |
| 75 | 163 | more verbose and safer versions. It still sends them to the normal |
| 76 | 164 | server error log. |
| 77 | 165 | |
| 78 | 166 | =end original |
| 79 | 167 | |
| 80 | CGI::Carpモジュールを使いましょう。 | |
| 168 | C<CGI::Carp> モジュールを使いましょう。 | |
| 81 | ||
| 169 | このモジュールは C<warn> と C<die> の置き換えを行い、さらに通常の | |
| 82 | C<confess>といった関数をより饒舌で | |
| 170 | C<Carp> モジュールの C<carp>、C<croak>、C<confess> といった関数をより饒舌で | |
| 171 | 安全なものに置き換えます。 | |
| 83 | 172 | その出力は、サーバーの通常のエラーログに送られます。 |
| 84 | 173 | |
| 85 | ||
| 174 | use CGI::Carp; | |
| 86 | ||
| 175 | warn "This is a complaint"; | |
| 87 | ||
| 176 | die "But this one is serious"; | |
| 88 | 177 | |
| 89 | ||
| 178 | =begin original | |
| 90 | ||
| 180 | The following use of C<CGI::Carp> also redirects errors to a file of your choice, | |
| 181 | placed in a C<BEGIN> block to catch compile-time warnings as well: | |
| 182 | ||
| 183 | =end original | |
| 184 | ||
| 185 | 以下の C<CGI::Carp> の使用例では、エラーをあなたの選択したファイルへ | |
| 186 | リダイレクトし、コンパイル時の警告も同様に補足するため C<BEGIN> ブロックに | |
| 91 | 187 | 置いています: |
| 92 | 188 | |
| 93 | ||
| 189 | BEGIN { | |
| 94 | ||
| 190 | use CGI::Carp qw(carpout); | |
| 95 | ||
| 191 | open(LOG, ">>/var/local/cgi-logs/mycgi-log") | |
| 96 | ||
| 192 | or die "Unable to append to mycgi-log: $!\n"; | |
| 97 | ||
| 193 | carpout(*LOG); | |
| 98 | ||
| 194 | } | |
| 99 | 195 | |
| 100 | ||
| 196 | =begin original | |
| 197 | ||
| 198 | You can even arrange for fatal errors to go back to the client browser, | |
| 199 | which is nice for your own debugging, but might confuse the end user. | |
| 200 | ||
| 201 | =end original | |
| 202 | ||
| 203 | 深刻なエラーをクライアントのブラウザに戻すように変更することもできます。 | |
| 101 | 204 | これはあなたがデバッグするには良いでしょうが、エンドユーザーを |
| 102 | 205 | 混乱させてしまうかもしれません。 |
| 103 | 206 | |
| 104 | ||
| 207 | use CGI::Carp qw(fatalsToBrowser); | |
| 105 | ||
| 208 | die "Bad error here"; | |
| 106 | 209 | |
| 107 | 210 | =begin original |
| 108 | 211 | |
| 109 | 212 | Even if the error happens before you get the HTTP header out, the module |
| 110 | 213 | will try to take care of this to avoid the dreaded server 500 errors. |
| 111 | 214 | Normal warnings still go out to the server error log (or wherever |
| 112 | 215 | you've sent them with C<carpout>) with the application name and date |
| 113 | 216 | stamp prepended. |
| 114 | 217 | |
| 115 | 218 | =end original |
| 116 | 219 | |
| 117 | あなたがHTTPヘッダーを受け取るよりも前にエラーが起こったとしても、 | |
| 220 | あなたが HTTP ヘッダーを受け取るよりも前にエラーが起こったとしても、 | |
| 118 | モジュールはサーバーの500エラーを避けるためにそのエラーを取り扱おうと | |
| 221 | モジュールはサーバーの 500 エラーを避けるためにそのエラーを取り扱おうと | |
| 119 | 222 | するでしょう。 |
| 120 | 通常の警告はサーバーのエラーログ(もしくはあなたがC<carpout>で指定した場所)に | |
| 223 | 通常の警告はサーバーのエラーログ(もしくはあなたが C<carpout> で指定した場所)に | |
| 121 | 224 | アプリケーションの名前と日付を伴って送られます。 |
| 122 | 225 | |
| 123 | 226 | =head2 How do I remove HTML from a string? |
| 124 | 227 | |
| 125 | (ある文字列からHTMLを取り除くには?) | |
| 228 | (ある文字列から HTML を取り除くには?) | |
| 126 | 229 | |
| 127 | 230 | =begin original |
| 128 | 231 | |
| 129 | The most correct way (albeit not the fastest) is to use HTML::Parser | |
| 232 | The most correct way (albeit not the fastest) is to use C<HTML::Parser> | |
| 130 | 233 | from CPAN. Another mostly correct |
| 131 | way is to use HTML::FormatText which not only removes HTML but also | |
| 234 | way is to use C<HTML::FormatText> which not only removes HTML but also | |
| 132 | 235 | attempts to do a little simple formatting of the resulting plain text. |
| 133 | 236 | |
| 134 | 237 | =end original |
| 135 | 238 | |
| 136 | (最速ではありませんが)最も正しい方法は、CPANにあるHTML::Parserを | |
| 239 | (最速ではありませんが)最も正しい方法は、CPAN にある C<HTML::Parser> を | |
| 137 | 240 | 使うというものです。 |
| 138 | もう一つのまず正しい方法は、HTML::FormatText を使って HTML を | |
| 241 | もう一つのまず正しい方法は、C<HTML::FormatText> を使って HTML を | |
| 139 | 242 | 取り除くだけでなく、結果のプレーンテキストを簡単に整形することです。 |
| 140 | 243 | |
| 141 | ||
| 244 | =begin original | |
| 245 | ||
| 246 | Many folks attempt a simple-minded regular expression approach, like | |
| 247 | C<< s/<.*?>//g >>, but that fails in many cases because the tags | |
| 248 | may continue over line breaks, they may contain quoted angle-brackets, | |
| 249 | or HTML comments may be present. Plus, folks forget to convert | |
| 250 | entities--like C<<> for example. | |
| 251 | ||
| 252 | =end original | |
| 253 | ||
| 254 | 多くの人が、C<< s/<.*?>//g >> のような単純な(simple-minded)正規表現を | |
| 142 | 255 | 使ったアプローチを行おうとするのですが、これは多くの場合 |
| 143 | 失敗していまいます。 | |
| 256 | 失敗していまいます。 | |
| 257 | なぜなら、タグは行をまたがって継続する可能性があり、 | |
| 144 | 258 | クォートされたアングルブラケットを含む可能性があり、 |
| 145 | 259 | HTML のコメントがあるかもしれないからです。 |
| 146 | さらに、人々はC<<>のようなエンティティを変換することを忘れてしまうのです。 | |
| 260 | さらに、人々は C<<> のようなエンティティを変換することを忘れてしまうのです。 | |
| 147 | 261 | |
| 148 | ||
| 262 | =begin original | |
| 263 | ||
| 264 | Here's one "simple-minded" approach, that works for most files: | |
| 265 | ||
| 266 | =end original | |
| 267 | ||
| 268 | 以下の例は「単純な」アプローチで、ほとんどのファイルに対しては | |
| 149 | 269 | うまくいきます: |
| 150 | 270 | |
| 151 | ||
| 271 | #!/usr/bin/perl -p0777 | |
| 152 | ||
| 272 | s/<(?:[^>'"]*|(['"]).*?\g1)*>//gs | |
| 153 | 273 | |
| 274 | =begin original | |
| 275 | ||
| 276 | If you want a more complete solution, see the 3-stage striphtml | |
| 277 | program in | |
| 278 | http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz | |
| 279 | . | |
| 280 | ||
| 281 | =end original | |
| 282 | ||
| 154 | 283 | もし、より完璧な解決策を求めているのなら、 |
| 155 | http://www.p | |
| 284 | http://www.cpan.org/authors/Tom_Christiansen/scripts/striphtml.gz | |
| 156 | 285 | にある 3-stage striphtml プログラムを参照してみてください。 |
| 157 | 286 | |
| 158 | 287 | =begin original |
| 159 | 288 | |
| 160 | 289 | Here are some tricky cases that you should think about when picking |
| 161 | 290 | a solution: |
| 162 | 291 | |
| 163 | 292 | =end original |
| 164 | 293 | |
| 165 | 294 | 以下に挙げたのは、あなたが自分でやろうとしたときに |
| 166 | 295 | 考慮すべきであろうトリッキーな例です: |
| 167 | 296 | |
| 168 | ||
| 297 | <IMG SRC = "foo.gif" ALT = "A > B"> | |
| 169 | 298 | |
| 170 | ||
| 299 | <IMG SRC = "foo.gif" | |
| 171 | 300 | ALT = "A > B"> |
| 172 | 301 | |
| 173 | ||
| 302 | <!-- <A comment> --> | |
| 174 | 303 | |
| 175 | ||
| 304 | <script>if (a<b && a>c)</script> | |
| 176 | 305 | |
| 177 | ||
| 306 | <# Just data #> | |
| 178 | 307 | |
| 179 | ||
| 308 | <![INCLUDE CDATA [ >>>>>>>>>>>> ]]> | |
| 180 | 309 | |
| 181 | 310 | =begin original |
| 182 | 311 | |
| 183 | 312 | If HTML comments include other tags, those solutions would also break |
| 184 | 313 | on text like this: |
| 185 | 314 | |
| 186 | 315 | =end original |
| 187 | 316 | |
| 188 | 以下のテキストのようにHTMLのコメントが他のタグを含んでいた場合には、 | |
| 317 | 以下のテキストのように HTML のコメントが他のタグを含んでいた場合には、 | |
| 189 | 318 | せっかくの対応策もダメにしてしまうかもしれません: |
| 190 | 319 | |
| 191 | ||
| 320 | <!-- This section commented out. | |
| 192 | ||
| 321 | <B>You can't see me!</B> | |
| 193 | ||
| 322 | --> | |
| 194 | 323 | |
| 195 | 324 | =head2 How do I extract URLs? |
| 196 | 325 | |
| 197 | (URLの展開を行うには?) | |
| 326 | (URL の展開を行うには?) | |
| 198 | 327 | |
| 199 | ||
| 328 | =begin original | |
| 200 | 329 | |
| 201 | | |
| 330 | You can easily extract all sorts of URLs from HTML with | |
| 202 | ||
| 331 | C<HTML::SimpleLinkExtor> which handles anchors, images, objects, | |
| 203 | | |
| 332 | frames, and many other tags that can contain a URL. If you need | |
| 204 | ||
| 333 | anything more complex, you can create your own subclass of | |
| 205 | ||
| 334 | C<HTML::LinkExtor> or C<HTML::Parser>. You might even use | |
| 206 | ||
| 335 | C<HTML::SimpleLinkExtor> as an example for something specifically | |
| 207 | | |
| 336 | suited to your needs. | |
| 208 | 337 | |
| 338 | =end original | |
| 339 | ||
| 340 | アンカー、イメージ、オブジェクト、フレーム、およびその他の URL を含む | |
| 341 | 多くのタグを扱える C<HTML::SimpleLinkExtor> を使って、HTML からあらゆる | |
| 342 | 種類の URL を簡単に抽出できます。 | |
| 343 | もしもっと複雑なものが必要なら、自分自身で C<HTML::LinkExtor> や | |
| 344 | C<HTML::Parser> のサブクラスを作れます。 | |
| 345 | 例えば、あなたの用途に特に適用するなら、C<HTML::SimpleLinkExtor> を | |
| 346 | 使うこともできます。 | |
| 347 | ||
| 209 | 348 | =begin original |
| 210 | 349 | |
| 211 | ||
| 350 | You can use C<URI::Find> to extract URLs from an arbitrary text document. | |
| 212 | bases, deal with HTML comments, deal with HREF and NAME attributes | |
| 213 | in the same tag, understand extra qualifiers like TARGET, or accept | |
| 214 | URLs themselves as arguments. It also runs about 100x faster than a | |
| 215 | more "complete" solution using the LWP suite of modules, such as the | |
| 216 | http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz program. | |
| 217 | 351 | |
| 218 | 352 | =end original |
| 219 | 353 | |
| 220 | ||
| 354 | 任意のテキスト文書から URL を抽出するためには、C<URI::Find> が使えます。 | |
| 221 | 同じタグにあるHREFやNAMEといったアトリビュートを扱うことができませんし、 | |
| 222 | TARGET のような追加の修飾子を理解せず、 | |
| 223 | URL自身を引数として受け取ることができません。 | |
| 224 | これは | |
| 225 | http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz | |
| 226 | のような、LWPスイートにあるモジュールを使っている、より“完全な” | |
| 227 | 解決策よりも百倍の早さで実行されます。 | |
| 228 | 355 | |
| 356 | =begin original | |
| 357 | ||
| 358 | Less complete solutions involving regular expressions can save | |
| 359 | you a lot of processing time if you know that the input is simple. One | |
| 360 | solution from Tom Christiansen runs 100 times faster than most | |
| 361 | module-based approaches but only extracts URLs from anchors where the first | |
| 362 | attribute is HREF and there are no other attributes. | |
| 363 | ||
| 364 | =end original | |
| 365 | ||
| 366 | もし入力が単純であることが分かっているなら、正規表現を使ったより不完全な | |
| 367 | 解法によって多くの処理時間を節約できます。 | |
| 368 | Tom Christiansen による一つの解法は、モジュールを使った手法よりも 100 倍 | |
| 369 | 速いですが、最初の属性が HREF で、その他の属性がないアンカーの URL のみを | |
| 370 | 抽出します。 | |
| 371 | ||
| 372 | #!/usr/bin/perl -n00 | |
| 373 | # qxurl - tchrist@perl.com | |
| 374 | print "$2\n" while m{ | |
| 375 | < \s* | |
| 376 | A \s+ HREF \s* = \s* (["']) (.*?) \g1 | |
| 377 | \s* > | |
| 378 | }gsix; | |
| 379 | ||
| 229 | 380 | =head2 How do I download a file from the user's machine? How do I open a file on another machine? |
| 230 | 381 | |
| 231 | (ユーザーのマシンからファイルをダウンロードするには? | |
| 382 | (ユーザーのマシンからファイルをダウンロードするには? 別のマシンにあるファイルをオープンするには?) | |
| 232 | 別のマシンにあるファイルをオープンするには?) | |
| 233 | 383 | |
| 234 | ||
| 384 | =begin original | |
| 385 | ||
| 386 | In this case, download means to use the file upload feature of HTML | |
| 387 | forms. You allow the web surfer to specify a file to send to your web | |
| 388 | server. To you it looks like a download, and to the user it looks | |
| 389 | like an upload. No matter what you call it, you do it with what's | |
| 390 | known as B<multipart/form-data> encoding. The C<CGI.pm> module (which | |
| 391 | comes with Perl as part of the Standard Library) supports this in the | |
| 392 | C<start_multipart_form()> method, which isn't the same as the C<startform()> | |
| 393 | method. | |
| 394 | ||
| 395 | =end original | |
| 396 | ||
| 397 | この場合、ダウンロードというのは HTML フォームのファイルアップロード機能を | |
| 398 | 使うということを意味します。 | |
| 399 | Web サーファーに、Web サーバーに送るファイルを指定できるようにします。 | |
| 400 | あなたにとってダウンロードに見えるものは、ユーザーにとってはアップロードに | |
| 401 | 見えます。 | |
| 402 | 何と呼ぶかには関わらず、B<multipart/form-data> | |
| 235 | 403 | エンコーディングとして知られているものを使うことができるでしょう。 |
| 236 | CGI.pmモジュール( | |
| 404 | C<CGI.pm> モジュール(標準ライブラリになっています)はこれを | |
| 237 | ||
| 405 | C<start_multipart_form()> という | |
| 406 | C<starform()> メソッドとは異なるメソッドでサポートしています。 | |
| 238 | 407 | |
| 239 | = | |
| 408 | =begin original | |
| 240 | 409 | |
| 241 | ||
| 410 | See the section in the C<CGI.pm> documentation on file uploads for code | |
| 411 | examples and details. | |
| 242 | 412 | |
| 413 | =end original | |
| 414 | ||
| 415 | コードのサンプルと詳細については、C<CGI.pm> の文書のファイルアップロードの | |
| 416 | 章を参照してください。 | |
| 417 | ||
| 418 | =head2 How do I make an HTML pop-up menu with Perl? | |
| 419 | ||
| 420 | (Perl で HTML のポップアップメニューを作るには?) | |
| 421 | ||
| 243 | 422 | =begin original |
| 244 | 423 | |
| 245 | ||
| 424 | (contributed by brian d foy) | |
| 246 | module (available from CPAN) supports this widget, as well as many | |
| 247 | others, including some that it cleverly synthesizes on its own. | |
| 248 | 425 | |
| 249 | 426 | =end original |
| 250 | 427 | |
| 251 | ||
| 428 | (brian d foy によって寄贈されました) | |
| 252 | CGI.pmモジュール(CPANから入手可能です)はこのウィジェットを他の多くのものと同様、 | |
| 253 | 独自のメニューを器用に統合しているものを含めてサポートしています。 | |
| 254 | 429 | |
| 430 | =begin original | |
| 255 | 431 | |
| 432 | The C<CGI.pm> module (which comes with Perl) has functions to create | |
| 433 | the HTML form widgets. See the C<CGI.pm> documentation for more | |
| 434 | examples. | |
| 435 | ||
| 436 | =end original | |
| 437 | ||
| 438 | C<CGI.pm> モジュール(標準配布です)には HTML フォームウィジェットを作るための | |
| 439 | 関数があります。 | |
| 440 | 更なる例については C<CGI.pm> の文書を参照してください。 | |
| 441 | ||
| 442 | use CGI qw/:standard/; | |
| 443 | print header, | |
| 444 | start_html('Favorite Animals'), | |
| 445 | ||
| 446 | start_form, | |
| 447 | "What's your favorite animal? ", | |
| 448 | popup_menu( | |
| 449 | -name => 'animal', | |
| 450 | -values => [ qw( Llama Alpaca Camel Ram ) ] | |
| 451 | ), | |
| 452 | submit, | |
| 453 | ||
| 454 | end_form, | |
| 455 | end_html; | |
| 456 | ||
| 256 | 457 | =head2 How do I fetch an HTML file? |
| 257 | 458 | |
| 258 | (HTMLファイルをフェッチするには?) | |
| 459 | (HTML ファイルをフェッチするには?) | |
| 259 | 460 | |
| 260 | ||
| 461 | =begin original | |
| 261 | インストールしているとすれば、次のようなものです: | |
| 262 | 462 | |
| 263 | ||
| 463 | (contributed by brian d foy) | |
| 264 | $text_data = `lynx -dump $url`; | |
| 265 | 464 | |
| 465 | =end original | |
| 466 | ||
| 467 | (brian d foy によって寄贈されました) | |
| 468 | ||
| 266 | 469 | =begin original |
| 267 | 470 | |
| 268 | ||
| 471 | Use the libwww-perl distribution. The C<LWP::Simple> module can fetch web | |
| 269 | ||
| 472 | resources and give their content back to you as a string: | |
| 270 | through proxies: | |
| 271 | 473 | |
| 272 | 474 | =end original |
| 273 | 475 | |
| 274 | ||
| 476 | libwww-perl ディストリビューションを使ってください。 | |
| 275 | ||
| 477 | C<LWP::Simple> はウェブ上のリソースをフェッチして、その内容を文字列として | |
| 276 | ||
| 478 | 返します: | |
| 277 | 479 | |
| 278 | | |
| 480 | use LWP::Simple qw(get); | |
| 279 | use LWP::Simple; | |
| 280 | $content = get($URL); | |
| 281 | 481 | |
| 282 | | |
| 482 | my $html = get( "http://www.example.com/index.html" ); | |
| 283 | use LWP::Simple; | |
| 284 | getprint "http://www.linpro.no/lwp/"; | |
| 285 | 483 | |
| 286 | | |
| 484 | =begin original | |
| 287 | # HTML-Treeパッケージも必要です。 | |
| 288 | use LWP::Simple; | |
| 289 | use HTML::Parser; | |
| 290 | use HTML::FormatText; | |
| 291 | my ($html, $ascii); | |
| 292 | $html = get("http://www.perl.com/"); | |
| 293 | defined $html | |
| 294 | or die "Can't fetch HTML from http://www.perl.com/"; | |
| 295 | $ascii = HTML::FormatText->new->format(parse_html($html)); | |
| 296 | print $ascii; | |
| 297 | 485 | |
| 486 | It can also store the resource directly in a file: | |
| 487 | ||
| 488 | =end original | |
| 489 | ||
| 490 | リソースを直接ファイルに保存することもできます: | |
| 491 | ||
| 492 | use LWP::Simple qw(getstore); | |
| 493 | ||
| 494 | getstore( "http://www.example.com/index.html", "foo.html" ); | |
| 495 | ||
| 496 | =begin original | |
| 497 | ||
| 498 | If you need to do something more complicated, you can use | |
| 499 | C<LWP::UserAgent> module to create your own user-agent (e.g. browser) | |
| 500 | to get the job done. If you want to simulate an interactive web | |
| 501 | browser, you can use the C<WWW::Mechanize> module. | |
| 502 | ||
| 503 | =end original | |
| 504 | ||
| 505 | もっと複雑なことをする必要がある場合は、仕事を行うための独自の | |
| 506 | ユーザーエージェント(例えばブラウザ)を作るために | |
| 507 | C<LWP::UserAgent> モジュールを使えます。 | |
| 508 | 対話的なウェブブラウザをシミュレートしたい場合は、 | |
| 509 | C<WWW::Mechanize> モジュールが使えます。 | |
| 510 | ||
| 298 | 511 | =head2 How do I automate an HTML form submission? |
| 299 | 512 | |
| 300 | (HTMLフォームの処理を自動化するには?) | |
| 513 | (HTML フォームの処理を自動化するには?) | |
| 301 | 514 | |
| 302 | ||
| 515 | =begin original | |
| 303 | さらにC<query_form>メソッドを使ってフォームをエンコードします: | |
| 304 | 516 | |
| 305 | | |
| 517 | If you are doing something complex, such as moving through many pages | |
| 306 | use | |
| 518 | and forms or a web site, you can use C<WWW::Mechanize>. See its | |
| 519 | documentation for all the details. | |
| 307 | 520 | |
| 308 | ||
| 521 | =end original | |
| 309 | $url->query_form(module => 'DB_File', readme => 1); | |
| 310 | $content = get($url); | |
| 311 | 522 | |
| 312 | ||
| 523 | もし、複数のページとフォームや web サイトを移動するような、複雑なことを | |
| 524 | しようとしているなら、C<WWW::Mechanize> が使えます。 | |
| 525 | 全ての詳細についてはこれのドキュメントを参照してください。 | |
| 526 | ||
| 527 | =begin original | |
| 528 | ||
| 529 | If you're submitting values using the GET method, create a URL and encode | |
| 530 | the form using the C<query_form> method: | |
| 531 | ||
| 532 | =end original | |
| 533 | ||
| 534 | GET メソッドを使って値を処理しているのであれば、URL を作って、 | |
| 535 | さらに C<query_form> メソッドを使ってフォームをエンコードします: | |
| 536 | ||
| 537 | use LWP::Simple; | |
| 538 | use URI::URL; | |
| 539 | ||
| 540 | my $url = url('http://www.perl.com/cgi-bin/cpan_mod'); | |
| 541 | $url->query_form(module => 'DB_File', readme => 1); | |
| 542 | $content = get($url); | |
| 543 | ||
| 544 | =begin original | |
| 545 | ||
| 546 | If you're using the POST method, create your own user agent and encode | |
| 547 | the content appropriately. | |
| 548 | ||
| 549 | =end original | |
| 550 | ||
| 551 | POST メソッドを使っているのであれば、自分用のエージェントを作成して | |
| 313 | 552 | コンテンツを適切にエンコードしてやります。 |
| 314 | 553 | |
| 315 | ||
| 554 | use HTTP::Request::Common qw(POST); | |
| 316 | ||
| 555 | use LWP::UserAgent; | |
| 317 | 556 | |
| 318 | ||
| 557 | $ua = LWP::UserAgent->new(); | |
| 319 | ||
| 558 | my $req = POST 'http://www.perl.com/cgi-bin/cpan_mod', | |
| 320 | ||
| 559 | [ module => 'DB_File', readme => 1 ]; | |
| 321 | ||
| 560 | $content = $ua->request($req)->as_string; | |
| 322 | 561 | |
| 323 | =head2 | |
| 562 | =head2 How do I decode or create those %-encodings on the web? | |
| 563 | X<URI> X<CGI.pm> X<CGI> X<URI::Escape> X<RFC 2396> | |
| 324 | 564 | |
| 325 | 565 | (web上で %-encodings をデコードしたり生成したりするには?) |
| 326 | 566 | |
| 327 | 567 | =begin original |
| 328 | 568 | |
| 329 | ||
| 569 | (contributed by brian d foy) | |
| 330 | that comes with perl, or some other equivalent module. The CGI module | |
| 331 | automatically decodes queries for you, and provides an escape() | |
| 332 | function to handle encoding. | |
| 333 | 570 | |
| 334 | 571 | =end original |
| 335 | 572 | |
| 336 | ||
| 573 | (brian d foy によって寄贈されました) | |
| 337 | または等価なモジュールを使うべきです。 | |
| 338 | CGI モジュールは自動的にクエリをデコードし、escape() 関数で | |
| 339 | エンコードもできます。 | |
| 340 | 574 | |
| 341 | 575 | =begin original |
| 342 | 576 | |
| 343 | The | |
| 577 | Those C<%> encodings handle reserved characters in URIs, as described | |
| 344 | ||
| 578 | in RFC 2396, Section 2. This encoding replaces the reserved character | |
| 579 | with the hexadecimal representation of the character's number from | |
| 580 | the US-ASCII table. For instance, a colon, C<:>, becomes C<%3A>. | |
| 345 | 581 | |
| 346 | 582 | =end original |
| 347 | 583 | |
| 348 | ||
| 584 | これらの C<%> 符号化は RFC 2396 の 2 章に記述されている、 | |
| 349 | ||
| 585 | URI として予約されている文字を扱います。 | |
| 586 | この符号化は予約文字を、その文字の番号の 16 進表現に | |
| 587 | US-ASCII テーブルを使って置き換えます。 | |
| 588 | 例えば、コロン (C<:>) は C<%3A> になります。 | |
| 350 | 589 | |
| 351 | ||
| 590 | =begin original | |
| 352 | 591 | |
| 353 | | |
| 592 | In CGI scripts, you don't have to worry about decoding URIs if you are | |
| 593 | using C<CGI.pm>. You shouldn't have to process the URI yourself, | |
| 594 | either on the way in or the way out. | |
| 354 | 595 | |
| 596 | =end original | |
| 597 | ||
| 598 | CGI スクリプトでは、C<CGI.pm> を使っているなら URL のデコードについて | |
| 599 | 気にする必要はありません。 | |
| 600 | エンコードにしてもデコードにしても、URI を自分で処理する必要はないはずです。 | |
| 601 | ||
| 355 | 602 | =begin original |
| 356 | 603 | |
| 357 | ||
| 604 | If you have to encode a string yourself, remember that you should | |
| 358 | ||
| 605 | never try to encode an already-composed URI. You need to escape the | |
| 359 | ||
| 606 | components separately then put them together. To encode a string, you | |
| 360 | ||
| 607 | can use the C<URI::Escape> module. The C<uri_escape> function | |
| 608 | returns the escaped string: | |
| 361 | 609 | |
| 362 | 610 | =end original |
| 363 | 611 | |
| 364 | し | |
| 612 | もし文字列を自分でエンコードする必要があるなら、 | |
| 365 | ||
| 613 | 決してすでに構成された URI をエンコードするべきではないことを | |
| 366 | ||
| 614 | 忘れないでください。 | |
| 367 | ||
| 615 | 要素を別々にエスケープして、それから全てを合わせます。 | |
| 368 | ||
| 616 | 文字列をエンコードするには、C<URI::Escape> モジュールが使えます。 | |
| 369 | ||
| 617 | C<uri_escape> 関数はエスケープされた文字列を返します: | |
| 370 | 618 | |
| 619 | my $original = "Colon : Hash # Percent %"; | |
| 620 | ||
| 621 | my $escaped = uri_escape( $original ); | |
| 622 | ||
| 623 | print "$escaped\n"; # 'Colon%20%3A%20Hash%20%23%20Percent%20%25' | |
| 624 | ||
| 371 | 625 | =begin original |
| 372 | 626 | |
| 373 | ||
| 627 | To decode the string, use the C<uri_unescape> function: | |
| 374 | regexp for breaking any arbitrary URI into components (Appendix B). | |
| 375 | 628 | |
| 376 | 629 | =end original |
| 377 | 630 | |
| 378 | ||
| 631 | 文字列をデコードするには、C<uri_unescape> 関数を使います: | |
| 379 | 任意の URI をコンポーネントに分割するための正規表現(Appendix B)を含みます。 | |
| 380 | 632 | |
| 381 | ||
| 633 | my $unescaped = uri_unescape( $escaped ); | |
| 382 | 634 | |
| 383 | ||
| 635 | print $unescaped; # back to original | |
| 384 | 636 | |
| 385 | 637 | =begin original |
| 386 | 638 | |
| 387 | ||
| 639 | If you wanted to do it yourself, you simply need to replace the | |
| 388 | ||
| 640 | reserved characters with their encodings. A global substitution | |
| 389 | ||
| 641 | is one way to do it: | |
| 390 | 642 | |
| 391 | 643 | =end original |
| 392 | 644 | |
| 393 | ||
| 645 | もしこれを自分でするなら、単に予約文字をエンコードされた物に置き換えます。 | |
| 394 | ||
| 646 | 全体を一度に変換するなら、以下のようにします: | |
| 395 | 送ることです: | |
| 396 | 647 | |
| 397 | | |
| 648 | # encode | |
| 649 | $string =~ s/([^^A-Za-z0-9\-_.!~*'()])/ sprintf "%%%0x", ord $1 /eg; | |
| 398 | 650 | |
| 651 | #decode | |
| 652 | $string =~ s/%([A-Fa-f\d]{2})/chr hex $1/eg; | |
| 653 | ||
| 654 | =head2 How do I redirect to another page? | |
| 655 | ||
| 656 | (別のページにリダイレクトするには?) | |
| 657 | ||
| 399 | 658 | =begin original |
| 400 | 659 | |
| 401 | ||
| 660 | Specify the complete URL of the destination (even if it is on the same | |
| 402 | ||
| 661 | server). This is one of the two different kinds of CGI "Location:" | |
| 662 | responses which are defined in the CGI specification for a Parsed Headers | |
| 663 | script. The other kind (an absolute URLpath) is resolved internally to | |
| 664 | the server without any HTTP redirection. The CGI specifications do not | |
| 665 | allow relative URLs in either case. | |
| 403 | 666 | |
| 404 | 667 | =end original |
| 405 | 668 | |
| 406 | ||
| 669 | (たとえ同じサーバでも)宛て先の完全な URL を指定してください。 | |
| 407 | ||
| 670 | これは Parsed Headers スクリプトとして CGI 仕様に定義された二つの異なった | |
| 408 | ||
| 671 | CGI "Location:" レスポンスのうちの一つです。 | |
| 409 | | |
| 672 | その他の種類 (絶対 URL パス) は HTTP リダイレクトなしにサーバによって | |
| 410 | ||
| 673 | 内部的に解決されます。 | |
| 411 | | |
| 674 | CGI 仕様ではどちらの場合でも相対 URL は認められていません。 | |
| 412 | 675 | |
| 413 | 676 | =begin original |
| 414 | 677 | |
| 415 | ||
| 678 | Use of C<CGI.pm> is strongly recommended. This example shows redirection | |
| 416 | i | |
| 679 | with a complete URL. This redirection is handled by the web browser. | |
| 417 | 680 | |
| 418 | 681 | =end original |
| 419 | 682 | |
| 420 | ||
| 683 | C<CGI.pm> を使うことを強くお勧めします。 | |
| 421 | ||
| 684 | この例では完全な URL へのリダイレクトを行います。 | |
| 685 | このリダイレクトは web ブラウザによって扱われます。 | |
| 422 | 686 | |
| 423 | | |
| 687 | use CGI qw/:standard/; | |
| 424 | Location: http://www.domain.com/newpage | |
| 425 | Window-target: <FrameName> | |
| 426 | 688 | |
| 427 | | |
| 689 | my $url = 'http://www.cpan.org/'; | |
| 690 | print redirect($url); | |
| 428 | 691 | |
| 429 | 692 | =begin original |
| 430 | 693 | |
| 431 | T | |
| 694 | This example shows a redirection with an absolute URLpath. This | |
| 432 | re | |
| 695 | redirection is handled by the local web server. | |
| 433 | received by the client browser. Except for NPH scripts, though, that | |
| 434 | local newline should get translated by your server into standard form, | |
| 435 | so you shouldn't have a problem here, even if you are stuck on MacOS. | |
| 436 | Everybody else probably won't even notice. | |
| 437 | 696 | |
| 438 | 697 | =end original |
| 439 | 698 | |
| 440 | ||
| 699 | この例では絶対 URL パスへのリダイレクトを行います。 | |
| 441 | ||
| 700 | このリダイレクトはローカルの web サーバによって行われます。 | |
| 442 | しかし、NPH スクリプトを除いて、このようなローカルな改行は | |
| 443 | サーバーによって標準的な形式に変換されることが多いので、 | |
| 444 | MacOS ではまっていた場合でも問題にはならないことが多いでしょう。 | |
| 445 | それ以外ではおそらく誰も気付きすらしないでしょう。 | |
| 446 | 701 | |
| 702 | my $url = '/CPAN/index.html'; | |
| 703 | print redirect($url); | |
| 704 | ||
| 705 | =begin original | |
| 706 | ||
| 707 | But if coded directly, it could be as follows (the final "\n" is | |
| 708 | shown separately, for clarity), using either a complete URL or | |
| 709 | an absolute URLpath. | |
| 710 | ||
| 711 | =end original | |
| 712 | ||
| 713 | しかし、直接コーディングするなら、完全な URL か絶対 URLpath を使って、 | |
| 714 | 以下のようになります(最後の "\n" は明確化するために分けて表示しています)。 | |
| 715 | ||
| 716 | print "Location: $url\n"; # CGI response header | |
| 717 | print "\n"; # end of headers | |
| 718 | ||
| 447 | 719 | =head2 How do I put a password on my web pages? |
| 448 | 720 | |
| 449 | (私のwebぺージでパスワードを入力するには?) | |
| 721 | (私の web ぺージでパスワードを入力するには?) | |
| 450 | 722 | |
| 451 | ||
| 723 | =begin original | |
| 452 | 必要があるでしょうし、先に例示した他のFAQの幾つかをチェックする | |
| 453 | 必要もあるでしょう。 | |
| 454 | 724 | |
| 725 | To enable authentication for your web server, you need to configure | |
| 726 | your web server. The configuration is different for different sorts | |
| 727 | of web servers--apache does it differently from iPlanet which does | |
| 728 | it differently from IIS. Check your web server documentation for | |
| 729 | the details for your particular server. | |
| 730 | ||
| 731 | =end original | |
| 732 | ||
| 733 | 利用する Web サーバーで認証を有効にするには、Web サーバーを設定することが | |
| 734 | 必要です。 | |
| 735 | web サーバの種類によって設定は異なります -- apache は iPlanet とは異なり、 | |
| 736 | また IIS とも異なります。 | |
| 737 | 特定のサーバーに関する詳細については、そのサーバーのドキュメントを | |
| 738 | チェックしてください。 | |
| 739 | ||
| 455 | 740 | =head2 How do I edit my .htpasswd and .htgroup files with Perl? |
| 456 | 741 | |
| 457 | (Perlを使って.htpasswdや.htgroupといったファイルを編集するには?) | |
| 742 | (Perl を使って .htpasswd や .htgroup といったファイルを編集するには?) | |
| 458 | 743 | |
| 459 | ||
| 744 | =begin original | |
| 745 | ||
| 746 | The C<HTTPD::UserAdmin> and C<HTTPD::GroupAdmin> modules provide a | |
| 747 | consistent OO interface to these files, regardless of how they're | |
| 748 | stored. Databases may be text, dbm, Berkeley DB or any database with | |
| 749 | a DBI compatible driver. C<HTTPD::UserAdmin> supports files used by the | |
| 750 | "Basic" and "Digest" authentication schemes. Here's an example: | |
| 751 | ||
| 752 | =end original | |
| 753 | ||
| 754 | C<HTTPD::UserAdmin> モジュールと C<HTTPD::GroupAdmin> モジュールは、 | |
| 460 | 755 | ファイルがどのように格納されているかに関係なくこれらのファイルに対する |
| 461 | 756 | 首尾一貫したオブジェクト指向インターフェースを提供します。 |
| 462 | ||
| 757 | データベースはテキスト、dbm、Berkeley DB、あるいは DBI 互換ドライバのある | |
| 463 | ||
| 758 | どんなデータベースでもかまいません。 | |
| 759 | C<HTTPD::UserAdmin> は "Basic" および "Digest" 認証スキームで | |
| 760 | 使われるファイルをサポートします。 | |
| 761 | 以下に例を挙げます: | |
| 464 | 762 | |
| 465 | ||
| 763 | use HTTPD::UserAdmin (); | |
| 466 | ||
| 764 | HTTPD::UserAdmin | |
| 467 | 765 | ->new(DB => "/foo/.htpasswd") |
| 468 | 766 | ->add($username => $password); |
| 469 | 767 | |
| 470 | 768 | =head2 How do I make sure users can't enter values into a form that cause my CGI script to do bad things? |
| 471 | 769 | |
| 472 | (私のCGIスクリプトに悪影響をもたらすようなものを、ユーザーが | |
| 770 | (私の CGI スクリプトに悪影響をもたらすようなものを、ユーザーがフォームに入力できないようにするには?) | |
| 473 | フォームに入力できないようにするにはどうするのでしょうか?) | |
| 474 | 771 | |
| 475 | ||
| 772 | =begin original | |
| 476 | にある CGI セキュリティ FAQを読んでください。そして | |
| 477 | http://www.perl.com/CPAN/doc/FAQs/cgi/perl-cgi-faq.html. | |
| 478 | にあるPerl/CGI FAQを読んでください。 | |
| 479 | 773 | |
| 480 | ||
| 774 | (contributed by brian d foy) | |
| 481 | データを使ってC<eval>やC<system>を使わないようにさせる汚染検査 | |
| 482 | (tainting、L<perlsec>を参照してください)を使います。汚染検査に加え、 | |
| 483 | 一引数形式の system() や exec() を決して使わないようにします。 | |
| 484 | その代わりに、シェルのグロビングが行われないように、 | |
| 485 | リストとしてコマンドと引数とを与えるようにします。 | |
| 486 | 775 | |
| 487 | = | |
| 776 | =end original | |
| 488 | 777 | |
| 778 | (brian d foy によって寄贈されました) | |
| 779 | ||
| 780 | =begin original | |
| 781 | ||
| 782 | You can't prevent people from sending your script bad data. Even if | |
| 783 | you add some client-side checks, people may disable them or bypass | |
| 784 | them completely. For instance, someone might use a module such as | |
| 785 | C<LWP> to access your CGI program. If you want to prevent data that | |
| 786 | try to use SQL injection or other sorts of attacks (and you should | |
| 787 | want to), you have to not trust any data that enter your program. | |
| 788 | ||
| 789 | =end original | |
| 790 | ||
| 791 | 人々がスクリプトに悪いデータを送るのを防ぐことは出来ません。 | |
| 792 | 例えクライアント側でチェックをしたとしても、それを無効にしたり | |
| 793 | 完全に回避したりできます。 | |
| 794 | 例えば、CGI プログラムに C<LWP> のようなモジュールを使うかもしれません。 | |
| 795 | SQL インジェクションや同様の種類の攻撃を行うようなデータを防ぎたいのなら | |
| 796 | (そしておそらくそうしたいでしょう)、プログラムに入力される | |
| 797 | どんなデータも信用しないようにする必要があります。 | |
| 798 | ||
| 799 | =begin original | |
| 800 | ||
| 801 | The L<perlsec> documentation has general advice about data security. | |
| 802 | If you are using the C<DBI> module, use placeholder to fill in data. | |
| 803 | If you are running external programs with C<system> or C<exec>, use | |
| 804 | the list forms. There are many other precautions that you should take, | |
| 805 | too many to list here, and most of them fall under the category of not | |
| 806 | using any data that you don't intend to use. Trust no one. | |
| 807 | ||
| 808 | =end original | |
| 809 | ||
| 810 | L<perlsec> 文書にはデータセキュリティに関する一般的な助言があります。 | |
| 811 | C<DBI> モジュールを使っているなら、データを埋めるのにプレースホルダを | |
| 812 | 使ってください。 | |
| 813 | C<system> や C<exec> で外部プログラムを実行しているなら、リスト形式を | |
| 814 | 使ってください。 | |
| 815 | その他、ここに書ききれないほどの注意するべき多くの事前注意があり、 | |
| 816 | そのほとんどは、使おうとしていないデータは使わないという分野に当てはまります。 | |
| 817 | 誰も信用しないでください。 | |
| 818 | ||
| 819 | =head2 How do I parse a mail header? | |
| 820 | ||
| 489 | 821 | (メールのヘッダーを解析するには?) |
| 490 | 822 | |
| 823 | =begin original | |
| 824 | ||
| 825 | For a quick-and-dirty solution, try this solution derived | |
| 826 | from L<perlfunc/split>: | |
| 827 | ||
| 828 | =end original | |
| 829 | ||
| 491 | 830 | 拙速な解決策なら、L<perlfunc/split> から派生した |
| 492 | 以下のやり方を試してみてください | |
| 831 | 以下のやり方を試してみてください: | |
| 493 | 832 | |
| 494 | ||
| 833 | $/ = ''; | |
| 495 | ||
| 834 | $header = <MSG>; | |
| 496 | ||
| 835 | $header =~ s/\n\s+/ /g; # merge continuation lines | |
| 497 | ||
| 836 | %head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header ); | |
| 498 | 837 | |
| 838 | =begin original | |
| 839 | ||
| 840 | That solution doesn't do well if, for example, you're trying to | |
| 841 | maintain all the Received lines. A more complete approach is to use | |
| 842 | the C<Mail::Header> module from CPAN (part of the C<MailTools> package). | |
| 843 | ||
| 844 | =end original | |
| 845 | ||
| 499 | 846 | このやり方は、たとえば受信した行すべてを保守しようとするときには |
| 500 | うまくありません。 | |
| 847 | うまくありません。 | |
| 501 | ||
| 848 | より完璧なアプローチは CPAN にある C<Mail::Header> モジュールを | |
| 502 | 一部です)。 | |
| 849 | 使うというものです(このモジュールは C<MailTools> パッケージの一部です)。 | |
| 503 | 850 | |
| 504 | 851 | =head2 How do I decode a CGI form? |
| 505 | 852 | |
| 506 | (CGIフォームをデコードするには?) | |
| 853 | (CGI フォームをデコードするには?) | |
| 507 | 854 | |
| 508 | 855 | =begin original |
| 509 | 856 | |
| 510 | ||
| 857 | (contributed by brian d foy) | |
| 511 | should you attempt to do so by hand! | |
| 512 | 858 | |
| 513 | 859 | =end original |
| 514 | 860 | |
| 515 | ||
| 861 | (brian d foy によって寄贈されました) | |
| 516 | あなたが手作業で行うことは多分ありません! | |
| 517 | 862 | |
| 518 | 863 | =begin original |
| 519 | 864 | |
| 520 | ||
| 865 | Use the C<CGI.pm> module that comes with Perl. It's quick, | |
| 521 | ||
| 866 | it's easy, and it actually does quite a bit of work to | |
| 522 | ||
| 867 | ensure things happen correctly. It handles GET, POST, and | |
| 523 | ||
| 868 | HEAD requests, multipart forms, multivalued fields, query | |
| 524 | s | |
| 869 | string and message body combinations, and many other things | |
| 525 | ||
| 870 | you probably don't want to think about. | |
| 526 | with GET/POST combinations where query fields are in more than one place. | |
| 527 | They don't deal with keywords in the query string. | |
| 528 | 871 | |
| 529 | 872 | =end original |
| 530 | 873 | |
| 531 | ||
| 874 | Perl に同梱されている C<CGI.pm> モジュールを使いましょう。 | |
| 532 | ||
| 875 | これは早く、簡単で、物事が正しく行われることを確実にするための | |
| 533 | ||
| 876 | ちょっとした作業を行います。 | |
| 534 | ||
| 877 | GET, POST, HEAD リクエスト、マルチパートフォーム、複数値フィールド、 | |
| 535 | ||
| 878 | クエリ文字列とメッセージボディの組み合わせ、およびその他の、 | |
| 536 | ||
| 879 | あなたが考えようとも思わないような多くの事柄を扱えます。 | |
| 537 | それは大きな罪なのです。また、HEADリクエストを | |
| 538 | 取り扱っていなかったりする場合もありますし、 | |
| 539 | ファイルのアップロードに使われる | |
| 540 | マルチパート形式を扱ってないこともあります。 | |
| 541 | あるいは二ヶ所以上で | |
| 542 | 問い合わせフィールドがある場合のGET/POSTの組み合わせに対応していません。 | |
| 543 | さらに問い合わせ文字列中にあるキーワードの扱いもしていません。 | |
| 544 | 880 | |
| 545 | 881 | =begin original |
| 546 | 882 | |
| 547 | I | |
| 883 | It doesn't get much easier: the C<CGI.pm> module automatically | |
| 548 | ||
| 884 | parses the input and makes each value available through the | |
| 549 | ||
| 885 | C<param()> function. | |
| 550 | of perl1 .. perl4, you might look into cgi-lib.pl (available from | |
| 551 | http://www.bio.cam.ac.uk/web/form.html). | |
| 552 | 886 | |
| 553 | 887 | =end original |
| 554 | 888 | |
| 555 | ||
| 889 | これ以上簡単にはなりません: C<CGI.pm> モジュールは入力を自動的にパースして、 | |
| 556 | ||
| 890 | それぞれの値を C<param()> 関数を通して利用可能にします。 | |
| 557 | 代わりに、CGI.pm か CGI_Lite.pm (CPAN で入手できます)を使ってください。 | |
| 558 | あなたが(モジュールを使うことのできない)perl1 〜 perl4 を使っているのなら、 | |
| 559 | cgi-lib.pl を調べてみてください | |
| 560 | (http://cgi-lib.stanford.edu/cgi-lib/で入手可能です) | |
| 561 | 891 | |
| 892 | use CGI qw(:standard); | |
| 893 | ||
| 894 | my $total = param( 'price' ) + param( 'shipping' ); | |
| 895 | ||
| 896 | my @items = param( 'item' ); # multiple values, same field name | |
| 897 | ||
| 562 | 898 | =begin original |
| 563 | 899 | |
| 564 | ||
| 900 | If you want an object-oriented approach, C<CGI.pm> can do that too. | |
| 565 | GETs should only be used for something that doesn't update the server. | |
| 566 | Otherwise you can get mangled databases and repeated feedback mail | |
| 567 | messages. The fancy word for this is ``idempotency''. This simply | |
| 568 | means that there should be no difference between making a GET request | |
| 569 | for a particular URL once or multiple times. This is because the | |
| 570 | HTTP protocol definition says that a GET request may be cached by the | |
| 571 | browser, or server, or an intervening proxy. POST requests cannot be | |
| 572 | cached, because each request is independent and matters. Typically, | |
| 573 | POST requests change or depend on state on the server (query or update | |
| 574 | a database, send mail, or purchase a computer). | |
| 575 | 901 | |
| 576 | 902 | =end original |
| 577 | 903 | |
| 578 | ||
| 904 | オブジェクト指向な手法が使いたいなら、C<CGI.pm> はそのようにもできます。 | |
| 579 | GET はサーバーを更新しないようなものに対してのみ使うべきです。 | |
| 580 | あるいは、データベースをいじったりメールメッセージによるフィードバックを | |
| 581 | 繰り返し行うようなこともできます。このことを表わすのにぴったりな | |
| 582 | 単語は“idempotency”です。その意味は、GET リクエストを作り出したものと | |
| 583 | 特定の URL とに違いがないということです。 | |
| 584 | これはつまり、HTTP プロトコルは GET リクエストがブラウザーや | |
| 585 | サーバー、あるいは途中にあるプロクシーによってキャッシングしている | |
| 586 | 可能性があることを定義しています。POST リクエストは | |
| 587 | キャッシュすることはできません。なぜなら呼び出しのそれぞれは | |
| 588 | 独立したものであるからなのです。 | |
| 589 | 典型的な例では、POST リクエストはサーバーの状態を変更したり、 | |
| 590 | 状態に依存しています(データベースに対する問い合わせや更新、メールの送信、 | |
| 591 | コンピューターの購入など)。 | |
| 592 | 905 | |
| 906 | use CGI; | |
| 907 | ||
| 908 | my $cgi = CGI->new(); | |
| 909 | ||
| 910 | my $total = $cgi->param( 'price' ) + $cgi->param( 'shipping' ); | |
| 911 | ||
| 912 | my @items = $cgi->param( 'item' ); | |
| 913 | ||
| 914 | =begin original | |
| 915 | ||
| 916 | You might also try C<CGI::Minimal> which is a lightweight version | |
| 917 | of the same thing. Other CGI::* modules on CPAN might work better | |
| 918 | for you, too. | |
| 919 | ||
| 920 | =end original | |
| 921 | ||
| 922 | 同じことをする軽量版の C<CGI::Minimal> も試したいかもしれません。 | |
| 923 | CPAN にあるその他の CGI::* モジュールもあなたのためによく働くでしょう。 | |
| 924 | ||
| 925 | =begin original | |
| 926 | ||
| 927 | Many people try to write their own decoder (or copy one from | |
| 928 | another program) and then run into one of the many "gotchas" | |
| 929 | of the task. It's much easier and less hassle to use C<CGI.pm>. | |
| 930 | ||
| 931 | =end original | |
| 932 | ||
| 933 | 多くの人々が自分用のデコーダを書こうとします (あるいは他のプログラムから | |
| 934 | コピーしようとします); そしてこの作業の多くの「コツ」の一つに出くわすことに | |
| 935 | なります。 | |
| 936 | C<CGI.pm> を使うことはより簡単で、面倒事も少なくなります。 | |
| 937 | ||
| 593 | 938 | =head2 How do I check a valid mail address? |
| 594 | 939 | |
| 595 | 940 | (メールアドレスが正しいかチェックするには?) |
| 596 | 941 | |
| 597 | 942 | =begin original |
| 598 | 943 | |
| 599 | ||
| 944 | (partly contributed by Aaron Sherman) | |
| 600 | 945 | |
| 601 | 946 | =end original |
| 602 | 947 | |
| 603 | ||
| 948 | (一部は Aaron Sherman によって寄贈されました) | |
| 604 | 949 | |
| 605 | 950 | =begin original |
| 606 | 951 | |
| 607 | ||
| 952 | This isn't as simple a question as it sounds. There are two parts: | |
| 608 | even then you face the halting problem), you cannot determine whether | |
| 609 | an email address is valid. Even if you apply the email header | |
| 610 | standard, you can have problems, because there are deliverable | |
| 611 | addresses that aren't RFC-822 (the mail header standard) compliant, | |
| 612 | and addresses that aren't deliverable which are compliant. | |
| 613 | 953 | |
| 614 | 954 | =end original |
| 615 | 955 | |
| 616 | ||
| 956 | これは見た目ほど単純な質問ではありません。 | |
| 617 | ||
| 957 | これは二つの部分からなります: | |
| 618 | そのアドレスが正しいものかどうかを決めることはできません。 | |
| 619 | あなたが電子メールヘッダーの標準を適用したとしても、 | |
| 620 | 問題が起こる可能性があります。 | |
| 621 | なぜなら、配達可能なアドレスには RFC-822(電子メールヘッダーの標準)に | |
| 622 | 適合していないものがあり、適合していても配達できないアドレスも | |
| 623 | あるからです。 | |
| 624 | 958 | |
| 625 | 959 | =begin original |
| 626 | 960 | |
| 627 | ||
| 961 | a) How do I verify that an email address is correctly formatted? | |
| 628 | mail addresses with a simple regex, such as | |
| 629 | C</^[\w.-]+\@(?:[\w-]+\.)+\w+$/>. It's a very bad idea. However, | |
| 630 | this also throws out many valid ones, and says nothing about | |
| 631 | potential deliverability, so it is not suggested. Instead, see | |
| 632 | http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz, | |
| 633 | which actually checks against the full RFC spec (except for nested | |
| 634 | comments), looks for addresses you may not wish to accept mail to | |
| 635 | (say, Bill Clinton or your postmaster), and then makes sure that the | |
| 636 | hostname given can be looked up in the DNS MX records. It's not fast, | |
| 637 | but it works for what it tries to do. | |
| 638 | 962 | |
| 639 | 963 | =end original |
| 640 | 964 | |
| 641 | ||
| 965 | a) メールアドレスが正しい形式かを検証するには? | |
| 642 | のように単純な正規表現で削除しようとしています。しかしながら、 | |
| 643 | これは正当なアドレスも一緒に取り除いてしまい、 | |
| 644 | 潜在的な到達性についてなにも言いません。ですからこれはお薦めしません。 | |
| 645 | 代わりに、完全な RFC 仕様に突き合わせてチェックを行い | |
| 646 | (ネストしたコメントを除く)、 | |
| 647 | あなたが受け取りたくないメールアドレスを探し出し、 | |
| 648 | さらにホスト名が DNS で引けるかどうかを確かめる | |
| 649 | http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz | |
| 650 | を参照してください。これは速くはありませんが、しかしきちんと動きます。 | |
| 651 | 966 | |
| 652 | 967 | =begin original |
| 653 | 968 | |
| 654 | ||
| 969 | b) How do I verify that an email address targets a valid recipient? | |
| 655 | enter their address twice, just as you normally do to change a password. | |
| 656 | This usually weeds out typos. If both versions match, send | |
| 657 | mail to that address with a personal message that looks somewhat like: | |
| 658 | 970 | |
| 659 | 971 | =end original |
| 660 | 972 | |
| 661 | ||
| 973 | b) メールアドレスが正当な受信者を対象としているかを検証するには? | |
| 662 | パスワードを変更するときと同じように | |
| 663 | ユーザーにアドレスを二回入力させるというものです。 | |
| 664 | これによって通常は打ち間違いを防ぐことができます。 | |
| 665 | 二回の入力がマッチしたなら、以下のような内容のメッセージをメールとして | |
| 666 | そのアドレスへ送ります: | |
| 667 | 974 | |
| 668 | ||
| 975 | =begin original | |
| 669 | 976 | |
| 977 | Without sending mail to the address and seeing whether there's a human | |
| 978 | on the other end to answer you, you cannot fully answer part I<b>, but | |
| 979 | either the C<Email::Valid> or the C<RFC::RFC822::Address> module will do | |
| 980 | both part I<a> and part I<b> as far as you can in real-time. | |
| 981 | ||
| 982 | =end original | |
| 983 | ||
| 984 | そのアドレスにメールを送ってそれが届いたかどうかを確認しなければ | |
| 985 | 完全にパート I<b> に答えられませんが、C<Email::Valid> か | |
| 986 | C<RFC::RFC822::Address> のモジュールは、リアルタイムでできる限りの | |
| 987 | ことに対してパート I<a> とパート I<b> の両方を行います。 | |
| 988 | ||
| 670 | 989 | =begin original |
| 671 | 990 | |
| 672 | | |
| 991 | If you want to just check part I<a> to see that the address is valid | |
| 673 | ||
| 992 | according to the mail header standard with a simple regular expression, | |
| 674 | ||
| 993 | you can have problems, because there are deliverable addresses that | |
| 675 | ||
| 994 | aren't RFC-2822 (the latest mail header standard) compliant, and | |
| 676 | | |
| 995 | addresses that aren't deliverable which, are compliant. However, the | |
| 996 | following will match valid RFC-2822 addresses that do not have comments, | |
| 997 | folding whitespace, or any other obsolete or non-essential elements. | |
| 998 | This I<just> matches the address itself: | |
| 677 | 999 | |
| 678 | 1000 | =end original |
| 679 | 1001 | |
| 680 | ||
| 1002 | もしあなたが単純な正規表現でアドレスがメールヘッダ標準に従っているかを | |
| 681 | | |
| 1003 | 見ることでパート I<a> をチェックしたいなら、問題を抱えることになります; | |
| 682 | | |
| 1004 | なぜなら、RFC-2822 (最新のメールヘッダ標準) に準拠してないけれども | |
| 683 | ||
| 1005 | 配達可能なアドレスが存在し、標準に準拠しているけれども配達不能なアドレスも | |
| 684 | ||
| 1006 | 存在するからです。 | |
| 1007 | しかし以下のコードは、コメント、折り畳みの空白、あるいはその他の時代遅れに | |
| 1008 | なっていたり本質的でない要素を含んでいない、有効な RFC-2822 アドレスに | |
| 1009 | マッチングします。 | |
| 1010 | これは I<単に> アドレス自身にマッチングします: | |
| 685 | 1011 | |
| 686 | ||
| 1012 | my $atom = qr{[a-zA-Z0-9_!#\$\%&'*+/=?\^`{}~|\-]+}; | |
| 687 | ||
| 1013 | my $dot_atom = qr{$atom(?:\.$atom)*}; | |
| 1014 | my $quoted = qr{"(?:\\[^\r\n]|[^\\"])*"}; | |
| 1015 | my $local = qr{(?:$dot_atom|$quoted)}; | |
| 1016 | my $quotedpair = qr{\\[\x00-\x09\x0B-\x0c\x0e-\x7e]}; | |
| 1017 | my $domain_lit = qr{\[(?:$quotedpair|[\x21-\x5a\x5e-\x7e])*\]}; | |
| 1018 | my $domain = qr{(?:$dot_atom|$domain_lit)}; | |
| 1019 | my $addr_spec = qr{$local\@$domain}; | |
| 688 | 1020 | |
| 689 | 1021 | =begin original |
| 690 | 1022 | |
| 1023 | Just match an address against C</^${addr_spec}$/> to see if it follows | |
| 1024 | the RFC2822 specification. However, because it is impossible to be | |
| 1025 | sure that such a correctly formed address is actually the correct way | |
| 1026 | to reach a particular person or even has a mailbox associated with it, | |
| 1027 | you must be very careful about how you use this. | |
| 1028 | ||
| 1029 | =end original | |
| 1030 | ||
| 1031 | もしアドレスが RFC 2822 仕様に準拠しているかどうかを見たいなら、単に | |
| 1032 | C</^${addr_spec}$/> とマッチングさせてください。 | |
| 1033 | しかし、このような正しい形式のアドレスが実際に特定の個人に届く | |
| 1034 | 正しい方法なのか、あるいはその個人に関連付けられたメールボックスに | |
| 1035 | 届くのかさえも明確にすることは不可能なので、これをどう使うかについては | |
| 1036 | とても慎重になる必要があります。 | |
| 1037 | ||
| 1038 | =begin original | |
| 1039 | ||
| 1040 | Our best advice for verifying a person's mail address is to have them | |
| 1041 | enter their address twice, just as you normally do to change a | |
| 1042 | password. This usually weeds out typos. If both versions match, send | |
| 1043 | mail to that address with a personal message. If you get the message | |
| 1044 | back and they've followed your directions, you can be reasonably | |
| 1045 | assured that it's real. | |
| 1046 | ||
| 1047 | =end original | |
| 1048 | ||
| 1049 | 私たちができる最善のアドバイスは、個人のメールアドレスをチェックするのに | |
| 1050 | パスワードを変更するときと同じようにユーザーにアドレスを | |
| 1051 | 二回入力させるというものです。 | |
| 1052 | これによって通常は打ち間違いを防ぐことができます。 | |
| 1053 | 二回の入力がマッチしたなら、個人的な内容のメッセージをメールとして | |
| 1054 | そのアドレスへ送ります。 | |
| 1055 | もしメッセージが返ってきて、それがあなたの指示に従っているなら、 | |
| 1056 | それが実際のものであると十分に仮定できます。 | |
| 1057 | ||
| 1058 | =begin original | |
| 1059 | ||
| 691 | 1060 | A related strategy that's less open to forgery is to give them a PIN |
| 692 | 1061 | (personal ID number). Record the address and PIN (best that it be a |
| 693 | random one) for later processing. | |
| 1062 | random one) for later processing. In the mail you send, ask them to | |
| 694 | 1063 | include the PIN in their reply. But if it bounces, or the message is |
| 695 | included via a | |
| 1064 | included via a "vacation" script, it'll be there anyway. So it's | |
| 696 | 1065 | best to ask them to mail back a slight alteration of the PIN, such as |
| 697 | 1066 | with the characters reversed, one added or subtracted to each digit, etc. |
| 698 | 1067 | |
| 699 | 1068 | =end original |
| 700 | 1069 | |
| 701 | より偽造のやりにくい別のやり方に、チェックに対象者に対してPIN | |
| 1070 | より偽造のやりにくい別のやり方に、チェックに対象者に対して PIN | |
| 702 | (Personal ID Number)を与えるというものがあります。 | |
| 1071 | (Personal ID Number) を与えるというものがあります。 | |
| 703 | 後の処理のためにアドレスとPIN(ランダムであることが望ましい)を | |
| 1072 | 後の処理のためにアドレスと PIN (ランダムであることが望ましい)を | |
| 1073 | 記録しておくのです。 | |
| 704 | 1074 | あなたがメールを送るときに、宛て先人に対して彼らの出すリプライに |
| 705 | PINを含めるように依頼するのです。 | |
| 1075 | PIN を含めるように依頼するのです。 | |
| 706 | しかしそれがそのまま返ってきたり、 | |
| 1076 | しかしそれがそのまま返ってきたり、あるいは返ってきたメッセージが | |
| 707 | ||
| 1077 | "vacation" スクリプトを通じてのものであっても、そのまま PIN が | |
| 708 | ||
| 1078 | 含まれてしまいます。 | |
| 709 | ですから、最善なやり方はメールを送るときに返事には | |
| 1079 | ですから、最善なやり方はメールを送るときに返事には文字を逆順にするとか、 | |
| 710 | ||
| 1080 | 各桁に対して足し算や引き算を行うなどして | |
| 711 | PINを変形したものを含めて返すように依頼するという方法です。 | |
| 1081 | PIN を変形したものを含めて返すように依頼するという方法です。 | |
| 712 | 1082 | |
| 713 | 1083 | =head2 How do I decode a MIME/BASE64 string? |
| 714 | 1084 | |
| 715 | 1085 | (MIME/BASE64 文字列のデコードを行うには?) |
| 716 | 1086 | |
| 717 | 1087 | =begin original |
| 718 | 1088 | |
| 719 | The MIME-Base64 package (available from CPAN) handles this as well as | |
| 1089 | The C<MIME-Base64> package (available from CPAN) handles this as well as | |
| 720 | 1090 | the MIME/QP encoding. Decoding BASE64 becomes as simple as: |
| 721 | 1091 | |
| 722 | 1092 | =end original |
| 723 | 1093 | |
| 724 | MIME-Base64 パッケージ(CPANで入手可能です)はこの問題と、 | |
| 1094 | C<MIME-Base64> パッケージ(CPAN で入手可能です)はこの問題と、 | |
| 725 | 1095 | MIME/QP エンコーディングを取り扱います。 |
| 726 | BASE64のデコードは以下のように単純です: | |
| 1096 | BASE64 のデコードは以下のように単純です: | |
| 727 | 1097 | |
| 728 | ||
| 1098 | use MIME::Base64; | |
| 729 | ||
| 1099 | $decoded = decode_base64($encoded); | |
| 730 | 1100 | |
| 731 | 1101 | =begin original |
| 732 | 1102 | |
| 733 | The MIME-Tools package (available from CPAN) supports extraction with | |
| 1103 | The C<MIME-Tools> package (available from CPAN) supports extraction with | |
| 734 | 1104 | decoding of BASE64 encoded attachments and content directly from email |
| 735 | 1105 | messages. |
| 736 | 1106 | |
| 737 | 1107 | =end original |
| 738 | 1108 | |
| 739 | MIME-Tools パッケージ (CPAN にあります) は BASE64 エンコードされた | |
| 1109 | C<MIME-Tools> パッケージ (CPAN にあります) は BASE64 エンコードされた | |
| 740 | 1110 | 添付ファイルと本文をメールのメッセージから直接抽出できます。 |
| 741 | 1111 | |
| 742 | ||
| 1112 | =begin original | |
| 743 | より直接的なやり方は、ちょっとした変換をした後でunpack()関数の | |
| 744 | “u”フォーマットを使うというものです: | |
| 745 | 1113 | |
| 746 | | |
| 1114 | If the string to decode is short (less than 84 bytes long) | |
| 747 | | |
| 1115 | a more direct approach is to use the C<unpack()> function's "u" | |
| 748 | | |
| 1116 | format after minor transliterations: | |
| 749 | print unpack("u", $len . $_); # uudecodeして出力 | |
| 750 | 1117 | |
| 751 | = | |
| 1118 | =end original | |
| 752 | 1119 | |
| 1120 | もしデコードしたい文字列が短い(84 文字以下)の場合、より直接的なやり方は、 | |
| 1121 | ちょっとした変換をした後で C<unpack()> 関数の "u" フォーマットを | |
| 1122 | 使うというものです: | |
| 1123 | ||
| 1124 | tr#A-Za-z0-9+/##cd; # remove non-base64 chars | |
| 1125 | tr#A-Za-z0-9+/# -_#; # convert to uuencoded format | |
| 1126 | $len = pack("c", 32 + 0.75*length); # compute length byte | |
| 1127 | print unpack("u", $len . $_); # uudecode and print | |
| 1128 | ||
| 1129 | =head2 How do I return the user's mail address? | |
| 1130 | ||
| 753 | 1131 | (ユーザーのメールアドレスを返すには?) |
| 754 | 1132 | |
| 755 | ||
| 1133 | =begin original | |
| 756 | ||
| 1135 | On systems that support getpwuid, the C<< $< >> variable, and the | |
| 1136 | C<Sys::Hostname> module (which is part of the standard perl distribution), | |
| 1137 | you can probably try using something like this: | |
| 1138 | ||
| 1139 | =end original | |
| 1140 | ||
| 1141 | getpwuid をサポートしているシステムであれば、C<< $< >> という変数と | |
| 1142 | C<Sys::Hostname> モジュール(標準の perl 配布キットの一部です)を使って | |
| 757 | 1143 | 以下のようなことが試せるでしょう。 |
| 758 | 1144 | |
| 759 | ||
| 1145 | use Sys::Hostname; | |
| 760 | ||
| 1146 | $address = sprintf('%s@%s', scalar getpwuid($<), hostname); | |
| 761 | 1147 | |
| 762 | 1148 | =begin original |
| 763 | 1149 | |
| 764 | Company policies on | |
| 1150 | Company policies on mail address can mean that this generates addresses | |
| 765 | that the company's | |
| 1151 | that the company's mail system will not accept, so you should ask for | |
| 766 | users' | |
| 1152 | users' mail addresses when this matters. Furthermore, not all systems | |
| 767 | 1153 | on which Perl runs are so forthcoming with this information as is Unix. |
| 768 | 1154 | |
| 769 | 1155 | =end original |
| 770 | 1156 | |
| 771 | 1157 | 会社のメールアドレスに関するポリシーが、これが生成するアドレスは |
| 772 | 1158 | その会社のメールシステムが受け付けないものである可能性があります。 |
| 773 | 1159 | ですから、ユーザーに、そのユーザーのメールアドレスを尋ねるべきでしょう。 |
| 774 | それに加え、Perlが動作する全てのシステムで | |
| 1160 | それに加え、Perl が動作する全てのシステムで | |
| 775 | この情報が(UNIXと同じように)得られるわけではありません。 | |
| 1161 | この情報が(UNIX と同じように)得られるわけではありません。 | |
| 776 | 1162 | |
| 777 | ||
| 1163 | =begin original | |
| 1164 | ||
| 1165 | The C<Mail::Util> module from CPAN (part of the C<MailTools> package) provides a | |
| 1166 | C<mailaddress()> function that tries to guess the mail address of the user. | |
| 1167 | It makes a more intelligent guess than the code above, using information | |
| 1168 | given when the module was installed, but it could still be incorrect. | |
| 1169 | Again, the best way is often just to ask the user. | |
| 1170 | ||
| 1171 | =end original | |
| 1172 | ||
| 1173 | CPAN にある C<Mail::Util> モジュール (C<MailTools> パッケージの一部です)は | |
| 778 | 1174 | メールアドレスがそのユーザーのものであるかどうかを確かめようとする |
| 779 | mailaddress()という関数を提供しています。 | |
| 1175 | C<mailaddress()> という関数を提供しています。 | |
| 780 | これは上で例示したやり方よりも賢く、 | |
| 1176 | これは上で例示したやり方よりも賢く、モジュールがインストールされたときの | |
| 781 | ||
| 1177 | 情報を使いますが、それでも正しくない可能性があります。 | |
| 782 | それでも正しくない可能性があります。 | |
| 783 | 1178 | くり返しますが、最善の方法はユーザーに尋ねること、というのがほとんどです。 |
| 784 | 1179 | |
| 785 | 1180 | =head2 How do I send mail? |
| 786 | 1181 | |
| 787 | 1182 | (メールを送るには?) |
| 788 | 1183 | |
| 789 | ||
| 1184 | =begin original | |
| 790 | 1185 | |
| 791 | | |
| 1186 | Use the C<sendmail> program directly: | |
| 792 | or die "Can't fork for sendmail: $!\n"; | |
| 793 | print SENDMAIL <<"EOF"; | |
| 794 | From: メールの発信者 <me\@host> | |
| 795 | To: 宛て先 <you\@otherhost> | |
| 796 | Subject: 適切なサブジェクト | |
| 797 | 1187 | |
| 798 | | |
| 1188 | =end original | |
| 799 | EOF | |
| 800 | close(SENDMAIL) or warn "sendmail didn't close nicely"; | |
| 801 | 1189 | |
| 1190 | C<sendmail> プログラムを直接使います: | |
| 1191 | ||
| 1192 | open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq") | |
| 1193 | or die "Can't fork for sendmail: $!\n"; | |
| 1194 | print SENDMAIL <<"EOF"; | |
| 1195 | From: User Originating Mail <me\@host> | |
| 1196 | To: Final Destination <you\@otherhost> | |
| 1197 | Subject: A relevant subject line | |
| 1198 | ||
| 1199 | Body of the message goes here after the blank line | |
| 1200 | in as many lines as you like. | |
| 1201 | EOF | |
| 1202 | close(SENDMAIL) or warn "sendmail didn't close nicely"; | |
| 1203 | ||
| 802 | 1204 | =begin original |
| 803 | 1205 | |
| 804 | The B<-oi> option prevents sendmail from interpreting a line consisting | |
| 1206 | The B<-oi> option prevents C<sendmail> from interpreting a line consisting | |
| 805 | 1207 | of a single dot as "end of message". The B<-t> option says to use the |
| 806 | 1208 | headers to decide who to send the message to, and B<-odq> says to put |
| 807 | 1209 | the message into the queue. This last option means your message won't |
| 808 | 1210 | be immediately delivered, so leave it out if you want immediate |
| 809 | 1211 | delivery. |
| 810 | 1212 | |
| 811 | 1213 | =end original |
| 812 | 1214 | |
| 813 | B<-oi>オプションはsendmailがドットだけの行を“メッセージの終わり”と | |
| 1215 | B<-oi> オプションは C<sendmail> がドットだけの行を“メッセージの終わり”と | |
| 814 | みなさないようにするためのオプションです。 | |
| 1216 | みなさないようにするためのオプションです。 | |
| 815 | メッセージを誰に | |
| 1217 | B<-t>オプションはメッセージを誰に送るかを決めるかのために | |
| 816 | B<-odq>オプションメッセージを | |
| 1218 | ヘッダーを使うことを指示し、B<-odq> オプションメッセージを | |
| 1219 | キューに入れることを指示します。 | |
| 817 | 1220 | 最後のオプションの意味は、あなたのメッセージがすぐには配送されないことを |
| 818 | 意味します。 | |
| 1221 | 意味します。 | |
| 819 | このオプションを取り除いてください。 | |
| 1222 | ですから、すぐに配送させたいのであればこのオプションを取り除いてください。 | |
| 820 | 1223 | |
| 821 | 1224 | =begin original |
| 822 | 1225 | |
| 823 | Alternate, less convenient approaches include calling mail (sometimes | |
| 1226 | Alternate, less convenient approaches include calling C<mail> (sometimes | |
| 824 | called mailx) directly or simply opening up port 25 have having an | |
| 1227 | called C<mailx>) directly or simply opening up port 25 have having an | |
| 825 | 1228 | intimate conversation between just you and the remote SMTP daemon, |
| 826 | probably sendmail. | |
| 1229 | probably C<sendmail>. | |
| 827 | 1230 | |
| 828 | 1231 | =end original |
| 829 | 1232 | |
| 830 | あるいは、直接 mail (mailx と呼ばれることもあります)を | |
| 1233 | あるいは、直接 C<mail> (C<mailx> と呼ばれることもあります)を呼びだしたり、 | |
| 831 | ||
| 1234 | 単純に 25 番ポートを使ってリモートの SMTP デーモン(多分 C<sendmail> でしょう) | |
| 832 | ||
| 1235 | との間で詳細な通信を行うといったあまり便利でない方法もあります。 | |
| 833 | 詳細な通信を行うといったあまり便利でない方法もあります。 | |
| 834 | 1236 | |
| 835 | ||
| 1237 | =begin original | |
| 836 | 1238 | |
| 837 | use Mail::Mailer | |
| 1239 | Or you might be able use the CPAN module C<Mail::Mailer>: | |
| 838 | 1240 | |
| 839 | ||
| 1241 | =end original | |
| 840 | $mailer->open({ From => $from_address, | |
| 841 | To => $to_address, | |
| 842 | Subject => $subject, | |
| 843 | }) | |
| 844 | or die "Can't open: $!\n"; | |
| 845 | print $mailer $body; | |
| 846 | $mailer->close(); | |
| 847 | 1242 | |
| 848 | ||
| 1243 | あるいは CPAN にあるモジュール C<Mail::Mailer> が使えるかもしれません: | |
| 849 | ||
| 1245 | use Mail::Mailer; | |
| 1246 | ||
| 1247 | $mailer = Mail::Mailer->new(); | |
| 1248 | $mailer->open({ From => $from_address, | |
| 1249 | To => $to_address, | |
| 1250 | Subject => $subject, | |
| 1251 | }) | |
| 1252 | or die "Can't open: $!\n"; | |
| 1253 | print $mailer $body; | |
| 1254 | $mailer->close(); | |
| 1255 | ||
| 1256 | =begin original | |
| 1257 | ||
| 1258 | The C<Mail::Internet> module uses C<Net::SMTP> which is less Unix-centric than | |
| 1259 | C<Mail::Mailer>, but less reliable. Avoid raw SMTP commands. There | |
| 1260 | are many reasons to use a mail transport agent like C<sendmail>. These | |
| 1261 | include queuing, MX records, and security. | |
| 1262 | ||
| 1263 | =end original | |
| 1264 | ||
| 1265 | C<Mail::Internet> モジュールは C<Mail::Mailer> より UNIX 的ではない | |
| 1266 | C<Net::SMTP> を使っていますが、信頼性も低いです。 | |
| 850 | 1267 | 生の SMTP コマンドを無視します。 |
| 851 | sendmail のような mail transport agent を使う理由はたくさんあります。 | |
| 1268 | C<sendmail> のような mail transport agent を使う理由はたくさんあります。 | |
| 852 | 1269 | その中にはキューイングも含まれますし、MX レコードやセキュリティと |
| 853 | 1270 | いったものが含まれます。 |
| 854 | 1271 | |
| 855 | 1272 | =head2 How do I use MIME to make an attachment to a mail message? |
| 856 | 1273 | |
| 857 | 1274 | (メールメッセージに添付するためにどうやって MIME を使えばいいですか?) |
| 858 | 1275 | |
| 859 | 1276 | =begin original |
| 860 | 1277 | |
| 861 | This answer is extracted directly from the MIME::Lite documentation. | |
| 1278 | This answer is extracted directly from the C<MIME::Lite> documentation. | |
| 862 | 1279 | Create a multipart message (i.e., one with attachments). |
| 863 | 1280 | |
| 864 | 1281 | =end original |
| 865 | 1282 | |
| 866 | この回答は MIME::Lite のドキュメントから直接持ってきたものです。 | |
| 1283 | この回答は C<MIME::Lite> のドキュメントから直接持ってきたものです。 | |
| 867 | 1284 | マルチパートメッセージ(つまり 添付つきのメッセージ) を作ります。 |
| 868 | 1285 | |
| 869 | ||
| 1286 | use MIME::Lite; | |
| 870 | 1287 | |
| 871 | ||
| 1288 | ### Create a new multipart message: | |
| 872 | ||
| 1289 | $msg = MIME::Lite->new( | |
| 873 | ||
| 1290 | From =>'me@myhost.com', | |
| 874 | ||
| 1291 | To =>'you@yourhost.com', | |
| 875 | ||
| 1292 | Cc =>'some@other.com, some@more.com', | |
| 876 | ||
| 1293 | Subject =>'A message with 2 parts...', | |
| 877 | ||
| 1294 | Type =>'multipart/mixed' | |
| 878 | ||
| 1295 | ); | |
| 879 | 1296 | |
| 880 | ||
| 1297 | ### Add parts (each "attach" has same arguments as "new"): | |
| 881 | ||
| 1298 | $msg->attach(Type =>'TEXT', | |
| 882 | ||
| 1299 | Data =>"Here's the GIF file you wanted" | |
| 883 | ||
| 1300 | ); | |
| 884 | ||
| 1301 | $msg->attach(Type =>'image/gif', | |
| 885 | ||
| 1302 | Path =>'aaa000123.gif', | |
| 886 | ||
| 1303 | Filename =>'logo.gif' | |
| 887 | ||
| 1304 | ); | |
| 888 | 1305 | |
| 889 | ||
| 1306 | $text = $msg->as_string; | |
| 890 | 1307 | |
| 891 | 1308 | =begin original |
| 892 | 1309 | |
| 893 | MIME::Lite also includes a method for sending these things. | |
| 1310 | C<MIME::Lite> also includes a method for sending these things. | |
| 894 | 1311 | |
| 895 | 1312 | =end original |
| 896 | 1313 | |
| 897 | MIME::Lite はまたこれらのものを送るためのメソッドを含みます。 | |
| 1314 | C<MIME::Lite> はまたこれらのものを送るためのメソッドを含みます。 | |
| 898 | 1315 | |
| 899 | ||
| 1316 | $msg->send; | |
| 900 | 1317 | |
| 901 | 1318 | =begin original |
| 902 | 1319 | |
| 903 | This defaults to using L<sendmail | |
| 1320 | This defaults to using L<sendmail> but can be customized to use | |
| 904 | 1321 | SMTP via L<Net::SMTP>. |
| 905 | 1322 | |
| 906 | 1323 | =end original |
| 907 | 1324 | |
| 908 | これはデフォルトでは L<sendmail | |
| 1325 | これはデフォルトでは L<sendmail> を使いますが、 | |
| 909 | 1326 | L<Net::SMTP> 経由で SMTP を使うようにカスタマイズできます。 |
| 910 | 1327 | |
| 911 | 1328 | =head2 How do I read mail? |
| 912 | 1329 | |
| 913 | 1330 | (メールを読み出すには?) |
| 914 | 1331 | |
| 915 | ||
| 1332 | =begin original | |
| 916 | ||
| 1334 | While you could use the C<Mail::Folder> module from CPAN (part of the | |
| 1335 | C<MailFolder> package) or the C<Mail::Internet> module from CPAN (part | |
| 1336 | of the C<MailTools> package), often a module is overkill. Here's a | |
| 1337 | mail sorter. | |
| 1338 | ||
| 1339 | =end original | |
| 1340 | ||
| 1341 | CPAN にある C<Mail::Folder> モジュール(C<MailFolder> パッケージの一部です)や | |
| 1342 | C<Mail::Internet> モジュール(これも C<MailTools> パッケージの一部です)が | |
| 917 | 1343 | 使えますが、モジュールを使うのはやりすぎかもしれません。 |
| 918 | 1344 | 以下にメールをソートする方法を示します。 |
| 919 | 1345 | |
| 920 | ||
| 1346 | #!/usr/bin/perl | |
| 921 | # bysub1 - サブジェクトによる単純なソート | |
| 922 | my(@msgs, @sub); | |
| 923 | my $msgno = -1; | |
| 924 | $/ = ''; # パラグラフ読み出し | |
| 925 | while (<>) { | |
| 926 | if (/^From/m) { | |
| 927 | /^Subject:\s*(?:Re:\s*)*(.*)/mi; | |
| 928 | $sub[++$msgno] = lc($1) || ''; | |
| 929 | } | |
| 930 | $msgs[$msgno] .= $_; | |
| 931 | } | |
| 932 | for my $i (sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msgs)) { | |
| 933 | print $msgs[$i]; | |
| 934 | } | |
| 935 | 1347 | |
| 936 | ||
| 1348 | my(@msgs, @sub); | |
| 1349 | my $msgno = -1; | |
| 1350 | $/ = ''; # paragraph reads | |
| 1351 | while (<>) { | |
| 1352 | if (/^From /m) { | |
| 1353 | /^Subject:\s*(?:Re:\s*)*(.*)/mi; | |
| 1354 | $sub[++$msgno] = lc($1) || ''; | |
| 1355 | } | |
| 1356 | $msgs[$msgno] .= $_; | |
| 1357 | } | |
| 1358 | for my $i (sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msgs)) { | |
| 1359 | print $msgs[$i]; | |
| 1360 | } | |
| 937 | 1361 | |
| 938 | ||
| 1362 | =begin original | |
| 939 | # bysub2 - awki的な、サブジェクトによるソート | |
| 940 | BEGIN { $msgno = -1 } | |
| 941 | $sub[++$msgno] = (/^Subject:\s*(?:Re:\s*)*(.*)/mi)[0] if /^From/m; | |
| 942 | $msg[$msgno] .= $_; | |
| 943 | END { print @msg[ sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msg) ] } | |
| 944 | 1363 | |
| 945 | ||
| 1364 | Or more succinctly, | |
| 946 | 1365 | |
| 947 | ||
| 1366 | =end original | |
| 948 | 1367 | |
| 949 | ||
| 1368 | あるいはもっと簡潔に: | |
| 950 | これは便利なときもありますが、高い移植性があるというわけではありません。 | |
| 951 | これは、便利さと移植性とのトレードオフの一例です。 | |
| 952 | 1369 | |
| 953 | ||
| 1370 | #!/usr/bin/perl -n00 | |
| 954 | ||
| 1371 | # bysub2 - awkish sort-by-subject | |
| 955 | I | |
| 1372 | BEGIN { $msgno = -1 } | |
| 1373 | $sub[++$msgno] = (/^Subject:\s*(?:Re:\s*)*(.*)/mi)[0] if /^From/m; | |
| 1374 | $msg[$msgno] .= $_; | |
| 1375 | END { print @msg[ sort { $sub[$a] cmp $sub[$b] || $a <=> $b } (0 .. $#msg) ] } | |
| 956 | 1376 | |
| 957 | use | |
| 1377 | =head2 How do I find out my hostname, domainname, or IP address? | |
| 958 | | |
| 1378 | X<hostname, domainname, IP address, host, domain, hostfqdn, inet_ntoa, | |
| 959 | ||
| 1379 | gethostbyname, Socket, Net::Domain, Sys::Hostname> | |
| 960 | my $addr = inet_ntoa(scalar gethostbyname($host || 'localhost')); | |
| 961 | 1380 | |
| 1381 | (私のホスト名/ドメイン名/IP アドレスを見つけるには?) | |
| 1382 | ||
| 962 | 1383 | =begin original |
| 963 | 1384 | |
| 964 | ||
| 1385 | (contributed by brian d foy) | |
| 965 | it out of /etc/resolv.conf, at least under Unix. Of course, this | |
| 966 | assumes several things about your resolv.conf configuration, including | |
| 967 | that it exists. | |
| 968 | 1386 | |
| 969 | 1387 | =end original |
| 970 | 1388 | |
| 971 | ||
| 1389 | (brian d foy によって寄贈されました) | |
| 972 | ドメイン名を知る最も単純な方法は | |
| 973 | /etc/resolev.conf を解析することでしょう。 | |
| 974 | もちろん、これはファイルが存在していることを含め、 | |
| 975 | resolv.confの設定に関して幾つかの仮定を行っています。 | |
| 976 | 1390 | |
| 977 | 1391 | =begin original |
| 978 | 1392 | |
| 979 | ||
| 1393 | The C<Net::Domain> module, which is part of the standard distribution starting | |
| 980 | ||
| 1394 | in perl5.7.3, can get you the fully qualified domain name (FQDN), the host | |
| 1395 | name, or the domain name. | |
| 981 | 1396 | |
| 982 | 1397 | =end original |
| 983 | 1398 | |
| 984 | ||
| 1399 | perl5.7.3 から標準配布されている C<Net::Domain> モジュールを使うと、 | |
| 985 | ||
| 1400 | 完全修飾ドメイン名 (FQDN)、ホスト名、ドメイン名が得られます。 | |
| 986 | 1401 | |
| 1402 | use Net::Domain qw(hostname hostfqdn hostdomain); | |
| 1403 | ||
| 1404 | my $host = hostfqdn(); | |
| 1405 | ||
| 1406 | =begin original | |
| 1407 | ||
| 1408 | The C<Sys::Hostname> module, included in the standard distribution since | |
| 1409 | perl5.6, can also get the hostname. | |
| 1410 | ||
| 1411 | =end original | |
| 1412 | ||
| 1413 | perl5.6 から標準配布されている C<Sys::Hostname> モジュールでも | |
| 1414 | ホスト名を得られます。 | |
| 1415 | ||
| 1416 | use Sys::Hostname; | |
| 1417 | ||
| 1418 | $host = hostname(); | |
| 1419 | ||
| 1420 | =begin original | |
| 1421 | ||
| 1422 | To get the IP address, you can use the C<gethostbyname> built-in function | |
| 1423 | to turn the name into a number. To turn that number into the dotted octet | |
| 1424 | form (a.b.c.d) that most people expect, use the C<inet_ntoa> function | |
| 1425 | from the C<Socket> module, which also comes with perl. | |
| 1426 | ||
| 1427 | =end original | |
| 1428 | ||
| 1429 | IP アドレスを得るには、名前から数値に変換するために C<gethostbyname> | |
| 1430 | 組み込み関数が使えます。 | |
| 1431 | 数値を、ほとんどの人が想定しているピリオド付きの形 (a.b.c.d) に変換するには、 | |
| 1432 | 標準配布されている C<Socket> モジュールの C<inet_ntoa> 関数を使います。 | |
| 1433 | ||
| 1434 | use Socket; | |
| 1435 | ||
| 1436 | my $address = inet_ntoa( | |
| 1437 | scalar gethostbyname( $host || 'localhost' ) | |
| 1438 | ); | |
| 1439 | ||
| 987 | 1440 | =head2 How do I fetch a news article or the active newsgroups? |
| 988 | 1441 | |
| 989 | (ニュースの | |
| 1442 | (ニュースの記事やアクティブなニュースグループを取得するには?) | |
| 990 | 1443 | |
| 991 | 1444 | =begin original |
| 992 | 1445 | |
| 993 | Use the Net::NNTP or News::NNTPClient modules, both available from CPAN. | |
| 1446 | Use the C<Net::NNTP> or C<News::NNTPClient> modules, both available from CPAN. | |
| 994 | 1447 | This can make tasks like fetching the newsgroup list as simple as |
| 995 | 1448 | |
| 996 | 1449 | =end original |
| 997 | 1450 | |
| 998 | Net::NNTP モジュールか News::NNTPClient モジュールのいずれかを使います。 | |
| 1451 | C<Net::NNTP> モジュールか C<News::NNTPClient> モジュールのいずれかを使います。 | |
| 999 | これらは両方ともCPANから入手可能です。 | |
| 1452 | これらは両方とも CPAN から入手可能です。 | |
| 1000 | 簡単にニュースグループのリストを取得するような | |
| 1453 | これらは以下のように簡単にニュースグループのリストを取得するような | |
| 1454 | 作業ができます。 | |
| 1001 | 1455 | |
| 1002 | ||
| 1456 | perl -MNews::NNTPClient | |
| 1003 | ||
| 1457 | -e 'print News::NNTPClient->new->list("newsgroups")' | |
| 1004 | 1458 | |
| 1005 | 1459 | =head2 How do I fetch/put an FTP file? |
| 1006 | 1460 | |
| 1007 | (FTPファイルをダウンロード/アップロードするには?) | |
| 1461 | (FTP ファイルをダウンロード/アップロードするには?) | |
| 1008 | 1462 | |
| 1009 | 1463 | =begin original |
| 1010 | 1464 | |
| 1011 | ||
| 1465 | (contributed by brian d foy) | |
| 1012 | available from CPAN) is more complex but can put as well as fetch. | |
| 1013 | 1466 | |
| 1014 | 1467 | =end original |
| 1015 | 1468 | |
| 1016 | ||
| 1469 | (brian d foy によって寄贈されました) | |
| 1017 | Net::FTP(これもCPANで入手可能)はこれよりも複雑ですが、 | |
| 1018 | ダウンロードとアップロードの両方ができます。 | |
| 1019 | 1470 | |
| 1471 | =begin original | |
| 1472 | ||
| 1473 | The C<LWP> family of modules (available on CPAN as the libwww-perl distribution) | |
| 1474 | can work with FTP just like it can with many other protocols. C<LWP::Simple> | |
| 1475 | makes it quite easy to fetch a file: | |
| 1476 | ||
| 1477 | =end original | |
| 1478 | ||
| 1479 | C<LWP> モジュールファミリー (CPAN で libwww-perl 配布として利用可能です) は | |
| 1480 | FTP をその他のプロトコルと同様に扱えます。 | |
| 1481 | C<LWP::Simple> はファイルをダウンロードするのをとても簡単にします: | |
| 1482 | ||
| 1483 | use LWP::Simple; | |
| 1484 | ||
| 1485 | my $data = get( 'ftp://some.ftp.site/some/file.txt' ); | |
| 1486 | ||
| 1487 | =begin original | |
| 1488 | ||
| 1489 | If you want more direct or low-level control of the FTP process, you can use | |
| 1490 | the C<Net::FTP> module (in the Standard Library since Perl 5.8). It's | |
| 1491 | documentation has examples showing you just how to do that. | |
| 1492 | ||
| 1493 | =end original | |
| 1494 | ||
| 1495 | FTP 処理をより直接的に、あるいは低レベルの制御がしたいなら、(Perl 5.8 以降 | |
| 1496 | 標準ライブラリに入っている) C<Net::FTP> モジュールが使えます。 | |
| 1497 | その文書にはこれを行う方法を示すための例が載っています。 | |
| 1498 | ||
| 1020 | 1499 | =head2 How can I do RPC in Perl? |
| 1021 | 1500 | |
| 1022 | (Perl で RPC を行うには | |
| 1501 | (Perl で RPC を行うには?) | |
| 1023 | 1502 | |
| 1024 | 1503 | =begin original |
| 1025 | 1504 | |
| 1026 | ||
| 1505 | (contributed by brian d foy) | |
| 1027 | will be released as part of the DCE-Perl package (available from | |
| 1028 | CPAN). The rpcgen suite, available from CPAN/authors/id/JAKE/, is | |
| 1029 | an RPC stub generator and includes an RPC::ONC module. | |
| 1030 | 1506 | |
| 1031 | 1507 | =end original |
| 1032 | 1508 | |
| 1033 | ||
| 1509 | (brian d foy によって寄贈されました) | |
| 1034 | これは DCE-Perl パッケージ(CPAN から入手可能です)の一部として | |
| 1035 | リリースされるでしょう。 | |
| 1036 | rpcgenスイートがCAPN/authors/id/JAKE/から入手可能です。 | |
| 1037 | これはRPCスタブのジェネレーターであり、RPC::ONCモジュールを含んでいます。 | |
| 1038 | 1510 | |
| 1511 | =begin original | |
| 1512 | ||
| 1513 | Use one of the RPC modules you can find on CPAN ( | |
| 1514 | http://search.cpan.org/search?query=RPC&mode=all ). | |
| 1515 | ||
| 1516 | =end original | |
| 1517 | ||
| 1518 | CPAN ( http://search.cpan.org/search?query=RPC&mode=all ) で見付かる | |
| 1519 | RFC モジュールの一つを使いましょう。 | |
| 1520 | ||
| 1039 | 1521 | =head1 AUTHOR AND COPYRIGHT |
| 1040 | 1522 | |
| 1041 | Copyright (c) 1997-1 | |
| 1523 | Copyright (c) 1997-2010 Tom Christiansen, Nathan Torkington, and | |
| 1042 | All rights reserved. | |
| 1524 | other authors as noted. All rights reserved. | |
| 1043 | 1525 | |
| 1044 | ||
| 1526 | This documentation is free; you can redistribute it and/or modify it | |
| 1045 | ||
| 1527 | under the same terms as Perl itself. | |
| 1046 | may be distributed only under the terms of Perl's Artistic License. | |
| 1047 | Any distribution of this file or derivatives thereof I<outside> | |
| 1048 | of that package require that special arrangements be made with | |
| 1049 | copyright holder. | |
| 1050 | 1528 | |
| 1051 | 1529 | Irrespective of its distribution, all code examples in this file |
| 1052 | 1530 | are hereby placed into the public domain. You are permitted and |
| 1053 | 1531 | encouraged to use this code in your own programs for fun |
| 1054 | 1532 | or for profit as you see fit. A simple comment in the code giving |
| 1055 | 1533 | credit would be courteous but is not required. |
| 1534 | ||
| 1535 | =begin meta | |
| 1536 | ||
| 1537 | Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> | |
| 1538 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-) | |
| 1539 | Status: completed | |
| 1540 | ||
| 1541 | =end meta |