#!/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 "" echo "" echo " " echo " " if [[ "${refresh}" == "yes" ]] then echo " " fi echo " " echo " " echo " " echo " Rx3 NS Admin: ${cmd_status}" echo " " echo " " ;; "txt") echo "Content-disposition: attachment; filename=${file_name}" echo "Content-type: text/plain" echo "" ;; esac } #-------------------------------------------------------------------------------------------------------------------------- # Tailer #-------------------------------------------------------------------------------------------------------------------------- Footer_Print () { case "${format}" in "html") echo " " echo "" echo "" ;; 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 "

" echo "
" echo "

" echo "" echo "

Rx3 NS Admin Service Usage

" echo "" echo " " echo " " echo " " echo " " echo "
" echo " " echo " " echo " " echo " " echo "
" echo "
"

	echo "      
" 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)
" echo "
" echo " - Example: https://www.rx3.net/cgi-bin-private/ns-admin_board.cgi?cmd=address_get&host=vpn0&domain=vpn.rx3
" echo "
" echo "
" echo "
" 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 to show" echo " + domain=: 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 to set" echo " + domain=: Domain name of the host name" echo " + [ip=]: IP address to be set (Default to requestor address)" echo " + [ttl=]: TTL to be set (Default to 600)
" fi } #-------------------------------------------------------------------------------------------------------------------------- # Main Board Print #-------------------------------------------------------------------------------------------------------------------------- Main_Board_Print () { if [[ "${format}" == "html" ]] then echo "" echo "

Rx3 NS Admin Board

" echo "

" echo "
" echo "" echo " Date: $(/bin/date)
" echo "

" echo "
" echo "" fi if [[ "${format}" == "html" ]] then echo "

" echo "
" echo "

" echo "" echo "

Rx3 NS Status Board

" echo "" echo " " echo " " 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 "" else echo "${domain};${host};${address};${owner};${ttl};${date}" fi idx=$((${idx}+1)) done if [[ "${format}" == "html" ]] then echo "
#DomainHostAddressOwnerTTLDate
${idx}${domain}${host}${address}${owner}${ttl}${date}
" echo "

" echo "
" echo "

" 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 " " echo " " echo " " echo " " echo "
" echo " " echo " " echo " " echo " " echo "
" echo "
"
	fi

	echo "Set $host.$domain. to  ${ip} with TTL ${ttl}: ${status}"

	if [[ "${format}" == "html" ]]
	then
	    echo "                
" echo "
" echo "
" 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 " " echo " " echo " " echo " " echo "
" echo " " echo " " echo " " echo " " echo "
" echo "
"

	    echo "$host.$domain.: ${status}"
	    echo "
" else echo "$host.$domain.:" echo "" fi echo "${host_info}" if [[ "${format}" == "html" ]] then echo "
" echo "
" echo "
" fi Footer_Print ;; *) cmd_status="${cmd}: UNKNOWN_CMD" Header_Print Footer_Print ;; esac