LinBPQ: portfreq – FREQS Node Command

intro

A couple of scripts have been put together that welds the linbpq application interface with a standard inetd service that once accessed launches a login to the node’s own telnet interface and retrieves the frequencies of the radios attached to the various ports. This will only work on nodes that have RIGCONTROL enabled.

Setting up the script is not straight forward unless one has experience with the OpenBSD or Linux operating systems.

Scripts

The scripts are in two parts, one is the main script handling the user interaction and the other is a special ’expect’ script that takes on the role of interacting with the node via the telnet interface as if it were an actual user.

File name: portfreq.sh

Set Permission: chmod 755 portfreq.sh
#!/bin/bash
script="/home/pi/linbpq/scripts/portfreq.expect"
user="YouCall"
pass="YourPassword!"
host="127.0.0.1"
port="8010"

RadioPorts=“1 2 3 4 5 6 7 8 21 22 23 24”

$script $host $port $user $pass "$RadioPorts"
echo "Bye!"

Adjust the RadioPorts= list to match your own BPQ radio ports.

File name: portfreq.expect

Set Permission: chmod 755 portfreq.expect
#!/usr/bin/expect 
set timeout 4

set host [lindex $argv 0]
set port [lindex $argv 1]
set login [lindex $argv 2]
set password [lindex $argv 3]
set radioports [lindex $argv 4]

log_user 0
spawn telnet $host $port

expect "callsign:"
send "$login\r"

expect "password:"
send "$password\r"

expect "Connected,"
send "PASSWORD\r"
expect "Ok"
foreach radioport $radioports {
log_user 0
        send "radio $radioport freq\r"
        expect {
                -re "(.*)Frequency is(.*)\r"  { set freq  "$expect_out(2,string)" }
                -re {.+(Radio\ not\ responding)} { set freq "Radio Borked" }
        }
        send_user "Port $radioport $freq\n"

}
expect eof
exit


Potential Gotchas: The above expect script will wait 4 seconds for the result from the node before forcing itself to quit. The interface with the node is a live session and therefore there isn’t an end-of-file signal or any other way of detecting the end of the port list, so a timeout is used instead.

Additionally, the expect script depends upon the detection of certain key words to perform actions, in some cases a sysop (that’s you) may have changed their node’s CTEXT, the Connected, portion may need to be adjusted to match your node’s connect text.

Packages Required

sudo apt install expect
sudo apt install openbsd-inetd

Inetd Service Configuration

sudo systemctl enable inetd
sudo service inetd start

Inetd configuration

The inetd daemon turns the script into a connectable internet service, using a simple telnet program it is then possible to log into the configured listening port for the script to access the script’s function. The daemon takes care of starting and stopping the script’s execution when a connection begins and ends.

File Name: /etc/inetd.conf

Add the below line to the /etc/inetd.conf file, be sure to maintain the spacing between the fields of the line (how many spaces isn’t important but the fields must be separated). This is one line, make sure you do not include any carriage returns or newlines.


portfreq  stream  tcp     nowait  pi  /home/pi/linbpq/scripts/portfreq.sh

The fields that will need your attention are the ones ’pi’ and ‘/home/pi/linbpq/scripts’ as these must reflect the user ID that linbpq runs under on your system, and the path to your linbpq directory, you may need to create the ‘scripts’ subdirectory.

The service requires a TCP port number, add a new line for ‘portfreq’ to /etc/services, make sure the port does not already exist, if the port number is already defined in the file then that means the port has already been taken by another service. Make sure the one you choose is above 1024 but below 65535.

File Name: /etc/services

The first word ’portfreq’ must match with its sibling configuration in inetd.conf

Example:

portfreq  63011/tcp # BPQ radio port FREQS node command

Restart the inetd service to load the new configuration changes:

sudo service inetd restart

Modifying linbpq configuration

Prerequisites: bpq32.cfg should already have a telnet port defined. The port is required for BPQ to create a loop-back connection to the host it is running on.

The documentation has an example provided at the very bottom, should the website be offline, below is a PDF backup.

CMDPORT

A list of up to 32 ports. These ports are used for connections to applications running on the same machine. This was originally intended to connect to a command shell to enable basic configuration editing, but has been generalised to allow connects to other tcp ports, thus providing an additional API option. 

BPQ32 Documentation.

Put the port number that you chose in the /etc/services setup in the CMDPORT= list within the bpq32.cfg telnet port configuration. There may already be a port defined there for normal telnet access to the node (default 8010), add your port to the list and make a note of its position in the list. The position of the portfreq port in the list will be needed later. The offset begins at zero (0) for the first port defined on the CMDPORT= line.

Example CMDPORT parameters:


CMDPORT=8010 2323 2424 63010 63011


Port 63011 (highlighted) is positioned at offset #4.

The next part focuses on a different segment of the bpq32.cfg configuration file, the APPLICATION definitions- these provide the different commands on the node command interface that users can use to do things on the node, such as access the BBS or log into the CHAT. Each application is defined with a number from 1-32.

Locate the existing APPLICATION definitions and pick the next available APPLICATION number.

Example APPLICATION definition:


APPLICATION 8,FREQS,C 10 HOST 4 S NOCALL

In the example above, #8 is selected for the application, followed by the word ”FREQS”- the alias or command a user uses on the node command line to start the node search.

C 10 – 10 in this example is the number associated with the BPQ Telnet Port, this can vary system to system so be sure to check your own to make sure the number matches. The ‘C’ refers to the internal node command ”connect”. When a user accesses the command ”FREQS”, the node begins a connection on BPQ port 10.

The keyword HOST with a number following tells BPQ to initiate a loopback connection to itself on the port defined in CMDPORT= at offset #4.

The following keys ”S” and ”NOCALL” refer to ”Stay” and ”Don’t send my callsign” when executing the command. This lets a user stay connected to the node.

As the portfreq script doesn’t require a login, then there is no purpose in sending the user’s callsign along with the initial connection.

Configuring the login for the expect script

See the documentation for the Telnet Port for defining Telnet users in BPQ.

Example:

USER=MyCall,MyPassword,MyCall,,SYSOP

Testing

After restarting linbpq the ‘FREQS’ command should now work from within the node. If it does not, then check to see if you can access the script running on the inetd by using the telnet command (you may need to install the telnet package first).

telnet localhost 63011

You should then be presented with this output:

Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Port 1  7.04512 MHz
Port 2  7.04512 MHz
Port 3  7.04512 MHz
Port 4  7.04512 MHz
Port 5  14.1022 MHz
Port 6  14.1022 MHz
Port 7  14.1022 MHz
Port 8  14.1022 MHz
Port 21  28.1566 MHz
Port 22  28.1566 MHz
Port 23  28.1566 MHz
Port 24  28.1566 MHz
Bye!
Connection closed by foreign host.

If this yields an error, go back and ensure that the file permissions, paths and file ownerships match your linbpq system. Double check that there are no errors in the /etc/inetd.conf including possibly incorrectly copy and pasted characters.

Check that the portfreq.expect script has matching login, password and the SYSOP field is set, and that the host is set to 127.0.0.1 and TCP port matches the one listed within the bpq32.cfg telnet port configuration.

If you have an error similar to:

/home/pi/linbpq//portfreq.sh: line 13: portfreq.expect: command not found

Edit the second line of the portfreq.sh script to the full path location of portfreq.expect. This can vary system to system- but wherever you created the script files within the linbpq directory will be where you need to point the path. In the above example, the scripts subdirectory was literally missing from the path.

Usage

Log into the node and issue the ’freqs’ command.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s