#!/bin/bash
# Version("2.2.0.1")
# InformationalVersion("2.2.0.1")

function send_404 {
	echo -e "HTTP/1.1 404 Not Found\r"
	echo -e "Content-Type: text/html\r"
	echo -e "\r"
	echo -e "<html><head><title>404 Not Found</title></head><body>\r"
	echo -e "<h1>404 Not Found</h1>\r"
	echo -e "The requested failover options was not found.\r"
	echo -e "</body></html>\r"
	echo -e "\r"
	
}

function send_403 {
	echo -e "HTTP/1.1 403 Forbidden\r"
	echo -e "Content-Type: text/html\r"
	echo -e "\r"
	echo -e "<html><head><title>403 Forbidden</title></head><body>\r"
	echo -e "<h1>403 Forbidden</h1>\r"
	echo -e "<p>The requested failover option is not available.\r</p>"
	echo -e "</body></html>\r"
	echo -e "\r"
	exit 0
}




function handle_reload {

	echo -e "HTTP/1.1 200 OK\r"
	echo -e "Content-Type: text/plain\r"
	echo -e "\r"
	/usr/bin/sudo /usr/sbin/asterisk -rx "module reload"
	echo -e "\r"
	exit 0
}


# Main Routine

if [ $QUERY_STRING == "reload" ]
then
	handle_reload
fi

# No request so request forbidden
send_403
exit 0

