WordPressでのpngリサイズって対応していないの?

pngのスクリーンショットをWindows Live Writerから(XMLRPC経由)WordPress 3.2.1-jaに登録しようとしたら、XML-RPCで登録できないというエラーが・・・試しにpngをgifに変更して登録するとうまくいく・・・

なぜだ?と思って調査。

- ./wp-includes/media.php

254行目のimagecreatefromstring()でApacheがabortしてた。

    function wp_load_image( $file ) {
            if ( is_numeric( $file ) )
                    $file = get_attached_file( $file );

            if ( ! file_exists( $file ) )
                    return sprintf(__('File “%s” doesn’t exist?'), $file);

            if ( ! function_exists('imagecreatefromstring') )
                    return __('The GD image library is not installed.');

            // Set artificially high because GD uses uncompressed images in memory
            @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );
            $image = imagecreatefromstring( file_get_contents( $file ) );

            if ( !is_resource( $image ) )
                    return sprintf(__('File “%s” is not an image.'), $file);

            return $image;
    }

GD/libpng経由でのリサイズ用png画像生成時に失敗するようだ。 こまりましたな。とりあえずgifで運用します。

Posted in PHP, 未分類 | Leave a comment

chromeのキャッシュ保存場所変更

我が家のメインPCのCドライブにはSSDを使っていますが、google chromeはデフォルトでC:\Users\(ユーザー名)\AppData\Local\Google\Chrome\User Data\Default\Cacheにキャッシュを作るため、ごりごりSSDに書き込みアクセスが行ってしまいます。

これをほかドライブに移動させるTIPSですが、起動オプションを明示するだけでできるんですね。

WS000017-8bit

–disk-cache-dir=”D:\tmp\chrome”がポイントです。

Posted in Windows | Leave a comment

CakePHP のquery()メソッドの動き

CakePHP 1.3を使っていますが、query()メソッドの動きが気になったのでメモ。

query()メソッドは、select for update等CakePHPのモデルでは提供できないSQLを発行する際によく使いますが、引数の渡し方によってクエリキャッシュが効く・効かないの違いがありました。

クエリキャッシュ有り

BIND変数を引き渡す場合で第3引数がないとクエリキャッシュが有効になってしまいます。これに気がつか無い人、結構いるのでは?

$this->query('select id from user where id = ? for update', array(1));

クエリキャッシュ無し

第3引数がキャッシュ利用有無になるので、falseを渡せばクエリキャッシュは効きません。

$this->query('select id from user where id = ? for update', array(1), false);

これ、はまりました。。

ちなみにdbo_source.php(CakePHP 1.3.11)だと以下の用になっています。

    351                 } else {
    352                         if (isset($args[1]) && $args[1] === true) {
    353                                 return $this->fetchAll($args[0], true);
    354                         } else if (isset($args[1]) && !is_array($args[1]) ) {
    355                                 return $this->fetchAll($args[0], false);
    356                         } else if (isset($args[1]) && is_array($args[1])) {
    357                                 $offset = 0;
    358                                 if (isset($args[2])) {
    359                                         $cache = $args[2];
    360                                 } else {
    361                                         $cache = true;
    362                                 }
    363                                 $args[1] = array_map(array(&$this, 'value'), $args[1]);
    364                                 return $this->fetchAll(String::insert($args[0], $args[1]), $cache);
    365                         }
    366                 }
Posted in PHP | Leave a comment

maildropの変数展開とシェル展開

maildropでは以下の展開ルールがあります。

参照ページ: http://www.courier-mta.org/maildropfilter.html

変数展開

Variable substitution
Variable substitution is performed on text literals that's surrounded by double quotation marks. The "$" character, followed by a variable name, is replaced by that variable's contents.

MAILBOX="$HOME/Mailbox"

要するに、ダブルクォートで囲むと$で始まる変数をmaildrop上で展開します。普通ですね。

変数の環境変数への反映

maildropでは、変数を定義すると、環境変数にもセットします。ので、外部コマンド実行時にmaildroprc上で定義した環境変数がそのまま使えますとのことです。

All internal variables are exported back as environment variables when maildrop runs an external command. Changes to internal variables, made by the filter file, are reflected in the exported environment.

これは意外と盲点でしたね。

Posted in Linux | Leave a comment

bashのコメントアウト ON/OFF

bashって、コメントアウトを使う・使わないって設定できるんですね。

コメントアウトを使う(デフォルト)

$ shopt -s interactive_comments
$ echo #asdf#asdf

コメントアウトを無視

$ shopt -u interactive_comments
$ echo #asdf#asdf
#asdf#asdf

参考(shopt)

$ shopt
cdable_vars     off
cdspell         off
checkhash       off
checkwinsize    on
cmdhist         on
dotglob         off
execfail        off
expand_aliases  on
extdebug        off
extglob         off
extquote        on
failglob        off
force_fignore   on
gnu_errfmt      off
histappend      off
histreedit      off
histverify      off
hostcomplete    on
huponexit       off
interactive_comments    on
lithist         off
login_shell     on
mailwarn        off
no_empty_cmd_completion off
nocaseglob      off
nocasematch     off
nullglob        off
progcomp        on
promptvars      on
restricted_shell        off
shift_verbose   off
sourcepath      on
xpg_echo        off
Posted in Linux, 未分類 | Leave a comment

