<%#
 Copyright 2016 Chen RuiWei <crwbak@gmail.com>
 Licensed to the public under the Apache License 2.0.
-%>

<% include("cbi/map") %>
<script type="text/javascript">//<![CDATA[
	function isIP(strIP)
	{
        var re = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g//匹配IP地址的正则表达式
        if (re.test(strIP))
        {
            if (RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256)
                return true;
        }
        return false;
	}

	var domains = document.getElementsByClassName('domain');
	for(var i = 0; i<domains.length; i++)
	{
		new XHR().get('<%=luci.dispatcher.build_url("admin", "services", "koolddns", "nslookup")%>', {index: i, domain: domains[i].getAttribute("hint")},
			function(x, result)
			{
				domains[result.index].innerHTML = result.value?result.value:"error";
			}
		);
	}
	var urls = document.getElementsByClassName('url');
	for(var i = 0; i<urls.length; i++)
	{
		var hint = urls[i].getAttribute("hint").replace(/(^[\s\r\n]*)|([\s\r\n]*$)/g, "");
		if (hint =="") continue;
		else if (isIP(hint))
			urls[i].innerHTML = hint;
		else
			new XHR().get('<%=luci.dispatcher.build_url("admin", "services", "koolddns", "curl")%>', {index: i, url: hint},
				function(x, result)
				{
					urls[result.index].innerHTML = result.value?result.value:"error";
				}
			);
	}
//]]>
</script>
