From 6ad5efea6d7bc976a04705f47a4745f8e562d7a9 Mon Sep 17 00:00:00 2001 From: Michal Micka Date: Thu, 3 Oct 2013 04:13:00 +0200 Subject: [PATCH 1/5] Fix: Make config parser python 3 compatible --- src/core/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/config.py b/src/core/config.py index 733e23e..2e0fa1d 100755 --- a/src/core/config.py +++ b/src/core/config.py @@ -84,7 +84,7 @@ class Option(object): class SourceGenerator(object): def __init__(self, filename, cppStyle = True): - print "Generating %s..." % filename + print ("Generating %s..." % filename) self.f = open(filename, 'w'); def write_header(self, Comment = True): From 7840e09884fd0237da365dc15784e973cac40596 Mon Sep 17 00:00:00 2001 From: mimicmod Date: Sat, 11 May 2013 19:03:00 -0400 Subject: [PATCH 2/5] 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; From 77323fa98dd560474251c2476bf56c8cb7733892 Mon Sep 17 00:00:00 2001 From: mimicmod Date: Sat, 11 May 2013 19:23:46 -0400 Subject: [PATCH 3/5] Removed unnecessary step in PtokaX regimport tool --- tools/px2uh_regimport.pl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/px2uh_regimport.pl b/tools/px2uh_regimport.pl index 59b694c..37100b0 100644 --- a/tools/px2uh_regimport.pl +++ b/tools/px2uh_regimport.pl @@ -54,12 +54,9 @@ sub dbimport $db->disconnect(); } -my @uhubaccounts; - for my $account (@pxaccounts) { $account->{'credentials'} = convertprofile $account->{'Profile'}; - push(@uhubaccounts, $account); } -dbimport @uhubaccounts; +dbimport @pxaccounts; From 77704f6e67d0912a3a963f76db97d412fd7c0737 Mon Sep 17 00:00:00 2001 From: mimicmod Date: Sun, 5 May 2013 13:34:03 -0400 Subject: [PATCH 4/5] Added simple tool to import FlexHub users --- tools/fh2uh_regimport.pl | 114 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tools/fh2uh_regimport.pl diff --git a/tools/fh2uh_regimport.pl b/tools/fh2uh_regimport.pl new file mode 100644 index 0000000..9fd10fd --- /dev/null +++ b/tools/fh2uh_regimport.pl @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +# A simple tool for importing FlexHub users to uhub sqlite database +# +# Usage: ./fh2uhub_regimport.pl +# +# 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"; +} \ No newline at end of file From 32c65ada49f259f65cf37b2bce11347212989a35 Mon Sep 17 00:00:00 2001 From: mimicmod Date: Sun, 5 May 2013 13:36:23 -0400 Subject: [PATCH 5/5] Fixed usage of FlexHub regimport tool --- tools/fh2uh_regimport.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/fh2uh_regimport.pl b/tools/fh2uh_regimport.pl index 9fd10fd..243e307 100644 --- a/tools/fh2uh_regimport.pl +++ b/tools/fh2uh_regimport.pl @@ -2,7 +2,7 @@ # A simple tool for importing FlexHub users to uhub sqlite database # -# Usage: ./fh2uhub_regimport.pl +# Usage: ./fh2uh_regimport.pl # # Note: uhub database has to be created before running this script.