Saturday, February 23, 2013

Proxior for Windows快速使用教程

准备好要使用的代理服务器

例如我们有一个Bitvise Tunnelier得到一个socks5的代理localhost:7070,还有一个goagent得到的HTTP代理localhost:8087。由于goagent对https支持不好,我们希望http://www.youtube.com/走goagent,https://www.youtube.com走SSH。

http://code.google.com/p/proxior/downloads/list
下载Proxior for windows并解压

配置(一定要做,默认配置不能直接用)

用UltraEdit或Notepad++(用记事本打开,如果不是一行一行的就说明不行)打开proxior.conf

配置代理服务器段为
socks5 SSH localhost:7070
proxy GAE localhost:8087

配置访问列表段
acl direct directlist
acl GAE gaelist
acl SSH sshlist
其中direct是常量,表示直接连接,上面的意思是,在得到一个URL后,先判断是否在directlist,若是则直接连接,否则判断是否在gaelist,若是使用GAE代理走,等等。


acl-default direct
如果没有匹配任何列表,则直接连接


acl-try SSH
如果连接重置,使用SSH连接


timeout 30
listen 0.0.0.0:9999
0.0.0.0表示监听所有本机地址,也可以设置为127.0.0.1,则别的机器无法访问

用上述文本编辑工具打开sshlist等list,里面就是匹配url。

匹配规则有两种:

如"vimeo.com",则http://www.vimeo.co/xxxx/sdfdsf会被匹配,网址含有vimeo.com的都匹配

再如"http://media-cache-*.pinterest.com/*" ,这个可以匹配http://media-cache-ec3.pinterest.com/aas/sdfs.jpg

注意,HTTPS传输是是无法侦测具体URL的,只知道连接的主机。如https://www.youtube.com/,则只能侦测到www.youtube.com

配合list优先级,gaelist里有http://*.youtube.com/*, sshlist有youtube.com。就使http的youtube走gae,https的走ssh

运行

双击run.bat

系统代理中的HTTP代理和HTTPS代理都设置为localhost:9999




管理列表

登陆 http://strongwillow.github.com/proxior.control/ 点setting, Target Proxy设置为你的代理端口,localhost:9999。你可以另存为下来使用。

进入RULES,这时可以看到1: Select a URL list: 下面已经有list了。

例如要添加一个rule:http://code.google.com/,用gae访问,可以先QUERY A URL,看看在不在现有的list,有的话可以删除。




点击gae,在2: URL rule: 输入http://code.google.com/,再点add输入。但并没有保存到磁盘,点击Flush存到磁盘。


日志

点log可以看到出现问题的URL。建议经常看看并添加到列表,点Clear Log清空log,长期不清空log可能会使其非常大。



最后

可以把iPhone和Android的HTTP代理都设置为 你的ip:9999,然后卸载掉SwitchySharp吧

Sunday, February 17, 2013

老友

昨天叶和丹来我这里玩。看了区府,爬了白云山。

Wednesday, January 30, 2013

Why a process's memory usage won't decrease after being freed?

I'm using OS X and use Activity Monitor to check the memory usage of my program. However, this may fool people to think that their programs have memory leakages.

Let's check this example.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

struct list {
  char data[1024];
  struct list *next;
};

int main(int argc, char *argv[])
{
  sleep(5);

  /* Consume some memory  */
  struct list *head = malloc(sizeof(struct list));
  
  int i = 300;
  struct list *p = head;
  while (i-->0) {
    p->next = malloc(sizeof(struct list));
    p = p->next;
  }
 
  printf("Consumed a lot memory. Wait 5s to free them\n");

  sleep(5);

  i = 300;
  while (i-->0) {
    p = head->next;
    free(head);
    head = p;
  }

  printf("freed, wait 10s to exit\n");
  sleep(10);

  return 0;
}

Open your Activity Monitor and filter out your program, you will see that at first stage, the program costs about 150kb, then about 500kb after five seconds. After freeing the memory, you can see that the program still costs 500kb.

Why is this happening?

Put simply, the memory malloc'ed is granted to your process and won't return to OS immediately after you call free. The freed memory can be used later by the process.

A little more detail: http://stackoverflow.com/questions/447899/why-does-my-c-program-not-free-memory-as-it-should/447932#447932

Thursday, January 24, 2013

Make shell script(PuTTY plink or SSH) a daemon that never dies! (using Ubuntu Upstart)

I have a script that creates a SSH Tunnel using PuTTY plink. Problem is that it dies sometimes. I have a old laptop running Ubuntu Server in my home. Also I want that script to be executed when the server starts up and automatically respawns another instance if it dies.

There are some old fashioned ways to do it which I won't detail. I'm going to introduce you the modern way using Upstart.

My first config is this one. Located at "/etc/init/plink.conf".

start on runlevel [2345] or net-device-up IFACE!=lo
stop on runlevel [!2345]

respawn

exec plink -D 7070 -N -pw mypassword user@host

However, this just won't work. I checked its status using "sudo status plink", only to find its state is "stopped/waiting". I also use "ps -ejH" to debug and find its pid changes every few seconds.Why is this happening?

Then I came across this page: http://www.greenend.org.uk/rjk/sshfwd/. It enlightens me to find out what plink says.

I created a script like this:

# redirect stderr to file 1
exec > /home/clear/ssh-forwarding.log 2>&1

exec plink -D 7070 -N -pw mypassword user@host
When I cat /home/clear/ssh-forwarding.log, then I found this:
The authenticity of host 'host (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is 62:af:59:cb:ef:89:b7:45:bc:56:a1:96:59:56:49:2f.
Are you sure you want to continue connecting (yes/no)? 

Then I realized that Upstart keeps respawning plink because it timeouts waiting for my answer.

The solution is simple.
1. su to root
2. issue the plink command and answer yes to trust the host.

The final plink.conf:

start on runlevel [2345] or net-device-up IFACE!=lo
stop on runlevel [!2345]
 
respawn
respawn limit 5 60 # respawn max 5 times in 60 seconds

script
 set -e
 exec > /home/clear/ssh-forwarding.log 2>&1
 exec plink -D 7070 -N -pw mypassword user@host
end script
Finally, reboot. I happily find that plink is running now!

Hello, world!

I started several blogs last few years. However, I kept it privately and locally at last, because its naiveness and the possibility to leak my personal information.

I decided to start this blog on blogger mainly because I want to contribute to the general accessible knowledge.

This blog mainly focuses on Unix and C related topics I came across.