About System

Enjoy Mac, Linux, Server

How to Make a Simple Audio/video Streaming Server

| Comments

  • Why need it

    • Music are pretty custom, hard to find a public streaming website that really fit for you.
    • You have download music everyday. More and more storage you use, you might never out of space on you desktop, but how about your iphone, ipad, android device? or your working laptop?
    • How to sync your music to different device? Each time download new music will need sync to different device.
    • In 90%, you have wifi, not necessary have everything on your device.
    • Download from torrent, then put to different device, after that you already not interested any more…
    • I have Linux server skill!!!
  • If you have problem above, then you need it.

Basic Principle

  1. Sync audio/video folder to your VPS or download by torrent.
  2. VPS auto detecting file type.
  3. VPS generate playlist for you.
  4. You able to access from all your device by access your VPS over html.

Step by Step on CentOS

1
2
3
4
5
6
7
8
9
10
11
cd /tmp
wget http://curl.haxx.se/download/curl-7.36.0.tar.gz
tar xvzf curl-7.36.0.tar.gz
cd curl-7.36.0
make && make install
cd /tmp
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar xvzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make && make install
1
2
3
4
5
6
7
cd /tmp
wget http://download.transmissionbt.com/files/transmission-2.82.tar.xz
tar xvfJ transmission-2.82.tar.xz
cd transmission-2.82
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
./configure
make && make install
  • Setup http mount point
1
useradd nginx

my example nginx vhost conf ( since I have lot of japanese content, I set html charset to shift_jis )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
server {
	listen		80;
	server_name	hostname;
	charset utf-8;
	root /home/nginx/html;
	location / {
		index index.html index.htm;
		autoindex on;
	}
	location /= {
		alias /home/nginx/html;
		index index.html index.htm;
		autoindex on;
	}
	location ~* \.(html|htm|txt)$ {
		index index.html index.htm;
		charset Shift_JIS;
	}
	location ~* player$ {
		index index.html index.htm;
		default_type 'text/html';
	}
}
  • Init transmission config
1
2
3
su - nginx
transmission-daemon
killall transmission-daemon

suggestion config ( ~/.config/transmission-daemon/settings.json )

1
2
3
"rpc-enabled": true,
"rpc-username": "login username",
"rpc-password": "login password", 

transmission smart enough if you using text password, it will convert to hash automatically

1
2
3
4
5
6
go get github.com/kiyor/playlist
go install github.com/kiyor/playlist
cp -r templates html/ #cp my repo's templates file to you html directory ( html/templates/*.tmpl )
cd html
git clone git@github.com:johndyer/mediaelement.git
git clone git@github.com:kiyor/mep-feature-playlist.git
  • Download or upload something to you html folder
1
2
su - nginx
transmission-daemon
  1. go to hostname:9091, upload torrent or magnet link and download to your html/bt
  2. after downloaded, try access your hostname/bt
  3. run playlist -dir ‘your html dir’, it would generate a file call player
  4. access your player in all your device

note

  • current only support mp3/wav as audio mp4 as video

Puppet Tips

| Comments

  • puppet with nginx artical link
  • important permission, puppet:puppet puppet_config_dir/rack
  • use templates is better for loadbalance, since you don’t need setup host in config, but speed is lower than files
example nginx conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

server {
    listen          8140 ssl;
    server_name     $hostname;

    access_log      /usr/local/nginx/logs/puppet_access.log;
    error_log       /usr/local/nginx/logs/puppet_error.log;

    ssl_certificate             /var/lib/puppet/ssl/certs/$hostname.pem;
    ssl_certificate_key         /var/lib/puppet/ssl/private_keys/$hostname.pem;
    ssl_crl                     /var/lib/puppet/ssl/ca/ca_crl.pem;
    ssl_client_certificate      /var/lib/puppet/ssl/certs/ca.pem;
    ssl_ciphers                 SSLv2:-LOW:-EXPORT:RC4+RSA;
    ssl_prefer_server_ciphers   on;
    ssl_verify_client           optional;
    ssl_verify_depth            1;
    ssl_session_cache           shared:SSL:128m;
    ssl_session_timeout         5m;

    location / {
        root                      /etc/puppet/rack/public;
        passenger_base_uri        /;
        passenger_enabled         on;
        passenger_set_cgi_param   HTTP_X_CLIENT_DN $ssl_client_s_dn;
        passenger_set_cgi_param   HTTP_X_CLIENT_VERIFY $ssl_client_verify;
    }
}

