From d685c2392f2a1ecd7cf13630add83c9bb64308ba Mon Sep 17 00:00:00 2001 From: Hannu Nyman Date: Wed, 11 Oct 2017 16:35:56 +0300 Subject: [PATCH] luci-app-noddos: backport from master Signed-off-by: Steven Hessing --- applications/luci-app-noddos/Makefile | 18 +++ .../htdocs/cgi-bin/clientdetails | 91 ++++++++++++++ .../luasrc/controller/noddos.lua | 10 ++ .../luasrc/model/cbi/noddos.lua | 46 ++++++++ .../luasrc/view/noddos/clients.htm | 111 ++++++++++++++++++ applications/luci-app-noddos/po/ja/noddos.po | 111 ++++++++++++++++++ .../luci-app-noddos/po/templates/noddos.pot | 92 +++++++++++++++ .../root/etc/uci-defaults/40_luci-noddos | 14 +++ 8 files changed, 493 insertions(+) create mode 100644 applications/luci-app-noddos/Makefile create mode 100755 applications/luci-app-noddos/htdocs/cgi-bin/clientdetails create mode 100644 applications/luci-app-noddos/luasrc/controller/noddos.lua create mode 100644 applications/luci-app-noddos/luasrc/model/cbi/noddos.lua create mode 100644 applications/luci-app-noddos/luasrc/view/noddos/clients.htm create mode 100644 applications/luci-app-noddos/po/ja/noddos.po create mode 100644 applications/luci-app-noddos/po/templates/noddos.pot create mode 100644 applications/luci-app-noddos/root/etc/uci-defaults/40_luci-noddos diff --git a/applications/luci-app-noddos/Makefile b/applications/luci-app-noddos/Makefile new file mode 100644 index 0000000000..4c2b9044a9 --- /dev/null +++ b/applications/luci-app-noddos/Makefile @@ -0,0 +1,18 @@ +# Copyright (C) 2017 Steven Hessing (steven.hessing@gmail.com) +# Based on initial implementation by Stan Grishin (stangri@melmac.net) +# This is free software, licensed under the GNU General Public License v3. + +include $(TOPDIR)/rules.mk + +PKG_LICENSE:=GPLv3 +PKG_MAINTAINER:=Steven Hessing + +LUCI_TITLE:=Noddos Service Web UI +LUCI_DESCRIPTION:=Provides Web UI for Noddos service. +LUCI_DEPENDS:=+luci +noddos +LUCI_PKGARCH:=all +PKG_RELEASE:=1 + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/applications/luci-app-noddos/htdocs/cgi-bin/clientdetails b/applications/luci-app-noddos/htdocs/cgi-bin/clientdetails new file mode 100755 index 0000000000..6ff4ce59f2 --- /dev/null +++ b/applications/luci-app-noddos/htdocs/cgi-bin/clientdetails @@ -0,0 +1,91 @@ +#!/usr/bin/lua + +-- clientdetails.lua : Provides details about client devices discovered by Noddos +-- Copyright (C) 2017 Steven Hessing (steven.hessing@gmail.com) +-- This is free software, licensed under the GNU General Public License v3. + +require "nixio.fs" + +print ("Content-type: Text/html\n") +local info = os.getenv("QUERY_STRING") + +local params = {} +local echo = {} + +function print_row(key) + print ("") + print (key) + print ("") + print (device[key]) + print ("") +end + +for name, value in string.gmatch(info .. '&', '(.-)%=(.-)%&') do + value = string.gsub(value , '%+', ' ') + value = string.gsub(value , '%%(%x%x)', function(dpc) + return string.char(tonumber(dpc,16)) + end ) + params[name] = value + + value = string.gsub(value, "%&", "&") + value = string.gsub(value, "%<", "<") + value = string.gsub(value, '%"', """) + echo[name] = value +end + +device = {} +profile = {} + +if nixio.fs.access("/var/lib/noddos/DeviceDump.json") then + io.input("/var/lib/noddos/DeviceDump.json") + local t = io.read("*all") + local json = require "luci.jsonc" + local devdump = json.parse(t) + for i, v in ipairs(devdump) do + if v.MacAddress == params["mac"] then + device = v + end + end + io.input("/var/lib/noddos/DeviceProfiles.json") + t = io.read("*all") + local temp = json.parse(t) + for i, v in ipairs(temp) do + if device.DeviceProfileUuid == v.DeviceProfileUuid then + profile = v + end + end +end +pagetop = [[ + + + Client Details by Noddos + + + + + + + + + +

