Anope IRC Services
Anope.org => Anope General => Topic started by: lavinpj1 on January 17, 2010, 04:22:38 PM
-
I knocked up the following over the past couple of days. It's just a modification of db-convert that ships with Anope 1.9, however it produces XML rather than the custom DB format. Google Code project can be found at http://code.google.com/p/anope-db-convert-xml/
The XML produced /should/ comply with the included DTD but let me know if it doesn't in any instances.
Benchmarks show it parsing 5000 nicks, 1000 chans and 100 bots into a 6.2MB XML file in just under 2 seconds. When the XML is used with simplexml and php a user can be authenticated by alias and password in 0.3 seconds including the time to parse the XML into the simplexml object.
Any comments, let me know.
Phil
-
Just for the sake of those who may use it could you provide some sample PHP code showing how to make use of the XML data?
-
Sure. The following function and test case takes a user and pass from the url (e.g. page.php?user=phil&pass=supersecretpassword) and checks it against the xml database. The function returns true on match and false on non-match. Test case echoes test data as appropriate.
<?php
if (authCheck('../../anope.xml', $_GET['user'], $_GET['pass'])) {
echo $_GET['user'] . ' is valid';
}
else {
echo $_GET['user'] . ' is invalid';
}
function authCheck($file, $user, $pass) {
// Make object
$xml = simplexml_load_file($file);
// Loop through and find user objects by their password
// This is more efficient to do this first since we must only
// loop nickcores and not every alias in every nick core
foreach ($xml->nickcores->nickcore as $core) {
// Check for password match
if (bin2hex(base64_decode($core->password)) == sha1($pass)) {
// Now loop through the aliases of the matching core
foreach ($core->aliases->alias as $alias) {
// Check for nick match
if ($alias->nick == $user) {
return true;
}
}
}
}
return false;
}
?>
You can run a simplexml object through print_r to see the full data output.
Phil