🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.free.newsservers
Article #164186

SOLVED: What is a quick Linux bash test of a free public newsserver on VPN?

#164186
From: VPN user
Date: Wed, 30 Mar 2016 00:47
98 lines
3771 bytes
> Here is the except TCL script.
> (BTW, what do people use for filename extensions for "expect" scripts?)
> 
> #!/usr/bin/expect
> # Test if NNTP posting is allowed by a given news server for the current VPN connection.
> # Use Model: $ vpnnntp.tcl nntp.aioe.org 119
> # Output: A message will state whether posting is allowed, or not.
> 
> # Abort if the process takes more than 10 seconds.
> # WIP: Need to test if this actually works as I haven't seen it happen yet.
> set timeout 10
> 
> # Obtain the newsserver & NNTP port from the command line:
> set _server [lindex $argv 0]
> set _port [lindex $argv 1]
> send_user "...Connecting to ${_server}:${_port}\n"
> 
> # Report whether the newsserver allows NNTP posting for this VPN connection.
> spawn telnet $_server $_port
> send_user "...Checking for connection-refused or for posting-ok condition...\n"
> expect {
>    "200 nntp.aioe.org InterNetNews NNRP server INN 2.5.4 ready (posting ok)"
>    {
>      send_user "...Good: Posting is allowed by ${_server}:${_port}\n"
>      send "quit\r"
>    }
> 
>    "Connection refused"
>    {
>      send_user "...Oops: Connections are refused by ${_server}:${_port}\n"
>    }
> 
>  }
> 
> expect eof

Above is the vpnnntp.tcl script which solves the original question.
Below is the bash vpnnntp.sh script which solves the original question.

Improvements are always welcome.

#!/bin/bash
# vpnnntp.sh will test whether nntp posting is ok given the current vpn server

# Free error checking:
set -u

# Output storage:
_outFile=/tmp/nntp.out

# If openvpn is not currently running, then exit.
openvpnPID=$(pgrep openvpn)
  if [ $? -ne 0 ]; then
    echo "Oops: Openvpn is not running."
    exit 1
  fi

# If the total number of arguments is 0, then use the default nntp server & nntp port.
# e.g., nntp.aioe.org:119
  if [ $# -eq 0 ]; then
    _nntpServer=nntp.aioe.org
    _nntpPort=119
 fi

# If the total number of arguments is 1, then use that nntp server & the default nntp port.
  if [ $# -eq 1 ]; then
    _nntpServer=$1
    _nntpPort=119
 fi

# If the total number of arguments is 2, then use that nntp server & that nntp port.
  if [ $# -eq 2 ]; then
    _nntpServer=$1
    _nntpPort=$2
 fi

# If the total number of arguments is greater than 2, then consider that an error.
  if [ $# -gt 2 ]; then
    echo "Oops: Too many arguments; maximum of 2"
    exit 1
 fi

# Attempt to connect to the given nntp server:
(
sleep 1
echo "quit";
) | telnet $_nntpServer $_nntpPort | tee $_outFile

# Test if the nntp server allows posting from the current openvpn IP address:
grep "posting ok" $_outFile 
if [ "$?" = "0" ]; then
  echo "Posting is ok because the exit return status was true = 0" # output on standard out
else
  echo "Posting is not ok because the exit return status was false = 1" 1>&2 # output on standard error
fi

exit 0
## End ##
Technical Details
Message-ID: <ndf7na$29b$10@news.mixmin.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!news.usenet.farm!..!..!not-for-mail
References: <nda1rf$65o$1@news.mixmin.net> <ndboei$tur$2@news.mixmin.net>

Show Full Headers
Complete Article Headers
Message-ID: <ndf7na$29b$10@news.mixmin.net>
Subject: SOLVED: What is a quick Linux bash test of a free public newsserver on VPN?
Date: Wed, 30 Mar 2016 00:47:38 +0000
From: VPN user <vpnuser@example.com>
References: <nda1rf$65o$1@news.mixmin.net> <ndboei$tur$2@news.mixmin.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!news.usenet.farm!..!..!not-for-mail
Newsgroups: alt.free.newsservers
Organization: Mixmin
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 30 Mar 2016 00:47:38 -0000 (UTC)
Injection-Info: news.mixmin.net; posting-host="2ca620a667accfe18cc30c1cbea46e4236ad982d";
Lines: 98