Skip to content

Commit

Permalink
Initial revision
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 19, 2002
0 parents commit a2bd8be
Show file tree
Hide file tree
Showing 15 changed files with 4,863 additions and 0 deletions.
1,422 changes: 1,422 additions & 0 deletions IcculusNews_daemon.pl

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions IcculusNews_dotqmail.pl
@@ -0,0 +1,82 @@
#!/usr/bin/perl -w

use strict;
use warnings;

# The ever important debug-spew-enabler...
my $debug = 0;

# most of these can be altered at runtime with command line options.
my $newshost = 'localhost';
my $newsauthor = 'postmaster';
my $postingagent = '/usr/local/bin/IcculusNews_post.pl';
my $queuenum = 1;
my $newspass = undef;
my $newspassfile = '/etc/IcculusNews_mailgatewaypass.txt';
my $portnum = 263;
my $newssubj = undef;

#-----------------------------------------------------------------------------#
# The rest is probably okay without you laying yer dirty mits on it. #
#-----------------------------------------------------------------------------#

# the mainline.

if ((not defined $newspass) && (not defined $ENV{'ICCNEWS_POST_PASS'})) {
if (defined $newspassfile) {
open(FH, $newspassfile) or die("failed to open $newspassfile: $!\n");
$newspass = <FH>;
chomp($newspass);
$newspass =~ s/\A\s*//;
$newspass =~ s/\s*\Z//;
close(FH);
}
}


for (my $i = 0; $i < scalar(@ARGV); $i++) {
my $arg = $ARGV[$i];
$debug = 1, next if ($arg eq '--debug');
$newshost = $ARGV[++$i], next if ($arg eq '--host');
$queuenum = $ARGV[++$i], next if ($arg eq '--queue');
$portnum = $ARGV[++$i], print("!!! FIXME: --port is ignored right now.\n"), next if ($arg eq '--port');
$newsauthor = $ARGV[++$i], next if ($arg eq '--user');
$newssubj = $ARGV[++$i], next if ($arg eq '--subj');
$postingagent = $ARGV[++$i], next if ($arg eq '--agent');

#$username = $arg, next if (not defined $username);
#$subject = $arg, next if (not defined $subject);
#$text = $arg, next if (not defined $text);
#etc.

print("Unknown argument \"$arg\".\n");
}

print(" reading from STDIN...\n") if $debug;
my $t = '';
$t .= $_ while (<STDIN>);

if (not defined $newssubj) {
if ($t =~ /^Subject:\s?(.*?)$/m) {
$newssubj = $1;
}
}

$newssubj = "Posting to IcculusNews mail gateway" if (not defined $newssubj);

print(" posting to IcculusNews's submission queue...\n") if $debug;
$ENV{'ICCNEWS_POST_PASS'} = $newspass if defined $newspass;
my $rc = open(PH, "|'$postingagent' '$newshost' '$newsauthor' '$queuenum' '$newssubj' -");
if (not $rc) {
print(" No pipe to IcculusNews: $!\n");
} else {
print PH "<i>$ENV{'SENDER'} sent us the following email:" .
"</i>\n<p>\n<pre>$t</pre>\n</p>\n";
close(PH);
print(" posted to submission queue.\n") if $debug;
}

exit 99; # prevent further qmail delivery with successful status.

# end of IcculusNews_dotqmail.pl ...

125 changes: 125 additions & 0 deletions IcculusNews_post.pl
@@ -0,0 +1,125 @@
#!/usr/bin/perl -w

use strict;
use Sys::Hostname;
use IO::Socket::INET;

my $version = "v2.0.0beta";

# The ever important debug-spew-enabler...
my $debug = 0;

#----------------------------------------------------------------------------#
# End of setup vars. The rest is probably okay without you touching it. #
#----------------------------------------------------------------------------#

sub usage {
print STDERR <<__EOF__;
IcculusNews_post $version
USAGE: $0 <host> <username> <queueid> <subject> <text>
if <username> is '-', the Anonymous account is used.
You will be prompted for a password if needed. You can
avoid the prompt if you set the ICCNEWS_POST_PASS
environment variable.
if <text> is '-', news is read from stdin.
__EOF__

exit 10;
}


sub okay_or_die {
my ($sock, $sect) = @_;
print "checking server response for: $sect\n" if $debug;
my $response = <$sock>;
chomp($response);
print "server said: \"$response\".\n" if $debug;
if ($response !~ /\A\+/) {
print $sock "QUIT\012"; # just in case.
close($sock);
die("Error reported during $sect: \"$response\".\n");
}
}


# the mainline.

my $user = undef;
my $host = undef;
my $pass = undef;
my $subj = undef;
my $text = undef;
my $qid = undef;

foreach (@ARGV) {
usage() if ($_ eq '--help');
$debug = 1, next if ($_ eq '--debug');
$host = $_, next if (not defined $host);
$user = $_, next if (not defined $user);
$qid = $_, next if (not defined $qid);
$subj = $_, next if (not defined $subj);
$text = $_, next if (not defined $text);
}

usage() if ((!defined $user) or (!defined $host) or (!defined $subj) or (!defined $text));

$text =~ s/\A\s*//;
$text =~ s/\s*\Z//;
if ($text eq '-') {
$text = '';
while (<STDIN>) {
$text .= $_;
}
}

$user =~ s/\A\s*//;
$user =~ s/\s*\Z//;

my $authstr = undef;
if ($user eq '-') {
$authstr = '-';
} else {
$pass = $ENV{'ICCNEWS_POST_PASS'};
if (not defined $pass) {
print("!!! FIXME: Prompt for a password here. export ICCNEWS_POST_PASS for now.\n");
exit(42);
}

$authstr = "\"$user\" \"$pass\"";
}

1 while ($text =~ s/\015\012/\012/s);
1 while ($text =~ s/\015/\012/s);
$text =~ s/^\.\012/..\012/sm;
1 while ($text =~ s/\012.\012/\012..\012/s);

print "Connecting to news server..." if $debug;
my $sock = IO::Socket::INET->new(PeerAddr => $host,
PeerPort => 263,
Type => SOCK_STREAM,
Proto => 'tcp');

die("Failed to connect to news server: $!\n") if not defined $sock;

print "connected.\n" if $debug;

okay_or_die($sock, 'initial welcome');
print $sock "AUTH $authstr\012";
okay_or_die($sock, 'user authorization');
print $sock "QUEUE $qid\012";
okay_or_die($sock, 'queue selection');
print $sock "POST $subj\012";
okay_or_die($sock, 'post command');
print $sock "$text\012.\012";
okay_or_die($sock, 'text posting');
print $sock "QUIT\012";
okay_or_die($sock, 'disconnection');
close($sock);

print("News item successfully posted.\n") if $debug;
exit 0;

# end of IcculusNews_post.pl ...

6 changes: 6 additions & 0 deletions TODO
@@ -0,0 +1,6 @@
- User interface to CREATEUSER.
- User interface to CHANGEPASSWORD (including emailing forgotten passwords).
- Have IcculusNews_post.pl prompt for a password.
- CREATEQUEUE.
- Shitloads more.

0 comments on commit a2bd8be

Please sign in to comment.