Friday, October 22, 2010

Password for null GNOME keyring in SVN

Today I tried to commit my codes to the google code repository after working on my 3rd year project. But when commit it asked me this,

> Password for '(null)' GNOME keyring:

I didn't have any idea about it and I had't faced to a such prompt before. I typed my SVN account password but failed. I searched through web to find out what is this GNOME keyring and what's wrong with that. Finally I found that there are more people who had faced to such a problem.

https://bugs.launchpad.net/ubuntu/+source/subversion/+bug/473139

https://bugs.launchpad.net/ubuntu/+source/gnome-keyring/+bug/593108

There was a solution suggested to avoid the SVN prompting for a password for a keyring. That was putting commnd in the terminal.

> rm ~/.gnome2/keyrings/login.keyring

After giving this command in the terminal I committed and that keyring asking was gone. Usual username and password for SVN were asked and after entering them, the codes are successfully committed. But then suddenly a dialog box appeared and asked me to enter a new password for a keyring. I typed my login password there to face whatever happens.
No problem occurred up to now after doing that. However still I have no clear idea about what are those keyrings. :)

( It seems this link also useful. But I found this one after everything is over )

Tuesday, August 24, 2010

Linking C libraries to php extensions

After learning to create a simple php module it took a long time for me to understand the correct way of porting an existing C library to to a php module. Sometimes I thought it may be impossible for me. After all I have managed to understand the correct way of doing it. If you need to learn about creating a simple php module, follow this article. So, here's the procedure I followed to build the php module which is linked to a C library.

1) First step is creating a simple C library to link to a php module. So, write and save the following source files.

Here's the "asanka.c" file,

#include
#include "asanka.h"

void setValue(int a){
value = a;
}

int getValue(){
return value;
}

void increment(){
value = value + 1;
}

void decrement(){
value = value - 1;
}


Here's the "asanka.h" file,

#include

int value;

void setValue(int a);

int getValue();

void increment();

void decrement();


Now create the C library called "libasanka.a" by giving the command,

gcc -c asanka.c
ar -cr libasanka.a asanka.o


Ok, now we have the library. Create a directory in some place, lets's say in your home directory as the "library". Inside that directory, create two directories as "lib" and "include". Put the library file "libasanka.a" into the "lib" directory and "asanka.h" file to the "include" directory. So, now the paths to both should be,

/home/username/library/include/asanka.h
/home/username/library/lib/libasanka.a


There's a reason for giving the path's of the files. We have to give the path when we create the php module.

2) Now it's time to create the php module. Goto ext directory of the php source and give the command in the terminal,

./ext_skel --extname=asanka


3) Now go into the newly created directory "asanka" inside the ext directory and open the auto generated file "asanka.c" (this is not the file we created). Add the following entries in the appropriated places,

PHP_FE(asanka_setValue, NULL)
PHP_FE(asanka_getValue, NULL)
PHP_FE(asanka_increment, NULL)
PHP_FE(asanka_decrement, NULL)


Add the following entries also in the appropriate place in the file,

PHP_FUNCTION(asanka_setValue)
{
int locValue;
int argc = ZEND_NUM_ARGS();

if (zend_parse_parameters(argc TSRMLS_CC, "l", &locValue) == FAILURE) {
php_error_doc_ref(NULL TSRMLS_CC, E_ERROR, "Invalid Parameters");
return;
}

setValue(locValue);
}

PHP_FUNCTION(asanka_getValue)
{
int locValue;
locValue = getValue();
RETURN_LONG(locValue);
}

PHP_FUNCTION(asanka_increment)
{
increment();
}

PHP_FUNCTION(asanka_decrement)
{
decrement();
}


4) Now open the file "php_asanka.h" in the same directory and add the following to it,

PHP_FUNCTION(asanka_setValue);
PHP_FUNCTION(asanka_getValue);
PHP_FUNCTION(asanka_increment);
PHP_FUNCTION(asanka_decrement);



5) Open the config.m4 file and add change it's content to be match with the following code,

dnl $Id$
dnl config.m4 for extension asanka

dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.

dnl If your extension references something external, use with:

PHP_ARG_WITH(asanka, for asanka support,
[ --with-asanka[=DIR] Include asanka support])

dnl Otherwise use enable:

dnl PHP_ARG_ENABLE(asanka, whether to enable asanka support,
dnl Make sure that the comment is aligned:
dnl [ --enable-asanka Enable asanka support])

if test "$PHP_ASANKA" != "no"; then
dnl Write more examples of tests here...

dnl # --with-asanka -> check with-path
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
dnl SEARCH_FOR="/include/asanka.h" # you most likely want to change this
if test -r $PHP_ASANKA/lib/libasanka.a; then # path given as parameter
ASANKA_DIR=$PHP_ASANKA
else # search default path list
AC_MSG_CHECKING([for asanka files in default path])
for i in /usr/local /usr; do
if test -r $i/lib/libasanka.a; then
ASANKA_DIR=$i
AC_MSG_RESULT(found in $i)
fi
done
fi
dnl
if test -z "$ASANKA_DIR"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please reinstall the libasanka distribution - asanka.h should be /include and libasanka.a should be in /lib])
fi

dnl # --with-asanka -> add include path
PHP_ADD_INCLUDE($ASANKA_DIR/include)

dnl # --with-asanka -> check for lib and symbol presence
LIBNAME=asanka # you may want to change this
LIBSYMBOL=getValue # you most likely want to change this

PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
[
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $ASANKA_DIR/lib, ASANKA_SHARED_LIBADD)
AC_DEFINE(HAVE_ASANKALIB,1,[ ])
],[
AC_MSG_ERROR([wrong asanka lib version or lib not found])
],[
-L$ASANKA_DIR/lib -lm
])
dnl
PHP_SUBST(ASANKA_SHARED_LIBADD)

PHP_NEW_EXTENSION(asanka, asanka.c, $ext_shared)
fi


6) Now run the following commands in terminal inside the "asanka" directory,

/usr/local/bin/phpize

./configure --with-asanka=/home/username/library/

sudo make


7) Now our new module is ready. You can find it in the "modules" directory inside the "asanka" directory. Copy that "asanka.so" shared object to the extensions directory of your installed php. If you don't know the path to the extensions directory, look at the phpinfo() page.

8) After placing "asanka.so" into the extensions directory, next thing is editing the php.ini file. Open it and add an entry as follows in the appropriate place,

extension=asanka.so

9) Now every things ok. Write a php file with the following content and place it in the "htdocs" directory of the apache server,

asanka_setValue(10);
asanka_increment();
asanka_increment();
echo asanka_getValue();


Check whether your web browser displays the correct output. If you see number 12, then your C library works correctly with the php module.

Saturday, August 21, 2010

Fundamental issue in the integration of php-tsql module and tikirisql library.

I think we've faced with a serious problem in works. Yesterday night I was working on integration of the php-tsql module with the tikirisql library. I was faced with a situation where it's hard to compile the integrated php module since it's makefile is an auto generated one. I think our tikirisql library makes us troubles since it's coded for a general purpose. I directly called the tikirisql's functions inside the php-tsql module. Then I compiled and placed it in my php extensions directory. When I try to run a testing php script in apache server which uses our php modules functions, the php file's going to be downloaded without rendering on the browser.
I think most probably the reason should be the usage of tikirisql's C files and header files within the php module. There may be some restrictions by the creators of php about the way we create extensions to the php.
Sometimes the same problem may have been encountered by the MySQL community who use a very simple php module which does only the exchanging of the web client's queries to MySQL server and results back to clients browser. They doesn't do parsing stuff in php module. I looked at the mysql module in php. It's very simple with only the standard source files. Those standard files are in each and every module in php. As I understand everything the mysql people has changed is the content in those source files. They have written new functions and called them. Therefore I think there may be a big reason for not using external libraries inside php modules.
I think we have to study more about the php internals to understand the problem and to find a possible solution.

Tuesday, August 17, 2010

A php progress bar

From several days I was trying to add a progress bar to the FIT4D's acquiring disk image front end. Even though I couldn't finish it, I thought to write a note about the things I learned from it. I found a php progress bar from here http://webscripts.softpedia.com/script/PHP-Clases/PHP-Progressbar-25825.html. Then I included the following code in a php file and opened it with browser.


require_once 'ProgressBar.class.php';
$bar = new ProgressBar();
$elements = 1000000; //total number of elements to process
$bar->initialize($elements); //print the empty bar
for($i=0;$i<$elements;$i++){ //do something here... $bar->increase(); //calls the bar with every processed element
}