IEの互換モード

IEの互換モードについて調べていてわかったことがあったので、メモ。

IEの互換モードは、設定するとIE7のUser-Agentでアクセスします。ただIE8の互換モード(Windows XP SP3)の場合、favicon取得時だけIE8のまんまなんですよね。

Windows7 + IE9の互換モードだとfaviconとるときもIE7のまんま。

おかしいですね。

IE9の場合

Windows7 SP1 + IE9(標準)

www.example.com 192.0.2.1 - - [19/Sep/2011:21:13:54 +0900] "GET /wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css?ver=3.0.83c HTTP/1.1" 200 1337 "http://www.example.com/" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)" 565 1636
www.example.com 192.0.2.1 - - [19/Sep/2011:21:14:53 +0900] "GET /favicon.ico HTTP/1.1" 200 20 "-" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)" 206 290

Windows7 SP1 + IE9(互換)

www.example.com 192.0.2.1 - - [19/Sep/2011:21:12:41 +0900] "GET /wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shThemeDefault.css?ver=3.0.83c HTTP/1.1" 304 - "http://www.example.com/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.1; InfoPath.2; InfoPath.3; .NET4.0C)" 765 171
www.example.com 192.0.2.1 - - [19/Sep/2011:21:12:35 +0900] "GET /favicon.ico HTTP/1.1" 200 20 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.1; InfoPath.2; InfoPath.3; .NET4.0C)" 340 290

favicon.ico取得にもMSIE 7.0となっていることがわかる。

IE8の場合

Windows XP SP3 + IE8(標準)

www.example.com 192.0.2.2 - - [19/Sep/2011:21:17:19 +0900] "GET /wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css?ver=3.0.83c HTTP/1.1" 200 1337 "http://www.example.com/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)" 532 1636
www.example.com 192.0.2.2 - - [19/Sep/2011:21:17:19 +0900] "GET /favicon.ico HTTP/1.1" 200 20 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)" 402 290

Windows XP SP3 + IE8(互換)

www.example.com 192.0.2.2 - - [19/Sep/2011:21:17:47 +0900] "GET /wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shThemeDefault.css?ver=3.0.83c HTTP/1.1" 200 667 "http://www.example.com/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0)" 564 965
www.example.com 192.0.2.2 - - [19/Sep/2011:21:17:47 +0900] "GET /favicon.ico HTTP/1.1" 200 20 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)" 401 290

通常のコンテンツ取得はMSIE 7.0なのに、favicon.ico取得がMSIE 8.0となっている。

Posted in Windows | Leave a comment

mailmanのバウンスメッセージ処理について

mailmanのバウンスメッセージ処理について興味があったので調べてみました。

はじめに、mailmanにはML購読ユーザにメールが一定期間届かない場合、自動退会する機能がついていますが、その処理はユーザからのバウンスメッセージを元に動作します。

「ユーザからのバウンスメッセージを元に動作する」と一口に書けばそれまでですが、インターネットでのバウンスメッセージには様々な形式があり、それぞれのバウンスメッセージを正しく解析するのは容易ではありません。sendmail/qmail/postfix/yahoo/exchange等様々がMTAが応答するバウンスメッセージはばらばらですから。

で、mailmanがこれら雑多なバウンスメッセージをどうやって判定しているかというと、MTAが出す個別のバウンスメッセージにそれぞれ対応しているようです。

実際の処理を見てみましょう。

これらバウンスメッセージの処理はBounceRunnerというmailmanへのバウンスメッセージを解析するデーモンプログラムで処理されています。

BounceRunnerではバウンスメールを解析し、ループ等の検出を行った後に、それぞれのMTAに対応したバウンスメッセージの処理にディスパッチしています。

- Mailman/Queue/BounceRunner.py

    227         # Try VERP detection first, since it's quick and easy
    228         addrs = verp_bounce(mlist, msg)
    229         if addrs:
    230             # We have an address, but check if the message is non-fatal.
    231             if BouncerAPI.ScanMessages(mlist, msg) is BouncerAPI.Stop:
    232                 return
    233         else:
    234             # See if this was a probe message.
    235             token = verp_probe(mlist, msg)
    236             if token:
    237                 self._probe_bounce(mlist, token)
    238                 return
    239             # That didn't give us anything useful, so try the old fashion
    240             # bounce matching modules.
    241             addrs = BouncerAPI.ScanMessages(mlist, msg)
    242             if addrs is BouncerAPI.Stop:
    243                 # This is a recognized, non-fatal notice. Ignore it.
    244                 return

この231/241行目に出てくるBouncerAPI.ScanMessages()というメソッドがポイントです。
このメソッドは、mailmanへのバウンスメッセージかどうかをMTA毎に解析します。(実際にはバウンスメッセージに含まれているバウンス元ユーザを抽出する処理を行っています)

