Home page of this blog

Thursday, September 30, 2010

Java code to parse a big contact.vcf file into multiple contact files

My old mobile is often crashing and restarting. I wanted to transfer my contacts from old mobile to new mobile, when I got a single Contact.vcf file from old mobile. This file contained all the contacts, but new mobile accepted only one contact from a .vcf file

I wrote the program now and transfered all my contacts, if someone maybe facing a similar problem,  ... so I just post the source code.

A single .vcf corresponds to a business card

Here is the program I wrote for my personal use to split a single big Contact.vcf to multiple contact files, here I used the contact name as the name of the new business card file. Thanks to java ... I did not spend much time on perl or python ...

import java.io.*;
import java.util.*;

public class splitter
{
 public static void main(String[] args) throws Exception
 {
  FileReader fin = new FileReader(args[0]);
  BufferedReader in = new BufferedReader(fin);

  LinkedList<String> contactNames = new LinkedList<String>();
  LinkedList<String> contactsList = new LinkedList<String>();

  StringBuffer contact = null;

  boolean hasName = false;

  for(String sLine = in.readLine(); sLine != null; sLine = in.readLine())
  {
   if(sLine.startsWith("BEGIN:"))
   {
    contact = new StringBuffer();
    hasName = false;
   }
   else if(sLine.startsWith("END:"))
   {
    contact.append(sLine + "\n");
    if(hasName)
    {
     contactsList.add(contact.toString());
    }
    contact = null;
    continue;
   }
   else if(sLine.startsWith("N:"))
   {
    String[] tokens = sLine.split(":");

    if(tokens.length == 2)
    {
     hasName = true;
     String[] names = tokens[1].split(";");

     if(names.length >= 1)
     {
      contactNames.add(((names.length >= 2)?names[1]:"") + "_" + names[0]);
     }
    }

   }

   contact.append(sLine + "\n");
  }

  in.close();
  fin.close();

  Iterator<String> it = contactsList.iterator();

  for(String contactName: contactNames)
  {
   System.out.println("ContactName:" + contactName);

   String sFileName = contactName.replaceAll(" ", "_");

   String sContact = it.next();
   System.out.println(sContact);

   FileWriter fw = new FileWriter(sFileName + ".vcf");
   PrintWriter out = new PrintWriter(fw, true);

   out.println(sContact);
   out.close();

   fw.close();

  }
  
 }
}

Monday, September 20, 2010

How to check if Ubuntu 64bit system is exploited by CVE-2010-3081 exploit

Note: This exploit check is needed only for 64 bit linux systems and do not bother if you have 32 bit linux systems

Having 64 bit ubuntu systems and not updated your kernel yet from security repositories? It may have been infected by exploit

CVE-2010-3081


To know more about exploit 
To check if kernel is infected by this exploit in Ubuntu follow the link


 https://www.ksplice.com/uptrack/cve-2010-3081.ssi.xhtml

If you don't know how to compile the tool yourself follow this step by step

Step 1: 

Download source code of the tool which checks if there is an exploit from

https://www.ksplice.com/support/diagnose-2010-3081.c

Step 2:

Compile it

gcc diagnose-2010-3081.c

Step 3:

Run the tool as a normal user (do not run as root!!)

./a.out


You should see a message like


Your system is free from the backdoors that would be left in memory
by the published exploit for CVE-2010-3081.



If you are not getting the above kind of message, it means your system is infected. If your system is compromised, disconnect internet first, then follow whichever fix is relevant. Simplest way is reinstall OS, scan your home folder for infected files




Note: This exploit check is needed only for 64 bit systems and do not bother if you have 32 bit linux systems. To know if you have 64 bit system use


uname -a | grep x86_64


If the result is displayed it means, you are running 64 bit system

Saturday, September 18, 2010

Installing new Adobe Flashplayer 64 bit in Ubuntu using a single command without using a PPA

Recently Adobe released 64 bit flashplayer for Windows, Mac and Linux.

