Archive for category ICT

Date: June 8th, 2010
Cate: ICT

Using PEAR to send Email via SMTP

The php mail() function is great. Super easy to use and no setup required. But it would seem some spam filters are often suspicious of email sent this way and rightly or wrongly I just don’t feel it is reliable enough.

I’m currently redesigning the Goonanism home page – it’s starting to look a bit stale (launch TBA) and I thought it was important that the contact page on the new site was as reliable as possible.

Knowing that my web hosts supported PEAR I decided to use PEAR’s Mail function instead. So I wrote the following script:
< ?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    require_once("Mail.php");
    $from = 'Website Enquiry ';
    $to = "Hammy Goonan ";
    $subject = "Website enquiry";
    $body = $message;
    $host = "hostdetails";
    $username = "username";
    $password = "password";
    $headers = array ('From' => $from,
        'To' => $to,
        'Subject' => $subject
    );
    $smtp = Mail::factory('smtp',
        array ('host' => $host,
            'auth' => true,
            'username' => $username,
            'password' => $password,
            'port' => '25'
        )
    );
    $mail = $smtp->send($to, $headers, $body);
    if (PEAR::isError($mail)) {
        echo($mail->getMessage());
    }
    else {
        echo("Message successfully sent!");
    }
?>

This gave me an error saying:

Class 'Net_SMTP' not found in /usr/local/php52/pear/Mail/smtp.php on line 210

So, using siteground as my host, I followed this tutorial.

Having uploaded the Net_STMP files and setting up my php.ini files I then got this error:

Fatal error: require_once() [function.require]: Failed opening required 'PEAR.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/goonanis/pear') in /home/goonanis/pear/Net_SMTP/SMTP.php

So it was clear to me that because of the new php.ini file, I would have to upload all the dependant packages to get this working.

Having uploaded various packages I was still getting an error saying:

Call to undefined method PEAR_Error::send()

Reading through various forums I realised that Mail::factory() will return a PEAR_Error object upon failure. So $smtp became a PEAR_Error so when I tried to call PEAR_Error::send() it wasn’t there, hence the error.

When I print_r() $smtp the PEAR_Error Object was actually throwing an error saying:

Unable to find class for driver smtp

A much more useful error message.

I only mention all of this because I had a lot of trouble sorting through forums to find this information out.

Anyway, the long and the short of it was that I needed to have the following packages and file structure for the PEAR Mail function to work:

pear
    /Mail
        /RFC822.php
        /mail.php
        /mock.php
        /null.php
        /sendmail.php
        /smtp.php
        /smtpmx.php
    /Net
        /SMTP.php
        /Socket.php
    /Mail.php
    /PEAR.php
    /PEAR5.php

Which you can find in the following PEAR packages:

  • Pear
  • Mail
  • Net_Socket
  • Net_STMP

I hope that helps!

Date: May 12th, 2010
Cate: ICT, Politics

Education, the Internet and the Filter

So Conroy’s proposed ISP level filter of the Internet just won’t work for a range of technical reasons. Whether or not it is effective in blocking websites, it will not stop one person getting access to child pornography so is therefore an awful waste of money. And that’s just the practical problem with it. The principled problem with it is that, inevitability, the filter’s scope will be broadened at some stage one way or another as history has shown us for just about every other breach of a population’s civil liberties. Civil Liberties are called that because they protect you from government so it is always dangerous to compromise.

But there is no doubt that the proliferation and normalisation of pornography is directly linked to it being available through the Internet. I think pornography is damaging to both women and men. It is even more damaging when it becomes normalised and is no longer challenged the way it should be.

Many opponents to the filter are saying that this money would be more effectively spent on educational initiatives. Teach ‘the kids’ how to avoid this sort of material. Increasingly I think that idea is also laughable. Young people are intuitively better at using computers and the internet than older people because they have always had it and just ‘get’ it.