Force Local User Use Proxy

| Comments

Setup local squid.conf with http_port 45678 transparent

ssh to your DD-WRT router and run

1
iptables -I FORWARD -p tcp -d 192.168.1.2 –dport 45678 -j ACCEPT

After accept local server forward make a script like ensquid.sh

1
2
#!/bin/sh
iptables -t nat -I PREROUTING -p tcp -s $1 –dport 80 -j DNAT –to 192.168.1.2:45678

add exec privilege and run

1
2
chmod u+x ensquid.sh
./ensquid.sh 192.168.1.x

Why I do that:

  • Sucker game console not support use proxy everywhere, like WiiU cannot use proxy on Nico App
  • I have two layer proxy setup for JP website. And ad deny feature on my proxy. Why not using it!

Cracked a Japanese iOS Online Game…

| Comments

These day I was playing a new iOS game named Road to Dragons, ロード・トゥ・ドラゴン.

Analysis the file system found all the cache data store form a plist file which is in /Library/Preferences/jp.co.acquire.RTD.plist

In my experience this kind of game will connect to server when out of battle. It will use local calculator to calculate the battle result. So it could be cracked during the battle.

I found the plist file contain a line like LOGINBONUS_PARAM

1
{"m_BonusLife":0,"m_BonusAttack":0,"m_BonusRecovery":0,"m_BonusEvoPoint":0,"m_BonusSoulPoint":0,"m_BonusCriticalRate":0,"m_BonusDropRate":0,"m_BonusQuestMoney":0,"m_BonusQuestExp":0,"m_BonusQuestFriendPoint":0}

That’s a strange line in this mass file, so I change all 0 to 100000 and try to get all the bonus.

It worked…So this game company use client and clean text (Ok, only Xcode can open this plist file) to calculate the battle and even it is multiplication…

Ok…That’s my first time to crack a online game…Maybe I will try more later…

Update

Pets soul could be changed too…

Edit MDBS30 and change quest’s reward_soul value…

What a suck game!

Control Different Region Player Connect Different Server

| Comments

Recently I wanted to upgrade my Minecraft player. I plan to use different server for different player. I’ve tried to check how does my home’s DD-WRT works on port forwarding. And I got the result. I could use port forwarding in iptables control player source ip connect different server.

