From 1ef780af198b81872717c37b879bb35ac43e2884 Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Tue, 5 Nov 2019 12:57:29 -0800 Subject: [PATCH] luci-app-nextdns: add luci integration for nextdns package Signed-off-by: Olivier Poitrey --- applications/luci-app-nextdns/Makefile | 12 +++ .../luasrc/controller/nextdns.lua | 32 +++++++ .../luasrc/model/cbi/overview.lua | 41 +++++++++ .../luasrc/view/nextdns/logread.htm | 46 ++++++++++ .../luci-app-nextdns/po/templates/nextdns.pot | 84 +++++++++++++++++++ .../root/etc/uci-defaults/60_luci-nextdns | 11 +++ 6 files changed, 226 insertions(+) create mode 100644 applications/luci-app-nextdns/Makefile create mode 100644 applications/luci-app-nextdns/luasrc/controller/nextdns.lua create mode 100644 applications/luci-app-nextdns/luasrc/model/cbi/overview.lua create mode 100644 applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm create mode 100644 applications/luci-app-nextdns/po/templates/nextdns.pot create mode 100755 applications/luci-app-nextdns/root/etc/uci-defaults/60_luci-nextdns diff --git a/applications/luci-app-nextdns/Makefile b/applications/luci-app-nextdns/Makefile new file mode 100644 index 0000000000..263b66e6a6 --- /dev/null +++ b/applications/luci-app-nextdns/Makefile @@ -0,0 +1,12 @@ +# Copyright 2019 Olivier Poitrey (rs@nextdns.io) +# This is free software, licensed under the Apache License, Version 2.0 + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI support for NextDNS +LUCI_DEPENDS:=+luci-compat +nextdns +LUCI_PKGARCH:=all + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/applications/luci-app-nextdns/luasrc/controller/nextdns.lua b/applications/luci-app-nextdns/luasrc/controller/nextdns.lua new file mode 100644 index 0000000000..0552981938 --- /dev/null +++ b/applications/luci-app-nextdns/luasrc/controller/nextdns.lua @@ -0,0 +1,32 @@ +-- Copyright 2019 Olivier Poitrey (rs@nextdns.io) +-- This is free software, licensed under the Apache License, Version 2.0 + +module("luci.controller.nextdns", package.seeall) + +local util = require("luci.util") +local i18n = require("luci.i18n") +local templ = require("luci.template") +local http = require("luci.http") + +function index() + if not nixio.fs.access("/etc/config/nextdns") then + return + end + + entry({"admin", "services", "nextdns"}, firstchild(), _("NextDNS"), 60).dependent = false + entry({"admin", "services", "nextdns", "overview"}, cbi("overview", {hideresetbtn=true, hidesavebtn=true}), _("Overview"), 10).leaf = true + entry({"admin", "services", "nextdns", "log"}, template("nextdns/logread"), _("Logs"), 30).leaf = true + + entry({"admin", "services", "nextdns", "logread"}, call("logread"), nil).leaf = true + +end + +function logread() + local content = util.trim(util.exec("logread -e 'nextdns'")) or "" + + if content == "" then + content = "No nextdns related logs yet!" + end + http.write(content) +end + diff --git a/applications/luci-app-nextdns/luasrc/model/cbi/overview.lua b/applications/luci-app-nextdns/luasrc/model/cbi/overview.lua new file mode 100644 index 0000000000..a932a85f89 --- /dev/null +++ b/applications/luci-app-nextdns/luasrc/model/cbi/overview.lua @@ -0,0 +1,41 @@ +local uci = require("luci.model.uci").cursor() + +nextdns = Map("nextdns", translate("NextDNS"), + translate("NextDNS Configuration.") + .. "
" + .. translatef("For further information, go to " + .. "nextdns.io")) + + +function nextdns.on_after_commit(self) + luci.sys.call("env -i /etc/init.d/nextdns restart >/dev/null 2>&1") +end + +s = nextdns:section(TypedSection, "nextdns", translate("General")) +s.anonymous = true + +enabled = s:option(Flag, "enabled", translate("Enabled"), + translate("Enable NextDNS.")) +enabled.rmempty = false + +conf = s:option(Value, "config", translate("Configuration ID"), + translate("The ID of your NextDNS configuration.") + .. "
" + .. translate("Go to nextdns.io to create a configuration.")) +conf.rmempty = false + +report_client_info = s:option(Flag, "report_client_info", translate("Report Client Info"), + translate("Expose LAN clients information in NextDNS analytics.")) +report_client_info.rmempty = false + +hardened_privacy = s:option(Flag, "hardened_privacy", translate("Hardened Privacy"), + translate("When enabled, use DNS servers located in jurisdictions with strong privacy laws.") + .. "
" + .. translate("Available locations are: Switzerland, Iceland, Finland, Panama and Hong Kong.")) +hardened_privacy.rmempty = false + +log_query = s:option(Flag, "log_query", translate("Log Queries"), + translate("Log individual queries to system log.")) +log_query.rmempty = false + +return nextdns diff --git a/applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm b/applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm new file mode 100644 index 0000000000..0a98b2704f --- /dev/null +++ b/applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm @@ -0,0 +1,46 @@ +<%+header%> + + + + + +
+
+
<%:The syslog output, pre-filtered for nextdns related messages only.%>
+ +
+
+ +<%+footer%> diff --git a/applications/luci-app-nextdns/po/templates/nextdns.pot b/applications/luci-app-nextdns/po/templates/nextdns.pot new file mode 100644 index 0000000000..6f943818b5 --- /dev/null +++ b/applications/luci-app-nextdns/po/templates/nextdns.pot @@ -0,0 +1,84 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:34 +msgid "" +"Available locations are: Switzerland, Iceland, Finland, Panama and Hong Kong." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:21 +msgid "Configuration ID" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:18 +msgid "Enable NextDNS." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:17 +msgid "Enabled" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:28 +msgid "Expose LAN clients information in NextDNS analytics." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:6 +msgid "" +"For further information, go to nextdns.io" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:14 +msgid "General" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:24 +msgid "Go to nextdns.io to create a configuration." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:31 +msgid "Hardened Privacy" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:37 +msgid "Log Queries" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:38 +msgid "Log individual queries to system log." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:18 +msgid "Logs" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:16 +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:3 +msgid "NextDNS" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:4 +msgid "NextDNS Configuration." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:17 +msgid "Overview" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:27 +msgid "Report Client Info" +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:22 +msgid "The ID of your NextDNS configuration." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm:41 +msgid "The syslog output, pre-filtered for nextdns related messages only." +msgstr "" + +#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:32 +msgid "" +"When enabled, use DNS servers located in jurisdictions with strong privacy " +"laws." +msgstr "" diff --git a/applications/luci-app-nextdns/root/etc/uci-defaults/60_luci-nextdns b/applications/luci-app-nextdns/root/etc/uci-defaults/60_luci-nextdns new file mode 100755 index 0000000000..95fc92280e --- /dev/null +++ b/applications/luci-app-nextdns/root/etc/uci-defaults/60_luci-nextdns @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@nextdns[-1] + add ucitrack nextdns + set ucitrack.@nextdns[-1].init=nextdns + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 -- 2.30.2