Saturday, November 19, 2011

Drupal development, a more pleasant way.

Why this post


In my spare time I am making a website for a youth movement using Drupal. Drupal is a very nice CMS that is quite powerful. You can use a lot of code (modules) that are provided by the Drupal community but if it goes wrong it might be hard to find out why. In the beginning I was just making my changes in the Drupal files and when I wanted to test them I uploaded the files to my hosting provider. It seems that it is hard to find a worse way of Drupal development :-). This week I noticed one of the major disadvantages of my approach. After uploading some code my site reported a 500 error message (server error). Since I don't have access to the server itself I couldn't check if it was indeed the server that was erroneous or that it was something I have done. The next day I still got the same error so it was likely that my code was at fault. Finding the fault was quite hard because the only hint I got was (500 server error). Then I realised that it was my own fault. If you want to do some development you should always invest some time in setting up a proper development environment. I knew this when I started the website project but I was too lazy to do it. Now I found out that is was plain stupid since it is very easy to setup a nice Drupal development!

How to quickly setup a good Drupal development environment.


Thanks to some Drupal enthousiasts setting up a Drupal development is easier than ever. There is a Drupal Quickstart project that provides a virtual machine that contains an Ubuntu OS that is configured for some serious Drupal development. You can find the project at http://drupal.org/project/quickstart. Just follow the steps explained on that website to set up the environment.

The Ubuntu OS contains a Drupal 6 and a Drupal 7 example and also has some nice scripts to setup new Drupal installations. Unfortunately I already had started development and I didn't want to lose my previous work.

Importing an existing Drupal project in you development environment


I had my Drupal files on a USB stick so I could easily import them into the Virtual Machine. I also had a backup of the Drupal tables from my database that I made using phpmyadmin (It is wise to use a prefix like 'Drupal_' or a separate database when performing a Drupal installation).

Setting up the database


In the Virtual Machine (Quickstart) you launch firefox. In the toolbar there will be a link to PHPMyAdmin. You browse to PHPMyAdmin and login using the root as username and quickstart as password. Without selecting a database you click on SQL on the left pane.


This will give you a window where you can enter MySQL statements. Make a user that has the same name as you used when making your Drupal installation and give him the same password.


CREATE USER 'YOUR_USERNAME'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD_IN_PLAIN_TEXT';


After typing this statement you click 'Go'. Next you'll have to make the table that you used when making your Drupal installation.


CREATE TABLE TABLE_NAME_FROM_YOUR_DRUPAL_INSTALL;


Now you'll have to make sure that your user has the appropriate rights on your table. Because this is a development environment it won't hurt to grant him all rights.


GRANT ALL PRIVILEGES ON TABLE_NAME_FROM_YOUR_DRUPAL_INSTALL.* TO 'YOUR_USERNAME'@'localhost';



Logout of PHPMyAdmin and log back in using YOUR_USERNAME and YOUR_PASSWORD_IN_PLAIN_TEXT. Now select the table of your Drupal Install which is still empty. Now you can click on import tab on the right pane. There you can select your SQL backup file (click browse) and confirm it (click go). Now your Drupal tables will be imported. I had my files gzipped and I got a strange error. Trying the unzipped SQL-file worked for me. Congratulations your database is setup!

Placing the Drupal files.


For consistency I thought it would be best to place the Drupal files in the websites folder which is located in the home folder of the Quickstart user. Just make a new dir that identifies your drupal installation (e.g. drupal_42) and place the files of your Drupal project there. See to it that you also copy the .htacces file. Files starting with a dot are hidden in Linux. You can make them visible in nautilus by pressing ctrl+h or by using the menu: View-> Show hidden files.

Making it work


All the contents of your Drupal project are in place but how can you view your website? For this you need to do some additional setup. Notice that in the websites folder (/home/quickstart/websites) there is a config folder. This folder contains (links to) all the necessary configuration files that you'll need. Will split the changes per file.

hosts


Here you can set aliases that point to IP-addresses. As your localhost (your Virtual machine) will generate your site you will need to setup the name (URL) of your website to point to your localhost. This can be done by adding a rule at the end of the file. You can see that there are already URLs pointing to the localhost, these are the example Drupal installations that are pre-installed. Just add a rule with a URL you like.

