Thursday, May 17, 2007

Making my own intranet, Part 1

The General Idea
So I've decided to make my own intranet, eh? (oh wait... I'm not Joe Burns)

I have decided to make my own intranet at work, and have opted against out-of-the-box solutions because I plan on doing some heavy development on little projects here and there that I want to integrate nicely into the intranet.

Since I'm having fun doing this, I thought I'd describe just what I'm doing to make my life a little bit easier.

The Content Management System (CMS) Idea
First off, I wrote my own CMS which is uber-lame. It is a table that looks up the URL in a database and lets the database tell it the title of the page, whether or not the page is available or not, and it gives it a small string which is a path and file prefix for the actual content of the site...

Yeah, I'm horible at describing things, so let's start with an example, if you go to http://ourserver/intranet/myhr/ then it looks up "/intranet/myhr" in the database to find the following data:
title: "My HR"
file: "myhr"
enabled: y

Yay, we have a title and it is enable, things are looking good!

Now it goes to my super top-secret folder that is not accessible via the web and looks for the following files:

myhr.head.php
myhr.content.php
myhr.tail.php

The head is called before anything is displayed on the screen, but right after sessions have been started.

The content is what is displayed in the middle of the page... this should really do nothing more than display what was processed in the head.

The tail is the file included at the bottom of the page, which I doubt I'll use much other than to include javascript calls that need to be made at the end of the document.

The content page is required, but the head and tail are optional. If the content page does not exist, it displays an error page instead... if I were smart, I would send 404 headers in the notfound.head.php file, just to maintain standards.

The Cool Idea(s)

Cool idea 1: tossing the milk when it goes bad

I've also got launch and expiration dates in the page table, so the page only displays during the time it should be displayed... I will probably also write a script to browse the database for pages that are nearing expiration to send me an email reminder, which means I can set a 1 year expiration on every content page if I wanted to, then have it remind me in a year to review the content for accuracy then make changes and extend the expiration date.

Cool idea 2: group-based access
I've always enjoyed user and group-based access levels, and with the magic of Active Directory, LDAP, PHP, and some out of date trail mix I've been able to do just that! (and get a stomach ache)

Basically I've thrown together a short script that authenticates usernames and passwords against LDAP (which is pointed at our Active Directory domain controller) and after authenticating I'm grabbing the "memberof" attribute of the user since I've already got a valid ldap bind.

This means I can take all of the users and groups I'm already managing for file permissions and use those same users and groups to manage permission on the intranet! Wo0t!

Cool idea 3: wiki-style page creation
Quite possibly the second-coolest idea (sorry, but that ldap thing is cool !), adding some code in the page-not-found script to add a "create this page" link if the logged in user is a member of the intranet admin group!

I could also add an "edit this page" link at the bottom of each page, or possibly just assign a shortcut key or something to edit the page.

I would do 99% of my coding in the Zend Development Environment anyway, but man it would be nice to manage user permissions, expiration dates, and things of that nature in a nice GUI other than phpmyadmin!

More to come...