What needs to be taught is respect for women and respect for yourself. Young people need to understand that pornography is not healthy and need to be given the tools to negotiate the mountains of contradictory and confusing emotions and responses they are experiencing. They need to be given guidance on how to deal with these feelings and thoughts and how to channel them in a healthy, constructive way which includes an intimate awareness of the role gender plays.

Sure, the Internet has made pornography freely and easily available. But it’s not the Internet’s fault, the internet is inherently neutral. It’s the patriarchy that is to blame and needs to be challenged and no amount of filtering the internet will do that.

Date: May 12th, 2010
Cate: ICT, Politics

Fuck Censorship!

Date: May 11th, 2010
Cate: ICT, Politics
1 msg

The filter is ridiculous!!

I thought this was worth reproducing (from the wonderful @jimboot):

Date: April 30th, 2010
Cate: ICT
2 msgs

Embedding a MP3 in a Drupal Site

So, after many many hours of searching the web to find a way to embed a MP3 player in a Drupal content item, I have finally found the answer. It’s much more straight forward than I thought as it doesn’t rely on Modules at all.

You simply add the following text to your content item:

<object type="application/x-shockwave-flash">
<param name="movie" value="/modules/audio/players/1pixelout.swf" />
<param name="wmode" value="transparent" />
<param name="menu" value="false" />
<param name="quality" value="high" />
<embed src="/modules/audio/players/1pixelout.swf" flashvars="soundFile=http://yourfile.mp3" width="290" height="24" />
</embed></object>

You will need to have your content format set to “Full HTML” to do this (or “PHP code” I suppose).

I actually found the answer here and thought it was worth reproducing.

Date: April 22nd, 2010
Cate: ICT

World Bank Data

The World Bank has decided to make its development data freely and publicly available.

You can see it all at http://data.worldbank.org/.

The World Bank has always been public enemy number one for me (maybe number 2, the IMF is in hot contention). However, it must be applauded for this initiative.

The data is provided in a range of formats and even has an API so that developers can easily interact with it.

The World Bank have pointed to the work of Random Hack of Kindness as their inspiration for the initative.

Now all I need is a project that utilises this data. Any suggestions?

Date: February 10th, 2010
Cate: ICT

LAMP installation on Ubuntu with Mod_Rewrite

So there is plenty of information out there about installing a standard LAMP server out there.

I’ve had a LAMP server on my Ubuntu laptop for quite some time. But i ran into troubles when I wanted to have a CakePHP installation on my local machine because I couldn’t get Apache’s mod_rewrite to work.

I’ve finally figured it out, and, given the difficulty I had finding the information I thought I should probably share my experience with the world.

So, firstly, installing LAMP. In case you’d missed it, LAMP stands for Linux, Apache, MySQL, PHP.

