[OUTDATED]Installing OpenVPN in rockmeweb.net Hosted VPS [Ubuntu or Debian]

VPS has been around for quiet sometime, and, If only I knew it earlier, I wouldn’t gave justhost.com people my money this year for their crappy server :) .

Anyways, I got myself a VPS a week ago. before I decided to get one, I was actually seeking for a VPN provider. and when I googled, the term VPS keeps coming on to my screen….so I decided to give it a click…then I got a VPS from rockmyweb.net, nice speed, nice configuration, and cheap.

There are a lot of people talks about setup a VPN in VPS, but those threads are soooo long…after 2 days, I found this http://vpsnoc.com/blog/how-to-install-openvpn-on-a-debianubuntu-vps-instantly/.

This is quick and dirty. and there are a few things I need to modify here for rockmyweb.net hosted VPS, and I use ubuntu for my OS.

Requirement:

A VPS
NAT is enable on your server
Able to create tun nod

This script gives you one cert for you to connect to VPN, for multiple user, see openvpn docs. it’s just a matter of running ./build-key

make sure you have /dev/net/tun
normally you don’t, so you need to create one with root privilege.

mknod /dev/net/tun c 10 200

and you can make sure you have nat support

root@znxf:~# iptables -t nat -L

This usually gives you an empty list, but we know that nat is working(support staff says otherwise, but well, it’s working).
If you see a error message instead, you’ll need to contact support.

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

After you ran this script, you should have keys.tgz in your root folder. Move it to your ftp and download it to your computer, or scp it or whatever.

#!/bin/bash
#
# CrUmp crumpz.info
# Modified for rockmyweb.net hosted VPS
# 04/30/2011
#
# Quick and dirty OpenVPN install script
# Tested on debian 5.0 32bit, openvz minimal debian OS template
# and Ubuntu 9.04 32 bit minimal, should work on 64bit images as well
# Please submit feedback and questions at support@vpsnoc.com

# John Malkowski vpsnoc.com 01/18/2010
#
#
ip=`grep address /etc/network/interfaces | grep -v 127.0.0.1  | awk '{print $2}'`
dnss=`cat /etc/resolv.conf |grep [0-9] | awk '{print $2}'`
dns1=`echo $dnss | awk '{print $1}'`
dns2=`echo $dnss | awk '{print $2}'`

apt-get update
apt-get install openvpn libssl-dev  openssl
cd /etc/openvpn/
cp -R /usr/share/doc/openvpn/examples/easy-rsa/ /etc/openvpn/
cd /etc/openvpn/easy-rsa/2.0/
chmod +rwx *
. ./vars
./clean-all
source ./vars

echo -e "\n\n\n\n\n\n\n" | ./build-ca
clear
echo "####################################"
echo "Feel free to accept default values"
echo "Wouldn't recommend setting a password here"
echo "Then you'd have to type in the password each time openVPN starts/restarts"
echo "####################################"
./build-key-server server
./build-dh
cp keys/{ca.crt,ca.key,server.crt,server.key,dh1024.pem} /etc/openvpn/

clear
echo "####################################"
echo "Feel free to accept default values"
echo "This is your client key, you may set a password here but it's not required"
echo "####################################"
./build-key client1
cd keys/

client="
client
remote $ip 1194
dev tun
comp-lzo
ca ca.crt
cert client1.crt
key client1.key
route-delay 2
route-method exe
redirect-gateway def1
verb 3"

echo "$client" > $HOSTNAME.ovpn

tar czf keys.tgz ca.crt ca.key client1.crt client1.csr client1.key $HOSTNAME.ovpn
mv keys.tgz /root

opvpn="
dev tun
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
push "route 10.8.0.0 255.255.255.0"
push "redirect-gateway"
push "dhcp-option DNS $dns1"
push "dhcp-option DNS $dns2"
comp-lzo
keepalive 10 60
ping-timer-rem
persist-tun
persist-key
group daemon
daemon"

