Alfred's spAcE

2017.10.04

Facebook登录验证码…

Filed under: misc — Alfred Yang @ 16:17

不知道怎么了,登录facebook要发短信验证,而且手机上一直收到一堆乱码

比如这样的:

孃九㘸ㄶ㤷⁩猠祯畲⁆慣敢潯欠獥捵物瑹⁣潤攮⁏爠景汬潷⁴桩猠汩湫㨠桴瑰猺⼯晢⹣潭⽬⼲敄挲䉚慭潷敍慁

孃九㘸ㄶ㤷⁩猠祯畲⁆慣敢潯欠獥捵物瑹⁣潤攮⁏爠景汬潷⁴桩猠汩湫㨠桴瑰猺⼯晢⹣潭⽬⼲桭㝫楸睐㤸橉䑬

网上搜了,也没找到头绪;

后来,在发送短信验证码的页面那里,把语言设置成中文,就能收到正常的英文短信。

2016.05.17

ss-redir

Filed under: Linux, misc — Tags: , , , , — Alfred Yang @ 20:20

I’ve just setup ss-redir on my Linksys E3000.

  1. Install entware on my router, it is using shibby tomato rom;
  2. Install shadowsocks-libev;
  3. Refer to here to setup iptables rules; I don’t redirect UDP traffic;
  4. If your DNS will be poisoned, you should manage to fix it first;

Let’s f**k GFW.

Some notes:

I prefer to use ipset, so we don’t need many iptable rules, below is my part of iptables setup script:

#!/bin/sh

# clear ss rules
iptables-save -c | grep -v "SHADOWSOCKS" | \
 grep -v "gfwlist" | \
 iptables-restore -c 2>/dev/null

IPTA='iptables -t nat -A SHADOWSOCKS'

# create ss chain in table - NAT
iptables -t nat -N SHADOWSOCKS

# ignore not in gfwlist
$IPTA -m set ! --set gfwlist dst -j RETURN

# redirect ss-redir
$IPTA -p tcp -j REDIRECT --to-ports 1081

# redirect NAT output to ss chain
iptables -t nat -I PREROUTING -p tcp -j SHADOWSOCKS

# redirect local output traffic to ss chain
iptables -t nat -I OUTPUT -p tcp -j SHADOWSOCKS

Of coz, using ipset imply that your router has ipset kernel module; I add below init script to my router:

for module in ipt_REDIRECT ip_set ipt_set ip_set_nethash ip_set_iphash 
do
 modprobe $module
done
ipset -N gfwlist iphash

My dnsmasq can support gfwlist, so ipset “gfwlist”‘s entries do not need to manual enter, but my dnsmasq config file will be a bit big. Below is part of my script to generate DNS and ipset related things:

#!/bin/sh
BASE=/opt/shadowsocks
DNSMASQ=$BASE/dnsmasq.d
GFWLIST=$DNSMASQ/gfwlist.conf
TMPFILE=/tmp/gfwlist.tmp 
TMPLIST=/tmp/gfwlist.conf
URL=<some url to get gfwlist.conf>
# below change to your secure DNS
DNS=127.0.0.1#5353

set -e

[ -d $DNSMASQ ] || mkdir -p $DNSMASQ

curl -s $URL > $TMPFILE

# change to our dns
sed -i "s|^\(server.*\)/[^/]*$|\1/$DNS|" $TMPFILE

echo . > $TMPLIST
grep "^server" $TMPFILE >> $TMPLIST
grep "^ipset" $TMPFILE >> $TMPLIST
sed "1d" -i $TMPLIST

# update conf file
mv $TMPLIST $GFWLIST
echo Update done.

# flush ipset
echo flush ipset.
ipset -F gfwlist

# restart dnsmasq
echo restart dnsmasq.
service dnsmasq restart

 

2016.02.10

decorator in python

Filed under: misc — Tags: — Alfred Yang @ 20:55

