Showing posts with label HOWTOs. Show all posts
Showing posts with label HOWTOs. Show all posts

Wednesday, April 29, 2009

HOWTO: Share internet connection (painlessly) from your Ubuntu machine over Wireless

Internet connection sharing (ICS) had been one of the insane things that I've always made use of, be it in Windoze or otherwise. And now with us using mobile broadband, me having my Acer Aspire One notebook installed with Ubuntu on it, it's time to take up the challenge again to get this up and running! No need for Wireless@SG anymore, I can BECOME Wireless@SG! :D

Problem was, after reading many Ubuntu forums and HOWTOs, trying out Firestarter many times (and I'm currently too lazy to learn to configure iptables myself manually), I was almost ready to give up, until I read up on ipmasq out of curiousity... You would need to use the terminal, so if you have an allergy to the terminal it'd be good to learn and overcome that first :)

If this was helpful to you, or if you have any questions, do leave a comment!

This HOWTO was done on the following:
  • Ubuntu Jaunty 9.0.4 UNR (Ubuntu Netbook Release)
  • Huawei E180 HSPA USB Modem
  • Acer Aspire One A150

Here's what you do:
1) Install dnsmasq and ipmasq
Run the following command in terminal:
sudo apt-get install dnsmasq ipmasq -y

2) Disable dnsmasq from autostarting
In your terminal, type:
sudo gedit /etc/default/dnsmasq

Look for the line that states "ENABLED=1" and change it to "ENABLED=0"

3) Kill off dnsmasq daemon
We don't want dnsmasq to be running as a daemon here, since NetworkManager tries to start it for shared connections.
sudo killall dnsmasq

4) Enable wireless
You should know how to do this if it's not already on...

5) Configure wireless
  1. Left click network manager applet in the top panel.
  2. Select "Create new wireless network".
  3. Type in the network name and change your security settings as needed.
This would tell NetworkManager to create an ad-hoc wireless network.

6) Check wireless config
  1. Right click network manager applet.
  2. Select "Edit Connections...".
  3. Go to the "Wireless" tab.
  4. Select your ad-hoc network and click on "Edit".
  5. Go to "IPv4 Settings" tab
  6. The method should be "Shared to other computers"
This is so that dnsmasq will run whenever this network is connected to, providing us a DHCP and DNS server for that ad-hoc network.

7) Configure ipmasq
In terminal, type:
sudo dpkg-reconfigure ipmasq
  1. Should PPP connections recompute the firewall? Yes
  2. Just press Ok
  3. When should ipmasq be started? After network interfaces are brought up

8) Connect internet facing modem connection if not already done so
For me I just select my service provider and Ubuntu "dials up" to connect

9) Run ipmasq to configure iptables
iptables configs does the actual routing, ipmasq helps configure iptables PAINLESSLY :)
From terminal, type:
sudo ipmasq

10) Get ipmasq to run whenever a network interface goes up or down
iptables configurations are not persistent, so I use ipmasq to autoconfig for me everytime a network interface goes up. Note that you can also use other methods to persist iptables. NetworkManager fires off scripts in /etc/network/if-up.d whenever an interface goes up, so let's tell it to run ipmasq too.
In terminal, type these commands:
cd /etc/network/if-up.d
sudo gedit config-iptables
Copy and paste the following into the editor, save and exit.
#! /bin/sh

/usr/sbin/ipmasq
Then in terminal again, make the script executable:
sudo chmod +x config-iptables
You will want ipmasq to autoconfig again when a network interface goes down, so run the following in terminal:
sudo cp config-iptables /etc/network/if-post-down.d

11) Connect client, start surfing :)
You're done! Now just get another wifi client to join in the ad-hoc network, and after it gets an IP automatically we should be good to go!

Wednesday, March 11, 2009

HOWTO: Determining the day of the week from the date in Microsoft Logparser

One of the issues we encountered in working with Microsoft Logparser is that we needed to determine which day of the week it was given a date.  Though there wasn't any function to do so, it seemed that the solution was pretty simple, actually.

(Apologize in advance for the bad reading formatting here, but these should work just by copying and pasting into your command prompt.  For some additional sanity I colour the more important parts red, heh.)

The code itself to convert is like this:
MOD(DIV(TO_INT(TO_DATE(DateTime)), 86400), 7)
Where DateTime is the input column with the datetime stamp.  86400 is the number of seconds in a day, and 7 is well....the number of days in a week :P