echo "$opvpn" > /etc/openvpn/openvpn.conf

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j SNAT --to $ip

echo "#!/bin/sh" > /etc/network/if-up.d/iptables
echo "iptables-restore < /etc/iptables.conf" >> /etc/network/if-up.d/iptables
chmod +x /etc/network/if-up.d/iptables
sysctl -w net.ipv4.ip_forward=1

/etc/init.d/openvpn start
clear

echo "OpenVPN has been installed
Download /root/keys.tgz using winscp or other sftp/scp client such as filezilla
Create a directory named vpn at C:Program FilesOpenVPNconfig and untar the content of keys.tgz there
Start openvpn-gui, right click the tray icon go to vpn and click connect
For support/bug reports email us at support@vpsnoc.com"

Now you can download the keys and unpack it to use with Tunnelblick(Mac), or other VPN clients.

The C Programming Language Chapter 1 Exercise 1-16

好吧,这个说的是要把之前说到的主程序的 main function 部分修改一下,使它可以正确计算输入的字符个数,虽然它定下了 1000个字符的限制,通过修改 main() 的部分,超过一千字的,只计算字符个数而不打印超出的部分。

要求: Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text.

这里有标准答案(话说,标准答案都很啰嗦啊。。。。),以下是自己写的。。。

#include 
#define MAXLINE 10

int getline (char line[], int maxline);
void copy(char to[], char from[]);

int getline(char s[], int lim)
{
	int c, i;
	for(i = 0; i < lim-1 && (c=getchar())!=EOF && c!='n'; ++i)
		s[i] = c;
	if(c=='n')
	{
		s[i]=c;
		++i;
	}
	s[i] = '';
	return i;
}
void copy(char to[], char from[])
{
	int i;
	i=0;
	while ((to[i] = from[i]) != '')
		++i;
}

int main (int argc, char const *argv[])
{
	int len;
	int max;
	char line[MAXLINE];
	char longest[MAXLINE];
	int c;

	max = 0;
	while ((len = getline(line, MAXLINE)) > 0){
		if(line[len-1] != 'n'){
			while((c = getchar())!='n')
				++len;
		}
		if(len>max)
		{
			max = len;
			copy(longest, line);

		}
	}
	if(max > 0)
		printf("nnLongest line has %d characters.nIt's:n%sn[... %d more chars are not printed]n(Newline and "\0" are counted)nn", max, longest,max-MAXLINE);
	return 0;
}

The C Programming Language Chapter 1 Exercise 1-13

这个是昨天写的,这是这本书第一个比较正经的,需要思考一下的练习
要求: Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging.

这里有标准答案,我自己写了一个,如下。

#include 

#define	ARRAY_SLOTS	12

int main (int argc, char const *argv[])
{
	int stars, counter, c, wc;

	int wordTable[ARRAY_SLOTS];
	stars=wc=counter=0;

	for(counter = 0; counter < ARRAY_SLOTS; ++counter)
	{
		wordTable[counter] = 0;
	}

	while ((c = getchar()) != EOF)
		{
			wc++;
		if(c == ' ' || c == 't' || c == 'n')
		{
			--wc;
			if(wc > 10)
			{
				++wordTable[11];
			}
			else if(wc <=10 && wc > 0) //otherwise it will count newline
			{
				++wordTable[wc];
			}

		wc=0;
		}
	}

	for(counter = 1; counter < ARRAY_SLOTS; ++counter)
	{
		if(wordTable[counter] > wordTable[0])
		{
			wordTable[0] = wordTable[counter];
		}
	}

	for(counter = wordTable[0]; counter > 0; counter--)
	{
		printf("%7d|", counter);
		for(stars = 1; stars <= ARRAY_SLOTS; stars++)
		{
			if(wordTable[stars]>=counter)
			{
				printf("*  ");
			}
			else
				{
				printf("   ");}
				}
		printf("n");
	}

	printf("        ");
	for(counter = 1; counter < ARRAY_SLOTS ; ++counter)
	{
		printf("---");
	}

	printf("n       ");
	for(counter = 1; counter < ARRAY_SLOTS ; ++counter)
	{
		if(counter < 11)
		{
			printf("%2d ",counter);
		}
		else{
			printf(" moren");
		}
	}

	return 0;
}