Client Details

+]] +print (pagetop) + +if params["mac"] ~= nil then + print ("") + for i, key in ipairs{"MacAddress", "Ipv4Address", "Ipv6Address", "DeviceProfileUuid", "DhcpHostname", "DhcpVendor", "SsdpFriendlyName", "SsdpLocation", "SsdpManufacturer", "SsdpModelName", "SsdpModelUrl", "SsdpSerialNumber", "SsdpServer","SsdpUserAgent", "MdnsDeviceUrl", "MdnsHw", "MdnsManufacturer", "MdnsModelName", "MdnsOs", "WsDiscoveryTypes", "WsDiscoveryXaddrs", "DnsQueries"} do + print_row(key) + end + print ("
") +else + print ("no mac address specified") +end + +pagebase = [[

+Client Details by +Noddos + +]] + +print (pagebase) diff --git a/applications/luci-app-noddos/luasrc/controller/noddos.lua b/applications/luci-app-noddos/luasrc/controller/noddos.lua new file mode 100644 index 0000000000..c45e24bc97 --- /dev/null +++ b/applications/luci-app-noddos/luasrc/controller/noddos.lua @@ -0,0 +1,10 @@ +-- Copyright 2017 Steven Hessing (steven.hessing@gmail.com) +-- This is free software, licensed under the GNU General Public License v3. +-- /usr/lib/lua/luci/controller/noddos.lua + +module("luci.controller.noddos", package.seeall) +function index() + entry({"admin", "status", "noddos"}, template("noddos/clients"), _("Noddos Clients"), 3) + entry({"admin", "network", "noddos"}, cbi("noddos"), _("Noddos Client Tracking"), 55) +end + diff --git a/applications/luci-app-noddos/luasrc/model/cbi/noddos.lua b/applications/luci-app-noddos/luasrc/model/cbi/noddos.lua new file mode 100644 index 0000000000..3abb73bc66 --- /dev/null +++ b/applications/luci-app-noddos/luasrc/model/cbi/noddos.lua @@ -0,0 +1,46 @@ +-- Copyright 2017 Steven Hessing (steven.hessing@gmail.com) +-- This is free software, licensed under the GNU General Public License v3. +-- /usr/lib/lua/luci/model/cbi/noddos.lua + +m = Map("noddos", translate("Client Firewall"), + translate("Noddos controls traffic from the clients on your network to the Internet. " .. + "This helps protect your network, the bandwidth on your Internet connection and " .. + "the Internet")) + +s = m:section(TypedSection, "noddos", translate("Server Settings")) +s.anonymous = true +s.addremove = false + +s:option(Flag, "rfc1918", + translate("Private networks"), + translate("Report traffic to private networks (10/8, 172.16/12, 192.168/16, fd75:6b5d:352c:ed05::/64)")).default=false + +s:option(Flag, "upload", + translate("Upload anonimized traffic stats"), + translate("Uploading your statistics helps improving device recognition " .. + "and discovering hacked devices & botnets")) + +o = s:option(DynamicList, "whitelistipv4", + translate("Excluded IPv4 addresses"), + translate("Don't monitor these IPv4 addresses")) +o.optional = true +o.placeholder = "127.0.0.1 192.168.1.1" +o.delimiter = " " +o.datatype="list(ip4addr)" + +o = s:option(DynamicList, "whitelistipv6", + translate("Excluded IPv6 addresses"), + translate("Don't monitor these IPv6 addresses")) +o.optional = true +o.delimiter = " " +o.datatype="list(ip6addr)" + +o = s:option(DynamicList, "whitelistmac", + translate("Excluded MAC addresses"), + translate("Don't monitor these MAC addresses")) +o.optional = true +o.delimiter = " " +o.datatype="list(macaddr)" + +return m + diff --git a/applications/luci-app-noddos/luasrc/view/noddos/clients.htm b/applications/luci-app-noddos/luasrc/view/noddos/clients.htm new file mode 100644 index 0000000000..f2fb9312a7 --- /dev/null +++ b/applications/luci-app-noddos/luasrc/view/noddos/clients.htm @@ -0,0 +1,111 @@ +<%# + Copyright (C) 2017 Steven Hessing + This is free software, licensed under the GNU General Public License v3. + /usr/lib/lua/luci/view/clients.htm +-%> + +<%- + + require "nixio.fs" + require "os" + + local last_modified = "" + local style = true + local v + local devdump + + if nixio.fs.access("/var/lib/noddos/DeviceDump.json") then + last_modified = os.date("%c", nixio.fs.stat("/var/lib/noddos/DeviceDump.json")['mtime']) + io.input("/var/lib/noddos/DeviceDump.json") + t = io.read("*all") + devdump = luci.jsonc.parse(t) + io.input("/var/lib/noddos/DeviceProfiles.json") + t = io.read("*all") + temp = luci.jsonc.parse(t) + devicevalues = {} + for i, v in ipairs(temp) do + devicevalues[v.DeviceProfileUuid] = v + end + end +-%> + +<%+header%> + +
+