I write a script to check-in a web service; it consists of 1~3 http gets, and maybe one http post to login my account. It is very handy, I can use crontab to let it run by schedule, so if my computer is running, I won’t forget to check-in.

I often see the requests lib complains SSLError – “Unexpected EOF”; I’m not sure what’s the problem, but usually a retry can solve this problem. So I think of add a retry mechanism to all these gets and posts. The retry codes will be like this:

_retry_cnt = 3
while _retry_cnt > 0:
    try:
        # gets/posts
        break
    except:
        _retry_cnt -= 1
else:
    # too many error, quit
    quit()

But as you can see, I have to copy them to replace all gets/posts, it does not look like an good idea. After look up in python language reference, find decorator; so I don’t need to change all gets/posts, I just need to add a decorator before my gets/posts functions. I will be like this:

# decorator function to do 3 times retries
def web_try(Func):
    def action(*args, **kwds):
        _retry_cnt = 3 
        while _retry_cnt > 0:
            try:
                Func(*args, **kwds)
                break
            except:
                myprint('exception count down')
               _retry_cnt -= 1
        else:
            myprint('too many retries, abort mission!')
            quit()
    return action

# two functions need decorator
@web_try
def web_get(url):
    b.open(url) # b is a robobrowser object

@web_try
def web_auth(url, payload):
    b.session.post(url, data=payload)

So I don’t need to need to do code changes in main logic.

2015.12.21

Firefox in LXC

Filed under: Linux, misc — Tags: , — Alfred Yang @ 19:49

This is referring to https://www.stgraber.org/2014/02/09/lxc-1-0-gui-in-containers/

## I use Trusty in Wily
$ lxc-create -t download -n gui -- -d ubuntu -r trusty -a amd64

## change mount and pre-start hook(replacing USERNAME appropriately):
$ vi ~/.local/share/lxc/gui/config
lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
lxc.mount.entry = /tmp/.X11-unix tmp/.X11-unix none bind,optional,create=dir
lxc.mount.entry = /dev/video0 dev/video0 none bind,optional,create=file

lxc.hook.pre-start = /home/USERNAME/.local/share/lxc/gui/setup-lxc.sh

# change id_map, same file
lxc.id_map = u 0 100000 65536
lxc.id_map = g 0 100000 65536
-> (assuming uid/gid is 1000/1000)
lxc.id_map = u 0 100000 1000
lxc.id_map = g 0 100000 1000
lxc.id_map = u 1000 1000 1
lxc.id_map = g 1000 1000 1
lxc.id_map = u 1001 101001 64535
lxc.id_map = g 1001 101001 64535

## create start-up hook
$ vi ~/.local/share/lxc/gui/setup-lxc.sh
#!/bin/sh
PULSE_PATH=$LXC_ROOTFS_PATH/home/ubuntu/.pulse_socket

if [ ! -e "$PULSE_PATH" ] || [ -z "$(lsof -tn $PULSE_PATH 2>&1)" ]; then
    pactl load-module module-native-protocol-unix auth-anonymous=1 \
        socket=$PULSE_PATH
fi

# below to let container can connect to host X server
XAUTH_FILE="${LXC_ROOTFS_PATH}/home/ubuntu/.Xauthority"
rm $XAUTH_FILE
touch $XAUTH_FILE
xauth extract - $DISPLAY | xauth -f $XAUTH_FILE merge ~/.Xauthority

## after create script, make it executable
chmod a+x ~/.local/share/lxc/gui/setup-lxc.sh
## change folder owner
$ sudo chown -R 1000:1000 ~/.local/share/lxc/gui/rootfs/home/ubuntu