Then save your file and close it.

Apache


Next you'll have to configure Apache. Apache is the server which will generate the HTML using the PHP files. Your site needs to be registered to Apache so it knows that is should process the necessary files. The configuration files of Apache can be found by following apache-sites-available link in /home/quickstart/websites/config. There you see the config files of the other pre-installed Drupal sites. As I wanted to get my installation working without too much trouble, I made a copy of example.dev named drupal42.dev. Then I changed the content to reflect my project. It is rather straightforward. Just change example.dev into drupal42.dev. And where you see a path pointing to the example.dev folder, you change it to the folder where you copied your Drupal project files. Save your changes and all the configuration is done. It might be necessary to restart Apache to notice the configurationfiles.


sudo /etc/init.d/apache2 restart



The result


To view the result open up firefox and browse to your URL (e.g. http://drupal42.dev/). And you should see your website. If you get a permission denied error you should check the permissions of your files from your drupal installation. The owner should be quickstart and the group should be www-data. (browse to root folder using a command shell and execute sudo chown -R quickstart:www-data . , including the dot!). If it still doesn't work make sure group permissions are set correctly (they should be able to read and execute files). sudo chmod -R 755 *

It works, now what?


Now you have got a server which you can configure yourself. The default is actually good already for development. Warnings and errors are shown in the browser so you can get more debug information than on a production server. There are also IDEs installed on the Virtual machine. Eclipse and Netbeans. I have setup Netbeans but you can use Eclipse also.

Netbeans


Launch netbeans from your desktop or from the upper gnome panel. Click File->New Project... Then in the new window select PHP project with existing sources. Click Next. Then you can select your source folder using the browse button and give the project an appropriate name. You can also select a PHP version that you want to use. Click next again and look at the run configuration. Make sure that the project URL is correct. This is the URL where you browse to see your website in your development environment. The default is http://localhost/drupal42.dev/ so you probably have to change this to http://drupal42.dev/. When you click finish your project will be imported into the IDE.



Why should you use an IDE for development? There are multiple reasons actually. You have good syntax highlighting. You have tools for Version control that are integrated into the IDE. You can do real debugging (Setting breakpoints, stepping through code, examining content of variables,...). If you don't know Netbeans or Eclipse it might be interesting to learn how to work with one of them. They are both pretty nice. There are sometimes plugins which configure the IDE for you for Drupal development. I think Eclipse can generate code for Drupal hooks. (Yes it does http://drupal.org/node/75242#templates and for netbeans http://drupal.org/project/nb_templates). Don't you love open source community software :-).

And what was the error?


I had a typo in the code for my own custom module. After my function there was one } too much. Again, plain stupid.

Friday, November 4, 2011

Android Recover Mail password

It's probably necessary that your device is rooted in order to be able to do this. I'm not sure though. This blog post is for people willing to recover there OWN password, do not misuse this information.

Prerequisites


Before you can start, it is necessary that the tools of the Android SDK are installed and ready to be used. How to install these tools is explained here


The story


We want to recover the password of our e-mail account. Because android needs this password to download your e-mail, it will store the password on your phone. The data of applications is stored in /data/data. At that location there are directories for the different applications. The directory for mail is com.android.email. There we have to find the password. The password is located in 1 of the databases that is in the com.android.email folder. The databases are SQLite databases, so the easiest way to recover the password is by browsing the databases using an appropriate tool.


The recovery steps


First you need to get the contents of com.android.email. (You don't need it all but this way you can inspect the other contents also.) This is done by executing the following command in the shell of your ubuntu installation:

adb pull /data/data/com.android.email ~/email_of_phone

This will place the contents in a folder named "email_of_phone" in your home directory.


Next you'll need to install a tool to explore the databasefiles. I have used SQLitebrowser which is in the repositories. Just install it by using the command:

sudo apt-get install sqlitebrowser

When this is done you'll have to launch the SQLitebrowser. Just use shell:

sqlitebrowser

The people who are no shell-enthousiasts can be happy, from now on everything is by GUI. The GUI is very straightforward. Click the Folder icon (with the arrow). This opens up a dialog window where you can select your database. The database will be 1 of the databases in ~/email_of_phone/databases. For me it was the EmailProvider.db so you should try that one first :-).