<%:Clients%>

+
<%:The following clients have been discovered on the network. The last discovery was completed at %><%=last_modified%>
+ +
+ <%:Recognized Clients%> +
+ + + + + + + + + + + <% + for i,v in ipairs(devdump) do + if v.DeviceProfileUuid ~= "" then + %> + + + + + + + + + <% + style=false + end + end + %> +
<%:Hostname%><%:IPv4%><%:MAC%><%:Manufacturer%><%:Model%><%:Class%>
<%=v.Hostname%><%=v.Ipv4Address%><%=v.MacAddress%><%=devicevalues[v.DeviceProfileUuid].Manufacturer%><%=devicevalues[v.DeviceProfileUuid].Model%><%=devicevalues[v.DeviceProfileUuid].ThingClass%>
+
+
+
+
+ <%:Unrecognized Clients%> +
+ + + + + + + + + + + + <% + for i,v in ipairs(devdump) do + if v.DeviceProfileUuid == "" then + %> + + + + + + + + + + <% + style=false + end + end + %> +
<%:Hostname%><%:IPv4%><%:MAC%><%:Manufacturer%><%:Model%><%:DhcpVendor%><%:DhcpHostname%>
<%=v.Hostname%><%=v.Ipv4Address%><%=v.MacAddress%><%=v.SsdpManufacturer%><%=v.SsdpModelName%><%=v.DhcpVendor1%><%=v.DhcpHostname%>
+
+
+ +
+ +<%+footer%> + diff --git a/applications/luci-app-noddos/po/ja/noddos.po b/applications/luci-app-noddos/po/ja/noddos.po new file mode 100644 index 0000000000..c6b461747f --- /dev/null +++ b/applications/luci-app-noddos/po/ja/noddos.po @@ -0,0 +1,111 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Project-Id-Version: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.4\n" +"Last-Translator: INAGAKI Hiroshi \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"Language: ja\n" + +msgid "Class" +msgstr "クラス" + +msgid "Client Firewall" +msgstr "クライアント ファイアウォール" + +msgid "Clients" +msgstr "クライアント" + +msgid "DhcpHostname" +msgstr "DHCP ホスト名" + +msgid "DhcpVendor" +msgstr "DHCP ベンダー" + +msgid "Don't monitor these IPv4 addresses" +msgstr "これらの IPv4 アドレスを監視しません。" + +msgid "Don't monitor these IPv6 addresses" +msgstr "これらの IPv6 アドレスを監視しません。" + +msgid "Don't monitor these MAC addresses" +msgstr "これらの MAC アドレスを監視しません。" + +msgid "Excluded IPv4 addresses" +msgstr "除外する IPv4 アドレス" + +msgid "Excluded IPv6 addresses" +msgstr "除外する IPv6 アドレス" + +msgid "Excluded MAC addresses" +msgstr "除外する MAC アドレス" + +msgid "Hostname" +msgstr "ホスト名" + +msgid "IPv4" +msgstr "IPv4" + +msgid "MAC" +msgstr "MAC" + +msgid "Manufacturer" +msgstr "製造元" + +msgid "Model" +msgstr "モデル" + +msgid "Noddos Client Tracking" +msgstr "Noddos クライアント トラッキング" + +msgid "Noddos Clients" +msgstr "Noddos クライアント" + +msgid "" +"Noddos controls traffic from the clients on your network to the Internet. " +"This helps protect your network, the bandwidth on your Internet connection " +"and the Internet" +msgstr "" +"Noddos は、ネットワーク内のクライアントからインターネットへのトラフィックを制" +"御します。これは、ネットワークとインターネット接続の帯域幅、インターネットの" +"保護に役立ちます。" + +msgid "Private networks" +msgstr "プライベート ネットワーク" + +msgid "Recognized Clients" +msgstr "識別済クライアント" + +msgid "" +"Report traffic to private networks (10/8, 172.16/12, 192.168/16, " +"fd75:6b5d:352c:ed05::/64)" +msgstr "" +"プライベート ネットワークへのトラフィックについてのレポート(10/8, " +"172.16/12, 192.168/16, fd75:6b5d:352c:ed05::/64)" + +msgid "Server Settings" +msgstr "サーバー設定" + +msgid "" +"The following clients have been discovered on the network. The last " +"discovery was completed at" +msgstr "" +"以下のクライアントがネットワーク内で見つかりました。探索の最終実行日時:" + +msgid "Unrecognized Clients" +msgstr "未識別クライアント" + +msgid "Upload anonimized traffic stats" +msgstr "匿名トラフィック状況のアップロード" + +msgid "" +"Uploading your statistics helps improving device recognition and discovering " +"hacked devices & botnets" +msgstr "" +"デバイスの識別や、ハックされたデバイスとボットネットの発見の改善に役立てるた" +"め、統計をアップロードします。" diff --git a/applications/luci-app-noddos/po/templates/noddos.pot b/applications/luci-app-noddos/po/templates/noddos.pot new file mode 100644 index 0000000000..69d135770b --- /dev/null +++ b/applications/luci-app-noddos/po/templates/noddos.pot @@ -0,0 +1,92 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +msgid "Class" +msgstr "" + +msgid "Client Firewall" +msgstr "" + +msgid "Clients" +msgstr "" + +msgid "DhcpHostname" +msgstr "" + +msgid "DhcpVendor" +msgstr "" + +msgid "Don't monitor these IPv4 addresses" +msgstr "" + +msgid "Don't monitor these IPv6 addresses" +msgstr "" + +msgid "Don't monitor these MAC addresses" +msgstr "" + +msgid "Excluded IPv4 addresses" +msgstr "" + +msgid "Excluded IPv6 addresses" +msgstr "" + +msgid "Excluded MAC addresses" +msgstr "" + +msgid "Hostname" +msgstr "" + +msgid "IPv4" +msgstr "" + +msgid "MAC" +msgstr "" + +msgid "Manufacturer" +msgstr "" + +msgid "Model" +msgstr "" + +msgid "Noddos Client Tracking" +msgstr "" + +msgid "Noddos Clients" +msgstr "" + +msgid "" +"Noddos controls traffic from the clients on your network to the Internet. " +"This helps protect your network, the bandwidth on your Internet connection " +"and the Internet" +msgstr "" + +msgid "Private networks" +msgstr "" + +msgid "Recognized Clients" +msgstr "" + +msgid "" +"Report traffic to private networks (10/8, 172.16/12, 192.168/16, " +"fd75:6b5d:352c:ed05::/64)" +msgstr "" + +msgid "Server Settings" +msgstr "" + +msgid "" +"The following clients have been discovered on the network. The last " +"discovery was completed at" +msgstr "" + +msgid "Unrecognized Clients" +msgstr "" + +msgid "Upload anonimized traffic stats" +msgstr "" + +msgid "" +"Uploading your statistics helps improving device recognition and discovering " +"hacked devices & botnets" +msgstr "" diff --git a/applications/luci-app-noddos/root/etc/uci-defaults/40_luci-noddos b/applications/luci-app-noddos/root/etc/uci-defaults/40_luci-noddos new file mode 100644 index 0000000000..17abbc41ca --- /dev/null +++ b/applications/luci-app-noddos/root/etc/uci-defaults/40_luci-noddos @@ -0,0 +1,14 @@ +#!/bin/sh + +# Copyright (C) 2017 Steven Hessing (steven.hessing@live.com) +# This is free software, licensed under the GNU General Public License v3 + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@noddos[-1] + add ucitrack noddos + set ucitrack.@noddos[-1].init=noddos + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 -- 2.30.2