Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: Convert databases (1.8 and 1.9) to XML  (Read 5243 times)

0 Members and 1 Guest are viewing this topic.

lavinpj1

  • Guest
Convert databases (1.8 and 1.9) to XML
« 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
Logged

Jobe

  • Contributor
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1023
    • Anope IRC Services
Re: Convert databases (1.8 and 1.9) to XML
« Reply #1 on: January 18, 2010, 08:54:10 AM »

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?
Logged
Your IP: ()
My IRC Status:

Come along and visit http://www.anopequotes.org/

lavinpj1

  • Guest
Re: Convert databases (1.8 and 1.9) to XML
« Reply #2 on: January 18, 2010, 09:15:07 AM »

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.

Code: [Select]
<?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
Logged
Pages: [1]   Go Up