When the databases is opened you can see that there is a table called HostAuth. This might be interesting to find out our authentication credentials. So we click the + sign to the left of it.



Then we can see that it has indeed a password field!



But we are not interested in the table layout. We want the content of the table. So click the "Browse Data" tab.



The last step is changing the table that is shown to HostAuth.




Finally you can read the content of the table. In the Password field, you can read the password in plaintext.

Saturday, March 12, 2011

Quiet down a Noisy Fan (Sony VAIO VPCEB1S1E model PCG-71211M) (OS independent)

This post will tell you how to solve a noisy fan problem. My notebook ran hot very quickly resulting in a fan that is going crazy. (This post won't be about ubuntu nor android but the solution worked so well that I thought I should share it anyway.)

First it is interesting to think about any possible reasons your PC is running hot. If you are doing very intensive tasks it might be normal that it's hot. But if your notebook or PC runs hot when doing normal stuff (e.g. searching in a large PDF document) then there might be a problem with the heath conduction within your notebook.

My Notebook worked fine before so I knew it wasn't a design flaw of my notebook itself. One very likely possibility is that there is dust in your computer which prevents a good internal air (and thus heat) flow. Since my warranty expired 2 weeks before being fed up with the noise there was only 1 budget friendly solution, so I searched for my screwdrivers.

Before opening up a notebook it can be wise to search for a service/repair manual of your notebook which describes how to open up your notebook. As I couldn't find any on my model (PCG-71211M) I decided to work without a map. Be warned that notebooks can be quite a pain to put together again (ordinary PC's are like 4 piece jigsaw puzzles compared to notebooks!). Luckily my Vaio didn't need a lot of disassembling for my goal.

Now I will describe how I opened up my notebook with some accompanying pictures (you can click on them to enlarge them). If you try this yourself, know that it is on your own responsibility! Lets start with a picture:



This is the backside of your notebook, you might already familiar with it. You can notice that there are quite a lot of screws. Since they may vary in size it is important to work neatly. HINT: It can be useful to work on a large table and put the screw upside down on the table in the same layout you took them out of your notebook. (This sounds lame but if you've got more than 20 screws you won't remember which one went where.)

Ok, first remove the battery. Slide the lock and pull the release button away and you can roll out the battery. Your notebook should look now like the picture below. As you can see there already 19 screws visible (don't worry we only need to remove 21 screws in total).



When you remove screws 16 and 17 you can remove the cover protecting your hard disk. You can raise the cover at the side that is nearest to you (nearest to the bottom of the picture). Then you can see screws 21 and 22. Apparently I forgot number 20 when photo shopping the pictures and I am to lazy to redo them :-).



Now that all the screws are located remove them all! And I mean all of them. Otherwise you can force the body at the places where it is still screwed together! When all screws are gone you can first remove your Hard Disk. When screws 16,17,21 & 22 are removed you can slide your Hard Drive as depicted below. You want to treat this hard disk with care since it contains all your precious data.



After removing your Hard disk you can remove your CD/DVD drive. When screws 6 and 9 are removed, you can just slide it out.



You can also remove the cover that is fixed by screw number 10. Behind this is your RAM memory. I removed the RAM memory also but I don't think it is necessary. (The cover must be removed however!)

Now you should be ready to open up the body! Maybe to be sure you can do a last check to see if all screws are removed. Then you can start lifting the side that is nearest to you and open up the body like it was a treasure chest (full of dust). Be careful however, there are little plastic hooks that hold the body together. So you might have to apply some light pressure at some points using a screw driver. Be gently however since you don't want to break of any of the hooks. It is not hard but the first time you might have to get used to it. When your notebook is opened up it should look like this:



