文章分类 » soft

一段指定附件下载名的apache配置

继续优化

SetEnvIf Request_URI "\/SAVE\/(.*)$" save_file_name="$1"
SetEnvIf Request_URI "\.(jpg|jpeg|png|gif|bmp)$" is_image_file
#除了图片,其他文件直接访问均提示下载,防止上传了js,css,html等不应该被浏览器加载的文件
Header set Content-Disposition attachment env=!is_image_file
Header set Content-Disposition "attachment; filename=%{save_file_name}e" env=save_file_name
RewriteEngine On
RewriteRule ^/(.*)\/SAVE\/.*$ /$1 [L]

——————————————————-
优化一下~

SetEnvIf Request_URI "\/SAVE\/(.*)$" save_file_name="$1"
Header set Content-Disposition "attachment; filename=%{save_file_name}e" env=save_file_name
RewriteEngine On
RewriteRule ^/(.*)\/SAVE\/.*$ /$1 [L]

只需要访问 : ….5_1300238850.jpg/SAVE/我的图片.jpg 就可以了,ie下文件名后面竟然也不会出现“[1]”了~
—————————————-

SetEnvIf Request_URI "_DOWN_NAME_(.*)_DOWN_EXT_(.*)$" save_file_name="$1.$2"
#下面这种ie下有问题
#SetEnvIf Request_URI "_DOWN_NAME_(.*)$" save_file_name="$1"
Header set Content-Disposition "attachment; filename=%{save_file_name}e" env=save_file_name
RewriteEngine On
RewriteRule ^/(.*)\._DOWN_NAME_.*$ /$1 [L]

实现的效果:
假设一个附件上传后的地址是:
http://foo.com/03/21/1bc5b77f3e50b7fbe12c792ee438da45_1300688708.jpg

如果想要指定下载名,则访问:
http://foo.com/03/21/1bc5b77f3e50b7fbe12c792ee438da45_1300688708.jpg._DOWN_NAME_我的图片_DOWN_EXT_jpg

ie下的效果:
screenshot_127.png

chrome下的效果:
screenshot_128.png

FF下的效果,很杯具:
screenshot_129.png

———–
vim->email->wordpress

使用gsasl模拟smtp认证

使用gsasl模拟smtp认证