I saw lots of links specifying on using a PPA and I did not want to as I don't know the creator of the PPA. Here I share how I installed 64bit preview flashplayer in my ubuntu in a single shot

This is how I installed the new 64 bit adobe flash player in a single command

sudo apt-get remove flashplugin-nonfree flashplugin-installer && mkdir -p flashplugin-64 && cd flashplugin-64 && wget -c http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_2_p3_64bit_linux_111710.tar.gz && tar xzf flashplayer10_2_p3_64bit_linux_111710.tar.gz && sudo cp libflashplayer.so /usr/lib64/mozilla/plugins/


Just copy the above command and paste it in your terminal

Explanation of the command in detail (in case you wonder what it does )

sudo apt-get remove flashplugin-nonfree flashplugin-installer 
removes existing flashplugin package from ubuntu repository


mkdir -p flashplugin-64 
creates a new directory named flashplugin-64 if it is not there


cd flashplugin-64 
changes to the directory flashplugin-64


wget -c http://download.macromedia.com/pub/labs/flashplayer10/flashplayer_square_p2_64bit_linux_092710.tar.gz


fetches the preview flashplayer tarball from adobe website (whose codename is called square) and puts in current directory


tar xzf flashplayer_square_p2_64bit_linux_092710.tar.gz
unzips the fetched tarball 


sudo cp libflashplayer.so /usr/lib64/mozilla/plugins/ 
copies the newly extracted flashplayer shared object into 64bit plugin folder of mozilla




The below screenshot  shows the command in action






The below screenshot shows the plugin list in chromium




Below screenshot shows the plugin list in Firefox x64 beta 6

Saturday, September 11, 2010

Configuring rpmfusion kernel module for ASUS N13 Wifi USB adapter in Ubuntu Lucid

Recently I bought ASUS USB Wifi N adapter after seeing it had linux support.

The details of this adapter as printed by lsusb is as follows

Bus 001 Device 002: ID 0b05:1784 ASUSTek Computer, Inc.


I thought it will be detected straight away by Ubuntu when I plugged in. That was not the case. The model required rt3070sta kernel module. This I came to know from searching Ubuntu forums. The module is in staging and it is still rt2870sta and did not work.

Now that it did not work for me, I compiled the source code bundled in the CD and connected to my home router. But it was not the latest source code. So I went to ralink site and downloaded the source and compiled it. But the code had debug prints to log to systemlog and it kept filling syslog. oops

To my surprise Windows 7 pulled the driver from net, autoconfigured and no need to tell it is way ahead of the curve. Now back to Ubuntu

I wanted to get the latest rt3070sta driver source compiled for 2.6.35 kernel in Lucid, and I ended up in compilation errors. Then came an idea, that rpmfusion would have compiled the driver for 2.6.34 for Fedora 13 and 2.6.35 for Fedora 14 rawhide, so I went straight to rpmfusion website and downloaded the source code

Then I experimented patched driver source from rpmfusion.org in Ubuntu. And the experiment worked extremely well to my delight. There was no compilation errors, not with 2.6.32 or 2.6.35 kernel, wow, Fedora and its community rocks as always

There was no flooding debug prints, no unncessary tftpboot configuration, support for 2.6.34 kernel ... the signal was good and everything seemed to work well with the patched source code from rpmfusion.org



Here is the summary of what I did to configure the ASUS Wifi module step by step, as this may help someone


Step 1

Download rt3070-kmod src rpm from rpmfusion updates for Fedora 13, http://download1.rpmfusion.org/free/fedora/updates/13/SRPMS/repoview/index.html

http://download1.rpmfusion.org/free/fedora/updates/13/SRPMS/rt3070-kmod-2.3.0.2-1.fc13.5.src.rpm


Step 2

Install p7zip-full if it is not already installed, this is to extract the source rpm

sudo aptitude install p7zip-full


Step 3

Extract the source rpm, by right clicking the downloaded rpm





