3/28/2013

Ubuntu下的Privoxy使用与配置同步方案

在笔记本上装了64位版的Ubuntu 12.10,第一件事就是配置如何Fuck GFW,下载Chromium。

由于流量有限,自然用Privoxy比较合适。但在修改/etc/privoxy/config的时候一不小心就把默认的config文件给覆盖了,而且还是用的Windows版本的文件。然后无论如何都不能启动/etc/init.d/privoxy start。 重装privoxy,提取源码包中的config文件都不行。

后来自己手写了一个config文件,可以勉强启动并且根据规则判断是否转发。但http://p.p/页面一直显示:

"500 Internal Privoxy Error
Privoxy encountered an error while processing your request:
Could not load template file default or one of it's
included components.
Please contact your proxy administrator.
If you are the proxy administrator, please put the
required file(s)in the (confdir)/templates directory.

这时候我强迫症发作了:用VirtualBox全新安装了一个Ubuntu,然后把默认的配置文件提取出来:点此下载(/etc/privoxy目录下的所有文件)。

对比可以发现原因是Linux和Windows下的config和config.txt不能通用。主要在于目录变量以及功能的支持上:Linux下的config默认内容:
user-manual /usr/share/doc/privoxy/user-manual
confdir /etc/privoxy
logdir /var/log/privoxy
actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.
actionsfile default.action   # Main actions file
actionsfile user.action      # User customizations
filterfile default.filter
filterfile user.filter      # User customizations
logfile logfile
listen-address  localhost:8118
toggle  1
enable-remote-toggle  0
enable-remote-http-toggle  0
enable-edit-actions 0
enforce-blocks 0
buffer-limit 4096
forwarded-connect-retries  0
accept-intercepted-requests 0
allow-cgi-request-crunching 0
split-large-forms 0
keep-alive-timeout 5
socket-timeout 300

Windows下的config.txt默认内容:
confdir .
logdir .
actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.
actionsfile default.action   # Main actions file
actionsfile user.action      # User customizations
filterfile default.filter
filterfile user.filter      # User customizations
logfile logfile
listen-address  127.0.0.1:8118
toggle  1
enable-remote-toggle  0
enable-remote-http-toggle  0
enable-edit-actions 0
enforce-blocks 0
buffer-limit 4096
enable-proxy-authentication-forwarding 0
forwarded-connect-retries  0
accept-intercepted-requests 0
allow-cgi-request-crunching 0
split-large-forms 0
keep-alive-timeout 5
tolerate-pipelining 1
socket-timeout 300

最后完全重写了转发的规则,以前都是直接写在config文件里。但现在需要多平台同步,并且config文件不能通用,只好把forward规则改写成action的方式。
要感谢 七星庐:强大的代理调度器代理 Privoxy 和 cckpg的autoproxy2privoxy 的帮助。其实改写过程就几分钟,但苦在Privoxy的action功能太强大,这种简单的功能反而不知道如何下手。

然后就是把新写好的config和proxy.action文件放到Dropbox里Windows版的Privoxy目录下,再用硬链接链接到/etc/privoxy目录下。

这样Windows直接打开Dropbox中的exe程序就可以使用,Ubuntu下也可以同步到最新的规则。

但是经过多机实验,发现一个BUG,如果在Windows平台下修改proxy.action文件,会导致Ubuntu的硬链接失效。初步认为是坚果云同步文件的实现方式造成的。但由于网络环境导致Dropbox不能实时同步,所以不能确定原因。

EOF

3/17/2013

The Old Reader的全屏模式Bookmarklet

Google Reader要关了,The Old Reader是个不错的替代品。但是没有全屏模式这一点我有点小不爽。所以自己DIY了一个Bookmarklet凑合用着。 

update:HeiNotes指出了这个脚本不能适用于https的theoldreader,已经改正 http://www.heinotes.com/2013/03/HTTPS-The-Old-Reader-Fullscreen.html


JavaScript 代码:

javascript:(function(){var v=new RegExp('theoldreader.com');if(!v.test(document.URL)){alert('The script can only work in theoldreader.com!');}else{a=document.getElementById('main');b=document.getElementById('sidebar');c=document.getElementsByClassName('subscribe-fixed-top');d=document.getElementsByClassName('navbar-fixed-top');e=document.getElementsByClassName('container-fluid');if(typeof top == 'undefined'){var top='';}if('none' != b.style.display){top=window.getComputedStyle(e[0],null).getPropertyValue('top');e[0].style.top='5px';left=a.style.left;width=a.style.width;b.style.display='none';c[0].style.display='none';d[0].style.display='none';a.style.left='-25px';a.style.width='99%';}else{b.style.display='block';c[0].style.display='block';d[0].style.display='block';e[0].style.top=top;a.style.left=left;a.style.width=width;}return;}})();

直接复制再粘贴到收藏夹栏里即可。或者直接拖动下面一句文字:


下面是代码的简短注释:

//a means main body that display the real entities.
//b means the sidebar on the left.
//c means the add subscription button.
//d means the header in the top
//e means the container of the main(a), the sidebar(b) and the ADD BUTTON(c).

仅在Chrome和IE 10上测试通过。

FullScreen for the Old Reader

It's a bookmarklet for The Old Reader, the best alternative of the Google Reader. It can toggle the interface of your Old Reader just like the fullscreen feature of Google Reader with one click.


Here is the JavaScript code:

javascript:(function(){var v=new RegExp('theoldreader.com');if(!v.test(document.URL)){alert('The script can only work in theoldreader.com!');}else{a=document.getElementById('main');b=document.getElementById('sidebar');c=document.getElementsByClassName('subscribe-fixed-top');d=document.getElementsByClassName('navbar-fixed-top');e=document.getElementsByClassName('container-fluid');if(typeof top == 'undefined'){var top='';}if('none' != b.style.display){top=window.getComputedStyle(e[0],null).getPropertyValue('top');e[0].style.top='5px';left=a.style.left;width=a.style.width;b.style.display='none';c[0].style.display='none';d[0].style.display='none';a.style.left='-25px';a.style.width='99%';}else{b.style.display='block';c[0].style.display='block';d[0].style.display='block';e[0].style.top=top;a.style.left=left;a.style.width=width;}return;}})();

PS: You can copy this code and paste it on your browser's bookmarks bar. Or just try dragging the fonts below.


And here is simple comments:

//a means main body that display the real entities.
//b means the sidebar on the left.
//c means the add subscription button.
//d means the header in the top
//e means the container of the main(a), the sidebar(b) and the ADD BUTTON(c).

I just test the code in chrome and IE 10.