#!/usr/bin/perl
# This perl script is intended to make ifcico(ifmail) & fidogate password files
# from t-mail(dos/os2/win*) password.lst file.
# (c) Olli (olli@digger.org.NOSPAMru,remove NOSPAM before mailing)
# greetz: i_L, Corvin, kati, vika
# Thanx : Peter V. Chernikoff (peter@digger.org.NOSPAMru,remove NOSPAM before mailing)
# for help in moving my node to Linux. =)
# License is current GNU GPL.
$mnt="/os2";
$tmail_dir="$mnt/m/tos2";
$passwords_lst="$tmail_dir/password.lst";
$fgate_path="/tmp/fidogate";
$fg_pass="$fgate_path/passwd";
$if_path="/tmp/ifmail";
$ifpass="$if_path/ifmail-passwd";
####  Proggie goes here ###
system `mkdir $if_path 2> /dev/null`;
system `mkdir $fgate_path 2> /dev/null`;
print "opening $passwords_lst ..\n" ;
open  ( TCTL, $passwords_lst ) || die "Can't open $passwords_lst , $! .";
while ( <TCTL> )
{unless ( /^\s*;/ )
  {chomp;
  $_=&comment_split($_);
  s/A-Z/a-z/;
  if ( /^\s*\d+/ ) { /^\s*(\S+:\S*)\s+(\S+)\s*/ ; 
  $tpasswd_hash{$1} = $2 ;  }
 }
} #EOF <TCTL> 
close(TCTL);
open ( IFCTL, ">$ifpass") || die "Can't open $ifpass , $! .";
print "Results will be also in $ifpass\n";
foreach $tmp (keys %tpasswd_hash)
{if ($tmp) # w/o this - null key, damn I was too lazy to find correct regexp
 { print       "password\t$tmp\t\t$tpasswd_hash{$tmp}\n";
   print IFCTL "password\t$tmp\t\t$tpasswd_hash{$tmp}\n";
 }
}
close IFCTL;
print "opening $fg_pass\n";
open ( FGCTL, ">$fg_pass") || die "Can't open $fg_pass , $! .";
foreach $tmp (keys %tpasswd_hash)
{if ($tmp) # w/o this - null key, damn I was too lazy to find correct regexp
 {print       "uplink\t$tmp\t\t$tpasswd_hash{$tmp}\tAreafix\n";
  print FGCTL "uplink\t$tmp\t\t$tpasswd_hash{$tmp}\tAreafix\n";
  print       "packet\t$tmp\t\t$tpasswd_hash{$tmp}\n";
  print FGCTL "packet\t$tmp\t\t$tpasswd_hash{$tmp}\n";
  print       "af\t$tmp\t\t$tpasswd_hash{$tmp}\t1\tCDFHILNPRSX\t\"SysOp\"\n";
  print FGCTL "af\t$tmp\t\t$tpasswd_hash{$tmp}\t1\tCDFHILNPRSX\t\"SysOp\"\n";
  print       "ff\t$tmp\t\t$tpasswd_hash{$tmp}\t1\tCDFHILNPRSX\t\"SysOp\"\n";
  print FGCTL "ff\t$tmp\t\t$tpasswd_hash{$tmp}\t1\tCDFHILNPRSX\t\"SysOp\"\n";
 }
}
close FGCTL;
exit;
###################
sub comment_split
{$_=$_[0];
 if ( /;/ )  { return $`;}
    else     { return $_;}
}
