pyblosxomのSVN trunkにcheck_javascriptプラグインが追加されてた!
posted by jun-g at 金, 15 12月 2006 03:30 JST
昨日、pyblosxomのSVN trunkにcheck_javascriptプラグインが新たに登録されてた。どうもJavaScriptを利用したコメントスパム対策用のプラグインみたい。という事は、こいつを利用すればMagicWordプラグインは不要、さらにtrackbackプラグインへの修正も不要って事かー!ムホムホ!!という事で早速試してみた。
まずはいつも通りcheck_javascript.pyをpluginsディレクトリにコピーして、config.pyを編集してプラグインがロードされるように設定。そして、コメントフォーム用のflavourであるcomment-form.htmlを、trunkの雛型を参考にして以下の通り修正。
--- comment-form.html.orig Sun Oct 15 02:59:40 2006
+++ comment-form.html Fri Dec 15 03:00:11 2006
@@ -3,7 +3,7 @@
<div class="blosxomCommentForm">
<form method="post" action="$base_url/$file_path.html#commentMessage" id="comments_form">
<fieldset>
-<input type="hidden" name="secretToken" value="pleaseDontSpam" />
+<input type="hidden" name="secretToken" id="secretTokenInput" value="pleaseDontSpam" />
<input name="parent" type="hidden" value="$file_path" />
<input name="title" type="hidden" value="$title" />
<label class="commentForm">Name</label><br />
@@ -21,6 +21,11 @@
<input name="submit" type="submit" value="Post" />
</fieldset>
</form>
+<script type="text/javascript"><!--
+// used by check_javascript.py. this is almost entirely backwards compatible,
+// back to 4.x browsers.
+document.getElementById("secretTokenInput").value = "$blog_title";
+//--></script>
</div> <!-- ends blosxomCommentForm div -->
</div>
</div> <!-- ends blosxomComments div -->
パラメータ「secretTokenInput」の値にJavaScriptで$blog_titleの値を設定し、プラグイン側のcb_comment_reject()で値をチェックする、という仕組みらしい。お手軽やね。あ、でもJavaScript使うって事は、テキストブラウザや古いブラウザからはコメント投稿できないって事かー!ま、いいか。
という事で、簡単さに惹かれてこいつを導入する事に決定。効果の程はこれいかに。
trunkのcomments plugin
posted by jun-g at 火, 12 12月 2006 03:00 JST
先日のtrackback pluginのパッチは無事に取り込まれた模様。よかった。
そのパッチを作る際、trunkのcomments.pyを軽く見たんやけど、なんかメール送信時の非ASCII文字を受け付けない問題とか色々修正されてるっぽかったので、近々試してみないとなぁと思ってたら、shunuhsさんがtrunkに入れ替えた上にパッチを書いて、しかもtb spam用のプラグインまで作ってた。素晴らしいっす。仕事早いっす。動作実績があると心強いので、早速僕もtrunkのcomments/trackback pluginに入れ替える事にした。最近コメントスパムに悩まされていたので、ついでにMagicWord pluginも導入することに。
が、その前にshunuhsさんが「メールが飛ばない」と言われている問題を調べてみる事にした。テスト環境のcomments.pyをtrunkのものに入れ替えて試してみると、pyblosxomのエラーログに
2006-12-12 00:07:34,909 [ERROR] comments: error sending email: ['Traceback (most recent call last):\n', ' File "/pub/www/pyblosxom/plugins/comments.py", line 524, in send_email\n msg=body)\n', ' File "/usr/local/lib/python2.4/smtplib.py", line 692, in sendmail\n (code,resp) = self.data(msg)\n', ' File "/usr/local/lib/python2.4/smtplib.py", line 485, in data\n q = quotedata(msg)\n', ' File "/usr/local/lib/python2.4/smtplib.py", line 193, in quotedata\n re.sub(r\'(?:\\r\\n|\\n|\\r(?!\\n))\', CRLF, data))\n', ' File "/usr/local/lib/python2.4/sre.py", line 142, in sub\n return _compile(pattern, 0).sub(repl, string, count)\n', 'TypeError: expected string or buffer\n']
というのが出てた。どうもメール送信時にエラーになってるっぽい。で、なんとなくピンときて入れた修正が以下。
--- comments.py.orig Tue Dec 12 01:52:47 2006
+++ comments.py Tue Dec 12 02:36:47 2006
@@ -521,7 +521,7 @@
server = smtplib.SMTP(config['comment_smtp_server'])
server.sendmail(from_addr=email,
to_addrs=config['comment_smtp_to'],
- msg=body)
+ msg=body.as_string())
server.quit()
except Exception, e:
予想適中、無事にメール送信できるようになった。しかーし!現状のcomments.pyの作りだと、メールヘッダに設定されるべき「From」「To」「Subject」がメール本文に記載されるという超手抜き仕様。現状だとこんな本文のメールが来る。
From: from_at_aemonfreaks.com
To: to_at_daemonfreaks.com
Date: Mon, 11 Dec 2006 16:20:32 -0000
Subject: comment by TEST
Name: TEST
URL:
Hostname: localhost.daemonfreaks.local (192.168.0.21)
Entry URL: http://localhost/blog/200611060000
Comment location: /pub/www/pyblosxom/entries/comments/200611060000-1165854032.63.cmt
Hello, world.
しかも件名が空。イケてない。先頭の4行は明らかにメールヘッダにあるべき。なので、以前自分で修正したやつと同様の修正を今回も入れる事にした。修正内容は以下のとおり。
--- comments.py.orig Tue Dec 12 01:52:47 2006
+++ comments.py Tue Dec 12 01:48:48 2006
@@ -475,13 +475,9 @@
comment_dir = os.path.join(config['comment_dir'], entry['absolute_path'])
# create the message
+ from email.Header import Header
from email.MIMEText import MIMEText
message = []
- message.append("From: %s" % email)
- message.append("To: %s" % config["comment_smtp_to"])
- message.append("Date: %s" % formatdate(float(comment['pubDate'])))
- message.append("Subject: comment by %s" % author)
- message.append("")
message.append("Name: %s" % author)
if comment.has_key('email'):
message.append("Email: %s" % comment['email'])
@@ -498,7 +494,13 @@
body = '\n'.join(message)
body = MIMEText(body.encode('utf-8'), 'plain', 'utf-8')
-
+ subj = "comment by %s" % author
+ subj = Header(subj.encode("utf-8"), "utf-8")
+ body["Subject"] = subj
+ body["From"] = config["comment_smtp_from"]
+ body["To"] = config["comment_smtp_to"]
+ body["Date"] = formatdate(float(comment['pubDate']))
+
if (config.has_key('comment_mta_cmd')):
argv = [config['comment_mta_cmd'],
'-s',
@@ -506,7 +508,7 @@
config['comment_smtp_to']]
# TODO: switch to subprocess when we can require python 2.4
process = popen2.Popen3(argv, capturestderr=True)
- process.tochild.write(body)
+ process.tochild.write(body.as_string())
process.tochild.close()
process.wait()
stdout = process.fromchild.read()
@@ -521,7 +523,7 @@
server = smtplib.SMTP(config['comment_smtp_server'])
server.sendmail(from_addr=email,
to_addrs=config['comment_smtp_to'],
- msg=body)
+ msg=body.as_string())
server.quit()
except Exception, e:
これで「Subject」「From」「To」(「Date」はオマケ)が正しくメールヘッダに設定されるようになった。ちなみに「comment_mta_cmd」を使用してメール送信を行う場合の動作は未確認なので、どなたか試してみてください…。
と、ここまで調べたところで時間切れになってしまった。続きは明日以降で。Magic Wordとtb_spam.pyの動作確認をしてから全部導入することにしよう。
買い物とか
posted by jun-g at 日, 10 12月 2006 18:12 JST
昨日は嫁といっしょにものすごい久しぶりにアメ村に買い物に行ってきた。
まず、友達に教えてもらった「POKER FACE」という堀江の眼鏡屋に行って眼鏡を物色。最近すっかり目が悪くなって、8年前に作った眼鏡の度数が全然合わなくなってしまっていたので。色々試着した結果、Starck Eyesというブランドの眼鏡が気に入ったので購入。ヒンジ部分が全方向に曲がるハイテクな作りで、フィット感抜群。出来上がりは来週とのことで、今から楽しみ。
次に行き着けのルームエイチ(クラブ/レイヴウェア専門店)で服を物色。前から気になってたブランド「ブロス」のTシャツが入荷していたので、入荷していた3種類共購入。そして嫁に勧められたサイバードッグのベストと、サイズを計るために何気に試着したサイバードッグのジャージを購入。あと、フックが大量についたラバーのベルトも購入。実はこれが一番欲しかった。
で、夕方から散髪の予約を入れていたので、美容室に移動。いつもどおり美容師の友達におまかせで切ってもらう。今回もいい感じにアシンメトリーなモヒカンスタイル。そろそろ部分的にカラーを入れるべきか悩むな。
てな感じで外出終了。服とか買いに出たのは久々だったので楽しかった。10万近く使ったのでノートパソコンを買うために貯めてた貯金が無くなってしまった気がするけど(゚ε゚)キニシナイ!!