<%+cbi/valueheader%>
<%uci=require"luci.model.uci".cursor()%>
<%nixio=require"nixio"%>

<%if uci:get("autoipsetadder","autoipsetadder","enabled")=="1" then%>
<textarea id="cbid.logview.1.conf" class="cbi-input-textarea" style="width: 100%;display:inline" data-update="change" rows="10" cols="60" readonly="readonly" > </textarea>
<input type="checkbox" value="reverse" onclick=" return reverselog()" style="vertical-align:middle;height: auto;" checked><%:reverse%></input>
<input type="button" class="cbi-button cbi-button-apply" id="apply_update_button" value="dellog" onclick=" return apply_del_log() "/>

<input type="button" class="cbi-button cbi-button-apply" id="apply_update_button" value="debug" onclick=" return debug_ip() "/>

<textarea id="cbid.logview.2.conf" class="cbi-input-textarea" style="width: 100%;display:none" data-update="change" rows="10" cols="60" readonly="readonly" > </textarea>

<script type="text/javascript">//<![CDATA[
var islogreverse = true;
function apply_del_log(){
	XHR.get('<%=url([[admin]], [[services]], [[autoipsetadder]], [[dodellog]])%>',null,function(x, data){
	var lv = document.getElementById('cbid.logview.1.conf');
		lv.innerHTML="";
	}
		);
	return
}
function reverselog(){
	var lv = document.getElementById('cbid.logview.1.conf');
	lv.innerHTML=lv.innerHTML.split('\n').reverse().join('\n')
	if (islogreverse){
	islogreverse=false;
	}else{
	islogreverse=true;
	}
	return
}
function debug_ip(){
	var lv2 = document.getElementById('cbid.logview.2.conf');
	lv2.style.display="inline"
	XHR.get('<%=url([[admin]], [[services]], [[autoipsetadder]], [[debugip]])%>',null,function(x, data){
	var lv2 = document.getElementById('cbid.logview.2.conf');
	lv2.innerHTML = x.responseText; 
	}
		);
	return
}
function poll_check(){
XHR.poll(3, '<%=url([[admin]], [[services]], [[autoipsetadder]], [[getlog]])%>', null,
	function(x, data) {
		var lv = document.getElementById('cbid.logview.1.conf');
		if (x.responseText && lv) {
			if (islogreverse){
				lv.innerHTML = x.responseText.split('\n').reverse().join('\n')+lv.innerHTML;
			}else{
				lv.innerHTML += x.responseText;
			}
		}
	}
);}
poll_check();

//]]>
</script>
<%end%>		
<%+cbi/valuefooter%>