- Complete migration,

- Move usr/lib, usr/sbin & var/www to lib, sbin & www,
- Add dns_host_update() to dns library,
- Add RPM Spec & bash completion files.
This commit is contained in:
2026-04-19 12:06:40 +02:00
parent f58ffedef9
commit ad3862a5e0
36 changed files with 3481 additions and 2118 deletions

534
www/cgi-bin/ns-admin_board.cgi Executable file
View File

@@ -0,0 +1,534 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------------------------------------------
#
# Rx3 NS Admin Board CGI
#
# Copyright (C) 2025-2026 Arnaud G. GIBERT
# mailto:arnaud@rx3.net
#
# This is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; If not, see
# <https://www.gnu.org/licenses/>.
#
#-----------------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------------
# Includes
#-----------------------------------------------------------------------------------------------------------------------------------
: "${RX3_LIB_DIR:=/usr/lib/rx3}"
. "${RX3_LIB_DIR}/dns.bash"
. /etc/sysconfig/rx3-ns # To be removed?
#-----------------------------------------------------------------------------------------------------------------------------------
# Global Variables
#-----------------------------------------------------------------------------------------------------------------------------------
declare -g VERSION="1.2.0"
declare -g NAME="ns-admin_board.cgi"
declare -g DEBUG=""
#declare -g DEBUG="echo"
#declare -g DEBUG=":"
# No Log please
export LOG=""
declare -g CMD=""
declare -g FORMAT=""
declare -g IP=""
declare -g HOST=""
declare -g DOMAIN=""
declare -g REDIRECT=""
declare -g CMD_STATUS=""
declare -g REFRESH=""
declare -g TTL=""
declare -g STATUS=""
declare -g FILE_NAME=""
declare -g REMOTE_IP="${REMOTE_ADDR}"
declare -g HOST_INFO=""
#-----------------------------------------------------------------------------------------------------------------------------------
# Lookup Domain Owner
#-----------------------------------------------------------------------------------------------------------------------------------
nab_lookup_domain_owner()
{
local ldo_blk
local ldo_domain
local ldo_host
local ldo_owner
local OIFS
for ldo_blk in ${NS_LIST}
do
OIFS="${IFS}"
IFS=":"
set ${ldo_blk}
ldo_domain="$1"
ldo_host="$2"
ldo_owner="$3"
IFS="${OIFS}"
if [[ "${HOST}.${DOMAIN}" == "${ldo_host}.${ldo_domain}" ]]
then
echo "${ldo_owner}"
fi
done
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Header Print
#-----------------------------------------------------------------------------------------------------------------------------------
nab_header_print()
{
case "${FORMAT}"
in
"html")
echo "Content-type: text/html"
echo ""
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"
echo "<HTML>"
echo " <HEAD>"
echo " <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">"
if [[ "${REFRESH}" == "yes" ]]
then
echo " <META http-equiv=\"Refresh\" content=\"300\">"
fi
echo " <META http-equiv=\"Pragma\" content=\"no-cache\">"
echo " <LINK REL=\"shortcut icon\" HREF=\"/favicon.ico\" TYPE=\"image/x-icon\">"
echo " <LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"/tdsots/default.css\">"
echo " <TITLE>Rx3 NS Admin: ${CMD_STATUS}</Title>"
echo " </HEAD>"
echo " <BODY>"
;;
"txt")
echo "Content-disposition: attachment; filename=${FILE_NAME}"
echo "Content-type: text/plain"
echo ""
;;
esac
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Footer Print
#-----------------------------------------------------------------------------------------------------------------------------------
nab_footer_print()
{
case "${FORMAT}"
in
"html")
echo " </BODY>"
echo ""
echo "</HTML>"
;;
esac
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Usage Print
#-----------------------------------------------------------------------------------------------------------------------------------
nab_usage_print()
{
if [[ "${FORMAT}" == "html" ]]
then
echo " <P>"
echo " <BR>"
echo " </P>"
echo ""
echo " <H2>Rx3 NS Admin Service Usage</H2>"
echo ""
echo " <TABLE BORDER=\"1\" WIDTH=\"95%\" ALIGN=\"CENTER\">"
echo " <TR><TD>"
echo " <TABLE BORDER=\"0\" WIDTH=\"95%\" ALIGN=\"CENTER\">"
echo " <TR><TD>"
echo " <PRE>"
echo " - cmd=address_get: Get the host IP address"
echo " + [format=html|txt]: Output request format (Default to html)"
echo " + host=&lt;Host Name&gt;: Host name to show"
echo " + domain=&lt;Domain Name&gt;: Domain name of the host name"
echo ""
echo " - cmd=address_set: Set the host IP address"
echo " + [format=html|txt]: Output request format (Default to html)"
echo " + host=&lt;Host Name&gt;: Host name to set"
echo " + domain=&lt;Domain Name&gt;: Domain name of the host name"
echo " + [ip=&lt;IP Address&gt;]: IP address to be set (Default to requestor address)"
echo " + [ttl=&lt;TTL&gt;]: TTL to be set (Default to 600)"
echo ""
echo " - Example: https://www.rx3.net/cgi-bin-private/ns-admin_board.cgi?cmd=address_get&amp;host=vpn0&amp;domain=vpn.rx3"
echo " </PRE>"
echo " </TD></TR>"
echo " </TABLE>"
echo " </TD></TR>"
echo " </TABLE>"
else
echo "Rx3 NS Service Usage:"
echo " - cmd=address_get: Get the host IP address"
echo " + [format=html|txt]: Output request format (Default to html)"
echo " + host=<Host Name>: Host name to show"
echo " + domain=<Domain Name>: Domain name of the host name"
echo ""
echo " - cmd=address_set: Set the host IP address"
echo " + [format=html|txt]: Output request format (Default to html)"
echo " + host=<Host Name>: Host name to set"
echo " + domain=<Domain Name>: Domain name of the host name"
echo " + [ip=<IP Address>]: IP address to be set (Default to requestor address)"
echo " + [ttl=<TTL>]: TTL to be set (Default to 600)"
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Result Print
#-----------------------------------------------------------------------------------------------------------------------------------
nab_result_print()
{
local message="$1"
if [[ "${FORMAT}" == "html" ]]
then
echo " <TABLE BORDER=\"1\" WIDTH=\"95%\" ALIGN=\"CENTER\">"
echo " <TR><TD>"
echo " <TABLE BORDER=\"0\" WIDTH=\"95%\" ALIGN=\"CENTER\">"
echo " <TR><TD>"
echo " <PRE>"
echo "${message}"
echo " </PRE>"
echo " </TD></TR>"
echo " </TABLE>"
echo " </TD></TR>"
echo " </TABLE>"
else
echo "${message}"
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Main Board Print
#-----------------------------------------------------------------------------------------------------------------------------------
nab_main_board_print()
{
local blk
local domain
local host
local owner
local address
local ttl
local date
local class
local idx=0
local OIFS
if [[ "${FORMAT}" == "html" ]]
then
echo ""
echo " <H1>Rx3 NS Admin Board</H1>"
echo " <P>"
echo " <BR>"
echo ""
echo " <b>Date: $(/bin/date)</b><br>"
echo " </P>"
echo " <HR>"
echo ""
echo " <P>"
echo " <BR>"
echo " </P>"
echo ""
echo " <H2>Rx3 NS Status Board</H2>"
echo ""
echo " <TABLE BORDER=\"1\" WIDTH=\"100%\">"
echo " <TR class=\"header\"><TD class=\"header\">#</TD><TD>Domain</TD><TD>Host</TD><TD>Address</TD><TD>Owner</TD><TD>TTL</TD><TD>Date</TD></TR>"
else
echo "TABLE: RX3-NS_Status_Board"
echo "#;Domain;Host;Address;Owner;TTL;Date"
fi
for blk in ${NS_LIST}
do
OIFS="${IFS}"
IFS=":"
set ${blk}
domain="$1"
host="$2"
owner="$3"
IFS="${OIFS}"
address="$( dig -t A "${host}.${domain}." | grep "^${host}.${domain}" | awk '{print $5}')"
ttl="$( dig -t A "${host}.${domain}." | grep "^${host}.${domain}" | awk '{print $2}')"
date="$( dig -t TXT "${host}.${domain}." | grep "^${host}.${domain}" | awk '{print $5 " " $6}' | sed -e 's/\"//g')"
if [[ "${REMOTE_USER}" == "${owner}" ]]
then
class="default"
else
class="dark"
fi
if [[ "${FORMAT}" == "html" ]]
then
echo " <TR class=\"${class}\"><TD class=\"header\">${idx}</TD><TD>${domain}</TD><TD>${host}</TD><TD>${address}</TD><TD>${owner}</TD><TD>${ttl}</TD><TD>${date}</TD></TR>"
else
echo "${domain};${host};${address};${owner};${ttl};${date}"
fi
idx=$(( idx + 1 ))
done
if [[ "${FORMAT}" == "html" ]]
then
echo " </TABLE>"
echo " <P>"
echo " <BR>"
echo " </P>"
else
echo ""
fi
nab_usage_print
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Query String Parse
#-----------------------------------------------------------------------------------------------------------------------------------
nab_query_string_parse()
{
local var
local arg
local i
CMD=""
FORMAT=""
IP=""
HOST=""
DOMAIN=""
TTL=""
if [[ "${QUERY_STRING}" != "" ]]
then
local OIFS="${IFS}"
IFS="&"
set ${QUERY_STRING}
IFS="${OIFS}"
i=$#
while [[ "${i}" != "0" ]]
do
var="${1/=*/}"
arg="${1/*=/}"
case "${var}"
in
"cmd")
CMD="${arg}"
;;
"format")
FORMAT="${arg}"
;;
"host")
HOST="${arg}"
;;
"domain")
DOMAIN="${arg}"
;;
"ip")
IP="${arg}"
;;
"ttl")
TTL="${arg}"
;;
esac
shift
i=$(( i - 1 ))
done
fi
if [[ "${FORMAT}" == "" ]]
then
FORMAT="html"
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Command Handler
#-----------------------------------------------------------------------------------------------------------------------------------
nab_command_handler()
{
local owner
local status
case "${CMD}"
in
"")
CMD_STATUS="OK"
REFRESH="yes"
nab_header_print
nab_main_board_print
nab_footer_print
;;
"address_set")
owner="$( nab_lookup_domain_owner)"
if [[ "${owner}" != "" ]]
then
if [[ "${REMOTE_USER}" == "${owner}" ]]
then
if [[ "${IP}" == "" ]]
then
IP="${REMOTE_IP}"
fi
if [[ "${TTL}" == "" ]]
then
TTL="600"
fi
dns_host_update "${HOST}" "${DOMAIN}" "${IP}" "${TTL}"
if [[ "$?" == "0" ]]
then
status="OK"
else
status="KO"
fi
else
status="KO - Not Authorized"
fi
else
status="KO - Domain not found"
fi
CMD_STATUS="${CMD}: ${status}"
REFRESH="no"
nab_header_print
nab_result_print "Set ${HOST}.${DOMAIN}. to ${IP} with TTL ${TTL}: ${status}"
nab_footer_print
;;
"address_get")
owner="$( nab_lookup_domain_owner)"
if [[ "${owner}" != "" ]]
then
HOST_INFO="$( dig -t ANY "${HOST}.${DOMAIN}.")"
if [[ "$?" == "0" ]]
then
status="OK"
else
status="KO"
fi
else
status="KO - Domain not found"
fi
CMD_STATUS="${CMD}: ${status}"
REFRESH="no"
nab_header_print
if [[ "${FORMAT}" == "html" ]]
then
nab_result_print "${HOST}.${DOMAIN}.: ${status}<br>
${HOST_INFO}"
else
echo "${HOST}.${DOMAIN}.:"
echo ""
echo "${HOST_INFO}"
fi
nab_footer_print
;;
*)
CMD_STATUS="${CMD}: UNKNOWN_CMD"
nab_header_print
nab_footer_print
;;
esac
}
#-----------------------------------------------------------------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------------------------------------------------------------
nab_query_string_parse
dns_init
nab_command_handler
dns_deinit