So this is my iptables rule

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT 0 -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
DROP udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:520
DROP udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:520
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:520
logaccept tcp -- 0.0.0.0/0 192.168.1.1 tcp dpt:23
DROP icmp -- 0.0.0.0/0 0.0.0.0/0
DROP 2 -- 0.0.0.0/0 0.0.0.0/0
ACCEPT 0 -- 0.0.0.0/0 0.0.0.0/0 state NEW
logaccept 0 -- 0.0.0.0/0 0.0.0.0/0 state NEW
DROP 0 -- 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT 47 -- 192.168.1.0/24 0.0.0.0/0
ACCEPT tcp -- 192.168.1.0/24 0.0.0.0/0 tcp dpt:1723
ACCEPT 0 -- 0.0.0.0/0 0.0.0.0/0
TCPMSS tcp -- 0.0.0.0/0 0.0.0.0/0 tcp flags:0x06/0x02 TCPMSS clamp to PMTU
lan2wan 0 -- 0.0.0.0/0 0.0.0.0/0
ACCEPT 0 -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT tcp -- 0.0.0.0/0 192.168.1.131 tcp dpt:25565
ACCEPT udp -- 0.0.0.0/0 192.168.1.131 udp dpt:25565
ACCEPT tcp -- 0.0.0.0/0 192.168.1.131 tcp dpt:80
ACCEPT udp -- 0.0.0.0/0 192.168.1.131 udp dpt:80
ACCEPT tcp -- 0.0.0.0/0 192.168.1.131 tcp dpt:443
ACCEPT udp -- 0.0.0.0/0 192.168.1.131 udp dpt:443
ACCEPT tcp -- 0.0.0.0/0 192.168.1.131 tcp dpt:548
ACCEPT udp -- 0.0.0.0/0 192.168.1.131 udp dpt:548
ACCEPT tcp -- 0.0.0.0/0 192.168.1.1 tcp dpt:80
ACCEPT udp -- 0.0.0.0/0 192.168.1.1 udp dpt:80
ACCEPT tcp -- 0.0.0.0/0 192.168.1.1 tcp dpt:443
ACCEPT udp -- 0.0.0.0/0 192.168.1.1 udp dpt:443
ACCEPT tcp -- 0.0.0.0/0 192.168.1.131 tcp dpt:22
ACCEPT udp -- 0.0.0.0/0 192.168.1.131 udp dpt:22
ACCEPT tcp -- 0.0.0.0/0 192.168.1.133 tcp dpt:51413
ACCEPT udp -- 0.0.0.0/0 192.168.1.133 udp dpt:51413
ACCEPT tcp -- 0.0.0.0/0 192.168.1.133 tcp dpt:9091
ACCEPT udp -- 0.0.0.0/0 192.168.1.133 udp dpt:9091
ACCEPT tcp -- 0.0.0.0/0 192.168.1.131 tcp dpt:8123
ACCEPT udp -- 0.0.0.0/0 192.168.1.131 udp dpt:8123
ACCEPT tcp -- 0.0.0.0/0 192.168.1.141 tcp dpt:6699
ACCEPT udp -- 0.0.0.0/0 192.168.1.141 udp dpt:6699
TRIGGER 0 -- 0.0.0.0/0 0.0.0.0/0 TRIGGER type:in match:0 relate:0
trigger_out 0 -- 0.0.0.0/0 0.0.0.0/0
ACCEPT 0 -- 0.0.0.0/0 0.0.0.0/0 state NEW
DROP 0 -- 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain advgrp_1 (0 references)
target prot opt source destination
Chain advgrp_10 (0 references)
target prot opt source destination
Chain advgrp_2 (0 references)
target prot opt source destination
Chain advgrp_3 (0 references)
target prot opt source destination
Chain advgrp_4 (0 references)
target prot opt source destination
Chain advgrp_5 (0 references)
target prot opt source destination
Chain advgrp_6 (0 references)
target prot opt source destination
Chain advgrp_7 (0 references)
target prot opt source destination
Chain advgrp_8 (0 references)
target prot opt source destination
Chain advgrp_9 (0 references)
target prot opt source destination
Chain grp_1 (0 references)
target prot opt source destination
Chain grp_10 (0 references)
target prot opt source destination
Chain grp_2 (0 references)
target prot opt source destination
Chain grp_3 (0 references)
target prot opt source destination
Chain grp_4 (0 references)
target prot opt source destination
Chain grp_5 (0 references)
target prot opt source destination
Chain grp_6 (0 references)
target prot opt source destination
Chain grp_7 (0 references)
target prot opt source destination
Chain grp_8 (0 references)
target prot opt source destination
Chain grp_9 (0 references)
target prot opt source destination
Chain lan2wan (1 references)
target prot opt source destination
Chain logaccept (2 references)
target prot opt source destination
ACCEPT 0 -- 0.0.0.0/0 0.0.0.0/0
Chain logdrop (0 references)
target prot opt source destination
DROP 0 -- 0.0.0.0/0 0.0.0.0/0
Chain logreject (0 references)
target prot opt source destination
REJECT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp reject-with tcp-reset
Chain trigger_out (1 references)
target prot opt source destination

The only useful in this table is FORWARD

The rule is looks like that

1
2
iptables -t nat -I PREROUTING -p tcp -d 192.168.1.1 --dport 10001 -j DNAT --to 192.168.1.131:10002
iptables -I FORWARD -p tcp -d 192.168.1.131 --dport 10002 -j ACCEPT

Test Success.

The script

1
2
3
#!/bin/sh
iptables -t nat -I PREROUTING -p tcp -s $1 -d $2 --dport $3 -j DNAT --to $2:$4
iptables -I FORWARD -p tcp -s $1 -d $2 --dport $3 -j ACCEPT
$1: source ip
$2: server ip
$3: service port
$4: forward port

So Now I can make my Chinese player play my Chinese server and US player play US server. The server could automatic choose server depends on region.

How to Use Ramdisk in Your Mac

| Comments

You can simply use command to create a ramdisk.

1
diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://512000`

This is 250 MB ramdisk, you can change 512000 to change the volume of the ramdisk. If you want to use ramdisk for your safari cache You can close the safari and run these

1
2
3
rm -rf ~/Library/Caches/com.apple.Safari
mkdir /Volumes/ramdisk/com.apple.Safari
ln -s /Volumes/ramdisk/com.apple.Safari/ ~/Library/Caches/com.apple.Safari

