March 2010

Deploying Drupal via CVS (including modules).

Deploying Drupal via CVS (including modules).

If you're not using version control for your software projects please turn in your geek badge at the door. Seriously, version control makes life so much easier when developing features for a site or deploying a site. The best version control out there currently would have to be Git, subversion a distant second, and coming in last the old and painful CVS. Drupal is currently on CVS, but migrating to Git, we'll have to deal with CVS for now.

Needless to say, these have to be run from the command line

Step One: Installing the Core

In the directory that you would normally download and unzip drupal you'll want to run this command to grab Drupal core from the CVS server

cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal co -r DRUPAL-6-14 drupal
That will grab

  • Drupal version 6.14
  • place all the files in a directory called 'drupal'

Simple, fast, painless.

Step Two: Installing Modules via CVS

Every install of Drupal needs CCK and Views. So here are the commands to install each of them. Now you will want to navigate to your drupal/sites/all/modules directory. From there run the following commands.

This will checkout cck version 6.x-2.6

cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-6--2-6 -d cck contributions/modules/cck

This will checkout views version 6.x-2.8

cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-6--2-8 -d views contributions/modules/views

I think you get the picture. Continue this as you see fit.

To see the module version in Drupal you will need to also install the CVS Deploy module. Very important

Step 3: Upgrade Time

Core

So after a while you have to upgrade Drupal core you simply navigate to your root drupal directory and run this command.

cvs update -dP -r DRUPAL-6-15
That will make all the necessary changes to bring Drupal from 6.14 -> 6.15

Modules

For modules you'll want to navigate inside the module directory and run the update command, for example for cck you would go to drupal/sites/all/modules/cck and run

cvs update -r DRUPAL-6--2-7 -dP
That will upgrade CCK from 2.6 -> 2.7

Step 4: Eat some chocolate ice cream

PDO_Mysql error with Zend Server and socket

PDO_Mysql error with Zend Server and socket

I've headed this issue off before, but now I think I know why it happens.

The problem

With a new install of Zend Server on my Mac and trying to access a DB with my Zend Framework web app I am greeted with an error of

Message: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" when trying to run our application.

This was rather frustrating as I changed all instances of mysql_default_socket in the PHP settings (php.ini). It still didn't pick up the location of the socket. Since I'm using PDO, it looks like this is an issue in PHP 5.2 for PDO.

http://forums.zend.com/viewtopic.php?f=44&t=568

The work around for me has been to declare the socket in my application.ini file

resources.db.params.unix_socket = "/usr/local/zend/mysql/tmp/mysql.sock"

The problem this introduces, haveing a different application.ini on the server and on then on my local devel machine.

Ugggg.

Linux fdisk and the 2TB limit

Linux fdisk and the 2TB limit

Running out of space on the backup drive, I added another 1.5TB drive to the existing one to hold the company backup files. We do rsync style snapshots with a linux server and it was at 80% capacity. So I added another Seagate SATA to the simple Hardware RAID SATA card in the machine. Everything went well. Ran fdisk to partition the drive, ran mke2fs -f /dev/hde1 to format in EXT3 format. After that was done the

df -h

command showed only 2TB. That's odd, I know the filesystem takes some drive space, but not 1TB of it.

So after a little investigating you need to use a program called

parted

for drives >2TB. The commands are as follows

parted /dev/hde1

Once in the parted command prompt then you can run these commands on the new drive.

mktable gpt
mklabel 
mkpart primary 0 100%
quit

You can now format with

mke2fs -j /dev/hde1

References:
http://ubuntuforums.org/archive/index.php/t-901368.html

More Zend Framework Fun

More Zend Framework Fun

Zend Framework Form Hash Ajax

This one sucked hunting down the answer.

The problem. I would include a token (hash) in the form I was producing. I set the form as a checkbox that as soon as it's checked it fires off an AJAX request with the token, and data. The first time it worked great, every other time it would tell me the Token was missing. Hmmmm....

