🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #24955

INN -> Cyclone conversion script

#24955
From: Jeff Garzik
Date: Wed, 07 Jan 1998 00:00
360 lines
8723 bytes
This is a multi-part message in MIME format.

--------------1FD938F518AD500D68678D2E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The following script will perform a basic conversion from an INN
configuration to a Cyclone feeder configuration.  hosts.nntp, INNfeed,
nntpsend, and newsfeeds are all supported.  The more esoteric options of
those files are not supported, as many of them do not have Cyclone
counterparts.

Let me know if any problems arise in the conversion, and I'll do my best
to fix it.
-- 
Jeff Garzik			    Typhoon, Cyclone, Diablo, and INN
Spinne USENET News Service	        Fast and efficient news feeds
http://www.spinne.com/usenet/	           News tuning and consulting

--------------1FD938F518AD500D68678D2E
Content-Type: text/plain; charset=us-ascii; name="inn2cyclone"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="inn2cyclone"

#!/usr/local/bin/perl -w

#
# Copyright 1998 Spinne, Inc.
# Author: Jeff Garzik <jeff.garzik@spinne.com>
#
# inn2cyclone - convert various INN configuration files into
#		a single Cyclone-style feeds.conf file
#
# feeds.conf output sent to stdout.  Typical usage:
#
#	cd /var/news/etc
#	inn2cyclone -h hosts.nntp -n newsfeeds -t nntpsend.ctl \
#		-i innfeed.conf > /tmp/cyclone-feeds.conf
#
# The "-n path-to-newsfeeds" argument is required.  All other
# arguments are optional, depending on what files you wish to input.
#
# Unfortunately there is no correlation between hosts.nntp and the
# other INN configuration files.
#

use strict;

use Getopt::Std;
use vars qw($opt_h $opt_n $opt_i $opt_t);



sub Usage {
  print STDERR "usage: inn2cyclone ",
  	"-h hosts.nntp ",
	"-n newsfeeds ",
	"-t nntpsend.ctl ",
	"-i innfeed.conf\n";
  print STDERR "newsfeeds file REQUIRED\n";
  exit(1);
}


# parse command line
getopts("h:n:i:t:");
$opt_n || &Usage;



my ($newsfeeds, $hosts, $innfeed, @feeds, %feedinfo);

my @directives = (
	'IncomingHostname',
	'OutgoingFeedName',
	'OutgoingHostname',
	'Aliases',
	'PortNumber',
	'NumberOfStreams',
	'AllowStreaming',
	'Subscription',
	'MaxLength',
	'MinLength',
	'MaxHops',
	'MaxCrosspost',
	'MaxDepth',
);

&read_innfeed_conf ($opt_i) if ($opt_i);
&read_nntpsend ($opt_t) if ($opt_t);
&read_hosts ($opt_h) if ($opt_h);
&read_newsfeeds ($opt_n);
&output_newsfeeds;

