From: Steven Hessing Date: Fri, 22 Sep 2017 05:08:43 +0000 (-0700) Subject: luci-app-noddos: Noddos, device-aware cloud-powered firewall (new package) X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=3b23203ce95c48a08b417a303ee8c6dc47f6eb60;p=project%2Fluci.git luci-app-noddos: Noddos, device-aware cloud-powered firewall (new package) Signed-off-by: Steven Hessing --- 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..45c9ca8c1e --- /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 + %> +
HostnameIPv4MACManufacturerModelClass
<%=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 + %> +
HostnameIPv4MACManufacturerModelDhcpVendorDhcpHostname
<%=v.Hostname%><%=v.Ipv4Address%><%=v.MacAddress%><%=v.SsdpManufacturer%><%=v.SsdpModelName%><%=v.DhcpVendor1%><%=v.DhcpHostname%>
+
+
+ +
+ +<%+footer%> + 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