Archive for the ‘Computers & Internet’ category

8 bit characters in Active Directory

May 6th, 2009

Once again, after discovering very little information from Microsoft about Active Directory over LDAP I was posed with a question on the adLDAP forums https://sourceforge.net/forum/?group_id=104193

And that was how to handle accented characters over LDAP. Running a standard ldap_modify() will cause a ‘Constraint violation’ error from the domain controller.

I finally discovered, after reading the RFC for LDAP that I need to encode the ‘offending’ characters as UTF-8.

I could have simply executed

$adldap->user_modify('AD.UserName', array('firstname'=>utf8_encode('Göran'));

but that would be too easy wouldn’t it. Seeing as my believe with libraries should be, you shouldn’t have to think about this, let us allow the library to do this work for us.

Whenever you modify or create attributes in adLDAP it passes the attributes array through a schema function so let’s process the array detecting 8 bit characters

array_walk($attributes, array($this, 'encode8bit'));

Then let us create the function encode8bit

protected function encode8bit(&$item, $key) {
        $encode = false;
        if (is_string($item) === true) {
            for ($i = 0; $i < strlen($item); $i++)
            {
                // Detect the ordinal value of the character
                if (ord($item[$i]) >> 7) {
                    $encode = true;
                }

            }
        }
        if ($encode === true) {
            $item = utf8_encode($item);
        }
    }   

Update WordPress was messing with the rendering of this function, I’ve now corrected it.

I’ve committed the code to the repository trunk and it’s now available to download directly from SVN

adLDAP version 3.0

May 1st, 2009

adldapWell since joining the adLDAP project on SourceForge, I’ve just published version 3.0.

Version 3.0 is a big change from 2.0, firstly I’ve removed support for PHP 4, by using proper PHP 5 constructors and making variables / functions public and protected.

I’ve added a number of new functions for Exchange mailbox creation, contact management and user deletion (as well as PHP Doc style commenting the code).

I’ve also gone and re-organised much of the documentation on the Wiki.

Go check it out for yourself http://adldap.sourceforge.net

Active Directory Management over PHP

April 22nd, 2009

Update: I’m now part of the original adLDAP project, so libAD has been withdrawn, look forward to seeing my contributions and Exchange supposed on adLDAP in the near future.

A while ago I started using a library called adLDAP, unfortunately there have been a number of bugs and lack of some features with it.  Couple this with the lack of updates for the past two years, I decided to re-work this library and release it myself.  This library is called libAD.

libAD is a PHP library providing Active Directory authentication and management over LDAP.

It provides intelligent Active Directory integration with PHP. This extends on the original project that has not been updated for some time. It’s aim is to help other developers with getting over the same hurdles that we’ve experienced in getting the whole LDAP SSL Active Directory puzzle working natively on Linux.

This library is not designed to be a complete Active Directory management systems, but give you a set of functions through an API that will allow you to interface successfully with your Active Directory.

Given the varied nature of organisations and sites, adLDAP may not be your complete solution, but it should be a very sound starting point. LDAP isn’t overly friendly on first glance, and it’s a steep learning curve made alot worse when coupled with Microsoft’s seemingly unending army of catches.

The information you can retrieve from Active Directory is as useful as you make it. If you don’t fill out all their account information there’s not really going to be much to query.

libAD is open source software and is released under the GNU General Public License v2. This is a change from the license used under adLDAP which was LGPL.

Update: I’m now part of the original adLDAP project, so libAD has been withdrawn, look forward to seeing my contributions and Exchange supposed on adLDAP in the near future.

Windows Update frustrations

April 19th, 2009

These days I’m a Mac person, but I do still use Windows for work and also occasionally for other bits and pieces, such as games, Windows software or Windows development.

Now today I booted my Mac into Windows Vista under Bootcamp, started a video encoding process that would take between 2 and 3 hours.  Obviously I’m not going to sit in front of my computer watching it encode a movie file, that would just be a monumental waste of time, so I leave it running.

I come back 2 hours later to discover the computer in sleep mode, that’s fine if the encode has finished then it’ll usually go to sleep automatically.  I wake the computer to discover the OS X login screen.

I check the Windows logs to discover that Windows Update has decided not only to download and install new updates but decided that regardless of what the computer is doing at that current time it should reboot itself and loose any work I happened to be working on.

Now I understand for the default settings and need for Windows Update to auto download and install, it helps protect computers from users who don’t, and have no need, to know about what security patches are required.

What I object to is Windows deciding to reboot itself automatically.  I’ve seen the little prompt before saying click me to snooze the reboot, but I wasn’t at my PC to be able to see that prompt.

The Windows Update system should look at the system processes and open applications to determine whether it might be acceptable to display the prompt, if the processor is very busy, there might just be a chance, that something important is going on!  Alternatively, maybe Microsoft can provide a way to applications to send a flag saying ‘Busy here, move along please’ and then remove the flag when they exit.  If they are worried about Viruses setting that flag then maybe restrict it to digitally signed applications only?

I feel Microsoft are intentionally putting features in Windows to piss off IT professionals!  So two hours of wasted processor time thanks to Windows Update.

Copyright infringement and The Pirate Bay

April 17th, 2009

PiratesLet’s get a few things straight, downloading copyrighted music, software, games and music is NOT theft and it is not a criminal act.  It is a civil act of copyright infringement.  Now that’s out of the way I will also start by saying I do not agree or believe in piracy or copyright infringment in any way, shape or form.

Firstly, today the founders of The Pirate Bay (and I won’t link) have been found guilty of breaking copyright law and sentenced to jail. Now whilst there are lot of torrents on The Pirate Bay that contain copyrighted files that are being shared illegally, none of these files are actually stored by the pirate bay whatsoever.  They are effectually a search engine for .torrent files.

So what does the rulings in the Swedish courts today mean?  Does it mean the fact you can find illegally shared files by Google mean that Google should be shut down?  Of course it would be ludicrous to suggest such a thing, but actually is it?  Google can be used for exactly the same thing as The Pirate Bay can.  Just Google ‘casino royale avi filetype:torrent’ and I can guarantee you’ll be able to find a page with a link to a .torrent download for that movie.

Does this mean that copyright holders shouldn’t protect their property and their rights, no of course they should, I just feel they are going about it the wrong way.

DRM (Digital Rights Management)

I have no problem with DRM until it gets in my way of doing something I want to do with it.  Now this does not mean sharing the files amongst my friends.  It means if I buy something from iTunes (pre music going DRM-free) and I change from an iPod to a Zune then I shouldn’t have to re-buy all my music.  Secondly if I want to archive all my DVD’s for playback on Apple TV and then put my DVD’s in the loft I shouldn’t have to find ways around the insane corruption that Sony puts on it’s DVD’s courtesy of the Arccos software.

For the most part DRM only seeks to annoy legitimate customers, as anyone who truely wants to pirate something, will find a way to do so regardless of how ‘protected’ the studios believe DRM to be… just take a look at how quickly BD+ got cracked.

Pricing

If I want to legitimately purchase a movie from iTunes for example, and let’s take an example of  ‘Max Payne‘, this costs £10.99 from the store. I can buy that same movie from play.com for £12.99.  Heck, when Quantum of Solace came out you could buy it from Tesco for £7, yet it was still £10.99 on iTunes and they won’t even let you buy an HD version!

Can the studios please explain to me how a movie that only has to be digitised once, costs nothing in physical storage in a warehouse, has no manufacturing costs and no distribution/delivery costs can cost only slightly less or indeed even more than it does in a shop?

If they studios want to stop people downloading for free they need to radically reduce the price of legitimately buying a film online.

Software

I can also see the arguement from the angle of the copyright holder, I am a software developer.  I have written and sold software online, only a minority of which are GPL’d.

There is a small subset of people out there that think it is their god-given right to give my software away and use it without me even getting a small amount of money for my efforts in developing it (I’ve never charge mega-bucks for applications, unlike some companies out there).

I do believe that copyright holders have the right to protect their rights, and make a living from it.

If I GPL’d my code and even though I sold it, there is nothing preventing someone else taking my same code and competing with me.  I’m not a Red Hat or a Novell of this world, I can offer the value added benefits of support and protection that they offer.  I wouldn’t be able to make any money from this type of arrangement.

This is why I believe the shared source licenses.  Basically buy the software, get the source, change what you want to in the source, but have no rights to redistribute it without permission.

Some more iPhone SDK tips and tricks

April 8th, 2009

In working on an update to one of my applications on the Apple iPhone I thought I’d share another quick tip.

I found on a blog and it works brilliantly,  to make rounded corners on any UIImage.

ImageManipulator.h

@interface ImageManipulator : NSObject {
}
+(UIImage *)makeRoundCornerImage:(UIImage*)img :( int) cornerWidth :( int) cornerHeight;
@end

ImageManipulator.m

#import "ImageManipulator.h"

@implementation ImageManipulator

static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth, float ovalHeight)
{
    float fw, fh;
    if (ovalWidth == 0 || ovalHeight == 0) {
        CGContextAddRect(context, rect);
        return;
    }
    CGContextSaveGState(context);
    CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect));
    CGContextScaleCTM (context, ovalWidth, ovalHeight);
    fw = CGRectGetWidth (rect) / ovalWidth;
    fh = CGRectGetHeight (rect) / ovalHeight;
    CGContextMoveToPoint(context, fw, fh/2);
    CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);
    CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1);
    CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1);
    CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1);
    CGContextClosePath(context);
    CGContextRestoreGState(context);
}