The return values (proved consistent within the range of my testing) are with Sunday as 1, and running all the way to Saturday as 0, i.e.:
Sat - 0
Sun - 1
Mon - 2
Tue - 3
Wed - 4
Thu - 5
Fri - 6

Combined into a simple query:
logparser -i:csv -o:datagrid "SELECT DISTINCT TO_DATE(DateTime), MOD(DIV(TO_INT(TO_DATE(DateTime)), 86400), 7) FROM datetest.csv"
(datetest.csv is my input test file here.)


And making use of some additional (simple but crazy!) programming to output as days instead of numbers (referencing from this article)
logparser -i:csv -o:datagrid "SELECT DISTINCT TO_DATE(DateTime), Day USING CASE MOD(DIV(TO_INT(TO_DATE(DateTime)), 86400), 7) WHEN 0 THEN 'SAT' ELSE CASE MOD(DIV(TO_INT(TO_DATE(DateTime)), 86400), 7) WHEN 1 THEN 'SUN' ELSE CASE MOD(DIV(TO_INT(TO_DATE(DateTime)), 86400), 7) WHEN 2 THEN 'MON' ELSE CASE MOD(DIV(TO_INT(TO_DATE(DateTime)), 86400), 7) WHEN 3 THEN 'TUE' ELSE CASE MOD(DIV(TO_INT(TO_DATE(DateTime)), 86400), 7) WHEN 4 THEN 'WED' ELSE CASE MOD(DIV(TO_INT(TO_DATE(DateTime)), 86400), 7) WHEN 5 THEN 'THU' ELSE 'FRI' END END END END END END AS Day FROM datetest.csv"

The output that I get :D

Hope this helped you.  Any comments/feedback is much appreciated!

References:

Tuesday, July 08, 2008

Getting NetBeans 6.1 to work with Nokia Symbian S40 and S60 SDKs

For Symbian S60 SDK
It seems that the steps to get the S60 SDK to work with NetBeans 6.1 isn't that intuitive (read: we need to scour the documentation to get it right), and the information isn't (easily) found on the Net, so I'll write it down here to share.

(If you get a NullPointerException thrown by the SDK, complaining that it failed to initialize session at the Connect to Agent step, you might want to try these steps to configure NetBeans to recognise the S60 SDK properly. )

In order to get NetBeans to be able to launch the S60 emulator successfully (to test run our midlet projects), we need to take note when configuring NetBeans to recognise the S60 platform.

This obscure information can be found in your NetBeans help section if you installed the S60 SDK enabling the automatic integration with NetBeans IDE.
S60 3rd Edition SDK for Symbian OS, Feature Pack 2 > Tools and Utilities > Using the SDK with an IDE > Java Development > NetBeans > Installing and configuring NetBeans

1) In NetBeans, select Tools > Java Platforms.

2) Select Add Platform.

3) Select the radio option Java ME MIDP Platform Emulator, click next and wait~~~.

4) If the S60 SDK isn't listed, click on Find More Java ME Platform Folders and select the main folder where your S60 SDK is installed. Select the S60 SDK and click next.

5) NetBeans will autodetect the platform details (the MIDP profiles, CLDC configurations and optional APIs supported by the SDK) if the correct folder/SDK was selected. What remains is to click on finish to add the S60 SDK into the list of Java Platforms for NetBeans.

6) Use the S60 Emulator in a project configuration and run the main project as per normal. You should see that the emulator fires up as it should =)


For Symbian S40 SDK
The steps to configure NetBeans with the S40 SDK are similar.

1) In NetBeans, select Tools > Java Platforms.

2) Select Add Platform.

3) Select the radio option Custom Java ME MIDP Platform Emulator, and click next.

4) Click on Browse to select the main folder where your S40 SDK is installed.

5) Give the platform and device names. Click Next, then Finish to add the SDK to the list of Java Platforms.

6) Use the S40 Emulator in a project configuration and run the main project as per normal.

Thursday, May 29, 2008

Assessment Methodology

Done by hitechpo on House of Hackers blog.

[Parts 1, 2, 3, 4 and 5]

Introduction to reverse engineering

Done by n2u in House of Hackers blog.

[Part 1]
[Part 2]

Friday, February 01, 2008

Creating a tar.gz MyDSL extension

This HOWTO is meant to be a correction for the steps found in the DSL wiki to create a MyDSL extension for 4.2.4.