The C Programming Language Chapter 1 Exercise 1-14

这个有点太坏了,难度不算是很高吧,这才第二十四页呀。。。。不过很有趣。

这里有“标准答案”。不过我的跟他的不同,我只用到两个变量,一个数组~~

要求: Write a program to print a histogram of the frequencies of different characters in its input.

#include 

//there are 94 visible chars in ascii table
//make an array that holds 95 ints, the array[0]
//holds the the maximum char.

#define ARRAY_SLOT	96

int main(int argc, char *argv[])
{
	int c,stars;
	int charTable[ARRAY_SLOT];

	for (c=0; c < ARRAY_SLOT ; c++ )
	{
		charTable[c]=0;
	}

	while ((c = getchar())!= EOF)
	{
		//visible ascii is from 32 to 126
		if (c>=32 && c<=126)
		{
			//input to array, charTable[1] to charTable[95]
			++charTable[c-31];
		}
		else if (c='n')
		{
			;
		}
		else
		{;}
	}

for (c=1;ccharTable[0])
	{
	//charTable[0] for the biggest number
	charTable[0] = charTable[c];
	}
}

for (c = charTable[0]; c > 0; c-- )
{
	printf("%4d|",c);
	for (stars=1; stars < 96 ;stars++ )
	{
		if (charTable[stars]!=0)
		{
			if (charTable[stars]>=c)
			{
				printf("*");
			}
			else{
				printf(" ");
				};
		}
		else
			; //do nothing.

	}
	printf("n");
	}

printf("     ");