+(UIImage *)makeRoundCornerImage : (UIImage*) img : (int) cornerWidth : (int) cornerHeight
{
	UIImage * newImage = nil;

	if( nil != img)
	{
		NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
		int w = img.size.width;
		int h = img.size.height;

		CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
		CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);

		CGContextBeginPath(context);
		CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
		addRoundedRectToPath(context, rect, cornerWidth, cornerHeight);
		CGContextClosePath(context);
		CGContextClip(context);

		CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);

		CGImageRef imageMasked = CGBitmapContextCreateImage(context);
		CGContextRelease(context);
		CGColorSpaceRelease(colorSpace);
		[img release];

		newImage = [[UIImage imageWithCGImage:imageMasked] retain];
		CGImageRelease(imageMasked);

		[pool release];
	}

    return newImage;
}

@end

Just call the static method makeRoundCornerImage and pass your image to have the image rounded off the way you want.

For example

UIImage *imageFromFile = [UIImage imageNamed:@"myimage.png"];
imageFromFile = [ImageManipulator makeRoundCornerImage:imageFromFile : 20 : 20];

Note that you do need the CoreGraphics framework for this to compile.

More information can be found at the blog post link above.

The second tip is to load a remote image over the web and display it in a UIImageView object.

Create the following method in your interface