At this moment you might be a bit disappointed as you might have thought that there would be much more dust. But don't worry! The picture above was taken before the cleanup of my notebook so it didn't look too bad either! But the cleaning helped a lot! Before you start cleaning: REMOVE THE POWER SUPPLY OF THE FAN!. This is circled in blue on the picture above.

Now the cleaning can begin. I cleaned it using a vacuum cleaner which can blow air. If you don't have a vacuum cleaner which can blow you might want to search for cans containing pressurized air (so called air dusters). I've heard that sucking air isn't a good idea (don't know if this is true but I'd rather play safe). The metal on the upper part (see picture) I have cleaned using a cloth (that was a bit wet). Then I dried the cloth and cleaned it again. Make sure everything is dry when you put your notebook back together! The other parts I have blown out using the vacuum cleaner. When cleaning the ventilator you should hold it still using one of your hands. Be sure to send a strong air flow through the ventilator shaft. (The metal block that goes to the side of your notebook on the right.) Since this is a place were dust can easily get trapped. (Again hold the ventilator).

When the cleaning is done you can put your notebook back together by performing the steps above in reverse order. THE FIRST STEP IS TO RECONNECT YOUR FAN. If you don't reconnect your fan you are blessed with a notebook that will be very silent (but silence can (and will) kill!). The re-closing of the body is the hardest part. First make sure the back sides (sides furthest away from you) fit together and than close the body. Then gently press the body together at the sides. You might hear little clicking sounds.

Next insert the hard drive and CD/DVD drive again. Just gently slide them back in. Remember that screws 16 and 17 are there to keep the cap fixed to the body so they should be screwed after placing the cover over the hard disk.

If everything is back at its place then you should boot up your notebook and enjoy the silence.

Thursday, February 24, 2011

Ubuntu and EasySMS (for android)

Introduction


When you are on your computer almost all the time it might be interesting to send sms messages using your computer. There is an application for Android that lets you do this. It is called EasySMS and is available in the Android market.

But it only gets useful if it's configured well. So I want to share my configuration. Important to note is that my configuration is for USB connections. As I prefer a USB connection to a WiFi connection.

Configuration on the phone


After installing the application from the market you can launch the application (you can choose free or paid version. The paid version obviously has some advantages and I bought it).
When the application is launched you see a screen were you can set configuration options. Check the box before "Auto" underneath "Control of services Wifi/USB". Secondly you should set a port for Wifi/USB (mine is set to 2511 but you can choose any number higher than 1023). I have got the HTC Hero and my phone needs the checkbox before "Alt. send" to be checked. Normally you only have to check this if you notice that your messages don't get send.
You can set other configurations as you wish.

Configuration of Ubuntu


This part will tell you how to make it possible to send SMS messages by just clicking one button. A requirement for your system is that you have the Android SDK somewhere on it. You can find the SDK on http://developer.android.com/sdk/index.html

First make an simple script "startUSBSMS.sh" with the following contents:
#!/bin/sh
$PATH_TO_ANDROID_SDK/tools/adb forward tcp:1977 tcp:2511
google-chrome http://localhost:1977/

Of course you can use another browser by changing google-chrome to firefox or any other browser launching command. $PATH_TO_ANDROID_SDK must be changed to the android SDK folder containing the tools folder. It is important that the bold port numbers match and that the number in italics is the same as the port number that was chosen during the configuration of the phone. Finally you should make the script executable (chmod +x startUSBSMS.sh or using the properties window of the file)

Normally you can add a custom application launcher to one of your gnome panels. When creating this launcher you can select an icon and a command. The command is just the path to your script.

This might work for you but I had to do a little bit of extra work. Since my phone wasn't always connected with the right permissions I had to create some udev rules to make sure my phone was accessible. The udev rules should only be executed when you're phone is connected. One way to do this is to find out the VendorId corresponding with your phone. This can be done by executing lsusb WHEN YOUR PHONE IS CONNECTED VIA USB! it will give output of the different USB devices. Find the line corresponding to your phone. Normally every line has a description. Ee.g. I have a htc (=High Tech Corporation) Hero phone and output is:

Bus 002 Device 003: ID 0bb4:0c99 High Tech Computer Corp.

