| 1 |
#!/usr/bin/perl
|
| 2 |
|
| 3 |
|
| 4 |
$cdb_command = "/usr/local/bin/cdb";
|
| 5 |
|
| 6 |
if (scalar(@ARGV) != 2) {
|
| 7 |
&usage;
|
| 8 |
exit;
|
| 9 |
}
|
| 10 |
|
| 11 |
&header;
|
| 12 |
|
| 13 |
# remove a trailing /
|
| 14 |
$dirpath = $ARGV[0];
|
| 15 |
$dirpath =~ s!(.*)/$!$1!;
|
| 16 |
|
| 17 |
$dirpath2 = $ARGV[1];
|
| 18 |
$dirpath2 =~ s!(.*)/$!$1!;
|
| 19 |
|
| 20 |
$max_uid = -1;
|
| 21 |
|
| 22 |
opendir FILEDIR, $dirpath or die "Error opening filedir!\n";
|
| 23 |
|
| 24 |
while ($filename = readdir FILEDIR) {
|
| 25 |
if ($filename =~ m/^\./) { next; } #ignore . and ..
|
| 26 |
|
| 27 |
if ( ! (($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
| 28 |
$atime,$mtime,$ctime,$blksize,$blocks) = stat $dirpath ."/". $filename )) {
|
| 29 |
print "Error stat-ing the file $pathdir/$filename!\n" ; next; }
|
| 30 |
|
| 31 |
$type = ($mode & 070000) >> 12;
|
| 32 |
|
| 33 |
if ($type != 0) {
|
| 34 |
print "File ". $dirpath ."/". $filename ." its not regular\n";
|
| 35 |
next;
|
| 36 |
}
|
| 37 |
convertfile($filename);
|
| 38 |
}
|
| 39 |
|
| 40 |
closedir FILEDIR;
|
| 41 |
|
| 42 |
sub convertfile {
|
| 43 |
my $filen = shift;
|
| 44 |
my ($key, $val, $outpath);
|
| 45 |
|
| 46 |
open FILE, $dirpath ."/". $filen or die "Error opening file ". $dirpath ."/". $filen ."\n";
|
| 47 |
$outpath = $dirpath2 ."/". $filen;
|
| 48 |
if (open FILEOUT, $outpath) {
|
| 49 |
die "Found existent file : ". $outpath ."!! Plese provide an empty output directory !!";
|
| 50 |
}
|
| 51 |
|
| 52 |
close FILEOUT;
|
| 53 |
open CDB, "| $cdb_command -c -t '". $outpath . ".tmp' '". $outpath ."'" || die "Error running $cdb_command\n";
|
| 54 |
print "Converting file ". $filen ."... ";
|
| 55 |
|
| 56 |
while($line = <FILE>) {
|
| 57 |
if ($line =~ m/^#/) { next; }
|
| 58 |
if ($line =~ m/^"(.*)"="(.*)"\s*$/) {
|
| 59 |
|
| 60 |
$key = $1;
|
| 61 |
$val = $2;
|
| 62 |
|
| 63 |
$key =~ s/\\\\/\\/g;
|
| 64 |
print CDB "+". length($key) .",". length($val) .":". $key ."->". $val ."\n";
|
| 65 |
}
|
| 66 |
}
|
| 67 |
print CDB "\n";
|
| 68 |
close CDB;
|
| 69 |
close FILE;
|
| 70 |
print "done\n";
|
| 71 |
}
|
| 72 |
|
| 73 |
sub header {
|
| 74 |
print "Account files flat2cdb converting tool.\n";
|
| 75 |
print " Copyright (C) 2003 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\tflat2cdb.pl <inputdir> <outputdir>\n\n";
|
| 82 |
print "\t <inputdir>\t: directory with the input flat account files\n";
|
| 83 |
print "\t <outputdir>\t: directory where the output cdb account files will reside\n";
|
| 84 |
}
|