Article View: news.software.nntp
Article #39748dnewgroup: a diablo "newgroup" command
From: Paul Martin
Date: Fri, 10 Sep 1999 00:00
Date: Fri, 10 Sep 1999 00:00
110 lines
3294 bytes
3294 bytes
After getting sick of doing this by hand, I coded.
#!/usr/bin/perl
# dnewgroup, create new newsgroups in diablo
# Copyright 1999 Paul Martin <pm@zetnet.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
use Getopt::Std;
# Constants
sub dkp { '/news/dbin/dkp' };
sub dactive { '/news/dactive.kp' };
# Convert string to escaped version
sub encode {
my $return;
$_ = shift;
for (split //) {
$return .= $_, next if /[a-zA-Z0-9.]/;
$return .= sprintf("%%%02x",ord($_));
}
return $return;
}
# Exclude disallowed characters
sub sanitize {
my $return;
$_ = shift;
for (split //) {
$return .= $_, next if /[a-zA-Z0-9@+_., -]/;
$return .= ' ', next if /\t/;
$return .= '?';
}
return $return;
}
### main
my %opts;
getopts('mhud:n:',\%opts);
# It appears not to be good thing to be messing around with dactive.kp
# if you're not running as the news user
if ( ((getpwuid($<))[0] ne 'news') && !$opts{'u'} ) {
print "Error! You are not running this as user 'news'.\n";
exit;
}
# Dispense help
if ($opts{'h'} or !$opts{'n'}) {
print <<EOF;
$0 [-h] [-u] [-d description] [-m] -n newsgroup
-h help
-d newsgroup description
-n newsgroup name
-m moderated
-u no userid checks
EOF
exit;
}
my ($status,$description);
my $tim=sprintf("%08x",time);
my $newsgroup = $opts{'n'};
# Status flag, y=posting allowed, m=moderated
if ($opts{'m'}) {
$status = 'm';
} else {
$status = 'y';
}
# Mangle the description field so Diablo likes it
$description = &encode(&sanitize($opts{'d'}));
# Modify the database
system dkp, '-w', dactive, $newsgroup, 'NB=0000000001';
system dkp, '-w', dactive, $newsgroup, 'NE=0000000000';
system dkp, '-w', dactive, $newsgroup, "CTS=$tim";
system dkp, '-w', dactive, $newsgroup, "LMTS=$tim";
system dkp, '-w', dactive, $newsgroup, "S=$status";
system dkp, '-w', dactive, $newsgroup, "GD=$description"
if $opts{'d'};
--
Paul Martin <pm@zetnet.net>
at home, swap dash to dot to email.
Technical Details
Message-ID:
<37d923a5$0$122@master.news.zetnet.net>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-mailShow Full Headers
Complete Article Headers
Message-ID: <37d923a5$0$122@master.news.zetnet.net> Subject: dnewgroup: a diablo "newgroup" command Date: Fri, 10 Sep 1999 00:00:00 +0000 From: pm@nowster-zetnet.co.uk (Paul Martin) 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: 523419220 X-Trace: master.news.zetnet.net 936977317 122 root@194.247.42.229 User-Agent: slrn/0.9.5.7 (UNIX) Newsgroups: news.software.nntp