| 1 |
#!/usr/bin/perl
|
| 2 |
|
| 3 |
|
| 4 |
require "db_api.pl";
|
| 5 |
|
| 6 |
if (scalar(@ARGV) != 5) {
|
| 7 |
&usage;
|
| 8 |
exit;
|
| 9 |
}
|
| 10 |
|
| 11 |
&header;
|
| 12 |
|
| 13 |
# remove a trailing /
|
| 14 |
$dirpath = $ARGV[0];
|
| 15 |
$dirpath =~ s!(.*)/$!$1!;
|
| 16 |
|
| 17 |
$dbh = &db_init($ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4]);
|
| 18 |
|
| 19 |
opendir FILEDIR, $dirpath or die "Error opening filedir!\n";
|
| 20 |
|
| 21 |
while ($filename = readdir FILEDIR) {
|
| 22 |
if ($filename =~ m/^\./) { next; } #ignore . and ..
|
| 23 |
|
| 24 |
|
| 25 |
if ( ! (($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
| 26 |
$atime,$mtime,$ctime,$blksize,$blocks) = stat "$dirpath/$filename" )) {
|
| 27 |
print "Error stat-ing the file $pathdir/$filename!\n" ; next; }
|
| 28 |
|
| 29 |
$type = ($mode & 070000) >> 12;
|
| 30 |
|
| 31 |
if ($type != 0) {
|
| 32 |
print "File $dirpath/$filename its not regular\n";
|
| 33 |
next;
|
| 34 |
}
|
| 35 |
convertfile2db("$dirpath/$filename");
|
| 36 |
}
|
| 37 |
|
| 38 |
closedir FILEDIR;
|
| 39 |
|
| 40 |
sub convertfile2db {
|
| 41 |
my $filen = shift;
|
| 42 |
my ($userid, $count, $alist);
|
| 43 |
|
| 44 |
open FILE, $filen or die "Error opening file $filen\n";
|
| 45 |
print "Converting file $filen ... ";
|
| 46 |
|
| 47 |
$count = 0;
|
| 48 |
$userid = ""; undef @alist;
|
| 49 |
while($line = <FILE>) {
|
| 50 |
if ($line =~ m/".*"=".*"/) {
|
| 51 |
|
| 52 |
$line =~ m/^"([A-Za-z0-9]+)\\\\(.*)"="(.*)"/;
|
| 53 |
|
| 54 |
$alist[$count]{tab} = $1;
|
| 55 |
$alist[$count]{col} = $2;
|
| 56 |
$alist[$count]{val} = $3;
|
| 57 |
|
| 58 |
$alist[$count]{col} =~ s!\\\\!_!g;
|
| 59 |
|
| 60 |
if ($alist[$count]{col} =~ m!userid$!) {
|
| 61 |
$userid = $alist[$count]{val};
|
| 62 |
}
|
| 63 |
$count++;
|
| 64 |
}
|
| 65 |
}
|
| 66 |
if ($userid ne "") {
|
| 67 |
&db_set($dbh, $userid, $alist);
|
| 68 |
}
|
| 69 |
close FILE;
|
| 70 |
print "done\n";
|
| 71 |
}
|
| 72 |
|
| 73 |
sub header {
|
| 74 |
print "Account files to db accounts converting tool.\n";
|
| 75 |
print " Copyright (C) 2002 Mihai RUSU (dizzy\@roedu.net)\n";
|
| 76 |
print " People Versus People Gaming Network (www.pvpgn.org)\n\n";
|
| 77 |
}
|
| 78 |
|
| 79 |
sub usage {
|
| 80 |
&header;
|
| 81 |
print "Usage:\n\n\tfiles2db.pl <filedir> <dbhost> <dbname> <dbuser> <dbpass>\n\n";
|
| 82 |
print "\t <filedir>\t: directory with the account files\n";
|
| 83 |
print "\t <dbhost>\t: the database host\n";
|
| 84 |
print "\t <dbname>\t: the database name\n";
|
| 85 |
print "\t <dbuser>\t: the database user\n";
|
| 86 |
print "\t <dbpass>\t: the database password\n";
|
| 87 |
}
|