The number after ID and before the following colon will be the vendorid. Now we have got all the information to make the udev rules. Make a file /etc/udev/rules.d/50-android.rules with the following content:
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", RUN+="$PATH_TO_ANDROID_SDK/tools/adb start-server"

Finally execute sudo restart udev to make sure the rules are activated. After reconnecting your phone you should be able to use your SMS button!

EasySMS link


http://www.fireblade.org/EasySMS/

Saturday, May 22, 2010

Easiest fix for sound Sony VAIO VPCEB1S1E

Easiest fix for sound Sony Vaio VPCEB1S1E



In my previous post I allready explained some fixes. But now it's even more easier, just follow these little steps

   1)Download the following zip file on your pc
vaio_soundfix.zip


   2)Go to the folder where you downloaded the file and extract it

   3)This will create a folder called "vaio_soundfix"
Because we will need root privileges we will continue in terminal:
   4)Open up a terminal

   5)Change the current directory to the vaio_soundfix you just created*

   6)type in the following command (caution: capital I) and confirm with enter
sudo ./Install.sh

This will output something like:

username@computername:DirectoryWhereYouExtractedFiles/vaio_soundfix$ sudo ./Install.sh
Now in directory /opt/vaio/vaio_soundfix
update-rc.d: warning: /etc/init.d/soundvaio missing LSB information
update-rc.d: see
Adding system startup for /etc/init.d/soundvaio ...
/etc/rc0.d/K20soundvaio -> ../init.d/soundvaio
/etc/rc1.d/K20soundvaio -> ../init.d/soundvaio
/etc/rc6.d/K20soundvaio -> ../init.d/soundvaio
/etc/rc2.d/S20soundvaio -> ../init.d/soundvaio
/etc/rc3.d/S20soundvaio -> ../init.d/soundvaio
/etc/rc4.d/S20soundvaio -> ../init.d/soundvaio
/etc/rc5.d/S20soundvaio -> ../init.d/soundvaio
All done, press enter to quit…

So the warning is normal.

   7)Reboot & enjoy the bootsound!

   *Some more information on how to go to the right directory. If you have for example downloaded vaio_soundfix.zip to 'Downloads'. You just type the following command in the terminal:
cd ~/Downloads

'~' Must be a 'tilde' for some reason it won't show correctly...
cd is the change directory command and is followed by the directory to which you want to change. ~ is a wildcard that gets replaced by the home directory of the userdirectory. So this command will move your current directory to the Downloads-folder in your own home-folder.

For the people interested: You can also just open the Install.sh script with gedit if you want to see what it does. I've commented it a little bit.

Tuesday, May 4, 2010

Fixing sound issue on Sony vaio VPCEB1S1E

edit:The easiest solution (which is also persistent!) is explained in a newer post which can be found here!!!


This blogpost will explain how to make sound work on a Sony Vaio VPCEB1S1E. The solution is based on bug report 445889. Where Arwin Tugade posted a solution. In this post I'll try to provide a more detailed explanation.

There are 2 solutions: an easy one and a hard one. The easy one is however not persistent. So after each reboot you'll have to redo all the steps to enable your sound. The hard one on the other hand is persistent. I will explain both.

Easy (non persistent) solution



For the easy solution a python script has to be downloaded. This script is called HDA Analyzer and provides a GUI which will help us to enable the intern speaker of our notebook. (HDA Analyzers wiki can be found on:http://www.alsa-project.org/main/index.php/HDA_Analyzer)
First you'll have to download the script. This can be don by starting up a terminal and execute the following command:
wget -O run.py http://www.alsa-project.org/hda-analyzer.py

Next will have to run this script with super user privileges. This can be done by executing the next command in the terminal:
sudo python run.py

You will be prompted to enter your password. After entering your password a GUI will start up. In the GUI click on "Node[0x19] PIN" in the list on the left-side. Then in the right part you'll have to change the value of the dropdownlist next to VREF to HIZ. See picture:

Now the sound of your notebook should work!

When you close the application a popup will ask "HDA-Analyzer: Would you like to revert settings for all HDA codecs?". Answer No.

Hard (persistent) solution



Warning: The following instructions are to be used on Lucid only. If the process isn't performed right, it might break your system. And thus you will need to re-install your computer. I hereby clearly state that I won't take any responsibility for broken systems.

Before trying this you might first check out the solution above because if that won't work, this also won't work. For a persistent solution we wil create a custom kernel. This means we need to recompile the kernel. Therefore we first need to be sure the have some packages. This by entering the 2 following commands:
sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package

and
sudo apt-get build-dep linux


Then we need to download the kernel source, do this by entering the following commands:

sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)

