From 75432f3cfd8d754e04c983664f20e8b981b301b2 Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Sat, 14 Dec 2019 17:48:24 +0800 Subject: [PATCH] luci-app-onliner: add package --- README.md | 3 +- package/ctcgfw/luci-app-onliner/Makefile | 32 + .../luasrc/controller/onliner.lua | 17 + .../luasrc/view/onliner/display.htm | 905 ++++++++++++++++++ .../luasrc/view/onliner/onliner.htm | 99 ++ .../luci-app-onliner/po/zh-cn/onliner.po | 11 + .../root/usr/share/onliner/setnlbw.sh | 20 + 7 files changed, 1086 insertions(+), 1 deletion(-) create mode 100644 package/ctcgfw/luci-app-onliner/Makefile create mode 100644 package/ctcgfw/luci-app-onliner/luasrc/controller/onliner.lua create mode 100644 package/ctcgfw/luci-app-onliner/luasrc/view/onliner/display.htm create mode 100644 package/ctcgfw/luci-app-onliner/luasrc/view/onliner/onliner.htm create mode 100644 package/ctcgfw/luci-app-onliner/po/zh-cn/onliner.po create mode 100755 package/ctcgfw/luci-app-onliner/root/usr/share/onliner/setnlbw.sh diff --git a/README.md b/README.md index 5e40f2d845..c975394af7 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,8 @@ luci-theme-darkmatter source: [apollo-ng/luci-theme-darkmatter](https://github.c luci-app-koolproxyR source: [Ameykyl/luci-app-koolproxyR](https://github.com/Ameykyl/luci-app-koolproxyR).
openwrt-chinadns-ng source: [pexcn/openwrt-chinadns-ng](https://github.com/pexcn/openwrt-chinadns-ng).
luci-app-ssr-plus-jo source: [brokeld/luci-app-ssr-plus-jo](https://github.com/brokeld/luci-app-ssr-plus-jo).
-openwrt-udpspeeder source: [pexcn/openwrt-udpspeeder](https://github.com/pexcn/openwrt-udpspeeder). +openwrt-udpspeeder source: [pexcn/openwrt-udpspeeder](https://github.com/pexcn/openwrt-udpspeeder).
+luci-app-onliner source: [rufengsuixing/luci-app-onliner](https://github.com/rufengsuixing/luci-app-onliner). # License ### [GPL v3](https://www.gnu.org/licenses/gpl-3.0.html). diff --git a/package/ctcgfw/luci-app-onliner/Makefile b/package/ctcgfw/luci-app-onliner/Makefile new file mode 100644 index 0000000000..f12e2ffc25 --- /dev/null +++ b/package/ctcgfw/luci-app-onliner/Makefile @@ -0,0 +1,32 @@ +# Copyright (C) 2016 Openwrt.org +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI support arp online +LUCI_DEPENDS:=+luci-app-nlbwmon +LUCI_PKGARCH:=all +PKG_NAME:=luci-app-onliner +PKG_VERSION:=1.1 +PKG_RELEASE:=3 + +define Package/luci-app-onliner/install + $(INSTALL_DIR) $(1)/usr/lib/lua/luci + cp -pR ./luasrc/* $(1)/usr/lib/lua/luci + $(INSTALL_DIR) $(1)/ + cp -pR ./root/* $(1)/ +endef + +define Package/luci-app-onliner/postinst +#!/bin/sh + rm -f /tmp/luci-indexcache + rm -f /tmp/luci-modulecache/* + chmod -R 755 /usr/share/onliner/* +exit 0 +endef +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature + diff --git a/package/ctcgfw/luci-app-onliner/luasrc/controller/onliner.lua b/package/ctcgfw/luci-app-onliner/luasrc/controller/onliner.lua new file mode 100644 index 0000000000..79f5f6f50f --- /dev/null +++ b/package/ctcgfw/luci-app-onliner/luasrc/controller/onliner.lua @@ -0,0 +1,17 @@ +module("luci.controller.onliner",package.seeall) +nixio=require"nixio" +function index() +entry({"admin","status","onliner"},alias("admin","status","onliner","onliner"),_("Connection info")) +entry({"admin","status","onliner","onliner"},template("onliner/onliner"),_("Online User"),1) +entry({"admin", "status","onliner","speed"}, template("onliner/display"), _("Speed monitor"), 2) +entry({"admin", "status","onliner","setnlbw"}, call("set_nlbw")) +end +function set_nlbw() + if nixio.fs.access("/var/run/onsetnlbw") then + nixio.fs.writefile("/var/run/onsetnlbw","1"); + else + io.popen("/usr/share/onliner/setnlbw.sh &") + end + luci.http.prepare_content("application/json") + luci.http.write('') +end diff --git a/package/ctcgfw/luci-app-onliner/luasrc/view/onliner/display.htm b/package/ctcgfw/luci-app-onliner/luasrc/view/onliner/display.htm new file mode 100644 index 0000000000..0964ccb2a8 --- /dev/null +++ b/package/ctcgfw/luci-app-onliner/luasrc/view/onliner/display.htm @@ -0,0 +1,905 @@ +<%# + Copyright 2017 Jo-Philipp Wich + Licensed to the public under the Apache License 2.0. +-%> + +<% css = [[ + + #chartjs-tooltip { + opacity: 0; + position: absolute; + background: rgba(0, 0, 0, .7); + color: white; + padding: 3px; + border-radius: 3px; + -webkit-transition: all .1s ease; + transition: all .1s ease; + pointer-events: none; + -webkit-transform: translate(-50%, 0); + transform: translate(-50%, 0); + z-index: 200; + } + + #chartjs-tooltip.above { + -webkit-transform: translate(-50%, -100%); + transform: translate(-50%, -100%); + } + + #chartjs-tooltip.above:before { + border: solid; + border-color: #111 transparent; + border-color: rgba(0, 0, 0, .8) transparent; + border-width: 8px 8px 0 8px; + bottom: 1em; + content: ""; + display: block; + left: 50%; + top: 100%; + position: absolute; + z-index: 99; + -webkit-transform: translate(-50%, 0); + transform: translate(-50%, 0); + } + + table { + border: 1px solid #999; + border-collapse: collapse; + margin: 0 0 2px !important; + } + + th, td, table table td { + border: 1px solid #999; + text-align: right; + padding: 1px 3px !important; + white-space: nowrap; + } + + tbody td { + border-bottom-color: #ccc; + } + + tbody td[rowspan] { + border-bottom-color: #999; + } + + tbody tr:last-child td { + border-bottom-color: #999; + } + + .kpi { + display: inline-block; + vertical-align: top; + } + + .kpi ul { + list-style: none; + } + + .kpi li { + margin: 10px; + display: none; + } + + .kpi big { + font-weight: bold; + } + + #detail-bubble { + position: absolute; + opacity: 0; + visibility: hidden; + } + + #detail-bubble.in { + opacity: 1; + visibility: visible; + transition: opacity 0.5s; + } + + #detail-bubble > div { + border: 1px solid #ccc; + border-radius: 2px; + padding: 5px; + background: #fcfcfc; + } + + #detail-bubble .head { + text-align: center; + white-space: nowrap; + position: relative; + } + + #detail-bubble .head .dismiss { + top: 0; + right: 0; + width: 20px; + line-height: 20px; + text-align: center; + text-decoration: none; + font-weight: bold; + color: #000; + position: absolute; + font-size: 20px; + } + #detail-bubble .kpi { + margin: 40px 5px 5px; + font-size: smaller; + text-align: left; + } + + #detail-bubble .kpi ul { + margin: 0; + } + + #bubble-arrow { + border: 1px solid #ccc; + border-width: 1px 0 0 1px; + background: #fcfcfc; + width: 15px; + height: 15px; + position: absolute; + left: 0; + top: -8px; + transform: rotate(45deg); + margin: 0 0 0 -8px; + } + + tr.active > td { + border-bottom: 2px solid red; + } + + tr.active > td.active { + border: 2px solid red; + border-bottom: none; + } + + td.detail { + border: 2px solid red; + border-top: none; + opacity: 0; + transition: opacity 0.5s; + } + + td.detail.in { + opacity: 1; + } + + th.hostname, + td.hostname { + text-align: left; + } + +]] -%> + +<%+header%> + + + + + +

<%:Netlink Bandwidth Monitor%>

+ +
+ +
+
+ × +
+
    +
  • <%_Hostname: example.org%>
  • +
  • <%_Vendor: Example Corp.%>
  • +
+
+
+
+
+
+ + + +
+
+
+
    +
  • <%_0 hosts%>
  • +
  • <%_0 download%>
  • +
  • <%_0 upload%>
  • +
  • <%_0 connections%>
  • +
+
+
+ + + + + + + + +
<%:Host%><%:MAC%><%:Connections%><%:Download (Bytes / Packets)%><%:Upload (Bytes / Packets)%>
+
+ + + + + + + +<%+footer%> diff --git a/package/ctcgfw/luci-app-onliner/luasrc/view/onliner/onliner.htm b/package/ctcgfw/luci-app-onliner/luasrc/view/onliner/onliner.htm new file mode 100644 index 0000000000..f424874b4e --- /dev/null +++ b/package/ctcgfw/luci-app-onliner/luasrc/view/onliner/onliner.htm @@ -0,0 +1,99 @@ +<%# + Copyright 2008 Steven Barth + Copyright 2008-2011 Jo-Philipp Wich + Licensed to the public under the Apache License 2.0. +-%> + +<% +local util = require "luci.util" +local function online_data() + local rv = { } + local fd = util.execi("/usr/bin/awk 'NR==FNR{a[$2]=$4}NR!=FNR&&!a[$4]{a[$4]=\"\?\"}NR!=FNR&&/0x[26]/{print a[$4],$1,$4,$6}' /tmp/dhcp.leases /proc/net/arp") + while true do + local ln = fd() + if ln == nil then break end + local name,ip,mac,dev = ln:match("^(%S+) (%S+) (%S+) (%S+)") + if mac and ip and name and dev then + rv[#rv+1] = { + hostname = name, + device = dev, + macaddr = mac, + ipaddr = ip + } + end + end + return rv +end + + +if luci.http.formvalue("status") == "1" then + local rv = { + onlines = online_data() + } + luci.http.prepare_content("application/json") + luci.http.write_json(rv) + return +end +-%> + +<%+header%> + + + + +

<%:Status%>

+ +
+ <%:user online%> + + + + + + + + + + + +
<%:Hostname%><%:IPv4-Address%><%:MAC-Address%><%:Interface%>

<%:Collecting data...%>
+
+ +<%+footer%> \ No newline at end of file diff --git a/package/ctcgfw/luci-app-onliner/po/zh-cn/onliner.po b/package/ctcgfw/luci-app-onliner/po/zh-cn/onliner.po new file mode 100644 index 0000000000..f38ef9f7ba --- /dev/null +++ b/package/ctcgfw/luci-app-onliner/po/zh-cn/onliner.po @@ -0,0 +1,11 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8\n" + +msgid "Connection info" +msgstr "连接信息" + +msgid "Online User" +msgstr "在线用户" + +msgid "Speed monitor" +msgstr "宽带监视" diff --git a/package/ctcgfw/luci-app-onliner/root/usr/share/onliner/setnlbw.sh b/package/ctcgfw/luci-app-onliner/root/usr/share/onliner/setnlbw.sh new file mode 100755 index 0000000000..8c10303593 --- /dev/null +++ b/package/ctcgfw/luci-app-onliner/root/usr/share/onliner/setnlbw.sh @@ -0,0 +1,20 @@ +#!/bin/sh +PATH="/usr/sbin:/usr/bin:/sbin:/bin" +echo "1">/var/run/onsetnlbw +interval=$(uci get nlbwmon.@nlbwmon[0].refresh_interval) +uci set nlbwmon.@nlbwmon[0].refresh_interval=2 +/etc/init.d/nlbwmon reload +while true +do + sleep 12 + watchdog=$(cat /var/run/onsetnlbw) + if [ "$watchdog"x == "0"x ]; then + uci set nlbwmon.@nlbwmon[0].refresh_interval=$interval + uci commit nlbwmon + /etc/init.d/nlbwmon reload + rm -f /var/run/onsetnlbw + exit 0 + else + echo "0">/var/run/onsetnlbw + fi +done \ No newline at end of file