Merge pull request #30 from klondi/mimicfixes

Mimicfixes
This commit is contained in:
Jan Vidar Krey 2014-11-25 07:55:56 +01:00
commit 0e27e4219d
3 changed files with 177 additions and 1 deletions

View File

@ -84,7 +84,7 @@ class Option(object):
class SourceGenerator(object): class SourceGenerator(object):
def __init__(self, filename, cppStyle = True): def __init__(self, filename, cppStyle = True):
print "Generating %s..." % filename print ("Generating %s..." % filename)
self.f = open(filename, 'w'); self.f = open(filename, 'w');
def write_header(self, Comment = True): def write_header(self, Comment = True):

114
tools/fh2uh_regimport.pl Normal file
View File

@ -0,0 +1,114 @@
#!/usr/bin/perl
# A simple tool for importing FlexHub users to uhub sqlite database
#
# Usage: ./fh2uh_regimport.pl <flexhub_userlist> <uhub_database>
#
# Note: uhub database has to be created before running this script.
use File::Slurp;
use Data::Dumper;
use DBI;
my @uhubaccounts;
my $text = read_file $ARGV[0];
my $dbfile = $ARGV[1];
sub convertprofile
{
$flexprofile = $_[0];
if($flexprofile >= 0 && $flexprofile <= 3)
{
return 'user';
}
elsif($flexprofile >= 4 && $flexprofile <= 6)
{
return 'operator';
}
elsif($flexprofile >= 7 && $flexprofile <= 8)
{
return 'super';
}
elsif($flexprofile >= 9 && $flexprofile <= 10)
{
return 'admin';
}
return 'unknown';
}
sub parseinfo
{
my @info = split('\n', $_[0]);
for my $line (@info)
{
chop $line;
my %reginfo;
if ($line =~ /\["sNick"\]\s*=\s*\S+/)
{
my @nick = split(/\["sNick"\]\s*=\s*"(\S+)"/, $line);
$reginfo->{'nickname'} = $nick[1];
}
elsif ($line =~ /\["sPassword"\]\s*=\s*\S+/)
{
my @password = split(/\["sPassword"\]\s*=\s*"(\S+)"/, $line);
$reginfo->{'password'} = $password[1];
}
elsif ($line =~ /\["iLevel"\]\s*=\s*\S+/)
{
my @level = split(/\["iLevel"\]\s*=\s*(\d+)/, $line);
$reginfo->{'credentials'} = convertprofile $level[1];
}
elsif ($line =~ /\["iRegDate"\]\s*=\s*\S+/)
{
my @created = split(/\["iRegDate"\]\s*=\s*(\d+)/, $line);
$reginfo->{'created'} = $created[1];
}
elsif ($line =~ /\["iLastLogin"\]\s*=\s*\S+/)
{
my @activity = split(/\["iLastLogin"\]\s*=\s*(\d+)/, $line);
$reginfo->{'activity'} = $activity[1];
}
}
return %{$reginfo};
}
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,created,activity) VALUES('$import->{'nickname'}','$import->{'password'}','$import->{'credentials'}',datetime($import->{'created'}, 'unixepoch'),datetime($import->{'activity'}, 'unixepoch'));");
}
}
$db->disconnect();
}
if ($text =~ /tAccounts = {/)
{
$text =~ s/^(?:.*\n){1}/},\n/;
my @flexaccounts = split('},.*\n.*\[".+"\] = {', $text);
shift(@flexaccounts);
for my $account (@flexaccounts)
{
my %info = parseinfo $account;
push(@uhubaccounts, \%info);
}
dbimport @uhubaccounts;
}
else
{
print "Provided file is not valid FlexHub userlist.\n";
}

62
tools/px2uh_regimport.pl Normal file
View File

@ -0,0 +1,62 @@
#!/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 <ptokax_userlist.xml> <uhub_database.db>
#
# 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();
}
for my $account (@pxaccounts)
{
$account->{'credentials'} = convertprofile $account->{'Profile'};
}
dbimport @pxaccounts;