| 1 |
#!/usr/bin/perl
|
| 2 |
|
| 3 |
#Usage: fsgs2bnetd "source directory" "destination directory"
|
| 4 |
#source directory: directory contains fsgs account files
|
| 5 |
#destnation directory: directory to save newly created bnetd
|
| 6 |
# accounts,should exist before run this
|
| 7 |
#
|
| 8 |
#there is another change made to bnetd account in this script
|
| 9 |
#i think fsgs account filename format <username> is better
|
| 10 |
#than using bnetd's <userid>, so i kept it in fsgs format.
|
| 11 |
#you may change it by edit the script yourself
|
| 12 |
|
| 13 |
$ARGV[1] eq "" && die "error arguments";
|
| 14 |
|
| 15 |
$s_dir=$ARGV[0];
|
| 16 |
$d_dir=$ARGV[1];
|
| 17 |
|
| 18 |
opendir(DIR,$s_dir) || die "error open dir";
|
| 19 |
@files= grep { /^[^.]/ && -f "$s_dir/$_" } readdir(DIR);
|
| 20 |
closedir DIR;
|
| 21 |
|
| 22 |
$userid=1;
|
| 23 |
$fsgs{'name'}="\"BNET\\\\acct\\\\username\"";
|
| 24 |
$fsgs{'password'}="\"BNET\\\\acct\\\\passhash1\"";
|
| 25 |
|
| 26 |
foreach (@files)
|
| 27 |
{
|
| 28 |
open(S_FILE,"$s_dir/$_") || die "error open s_file: $_\n";
|
| 29 |
|
| 30 |
$dest_file=lc("$d_dir/$_");
|
| 31 |
open(D_FILE,">$dest_file") || die "error open d_file: $_\n";
|
| 32 |
|
| 33 |
while (<S_FILE>)
|
| 34 |
{
|
| 35 |
chop($_);
|
| 36 |
($name,$value)=split(/:/,$_);
|
| 37 |
|
| 38 |
foreach (keys %fsgs)
|
| 39 |
{
|
| 40 |
if ($_ eq $name)
|
| 41 |
{
|
| 42 |
if ( $_ eq "password" )
|
| 43 |
{
|
| 44 |
$value=&passconv($value);
|
| 45 |
}
|
| 46 |
print D_FILE "$fsgs{$_}=\"$value\"\n";
|
| 47 |
break;
|
| 48 |
}
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
print D_FILE "\"BNET\\\\acct\\\\userid\"=\"$userid\"\n";
|
| 53 |
$userid++;
|
| 54 |
close(S_FILE);
|
| 55 |
close(D_FILE);
|
| 56 |
}
|
| 57 |
|
| 58 |
sub passconv
|
| 59 |
{
|
| 60 |
($f_pass)=@_;
|
| 61 |
my ($d_pass)="";
|
| 62 |
$f_pass=lc($f_pass);
|
| 63 |
$length=length($f_pass);
|
| 64 |
|
| 65 |
for ($i=0;$i<=$length;$i=$i+2)
|
| 66 |
{
|
| 67 |
$a=2*(int(($i/2)/4)*8+3-$i/2);
|
| 68 |
$d_pass .= substr($f_pass,$a,2);
|
| 69 |
}
|
| 70 |
|
| 71 |
return $d_pass;
|
| 72 |
}
|