From 7840e09884fd0237da365dc15784e973cac40596 Mon Sep 17 00:00:00 2001 From: mimicmod Date: Sat, 11 May 2013 19:03:00 -0400 Subject: [PATCH] Added simple tool to import PtokaX (< 0.5.0.0) users --- tools/px2uh_regimport.pl | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tools/px2uh_regimport.pl diff --git a/tools/px2uh_regimport.pl b/tools/px2uh_regimport.pl new file mode 100644 index 0000000..59b694c --- /dev/null +++ b/tools/px2uh_regimport.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl + +# A simple tool for importing PtokaX (< 0.5.0.0) users to uhub sqlite database. +# Userlist MUST be in xml format. +# +# Usage: ./px2uh_regimport.pl +# +# Note: uhub database has to be created before running this script. + +use XML::Simple; +use DBI; + +# create xml object +my $xml = new XML::Simple; + +# read XML file +my $regdata = $xml->XMLin($ARGV[0], ForceArray => [ 'RegisteredUser' ]); + +my $dbfile = $ARGV[1]; +my @pxaccounts = @{$regdata->{'RegisteredUser'}}; + +sub convertprofile +{ + $pxprofile = $_[0]; + if($pxprofile == 2 || $pxprofile == 3) + { + return 'user'; + } + elsif($pxprofile == 1) + { + return 'operator'; + } + elsif($pxprofile == 0) + { + return 'admin'; + } + + return 'unknown'; +} + +sub dbimport +{ + my @arr = @_; + my $db = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "", {RaiseError => 1, AutoCommit => 1}); + + for my $import (@arr) + { + if ($import->{'credentials'} ne 'unknown') + { + $db->do("INSERT OR IGNORE INTO users (nickname,password,credentials) VALUES('$import->{'Nick'}','$import->{'Password'}','$import->{'credentials'}');"); + } + } + + $db->disconnect(); +} + +my @uhubaccounts; + +for my $account (@pxaccounts) +{ + $account->{'credentials'} = convertprofile $account->{'Profile'}; + push(@uhubaccounts, $account); +} + +dbimport @uhubaccounts;