summaryrefslogtreecommitdiffhomepage
path: root/applications
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-11-19 12:04:07 +0100
committerGitHub <noreply@github.com>2019-11-19 12:04:07 +0100
commit15816e668df0bbdc36f6426557e488f6ade2e3ed (patch)
tree576b04d39c5381944dfeb1d75211f37da6e1535b /applications
parent8262e1272552db43cef527e5da88e6706d50e7a4 (diff)
parent29fdc2b014b05a4d6ae2324b36ea9ce1c956360b (diff)
Merge pull request #3328 from ysc3839/nextdns
luci-app-nextdns: port to client side
Diffstat (limited to 'applications')
-rw-r--r--applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/logread.js43
-rw-r--r--applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js44
-rw-r--r--applications/luci-app-nextdns/luasrc/controller/nextdns.lua22
-rw-r--r--applications/luci-app-nextdns/luasrc/model/cbi/overview.lua41
-rw-r--r--applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm46
-rw-r--r--applications/luci-app-nextdns/po/templates/nextdns.pot46
-rw-r--r--applications/luci-app-nextdns/root/usr/share/rpcd/acl.d/luci-app-nextdns.json10
7 files changed, 124 insertions, 128 deletions
diff --git a/applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/logread.js b/applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/logread.js
new file mode 100644
index 000000000..9b3c7bfc4
--- /dev/null
+++ b/applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/logread.js
@@ -0,0 +1,43 @@
+'use strict';
+'require fs';
+
+return L.view.extend({
+ render: function() {
+ L.Poll.add(function() {
+ return L.resolveDefault(fs.exec('/sbin/logread', ['-e', 'nextdns']), { code: 1 })
+ .then(function(res) {
+ var content;
+ if (res.code === 0)
+ content = res.stdout.trim();
+ if (!content)
+ content = _('No nextdns related logs yet!');
+ var view = document.getElementById("view_id");
+ view.value = content;
+ view.scrollTop = view.scrollHeight;
+ });
+ });
+ return E('div', { class: 'cbi-map' },
+ E('div', { class: 'cbi-section' }, [
+ E('div', { class: 'cbi-section-descr' },
+ _('The syslog output, pre-filtered for nextdns related messages only.')),
+ E('textarea', {
+ id: 'view_id',
+ readonly: 'readonly',
+ wrap: 'off',
+ style: 'width: 100% !important;\
+ height: 450px !important;\
+ border: 1px solid #cccccc;\
+ padding: 5px;\
+ font-size: 12px;\
+ font-family: monospace;\
+ resize: none;\
+ pointer-events: auto;\
+ cursor: auto;'
+ })
+ ])
+ );
+ },
+ handleSaveApply: null,
+ handleSave: null,
+ handleReset: null
+});
diff --git a/applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js b/applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js
new file mode 100644
index 000000000..2fd693f3e
--- /dev/null
+++ b/applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js
@@ -0,0 +1,44 @@
+'use strict';
+'require form';
+
+return L.view.extend({
+ render: function() {
+ var m, s, o;
+
+ m = new form.Map('nextdns', _('NextDNS'),
+ _('NextDNS Configuration.')
+ + '<br>'
+ + _('For further information, go to \
+ <a href="https://nextdns.io" target="_blank">nextdns.io</a>.'));
+
+ s = m.section(form.TypedSection, 'nextdns', _('General'));
+ s.anonymous = true;
+
+ o = s.option(form.Flag, 'enabled', _('Enabled'),
+ _('Enable NextDNS.'));
+ o.default = '1';
+ o.rmempty = false;
+
+ s.option(form.Value, 'config', _('Configuration ID'),
+ _('The ID of your NextDNS configuration.')
+ + '<br>'
+ + _('Go to nextdns.io to create a configuration.'));
+
+ o = s.option(form.Flag, 'report_client_info', _('Report Client Info'),
+ _('Expose LAN clients information in NextDNS analytics.'));
+ o.default = '1';
+ o.rmempty = false;
+
+ o = s.option(form.Flag, 'hardened_privacy', _('Hardened Privacy'),
+ _('When enabled, use DNS servers located in jurisdictions with strong privacy laws.')
+ + '<br>'
+ + _('Available locations are: Switzerland, Iceland, Finland, Panama and Hong Kong.'));
+ o.rmempty = false;
+
+ o = s.option(form.Flag, 'log_queries', _('Log Queries'),
+ _('Log individual queries to system log.'));
+ o.rmempty = false;
+
+ return m.render();
+ },
+});
diff --git a/applications/luci-app-nextdns/luasrc/controller/nextdns.lua b/applications/luci-app-nextdns/luasrc/controller/nextdns.lua
index 055298193..bfa4887b0 100644
--- a/applications/luci-app-nextdns/luasrc/controller/nextdns.lua
+++ b/applications/luci-app-nextdns/luasrc/controller/nextdns.lua
@@ -3,30 +3,12 @@
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)
+ entry({"admin", "services", "nextdns", "overview"}, view("nextdns/overview"), _("Overview"), 10).leaf = true
+ entry({"admin", "services", "nextdns", "log"}, view("nextdns/logread"), _("Logs"), 30).leaf = true
end
-
diff --git a/applications/luci-app-nextdns/luasrc/model/cbi/overview.lua b/applications/luci-app-nextdns/luasrc/model/cbi/overview.lua
deleted file mode 100644
index a932a85f8..000000000
--- a/applications/luci-app-nextdns/luasrc/model/cbi/overview.lua
+++ /dev/null
@@ -1,41 +0,0 @@
-local uci = require("luci.model.uci").cursor()
-
-nextdns = Map("nextdns", translate("NextDNS"),
- translate("NextDNS Configuration.")
- .. "<br>"
- .. translatef("For further information, go to "
- .. "<a href=\"https://nextdns.io\" target=\"_blank\">nextdns.io</a>"))
-
-
-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.")
- .. "<br>"
- .. 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.")
- .. "<br>"
- .. 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
deleted file mode 100644
index 0a98b2704..000000000
--- a/applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm
+++ /dev/null
@@ -1,46 +0,0 @@
-<%+header%>
-
-<style type="text/css">
- select[readonly],
- textarea[readonly]
- {
- width: 100% !important;
- height: 450px !important;
- border: 1px solid #cccccc;
- padding: 5px;
- font-size: 12px;
- font-family: monospace;
- resize: none;
- pointer-events: auto;
- cursor: auto;
- }
-</style>
-
-<script type="text/javascript">
-//<![CDATA[
- function log_update()
- {
- XHR.poll(-1, '<%=luci.dispatcher.build_url("admin", "services", "nextdns", "logread")%>', null,
- function(x)
- {
- if (!x)
- {
- return;
- }
- var view = document.getElementById("view_id");
- view.value = x.responseText;
- view.scrollTop = view.scrollHeight;
- });
- }
- window.onload = log_update();
-//]]>
-</script>
-
-<div class="cbi-map">
- <div class="cbi-section">
- <div class="cbi-section-descr"><%:The syslog output, pre-filtered for nextdns related messages only.%></div>
- <textarea id="view_id" readonly="readonly" wrap="off" value=""></textarea>
- </div>
-</div>
-
-<%+footer%>
diff --git a/applications/luci-app-nextdns/po/templates/nextdns.pot b/applications/luci-app-nextdns/po/templates/nextdns.pot
index 6f943818b..1b333a7a9 100644
--- a/applications/luci-app-nextdns/po/templates/nextdns.pot
+++ b/applications/luci-app-nextdns/po/templates/nextdns.pot
@@ -1,83 +1,87 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:34
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:35
msgid ""
"Available locations are: Switzerland, Iceland, Finland, Panama and Hong Kong."
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:21
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:22
msgid "Configuration ID"
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:18
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:18
msgid "Enable NextDNS."
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:17
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:17
msgid "Enabled"
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:28
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:28
msgid "Expose LAN clients information in NextDNS analytics."
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:6
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:11
msgid ""
"For further information, go to <a href=\"https://nextdns.io\" target=\"_blank"
-"\">nextdns.io</a>"
+"\">nextdns.io</a>."
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:14
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:14
msgid "General"
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:24
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:25
msgid "Go to nextdns.io to create a configuration."
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:31
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:32
msgid "Hardened Privacy"
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:37
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:38
msgid "Log Queries"
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:38
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:39
msgid "Log individual queries to system log."
msgstr ""
-#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:18
+#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:13
msgid "Logs"
msgstr ""
-#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:16
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:3
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:8
+#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:11
msgid "NextDNS"
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:4
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:9
msgid "NextDNS Configuration."
msgstr ""
-#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:17
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/logread.js:13
+msgid "No nextdns related logs yet!"
+msgstr ""
+
+#: applications/luci-app-nextdns/luasrc/controller/nextdns.lua:12
msgid "Overview"
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:27
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:27
msgid "Report Client Info"
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:22
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:23
msgid "The ID of your NextDNS configuration."
msgstr ""
-#: applications/luci-app-nextdns/luasrc/view/nextdns/logread.htm:41
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/logread.js:22
msgid "The syslog output, pre-filtered for nextdns related messages only."
msgstr ""
-#: applications/luci-app-nextdns/luasrc/model/cbi/overview.lua:32
+#: applications/luci-app-nextdns/htdocs/luci-static/resources/view/nextdns/overview.js:33
msgid ""
"When enabled, use DNS servers located in jurisdictions with strong privacy "
"laws."
diff --git a/applications/luci-app-nextdns/root/usr/share/rpcd/acl.d/luci-app-nextdns.json b/applications/luci-app-nextdns/root/usr/share/rpcd/acl.d/luci-app-nextdns.json
new file mode 100644
index 000000000..2e7a64654
--- /dev/null
+++ b/applications/luci-app-nextdns/root/usr/share/rpcd/acl.d/luci-app-nextdns.json
@@ -0,0 +1,10 @@
+{
+ "luci-app-nextdns": {
+ "description": "Grant logread access to LuCI app nextdns",
+ "read": {
+ "file": {
+ "/sbin/logread": [ "exec" ]
+ }
+ }
+ }
+}