&
apt-get source linux-image-$(uname -r)


Note: The source will be placed in your current working directory. You can use the pwd command to print this directory out. As I myself am new to building kernels I have just put it in my home folder. But there might be a better practice.

Note2:The `uname -r` command makes sure that you download the source of the kernel you are currently using

Go into the directory with the kernel source:
It's name will start with linux and contain the first part of the kernel release number.
For example when the `uname -r` command returns "2.6.32-21-generic". The kernel source will be in a map with a name like `linux-2.6.32`. In that case you want to go into that directory by executing the following command:

cd linux-2.6.32


Now we are going to change the source. Therefore we need to open the file that needs to be changed in a text-editor. You can open it with gedit by executing the following command:

gedit sound/pci/hda/patch_realtek.c


Then find “static struct hda_verb alc269_init_verbs[] = {“. In my file it was around line number 13272 but it may be different because you might have got another version of the file, depending on your current kernel. In this struct definition (thus the code between curly brackets) you must find the line stating:
{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},

and you will have to change this line into:

{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},

Than save and quit the file.

Now that the source is changed we need to recompile the kernel.
This is done by executing the following 2 commands:
fakeroot debian/rules clean


And

AUTOBUILD=1 fakeroot debian/rules binary-debs-FLAVOUR

Where FLAVOUR must be changed to the flavour you wish. If you type `uname -r` in your terminal you will get the release of your kernel and normally this contains the flavour you need. For example:
if `uname -r` results in the following answer:
2.6.32-21-generic

Then your flavour is generic and the second command should have been:
AUTOBUILD=1 fakeroot debian/rules binary-debs-generic

I haven't test this because I had executed
AUTOBUILD=1 fakeroot debian/rules binary-debs

by mistake and this command builds kernels for every possible flavour. You can do this also, but I don't recommend this since building may take a while...

After the building of the kernel you will have 2 deb files. You can install them by executing the command:

sudo dpkg -i name_of_file.deb


I have first installed the header file and then the image, but I don't know if the order is important.

URLs of the webpages that helped me a lot:



The bug report that showed me the solution. (THANK YOU Arwin Tugade)
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/445889

The necessary information on Kernel compiling
https://help.ubuntu.com/community/Kernel/Compile

Monday, December 21, 2009

udev rules needed for your android device

This blogpost will contain the udev-rules needed for making adb work.

This information is partly copied from here. I've posted it here because that source wasn't available anymore, and it was for htc-devices only.

To add the rules file you must do the following steps:

1. Login as root and create this file: /etc/udev/rules.d/50-android.rules.
   For Gusty/Hardy/Intrepid/Jaunty/Karmic, edit the file to read:
     SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
   For Dapper and earlier, edit the file to read:
     SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0bb4", MODE="0666"
2. Now execute:
   chmod a+rx /etc/udev/rules.d/50-android.rules
3. And make the rule active by restarting udev:
   sudo /etc/init.d/udev restart

It is important to note that this only works for HTC-devices. However you can make it work for any device. You'll just have to change the value of SYSFS{idVendor} into another value (read further).

You can obtain the value of SYSFS{idVendor} by connecting your device via usb and launching the command lsusb:
an example output:

Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 003: ID 0bb4:0c02 High Tech Computer Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


As you can see this is for a HTC (High Tech Computer Corp.) Device. And you can read the id of the vendor after ID and before the colon. So if you have another device, just use the id printed out. This by putting it in the quotes, instead of 0bb4 in /etc/udev/rules.d/50-android.rules.