for(c = 1; c < ARRAY_SLOT ; ++c)
{
	if (charTable[c])
	{
		printf("-");
	}

}
printf("n     ");
for (c=1; c
					

what do you need to do to run "backup" PSN games on geohot's 3.55 cfw

google is your friend, and you’ll need a few things:

1. PSL1GHT vm and VirtualBox

2. geohot’s signing tools, at geohot.com

3. PS3 tools from fail0verflow

4. ftp server for PS3

5. little experiences with linux terminal.

you can get cracked games from PS3ISO.com, these games don’t work directly with geohot’s cfw because this cfw is not allowing of running unsigned/modified EBOOT.BIN. what we have to do is very simple: to sign the EBOOT.BIN using geohot’s signing tools: make_self_npdrm and package_finalize.

first you need to set up the environment, in VM, and everything is done in terminal:

1. get geohot’s tools, git clone https://github.com/geohot/ps3publictools.git ,and compile them with “make linux”, then cp these files to /usr/bin, the password is “password”

2. go to ~/dev/ps3/ps3tools and “make”, then copy ‘unself’ to /usr/bin

On PS3: install a ftp server, get it here: http://www.megaupload.com/?d=CZBW58WW

Get the game you like from PS3ISO.com

if game.pkg installs:

1. get EBOOT.BIN from PS3 and run:
2. run “unself EBOOT.BIN eboot.elf”
3. and run “make_self_npdrm eboot.elf EBOOT.BIN [content id]“. use “PS3_SFO_Editor_LE.gambas” to read content id, or simply use game folder name.
4. copy the new EBOOT.BIN to the game folder, done.

If the game.pkg won’t install, just use package_finalize on the game.pkg:
1. run “package_finalize game.pkg” and you should be able to run the install, then,
2. get EBOOT.BIN from PS3 and run:
3. run “unself EBOOT.BIN eboot.elf”
4. and run “make_self_npdrm eboot.elf EBOOT.BIN [content id]“. use “PS3_SFO_Editor_LE.gambas” to read content id, or simply use game folder name.
5. copy the new EBOOT.BIN to the game folder, done. (yea…same shit..)

Tested on Lumine : supernova and echochrome.

Getting Skillsoft Course Manager (SCM) to work with OSX Snow Leopard

I’ve used VM to run Skillsoft Course Manager since day one because I don’t have a PC… It’s a bit inconvenience, obviously. So after a simple googling I found there is a version for Mac… -_-

However, after visiting Client Download for Mac and installing a Mac SCM, it didn’t appare to work…

I have OSX Snow Leopard with the lastest updates, including JAVA SE build 1.6.0_22-b04-307-10M3261 installed. And the fix was easy, well after 2 hours of my time -_- .

in ~/Applications/SkillSoft/SkillSoftContent/client/ you’ll find MacOCMStart.sh, this script executes the java contents and runs the program for you. In this file, whenever you see “exec java -Xdock:name=….”, you change it to “exec java -d32 -Xdock:name=….”

That’s it!

Oh if you didn’t pay for it (you know what I meant :D ), copied the “Content” folder from Windows’s version, and when asked for the user ID, use “REBELS – We Make All Days Party Days!” without the quotation mark.

UPDATE: Mah, the SCM is too old I guess…when play on mac it has no sound :( check the spec, they said it supports only 10.4…..oh well….

Passed CompTIA A+ exams

After almost a month of preparation, I took and passed the CompTIA A+ test today, in coming weeks I’ll be receiving the certification document from CompTIA. YAY

To be honest it’s not a hard test, that’s why it’s known as “entry level” of IT support certification. Any person with computer repairing experience and study the material would pass this set of 2 exams. But still, studying is a big part of this.

There are 2 parts of the exam:

220-701: CompTIA A+ Essentials  and,

220-702: CompTIA A+ Practical Application.

I was pretty not confident when I take the Practical Applications because it was somewhat confusing while answering the questions. Yet surprisingly I’ve done better than I expected. 810 out of 900, phew…I was not dare to look on the screen when I click “End exam” because I was so afraid there were a big “Fail” on the screen…..

The material I used to prepare the test was:
CompTIA A+ Certification All-in-One Exam Guide, Seventh Edition and,

Skillsoft’s interactive course software.

The book is a great book, but….it’s an overkill! I read half of it and gave up :D it’s got 1300+ pages.

The interactive course is good stuff. I was able to take a pre-test before a new topic, and went through the topic, then take the skill test again. I think it’s good way of studying, if I got the software first, I wouldn’t have to read the book LOL.

My next objective is the CompTIA Network+. Wish myself luck :D

第七章, Core Data Basics

這章主要講解如何使用 Cocoa 的 NSManagedObject 來做簡單的數據管理程序。

Core Data 是一個很方便的功能,利用它,可以幾乎不用寫任何代碼,就可以做出基本的數據管理程序,比如倉庫管理,人員管理之類的。
使用 Core data templet 來創建 Project,只需要建立好 Model,Xcode 會自動生成各種對應 GUI 的 Binding。
使用內置的 Data Model 編輯器,建立好 Model, 然後打開 NIB, 並把 data model 從草圖拖動 到 IB 的 Windows 上,就可以自動生成 GUI。生成後,所有的 Binding 已經建立。基本上已經可用了。
如果需要為已經建立的程序制定功能,必須 subclass NSManagedObject.
書中第 159 頁漏掉一段,如下:
In order to customize NSManagedObject’s behavior, we need to create a subclass, and update our data model so that it knows there’s a specific class to use for the MythicalPerson entity. Create a new Objective-C class in your project, by right-clicking on the folder you want to add it to, and selecting “Add->New File…” from the context menu. Use the assistant that appears to create a Cocoa/Objective-C class. Depending on your version of Xcode, you may be able to specify you want a subclass of NSManagedObject here. Do so if you can, but otherwise NSObject will do, we’ll fix it after saving.. Click “Next”, name the new class “MythicalPerson”, and click “Finish”. If your version of Xcode didn’t let you pick NSManage- dObject as the superclass for your new class, now’s the time to go into the @interface declaration in MythicalPerson.h, and change the superclass to NSManagedObject.
Now that the class is in place, go back to the data model we created earlier, select the MythicalPerson entity, and change its class name from NSManagedObject to MythicalPer- son. Save your work, and you’ve now got a model class of your own, ready for customizing.
這段很重要,但是沒有在書上印出來 =_=
如果需要驗證某個 property ,需要 subclass NSManagedObject, 並 Implement
-(BOOL)validate<key>:(id *)ioValue error:(NSError **)outError
比如書上的例子:

[code lang-c]-(BOOL)validateName:(id *)ioValue error:(NSError **)outError
{
    if (*ioValue == nil){
        return YES;
    }
    if ([*ioValue isEqualToString:@"Bob"]){
        if (outError != NULL) {
            NSString *errorStr = NSLocalizedString(
            @"You're not allowed to name a mythical person 'Bob'."
            "'Bob'is a real person, just liek you and me.",
            @"validation:invalid name error");
            NSDictionary *userInfoDict = [NSDictionary dictionaryWithObject:errorStr forKey:NSLocalizedDescriptionKey];
            NSError *error = [[[NSError alloc] initWithDomain:@"MythicalPersonErrorDomain" code:13013 userInfo:userInfoDict] autorelease];
            *outError = error;
        }
        return NO;
    }
    return YES;
}

[/code]
目前比較讓我摸不著頭腦的是 NSError 的方法們,應該用多了就能熟悉。
還有就是驗證多個 properties, 需要 Implement
[code]- (BOOL)validateForInsert:(NSError **)error[/code]和[code]- (BOOL)validateForUpdate:(NSError **)error [/code]這兩個方法。

Cocoa Programming for Mac OS X Chapter 15 Challenge

这章就是教你怎么自己做 Alert Panels. 就是你要做什么事情之前弹出个窗口问你是否继续阿, 是否退出阿, 是否取消阿之类的东西.

Challenge
Add to the Alert sheet another button that says Keep, but no raise. Instead of deleting the employees, this button will simply set the raises of the selected employees to zero.
这个我很纠结地试了很久, 最后还是上网查了. 然后查出来的方法其实之前也有想过, 但不确定, 也不知道该怎么用. 学习了.
添加修改的源码:

-(IBAction)removeEmployee:(id)sender
{
NSArray *selectedPeople = [employeeController selectedObjects];
NSAlert *deletionAlert = [NSAlert alertWithMessageText:@"Delete or clear raise?"
defaultButton:@"Delete"
alternateButton:@"Cancel"
otherButton:@"Clear"
informativeTextWithFormat:@"Are you sure that you want to remove or clear %d people?",[selectedPeople count]];
[deletionAlert beginSheetModalForWindow:[tableView window]
modalDelegate:self
didEndSelector:@selector(alertEnded:code:context:)
contextInfo:NULL];
}

-(void)alertEnded:(NSAlert *)alert code:(int)choice context:(void *)v
{
if (choice == NSAlertDefaultReturn)
{
[employeeController remove:nil];
}
else if (choice == NSAlertOtherReturn) {
NSArray *selectedPeople = [employeeController selectedObjects];
for (Person *p in selectedPeople){
//这是 for 很基本的用法…
//[p setExpectedRaise:0.0]; //通用的写法.
//setExpectedRaise 是 expectedRaise 的 setter, 由@property &
//@synthesize 自动生成. 不是我定义的, 但我仍然可以使用, 或者重写.
//但在 Objective-C 2.0, 这也可以写成:
p.expectedRaise=0.0; //新的写法. }
}
else {
return;
}
}
其实昨天也刚刚学到, MVC之中 Controller 是不储存任何数据的, 怎么今天就忘记了呢…
强力极力推荐 iTunesU 上的 Stanford University – iPhone Application Development (Winter 2010), 看了几课, 很多看书的时候很模糊的东西也慢慢清晰起来了. 虽然它是说 iPhone 的, 但这种东西一样通百样的. 真的是很不错, 免费的大学课程页~~~~