## install software in container
$ lxc-start -n gui -d
$ lxc-attach -n gui -- umount /tmp/.X11-unix
# you can change ubuntu repo to your prefer site;
$ lxc-attach -n gui -- apt-get update
$ lxc-attach -n gui -- apt-get dist-upgrade -y
$ lxc-attach -n gui -- apt-get install ubuntu-artwork dmz-cursor-theme ca-certificates pulseaudio firefox -y
$ lxc-attach -n gui -- apt-get -f install -y
$ lxc-attach -n gui -- sudo -u ubuntu mkdir -p /home/ubuntu/.pulse/
$ echo "disable-shm=yes" | lxc-attach -n gui -- sudo -u ubuntu tee /home/ubuntu/.pulse/client.conf
# optional install - tmpreaper fonts-wqy-microhei flashplugin-installer default-jre icedtea-7-plugin
$ lxc-stop -n gui

## script to start firefox in LXC
$ vi ~/.local/share/lxc/gui/start-firefox 
#!/bin/sh
CONTAINER=gui
CMD_LINE="firefox $*"

STARTED=false

if ! lxc-wait -n $CONTAINER -s RUNNING -t 0; then
 lxc-start -n $CONTAINER -d
 lxc-wait -n $CONTAINER -s RUNNING
 STARTED=true
fi

PULSE_SOCKET=/home/ubuntu/.pulse_socket

lxc-attach --clear-env -n $CONTAINER -- sudo -u ubuntu -i \
 env DISPLAY=$DISPLAY PULSE_SERVER=$PULSE_SOCKET $CMD_LINE

if [ "$STARTED" = "true" ]; then
 lxc-stop -n $CONTAINER -t 10
fi

## desktop file (replacing USERNAME appropriately):
$ vi ~/.local/share/applications/lxc-firefox.desktop 
[Desktop Entry]
Version=1.0
Name=Firefox in LXC
Comment=Access the Internet
Exec=/home/USERNAME/.local/share/lxc/gui/start-firefox %U
Icon=/home/USERNAME/.local/share/lxc/gui/rootfs/usr/share/pixmaps/firefox.png
Type=Application
Categories=Network;WebBrowser;

Import non-ubuntu image in lxd

Filed under: Linux, misc — Tags: — Alfred Yang @ 13:08

Now, lxd-images can only import Ubuntu images from Ubuntu cloud images.

$ lxd-images import -h
usage: lxd-images import [-h] {busybox,ubuntu} ...

positional arguments:
 {busybox,ubuntu}
 busybox Busybox image
 ubuntu Ubuntu images

optional arguments:
 -h, --help show this help message and exit

However, we still can see a lot of lxd images on https://images.linuxcontainers.org, how to copy CentOS image from it?

We can add remote site by “lxc remote add”, then you can use “lxc image copy” to copy remote image to your local.

2015.11.18

Mac OS X in VBox in Ubuntu in Thinkpad

Filed under: Linux, misc — Tags: , , — Alfred Yang @ 20:22

mac-in-vb

2011.09.10

2011.06.06

喂蚊子

Filed under: misc — Alfred Yang @ 03:16

    夏天一来,蚊子也开始肆虐。懒得找蚊香片,不知道扔哪里去了 -_-  一晚上不摸死个十几只蚊子,估计无法平复心中的怒火,哈哈,一摸就摸死一只的感觉好爽。应该很快就能搬新家了,24层蚊子该少些吧  //pray

2011.05.21

Protected: so long…

Filed under: misc — Alfred Yang @ 01:43

This content is password protected. To view it please enter your password below:

2011.02.10

中国行业收入差距扩大至15倍跃居世界首位

Filed under: misc — Alfred Yang @ 14:01

  hoho,中国这种事情也要争第一。

  很少看新闻的,偶尔看看。不过看那些评论,也感觉实在无聊,基本上也就那些论调。当然这里说的是行业收入差距,不是个体的收入差距,但把一堆人拉平了,都没法把这个差距缩小。早上听新闻,2010年房价,杭州排第一了,真是后悔没有早买房啊,hoho,就算买,不过也似乎没有多余的钱买多套。

  兔子急了还咬人呢。

可惜youtube的,估计大家都不好看到
Older Posts »