キーボードのバックライト(笑)がかっこいい。
PCで一番重要なもの。
それはOSでもソフトウエアでもなくキーボードです。
前回の黒MacBookがかなりよかったので今回もMacBookにしましたが、新し
今回のMacBookではWindowsも使わないでみます。
「CSVファイルで落としてください」という管理機能はよくある普通のリクエストです。
が、PHPが.htaccessで
php_value auto_prepend_file default-header.php
とかしているとすべてのURLのPHPスクリプトの実行前に、default-hea
そんなときは、auto_prepend_fileで指定されたスクリプトの先頭で、
<?php ob_start(); //output buffering
をやっておきます。条件によってCSV(など)のダウンロードをするときには、
<?php ob_clean(); //output buffer clear header("Cache-Control: public"); header('Content-type: application/x-csv'); header('Content-Disposition: attachment; filename="address.csv"');
見たいにすればいいのではないでしょうか?
* 追記: exit() とかで抜けないとauto_append_fileで指定されたPHPスクリプトが動
hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ python manage.py dumpdata auth > auth.json hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "drop database tohyo" | sudo mysql hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ more ../mysql/create.sh echo "CREATE DATABASE IF NOT EXISTS tohyo DEFAULT CHARACTER SET utf8" | sudo mysql echo "grant all privileges on tohyo.* to 'tohyo'@'localhost' identified by 'tohyo'" | sudo mysql hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ ../mysql/create.sh hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ python manage.py syncdb Creating table auth_permission Creating table auth_group Creating table auth_user Creating table auth_message Creating table django_content_type Creating table django_session Creating table django_site Creating table django_admin_log Creating table microblog_tag Creating table microblog_note Creating table microblog_profile You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (Leave blank to use 'hdknr'): admin E-mail address: admin@hoge.com Password: Password (again): Superuser created successfully. Installing index for auth.Permission model Installing index for auth.Message model Installing index for admin.LogEntry model Installing index for microblog.Note model Installing index for microblog.Profile model hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "select * from auth_group " | sudo mysql tohyo -t hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ python manage.py loaddata auth.json Installing json fixture 'auth' from absolute path. Installed 35 object(s) from 1 fixture(s) hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "select * from auth_group " | sudo mysql tohyo -t +----+--------+ | id | name | +----+--------+ | 1 | member | +----+--------+ hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ cp auth.json microblog/fixture/initial_data.json hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "drop database tohyo" | sudo mysql hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ ../mysql/create.sh hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ python manage.py syncdb hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "select * from auth_group " | sudo mysql tohyo -t ”アプリケーション”/fixture/initial_data.jsonはだめのようです。
hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !610 echo "drop database tohyo" | sudo mysql hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !611 ../mysql/create.sh hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !612 python manage.py syncdb Creating table auth_permission Creating table auth_group Creating table auth_user Creating table auth_message Creating table django_content_type Creating table django_session Creating table django_site Creating table django_admin_log Creating table microblog_tag Creating table microblog_note Creating table microblog_profile You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (Leave blank to use 'hdknr'): admin E-mail address: admin@hdknr.vpc Password: Password (again): Superuser created successfully. Installing index for auth.Permission model Installing index for auth.Message model Installing index for admin.LogEntry model Installing index for microblog.Note model Installing index for microblog.Profile model Installing json fixture 'initial_data' from absolute path. Installed 35 object(s) from 1 fixture(s) hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "select * from auth_group " | sudo mysql tohyo -t +----+--------+ | id | name | +----+--------+ | 1 | member | +----+--------+ プロジェクト直下に置くとよいみたいです。
これとは別にsqlも用意しておいた方がいいような気がしますがどうなんでしょうか。デ
ちなみに、
hdknr@deb09:~/bitbucket/tohyo/trunk/tohy
で読みやすくしたほうがいいでしょうね。
ちなみに、多くのauthのデータはデフォルトのsyncdbで追加されるので、以下
hdknr@deb09:~/bitbucket/tohyo/trunk/tohy
[
{
"pk": 1,
"model": "auth.group",
"fields": {
"name": "member",
"permissions": []
}
}
]
hdknr@deb09:~/bitbucket/tohyo/trunk/tohy
echo "drop database tohyo" | sudo mysql
hdknr@deb09:~/bitbucket/tohyo/trunk/tohy
../mysql/create.sh
hdknr@deb09:~/bitbucket/tohyo/trunk/tohy
python manage.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table microblog_tag
Creating table microblog_note
Creating table microblog_profile
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'hdknr'): admin
E-mail address: admin@hdknr.vpc
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for admin.LogEntry model
Installing index for microblog.Note model
Installing index for microblog.Profile model
Installing json fixture 'initial_data' from absolute path.
Installed 1 object(s) from 1 fixture(s)
hdknr@deb09:~/bitbucket/tohyo/trunk/tohy
echo "select * from auth_group " | sudo mysql tohyo -t
+----+--------+
| id | name |
+----+--------+
| 1 | member |
+----+--------+
connectionMade()でダンプしても証明書情報がまだ来ていないようです。
#!/usr/bin/python import sys from twisted.internet.protocol import ClientFactory from twisted.protocols.basic import LineReceiver from twisted.internet import ssl, reactor from OpenSSL import SSL, crypto import hashlib class SslClient(LineReceiver): def dump(self): print str(dir(crypto)) cert = self.transport.socket.get_peer_certificate() #X509 if cert != None: print "X.509:subject:",str(cert.get_subject()) print "X.509:issuer:",str(cert.get_issuer()) print "X.509:pubkey:",str(cert.get_pubkey()) print "X.509:serial:",str(cert.get_serial_number()) print "X.509:version:",str(cert.get_version()) ft=[crypto.FILETYPE_PEM,crypto.FILETYPE_ASN1] out=[crypto.dump_certificate(x,cert) for x in ft ] print "PEM" print out[0] def connectionMade(self): self.count=0 print "connected" # self.dump() self.sendLine("GET / HTTP/1.0\n\n") def connectionLost(self, reason): print 'connection lost (protocol)' def lineReceived(self,line): if self.count ==0: self.dump() self.count = self.count + 1 print "receive:", line # def dataReceived(self,data): # print "data received:" class SslClientFactory(ClientFactory): protocol = SslClient def clientConnectionFailed(self, connector, reason): print 'connection failed:', reason.getErrorMessage() reactor.stop() def clientConnectionLost(self, connector, reason): print 'connection lost:', reason.getErrorMessage() reactor.stop() def main(): factory = SslClientFactory() cname ="www.nri.co.jp" #"trac.hdknr.com" reactor.connectSSL(cname,443, factory, ssl.ClientContextFactory()) reactor.run() if __name__ == '__main__': main()
実行
hdknr@deb09:~/tmp$ python ssl_client.py > test.log
確認
connected
['Error', 'FILETYPE_ASN1', 'FILETYPE_PEM', 'NetscapeSPKI', 'NetscapeSPKIType', 'PKCS12Type'
, 'PKCS7Type', 'PKey', 'PKeyType', 'TYPE_DSA', 'TYPE_RSA', 'X509', 'X509Extension', 'X509Ex
tensionType', 'X509Name', 'X509NameType', 'X509Req', 'X509ReqType', 'X509StoreType', 'X509T
ype', 'X509_verify_cert_error_string', '_C_API', '__doc__', '__file__', '__name__', 'dump_c
ertificate', 'dump_certificate_request', 'dump_privatekey', 'load_certificate', 'load_certi
ficate_request', 'load_pkcs12', 'load_pkcs7_data', 'load_privatekey']
X.509:subject: <X509Name object '/C=JP/ST=Tokyo/L=Chiyoda-ku/O=Nomura Research Institute, L
td./OU=Corporate Communications Department 2/OU=Terms of use at www.verisign.co.jp/rpa (c)
04/OU=Authenticated by VeriSign Japan K.K./OU=Member, VeriSign Trust Network/CN=www.nri.co.
jp'>
X.509:issuer: <X509Name object '/O=VeriSign Trust Network/OU=VeriSign, Inc./OU=VeriSign Int
ernational Server CA - Class 3/OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 V
eriSign'>
X.509:pubkey: <PKey object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YInTyZowIDAQABo4IBeTCCAXUwCQYDVR0TBAIwADCBrAYDVR0g
BIGkMIGhMIGeBgtghkgBhvhFAQcBATCBjjAoBggrBgEFBQcCARYcaHR0cHM6Ly93
d3cudmVyaXNpZ24uY29tL0NQUzBiBggrBgEFBQcCAjBWMBUWDlZlcmlTaWduLCBJ
bmMuMAMCAQEaPVZlcmlTaWduJ3MgQ1BTIGluY29ycC4gYnkgcmVmZXJlbmNlIGxp
YWIuIGx0ZC4gKGMpOTcgVmVyaVNpZ24wEQYJYIZIAYb4QgEBBAQDAgZAMCgGA1Ud
JQQhMB8GCWCGSAGG+EIEAQYIKwYBBQUHAwEGCCsGAQUFBwMCMDQGCCsGAQUFBwEB
BCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AudmVyaXNpZ24uY29tMEYGA1Ud
HwQ/MD0wO6A5oDeGNWh0dHA6Ly9jcmwudmVyaXNpZ24uY29tL0NsYXNzM0ludGVy
bmF0aW9uYWxTZXJ2ZXIuY3JsMA0GCSqGSIb3DQEBBAUAA4GBALYhYXknbFyQndKr
dRSN351NMcvsvbwVp7DCrRYQZfTFbvZKKICTBW1Y3xcUkTJodzw0OadTFr/0egVz
K9HwTGVUIUmtrL011t3T4fNslEsDoL3Af+/wFG8qdpCgH1pRqBQWGIwKPPNZ+NUe
M6pMCtAc4Yhma8qSmomlmwV6Q2ir
-----END CERTIFICATE-----receive: HTTP/1.1 200 OK
receive: Date: Wed, 18 Mar 2009 07:46:46 GMT
receive: Server: Apache
receive: Last-Modified: Wed, 18 Mar 2009 01:32:14 GMT
receive: ETag: "baae-a73b8380"
receive: Accept-Ranges: bytes
receive: Content-Length: 47790
receive: Connection: close
receive: Content-Type: text/html
receive:
connection lost (protocol)
connection lost: Connection was closed cleanly.
”Postfix:DebianでさらからMailJailの環境を作る - Windows Live"だけでは不足でした。(trac)
Djangoでメール送信。
hdknr@deb09:~/tohyo/tohyo/trunk/tohyo$ more microblog/mails.py from django.core.mail import send_mail def test(): print send_mail('aaaaaaaaaaaaaa_subject____','message','tohyo@hdknr.test',['test@hdknr.test'],fail_silently=False)
実行するとエラー
Mar 14 03:20:19 deb09 postfix/smtp[3609]: 5CA881DD587: to=<mailjail@mailjail.local>, orig_to=<test@hdknr.test>, relay=none, delay=0.29, delays=0.16/0.05/0.07/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=mailjail.local type=A: Host not found)
なので、/etc/postfix/main.cfの修正
virtual_alias_maps = proxy:mysql:/etc/postfix/MySQL/mysql/vir
tual_alias_maps.cf,hash:/etc/postfix/virtual-test
deb09:/etc/postfix# more virtual-test
@hdknr.test mailjail@mailjail.local
再度エラー。
Mar 14 03:20:19 deb09 postfix/smtp[3609]: B17571DD5CC: to=<mailjail@mailjail.local>, orig_to=<tohyo@hdknr.test>, relay=none, delay=0.04, delays=0.02/0.01/0/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=mailjail.local type=A: Host not found)
Mar 14 03:20:19 deb09 postfix/qmgr[3601]: B17571DD5CC: removed
/etc/hosts修正。
deb09:/etc/postfix# vi /etc/hosts
127.0.1.1 deb09.hdknr.local deb09 mailjail.local
それでもエラー。
Mar 14 03:23:28 deb09 postfix/smtp[3625]: AA87C1DD5CC: to=<mailjail@mailjail.local>, orig_to=<tohyo@hdknr.test>, relay=none, delay=0.08, delays=0.07/0.01/0/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=mailjail.local type=A: Host not found)
virtual に “mailjail.local”を追加する。
deb09:/etc/postfix# echo "insert into domain ( domain,transport) values('mailjail.local','mailjail')" | mysql postfix –t
deb09:/etc/postfix# echo "select * from domain" | mysql postfix -t
+----------------+-------------+---------+-----------+----------+-------+------- ----+----------+---------------------+-- -------------------+--------+
| domain | description | aliases | mailboxes | maxquota | quota | transport | backupmx | created | modified | active |
+----------------+-------------+---------+-----------+----------+-------+------- ----+----------+---------------------+-- -------------------+--------+
| ALL | | 0 | 0 | 0 | 0 | | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | 1 |
| hdknr.vpc | | 10 | 10 | 10 | 0 | virtual | 0 | 2009-03-09 02:13:56 | 2009-03-09 02:13:56 | 1 |
| hdknr.test | | 0 | 0 | 0 | 0 | mailjail | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | 1 |
| mailjail.local | | 0 | 0 | 0 | 0 | mailjail | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 | 1 |
+----------------+-------------+---------+-----------+----------+-------+------- ----+----------+---------------------+-- -------------------+--------+
うまくいきました。
Mar 14 03:30:58 deb09 postfix/pipe[3654]: 252D01DD5CB: to=<mailjail@mailjail.local>, orig_to=<test@hdknr.test>, relay=mailjail, delay=0.16, delays=0.09/0.03/0/0.04, dsn=2.0.0, status=sent (delivered via mailjail service)
hdknr@deb09:~/mailjail/mail$ more *
From tohyo@hdknr.test Sat Mar 14 03:30:58 2009
Return-Path: <tohyo@hdknr.test>
Delivered-To: mailjail@mailjail.local
Received: from deb09.hdknr.local (localhost [127.0.0.1])
by deb09.hdknr.local (Postfix) with ESMTP id 252D01DD5CB
for <test@hdknr.test>; Sat, 14 Mar 2009 03:30:58 +0900 (JST)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Subject: aaaaaaaaaaaaaa_subject____
From: tohyo@hdknr.test
To: test@hdknr.test
Date: Fri, 13 Mar 2009 18:30:58 -0000
Message-ID: <20090313183058.3648.67160@deb09.hdknr.local>
message
とりあえず、urls.pyで以下のようにして実装してみました。
from django.conf.urls.defaults import * from django.http import HttpResponseRedirect from microblog import views LOGIN_URL=('/microblog/login/?next=%s' def action_acl(views,action,allow ): def _action(request,*args,**kwargs): if not request.user.is_authenticated(): return HttpResponseRedirect( LOGIN_URL % request.path) for u in request.user.groups.iterator(): if u in allow: return getattr(views,action)(request,*args,**kwargs) return HttpResponseRedirect( LOGIN_URL % request.path) return _action urlpatterns = patterns('tohyo.microblog.views', (r'^note/' , action_acl(views,'note_index',['member'] )), )
action_acl関数で対象のアクションに対して許可されているロール(groups)を現在のユーザーを持っているかどうかを確認して認証されていない、
あるいはグループに属していない人をログインページに飛ばしています。
こんなんでいいのかな?
Mar 9 03:10:48 deb09 postfix/trivial-rewrite[5593]: fatal: mysql:/etc/postfix/MySQL/mysql/virtual_a
deb09:/etc/postfix/MySQL/mysql# postmap -v mysql:/etc/postfix/MySQL/mysql/virtual_a
postmap: fatal: dict_mkmap_func: unsupported dictionary type: mysql does not allow map creation.
問題はこれか?
Mar 9 03:20:59 deb09 postfix/trivial-rewrite[5628]: warning: connect to mysql server localhost: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
chrootしているのです!
deb09:/etc/postfix/MySQL/mysql# grep proxy /etc/postfix/main.cf
transport_maps =proxy:mysql:/etc/postfix/MySQL/mysql/vi
virtual_transport=proxy:mysql:/etc/postf
virtual_alias_maps = proxy:mysql:/etc/postfix/MySQL/mysql/vir
virtual_mailbox_domains = proxy:mysql:/etc/postfix/MySQL/mysql/vir
virtual_mailbox_maps = proxy:mysql:/etc/postfix/MySQL/mysql/vir
うまくいった。忘れるんだよな。。。。
http_proxy以外にhttps_proxyも必要です。
[hdknr@localhost bin]$ curl -I http://www.msn.com
HTTP/1.0 405 Method Not Allowed
Date: Fri, 06 Mar 2009 05:59:15 GMT
Server: Microsoft-IIS/6.0
P3P: CP="BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo"
S: TK2PTLRENB09
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 3026
X-Cache: MISS from proxy
X-Cache: MISS from proxy
X-Cache: MISS from nrisaf53.index.or.jp
Proxy-Connection: close
[hdknr@localhost bin]$ curl -I https://www.msn.com
curl: (6) Couldn't resolve host 'www.msn.com'
[hdknr@localhost bin]$ vi ~/.proxy
export https_proxy=http://xga00008:H7scJzUh@hoge.enterprois
[hdknr@localhost bin]$ curl -I https://trac.hdknr.com
HTTP/1.0 200 Connection established