I'll be focusing on the steps to package the extension itself, assuming that the application has already been tested to work from within the /opt folder.

The program for the instructions will be called my_program ;)

Step 1:
Create working folder to hold all the needed files for the extension. Note that all commands following this step will be run from the /home/dsl/work folder, and not from the / folder.
sudo su
mkdir -p /home/dsl/work/opt
cd /home/dsl/work/


Optional:
If we want an icon on the desktop for the extension.
mkdir -p ./home/dsl/.xtdesktop

Copy in the icons to ./home/dsl/.xtdesktop!
cp [location_of_icon] ./home/dsl/.xtdesktop

Create the .lnk file neeeded.
touch ./home/dsl/.xtdesktop/my_program.lnk
nano ./home/dsl/.xtdesktop/my_program.lnk

A sample of the .lnk file:
table Icon
Type: Program
Caption: ImageMagick
Command: /opt/imagemagick/bin/display
Icon: /home/dsl/.xtdesktop/imagemagick.xpm
X: 420 (X position)
Y: 384 (Y position)
end


Optional:
If we want a menu entry in the DSL menu for the extension (most probably, unless the application is mainly run from console with parameters)
mkdir -p tmp/mydsl.menu
touch tmp/mydsl.menu/my_program

Edit the menu entry file.
nano tmp/mydsl.menu/my_program

The format for the contents of the file is as follows:
[exec] (display name) {command}

An example:
[exec] (Launch my_program) {sh /opt/my_program/launch.sh}

Just add more lines to the file using the same format for additional menu entries.

Step 2:
Copy the program files.
cp -Pr /opt/my_program ./opt/

# only if there are other files needed in /home/dsl
cp -Pr /home/dsl/whatever ./home/dsl/


Step 3:
Change ownerships.
chown -R 0.0 ./opt/
chown -R 0.0 ./tmp/
chown -R 1001.50 ./home/dsl/
chown 1001.50 ./tmp/mydsl.menu/my_program


Step 4:
Create file list.
find . > files.txt


Step 5:
Edit the file list, remove all entries that're directories &/or dot paths (refer to wiki)
nano files.txt


Step 6:
Create the archive.
tar cvf my_program.tar --no-recursion \
--numeric-owner -T files.txt

gzip -9 my_program.tar


Optional:
If this is an extension for the official DSL repository, be sure to create an info file (check some of the others for reference) and md5sum:
md5sum my_program.tar.gz > my_program.tar.gz.md5.txt


Troubleshooting:
- If the extension might not work at first, try checking the shell scripts for dot (/relative) paths and changing them to absolute paths.





PS: Do drop me a comment if you found this useful, or if you have any comments/suggestions to leave behind!

Making a new DSL cloop file

This HOWTO is meant to be a correction for the steps found in the DSL wiki to create a new cloop file for 4.2.4. I'll leave the why for your reading from that page itself. ;)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Some things to note before we start:

DSL usually represents the path and file of the KNOPPIX image as
/cdrom/knoppix/knoppix
when in MSDOS/Windows it's represented as
[drive]:\KNOPPIX\KNOPPIX

You should always type the image filenames in DSL as all caps even though it shows up otherwise, in case of any incompatibilities with syslinux/isolinux. ;)

I use /tmp as the base working folder. Feel free to use any other folder that has enough space.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Step 1:
Locate where the KNOPPIX image is stored and setup a loop device to access the image.
sudo su
losetup /dev/cloop1 /cdrom/KNOPPIX/KNOPPIX


Step 2:
Mount the cloop.
mkdir -p /mnt/loop
mount /dev/cloop1 /mnt/loop


Step 3:
Copy everything to the temporary storage.
cp -a /mnt/loop /tmp
SAND_BOX=/tmp/loop
cd $SAND_BOX


Step 4:
Do what you want with the temporary storage ;)

Step 5:
Create a new compressed image.
mkisofs -hide-rr-moved -allow-leading-dots \
-R -l -V "KNOPPIX ISO9660" \
-v -allow-multidot $SAND_BOX | \
create_compressed_fs - \
65536 > [location_for_new_image_file]/KNOPPIX2


Step 6:
Unmount and detach.
cd $HOME
umount /mnt/loop
losetup -d /dev/cloop1