Another app’s caches you can just modify path form the code above.

If you need it runs automatically when you reboot. Create a script like ramedisk.sh and chmod u+x ramdisk.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh
if [ ! -d "/Volumes/ramdisk" ]; then
	diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://512000`
fi
if [ ! -d "/Volumes/ramdisk/com.apple.Safari" ]; then
	rm -rf ~/Library/Caches/com.apple.Safari
	mkdir /Volumes/ramdisk/com.apple.Safari
	ln -s /Volumes/ramdisk/com.apple.Safari/ ~/Library/Caches/com.apple.Safari
fi
if [ ! -d "/Volumes/ramdisk/Google" ]; then
	rm -rf ~/Library/Caches/Google
	mkdir /Volumes/ramdisk/Google
	ln -s /Volumes/ramdisk/Google/ ~/Library/Caches/Google
fi
 
if [ -d "/Volumes/ramdisk/com.apple.Safari" ] && [ -d "/Volumes/ramdisk/Google" ]; then
	echo "Ramdisk is enabled!"
else
	echo "Error"
fi

rc.local file might not work, Mac looks not load rc.local, what I do is append these to terminal login sheel and run terminal when Mac start. You need add a check like if [[ $(tty) = /dev/ttys001 ]]; then ~/ramdisk.sh; fi;

You can also modify this if you need. More information Testing software: Blackmagic Disk Speed Test

10 Bit YUV 4:2:2 PAL Default SSD Default Ramdisk
Disk Write Speed MB/s 180 800
Disk Read Speed MB/s 210 800

Share My Mac’s Apps List

| Comments

Last year I bought 2011 Mac Air for learning Objective-C. Now I’m using OSX for my main environment. Most of the people who never use OSX thought “Mac is over prices, only the hardware is good and not support a lot of apps”. But most of Mac users love Mac is because the OS. So apps I use to make me think Mac is awesome.

1st: Xcode

Without Xcode, your Mac is not completed. Not because you need programing something, just because you really need command line tools from Xcode. Regular command line is not enough to access some awesome command. After you install the Xcode and download the command line tools, your Mac is ready to go.

2nd: Terminal

This topic will be very huge. Terminal could be use everywhere. The most important things on Terminal is because they can easily edit root file without any problem. Also you can ssh via terminal. Windows use putty, that’s not good. Terminal have great GUI, not only help you do your works but also make the works look amazing.

3rd: MacPorts

If you are familiar with Linux, you must know rpm and apt-get. port is similar like these, but port let you download the source and compile by yourself. The package might be install slowly and cpu will almost 100%. Whatever you could use a lot of Linux 3rd party package in your Mac like nmap, watch and so on.

4th: TextMate

TextMate is an awesome text editor in Mac. It could use a lot of plugin and even compile your code without other apps. What I have problem is I cannot change default table size as space, and also sometimes auto tab will annoying you.

5th: MacVim

Powerful, not not for newbie developer. I use MacVim for view the php or custom stuff. You could do whatever in Vim, same as MacVim. If you are developer, you should know how to use keyboard control the cursor at least.

6th: BBedit

Good text editor for project diff and support real-time word suggestion. I purchase this app only for these two reason. OK, one more reason: it is available in App Store.

7th: Coda / Coda 2

If you are a web developer, You must have this app. This is the best php writer.

8th: Sequel Pro

FREE MySql app. The GUI is sample, easy for use. If you should manage mysql database data, you must have it.

9th: Navicat

This app have a lot of version. You can try Navicat Premium first, and then try Navicat Premium Essentials. This app is best for SQL data structural; not very good for data editing.

10: CyberDuck

FREE / PAY ftp / sftp kind of app. This app is enough if you just use ftp for some time.

11: Transmit

Best ftp / sftp kind of app. The only thing is it could not zip the file by GUI. The GUI of the app is amazing.

12: Evernote

Good app for note, sync with all your device. Only poor is it is not stable when you offline.

13: Dropbox

I don’t wanna say anything, if you don’t have account just click me.

14: VMware

If you will use Linux or Windows for some reason, you must have this one. It cost money but more like a product.

15: VirtualBox

FREE but not very good for GUI access. I think VirtualBox is best for virtual a server. You can modify more complex than VMware.

16: GitHub

If you have source code in your Mac, please use it to control it. It reduce your madness.