- Initial release.
This commit is contained in:
460
var/www/cgi-bin/ns-admin_board.cgi
Executable file
460
var/www/cgi-bin/ns-admin_board.cgi
Executable file
@@ -0,0 +1,460 @@
|
||||
#!/bin/bash
|
||||
|
||||
. /etc/sysconfig/rx3-ns
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Lookup Domain Owner ()
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Lookup_Domain_Owner ()
|
||||
{
|
||||
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
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Tailer
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Footer_Print ()
|
||||
{
|
||||
case "${format}"
|
||||
in
|
||||
"html")
|
||||
echo " </BODY>"
|
||||
echo ""
|
||||
echo "</HTML>"
|
||||
;;
|
||||
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Args
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
cmd=""
|
||||
format=""
|
||||
ip=""
|
||||
host=""
|
||||
domain=""
|
||||
redirect=""
|
||||
|
||||
remote_ip="${REMOTE_ADDR}"
|
||||
|
||||
if [[ "${QUERY_STRING}" != "" ]]
|
||||
then
|
||||
OIFS=${IFS}
|
||||
IFS="\&"
|
||||
set ${QUERY_STRING}
|
||||
IFS=${OIFS}
|
||||
|
||||
i=$#
|
||||
|
||||
while [[ "${i}" != 0 ]]
|
||||
do
|
||||
var=${1/=*/}
|
||||
arg=${1/*=/}
|
||||
|
||||
case "${var}"
|
||||
in
|
||||
"format")
|
||||
format=${arg}
|
||||
;;
|
||||
|
||||
"cmd")
|
||||
cmd=${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
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Usage_Print
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
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" cols=1 width="95%" nosave align=\"CENTER\">"
|
||||
echo " <tr>"
|
||||
echo " <td>"
|
||||
echo " <table border="0" cols=1 width="95%" nosave align=\"CENTER\">"
|
||||
echo " <tr>"
|
||||
echo " <td>"
|
||||
echo " <pre>"
|
||||
|
||||
echo " <BR>"
|
||||
echo " - cmd=address_get: Get the host IP address<br>"
|
||||
echo " + [format=html|txt]: Output request format (Default to "html")<br>"
|
||||
echo " + host=<Host Name>: Host name to show<br>"
|
||||
echo " + domain=<Domaine Name>: Domain name of the host name<br>"
|
||||
echo "<br>"
|
||||
echo " - cmd=address_set: Set the host IP address<br>"
|
||||
echo " + [format=html|txt]: Output request format (Default to "html")<br>"
|
||||
echo " + host=<Host Name>: Host name to set<br>"
|
||||
echo " + domain=<Domaine Name>: Domain name of the host name<br>"
|
||||
echo " + [ip=<IP Address>]: IP address to be set (Default to requestor address)<br>"
|
||||
echo " + [ttl=<TTL>]: TTL to be set (Default to 600)<br>"
|
||||
echo "<br>"
|
||||
echo " - Example: https://www.rx3.net/cgi-bin-private/ns-admin_board.cgi?cmd=address_get&host=vpn0&domain=vpn.rx3<br>"
|
||||
|
||||
echo " </pre>"
|
||||
echo " </td>"
|
||||
echo " </tr>"
|
||||
echo " </table>"
|
||||
echo " </td>"
|
||||
echo " </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=<Domaine 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=<Domaine 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)<br>"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Main Board Print
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Main_Board_Print ()
|
||||
{
|
||||
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 ""
|
||||
fi
|
||||
|
||||
if [[ "${format}" == "html" ]]
|
||||
then
|
||||
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
|
||||
|
||||
idx=0
|
||||
|
||||
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
|
||||
|
||||
Usage_Print
|
||||
}
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
# Command Handler
|
||||
#--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
case "${cmd}"
|
||||
in
|
||||
"")
|
||||
cmd_status="OK"
|
||||
refresh="yes"
|
||||
|
||||
Header_Print
|
||||
|
||||
Main_Board_Print
|
||||
|
||||
Footer_Print
|
||||
;;
|
||||
|
||||
"address_set")
|
||||
owner=$(Lookup_Domain_Owner)
|
||||
|
||||
if [[ "${owner}" != "" ]]
|
||||
then
|
||||
if [[ "${REMOTE_USER}" == "${owner}" ]]
|
||||
then
|
||||
if [[ "${ip}" == "" ]]
|
||||
then
|
||||
ip="${remote_ip}"
|
||||
fi
|
||||
|
||||
if [[ "${ttl}" == "" ]]
|
||||
then
|
||||
ttl="600"
|
||||
fi
|
||||
|
||||
sudo /usr/local/sbin/ip_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"
|
||||
|
||||
Header_Print
|
||||
|
||||
if [[ "${format}" == "html" ]]
|
||||
then
|
||||
echo " <table border="1" cols=1 width="95%" nosave align=\"CENTER\">"
|
||||
echo " <tr>"
|
||||
echo " <td>"
|
||||
echo " <table border="0" cols=1 width="95%" nosave align=\"CENTER\">"
|
||||
echo " <tr>"
|
||||
echo " <td>"
|
||||
echo " <pre>"
|
||||
fi
|
||||
|
||||
echo "Set $host.$domain. to ${ip} with TTL ${ttl}: ${status}"
|
||||
|
||||
if [[ "${format}" == "html" ]]
|
||||
then
|
||||
echo " </pre>"
|
||||
echo " </td>"
|
||||
echo " </tr>"
|
||||
echo " </table>"
|
||||
echo " </td>"
|
||||
echo " </tr>"
|
||||
echo " </table>"
|
||||
fi
|
||||
|
||||
Footer_Print
|
||||
;;
|
||||
|
||||
"address_get")
|
||||
|
||||
owner=$(Lookup_Domain_Owner)
|
||||
if [[ "${owner}" != "" ]]
|
||||
then
|
||||
# if [[ "${REMOTE_USER}" == "${owner}" ]]
|
||||
# then
|
||||
# host_info="$(host ${host}.${domain})"
|
||||
host_info="$(dig -t ANY ${host}.${domain}.)"
|
||||
|
||||
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"
|
||||
|
||||
Header_Print
|
||||
|
||||
if [[ "${format}" == "html" ]]
|
||||
then
|
||||
echo " <table border="1" cols=1 width="95%" nosave align=\"CENTER\">"
|
||||
echo " <tr>"
|
||||
echo " <td>"
|
||||
echo " <table border="0" cols=1 width="95%" nosave align=\"CENTER\">"
|
||||
echo " <tr>"
|
||||
echo " <td>"
|
||||
echo " <pre>"
|
||||
|
||||
echo "$host.$domain.: ${status}"
|
||||
echo "<br>"
|
||||
else
|
||||
echo "$host.$domain.:"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "${host_info}"
|
||||
|
||||
if [[ "${format}" == "html" ]]
|
||||
then
|
||||
echo " </pre>"
|
||||
echo " </td>"
|
||||
echo " </tr>"
|
||||
echo " </table>"
|
||||
echo " </td>"
|
||||
echo " </tr>"
|
||||
echo " </table>"
|
||||
fi
|
||||
|
||||
Footer_Print
|
||||
;;
|
||||
|
||||
*)
|
||||
cmd_status="${cmd}: UNKNOWN_CMD"
|
||||
|
||||
Header_Print
|
||||
Footer_Print
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user