- Mailman/Bouncers/BouncerAPI.py

     61 # msg must be a mimetools.Message
     62 def ScanMessages(mlist, msg):
     63     for module in BOUNCE_PIPELINE:
     64         modname = 'Mailman.Bouncers.' + module
     65         __import__(modname)
     66         addrs = sys.modules[modname].process(msg)
     67         if addrs:
     68             # Return addrs even if it is Stop. BounceRunner needs this info.
     69             return addrs
     70     return []

63行目-69行目でMTA毎の個別処理についてループしていますが、このループ一覧は以下になります。

- Mailman/Bouncers/BouncerAPI.py

     39 BOUNCE_PIPELINE = [
     40     'DSN',
     41     'Qmail',
     42     'Postfix',
     43     'Yahoo',
     44     'Caiwireless',
     45     'Exchange',
     46     'Exim',
     47     'Netscape',
     48     'Compuserve',
     49     'Microsoft',
     50     'GroupWise',
     51     'SMTP32',
     52     'SimpleMatch',
     53     'SimpleWarning',
     54     'Yale',
     55     'LLNL',
     56     'AOL',
     57     ]

これを見る限り、DSN(Delivery Status Notifycation)から始まり、qmail->postfix->yahoo …と個別に判定を加えているようです。

試しにDSNを見てみましょう。PGをざっと見る限り、マルチパートで且つ、DSNの書式に則った応答の場合は、バウンスメッセージからバウンス応答したユーザ情報を抜き出す作りになっているようです。
- Mailman/Bouncers/DSN.py

     64             for header in ('original-recipient', 'final-recipient'):
     65                 for k, v in msgblock.get_params([], header):
     66                     if k.lower() == 'rfc822':
     67                         foundp = True
     68                     else:
     69                         params.append(k)
     70                 if foundp:
     71                     # Note that params should already be unquoted.
     72                     addrs.extend(params)
     73                     break
     74                 else:
     75                     # MAS: This is a kludge, but SMTP-GATEWAY01.intra.home.dk
     76                     # has a final-recipient with an angle-addr and no
     77                     # address-type parameter at all. Non-compliant, but ...
     78                     for param in params:
     79                         if param.startswith('<') and param.endswith('>'):
     80                             addrs.append(param[1:-1])

MTA毎に個別の処理を書いてはいますが、本当に個別となる部分だけを抽出して書いているので、かなりきれいなプログラムだと思いました。すごいな、mailman。

Posted in Linux | Leave a comment

Adobe Flash Playerの手動アップデート

どうも、proxyを通してAdobe Flash Playerのアップデートができないようだ。

前からこうだっけ・・・

でもバージョンががんがん上がるし、脆弱性もばんばん見つかるので、手をこまねくわけにはいかず、手動でバージョンアップする方法をメモ。

以下のURLから最新のAdobe Flash Playerのバイナリを直接ダウンロードしてから、セットアップすればよいという結論になった。

Archived Flash Player versions

Posted in 未分類 | Leave a comment

CentOS6 ext4でのファイルシステム拡張

ファイルサーバ用途で利用しているCentOS6の特定パーティションが一杯になってきたので、VM上でディスクを拡張し、OS起動後オンラインでファイルシステム拡張してみました。

リサイズ前

[root@host1 ~]# df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/mapper/vg_host1-lv_root
                       34G  5.0G   27G  16% /
tmpfs                 1.9G   88K  1.9G   1% /dev/shm
/dev/sda1             485M   48M  412M  11% /boot
/dev/sdb               99G   86G  7.6G  92% /data

リサイズ中

100GBを200GBに拡張しました。

[root@host1 ~]# resize2fs /dev/sdb
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/sdb is mounted on /data; on-line resizing required
old desc_blocks = 7, new_desc_blocks = 13
Performing an on-line resize of /dev/sdb to 52428800 (4k) blocks.
The filesystem on /dev/sdb is now 52428800 blocks long.

拡張中はだんだん容量が増えていきます。

[user1@host1 backup]$ df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/mapper/vg_host1-lv_root
                       34G  5.0G   27G  16% /
tmpfs                 1.9G   88K  1.9G   1% /dev/shm
/dev/sda1             485M   48M  412M  11% /boot
/dev/sdb              153G   86G   59G  60% /data

簡単でオンラインに拡張できるので、すばらしいですね。ただ拡張中はI/O waitが100%になるので、実際の運用ではタイミングを見計らわないと痛い目に遭いそうだと言うことはわかりました。

Posted in Linux | Leave a comment

IPv6 + SOCKS 5 Proxy

SSH PortForwarding(PortForwarderを利用)のSOCKS5 Proxyを利用して、FirefoxからIPv6のプロキシを実現しようとしたが、うまくいかなかった。

調査したところ、FirefoxにFoxyProxyプラグインを導入して、特定のIPv6サイトだけローカルホストのSOCKS 5プロキシを使うと設定したら、これがばっちり動いた。

こんな使い方ができるなんて。

Posted in Windows | Leave a comment