-(UIImage*) newUIImageWithURLString:(NSString*)urlString
{
	return [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]];
}

Then call the following

UIImage *myImage = [self newUIImageWithURLString:@"http://url.to/image.jpg"];

.tel goes live

March 25th, 2009

media_right_3Well I’ve just got my .tel domain http://richardhyland.tel

Time will tell if it’s any good or going to work, however I’ve actually got a .tel iPhone management tool awaiting approval from Apple.

Changing browser loyalties

March 11th, 2009

internet_explorer_7_logoI’m a web developer and unlike a lot of developers I have been a big fan and user of Internet Explorer 7 and now version 8.

However the standards compliance of Internet Explorer has always left something to be desired.  With the introduction of 7 a few years back the job of making sites work in Internet Explorer became a whole lot easier, but there is still a lot missing that really ought to be included, and thank goodness transparent PNG support was added.

Recently I switched to using Internet Explorer 8 RC as my main browser and whilst I like it there were a number of failings I found.  The first is the so-called standards compliance.  Well seeing as it doesn’t support lots of CSS 3 properties doesn’t really make it standards compliant, but I digress. Mainly my issues were with it’s rendering of pages that looked great in Firefox, Chrome, Opera and Safari but just didn’t work properly in Internet Explorer 8.  The sites weren’t even using browser sniffing to load different stylesheets.  Quite simply IE’s implementation of the standards was different to all the other major browsers.  Sorry Microsoft, must try harder!

Over the past month or so I’ve suddenly discovered that I now use Firefox 3 as my primary browser at work (I still use Safari 4 at home as I’m a mac person) and combine it with Firebug and it’s simply stunning.

Spreadfirefox Affiliate Button

What actually prompted me to write about this was a story I picked up upon this morning entitled ‘IE8 May Be End of the Line For Internet Explorer‘.  It discusses the fact that Microsoft might be considering using Webkit (the engine behind Chrome and Safari) for Internet Explorer. In an article on AppleInsider Steve Ballmer is quoted as saying

Addressing a developer conference in Sydney Australia, Microsoft CEO Steve Ballmer said the idea of using WebKit as the rendering engine within its web browser was “interesting” and added “we may look at that.”

The fact that Ballmer would even mention using WebKit is very interesting indeed as you’d expect such a thing to be dismissed out of hand.  WebKit quite simply has the fastest and best rendering engine of any modern browser.  Just try Safari 4 on Windows or a Mac to try it out for yourself

Living without Windows

March 10th, 2009

Quite possibly the best article I’ve read about living without Windows and using Linux instead, and just why Linux still has a long way to go when it comes to desktop usage for non-techies.

http://www.computerworld.com/action/article.do?command=viewArticleBasic&taxonomyName=Operating+Systems&articleId=9126042&taxonomyId=89&pageNumber=1