ページ更新: 2012-11-29 (木) (3054日前)
関連: ../Debian4.0, ソフト/Script言語/Python/WSGI (2008-08-26 新規作成) ExtLinkRewriterPlugin - Trac Hacks に関するメモ ExtLinkRewriterPlugin は、Trac の文書に記入した「外部へのサイトへのリンク(ExtLink)」を自動的に「リダイレクタ経由」に書き換える(Rewriter)プラグインである。 Refererヘッダを隠すために用いる。 自前で作ったリダイレクタ (↓)では、アンカーが拾えない(http://host/to?http://discypus.jp/#here の「#here」)のが残念。 アンカーを拾うには、#をエスケープして、リダイレクタ側で戻してやる必要がある? JavaScriptを併用すれば、出来るかも。 目次 [編集]インストール #Trac 0.11.1.ja1 を用いた。 # easy_install http://trac-hacks.org/svn/extlinkrewriterplugin/0.11/ Downloading http://trac-hacks.org/svn/extlinkrewriterplugin/0.11/ Doing subversion checkout from http://trac-hacks.org/svn/extlinkrewriterplugin/0.11/ to /tmp/easy_install-rDbzRu/0.11 Processing 0.11 Running setup.py -q bdist_egg --dist-dir /tmp/easy_install-rDbzRu/0.11/egg-dist-tmp-Hgm8oy zip_safe flag not set; analyzing archive contents... Adding ExtLinkRewriter 0.5 to easy-install.pth file Installed /usr/lib/python2.4/site-packages/ExtLinkRewriter-0.5-py2.4.egg Processing dependencies for ExtLinkRewriter==0.5[編集] 自作Redirector (for WSGI) #このプラグイン用に、Python でリダイレクタを書いてみた。 以下の2種類を作成した:
http://host/go/?http://discypus.jp/ の用にして使う。 どちらも WSGI を使用している:
refresh_redirector.wsgi #meta タグの http-equiv="Refresh" を用いている。
refresh_redirector.wsgi のソースコード: #!/usr/bin/env python # -*- coding: utf-8 -*- def application(environ, start_response): query = environ.get('QUERY_STRING') start_response('200 OK', [('Content-Type', 'text/html')]) return [ '<html>' '<head>', '<meta http-equiv="Refresh" content="%d;URL=%s" />' % (0, query), '</head>', '<body>', '</body>', '</html>', ] if __name__ == '__main__': from wsgiref import simple_server server = simple_server.make_server('', 8080, application) server.serve_forever() Apache httpdの設定例: WSGIScriptAlias /go "C:/Program Files/Apache Software Foundation/Apache2.2/wsgi/refresh_redirector.wsgi" <Location /go> WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Location>[編集] location_redirector.wsgi #Location ヘッダを用いている。
location_redirector.wsgi のソースコード: #!/usr/bin/env python # -*- coding: utf-8 -*- def application(environ, start_response): query = environ.get('QUERY_STRING') start_response('303 See Other', [('Location', query)]) return [] if __name__ == '__main__': from wsgiref import simple_server server = simple_server.make_server('', 8080, application) server.serve_forever() Apache httpdの設定例: WSGIScriptAlias /go "C:/Program Files/Apache Software Foundation/Apache2.2/wsgi/location_redirector.wsgi" <Location /go> WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Location>[編集] trac.ini #Trac の extlinkrewriter プラグインの設定例 [extlinkrewriter] format = /go?%s namespaces = http,https,ftp #target = _blank[編集] TODO #1. リダイレクタでURLを検査したい。 2. 「nginx + wsgi」で動かして、Webサーバからはリバースプロキシでつなげたらどうかな?
|