#!/usr/bin/perl -w
# This script is intended to send unsubscribe letters to ALL your links - it
# will create a shell script you may execute. Also it will create script for
# allfix all area unsubscribe. I had a need in both, you may use one or may
# ignore both.=)
#
# Well really it should unsubscribe only dead ones (if no bugs here ;) )
#
# The unsubscribe file must be created BEFORE running this script & you may 
# use fe2fgate_areas.pl to make it. Also this script require ifcico(qico) 
# passwords file , this file you may create w/ passwds2passwds.pl , BEWARE:
# since this script made for using this file made by passwds2passwds.pl it
# may do wrong things w/ another one. 
# License: GNU . 
# (c) Olli (olli@digger.org.NOSPAMru,remove NOSPAM before mailing)
# greetz: i_L, Corvin, Vika
# Thanx : Peter V. Chernikoff (peter@digger.org.NOSPAMru,remove NOSPAM before mailing)
# for help in moving my node to Linux. =)
$if_path="/tmp/ifmail";
$ifpass="$if_path/ifmail-passwd";
$uns_ar_list="/tmp/fidogate/unlink_it.txt";
$mua="/bin/mail";
$script="/tmp/unsubscribe.sh";
$script1="/tmp/unsubscribe1.sh";
$allfix_unlink_list="/tmp/allfix_unlink.txt";
$log_file="/tmp/unsubscribe.log";
local(%f_links_hash,%i_links_hash,%domain_hash);
# setting zone-domain dependecies
$domain_hash{"2:"}="fidonet.org";
$domain_hash{"275:"}="hacknet.org";
$domain_hash{"963:"}="viwanet.ru";
$domain_hash{"777:"}="basicnet.org";
####  Subroutines defnition  ###
sub domainset
{if ($_[0]) {$_=$_[0];} else {die "Err: no parameter in sub domainset.";}
 foreach $zone (keys %domain_hash)
 {if (/^$zone/) { $domain=$domain_hash{$zone}; last; }
 }
  if ($domain) { return $domain; }
  else { die "Can't find domain for $_[0].\n"; }
}
sub addr_convert                              # Seem 2 B done at 18.11.1999
{my ($inet_addr,$domain);
 if ($_[0]) {$_= $_[0];} else {die "Err: no parameter in sub addr_convert.";}
 $domain=domainset($_[0]);
 if (/^(\d+):(\d+)\/(\d+)\.(\d+)/)
 {print LOGF "\n$_\t\tp$4.f$3.n$2.z$1.$domain .\n";
  return ("p$4.f$3.n$2.z$1.$domain");
 } # end of point
 else
 {/^(\d+):(\d+)\/(\d+)/;
  print LOGF "\n$_\t\tf$3.n$2.z$1.$domain .\n";
  return ("f$3.n$2.z$1.$domain");
 } # end of node
# 2:5020/1234.123 is p123.f1234.n5020.z2.fidonet.org
} # end of addr_convert
####  Proggie goes here ###
print "Log will be in $log_file\n";
print "Script for echomail unsubscribe will be in $script\n";
print "Script for fileecho unsubscribe will be in $script1\n";
open  ( IFPASS, "<$ifpass"   ) || die "Can't read $ifpass : $! .\n";
open  ( LOGF,   ">$log_file" ) || die "Can't write $log_file : $! .\n";
open  ( SHSCR,   ">$script"  ) || die "Can't write $script : $! .\n";
open  ( SHSCR1,   ">$script1"  ) || die "Can't write $script1 : $! .\n";
open  ( UNSUB,    ">$allfix_unlink_list") || die "Can't write $allfix_unlink_list: $! .\n";
print UNSUB "-*\n";
close (UNSUB);
while ( <IFPASS> )
{chomp;
 /password\s+(\S+)\s+(\S+)/;
 $link=$1;
 next if ($link=~/\./);
 $f_links_hash{$link}=$2;
}
print SHSCR "\#!/bin/sh\n";
print SHSCR1 "\#!/bin/sh\n";
foreach $link (keys %f_links_hash)
{$i_links_hash{$link}=addr_convert ($link);
 print SHSCR "$mua -s $f_links_hash{$link} < $uns_ar_list AreaFix\@$i_links_hash{$link}\n";
 print SHSCR1 "$mua -s $f_links_hash{$link} < $allfix_unlink_list AllFix\@$i_links_hash{$link}\n";
}
close (IFPASS);
close (SHSCR);
close (SHSCR1);
close (LOGF);
system `chmod +x $script`;
system `chmod +x $script1`;
exit;