Optional:
If you're storing the new image file on a USB thumb drive, remember to make sure that the file is properly written to it before unplugging it. The way I do it is to unmount the volume, wait for the command to complete, then unplug.
umount [mount_point_for_USB_thumbdrive]


Testing:
We can test the new image file using this cheat code at startup (for syslinux/isolinus) :
dsl knoppix_file=KNOPPIX2



PS: Do drop me a comment if you found this useful, or if you have any comments/suggestions to leave behind!

DSL articles

Will be writing a couple of short HOWTOs for Damn Small Linux (DSL). Both to record down the steps, and also to correct the steps as shown in the original DSL wiki.

[update]
Making a new DSL cloop file (adapted and modified from here)
Creating a tar.gz MyDSL extension (adapted and modified from here)

Friday, November 16, 2007

HOWTO: Use VMware Player with a Live CD

Over the past few months, I've learnt far aplenty from various people's HOWTOs and papers, from the very simple to the stuff that I still don't really understand up till now. So just to exercise some writing muscle (if there's any left) and to contribute back to the community at large, here's a simple HOWTO ;)

------------------------

===Introduction===
VMware Player allows for running of virtual machines or preconfigured VMware Appliances from a single OS, meaning that we don't have to go through a costly repartition-format-install whenever we want to try out or run a different OS.

Many Linux distributions come packaged as a Live CD to help reduce the costs of trying out the OS, but a reboot with a CD-ROM drive and a CD burnt from the ISO file is needed. For people like me who have ultraportable laptops (no attached CD-ROM drive), don't want to have too many CDs lying around and don't want to go through the trouble of rebooting my M$ Windoze OS all the time, the VMware Player-Live CD combination would be the best in this case.

There are various restictions/limitations (not mentioned here) when using VMware Player with Live CDs depending on your needs, but for learning and trying out purposes these don't pose any problems.

===Instructions for use===
1. Download and install the free VMware Player.

2. Download the Live CD ISO which you wish to try out (e.g. Ubuntu, DSL, etc.)

3. Go to EasyVMX.com to create the VMware Player config file needed to run the virtual machine. The Super Simple Edition would suffice for our uses here.

4. Configure the page as follows:


Virtual Machine Name: Any name you want

Virtual Machine Operating System: Usually Generic Linux 2.6.x for more recent Linux versions

Virtual Machine Memory Size: Stick to the default (safe) option (320MB)

Virtual Machine Disk Size: No Disk (live CDs don't need hard drive space to function, only memory)

LiveCD (ISO): Here's the important part. Check the Enabled box and fill in the full filename of the Live CD ISO that you downloaded in step 2, including the ".iso" extension.
5. Click on "Create Virtual Machine"

6. Click on the link to download and open the ZIP file.


7. Navigate to the deepest folder, there you'll see a .VMX file named by your virtual machine name. Extract this to the same folder where you kept your Live CD ISO file.

8. You need to do some editing here. Fire up WordPad, and get it to open the VMX file you just unzipped. (You'll need to get it to show all filetypes)


9. Scroll down to the portion which says this:
# Settings for physical CDROM drive
ide1:0.present = "TRUE"
ide1:0.deviceType = "cdrom-raw"
ide1:0.startConnected = "TRUE"
ide1:0.fileName = "auto detect"
ide1:0.autodetect = "TRUE"

# LiveCD
ide1:1.present = "TRUE"
ide1:1.fileName = "mylivecd.iso"
ide1:1.deviceType = "cdrom-image"
ide1:1.startConnected = "TRUE"
ide1:1.mode = "persistent"
And swap the "ide1:0"s for "ide1:1"s. If you don't do this step VMware Player will not be able to find the ISO file when booting up, and you won't be able to use the Live CD ;)

The results of that section should look like this:
# Settings for physical CDROM drive
ide1:1.present = "TRUE"
ide1:1.deviceType = "cdrom-raw"
ide1:1.startConnected = "TRUE"
ide1:1.fileName = "auto detect"
ide1:1.autodetect = "TRUE"

# LiveCD
ide1:0.present = "TRUE"
ide1:0.fileName = "mylivecd.iso"
ide1:0.deviceType = "cdrom-image"
ide1:0.startConnected = "TRUE"
ide1:0.mode = "persistent"
10. Save the file.

11. Double click on the .VMX file, and you're on your way to using the Live CD! Enjoy ;)



PS: Do drop me a comment if you found this useful, or if you have any comments/suggestions to leave behind!