<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>一阁Blog</title>
	
	<link>http://yegle.net</link>
	<description>linux、Android、Networks、PHP，所有我感兴趣的技术……</description>
	<lastBuildDate>Sat, 06 Mar 2010 08:38:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/yegle" /><feedburner:info uri="yegle" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.0/</creativeCommons:license><item>
		<title>OpenVPN连接问题排查</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/H_z7eGX2ld4/</link>
		<comments>http://yegle.net/2010/03/05/debug-openvpn-log/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 04:52:32 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[网络相关]]></category>
		<category><![CDATA[openvpn]]></category>

		<guid isPermaLink="false">http://yegle.net/?p=455</guid>
		<description><![CDATA[OpenVPN相对于PPTP的一大优势，就是有完整的log，可以根据客户端的log来发现无法连接的问题所在。以下为本人的VPN用户经常遇到的问题，希望对其他搭建OpenVPN服务的人有所帮助。
注意：本日志主要用于本人的OpenVPN服务（https://yegle.net/openvpn/）的用户用于自行排查问题用，转载请保留此信息，谢谢:-)
各个平台下OpenVPN连接log所在的位置：
Windows下：如果使用OpenVPN GUI进行连接，默认的log会存放在OpenVPN安装目录下log文件夹。
Linux下：在OpenVPN配置文件中添加一行：log-append /path/to/logfile，连接后/path/to/logfile即为连接log。
Mac OS下：tunnelblick里，Details菜单（感谢@tianyi提供信息:-)）
Android下：tunneldroid里，按menu查看log。
OpenVPN的log文件为普通文本文件，可以用各种文本编辑器，例如记事本、写字板、VIM等工具打开。一般情况下为了方便查看问题所在，建议在OpenVPN的配置文件中添加verb 5，可以在log里输出更多有效信息。
正常连接时，log的最后一行是：
Fri Mar  5 09:58:04 2010 Initialization Sequence Completed
这表明OpenVPN成功建立了连接并成功修改了路由表，已经可以正常使用VPN。
问题1：
Mon Mar 01 21:42:13 2010 us=78000 CreateFile failed on TAP device: \\.\Global\{3D3B7076-EC34-48DE-82A4-B34956532951}.tap
Mon Mar 01 21:42:13 2010 us=78000 All TAP-Win32 adapters on this system are currently in use.
Mon Mar 01 21:42:13 2010 us=78000 Exiting
解答：这个问题仅在Windows上出现。原因未知，怀疑与防火墙软件有关。通常情况下可以通过重启系统解决。如果没有解决的话，可以到OpenVPN安装目录下bin文件夹，依次执行delalltap.bat和addtap.bat，即可解决。注意，如果使用的是Vista/Win7/Win2003Win2008这样的带UAC的Windows系统，需要用管理员权限执行这两个脚本。
问题2：
Thu Dec 03 22:46:07 2009 us=651000 C:\WINDOWS\system32\route.exe ADD 128.0.0.0 MASK 128.0.0.0 [...]]]></description>
			<content:encoded><![CDATA[<p>OpenVPN相对于PPTP的一大优势，就是有完整的log，可以根据客户端的log来发现无法连接的问题所在。以下为本人的VPN用户经常遇到的问题，希望对其他搭建OpenVPN服务的人有所帮助。</p>
<p>注意：本日志主要用于本人的OpenVPN服务（<a href="https://yegle.net/openvpn/">https://yegle.net/openvpn/</a>）的用户用于自行排查问题用，转载请保留此信息，谢谢:-)</p>
<p>各个平台下OpenVPN连接log所在的位置：</p>
<blockquote><p>Windows下：如果使用OpenVPN GUI进行连接，默认的log会存放在OpenVPN安装目录下log文件夹。<br />
Linux下：在OpenVPN配置文件中添加一行：log-append /path/to/logfile，连接后/path/to/logfile即为连接log。<br />
Mac OS下：tunnelblick里，Details菜单（感谢<a href="http://cuitianyi.com/">@tianyi</a>提供信息:-)）<br />
Android下：tunneldroid里，按menu查看log。</p></blockquote>
<p>OpenVPN的log文件为普通文本文件，可以用各种文本编辑器，例如记事本、写字板、VIM等工具打开。一般情况下为了方便查看问题所在，建议在OpenVPN的配置文件中添加verb 5，可以在log里输出更多有效信息。</p>
<p>正常连接时，log的最后一行是：</p>
<blockquote><p>Fri Mar  5 09:58:04 2010 Initialization Sequence Completed</p></blockquote>
<p>这表明OpenVPN成功建立了连接并成功修改了路由表，已经可以正常使用VPN。</p>
<p>问题1：</p>
<blockquote><p>Mon Mar 01 21:42:13 2010 us=78000 CreateFile failed on TAP device: \\.\Global\{3D3B7076-EC34-48DE-82A4-B34956532951}.tap<br />
Mon Mar 01 21:42:13 2010 us=78000 All TAP-Win32 adapters on this system are currently in use.<br />
Mon Mar 01 21:42:13 2010 us=78000 Exiting</p></blockquote>
<p>解答：这个问题仅在Windows上出现。原因未知，怀疑与防火墙软件有关。通常情况下可以通过重启系统解决。如果没有解决的话，可以到OpenVPN安装目录下bin文件夹，依次执行delalltap.bat和addtap.bat，即可解决。注意，如果使用的是Vista/Win7/<del datetime="2010-03-05T04:57:26+00:00">Win2003</del>Win2008这样的带UAC的Windows系统，需要用管理员权限执行这两个脚本。</p>
<p>问题2：</p>
<blockquote><p>Thu Dec 03 22:46:07 2009 us=651000 C:\WINDOWS\system32\route.exe ADD 128.0.0.0 MASK 128.0.0.0 10.7.0.1<br />
Thu Dec 03 22:46:07 2009 us=667000 ROUTE: route addition failed using CreateIpForwardEntry: 拒绝访问。   [status=5 if_index=14]<br />
Thu Dec 03 22:46:07 2009 us=667000 Route addition via IPAPI failed [adaptive]<br />
Thu Dec 03 22:46:07 2009 us=667000 Route addition fallback to route.exe<br />
Thu Dec 03 22:46:07 2009 us=667000 ERROR: Windows route add command failed [adaptive]: returned error code 1 </p></blockquote>
<p>解答：这是在Vista/Win7/<del datetime="2010-03-05T04:57:26+00:00">Win2003</del>Win2008等系统中没有用管理员权限安装及启动OpenVPN GUI造成的，OpenVPN进程没有相应权限修改系统路由表。解决方法是重新用管理员权限安装OpenVPN，并在启动OpenVPN GUI时右键选择使用管理员权限打开。</p>
<p>问题3：</p>
<blockquote><p>Mon Feb  1 18:44:52 2010 us=241882 /system/xbin/bb/route add -net 128.0.0.0 netmask 128.0.0.0 gw 10.7.0.1<br />
Mon Feb  1 18:44:52 2010 us=244293 ERROR: Linux route add command failed: could not execute external program<br />
Mon Feb  1 18:44:52 2010 us=244628 Initialization Sequence Completed</p></blockquote>
<p>解答：这是Android下，Cyanogen Mod和OpenEclair两个ROM，曾经有段时间使用了错误的OpenVPN二进制文件，导致的无法调用busybox添加ip和路由。具体请参考<a href="http://yegle.net/2010/02/25/android-openvpn/">Android上OpenVPN的设置与使用</a>这篇日志，重新安装OpenVPN二进制文件，相应地修复busybox</p>
<p>问题4：</p>
<blockquote><p>Sat Mar 06 16:31:42 2010 us=107000 There are no TAP-Win32 adapters on this system.  You should be able to create a TAP-Win32 adapter by going to Start -> All Programs -> OpenVPN -> Add a new TAP-Win32 virtual ethernet adapter.</p></blockquote>
<p>解答：这个问题在Windows上发生，原因未知。解决方案如log所述：开始->所有程序->OpenVPN->Add a new TAP-Win32 virtual ethernet adapter。如果是Vista/Win7，用管理员权限执行<br />
（待续）</p>
<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/Q0nR3U95xq8POo7tgJlmES-CTYQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/Q0nR3U95xq8POo7tgJlmES-CTYQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Q0nR3U95xq8POo7tgJlmES-CTYQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/Q0nR3U95xq8POo7tgJlmES-CTYQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/H_z7eGX2ld4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2010/03/05/debug-openvpn-log/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://yegle.net/2010/03/05/debug-openvpn-log/</feedburner:origLink></item>
		<item>
		<title>Android上OpenVPN的设置与使用</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/BGsVbdk1cIk/</link>
		<comments>http://yegle.net/2010/02/25/android-openvpn/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 15:49:39 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[手机软件]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[openvpn]]></category>

		<guid isPermaLink="false">http://yegle.net/?p=454</guid>
		<description><![CDATA[这个问题被问过很多次，加上我自己的VPN用户也有询问这个问题，很多人参考的又是网上古老的文档，所以我这里写一篇讲解一下。
想要阅读下文，请确保你知道什么是adb及如何使用adb 

首先明确一下，只有Android 1.6及更高版本才默认自带了TUN驱动。没有TUN驱动，Android是无法支持任何VPN的。但是我听说过有人把tun.ko（TUN驱动文件）移植到了G3 Hero里，从而让Android 1.5也可以使用OpenVPN。这个我没有证实过，稍后补充:-)
100228 UPDATE:确实有，Modaco ROM就是基于官方Android1.5内核的ROM，自带了tun驱动。HTC Hero用户可以参考这里安装
http://blog.devep.net/virushuo/2010/02/28/androidhtc_herovpn.html
其次确认一下你的系统里有没有busybox命令。目前基本上所有自定义rom都会有busybox这个东西。busybox是在嵌入式linux系统提供基本Linux命令集的工具，官网上的介绍是busybox-The Swiss Army Knife of Embedded Linux。从它的功能上来说也确实是个瑞士军刀~
呃跑题了…然后确认一下你的rom里是否已经预包含了OpenVPN。方法是：在adb shell中输入which openvpn，如果有输出类似/system/xbin/openvpn这样的字样，就说明你的rom已经预装了OpenVPN，你可以跳过安装OpenVPN的步骤了。
如果你的ROM里没有自带OpenVPN，通过以下方式安装。注意网上流传的一堆.so文件的安装方法仍然有效，但是完全没必要这么安装了。这里提供的openvpn for android二进制文件已经静态编译，不需要动态链接库的支持了：
1、下载http://github.com/downloads/fries/android-external-openvpn/openvpn-static-2.1.1.bz2
2、解压缩获得openvpn-static-2.1.1，执行adb push openvpn-static-2.1.1 /system/xbin/openvpn
3、adb shell，执行chmod 775 /system/xbin/openvpn
以上是安装OpenVPN二进制文件的过程。
OpenVPN的使用：
OpenVPN通常用数字证书进行验证，用一个.ovpn文件进行配置。将.ovpn文件、.key文件、.crt文件及ca.crt一共4个连接所需的文件放在/sdcard/openvpn/文件夹下，然后从market安装tunneldroid进行连接即可。
注意tunneldroid提供了修改DNS的选项。由于国内各个DNS基本都存在DNS污染，所以建议在tunneldroid的设置页面填一个国外的DNS，例如google的8.8.8.8。
以上如有疑问请回复提出。写twitter多了不会写长文了=。=
]]></description>
			<content:encoded><![CDATA[<p>这个问题被问过很多次，加上我自己的VPN用户也有询问这个问题，很多人参考的又是网上古老的文档，所以我这里写一篇讲解一下。</p>
<p>想要阅读下文，请确保你知道什么是adb及如何使用adb <img src='http://yegle.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
<span id="more-454"></span><br />
首先明确一下，只有Android 1.6及更高版本才默认自带了TUN驱动。没有TUN驱动，Android是无法支持任何VPN的。但是我听说过有人把tun.ko（TUN驱动文件）移植到了G3 Hero里，从而让Android 1.5也可以使用OpenVPN。这个我没有证实过，稍后补充:-)</p>
<p>100228 UPDATE:确实有，Modaco ROM就是基于官方Android1.5内核的ROM，自带了tun驱动。HTC Hero用户可以参考这里安装<br />
<a href="http://blog.devep.net/virushuo/2010/02/28/androidhtc_herovpn.html">http://blog.devep.net/virushuo/2010/02/28/androidhtc_herovpn.html</a></p>
<p>其次确认一下你的系统里有没有busybox命令。目前基本上所有自定义rom都会有busybox这个东西。busybox是在嵌入式linux系统提供基本Linux命令集的工具，官网上的介绍是busybox-The Swiss Army Knife of Embedded Linux。从它的功能上来说也确实是个瑞士军刀~</p>
<p>呃跑题了…然后确认一下你的rom里是否已经预包含了OpenVPN。方法是：在adb shell中输入which openvpn，如果有输出类似/system/xbin/openvpn这样的字样，就说明你的rom已经预装了OpenVPN，你可以跳过安装OpenVPN的步骤了。</p>
<p>如果你的ROM里没有自带OpenVPN，通过以下方式安装。注意网上流传的一堆.so文件的安装方法仍然有效，但是完全没必要这么安装了。这里提供的openvpn for android二进制文件已经静态编译，不需要动态链接库的支持了：<br />
1、下载<a href="http://github.com/downloads/fries/android-external-openvpn/openvpn-static-2.1.1.bz2">http://github.com/downloads/fries/android-external-openvpn/openvpn-static-2.1.1.bz2</a><br />
2、解压缩获得openvpn-static-2.1.1，执行adb push openvpn-static-2.1.1 /system/xbin/openvpn<br />
3、adb shell，执行chmod 775 /system/xbin/openvpn</p>
<p>以上是安装OpenVPN二进制文件的过程。</p>
<p>OpenVPN的使用：<br />
OpenVPN通常用数字证书进行验证，用一个.ovpn文件进行配置。将.ovpn文件、.key文件、.crt文件及ca.crt一共4个连接所需的文件放在/sdcard/openvpn/文件夹下，然后从market安装tunneldroid进行连接即可。</p>
<p>注意tunneldroid提供了修改DNS的选项。由于国内各个DNS基本都存在DNS污染，所以建议在tunneldroid的设置页面填一个国外的DNS，例如google的8.8.8.8。</p>
<p>以上如有疑问请回复提出。写twitter多了不会写长文了=。=</p>
<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/_yD_WrndzZ7gQrIWFRArtfv9WsE/0/da"><img src="http://feedads.g.doubleclick.net/~a/_yD_WrndzZ7gQrIWFRArtfv9WsE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/_yD_WrndzZ7gQrIWFRArtfv9WsE/1/da"><img src="http://feedads.g.doubleclick.net/~a/_yD_WrndzZ7gQrIWFRArtfv9WsE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/BGsVbdk1cIk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2010/02/25/android-openvpn/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://yegle.net/2010/02/25/android-openvpn/</feedburner:origLink></item>
		<item>
		<title>twitter抛弃HTTP Basic Auth对中国用户的影响</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/mbkWVRsrXgQ/</link>
		<comments>http://yegle.net/2010/02/12/impact-of-twitter-abandon-http-basic-auth/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 06:19:08 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[网络相关]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[twitter api proxy]]></category>

		<guid isPermaLink="false">http://yegle.net/?p=453</guid>
		<description><![CDATA[今天Twitter开发者邮件列表上有一则官方声明，原文链接：https://groups.google.com/group/twitter-development-talk/browse_thread/thread/c2c4963061422f28
原文比较长，只要关心其中对中国用户影响最大的一条就可以：twitter计划在2010年6月份停止HTTP Basic Auth支持。

对中国用户的影响：如果各个客户端不对代码进行或多或少的修改，所有twitter API proxy可能都要失效。
HTTP Basic Auth的用户名密码是简单地放在HTTP Request header里的，几乎以明文形式，容易被中途截获，被截获之后整个账户都存在危险。这样的缺点可以完全用OAuth来避免。
Twitter的OAuth支持，需要事先向twitter申请一个Key和Secret。每次用户登录一个有OAuth支持的客户端时，用户需要跳转到twitter官方页面完成登录并跳转回客户端，在此期间完成客户端与twitter官方的双向验证并由twitter分配一个access token。在后续的API请求时，需要对原来的未OAuth签名过的请求使用access token、Key、Secret进行数字签名，加上时间戳、hash、一个随机数、分配到的Key、一个特殊的http request header。hash的base string包括域名、http请求类型及请求参数。
上面进行数字签名的主要目的是，既能验证是从某个特定客户端发出的http请求，又能验证用户已经允许了这个请求，还能避免被man-in-the-middle攻击。
这样的问题是什么呢？
由于数字签名中包括域名一项，也就是说如果使用API proxy，即使相同的Key\Secret\access token\API请求，计算出来的hash值也不一样。所以客户端必须要考虑到API proxy的存在，修改数字签名部分代码，强制在计算hash时使用twitter.com作为base string的一部分，才能交给API proxy透明地转发请求。
这样的修改代码量可大可小。开发者也不一定愿意做这样的修改。以前的各个客户端添加的API proxy支持，除了让中国用户可以翻墙发推之外，还可以基本完全支持statusNet账户，一举两得。而这个针对API proxy修改OAuth数字签名部分代码的工作只对中国用户有意义。
表达能力不足，如果有疑问可以回复提出，我会再补充的。
]]></description>
			<content:encoded><![CDATA[<p>今天Twitter开发者邮件列表上有一则官方声明，原文链接：<a href="https://groups.google.com/group/twitter-development-talk/browse_thread/thread/c2c4963061422f28">https://groups.google.com/group/twitter-development-talk/browse_thread/thread/c2c4963061422f28</a></p>
<p>原文比较长，只要关心其中对中国用户影响最大的一条就可以：twitter计划在2010年6月份停止HTTP Basic Auth支持。<br />
<span id="more-453"></span><br />
对中国用户的影响：如果各个客户端不对代码进行或多或少的修改，所有twitter API proxy可能都要失效。</p>
<p>HTTP Basic Auth的用户名密码是简单地放在HTTP Request header里的，几乎以明文形式，容易被中途截获，被截获之后整个账户都存在危险。这样的缺点可以完全用OAuth来避免。</p>
<p>Twitter的OAuth支持，需要事先向twitter申请一个Key和Secret。每次用户登录一个有OAuth支持的客户端时，用户需要跳转到twitter官方页面完成登录并跳转回客户端，在此期间完成客户端与twitter官方的双向验证并由twitter分配一个access token。在后续的API请求时，需要对原来的未OAuth签名过的请求使用access token、Key、Secret进行数字签名，加上时间戳、hash、一个随机数、分配到的Key、一个特殊的http request header。hash的base string包括域名、http请求类型及请求参数。</p>
<p>上面进行数字签名的主要目的是，既能验证是从某个特定客户端发出的http请求，又能验证用户已经允许了这个请求，还能避免被man-in-the-middle攻击。</p>
<p>这样的问题是什么呢？<br />
由于数字签名中包括域名一项，也就是说如果使用API proxy，即使相同的Key\Secret\access token\API请求，计算出来的hash值也不一样。所以客户端必须要考虑到API proxy的存在，修改数字签名部分代码，强制在计算hash时使用twitter.com作为base string的一部分，才能交给API proxy透明地转发请求。</p>
<p>这样的修改代码量可大可小。开发者也不一定愿意做这样的修改。以前的各个客户端添加的API proxy支持，除了让中国用户可以翻墙发推之外，还可以基本完全支持statusNet账户，一举两得。而这个针对API proxy修改OAuth数字签名部分代码的工作只对中国用户有意义。</p>
<p>表达能力不足，如果有疑问可以回复提出，我会再补充的。</p>
<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/67F_xSk9ICaYFL_GRaJTcDwDe2g/0/da"><img src="http://feedads.g.doubleclick.net/~a/67F_xSk9ICaYFL_GRaJTcDwDe2g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/67F_xSk9ICaYFL_GRaJTcDwDe2g/1/da"><img src="http://feedads.g.doubleclick.net/~a/67F_xSk9ICaYFL_GRaJTcDwDe2g/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/mbkWVRsrXgQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2010/02/12/impact-of-twitter-abandon-http-basic-auth/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://yegle.net/2010/02/12/impact-of-twitter-abandon-http-basic-auth/</feedburner:origLink></item>
		<item>
		<title>merry xmas</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/RrMMvfV4-c0/</link>
		<comments>http://yegle.net/2009/12/24/merry-xmas/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 11:03:03 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[life]]></category>
		<category><![CDATA[xmas]]></category>

		<guid isPermaLink="false">http://yegle.net/2009/12/24/merry-xmas-2/</guid>
		<description><![CDATA[mplayer -loop 0 01-圣诞结.mp3
]]></description>
			<content:encoded><![CDATA[<p>mplayer -loop 0 01-圣诞结.mp3</p>
<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/YTw6rKmnW_cx-hqLISDbSM7o3Hs/0/da"><img src="http://feedads.g.doubleclick.net/~a/YTw6rKmnW_cx-hqLISDbSM7o3Hs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/YTw6rKmnW_cx-hqLISDbSM7o3Hs/1/da"><img src="http://feedads.g.doubleclick.net/~a/YTw6rKmnW_cx-hqLISDbSM7o3Hs/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/RrMMvfV4-c0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2009/12/24/merry-xmas/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>

		<feedburner:origLink>http://yegle.net/2009/12/24/merry-xmas/</feedburner:origLink><enclosure url="http://feedproxy.google.com/~r/yegle/~5/lF9cMLzhhXI/01-merry_xmas.mp3" length="6774536" type="audio/mpeg" /><feedburner:origEnclosureLink>http://yegle.net/wp-content/uploads/2009/12/01-merry_xmas.mp3</feedburner:origEnclosureLink></item>
		<item>
		<title>神奇的网络啊…</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/8jyvcCIoh7g/</link>
		<comments>http://yegle.net/2009/12/19/wtf/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 12:00:24 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://yegle.net/?p=444</guid>
		<description><![CDATA[这是个神奇的网络
你要是发出声音呢，有人会说你是想出风头，会说你不给面子，会说你死不放手，死缠烂打
你要是不发出声音呢，有人会说你认怂，会说你这下无话可说了吧，或者反过来说这人装清高，故弄玄虚
有人去ffmpeg issue tracker上丢人，这次是研究我到底是不是windows用户，以及我有qq号码，凭什么说与腾讯无关，还有我的vpn用户不遵守版权，为啥我就能这么义正辞严，还研究了我上次举报暴风之后隔这么久才举报射手，到底安的什么心。
有人邮件问我，为啥darwin是开源的，我不去要求苹果把mac os都开源了
有人或直接或委婉地质问我，为什么我不给射手面子
什么是开源软件？什么是自由软件？什么是GPL？
Tomasen仍然不承认之前有违反GPLv2的行为
这篇日志不开放评论，有意见请上twitter。如果你反感本人，记得千万别用dabr或者twip上twitter
]]></description>
			<content:encoded><![CDATA[<p>这是个神奇的网络</p>
<p>你要是发出声音呢，有人会说你是想出风头，会说你不给面子，会说你死不放手，死缠烂打</p>
<p>你要是不发出声音呢，有人会说你认怂，会说你这下无话可说了吧，或者反过来说这人装清高，故弄玄虚</p>
<p>有人去ffmpeg issue tracker上丢人，这次是研究我到底是不是windows用户，以及我有qq号码，凭什么说与腾讯无关，还有我的vpn用户不遵守版权，为啥我就能这么义正辞严，还研究了我上次举报暴风之后隔这么久才举报射手，到底安的什么心。</p>
<p>有人邮件问我，为啥darwin是开源的，我不去要求苹果把mac os都开源了</p>
<p>有人或直接或委婉地质问我，为什么我不给射手面子</p>
<p>什么是开源软件？什么是自由软件？什么是GPL？</p>
<p>Tomasen仍然不承认之前有违反GPLv2的行为</p>
<p>这篇日志不开放评论，有意见请上twitter。如果你反感本人，记得千万别用dabr或者twip上twitter</p>
<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/qVnIL97f6MdcLPQQ__g6ZcWAxng/0/da"><img src="http://feedads.g.doubleclick.net/~a/qVnIL97f6MdcLPQQ__g6ZcWAxng/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qVnIL97f6MdcLPQQ__g6ZcWAxng/1/da"><img src="http://feedads.g.doubleclick.net/~a/qVnIL97f6MdcLPQQ__g6ZcWAxng/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/8jyvcCIoh7g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2009/12/19/wtf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://yegle.net/2009/12/19/wtf/</feedburner:origLink></item>
		<item>
		<title>关于射手播放器</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/GygbtL4UkJU/</link>
		<comments>http://yegle.net/2009/12/18/shooterplayer-and-gpl/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 13:55:39 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[Linux新闻]]></category>

		<guid isPermaLink="false">http://yegle.net/?p=442</guid>
		<description><![CDATA[真是造孽啊…又举报了一个播放器，谁知道这么多不明真相的人围观…

总结一下经过：
起因：
射手播放器项目公开谴责腾讯违反开源协议
http://blog.splayer.org/?p=1960
当时射手网作者Tomasen在Twitter上自动转发了这篇博文，很多人RT了。
也就是无聊了，射手播放器不是开源么？啥协议？
上官网翻啊翻啊翻…哪都tmd找不到具体用什么license开源的。无奈进svn，终于找到了，原来是GPLv2。
这个是GPL的链接：点我啊点我！
既然来了SVN，看看有啥文件吧。居然在一个/lib文件夹下看见一堆二进制文件。又看见射手的wiki里居然明目张胆地这么写：
为什么一些项目只有类库但没有源码
* 射手播放器诞生以来，违反GPL授权协议的，对射手播放器代码抄袭行为不断。其中有一些老牌的所谓播放器，甚至还包括非常非常知名的大公司。面对国内 GPL维权无门，各方对开源协议的肆意践踏，射手播放器只好少许保护一下自己，对部分原创的扩展组件暂不向公众直接展示源码。部分源码开放规则还在策划中以适应中国的法律规则。走例如Zend之于php的道路。
什么？你说没看见？靠，看这个链接：点我
这段直接被删了。
我看了叫一个不爽啊，这tmd也叫GPLv2？看了一下射手开发博客上留言的一边倒，我说了一句：
狗咬狗、50笑百的事真多，射手播放器这样以gpl2开源的软件，居然部分代码以“怕被抄袭”而不开源，而且内置coreavc。开源不是请客吃饭，只要使用了gpl2释出，在我要求获得源码的时候你就有义务提供。这样的软件居然声讨腾讯， 不就是他们盗了你功能气不过么？
还有楼上说什么维护开源纯洁的人，你有在射手网站上明显的位置看到射手播放器是用什么协议开源的吗？跑svn里才能看到是gpl2。都不知道什么协议就妄谈支持开源，搞笑。
这下不得了，一帮比我还热衷开源的一致批判我。嘿嘿我乐了，都什么年代了？你射手网还想用“公开谴责”这样的CCAV用语来煽动民意？我偏偏要去举报一下。你不是谴责腾讯丫不开源么？我谴责你不开源。然后就有了这个issue:
https://roundup.ffmpeg.org/roundup/ffmpeg/issue1623
P.S.ffmpeg这服务器真不靠谱…老访问不了…
作者Tomasen，怎么说呢…几乎完全不了解GPL…
一上来首先指责我是“fan of qq player”
声明自己不是GPL expert
自己承认自己代码有部分没开源
总之，丢脸了。
其他自己看上面的链接吧。
cnbeta上肯定有人会到这里来围观，以下是给你们看的：

1、那tmd是狐狸！不是狗！
2、老子当年举报暴风影音的时候你们咋那么开心？双重标准？人家说自己是开源的你就真信了？谁给我个自己编译好的shooterplayer我看看？
3、Tomasen没有遵守GPLv2，如果不承认这个事实，光说什么“这样国内开源软件就更没前途”、“腾讯更不开源”这样的话，嘿嘿，不奉陪了。
4、腾讯请速给我电话，有人说我是你的员工，如果你不嫌弃我还没毕业的话！
5、证据我就不截图了，人家开源开发正规着呢，wiki有修改记录，svn有提交记录，不怕丫销毁证据
6、肯定有人说：那部分代码不用开源！自有模块！你还嫌Tomasen在ffmpeg issue tracker上丢人没丢够吗？
7、骂我的留言，我就不通过就不通过气死你~

]]></description>
			<content:encoded><![CDATA[<p>真是造孽啊…又举报了一个播放器，谁知道这么多不明真相的人围观…<br />
<span id="more-442"></span><br />
总结一下经过：<br />
起因：<br />
射手播放器项目公开谴责腾讯违反开源协议<br />
<a href="http://blog.splayer.org/?p=1960">http://blog.splayer.org/?p=1960</a><br />
当时射手网作者Tomasen在Twitter上自动转发了这篇博文，很多人RT了。<br />
也就是无聊了，射手播放器不是开源么？啥协议？<br />
上官网翻啊翻啊翻…哪都tmd找不到具体用什么license开源的。无奈进svn，终于找到了，原来是GPLv2。<br />
这个是GPL的链接：<a href="http://trac.splayer.org/browser/svplayer/License.txt">点我啊点我！</a></p>
<p>既然来了SVN，看看有啥文件吧。居然在一个<a href="http://trac.splayer.org/browser/svplayer/lib">/lib文件夹下</a>看见一堆二进制文件。又看见射手的wiki里居然明目张胆地这么写：</p>
<blockquote><p>为什么一些项目只有类库但没有源码<br />
* 射手播放器诞生以来，违反GPL授权协议的，对射手播放器代码抄袭行为不断。其中有一些老牌的所谓播放器，甚至还包括非常非常知名的大公司。面对国内 GPL维权无门，各方对开源协议的肆意践踏，射手播放器只好少许保护一下自己，对部分原创的扩展组件暂不向公众直接展示源码。部分源码开放规则还在策划中以适应中国的法律规则。走例如Zend之于php的道路。</p></blockquote>
<p>什么？你说没看见？靠，看这个链接：<a href="http://www.shooter.cn/w/index.php?title=%E5%B0%84%E6%89%8B%E6%92%AD%E6%94%BE%E5%99%A8_%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97&amp;oldid=3007#.E4.B8.BA.E4.BB.80.E4.B9.88.E4.B8.80.E4.BA.9B.E9.A1.B9.E7.9B.AE.E5.8F.AA.E6.9C.89.E7.B1.BB.E5.BA.93.E4.BD.86.E6.B2.A1.E6.9C.89.E6.BA.90.E7.A0.81">点我</a><br />
这段直接被删了。</p>
<p>我看了叫一个不爽啊，这tmd也叫GPLv2？看了一下射手开发博客上留言的一边倒，我说了一句：</p>
<blockquote><p>狗咬狗、50笑百的事真多，射手播放器这样以gpl2开源的软件，居然部分代码以“怕被抄袭”而不开源，而且内置coreavc。开源不是请客吃饭，只要使用了gpl2释出，在我要求获得源码的时候你就有义务提供。这样的软件居然声讨腾讯， 不就是他们盗了你功能气不过么？</p>
<p>还有楼上说什么维护开源纯洁的人，你有在射手网站上明显的位置看到射手播放器是用什么协议开源的吗？跑svn里才能看到是gpl2。都不知道什么协议就妄谈支持开源，搞笑。</p></blockquote>
<p>这下不得了，一帮比我还热衷开源的一致批判我。嘿嘿我乐了，都什么年代了？你射手网还想用“公开谴责”这样的CCAV用语来煽动民意？我偏偏要去举报一下。你不是谴责腾讯丫不开源么？我谴责你不开源。然后就有了这个issue:<br />
<a href="https://roundup.ffmpeg.org/roundup/ffmpeg/issue1623">https://roundup.ffmpeg.org/roundup/ffmpeg/issue1623</a><br />
P.S.ffmpeg这服务器真不靠谱…老访问不了…</p>
<p>作者Tomasen，怎么说呢…几乎完全不了解GPL…<br />
一上来首先指责我是“fan of qq player”<br />
声明自己不是GPL expert<br />
自己承认自己代码有部分没开源<br />
总之，丢脸了。<br />
其他自己看上面的链接吧。</p>
<p>cnbeta上肯定有人会到这里来围观，以下是给你们看的：<br />
<strong><br />
1、那tmd是狐狸！不是狗！<br />
2、老子当年<a href="http://yegle.net/2009/05/27/baofeng-media-player-on-ffmpeg-hall-of-shame/">举报暴风影音</a>的时候你们咋那么开心？双重标准？人家说自己是开源的你就真信了？谁给我个自己编译好的shooterplayer我看看？<br />
3、Tomasen没有遵守GPLv2，如果不承认这个事实，光说什么“这样国内开源软件就更没前途”、“腾讯更不开源”这样的话，嘿嘿，不奉陪了。<br />
4、腾讯请速给我电话，有人说我是你的员工，如果你不嫌弃我还没毕业的话！<br />
5、证据我就不截图了，人家开源开发正规着呢，wiki有修改记录，svn有提交记录，不怕丫销毁证据<br />
6、肯定有人说：那部分代码不用开源！自有模块！你还嫌Tomasen在ffmpeg issue tracker上丢人没丢够吗？<br />
7、骂我的留言，我就不通过就不通过气死你~<br />
</strong></p>
<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/dGqV_wYb0UnTzH9UM10Zr7MWO1o/0/da"><img src="http://feedads.g.doubleclick.net/~a/dGqV_wYb0UnTzH9UM10Zr7MWO1o/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/dGqV_wYb0UnTzH9UM10Zr7MWO1o/1/da"><img src="http://feedads.g.doubleclick.net/~a/dGqV_wYb0UnTzH9UM10Zr7MWO1o/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/GygbtL4UkJU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2009/12/18/shooterplayer-and-gpl/feed/</wfw:commentRss>
		<slash:comments>101</slash:comments>
		<feedburner:origLink>http://yegle.net/2009/12/18/shooterplayer-and-gpl/</feedburner:origLink></item>
		<item>
		<title>VPN使用的误区</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/lL-y5kfp9nM/</link>
		<comments>http://yegle.net/2009/12/16/misunderstanding-of-the-use-of-vpn/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 10:13:59 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[网络相关]]></category>
		<category><![CDATA[openvpn]]></category>

		<guid isPermaLink="false">http://yegle.net/?p=441</guid>
		<description><![CDATA[现在选择购买VPN的人越来越多了，但是很多人并不是很了解VPN，以至于很多时候使用上存在误区。
先举个推友的推做例子：
XXVPN确实不错，是我用过的VPN中最好的，无论是稳定性、保密性、速度都比XXXXVPN 要好
分条解释：
1、稳定性：
计算机程序是最讲究逻辑的，对于一个程序来说，除了“能工作”、“不能工作”这两个状态之外，只有一个“在XXXX状态下无法工作”的状态，而不存在所谓的“不稳定”状态。如果一个VPN，A能用而B不能用，那么多半是B的客户端设置问题而不是VPN服务端的问题
2、保密性：
有很多人误会vpn上网就绝对安全了。vpn只是提供一个到国外的加密信道，在没有使用ssl等端对端加密方法时，从加密信道出口到目的网站仍然是不加密的。具体的解释可以参考tor对自己安全性的描述。
3、速度快：
速度的快慢是个主观感受。免费vpn速度达到50k有人就觉得很快了，我用自己的vpn速度不到500k都嫌慢。拿腾讯qq下载测速和拿google chrome测速结果肯定不同。还有要区分是延时和速度，玩游戏追求低延时，搞下载追求高带宽，两者不同
是谁怂恿我写这个日志的…好像说完这三条就没了…orz…
]]></description>
			<content:encoded><![CDATA[<p>现在选择购买VPN的人越来越多了，但是很多人并不是很了解VPN，以至于很多时候使用上存在误区。<br />
先举个推友的推做例子：</p>
<blockquote><p>XXVPN确实不错，是我用过的VPN中最好的，无论是稳定性、保密性、速度都比XXXXVPN 要好</p></blockquote>
<p>分条解释：<br />
1、稳定性：<br />
计算机程序是最讲究逻辑的，对于一个程序来说，除了“能工作”、“不能工作”这两个状态之外，只有一个“在XXXX状态下无法工作”的状态，而不存在所谓的“不稳定”状态。如果一个VPN，A能用而B不能用，那么多半是B的客户端设置问题而不是VPN服务端的问题<br />
2、保密性：<br />
有很多人误会vpn上网就绝对安全了。vpn只是提供一个到国外的加密信道，在没有使用ssl等端对端加密方法时，从加密信道出口到目的网站仍然是不加密的。具体的解释可以参考tor对自己安全性的描述。<br />
3、速度快：<br />
速度的快慢是个主观感受。免费vpn速度达到50k有人就觉得很快了，我用自己的vpn速度不到500k都嫌慢。拿腾讯qq下载测速和拿google chrome测速结果肯定不同。还有要区分是延时和速度，玩游戏追求低延时，搞下载追求高带宽，两者不同</p>
<p>是谁怂恿我写这个日志的…好像说完这三条就没了…orz…</p>
<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/uZIryag6FZxpvMeGgeqOFq8b8Ks/0/da"><img src="http://feedads.g.doubleclick.net/~a/uZIryag6FZxpvMeGgeqOFq8b8Ks/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/uZIryag6FZxpvMeGgeqOFq8b8Ks/1/da"><img src="http://feedads.g.doubleclick.net/~a/uZIryag6FZxpvMeGgeqOFq8b8Ks/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/lL-y5kfp9nM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2009/12/16/misunderstanding-of-the-use-of-vpn/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://yegle.net/2009/12/16/misunderstanding-of-the-use-of-vpn/</feedburner:origLink></item>
		<item>
		<title>自动解压0day资源脚本</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/6Fquurn46Qg/</link>
		<comments>http://yegle.net/2009/11/21/script-auto-unrar-0day-resources/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 16:23:27 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[脚本]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://yegle.net/?p=439</guid>
		<description><![CDATA[这个脚本是以前在管理学校ftp的时候用的，当然自己在下载学校ftp资源的时候也常用这个脚本。
使用脚本要保证系统内存在rar命令。将脚本保存为dr，加上可执行权限后放到系统路径内可用

脚本能处理以下情况：
1、文件夹内压缩包以r00、r01结尾
2、文件夹内压缩包以part01.rar、part02.rar结尾
3、文件夹内包含多个子文件夹，以CD1、CD2命名
脚本能处理绝大多数0day的电影资源，但是没有经过严格测试。从我的使用来讲，至少90%以上的电影0day资源能顺利解压~
代码以CC by-nc-sa释出

#!/bin/bash
# by yegle@yegle.net
# released under CC by-nc-sa
function unrar&#40;&#41;&#123;
if test -e *01.&#91;Rr&#93;&#91;Aa&#93;&#91;Rr&#93;
then
	rar x *01.&#91;Rr&#93;&#91;Aa&#93;&#91;Rr&#93; &#38;&#38; rm *&#91;0-9&#93;&#91;0-9&#93;.&#91;Rr&#93;&#91;Aa&#93;&#91;Rr&#93;
elif test -e *.&#91;Rr&#93;00
then
	rar x *.&#91;Rr&#93;00 &#38;&#38; rarname=`basename *.&#91;Rr&#93;00 00` &#38;&#38; rm &#34;$rarname&#34;&#91;0-9&#93;&#91;0-9&#93; &#34;$rarname&#34;&#91;Aa&#93;&#91;Rr&#93;
elif test -e *.000
then
	rar x *.000 &#38;&#38; rm *.&#91;0-9&#93;&#91;0-9&#93;&#91;0-9&#93;
fi
rm -rf *.sfv Thumbs.db *COMPLETE* *.&#91;Dd&#93;&#91;Ii&#93;&#91;Zz&#93;
&#125;
&#160;
&#160;
&#160;
if test -e &#91;Cc&#93;&#91;Dd&#93;1
then
	for dir in ./&#91;Cc&#93;&#91;Dd&#93;&#91;1-9&#93;
	do
		cd $dir
		unrar
		cd -
	done
else unrar
fi

]]></description>
			<content:encoded><![CDATA[<p>这个脚本是以前在管理学校ftp的时候用的，当然自己在下载学校ftp资源的时候也常用这个脚本。</p>
<p>使用脚本要保证系统内存在rar命令。将脚本保存为dr，加上可执行权限后放到系统路径内可用<br />
<span id="more-439"></span><br />
脚本能处理以下情况：<br />
1、文件夹内压缩包以r00、r01结尾<br />
2、文件夹内压缩包以part01.rar、part02.rar结尾<br />
3、文件夹内包含多个子文件夹，以CD1、CD2命名</p>
<p>脚本能处理绝大多数0day的电影资源，但是没有经过严格测试。从我的使用来讲，至少90%以上的电影0day资源能顺利解压~<br />
代码以CC by-nc-sa释出</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># by yegle@yegle.net</span>
<span style="color: #666666; font-style: italic;"># released under CC by-nc-sa</span>
<span style="color: #000000; font-weight: bold;">function</span> unrar<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">*</span>01.<span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Aa<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	rar x <span style="color: #000000; font-weight: bold;">*</span>01.<span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Aa<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>.<span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Aa<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span>00
<span style="color: #000000; font-weight: bold;">then</span>
	rar x <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span>00 <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #007800;">rarname</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span>00 00<span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$rarname</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$rarname</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Aa<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Rr<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">*</span>.000
<span style="color: #000000; font-weight: bold;">then</span>
	rar x <span style="color: #000000; font-weight: bold;">*</span>.000 <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">*</span>.sfv Thumbs.db <span style="color: #000000; font-weight: bold;">*</span>COMPLETE<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #7a0874; font-weight: bold;">&#91;</span>Dd<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Ii<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Zz<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-e</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>Cc<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Dd<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">dir</span> <span style="color: #000000; font-weight: bold;">in</span> .<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Cc<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>Dd<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$dir</span>
		unrar
		<span style="color: #7a0874; font-weight: bold;">cd</span> -
	<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">else</span> unrar
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/CKQb1Wr119K-Z-Q_lR450SsS65M/0/da"><img src="http://feedads.g.doubleclick.net/~a/CKQb1Wr119K-Z-Q_lR450SsS65M/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/CKQb1Wr119K-Z-Q_lR450SsS65M/1/da"><img src="http://feedads.g.doubleclick.net/~a/CKQb1Wr119K-Z-Q_lR450SsS65M/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/6Fquurn46Qg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2009/11/21/script-auto-unrar-0day-resources/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://yegle.net/2009/11/21/script-auto-unrar-0day-resources/</feedburner:origLink></item>
		<item>
		<title>PHP cURL代码举例</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/t6Y9-1ajI6A/</link>
		<comments>http://yegle.net/2009/11/08/php-curl-intro/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 11:02:34 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[web编程]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://yegle.net/?p=437</guid>
		<description><![CDATA[上次贴出来的twitter同步到人人的代码，很多人留言说看不懂。其实这个代码从总体上说还是比较简单的，可能大家对curl相关函数不太了解导致抱怨说看不懂。这里写篇简单的日志介绍一下curl的使用。
注意：如果你需要深入学习，请在线查看php.net的文档，本文仅仅是对不了解PHP curl函数族的用户的入门简介。代码没有经过严格检查，如有错误请留言指出。同样，全文及以下代码以CC by-nc-sa释出，转载请注明出处。

curl是client url library的缩写。使用curl可以完成几乎所有的HTTP交互。我写的PHP代码里，包括本博客上帖出来的例如自动同步twitter到人人，以及twip项目里，大量使用了这个函数族。
PHP中curl库的介绍在这里：http://us3.php.net/manual/en/book.curl.php。如果需要使用PHP做HTTP交互相关的开发，建议仔细阅读这个页面提到的各个函数。
在PHP中使用curl非常简单。典型的使用例子：

$ch = curl_init&#40;&#41;;//创建一个curl会话，返回一个curl handle.
curl_setopt&#40;$ch,CURLOPT_URL,'http://example.com'&#41;;//设置该会话相关的URL地址
//在这个地方可以调用多次curl_setopt函数，进行更多具体的设置
curl_exec&#40;$ch&#41;;//执行curl操作
curl_close&#40;$ch&#41;;//结束该curl会话

各个函数的功能在注释里注明了。对于一般的开发者来说，关键的是掌握curl_setopt函数第二个参数可允许设置的所有内容。选择适当的curl_setopt参数，可以完成诸如用户名密码验证、post数据、保存cookie、使用代理连接、伪装成浏览器访问等等功能。可以说PHP中使用curl函数族的精髓在curl_setopt函数的使用。
举例说明一下几个典型的应用：
发送GET请求：

$url = 'http://example.com';
$ch = curl_init&#40;$url&#41;;
curl_exec&#40;$ch&#41;;
curl_close&#40;$ch&#41;;

访问这个PHP将得到http://example.com/页面的内容。这个代码仅仅是将GET得到的内容简单地“echo”出来，没有进行处理，也没有将网站的cookie以及header信息返回。
发送一个POST请求：

$url = 'http://example.com/index.php';
$ch = curl_init&#40;$url&#41;;
curl_setopt&#40;$ch,CURLOPT_POST,TRUE&#41;;
curl_setopt&#40;$ch,CURLOPT_POSTFIELDS,'username=test&#38;password=asdf'&#41;;
curl_exec&#40;$ch&#41;;
curl_close&#40;$ch&#41;;

这部分代码post了两个字段，username和password，执行这个脚本之后在index.php中可以通过$_POST['username']和$_POST['password']来访问这两个post字段的值
不直接输出结果，或需要先对结果进行过滤

$url = 'http://example.com';
$ch = curl_init&#40;$url&#41;;
curl_setopt&#40;$ch,CURLOPT_RETURNTRANSFER,TRUE&#41;;
$ret = curl_exec&#40;$ch&#41;;
curl_close&#40;$ch&#41;;
$ret = str_replace&#40;'fuck','XXXX',$ret&#41;;
echo $ret;

这部分代码，通过curl_setopt的设置，在执行curl_exec函数时不直接将结果输出，保存在$ret变量中，方便进行其他处理。注意的是：CURLOPT_RETURNTRANSFER的设置只是不让curl_exec不直接输出结果而已，无论有没有设置这个参数，curl_exec返回值里总是包含获得的页面内容。
返回服务端的完整信息：

function echo_header&#40;$ch,$str&#41;&#123;
header&#40;$str&#41;;
return strlen&#40;$str&#41;;
&#125;
$url = 'http://example.com/';
$ch = curl_init&#40;$url&#41;;
curl_setopt&#40;$ch,CURLOPT_HEADERFUNCTION,'echo_header'&#41;;
curl_exec&#40;$ch&#41;;
curl_close&#40;$ch&#41;;

这段代码将服务端的http return header原封不动地返回给客户端。使用CURLOPT_HEADERFUNCTION设置了一个回调函数，在curl_exec时，每从服务端得到一行return header信息，就调用这个函数，将curl handler和该header的内容作为参数调用这个函数。设置的函数*必须*返回header内容的长度。如果你足够敏感的话，你会发现，这个就是Twitter API proxy的简化版本。
使用cookie保持登录：

$login = 'http://example.com/login.php';
$view = 'http://example.com/user.php';
$ch = curl_init&#40;&#41;;
curl_setopt&#40;$ch,CURLOPT_URL,$login&#41;;
curl_setopt&#40;$ch,CURLOPT_COOKIEJAR,'/tmp/cookie'&#41;;
curl_setopt&#40;$ch,CURLOPT_POST,TRUE&#41;;
curl_setopt&#40;$ch,CURLOPT_POSTFIELDS,'username=test&#38;password=mypass'&#41;;
curl_setopt&#40;$ch,CURLOPT_RETURNTRANSFER,TRUE&#41;;
curl_exec&#40;$ch&#41;;
curl_setopt&#40;$ch,CURLOPT_URL,$view&#41;;
curl_setopt&#40;$ch,CURLOPT_COOKIEFILE,'/tmp/cookie'&#41;;
$ret = curl_exec&#40;$ch&#41;;
echo $ret;

这段代码稍微有点复杂。这个代码完成了两次curl_exec，演示了如何使用一个curl handler完成多次http request。绝大多数的网站都通过SESSION COOKIE完成用户的保持登录，也就是说只要cookie在，而且session没过期，就可以用这个cookie保持登录状态。这段代码首先在$login，使用POST完成了登陆，同时将cookie保存在/tmp/cookie里。在第二次curl_exec时，curl使用这个cookie以登录后的状态抓取了user.php的内容，并echo了出来。没错，这个代码就是twitter自动转发人人网站代码的简化版。
]]></description>
			<content:encoded><![CDATA[<p>上次贴出来的twitter同步到人人的代码，很多人留言说看不懂。其实这个代码从总体上说还是比较简单的，可能大家对curl相关函数不太了解导致抱怨说看不懂。这里写篇简单的日志介绍一下curl的使用。</p>
<p>注意：如果你需要深入学习，请在线查看php.net的文档，本文仅仅是对不了解PHP curl函数族的用户的入门简介。代码没有经过严格检查，如有错误请留言指出。同样，全文及以下代码以CC by-nc-sa释出，转载请注明出处。<br />
<span id="more-437"></span><br />
curl是client url library的缩写。使用curl可以完成几乎所有的HTTP交互。我写的PHP代码里，包括本博客上帖出来的例如自动同步twitter到人人，以及twip项目里，大量使用了这个函数族。</p>
<p>PHP中curl库的介绍在这里：<a href="http://us3.php.net/manual/en/book.curl.php">http://us3.php.net/manual/en/book.curl.php</a>。如果需要使用PHP做HTTP交互相关的开发，建议仔细阅读这个页面提到的各个函数。</p>
<p>在PHP中使用curl非常简单。典型的使用例子：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//创建一个curl会话，返回一个curl handle.</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #0000ff;">'http://example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//设置该会话相关的URL地址</span>
<span style="color: #666666; font-style: italic;">//在这个地方可以调用多次curl_setopt函数，进行更多具体的设置</span>
<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//执行curl操作</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//结束该curl会话</span></pre></div></div>

<p>各个函数的功能在注释里注明了。对于一般的开发者来说，关键的是掌握curl_setopt函数第二个参数可允许设置的所有内容。选择适当的curl_setopt参数，可以完成诸如用户名密码验证、post数据、保存cookie、使用代理连接、伪装成浏览器访问等等功能。可以说PHP中使用curl函数族的精髓在curl_setopt函数的使用。</p>
<p>举例说明一下几个典型的应用：<br />
发送GET请求：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://example.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>访问这个PHP将得到http://example.com/页面的内容。这个代码仅仅是将GET得到的内容简单地“echo”出来，没有进行处理，也没有将网站的cookie以及header信息返回。</p>
<p>发送一个POST请求：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://example.com/index.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_POST<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_POSTFIELDS<span style="color: #339933;">,</span><span style="color: #0000ff;">'username=test&amp;password=asdf'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>这部分代码post了两个字段，username和password，执行这个脚本之后在index.php中可以通过$_POST['username']和$_POST['password']来访问这两个post字段的值</p>
<p>不直接输出结果，或需要先对结果进行过滤</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://example.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fuck'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'XXXX'</span><span style="color: #339933;">,</span><span style="color: #000088;">$ret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span></pre></div></div>

<p>这部分代码，通过curl_setopt的设置，在执行curl_exec函数时不直接将结果输出，保存在$ret变量中，方便进行其他处理。注意的是：CURLOPT_RETURNTRANSFER的设置只是不让curl_exec不直接输出结果而已，无论有没有设置这个参数，curl_exec返回值里总是包含获得的页面内容。</p>
<p>返回服务端的完整信息：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> echo_header<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://example.com/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_HEADERFUNCTION<span style="color: #339933;">,</span><span style="color: #0000ff;">'echo_header'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>这段代码将服务端的http return header原封不动地返回给客户端。使用CURLOPT_HEADERFUNCTION设置了一个回调函数，在curl_exec时，每从服务端得到一行return header信息，就调用这个函数，将curl handler和该header的内容作为参数调用这个函数。设置的函数*必须*返回header内容的长度。如果你足够敏感的话，你会发现，这个就是Twitter API proxy的简化版本。</p>
<p>使用cookie保持登录：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$login</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://example.com/login.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://example.com/user.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #000088;">$login</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_COOKIEJAR<span style="color: #339933;">,</span><span style="color: #0000ff;">'/tmp/cookie'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_POST<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_POSTFIELDS<span style="color: #339933;">,</span><span style="color: #0000ff;">'username=test&amp;password=mypass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_COOKIEFILE<span style="color: #339933;">,</span><span style="color: #0000ff;">'/tmp/cookie'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span></pre></div></div>

<p>这段代码稍微有点复杂。这个代码完成了两次curl_exec，演示了如何使用一个curl handler完成多次http request。绝大多数的网站都通过SESSION COOKIE完成用户的保持登录，也就是说只要cookie在，而且session没过期，就可以用这个cookie保持登录状态。这段代码首先在$login，使用POST完成了登陆，同时将cookie保存在/tmp/cookie里。在第二次curl_exec时，curl使用这个cookie以登录后的状态抓取了user.php的内容，并echo了出来。没错，这个代码就是twitter自动转发人人网站代码的简化版。</p>
<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/Ay9tV1JMluGjhjnHQYKwSO5ncog/0/da"><img src="http://feedads.g.doubleclick.net/~a/Ay9tV1JMluGjhjnHQYKwSO5ncog/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Ay9tV1JMluGjhjnHQYKwSO5ncog/1/da"><img src="http://feedads.g.doubleclick.net/~a/Ay9tV1JMluGjhjnHQYKwSO5ncog/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/t6Y9-1ajI6A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2009/11/08/php-curl-intro/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://yegle.net/2009/11/08/php-curl-intro/</feedburner:origLink></item>
		<item>
		<title>test to post from my g2 using wptogo</title>
		<link>http://feedproxy.google.com/~r/yegle/~3/07fV3rUSIrI/</link>
		<comments>http://yegle.net/2009/11/01/test-to-post-from-my-g2-using-wptogo/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 07:07:22 +0000</pubDate>
		<dc:creator>yegle</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://yegle.net/2009/11/01/test-to-post-from-my-g2-using-wptogo/</guid>
		<description><![CDATA[hey it works!
]]></description>
			<content:encoded><![CDATA[<p>hey it works!</p>
<img src="http://yegle.net/34083cd2/4a7d9e50/FeedBurner/1.0 (http://www.FeedBurner.com).gif" />
<p><a href="http://feedads.g.doubleclick.net/~a/U_vdG3ZMgXOPKsTHgU3Jj9jQ6Dc/0/da"><img src="http://feedads.g.doubleclick.net/~a/U_vdG3ZMgXOPKsTHgU3Jj9jQ6Dc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/U_vdG3ZMgXOPKsTHgU3Jj9jQ6Dc/1/da"><img src="http://feedads.g.doubleclick.net/~a/U_vdG3ZMgXOPKsTHgU3Jj9jQ6Dc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/yegle/~4/07fV3rUSIrI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://yegle.net/2009/11/01/test-to-post-from-my-g2-using-wptogo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://yegle.net/2009/11/01/test-to-post-from-my-g2-using-wptogo/</feedburner:origLink></item>
	</channel>
</rss>
