<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>WilliamGates Blog &#187; Linux</title>
	<atom:link href="http://blog.williamgates.biz/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.williamgates.biz</link>
	<description>四片叶子的三叶草</description>
	<lastBuildDate>Fri, 11 Nov 2011 14:32:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>WordPress+WP-SuperCache之中文tag的Permalink问题全解析</title>
		<link>http://blog.williamgates.biz/2008/08/url-encoding-problem-in-wordpress-with-wp-super-cache/</link>
		<comments>http://blog.williamgates.biz/2008/08/url-encoding-problem-in-wordpress-with-wp-super-cache/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 04:50:17 +0000</pubDate>
		<dc:creator>WG</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[技术心得]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[技术]]></category>

		<guid isPermaLink="false">http://blog.williamgates.biz/?p=152</guid>
		<description><![CDATA[　　WordPress的中文支持有问题，特别是在使用Permalink的时候，这个大家都知道。本文将分析其中的原因和网上流传的多种解决方案，并给出一个具体的解决结论。 　　这个问题主要表现为，在默认情况下，Wordpress对于形如这样的链接（链接1）： 　　 www.example.com/tag/中文 　　不能正常访问，会产生404或500错误，或者其他的错误。 　　而对于这样的链接（链接2）： 　　 www.example.com/?tag=中文 　　WordPress就能够正确解析。 　　原因：参见这篇文章和这篇文章，这是URL编码问题造成的。对于上面的链接1，这是一个PathInfo，对于链接2，这是一个QueryString。事实证明，对于UTF-8的页面，IE和FF都会正确发送PathInfo和QueryString（而不像有些文章中说的，他们在不同的设置下会有错误的反应），但服务器端，IIS会将PathInfo转换成GBK编码从而造成错误，于是Windows下的此类问题只需要转回来就行了；但是Linux下，Apache不支持中文PathInfo，要么通过这篇文章中的方法来对Apache进行改造，要么只能像我一样，Linux主机无法使用中文permalink。于是，我们只能寻找绕路的方法。 　　解决方案分析： 　　一、转换编码（参见这篇文章） 　　原理是，IIS会将PathInfo中的UTF-8转换成GBK，而QueryString中就不会转换，故而为了使用Permalink，采用以下方法： 　　打开wp-includesclasses.php文件，找到第44行和第50行： if &#40; isset&#40;$_SERVER&#91;'PATH_INFO'&#93;&#41; &#41; $pathinfo = $_SERVER&#91;'PATH_INFO'&#93;; else $pathinfo = ''; $pathinfo_array = explode&#40;'?', $pathinfo&#41;; $pathinfo = str_replace&#40;&#34;%&#34;, &#34;%25&#34;, $pathinfo_array&#91;0&#93;&#41;; $req_uri = $_SERVER&#91;'REQUEST_URI'&#93;; 改为 if &#40; isset&#40;$_SERVER&#91;'PATH_INFO'&#93;&#41; &#41; $pathinfo = mb_convert_encoding&#40;$_SERVER&#91;'PATH_INFO'&#93;, &#34;UTF-8&#34;, &#34;GBK&#34;&#41;; else $pathinfo = ''; $pathinfo_array = explode&#40;'?', $pathinfo&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>　　WordPress的中文支持有问题，特别是在使用Permalink的时候，这个大家都知道。本文将分析其中的原因和网上流传的多种解决方案，并给出一个具体的解决结论。<br />
　　这个问题主要表现为，在默认情况下，Wordpress对于形如这样的链接（链接1）：<br />
　　</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">www.example.com/tag/中文</pre></div></div>

<p>　　不能正常访问，会产生404或500错误，或者其他的错误。<br />
　　而对于这样的链接（链接2）：<br />
　　</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">www.example.com/?tag=中文</pre></div></div>

<p>　　WordPress就能够正确解析。</p>
<p>　　原因：参见<a href="http://akun-007.javaeye.com/blog/222624">这篇文章</a>和这篇文章，这是URL编码问题造成的。对于上面的链接1，这是一个PathInfo，对于链接2，这是一个QueryString。事实证明，对于UTF-8的页面，IE和FF都会正确发送PathInfo和QueryString（而不像有些文章中说的，他们在不同的设置下会有错误的反应），但服务器端，IIS会将PathInfo转换成GBK编码从而造成错误，于是Windows下的此类问题只需要转回来就行了；但是Linux下，Apache不支持中文PathInfo，要么通过<a href="http://www.iceboy.cn/show-15-1.html">这篇文章</a>中的方法来对Apache进行改造，要么只能像我一样，<strong>Linux主机无法使用中文permalink</strong>。于是，我们只能寻找绕路的方法。<br />
<span id="more-152"></span><br />
　　解决方案分析：<br />
　　一、转换编码（参见<a href="http://www.bolarn.com/index.php/2008/01/26/52/">这篇文章</a>）<br />
　　原理是，IIS会将PathInfo中的UTF-8转换成GBK，而QueryString中就不会转换，故而为了使用Permalink，采用以下方法：<br />
　　打开wp-includesclasses.php文件，找到第44行和第50行：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span>
  <span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pathinfo_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;%25&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo_array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$req_uri</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>改为</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;GBK&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span>
  <span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pathinfo_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pathinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;%25&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pathinfo_array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$req_uri</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;GBK&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>　　局限：只对Windows主机、且必须是Windows下的IIS主机有效。</p>
<p>　　二、修改rewrite.php（参见<a href="http://www.allove.org/index.php/archives/wordpress-tags.html">这篇文章</a>）<br />
　　这是网上最常见的方法，原理是，让WordPress在对其他内容使用Permalink的时候，对tag不使用，而使用链接2的QueryString模式发送中文编码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_tag_permastruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tag_structure</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tag_structure</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">permalink_structure</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//-----this line need change------</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tag_structure</span> <span style="color: #339933;">=</span> ”<span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>把第5行改为</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">permalink_structure</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></div>

<p>　　局限：没有起到Permalink的“漂亮”作用，如果不能自己修改WP的文件就没办法了。</p>
<p>　　三、修改tag base（参见<a href="http://www.myfcys.cn/blog/index.php/2008.05/15">这篇文章</a>，经过我研究改造）<br />
　　原理同上，只要让WordPress在打开了Permalink功能后继续对tag不理不问就行了。那么，欺骗WordPress，让它用链接2的格式来显示Permalink，可行么？可行，因为WordPress可以自定义Permalink的形式：<br />
　　在WordPress的 Settings &#8211; Permalinks &#8211; Tag base 中填上<br />
　　</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">/</span>?tag<span style="color: #339933;">=</span></pre></div></div>

<p>　　注意&#8221;"不能少，引用原文中的写法不对。另外要注意每次输入&#8221;"，WP都会再次转义为&#8221;\&#8221;，所以每次点提交都会把&#8221;"翻一倍，点两次就是&#8221;\\&#8221;，所以不要多点，一次就对了。<br />
　　这个方法的结果是使得链接变成这个样子<br />
 　　</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">www.example.com/?tag=/中文/</pre></div></div>

<p>　　多出来的斜杠对于服务器丝毫没有影响，还是被视为QueryString，效果同上。<br />
　　局限是链接变得更加不好看了，更为致命的是插件生成的Sitemap中，tag链接会变成错误的形式，如果你很在乎Sitemap，请不要使用这个方法，除非你真的无法修改自己的rewrite.php文件。</p>
<p>　　但是当你使用WP-SuperCache或者类似的缓存插件时，它会加入自己的rewrite规则，所有请求先由自己判断，不在缓存中或者不符合缓存规则才交由WordPress处理。但问题在于，它不支持中文URL的解析，哪怕是QueryString也不行。于是我们必须绕过它。<br />
　　这是WP-SuperCache在.htaccess文件里所添加的rewrite规则</p>

<div class="wp_syntax"><div class="code"><pre class="xorg_conf" style="font-family:monospace;">RewriteEngine On
RewriteBase /
&nbsp;
RewriteCond %<span class="br0">&#123;</span>REQUEST_METHOD<span class="br0">&#125;</span> !=POST
RewriteCond %<span class="br0">&#123;</span>QUERY_STRING<span class="br0">&#125;</span> !.*s=.*
RewriteCond %<span class="br0">&#123;</span>QUERY_STRING<span class="br0">&#125;</span> !.*p=.*
RewriteCond %<span class="br0">&#123;</span>QUERY_STRING<span class="br0">&#125;</span> !.*attachment_id=.*
RewriteCond %<span class="br0">&#123;</span>QUERY_STRING<span class="br0">&#125;</span> !.*wp-subscription-manager=.*
RewriteCond %<span class="br0">&#123;</span>HTTP_COOKIE<span class="br0">&#125;</span> !^.*<span class="br0">&#40;</span>comment_author_|wordpress|wp-postpass_<span class="br0">&#41;</span>.*$
RewriteCond %<span class="br0">&#123;</span>HTTP:Accept-Encoding<span class="br0">&#125;</span> gzip
RewriteCond %<span class="br0">&#123;</span>DOCUMENT_ROOT<span class="br0">&#125;</span>/wp-content/cache/supercache/%<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span>/$1/index.html.gz -f
RewriteRule ^<span class="br0">&#40;</span>.*<span class="br0">&#41;</span> /wp-content/cache/supercache/%<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span>/$1/index.html.gz <span class="br0">&#91;</span>L<span class="br0">&#93;</span>
&nbsp;
RewriteCond %<span class="br0">&#123;</span>REQUEST_METHOD<span class="br0">&#125;</span> !=POST
RewriteCond %<span class="br0">&#123;</span>QUERY_STRING<span class="br0">&#125;</span> !.*s=.*
RewriteCond %<span class="br0">&#123;</span>QUERY_STRING<span class="br0">&#125;</span> !.*p=.*
RewriteCond %<span class="br0">&#123;</span>QUERY_STRING<span class="br0">&#125;</span> !.*wp-subscription-manager=.*
RewriteCond %<span class="br0">&#123;</span>QUERY_STRING<span class="br0">&#125;</span> !.*attachment_id=.*
RewriteCond %<span class="br0">&#123;</span>HTTP_COOKIE<span class="br0">&#125;</span> !^.*<span class="br0">&#40;</span>comment_author_|wordpress|wp-postpass_<span class="br0">&#41;</span>.*$
RewriteCond %<span class="br0">&#123;</span>DOCUMENT_ROOT<span class="br0">&#125;</span>/wp-content/cache/supercache/%<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span>/$1/index.html -f
RewriteRule ^<span class="br0">&#40;</span>.*<span class="br0">&#41;</span> /wp-content/cache/supercache/%<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span>/$1/index.html <span class="br0">&#91;</span>L<span class="br0">&#93;</span></pre></div></div>

<p>　　我们要做的就是不让它去判断中文tag链接，在两个 RewriteCond %{REQUEST_METHOD} !=POST 后面分别加入这样一句：</p>

<div class="wp_syntax"><div class="code"><pre class="xorg_conf" style="font-family:monospace;">RewriteCond %<span class="br0">&#123;</span>QUERY_STRING<span class="br0">&#125;</span> !.*tag=.*</pre></div></div>

<p>　　含义是如果QueryString中含有tag字样，请不要解析（交给下一条规则，一般来说就是WordPress的index.php了）。</p>
<p>　　结论：<br />
　　Windows+IIS主机下，通过方案一可以完美解决中文tag问题<br />
　　Linux+Apache主机下，<strong>不能使用中文Permalink</strong>，除非修改Apache，否则只有用方案二和方案三绕行。<br />
　　方案二是较为推荐的方法，但是搭配WP-SuperCache使用的时候，需要自己在.htaccess文件中加入一条不处理tag链接的规则。</p>
<p>Related posts:<ol>
<li><a href='http://blog.williamgates.biz/2011/10/how-to-purchase-android-apps-use-i809-at-mainland-china/' rel='bookmark' title='在国行双网机（如i909/i809）上使用Android Market购买app研究小结'>在国行双网机（如i909/i809）上使用Android Market购买app研究小结</a></li>
<li><a href='http://blog.williamgates.biz/2011/09/do-not-edit-hosts-of-android-unless-necessary/' rel='bookmark' title='慎改Android的Hosts文件'>慎改Android的Hosts文件</a></li>
<li><a href='http://blog.williamgates.biz/2011/11/do-not-and-do-not-edit-hosts-of-android/' rel='bookmark' title='再谈不要乱改Android的hosts文件'>再谈不要乱改Android的hosts文件</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.williamgates.biz/2008/08/url-encoding-problem-in-wordpress-with-wp-super-cache/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>巧用FTPRush删除Linux主机上的乱码文件</title>
		<link>http://blog.williamgates.biz/2008/02/use-ftprush-to-delete-files-with-chaos-code-name/</link>
		<comments>http://blog.williamgates.biz/2008/02/use-ftprush-to-delete-files-with-chaos-code-name/#comments</comments>
		<pubDate>Sun, 03 Feb 2008 07:59:40 +0000</pubDate>
		<dc:creator>WG</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技术心得]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[技术]]></category>

		<guid isPermaLink="false">http://blog.williamgates.biz/2008/02/03/124</guid>
		<description><![CDATA[　　如你所知，折腾的人永远有折腾得的事情好做，比如我今天想要试试看IPower的解压功能，一不小心解了一个中文名的文件到了用户根目录，解压出文件权限是644，文件名是一堆乱码……用FTPRush删除无效，重命名无效，移动也无效；PhpSpy的文件管理功能删除、重命名、移动也全都无效。 　　网上搜索Linux下删除乱码文件的方法，内容一大堆，但无一不需要使用Shell；唯一我可以使用的办法，就是用PhpSpy执行命令，用输入输出重定向来把ls输出的文件名直接导给rm命令；但是怎么试验都不成功，毕竟我只能执行一行命令，没法用vi（需要编辑ls生成的文件）。后来偶然看到有人说FTP可以删除，我试过了没用啊？难道有什么地方忽略了？ 　　我突然想到我的FTPRush是Unicode版的，而FTPRush的列表命令有一个编码的选择。打开工具-站点管理窗口-双击你的站点-目录列表方式-站点目录的字符集-选择WE/latin1(850)（大部分没有设置过locale的主机应该是这样），然后再登录FTP，发现乱码变了样子；删除之，一下子就成功了！ 　　结论：用FTP方式可以删除大部分乱码文件，除非有真正的系统不能接受的字符；但是删除的时候要确保你列出的文件名是正确的，这时候就需要把列表方式的编码设置正确。 Related posts: 慎改Android的Hosts文件 在国行双网机（如i909/i809）上使用Android Market购买app研究小结 再谈不要乱改Android的hosts文件]]></description>
			<content:encoded><![CDATA[<p>　　如你所知，折腾的人永远有折腾得的事情好做，比如我今天想要试试看IPower的解压功能，一不小心解了一个中文名的文件到了用户根目录，解压出文件权限是644，文件名是一堆乱码……用FTPRush删除无效，重命名无效，移动也无效；<a href="http://www.4ngel.net/project/phpspy.htm">PhpSpy</a>的文件管理功能删除、重命名、移动也全都无效。<br />
　　网上搜索Linux下删除乱码文件的方法，内容一大堆，但无一不需要使用Shell；唯一我可以使用的办法，就是用<a href="http://www.4ngel.net/project/phpspy.htm">PhpSpy</a>执行命令，用输入输出重定向来把ls输出的文件名直接导给rm命令；但是怎么试验都不成功，毕竟我只能执行一行命令，没法用vi（需要编辑ls生成的文件）。后来偶然看到有人说FTP可以删除，我试过了没用啊？难道有什么地方忽略了？<br />
　　我突然想到我的FTPRush是Unicode版的，而FTPRush的列表命令有一个编码的选择。打开<strong>工具</strong>-<strong>站点管理窗口</strong>-双击你的站点-<strong>目录列表方式</strong>-<strong>站点目录的字符集</strong>-选择<strong>WE/latin1(850)</strong>（大部分没有设置过locale的主机应该是这样），然后再登录FTP，发现乱码变了样子；删除之，一下子就成功了！<br />
　　结论：用FTP方式可以删除大部分乱码文件，除非有真正的系统不能接受的字符；但是删除的时候要确保你列出的文件名是正确的，这时候就需要把列表方式的编码设置正确。</p>
<p>Related posts:<ol>
<li><a href='http://blog.williamgates.biz/2011/09/do-not-edit-hosts-of-android-unless-necessary/' rel='bookmark' title='慎改Android的Hosts文件'>慎改Android的Hosts文件</a></li>
<li><a href='http://blog.williamgates.biz/2011/10/how-to-purchase-android-apps-use-i809-at-mainland-china/' rel='bookmark' title='在国行双网机（如i909/i809）上使用Android Market购买app研究小结'>在国行双网机（如i909/i809）上使用Android Market购买app研究小结</a></li>
<li><a href='http://blog.williamgates.biz/2011/11/do-not-and-do-not-edit-hosts-of-android/' rel='bookmark' title='再谈不要乱改Android的hosts文件'>再谈不要乱改Android的hosts文件</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.williamgates.biz/2008/02/use-ftprush-to-delete-files-with-chaos-code-name/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>部署Squid3.0的心得</title>
		<link>http://blog.williamgates.biz/2006/08/setup-squid/</link>
		<comments>http://blog.williamgates.biz/2006/08/setup-squid/#comments</comments>
		<pubDate>Sun, 13 Aug 2006 15:32:32 +0000</pubDate>
		<dc:creator>WG</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技术心得]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[技术]]></category>

		<guid isPermaLink="false">http://blog.williamgates.biz/2006/08/13/34</guid>
		<description><![CDATA[部署的是squid-3.0.PRE4.tar.gz，不加iptables，不使用任何外加插件 下面不是部署全过程，只是一点心得 一、configure的时候要注意参数 如果要使用HTTPS，要加上&#8211;enable-ssl（我加了才发现用不到……） 如果要在定义ACL的时候使用arp选项（即使用MAC地址来判定用户）需要加上&#8211;enable-arp-acl 如果要允许解析的URL中出现下划线，要加上&#8211;enable-underscore，因为默认情况下Squid会认为带下划线的URL是非法的，并拒绝访问该地址。这个我没试过 二、ACL配置 如果不加载第三方工具，ACL配置是Squid中唯一的访问控制方法。这个东西的功能其实跟CCProxy的身份控制差不多（但是没有用户名密码认证功能），但是配置起来要更复杂也更强大。 配置格式：acl aclname acltype string1 常用的定义类型： src ip-address/netmask src addr1-addr2/netmask 用来源的IP地址定义，一个ip#即mask方式就是网络，cidr方式就是单个ip acl aclname dst ip-address/netmask 目标地址 acl aclname arp mac-address 后悔编译的时候没加&#8211;enable-arp-acl参数，这个功能很有用的 acl aclname dstdomain .foo.com 类似于CCProxy的访问限制，例如可以限制只能访问.cn的站点、不能访问.xxx的站点等等 acl aclname dstdom_regex [-i] xxx 用正则，不过……谁这么无聊呢…… acl aclname http_status 200 301 500- 400-403 根据HTTP Response返回值，这个很有效，比如规定302Moved就不访问 acl aclname port 端口 acl aclname proto [...]]]></description>
			<content:encoded><![CDATA[<p>部署的是squid-3.0.PRE4.tar.gz，不加iptables，不使用任何外加插件<br />
下面不是部署全过程，只是一点心得</p>
<p>一、configure的时候要注意参数</p>
<ul>
<li>如果要使用HTTPS，要加上&#8211;enable-ssl（我加了才发现用不到……）</li>
<li>如果要在定义ACL的时候使用arp选项（即使用MAC地址来判定用户）需要加上&#8211;enable-arp-acl</li>
<li>如果要允许解析的URL中出现下划线，要加上&#8211;enable-underscore，因为默认情况下Squid会认为带下划线的URL是非法的，并拒绝访问该地址。这个我没试过</li>
</ul>
<p>二、ACL配置<br />
如果不加载第三方工具，ACL配置是Squid中唯一的访问控制方法。这个东西的功能其实跟CCProxy的身份控制差不多（但是没有用户名密码认证功能），但是配置起来要更复杂也更强大。</p>
<ul>
配置格式：<em>acl aclname acltype string1</em>
</ul>
<ul>
常用的定义类型：</p>
<li>src      ip-address/netmask<br />
src      addr1-addr2/netmask<br />
用来源的IP地址定义，一个ip#即mask方式就是网络，cidr方式就是单个ip</li>
<li>acl aclname dst      ip-address/netmask<br />
目标地址</li>
<li>acl aclname arp      mac-address<br />
后悔编译的时候没加&#8211;enable-arp-acl参数，这个功能很有用的</li>
<li>acl aclname dstdomain   .foo.com<br />
类似于CCProxy的访问限制，例如可以限制只能访问.cn的站点、不能访问.xxx的站点等等</li>
<li>acl aclname dstdom_regex [-i] xxx<br />
用正则，不过……谁这么无聊呢……</li>
<li>acl aclname http_status 200 301 500- 400-403<br />
根据HTTP Response返回值，这个很有效，比如规定302Moved就不访问</li>
<li>acl aclname port<br />
端口</li>
<li>acl aclname proto<br />
协议</li>
<li>acl aclname method<br />
方式，例如只能GET不能CONNECT</li>
<li>
acl aclname browser  [-i] regexp<br />
这个也太强了……限制浏览器用户代理标志类型</li>
</ul>
<p>还可以规定mime类型、响应时间等等等等……绝对强大<br />
<span id="more-34"></span><br />
我的ACL设置：<br />
很简单的设置，没有用复杂的功能限制</p>
<p>以下是默认的，直接使用了：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">acl all src 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span>0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1<span style="color: #000000; font-weight: bold;">/</span>255.255.255.255
acl to_localhost dst 127.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>
acl SSL_ports port <span style="color: #000000;">443</span> <span style="color: #000000;">563</span>
acl Safe_ports port <span style="color: #000000;">80</span>		<span style="color: #666666; font-style: italic;"># http</span>
acl Safe_ports port <span style="color: #000000;">21</span>		<span style="color: #666666; font-style: italic;"># ftp</span>
acl Safe_ports port <span style="color: #000000;">443</span> <span style="color: #000000;">563</span>	<span style="color: #666666; font-style: italic;"># https, snews</span>
acl Safe_ports port <span style="color: #000000;">70</span>		<span style="color: #666666; font-style: italic;"># gopher</span>
acl Safe_ports port <span style="color: #000000;">210</span>		<span style="color: #666666; font-style: italic;"># wais</span>
acl Safe_ports port <span style="color: #000000;">1025</span>-<span style="color: #000000;">65535</span>	<span style="color: #666666; font-style: italic;"># unregistered ports</span>
acl Safe_ports port <span style="color: #000000;">280</span>		<span style="color: #666666; font-style: italic;"># http-mgmt</span>
acl Safe_ports port <span style="color: #000000;">488</span>		<span style="color: #666666; font-style: italic;"># gss-http</span>
acl Safe_ports port <span style="color: #000000;">591</span>		<span style="color: #666666; font-style: italic;"># filemaker</span>
acl Safe_ports port <span style="color: #000000;">777</span>		<span style="color: #666666; font-style: italic;"># multiling http</span>
acl CONNECT method CONNECT</pre></div></div>

<p>以下是我修改的：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">http_access allow CONNECT all 
<span style="color: #666666; font-style: italic;">#默认是这句http_access deny CONNECT !SSL_ports</span>
<span style="color: #666666; font-style: italic;">#这样才能支持使用HTTPS地址前缀，也才能在下级生成Socks、FTP等代理</span>
acl LilyStudio src ip1 ip2
<span style="color: #666666; font-style: italic;">#两个ip地址是我要让其允许访问的</span>
http_access allow LilyStudio
http_access deny all</pre></div></div>

<p>要注意，acl 定义的name是全局的，也就是说不能重复定义一个name，即</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">acl a src 210.29.240.1
acl a src 210.29.240.2</pre></div></div>

<p>只会有后一条起作用</p>
<p>经过这样的配置，Squid就能完整地运行了，下面我们来看看在校园网内部署的时候，必不可少的二级代理的功能</p>
<p>三、二级代理的使用<br />
首先，要使用上级代理可以这样写配置文件</p>
<p><code>cache_peer <em>proxy1</em> parent  <em>port1</em> <em>port2</em> proxy-only login=<em>user</em>:<em>pwd</em> no-query default</code></p>
<ul>
<li>其中proxy1是上级代理的IP地址，port1是其http端口号，port2是icp端口号（打开的话，一般为3130，在此我们使用0，禁用</li>
<li>parent表示这是一个父代理（后面会提到兄弟代理）</li>
<li>login的作用是给上级代理的用户验证</li>
<li>proxy-only表示不进行本地缓存，直接将这个缓存服务器的内容转发给客户</li>
<li>no-query表示不发送icp信息</li>
<li>default表示这个代理是“最后的”选择，即如果所有线路都不通就发送给它，特别在不使用icp的时候有用</li>
</ul>
<p>　　Squid还支持所谓的兄弟代理（Sibling类型），对于父代理，Squid会一直向其要数据（如果没有本地缓存），等不到回应就无动作或返回超时；对于兄弟代理，Squid先从其上寻找数据，找不到则自己直接去访问数据，简而言之兄弟代理是另一个缓存而已。</p>
<p>以下这段是转的：</p>
<blockquote><p>
一般 Squid Server 运作的模式是：<br />
1. 当 Squid Server 没有资料时，会先向 Sibling 的 Squid Server 要资料，如果 Sibling 没资料，就跳过它直接向 Parent 要。<br />
2. 向 Parent 要资料，然後一直等，直到 Parent 给它资料为止(Parent 自己有的资料或上 internet 去拿)。<br />
3. 没有 Parent 时，就自己上 internet 去拿。<br />
4. 如果这三者都拿不到资料，才向用户端回报拿不到资料。 </p>
<p>　　一般而言，把网路上一层的 Squid Server  设成 Sibling 是不错的选择，因为网路上一层的 Squid Server 服务对象较多，其硬体较强，离我们比较近，速度也比较快；万一要不到资料，我们还可以自己上 internet 去拿。那什么时候设 Parent？当您的出口只有一个，或上一层 Squid Server 拿不到资料，自己也一定拿不到，只好将上一层 Squid Server 设为 Parent。 </p></blockquote>
<p>四、二级代理中的http CONNECT的问题</p>
<p>首先要确保Http_access中，</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#http_access deny CONNECT !SSL_ports</span></pre></div></div>

<p>这句话要注释掉</p>
<p>然后要写这个（查了官方FAQ才知道的）</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">never_direct allow all</pre></div></div>

<p>所有的访问都不会被直接转向，都必须通过cache_peer<br />
否则所有的GET会被发往上级代理，而CONNECT则会被发往目标地址，由于我们需要所有的情况都使用二级代理，所以需要如此设置</p>
<p>Related posts:<ol>
<li><a href='http://blog.williamgates.biz/2011/09/do-not-edit-hosts-of-android-unless-necessary/' rel='bookmark' title='慎改Android的Hosts文件'>慎改Android的Hosts文件</a></li>
<li><a href='http://blog.williamgates.biz/2011/10/how-to-purchase-android-apps-use-i809-at-mainland-china/' rel='bookmark' title='在国行双网机（如i909/i809）上使用Android Market购买app研究小结'>在国行双网机（如i909/i809）上使用Android Market购买app研究小结</a></li>
<li><a href='http://blog.williamgates.biz/2011/11/do-not-and-do-not-edit-hosts-of-android/' rel='bookmark' title='再谈不要乱改Android的hosts文件'>再谈不要乱改Android的hosts文件</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.williamgates.biz/2006/08/setup-squid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下多FTPD的共存，以及突破glftpd的chroot</title>
		<link>http://blog.williamgates.biz/2006/07/mulit-ftpd-under-linux/</link>
		<comments>http://blog.williamgates.biz/2006/07/mulit-ftpd-under-linux/#comments</comments>
		<pubDate>Sun, 09 Jul 2006 17:22:59 +0000</pubDate>
		<dc:creator>WG</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技术心得]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[glftpd]]></category>
		<category><![CDATA[技术]]></category>

		<guid isPermaLink="false">http://blog.williamgates.biz/2006/07/10/25</guid>
		<description><![CDATA[　　新接手一台FTP Server，其上本来的FTPD为vsftpd+ncftpd，vs做前台，仅提供匿名下载，nc做后台，仅给管理员使用。nc很不稳定，效率不高，功能单薄，我准备换成glftpd。但是糟糕的是，ncftpd原来只有一个管理员账号，所有的文件都属于这个用户，而且很多文件权限不是755，甚至只有644。有root当然可以chmod和chown，但是，原来1.5T的数据，且不是高速更新的FTP，如何chown？ 　　glftpd安装的时候，被我装在了 /jail 下，选择了“封闭环境”安装。但是当我尝试把别处的目录mount到它下面的时候，就遇到权限的问题，不仅不能删除很多来自ncftpd的文件，甚至部分文件根本无法访问。最糟糕的是，glftpd下载的时候会写文件（我后来才知道可以关掉这个功能），每下载一次，它会把该文件的GID加一，以方便计算下载总数。 　　于是我们的问题就归结成了，如何让glftpd获得UID不是100（新建用户默认值）的文件的所有权？ 　　翻看glftpd的文档，发现了一个本来应该不相干的内容：如何突破glftpd的chroot。我们都知道glftpd是用root启动的，但是启动后它会立刻换成较低权限的用户去运行，并且将该用户的root限定在某一个固定的目录下（在我的安装中，默认是“封闭环境”的根目录，即 /jail ）有的人需要突破这种限制，比如访问上层目录下的文件。我本来想用mount解决这个问题的，但是它的步骤说明吸引了我： 1. Change all instances of /site to /glftpd/site in your config file 把glftpd.conf配置文件中所有的路径都换成绝对路径，在此，我是 /jail/glftpd 2. Add the pwd_path and grp_path settings to the config file: pwd_path /glftpd/etc/passwd grp_path /glftpd/etc/group 修改passwd和group文件的路径，配置文件中默认没有这两行的 3. Change datapath from /ftp-data to /glftpd/ftp-data 还是改路径 4. Edit /glftpd/etc/passwd and change every user&#8217;s homedir [...]]]></description>
			<content:encoded><![CDATA[<p>　　新接手一台FTP Server，其上本来的FTPD为vsftpd+ncftpd，vs做前台，仅提供匿名下载，nc做后台，仅给管理员使用。nc很不稳定，效率不高，功能单薄，我准备换成glftpd。但是糟糕的是，ncftpd原来只有一个管理员账号，所有的文件都属于这个用户，而且很多文件权限不是755，甚至只有644。有root当然可以chmod和chown，但是，原来1.5T的数据，且不是高速更新的FTP，如何chown？<br />
　　glftpd安装的时候，被我装在了 /jail 下，选择了“封闭环境”安装。但是当我尝试把别处的目录mount到它下面的时候，就遇到权限的问题，不仅不能删除很多来自ncftpd的文件，甚至部分文件根本无法访问。最糟糕的是，glftpd下载的时候会写文件（我后来才知道可以关掉这个功能），每下载一次，它会把该文件的GID加一，以方便计算下载总数。<br />
　　于是我们的问题就归结成了，如何让glftpd获得UID不是100（新建用户默认值）的文件的所有权？<br />
　　翻看glftpd的文档，发现了一个本来应该不相干的内容：如何突破glftpd的chroot。我们都知道glftpd是用root启动的，但是启动后它会立刻换成较低权限的用户去运行，并且将该用户的root限定在某一个固定的目录下（在我的安装中，默认是“封闭环境”的根目录，即 /jail ）有的人需要突破这种限制，比如访问上层目录下的文件。我本来想用mount解决这个问题的，但是它的步骤说明吸引了我：<br />
<span id="more-25"></span></p>
<blockquote><p>
1. Change all instances of /site to /glftpd/site in your config file<br />
把glftpd.conf配置文件中所有的路径都换成绝对路径，在此，我是 /jail/glftpd</p>
<p>2. Add the pwd_path and grp_path settings to the config file:<br />
pwd_path /glftpd/etc/passwd<br />
grp_path /glftpd/etc/group<br />
修改passwd和group文件的路径，配置文件中默认没有这两行的</p>
<p>3. Change datapath from /ftp-data to /glftpd/ftp-data<br />
还是改路径</p>
<p>4. Edit /glftpd/etc/passwd and change every user&#8217;s homedir from /site to /glftpd/site.<br />
修改passwd文件，将家目录改成绝对路径</p>
<p>5. Edit /glftpd/ftp-data/users/default.* and change the HOMEDIR line from /siteto /glftpd/site.<br />
修改新建用户的默认家目录</p>
<p>6. You also need to change paths in some help files in /glftpd/ftp-data/help,possibly some more in /glftpd/ftp-data/text.<br />
我看了所有的这些文件，应该没什么要改的</p></blockquote>
<p>后面是最关键的：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Make a user, lets say root
site adduser root root *@127.0.0.1
site grpadd wheel root group (or root, depending on the OS you are running)
&nbsp;
Now go edit /glftpd/etc/passwd, you will see that glftpd has the 0:0 uid and gid
just give it 10:100 or 20:200 and give root 0:0, also change root's homedir -
default is /site, change it to /.
&nbsp;
Now edit the group file and move the number of glftpd to 100 or 200 and change roots to 0.</pre></div></div>

<p>　　看到了么，我就是在这发现了突破口！原来glftpd的用户也是可以自定义UID和GID的，那么我只要修改passwd文件，让所有的管理员都拥有root（这样不安全）或者原来的数据所有者（ncftpd的管理员帐户）的GID和UID就行了。我就是这么做的</p>
<p>　　这样，我既可以访问 /jail 以上的目录（/home/ftp/），不用mount了，也可以继续使用原来的数据，不用chmod和chown了。只要使用相同UID和GID的帐号，两个FTPD完全可以共存。（本来准备把所有文件下载再上传呢……谢天谢地）</p>
<p>　　要说明的是，你当然可以使用0:0做你的管理员帐号的UID和GID，但是这样不太安全，加上glftpd一直有chroot泄漏的传言（据说已修复），所以还是设定一个特定的用户为妙。另外，这样不再能使用glftpd的一个特色功能：设定用户的delown和renameown权限，因为所有用户看起来都一样了。但经过实际实验，基于路径的权限分配是没有问题的，基于flag的权限分配也很正常，但是有可能会在site who的时候，看到一个本不属于某个组的成员，显示在这组里（比如我的一个DirAdmin显示成SuperAdmin），但是不会真正拥有权限，放心。</p>
<p>Related posts:<ol>
<li><a href='http://blog.williamgates.biz/2011/10/how-to-purchase-android-apps-use-i809-at-mainland-china/' rel='bookmark' title='在国行双网机（如i909/i809）上使用Android Market购买app研究小结'>在国行双网机（如i909/i809）上使用Android Market购买app研究小结</a></li>
<li><a href='http://blog.williamgates.biz/2011/11/do-not-and-do-not-edit-hosts-of-android/' rel='bookmark' title='再谈不要乱改Android的hosts文件'>再谈不要乱改Android的hosts文件</a></li>
<li><a href='http://blog.williamgates.biz/2011/09/do-not-edit-hosts-of-android-unless-necessary/' rel='bookmark' title='慎改Android的Hosts文件'>慎改Android的Hosts文件</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.williamgates.biz/2006/07/mulit-ftpd-under-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

