Connecting to Active Directory using PHP

I really struggled to get PHP to be able to use LDAPS to talk to my domain controller. I wanted the ability to create users and set passwords and security groups so that I could administer users from my web interface.

It took a lot of googling but I finally got it working and it turns out in the end it is quite straight forward.

SETTING UP THE MACHINE

I started with a new Virtual machine with SSH and LAMP installed. I was using a 12.4LTS version of Ubuntu as it was a download I had handy.

Once set up the first thing to do is to turn on errors in PHP. This just makes it possible to debug what is happening.

To do this edit the php.ini file

sudo vim /etc/php5/apache2/php.ini

Around line 500 change the setting to turn errors on

display_errors = On

Remember to restart apache for it to take affect

sudo service apache2 restart

PHP

You need to ensure that the LDAP module for PHP is installed. To solve this run

sudo apt-get install php5-ldap

Then remember to restart the service

sudo service apache2 restart

ADD THE ROOT CERTIFICATEYou need install a certificate on your server. This is the Root certificate. To do this copy the root crt file to

/usr/local/share/ca-certificates

Once you have created the file you have to update the certificates. Run

sudo update-ca-certificates

This will place the certificate in the correct place.

etc/ssl/certs/

Configure LDAPS

The other thing I did was to change the LDAPS config

vim /etc/ldap/ldap.conf

and add

TLS_REQCERT never

to the bottom of the file

You should now be able to connect to LDAPS with PHP and create users in active directory.

Setup NTP service on Ubuntu

Having the correct time on your server is really important especially if you are looking at log files. There is nothing worse than knowing the time something went wrong but not finding it in the log file.

The simple way to solve the problem is to install an NTP service so that the time and date is checked and corrected on a regular basis.

Setup

The first thing to check is the current date and time on the server.

The date command will give you this.

> date

You can then check that the time is correct. If it is it maybe that the NTP service is already working.

Type

ps aux | grep ntp

If it is not installed type

sudo apt-get install ntp

Unfortuanatly installing the service does not change the time straight away. To Force a refresh type

sudo service ntp stop
sudo ntpd -gq
sudo service ntp start

Your servers should now give the correct time.

Less than a week to go

Well the big challenge starts in less than a week. I spent some time over the weekend making sure I have the correct kit. Looking at the weather forecast I am going to need lots of water proofs.

The sponsorship is going well and currently at £1661.

We even have a bake sale at work today to try and raise some more.

Hopefully if I can get a signal I will try and keep this up to date while we are doing it.

Three Peaks Challenge

Call me mad, call me silly, but I have signed up for the three peaks challenge.

Basically me and 9 of my colleagues have decided to climb the UK National 3 peaks (Ben Nevis, Scafell Pike and Snowdon) in 24 hours to raise money for two children’s charities.

Hopefully we make it but I will keep here updated with my training and progress.

Majorca in the sun

First full day of our summer vacation. We are spending the holiday in porta pensas. It is in the north of the ireland and is very pretty. Have spent the day around the pool which is freezing. Oliver is enjoying it however. He is full of beans and loving every bit. In contrast i just feel tired. It is strange how doing nothing all day makes you feel tired. Admitably the all inclusive drink does not help.

Have been thinking however about photo file storage. It feels like it should be a simple task but the more i think anout it the more complicated it becomes. On paper the idea has to be to just store one version of the photo. However, in practice this does not work. If you have a large tiff file you can not resize it on the fly for a website. So the question remains. I feel the best way is to upload the master file to the cloud and then have a script that runs on a scheduled job that tesizes and saves the image into a different folder. That way you have a folder for each purpose required but still have the master file.

WordPress Runkeeper plugin

After searching the wordpress plugin site and searching the internet I decided to take the plunge and produce my first wordpress plugin.

This has been done as a bit of fun in the evening. I am not a programer so i have taught myself everything.

As a result this may not be the most efficent or tidy plugin ever made. However, it seems to work for me.

It works by getting the runkeeper json feed and then i grab the values that i want to display. I then display the values using similar html and css.

Anyway I am releasing the code so that if anyone is interested in using it or would like to improve it they can.

Simply download the zip file and unpack it into your wordpress plugin directory.

Then activate the plugin via the normal way.

When you want to display the activity details in your post just type wprunkeeper activity=”(activityid)” in [ ]

The activity id can be got by looking at your runkeeper page. In the url it displays the activity id.

Again i can not stress enough that all of this is done in good faith. Please use at your own risk.

wprunkeeper plugin

Chester Half Marathon 2011

Distance
mi
Duration
h:m:s
Avg. Pace
min/mi
Avg.Speed
mph
Burned
calories
Climb
ft

Another year of running the Chester Half Marathon. I had done very little training so was not looking for my fastest time. However, I did better than expected. Above are my timings from Runkeeper.

Running

Distance
mi
Duration
h:m:s
Avg. Pace
min/mi
Avg.Speed
mph
Burned
calories
Climb
ft

Sunday long run

Distance
mi
Duration
h:m:s
Avg. Pace
min/mi
Avg.Speed
mph
Burned
calories
Climb
ft

17th April Run

Distance
mi
Duration
h:m:s
Avg. Pace
min/mi
Avg.Speed
mph
Burned
calories
Climb
ft

1 2 3