Then it worked as the developer of it mentioned. Now the hard part. I wanted to include it in our front end. But even though I included the above code segment inside the create_img2Main.php file in the lib directory of the FIT4D source, it doesn't show the dynamic progress bar. Instead, it suddenly shows the final state of the progress bar which is 100% filled.
According to my understanding, I think this is because the file create_img2Main.php is loaded using an ajax request from create_imgMain.php through functions in global.js file. I hope to discuss about the issue with Yasantha akka tomorrow.

Monday, July 26, 2010

Installing Forensic Investigation Toolkit (FIT4D)

To install FIT4D forensic investigation toolkit in Linux we need some extra tools which are necessary for the proper operation of FIT4D. Therefore first you have to install the following tools,

sudo apt-get install sleuthkit
sudo apt-get install ddrescue
sudo apt-get install foremost


Then if you haven't installed apache2 server with php5 and the mysql database server, you have to install them also. To do them give the command,

sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

When the installation proceeds it asks to set a password for the mysql root user. I set the password as "root" because in the FIT4D installation it asks for the root users password of the mysql database.
After setting this environment which is necessary to install FIT4D I have to check in the php.ini file whether,

register_globals="off"

is set to "off" as above. Then I copied the FIT4D source folder to the www directory of the apache2 server. In that source directory goto ~/www/FIT4D/config folder. If there is a install.lock file, delete it. Then start your apache2 server and mysql database server by issuing the commands,

sudo service mysql start
sudo service apache2 start


Now open your web browser(tested for firefox) and goto http://localhost/fit4d/.

Fill the information asked in the form, and click the button "configure". Now you can login to the system and go around.
However according to the source codes of FIT4D I've got, the database (named as "ptk") which is created by the installation process is not complete enough. Therefore I had to run an extra SQL script which is given to me in addition to FIT4D source. There's another thing to do. The tools we've install at the beginning are going to be used by the FIT4D system. Therefore the FIT4D system should be given permission to run those tools. To do it, I added an entry to the sudoers file in /etc/ directory. To change the sudoers file you should use the command,

sudo visudo

in terminal. When the file is opened, I entered the following text to the end of it.

www-data ALL=NOPASSWD: ALL

ok, now according to the specification we've completed the installation.

Saturday, June 26, 2010

Prevent apache2 from starting at boot time.

Apache2 server in my Ubuntu machine was used to start at each time I boot the Ubuntu. I found it recently and realized the reason which made me feel that machine is slow than the past days. Therefore I removed apache2 from the starting up at boot time by giving this command.

sudo update-rc.d -f apache2 remove

Tuesday, June 15, 2010

Installing Contiki and Cooja Simulator in UBUNTU

About a week ago, I thought to install TikiriDB and tryout it. To use it I have to install Contiki operating system and the cooja simulator which are the platform to run TikiriDB. Started from reading the tikiriDB home page (http://score.ucsc.lk/projects/tikiridb). There's a link provided in that page which shows how to install contiki and cooja in Ubuntu 8.10 (installing contiki/cooja). However I'm running Ubuntu 10.04 Lucid and it works. The only issue is if your going to install netsim simulator provided with contiki, your in trouble because the required package (libgtk1.2-dev) is not supporting to Ubuntu 9.04 and 10.04 as I know. By the way, I forget netsim and advanced to all the other things.
Here we go,

1. I had to install CVS to get the CVS version of Contiki,

sudo apt-get install cvs

2. Got the contiki source,

cvs -z3 -d:pserver:anonymous@contiki.cvs.sourceforge.net:/cvsroot/contiki co contiki-2.x

3. There is an example directory in the Contiki source which contains some example codes. To compile the hello-world example,

cd contiki-2.2.2/examples/hello-world

make TARGET=native

./hello-world.native

4. After testing that hello world example I cleaned the temporary files during the compilation,

make clean

5. Now contiki is ok. Then I needed java, since the cooja is a java based simulator,

sudo apt-get install sun-java6-jdk

6. To compile cooja I needed ant which is a compile tool,

sudo apt-get install ant

7. To compile and start cooja I gave the commands,

cd tools/cooja

ant run

8. To remove all the temporary files created during the compilation,

ant clean

After these steps cooja was started and I was exited by the facilities given in cooja. Then I stopped working on it and hope to complete the further configuration steps of cooja later.