http://codeutopia.net/blog/2008/10/16/how-to-csrf-protect-all-your-forms...

Hi Jani, I got a work around for the problem. The real problem is this, for AJAX requests, it works for first time and not for the subsequent requests. The AJAX request was having the same token for all it’s requests but the plugin was generating unique token for all the requests. So is the mismatch / problem. That was the problem.
Workaround:
What I did was, for each AJAX request, I stopped generating a new token and used the already generated one to compare. So by this way I can cover for multiple AJAX requests. It could be vulnerable for the time that it lives and after that I will eject (logout) the user from the system and then they (attacker) will have to login again and get a token and then attack (if they wanted to really). That was it.

I never did find an answer yet, I did post it to StackOverFlow
http://stackoverflow.com/questions/2474774/how-to-use-zend-framework-for...

Instead I did the whole thing manually..

Form

class Form_GroupListForm extends Zend_Form
{
    public function  __construct($options = null)
    {
        parent::__construct($options);
 
        $this->setName('grouplist');
 
        $groupmodel = new Default_Model_Group();
 
        $groups = new Zend_Form_Element_MultiCheckbox('groups');
        $groups->addMultiOptions($groupmodel->getGroupList())
               ->setLabel('Groups')
               ->setDescription('Groups this person belongs to:')
               ->setAttrib('class', 'ajaxcheckbox')
                ;
 
        $token = new Zend_Form_Element_Hash('grouplisttoken');
        $token->setSalt('hello')
              ->setTimeout(3600)    // Form times out after one hour
              ->removeDecorator('HtmlTag')
              ->removeDecorator('Label');
 
 
        $myNamespace = new Zend_Session_Namespace('authtoken');
        $myNamespace->authtoken = $hash = md5(time());
        $auth = new Zend_Form_Element_Hidden('authtoken');
        $auth->setValue($hash)
             ->setRequired('true')
              ->removeDecorator('HtmlTag')
              ->removeDecorator('Label');
 
 
 
        $this->addElements(array($groups, $auth));
 
 
    }
}

Notice the session being generated then stored as a hidden field. Dumb that I have to basically replicate the hash feature, but the hash has an hop of 1, meaning that it can only be used for one page refresh then it expires. There should be a way to persist this token over several ajax calls.

jQuery selector takes a second argument that sets context.

jQuery selector takes a second argument that sets context.

I was trying to concatenate a select to the almighty

this

in jQuery, but it just wasn't working.

I tried

$(this + 'input')

Didn't work, so I thought, maybe I need a space between this and input like so:
$(this + ' input')

No go..

Then I ran across this page.
http://stackoverflow.com/questions/306583/jquery-this-selector-and-children

Of course StackOverFlow has the answer.

The working result

$('input', this)

Perfect!!!

Auto start an SSH tunnel and keep alive

Auto start an SSH tunnel and keep alive

I have a program that needs to talk to another server, but to secure the traffic I've set up a port forwarding SSH tunnel. The only problem is that this tunnel needs to be kept alive and started when the server boots up. Here is how, using

/etc/inittab

For the server you want to make connections from follow these instructions.

Open up

/etc/inittab

and insert this code somewhere near the bottom

# Keeps an SSH port forwarding connect between serverA <---> serverB for mysql
sm:345:respawn:/usr/bin/ssh -N -L 3307:127.0.0.1:3306 -l admin 192.168.1.5

Let's break it down

<

ul>

  • sm This is just an random two letter code that distinguishes it from other processes inside inittab
  • 345 These are run-levels that you want the process to run.
  • respawn What to do if the process dies, respawn it
  • /usr/bin/ssh ssh binary
  • -N Tells SSH not to run any remote command after the connection has been established
  • -L 3307:127.0.0.1:3306 This tells SSH to set up a tunnel with local port being 3307, remote host 127.0.0.1, remote port 3306
  • -l admin What user to log in by
  • 192.168.1.5 Remote host to SSH into
  • For those familiar with SSH, it should go without saying that you need to set up pre-shared keys to automatically log into the remote server