#!/bin/sh

# Get all open ports
query=$(netstat -tn 2>/dev/null | grep :20 | grep ESTABLISHED)
date=$(date)

echo "--------------------------"
echo "Server connection count: $date"
stats=$(ps -C fwbooster -o %cpu,%mem,cmd)
echo "$stats"
echo ""

# Parse and display connection count for each port
parse_and_display() {
    port=$1
    name=$2
    count=$(echo "$query" | grep $port | wc -l)
    echo "Port $port: $count - $name"
}

parse_and_display 20004 "Routing Messages"
parse_and_display 20014 "SSL Default"
parse_and_display 20026 "FileWave Client to Booster connections using NATS Server: Remote Control Publishing, Remote Control Routing, device renaming, revoking device certificates, push notifications"

echo ""
echo "Booster to Booster Connections open:"
port9sample=$(echo "$query" | grep 20018)
echo "$port9sample"
echo "--------------------------"

echo ""
echo "Sample of 20 clients on 20014:"
port2sample=$(echo "$query" | grep 20014 | tail -n 20)
echo "$port2sample"
echo "--------------------------"

exit