Step 4

Change to extracted directory and extract DPO_RT3070_LinuxSTA_V2.3.0.2_20100412.tar.bz2





Step 5

Copy all the patch files into the newly extracted directory

cp rt3070-*.patch DPO_RT3070_LinuxSTA_V2.3.0.2_20100412/




Step 6

Installing the patches

Change to extracted folder where the patches have been copied (see previous step 5)




Brief explanation of what the patches does

rt3070-2.6.34.patch --> To avoid errors when compiling with kernel version 2.6.34 and above (this is due to the function usb_buffer_alloc and usb_buffer_free is not there from 2.6.34 and changed to usb_alloc_coherent and usb_free_coherent)
rt3070-no2.4-in-kernelversion.patch --> This patch removes kernel 2.4 support from the makefile
rt3070-Makefile.x-fixes.patch --> Fixes makefile installation rule
rt3070-strip-tftpboot-copy.patch --> This patch removes configuring tftpboot while installing the driver
rt3070-suppress-flood.patch --> To avoid numerous debug logs. This patch comments out debug logs

Install the patches in the correct order as mentioned below

1.To apply rt3070-2.6.34.patch run the following command --> patch -p1 <rt3070-2.6.34.patch
2.To apply rt3070-no2.4-in-kernelversion.patch run the following command --> patch -p1 <rt3070-no2.4-in-kernelversion.patch
3.To apply rt3070-Makefile.x-fixes.patch run the following command --> patch -p1 <rt3070-makefile.x-fixes.patch
4.To apply rt3070-strip-tftpboot-copy.patch run the following command --> patch -p1 <rt3070-strip-tftpboot-copy.patch
5.To apply rt3070-suppress-flood.patch run the following command --> patch -p1 <rt3070-suppress-flood.patch






Step 7

To avoid possible conflict with 2870 driver

Run this command (just copy the following and paste in the command line)


for sta in common/rtmp_init.c include/rt_ate.h include/os/rt_linux.h README_STA* RT2870STACard.dat ; do
sed 's|RT2870STA|RT3070STA|g' $sta > tmp.sta
touch -r $sta tmp.sta
mv tmp.sta $sta
done










Step 8

Build the kernel module

CFLAGS="-march=native -O2" make -j8

change -j8 to -j2 if you have core2duo, and -j4 if you have quadcore






Step 9

Copy the data file after creating the data directory for the module

sudo mkdir -p /etc/Wireless/RT3070STA

sudo cp RT2870STA.dat /etc/Wireless/RT3070STA/RT3070STA.dat



Step 10

Insert the module into the running kernel after copying into some directory which is common to all users

sudo cp os/linux/rt3070sta.ko /usr/local/bin/rt3070sta-rpmfusion-lucid.ko

sudo insmod /usr/local/bin/rt3070sta-rpmfusion-lucid.ko

Now configure networkmanager to connect to whichever wireless accesspoint you want to join and save it

Step 11

To automatically detect your wireless driver from next boot, add the following line before last line to /etc/rc.local by editing it as root



Upon reboot, your network adapter should be autodetected and connected (if you configured network manager to do so)


Step 12

Whenever there is a new kernel or kernel change rebuild the module, by following above steps

Friday, September 3, 2010

linux locate command

Today evening, my colleague was searching for a header file (errno.h) using nautilus in Ubuntu. He was waiting for his search to complete and making fun of the gnome icon doing animation. He waited for another 15 minutes ...

But, still nautilus kept on searching ... not a single result. Then I offered him my help, by opening command line.

locate errno.h






and instantly, it displayed all the files to the disbelief of my colleague

So do you want to search system files like that instantly? Use locate command



locate <system filename you want to search >


say for e.g I want to find javadoc, index.html path to open javadoc locally, here is how I search

locate index.html | grep java








Invoke updatedb as rootTo keep your locate db always updated which is maintained as an index for that superfast search

sudo updatedb