You’ve already got the Linux part, so I just went through the Synaptic Package Manager and installed the following repositories (you can find a much more detailed description here and here):

  • apache2
  • php5
  • mysql-server
  • php5-mysql (may be installed by default with the mysql-server package – sorry, can’t remember)
  • phpmyadmin
  • webmin (a very helpful program

Read what others have written on this topic as well though.

Next, in order to give yourself permissions to the /var/www/ directory, you need to run the following command in your terminal:
sudo chown -R $USER:$USER /var/www/

It’s not a secure thing to do (I don’t think) but it will make your life much easier (no permissions to worry about, no need to “sudo nautilus”).

Finally, getting mod_rewrite to work.

First, initiate it with the following command:
a2enmod rewrite

Then edit the file /etc/apache2/sites-enabled/000-default. You can do this with the following command:
nano /etc/apache2/sites-enabled/000-default

Then change the “AllowOverride None” to “AllowOverride All” in the “” section.

In other words, when you run the nano command above you see the following in amongst some other stuff:

Options Indexes FollowSymLinks MultiViews
AllowOverride none
Order allow,deny
allow from all

Change the AllowOverride to ‘All’.

Then restart your server with the following command:
sudo /etc/init.d/apache2 restart

And you’re done!

Disclaimer: I’m a terrible systems admin and make no guarantee for the above. However, it did work for me which makes me happy.

Date: February 9th, 2010
Cate: ICT
8 msgs

Why I choose Linux (part 382)

My laptop is now reaching old age. It’s over 3 years old and it’s starting to get a bit clunky. Time for a new one this year sometime.

I want a 13″ laptop as portability is an issue. So I started to look at the usual laptop vendors, Toshiba (which I currently have) and HP* were the two I checked out. As well as Mac.

You can get some reasonable 15″ laptops for around $1,200 which would suit my needs… if they were 13″. But as soon as you go with the smaller model it adds at least $1,000 to the price (often $2,000) and the processor significantly deteriorates in speed (almost halves in some cases).

Which leaves me with the MacBook. 13″ at around $1,200 with an Education discount.

There’s no denying the quality of the Mac hardware. The screens are nicer, they have the multi-touch touch pad, they are thin etc. But I just don’t was to run the MacOS. I prefer Linux.

There are a range of reasons but the primary one is that Mac locks you into Mac stuff, Linux just doesn’t. I hate iTunes and I hate iPhoto. If you want to take full advantage of the MacOS then you need to use these two programs and once you’ve done that you’re locked into them. You can’t reclaim your music (without significant hassle) once it’s in the iTunes library. Anything else just feels like a perpetual workaround.

I’ve got a huge personal commitment to Open Source Software and data longevity is a big reason for this.

So i’m going to buy a MacBook in the next 12 months, and I’m going to install Linux on it so that all my data is free forever, not locked into am over-hyped OS that could well go out of fashion one day and leave you with a bunch of music you’ll never be able to listen to again.

(Cue Mac Fanboys who are the second biggest reason I hate Macs. Actually, I don’t hate Macs (I use one at work) I just prefer Linux.)

*If you know of a laptop brand that matches a 13″ MacBook please let me know.

Date: January 25th, 2010
Cate: ICT

Why my site is blacked out

As you may have noticed, the first time you visit my site this week you will get a blanked out page with a message about the proposed internet filter.

It’s just a little protest and hopefully an awareness raising campaign. It’s run by the Electronic Frontiers Foundation who I recommend throwing a few dollars to.

We’ll resume normal service next week.

Date: January 11th, 2010
Cate: ICT
3 msgs

CakePHP and JQuery

A few months back I had the good fortune to come across JQuery. It change my life and made AJAX a breeze. In fact I simply don’t use straight Javascript any more, I only use JQuery.

About a month or two ago I also discovered the CakePHP development framework. Similarly, it seems to have changed my life (watch this space for my first CakePHP-based website).

Can you see where I’m going with this?

I wanted to be able to add JQuery to the CakePHP site that I am working on. It’s quite simple to do but I couldn’t really find anywhere that told me how to do it explicitly and I thought it might be worth explaining what I did here.

The first step is to have a functioning installation of CakePHP and a copy of JQuery.

You’ll need to put your JQuery file somewhere that CakePHP will be able to find it. As it turns out the best place would be /app/webroot/js/

Incidentally, this is also where you should include any external Javascript files. In the first instance I usually create a file called ‘javascript.js’ which includes all my Javascript calls.

So this leaves us with a directory structure that looks something like:
app/webroot/js/
    jquery.js/
    javascript.js/

Next, we need to include this file in the appropriate layout. If you haven’t done so already, it is most likely that this file will be called default.ctp and will live in app/views/layouts/. Now all you need to do is include the $javascript::link() method in your layout file.

In this case I’ve included the following line in my head tag:

< ?php echo $javascript->link(array('jquery.js', 'javascript.js')); ?>

And you’re done (of course it wouldn’t hurt you to go and read about the CakePHP Javascript Helper here). You can now proceed as usual and with the help of the HTML helper things might get easier yet.