Răsfoiți Sursa

Reverse log (#11)

* reverse log added

* more data once
rufengsuixing 5 ani în urmă
părinte
comite
0f05e921be

+ 1 - 1
Makefile

@@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=luci-app-adguardhome
 PKG_VERSION:=1.7
-PKG_RELEASE:=8
+PKG_RELEASE:=9
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 

+ 42 - 11
luasrc/controller/AdGuardHome.lua

@@ -11,22 +11,53 @@ entry({"admin", "services", "AdGuardHome"},
     entry({"admin","services","AdGuardHome","status"},call("act_status")).leaf=true
 	entry({"admin", "services", "AdGuardHome", "check"}, call("check_update"))
 	entry({"admin", "services", "AdGuardHome", "doupdate"}, call("do_update"))
+	entry({"admin", "services", "AdGuardHome", "getlog"}, call("get_log"))
+	entry({"admin", "services", "AdGuardHome", "dodellog"}, call("do_dellog"))
 end 
 
 function act_status()
-  local e={}
-  binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
-  e.running=luci.sys.call("pgrep "..binpath.." >/dev/null")==0
-  luci.http.prepare_content("application/json")
-  luci.http.write_json(e)
+	local e={}
+	binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
+	e.running=luci.sys.call("pgrep "..binpath.." >/dev/null")==0
+	luci.http.prepare_content("application/json")
+	luci.http.write_json(e)
 end
 function do_update()
-nixio.fs.writefile("/var/run/lucilogpos","0")
-luci.sys.exec("(touch /var/run/update_core ; sh /usr/share/AdGuardHome/update_core.sh >/tmp/AdGuardHome_update.log;rm /var/run/update_core) &")
-luci.http.prepare_content("application/json")
-luci.http.write('')
+	nixio.fs.writefile("/var/run/lucilogpos","0")
+	luci.sys.exec("(touch /var/run/update_core ; sh /usr/share/AdGuardHome/update_core.sh >/tmp/AdGuardHome_update.log;rm /var/run/update_core) &")
+	luci.http.prepare_content("application/json")
+	luci.http.write('')
+end
+function get_log()
+	logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
+	if (logfile==nil) then
+	luci.http.write("no log available\n")
+	return
+	end
+	luci.http.prepare_content("text/plain; charset=utf-8")
+	logpos=nixio.fs.readfile("/var/run/lucilogpos")
+	if (logpos ~= nil) then
+	fdp=tonumber(logpos)
+	else
+	fdp=0
+	end
+	f=io.open(logfile, "r+")
+	f:seek("set",fdp)
+	a=f:read(2048000)
+	if (a==nil) then
+	a=""
+	end
+	fdp=f:seek()
+	nixio.fs.writefile("/var/run/lucilogpos",tostring(fdp))
+	f:close()
+	luci.http.write(a)
+end
+function do_dellog()
+	logfile=uci:get("AdGuardHome","AdGuardHome","logfile")
+	nixio.fs.writefile(logfile,"")
+	luci.http.prepare_content("application/json")
+	luci.http.write('')
 end
-
 function check_update()
 	luci.http.prepare_content("text/plain; charset=utf-8")
 	logpos=nixio.fs.readfile("/var/run/lucilogpos")
@@ -37,7 +68,7 @@ function check_update()
 	end
 	f=io.open("/tmp/AdGuardHome_update.log", "r+")
 	f:seek("set",fdp)
-	a=f:read(8192)
+	a=f:read(2048000)
 	if (a==nil) then
 	a=""
 	end

+ 2 - 6
luasrc/model/cbi/AdGuardHome/log.lua

@@ -6,11 +6,7 @@ f=SimpleForm("logview")
 t=f:field(TextValue,"conf")
 t.rmempty=true
 t.rows=20
-function t.cfgvalue()
-if (logfile==nil) then
-	return "no log available"
-end
-return e.readfile(logfile)
-end
+t.template="AdGuardHome/log"
 t.readonly="readonly"
+nixio.fs.writefile("/var/run/lucilogpos","0")
 return f

+ 46 - 0
luasrc/view/AdGuardHome/log.htm

@@ -0,0 +1,46 @@
+<%+cbi/valueheader%>
+<%uci=require"luci.model.uci".cursor()%>
+<%nixio=require"nixio"%>
+
+<input type="checkbox" name="NAME" value="reverse" onclick=" return reverselog()" style="vertical-align:middle;" checked>reverse</input><br>
+<textarea id="cbid.logview.1.conf" class="cbi-input-textarea" style="width: 100%;display:inline" data-update="change" name="vbid.logview.1.conf" rows="32" cols="60" readonly="readonly" > </textarea>
+<input class="cbi-button cbi-button-apply" name="apply_update_button" id="apply_update_button" value="dellog" onclick=" return apply_del_log() "/>
+
+<script type="text/javascript">//<![CDATA[
+var islogreverse = true;
+function apply_del_log(){
+	XHR.get('<%=url([[admin]], [[services]], [[AdGuardHome]], [[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 poll_check(){
+XHR.poll(3, '<%=url([[admin]], [[services]], [[AdGuardHome]], [[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>
+		
+<%+cbi/valuefooter%>