sub read_nntpsend {
  my ($nntpsend_name) = @_;
  my (@host, $peername, $hostname);

  open(F, $nntpsend_name) or die "Cannot open $nntpsend_name: $!\n";

  while (<F>) {
    next if (/^\s+$/);
    next if (/^#/);
    next unless (/:/);

    @host = split(/:/);

    $peername = $host[0];
    $hostname = $host[1];

    if (! grep(/^$peername$/, @feeds) ) {
      push(@feeds, $peername);
    }

    $feedinfo{"$peername NumberOfStreams"} = 1;
    $feedinfo{"$peername OutgoingFeedName"} = $peername;
    $feedinfo{"$peername OutgoingHostname"} = $hostname;
  }

  close(F);
}

sub output_newsfeeds {
  my ($feed, @settings, $key, $setting);

  foreach $feed (@feeds) {
    print "#\n# $feed\n#\n\n<feed>\n";
    foreach $key (@directives) {
      if (exists $feedinfo{"$feed $key"}) {
        print "$key ", $feedinfo{"$feed $key"}, "\n";
      }
    }
    print "</feed>\n\n";
  }

}

sub read_innfeed_conf {
  my ($icname) = @_;
  my (%group, $in_grp, $in_peer, $peername, $hostname, $maxcxn, $port);
  my ($xpeername);

  $in_grp = 0;
  $in_peer = 0;

  open(F, $icname) or die "Cannot open hosts.nntp file $icname: $!\n";

  while (<F>) {
    next if (/^\s+$/);
    next if (/^#/);

    if (/^\s*group\s+/i) {
      %group = ();
      $in_grp = 1;
    }

    elsif (($xpeername) = (/^\s*peer\s+(\S+)/i)) {
      $peername = $xpeername;
      if (! grep(/^$peername$/, @feeds) ) {
        push(@feeds, $peername);
      }

      my ($key);
      $in_peer = 1;
      $maxcxn = 0;
      $port = 0;
      foreach $key (keys %group) {
        $feedinfo{"$peername $key"} = $group{$key}
	  if ($group{$key});
      }
      $feedinfo{"$peername OutgoingFeedName"} = $peername;
    }

    elsif (($hostname) = (/^\s*ip-name:\s+(\S+)/i)) {
      if ($in_peer) {
        $feedinfo{"$peername OutgoingHostname"} = $hostname;
      }
    }

    elsif (($maxcxn) = (/^\s*max-connections:\s+(\d+)/i)) {
      if (($in_grp) && (!$in_peer)) {
        $group{"NumberOfStreams"} = $maxcxn;
      } 
      elsif ($in_peer) {
        $feedinfo{"$peername NumberOfStreams"} = $maxcxn;
      }
    }

    elsif (($port) = (/^\s*port-number:\s+(\d+)/i)) {
      if (($in_grp) && (!$in_peer)) {
        $group{"PortNumber"} = $port;
      } 
      elsif ($in_peer) {
        $feedinfo{"$peername PortNumber"} = $port;
      }
    }

    elsif (/^\s*no-backlog:\s+true/i) {
      if (($in_grp) && (!$in_peer)) {
        $group{"MaxDepth"} = 100;
      } 
      elsif ($in_peer) {
        $feedinfo{"$peername MaxDepth"} = 100;
      }
    }

    elsif (/^\s*}\s*$/) {
      if ($in_peer) {
        $in_peer = 0;
      }
      elsif ($in_grp) {
        $in_grp = 0;
      }
    }

  }

  close(F);
}

sub read_hosts {
  my ($hfname) = @_;
  my (@hostline, $streaming, $host);

  open(F, $hfname) or die "Cannot open hosts.nntp file $hfname: $!\n";

  while (<F>) {
    next if (/^\s+$/);
    next if (/^#/);
    while (($_) && (/\s$/)) { chop; }

    @hostline = split(/:/);
    $host = $hostline[0];
    if (($hostline[1]) && ($hostline[1] =~ m#/s#)) {
      $feedinfo{"$host AllowStreaming"} = "True";
    }

    $feedinfo{"$host IncomingHostname"} = $host;

    if (! grep (/^$host$/, @feeds)) {
      push(@feeds, $host);
    }
  }

  close(F);
}

sub read_newsfeeds {
  my ($newsf) = @_;
  my ($line, $cont, $leading_ws, $s);

  if (! -f $newsf) {
    print STDERR "Cannot find newsfeeds file $newsf: $!\n";
    exit(1);
  }

  if (!open(F, $newsf)) {
    print STDERR "Cannot open newsfeeds file $newsf: $!\n";
    exit(1);
  }

  $line = '';

  while (<F>) {
    next if (/^#/);
    next if (/^\s*$/);
    $leading_ws = 0;
    while (($_) && (/^\s/o)) {
      ($s) = (/^\s+(.*)$/);
      $_ = $s;
      $leading_ws = 1;
    }
    while (($_) && (/\s$/o)) { chop; }

    $line .= $_;

    if ($line =~ m#\\$#) {
      chop $line;
      while (($line) && ($line =~ /\s$/)) { chop $line; }
    }

    else {
      &process_newsfeed_line($line);
      $line = '';
    }
  }

  close(F);
}

sub process_newsfeed_line {
  my ($line) = @_;
  my (@nf);

  @nf = split(/:/, $line);
  if ($#nf != 3) {
    print STDERR "INVALID LINE: $line\n";
    return;
  }

  my ($fname, $sub, $flags, $out) = @nf;
  my ($aliases);

  if ($fname =~ m#/#) {
    my ($peer, $tmpal) = ($fname =~ m#^([^/]+)/(.*)$#);

    $fname = $peer;
    $aliases = $tmpal;
  }

  return if ($fname =~ m#!$#);

  if (! grep(/^$fname$/, @feeds) ) {
    push(@feeds, $fname);
  }

  $feedinfo{"$fname OutgoingFeedName"} = $fname;
  $feedinfo{"$fname OutgoingHostname"} = $fname if ($fname =~ /\./);
  $feedinfo{"$fname Aliases"} = $aliases if ($aliases);
  $feedinfo{"$fname Subscription"} = $sub;

  &process_newsfeed_flags ($fname, $flags);

}


sub process_newsfeed_flags {
  my ($feedname, $flags) = @_;
  my (@flags, $flag, $arg1);

  @flags = split(/,/, $flags);
  foreach $flag (@flags) {
    # '<' size flag
    if (($arg1) = ($flag =~ m#^<(\d+)$#)) {
      $feedinfo{"$feedname MaxLength"} = $arg1 - 1;
    }

    # '>' size flag
    elsif (($arg1) = ($flag =~ m#^>(\d+)$#)) {
      $feedinfo{"$feedname MinLength"} = $arg1 + 1;
    }

    # 'G' crosspost flag
    elsif (($arg1) = ($flag =~ m#^G(\d+)$#)) {
      $feedinfo{"$feedname MaxCrosspost"} = $arg1;
    }

    # 'H' Path hops flag
    elsif (($arg1) = ($flag =~ m#^H(\d+)$#)) {
      $feedinfo{"$feedname MaxHops"} = $arg1;
    }
  }
}


--------------1FD938F518AD500D68678D2E--


Technical Details
Message-ID: <34B2C704.478E0D81@spinne.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <34B2C704.478E0D81@spinne.com>
Subject: INN -> Cyclone conversion script
Date: Wed, 07 Jan 1998 00:00:00 +0000
From: Jeff Garzik <jeff.garzik@spinne.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 313450666
Content-Type: multipart/mixed; boundary="------------1FD938F518AD500D68678D2E"
Organization: Spinne http://spinne.com
MIME-Version: 1.0
NNTP-Posting-Date: Tue, 06 Jan 1998 16:02:01 PST
Newsgroups: news.software.nntp