gsasl -a username --service=smtp -m LOGIN --verbose -c smtp.sina.com 25
Trying `smtp.sina.com'...
220 irxd5-187.sinamail.sina.com.cn ESMTP
EHLO [127.0.0.1]
250-irxd5-187.sinamail.sina.com.cn
250-8BITMIME
250-SIZE 83886080
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
EHLO [127.0.0.1]
250-irxd5-187.sinamail.sina.com.cn
250-8BITMIME
250-SIZE 83886080
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
AUTH LOGIN
334 VXNlcm5hbWU6
eHh4eAo=
334 UGFzc3dvcmQ6
Enter password: 
bGFuc2VkZWh1YQ==
235 #2.0.0 OK Authenticated
客户端认证完成(服务器可信)……
输入应用程序数据(用 EOF 结束输入):
^C

试了一下sina,163,qq,都只支持PLAIN LOGIN两种验证方式。。

———–
post by gmail~

jabberd2源码分析备忘:mio和sx部分

jabberd2的mio和sx目录是灰常重要的两个目录,关系底层逻辑:
mio封装了一套多路io的实现,支持kqueue,epoll,poll,select,可以在configure的时候通过–enable-mio=指定。
sx目录的代码则在mio的上层实现了一条支持插件的逻辑通道,一些非核心xmpp协议都可以通过插件的形式加入,例如sx/compress.c可以实现流的压缩。

代码包装层次比较深,看起来比较绕,所以以c2s目录里的main.c为入口,画了一张c2s与router的第一次写读的流程,当然这里没有错误处理部分。基本上展现了jabberd2的io逻辑。

      +--------------------------------------------------------------+
      | main.c                                                       |
      | 初始化mio和sx                                                |
      | 调用sx_client_init                                           |
      | 调用注册client初始化的插件                                   |
      | 构造stream头                                                 |
      | 调用注册stream头处理的插件                                   |
      | 将头追加到写缓存                                             |
    +-+ 触发event_WANT_WRITE:_sx_event(s, event_WANT_WRITE, NULL);   |
    | |                                                              |
    | | main loop(mio_run())                                         |
    | | while true:                                                  |
 +--|-+>if FD(m,fd)->type == type_NORMAL && MIO_CAN_READ(m,iter)     |
 |  | | 触发:action_READ                                             |
 |  | | 回调:c2s_router_mio_callback                                 |
 |  | | 调用:sx_can_read                                             |
 |  | | 触发:event_READ                                       -------------------------+
 |  | | if 读入.length > 0                                           |                 |
 |  | | 调用注册io读的插件:_sx_chain_io_read(s, out);                |                 |
 |  | | 调用:_sx_process_read(s, out);                               |                 |
 |  | | xml->nad                                                     |                 |
 |  | | 调用注册xml处理的插件                                        |                 |
 |  | | 触发:event_PACKET -|                                         |                 |
 |  | +--------------------+-----------------------------------------+                 |
 |  |                      |                                                           |
 |  |                      |                                                           |
 |  |                      |                                                           |
 |  |                      v                                                           |
 |  | +-----------------------------------------+                                      |
 |  | |  event_PACKET                           |                                      |
 |  | +-----------------------------------------+                                      |
 |  | |  回调:c2s_router_sx_callback            |                                      |
 |  | |  接收到的xml在这里已经被解成nad结构体   |                                      |
 |  | |  正式逻辑开始                           |                                      |
 |  | +-----------------------------------------+                                      |
 |  |                                                                                  |
 |  |                                                                                  |
 |  |                                                                                  |
 |  | +--------------------------------+       +------------------------------+        |
 |  |>  event_WANT_WRITE               | +---> |  event_WRITE                 |        |
 |    +--------------------------------+ |     +------------------------------+        |
 |    | 回调:c2s_router_sx_callback    | |     |  回调:c2s_router_sx_callbac  |        |
 |    | 调用:_mio_write                | |     |  调用:send()将数据送出       |        | 
 |    | 触发:action_WRITE              | |     +------------------------------+        |
 |    | 回调:c2s_router_mio_callback   | |                                             |
 |    | 调用:sx_can_write              | |                                             |
 |    | if 写缓存.length > 0           | |                                             |
 |    | 触发:event_WRITE            -----+                                             |
 |    | endif                          |                                               |
 |    | 触发:event_WANT_READ        -------+                                           |
 |    |                                |   |                                           |
 |    +--------------------------------+   |                                           |
 |                                         |                                           |
 |    +----------------------------------+ |   +-------------------------------+       |
 |    | event_WANT_READ                 <+-+   | event_READ                   <+-------+
 |    +----------------------------------+     +-------------------------------+        
 |    | 回调:c2s_router_sx_callback      |     | 回调:c2s_router_sx_callback   |        
 |    | 调用:_mio_read                   |     | 调用:recv()将数据读入         |        
 +----+-调用:MIO_SET_READ(m, FD(m,fd));  |     |                               |        
      |                                  |     |                               |        
      +----------------------------------+     +-------------------------------+        

-----------
post by gmail~

centos5安装jabberd2备忘

11.29日更正配置文件编辑部份
————————————-
之前已经yum安装过gcc和mysql

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum install expat expat-devel libidn libidn-devel udns udns-devel libgsasl libgsasl-devel openssl openssl-devel mysql-devel
cd ~
mkdir src
mkdir /opt/jabberd
cd src
wget http://codex.xiaoka.com/pub/jabberd2/releases/jabberd-2.2.11.tar.bz2
tar jxvf jabb*
cd jabb*
#初始化mysql
mysql -uroot -pxxxxx < tools/db-setup.mysql
./configure --prefix=/opt/jabberd --enable-mio=epoll --enable-mysql --enable-debug --enable-mio-debug
#因为我是开发之用所以加了调试选项--enable-debug --enable-mio-debug
make
make install
#为启动服务添加一个用户
useradd -d /dev/null jabber
cd /opt/jabberd
chown jabber:jabber -R ./
#然后按照文档改配置文件,下面直接写成sed表达式,方便以后自动化完成:http://www.jabberdoc.org/AdminGuide
#example.com
sed -i "s/\(]*>\)[^<]*/\1example.com/" etc/c2s.xml
#example.com
sed -i "s/\(\)[^<]*/\1example.com/" etc/sm.xml
#存储方式改成mysql
sed -i "s/sqlite<\/module>/mysql<\/module>/" etc/c2s.xml etc/sm.xml
#设置用户名和密码
sed -i "30,\$s/.*<\/user>/DBUSER<\/user>/" etc/c2s.xml etc/sm.xml
sed -i "30,\$s/.*<\/pass>/DBPASS<\/pass>/" etc/c2s.xml etc/sm.xml

安装和配置到此结束,启动一下~
sudo -u jabber bin/jabberd
输出调试信息
sudo -u jabber bin/jabberd -D

———–
post by gmail~

查看域名解析过程

dig命令,很强大~

dig -q www.google.com +trace

; <<>> DiG 9.7.1-P2 <<>> -q www.google.com +trace
;; global options: +cmd
.			517619	IN	NS	d.root-servers.net.
.			517619	IN	NS	k.root-servers.net.
.			517619	IN	NS	m.root-servers.net.
.			517619	IN	NS	a.root-servers.net.
.			517619	IN	NS	f.root-servers.net.
.			517619	IN	NS	j.root-servers.net.
.			517619	IN	NS	h.root-servers.net.
.			517619	IN	NS	l.root-servers.net.
.			517619	IN	NS	b.root-servers.net.
.			517619	IN	NS	c.root-servers.net.
.			517619	IN	NS	i.root-servers.net.
.			517619	IN	NS	g.root-servers.net.
.			517619	IN	NS	e.root-servers.net.
;; Received 228 bytes from 202.106.0.20#53(202.106.0.20) in 44 ms

com.			172800	IN	NS	i.gtld-servers.net.
com.			172800	IN	NS	e.gtld-servers.net.
com.			172800	IN	NS	b.gtld-servers.net.
com.			172800	IN	NS	d.gtld-servers.net.
com.			172800	IN	NS	m.gtld-servers.net.
com.			172800	IN	NS	j.gtld-servers.net.
com.			172800	IN	NS	g.gtld-servers.net.
com.			172800	IN	NS	a.gtld-servers.net.
com.			172800	IN	NS	f.gtld-servers.net.
com.			172800	IN	NS	h.gtld-servers.net.
com.			172800	IN	NS	l.gtld-servers.net.
com.			172800	IN	NS	k.gtld-servers.net.
com.			172800	IN	NS	c.gtld-servers.net.
;; Received 492 bytes from 192.5.5.241#53(f.root-servers.net) in 244 ms

google.com.		172800	IN	NS	ns2.google.com.
google.com.		172800	IN	NS	ns1.google.com.
google.com.		172800	IN	NS	ns3.google.com.
google.com.		172800	IN	NS	ns4.google.com.
;; Received 168 bytes from 192.12.94.30#53(e.gtld-servers.net) in 369 ms

www.google.com.		1200	IN	CNAME	www-g-com-chn.l.google.com.
;; Received 62 bytes from 216.239.34.10#53(ns2.google.com) in 456 ms

———–
post by gmail~