Software


After googling around for a plug-in to help me authenticate PHPBB3 forums against an already existing web application and finding none, I decided to write my own. I modelled it to auth_db and auth_apache and named it auth_dbext as short for authentication using DB from external source (external to PHPBB Database).

I am sharing it with others who might have a similar need and of course any improvements are welcome.

I have not implement some optional parts (see http://wiki.phpbb.com/Authentication_plugins for more info)

The login code is in the function (The full source code is at auth_dbext.phps)

[code lang="php"]
/**
* Login function
*/
function login_dbext(&$username, &$password)
{
global $db;

// do not allow empty password
if (!$password)
{
return array(
'status' => LOGIN_ERROR_PASSWORD,
'error_msg' => 'NO_PASSWORD_SUPPLIED',
'user_row' => array('user_id' => ANONYMOUS),
);
}

if (!$username)
{
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Note: on my systems, I include these following lines from an external file that is not web-accessible
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
$db_host = "localhost"; // Here goes the MySQL server address, hostname or IP
$db_user = "username"; // Here goes the MySQL user allowed to read the table below (GRANT SELECT ON ....)
$db_password = "passwd"; // Here should go the password associated with the above user
$db_database = "dbName"; // Here goes the Database containing the table below
$db_table = "tblUsers"; // Here will goes the table list users allowed to login into PHPBB
////////////////////////////////////////////////////////////////////////////////////////////////////////////
$col_username = "username";
$col_password = "password";
$hashMethod = "sha1"; // Can be one of: md5, sha1, plain
// In case you choose to use a non-standard hashing function, be
// sure to change below where the $hashedPassword variable is created

$objMySqli = new mysqli($db_host, $db_user, $db_password, $db_database);

/* check connection */
if (mysqli_connect_errno())
{
return array(
'status' => LOGIN_ERROR_EXTERNAL_AUTH ,
'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH ',
'user_row' => array('user_id' => ANONYMOUS),
);
}

// Check the User/Password
if($hashMethod == 'sha1')
{
$hashedPassword = sha1($password);
} elseif($hashMethod == 'md5') {
$hashedPassword = md5($password);
} else {
$hashedPassword = $password;
}
$sql =
"SELECT 11 as ID
FROM " . $db_table . "
WHERE
" . $col_username . " = '" . mysqli_real_escape_string($username) . "' AND
" . $col_password . " = '" . mysqli_real_escape_string($hashedPassword) . "'
";

if ( $result = $objMySqli->query($sql) )
{
if ( $result->num_rows <= 0 )
{
return array(
'status' => LOGIN_ERROR_USERNAME,
'error_msg' => 'LOGIN_ERROR_USERNAME',
'user_row' => array('user_id' => ANONYMOUS),
);
}

$sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type
FROM ' . USERS_TABLE . "
WHERE username = '" . $db->sql_escape($username) . "'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

if ($row)
{
// User inactive...
if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
{
return array(
'status' => LOGIN_ERROR_ACTIVE,
'error_msg' => 'ACTIVE_ERROR',
'user_row' => $row,
);
}

// Successful login...
return array(
'status' => LOGIN_SUCCESS,
'error_msg' => false,
'user_row' => $row,
);
}

// this is the user's first login so create an empty profile
return array(
'status' => LOGIN_SUCCESS_CREATE_PROFILE,
'error_msg' => false,
'user_row' => user_row_dbext($username, sha1($password)),
);
} else {
// TODO: Handle this situation
}

// Not logged in using the external DB
return array(
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
'error_msg' => 'LOGIN_ERROR_EXTERNAL_AUTH',
'user_row' => array('user_id' => ANONYMOUS),
);
}
[/code]

To use this plugin, copy it to the directory /includes/auth/ (the file should be /includes/auth/auth_dbext.php ) in your PHPBB3 install location.  This file can be downloaded at auth_dbext.php (ZIP) or view a highlighted source file at auth_dbext.phps

With my need to exchange data between a ASP.NET and PHP web applications, I decided to use JSON. The .NET team did a good job by integrating JSON de/serialization into the language (NET 3.5) but they decided not to follow JSON specifications for some good reasons. Serializing an object that has a DateTime property will insert a string that won’t be understood by json_decode of PHP.

On the site of JSON, there is no such thing as a date type.  I have taken the ISO 8601 path which is my preferred date format (MySQL and Swedish Locale standard)

Consider the following class:

[code lang="C#"]
[DataContract]
public class Person
{
[DataMember]
public DateTime DateOfBirth { set; get; }
[DataMember]
public string Names { set; get; }
}
[/code]

By Serializing it you will get something like

[code]

{"DateOfBirth" : "\/Date(1210408872000+0200)\/", "Names" : "Kavuna ka Lyaziga"}

[/code]

That Date is not defined as a JSON type. In case your JSON will be used directly by JavaScript or .NET (C#, VB) you will not need to write extra codes.

Yes Ubuntu Desktop 7.04 has been very useful for my children but when I tried to upgrade today to the latest 7.10 (gutsy), it appeared time consuming. It’s like when I was configuring a shared EPSON multi-function printer.

  • 5 hours process (the initial download was very fast less than 10 minutes at 2.2MBps)
  • Too many questions (like REPLACE this or that file, …, blah blah blah)
  • It hanged once and had to restart the computer and the upgrade process

If I had known (it is not mentioned on the Ubuntu website), I would have completely erased the machine (after backing up the important files) and done a fresh install. I am sure it would have taken less than 30 minutes.

I still love it because my children no longer download and install all the junkies that pop-up on the screen. Yes, I told them that they should read first whatever comes on the screen before clicking but they probably have no time to read all those confusing stuff that come up while using this or that site.
My children computer now runs on Ubuntu Desktop 7.04

I have not been able to correctly trace this error, but by only making sure that every XMLHttpRequest gets its unique name, the problem seems to dissappear. I suspect this error might be caused by an object not closing its connection properly.

[code]
Error: uncaught exception: [Exception... "Component returned failure code: 0x804b000f [nsIXMLHttpRequest.setRequestHeader]" nsresult: "0x804b000f (<unknown>)" location: "JS frame
[/code]

Curiously, this problem comes only in Firefox (I use 2.0.0.6) and not in Internet Explorer (I use ).

I was tired of having to visit the computer many times a week to correct any problems it might have. I have installed all possible tools but still some sites trick the children to installing things that contain dangerous stuff. OK, I have told them how one should read every message before clicking on related buttons but still, some spyware manage to get installed especially when they are in a hurry.

I have tried to have them use a non-admin account but some games stopped working. So, they needed a computer that works. I decided to give a try to Ubuntu Desktop (I installed 7.04 Feisty Fawn) and it works fine so far. The install was straight forward and very quick. My daughter told me that she finds the interface nice and not different from the one she was used to.

It was even a nice way to explain that a COMPUTER and WINDOWS are two different things (not only because they do two different tasks, but because they are independent from one another). It’s a way to introduce them to democracy showing that there are different options.

Actually, it’s somebody else who installed it. It’s a family member who was on vacation here and she had never installed an operating system (even windows) before.

I have launched a new service at http://www.bookingplaner.com or http://www.lokalbokning.se.

With this service, companies such as Schools or others with many rooms such as meeting rooms, teaching rooms will be able to manage their bookings. Once a company registers, it will have the opportunity to download a FREE personalized client software that will be installed on computers of its personnel using those rooms. They can even register visitors who can use the rooms from outside.

All the translations on the site and in the client are not yet finished but will be ready in the near future.

The service is FREE to use for those companies/institutions that don’t have many rooms to manage. But for those power users, there are paying options that one can upgrade to once happy with the service.

I will be registering domains from different countries once the translations are complete.

Since I started computer programming some years ago, I came to realize that a 24 hours day is very short. Sometimes I have to work for days with little or no sleep.

I always ask myself why a human body has (or needs) to rest (and most of all, sleep). Experts say that one needs at least 8 hours of sleep every day (of 24 hours).

So, is this an intended feature or it’s a design defect?

After 48 sleepless hours, I finally managed to mount a partition formatted using UFS (the native FreeBSD filesystem).

My configuration is:

HDA: 6 GB (This is where I installed Ubuntu: has partitions hda1, hda2, hda5)
HDC: 80 GB (This is my second hard disk: has one partition hdc1 with UFS)

[code]root@server:/# cat /proc/partitions

major minor #blocks name
3 0 3924648 hda
3 1 3694918 hda1
3 2 1 hda2
3 5 224878 hda5
22 0 78150744 hdc
22 1 78150710 hdc1

[/code]
Here is how I did it:

1. I created a mount point /home/myfiles
[code]root@server:/#mkdir /home/myfiles[/code]
2. I run the command [code]root@server:/#mount -r -t ufs -o ufstype=ufs2 /dev/hdc1 /home/myfiles[/code]

I can now read my files by going to /home/myfiles !

In case you want the drive to be remounted at reboot time, then you will have to edit the /etc/fstab file to add the mount information at the end of the file

[code]/dev/hdc1 /home/myfiles ufs auto,ro,ufstype=ufs2 0 0[/code]

Until now, it seems impossible to mount the drive in write mode. Some articles talk of re-compiling the kernel for write support.

The install was fast and painless.

I have configured it to be a LAMP in less than 20 minutes (have not counted though).


For formatting dates in MySQL one can use the DATE_FORMAT function like DATE_FORMAT(`date_col or value`, dateFormatString)

In a select query, that looks like SELECT DATE_FORMAT(`date_col or value`, dateFormatString) FROM `tableName`
. In case one wants to use the server current date, the query would look like SELECT DATE_FORMAT(NOW(), dateFormatString) FROM `tableName`

For a detailed explanation of the options that can be in a dateFormatString, read the MySQL date related page (dev.mysql.com/doc/).

In the general examples below, I will use the date 22 April 2007 16:15:23 (date of creation of this article)

Language Format String Output
English %m/%d/%Y 04/22/2007
English %m/%d/%Y %H:%i 04/22/2007 16:15
English %a, %D %b %Y %H:%i Sun, 22nd Apr 2007 16:15
Français %d-%m-%Y 22-04-2007
Français %d-%m-%Y %H:%i 22-04-2007 16:15
Français %a, %D %b %Y %H:%i Dim, 22 Avr 2007 16:15
Ikinyarwanda %d-%m-%Y 22-04-2007
Ikinyarwanda %d-%m-%Y %H:%i 22-04-2007 16:15
Ikinyarwanda %a, %D %b %Y %H:%i Cyu, 22 Mata 2007 16:15
Svenska %Y-%m-%d 2007-04-22
Svenska %Y-%m-%d %H:%i 2007-04-22 16:15
Svenska %Y-%m-%d %H:%i 22-april-2007 16:15

For PHP formatString, visit http://www.php.net/date

Next Page »