Pale Purple https://www.palepurple.co.uk Office Address Registered Office Blount House, Hall Court, Hall Park Way,,
Telford, Shropshire, TF3 4NQ GB
sales@palepurple.co.uk GB 884 6231 01
Xerte Online Toolkits is an open source Flash+Ajax+PHP web application which allows tutors to create rich multimedia presentations through a web browser.
We’ve been hosting a couple of Xerte based sites (for Techdis and Warwick University) for a couple of years now. Being an open source project – we initially added support to the Techdis version so that it automatically cleans itself monthly and so on (therefore creating an ideal sandpit).
In the past we’d encountered problems with XOT which seemed to only affect our hosting environment – and we’d spend a few hours tracking them down, patch the code and then commit our fixes to our local subversion repository and post a patch on the mailing list. A couple of weeks ago we noticed toolkits 1.7 had been released, and asked one customer if they’d like to be upgraded. Not surprisingly, they did.
So we set up a demo site for the 1.7 code base, using a copy of a customer’s live database – hoping it would suffice to illustrate the new code work(s) before upgrading their live version. Unfortunately it didn’t run – the database schema had significantly changed between versions – and there remains no obvious guide/help as to how to upgrade it.
Next up, we tried installing from scratch – but then found the various bugs we’d squashed out before had reappeared (or hadn’t been fixed in upstream).
At this point it became obvious that we needed to push our changes upstream to save ourselves future work.
So, over the last couple of days, we’ve been fairly busy, and thankfully the Xerte project have given us commit access – so hopefully our changes won’t be lost. This is just a short summary of a few changes we’ve made to the Subversion trunk of toolkits:
The existing codebase is vulnerable to SQL injection, and needs PHP’s magic_quotes functionality enabled. For various reasons (beyond the scope of this short blog post) this isn’t ideal.
Toolkit’s often issues database queries like the below :
include $site->php_library_path . "database_library.php"; $mysql_id=database_connect("index.php database connect success", "index.php database connect fail"); $query_response = mysql_query("SELECT x From y WHERE z = '{$_POST['template_id']}'); if($query_response === false) { receive_message($_SESSION['login_ldap'], "admin", "critical", "something is wrong", "something is wrong"); } else { $row = mysql_fetch_array($query_response); echo $row['blahblah']; }
Some problems with which are :
The code base also ran with PHP’s error_reporting effectively turned off – so undefined variable warnings and so on were not being reported
So, some fixes we’ve made are for instance :
$rows = db_query("select * from foo where id = ?", array($id));
_debug($string)
), so if something breaks some sort of audit trail exists.db_query_one($sql, $params)
function – this returns a single row or null – ideal for use if you are only expecting one row back – for example, retrieval by primary key.So the above code ends up being shrunk to :
require_once("config.php"); $row = db_query_one("SELECT x From y WHERE z = ?", array($_POST['template_id'])); if($row === null) { receive_message($_SESSION['login_id'], "admin", "critical", "something is wrong", "something is wrong"); } else { echo $row['x']; }
config.php always loads the database_library.php file, and starts a PHP session – before these were handled in a slightly haphazard manner – and in reality as it’s not possible for the someone to use the app and not require the functionality from either.
Other fixes/changes made include :
There is plenty of work remaining to be done – for instance :
Still, at least a start has been made.
‹ WordPress Performance Case Study New website ›