diff --git a/applications/luci-app-antiblock/Makefile b/applications/luci-app-antiblock/Makefile new file mode 100644 index 00000000000..0ffa841cc00 --- /dev/null +++ b/applications/luci-app-antiblock/Makefile @@ -0,0 +1,14 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-antiblock +PKG_LICENSE:=GPL-3.0-or-later +PKG_MAINTAINER:=Khachatryan Karen + +LUCI_TITLE:=AntiBlock Web UI +LUCI_URL:=https://github.com/karen07/luci-app-antiblock-openwrt-package +LUCI_DESCRIPTION:=Provides Web UI for AntiBlock +LUCI_DEPENDS:=+luci-base +antiblock + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/applications/luci-app-antiblock/htdocs/luci-static/resources/view/antiblock/domains.js b/applications/luci-app-antiblock/htdocs/luci-static/resources/view/antiblock/domains.js new file mode 100644 index 00000000000..efc78915f6e --- /dev/null +++ b/applications/luci-app-antiblock/htdocs/luci-static/resources/view/antiblock/domains.js @@ -0,0 +1,107 @@ +'use strict'; +'require ui'; +'require form'; +'require rpc'; +'require view'; + +const read_domains = rpc.declare({ + object: 'luci.antiblock', + method: 'read_domains' +}); + +const write_domains = rpc.declare({ + object: 'luci.antiblock', + method: 'write_domains', + params: ['domains'] +}); + +return view.extend({ + generic_failure: function (message) { + return E('div', { + 'class': 'error' + }, ['RPC call failure: ', message]); + }, + load: function () { + return Promise.all([ + read_domains() + ]); + }, + render: function (data) { + const main_div = E('div'); + + const header = E('h2', {}, _('AntiBlock')); + + const section_descr_div = E( + 'div', + { + class: 'cbi-section-descr', + }, + _('Domains count in file: ') + ); + + const section_div = E( + 'div', + { + class: 'cbi-section', + } + ); + + main_div.appendChild(header); + main_div.appendChild(section_div); + section_div.appendChild(section_descr_div); + + if (typeof data[0].domains !== 'undefined') { + const domains_textarea = E( + 'textarea', + { + class: 'cbi-input-textarea', + }, + ); + + section_descr_div.innerHTML += data[0].domains.length; + + domains_textarea.value = ''; + data[0].domains.forEach((element) => domains_textarea.value += element + '\n'); + + const btn_write_domains = E( + 'button', + { + class: 'btn cbi-button cbi-button-apply', + click: function (ev) { + ui.showModal(null, [ + E( + 'p', + { class: 'spinning' }, + _('Write domains') + ), + ]); + const lines = domains_textarea.value.split(/\r?\n/).filter(Boolean); + const write_domains_res = Promise.all([write_domains(lines)]); + write_domains_res.then( + function (value) { location.reload(); }, + function (error) { /* code if some error */ } + ); + }, + }, + _('Write domains') + ); + + section_div.appendChild(domains_textarea); + section_div.appendChild(btn_write_domains); + } else { + const error_div = E( + 'div', + { + }, + _('The File argument was not specified.') + ); + + section_div.appendChild(error_div); + } + + return main_div; + }, + handleSave: null, + handleSaveApply: null, + handleReset: null +}); diff --git a/applications/luci-app-antiblock/htdocs/luci-static/resources/view/antiblock/form.js b/applications/luci-app-antiblock/htdocs/luci-static/resources/view/antiblock/form.js new file mode 100644 index 00000000000..cfe616a46d8 --- /dev/null +++ b/applications/luci-app-antiblock/htdocs/luci-static/resources/view/antiblock/form.js @@ -0,0 +1,44 @@ +'use strict'; +'require view'; +'require form'; +'require tools.widgets as widgets'; + +return view.extend({ + render: function () { + const m = new form.Map('antiblock', _('AntiBlock')); + + const s = m.section(form.NamedSection, 'config', 'antiblock', _('AntiBlock')); + s.addremove = true; + + let o = s.option(form.Flag, 'enabled', _('Enabled')); + + o = s.option(form.Value, 'url', _('URL'), _('Domains file URL, either File or URL or both')); + o.default = 'https://antifilter.download/list/domains.lst'; + o.depends('enabled', '1'); + + o = s.option(form.Value, 'file', _('File'), _('Domains file path, either File or URL or both')); + o.depends('enabled', '1'); + + o = s.option(form.Value, 'DNS', _('DNS'), _('DNS address, required parameter')); + o.default = '1.1.1.1:53'; + o.depends('enabled', '1'); + + o = s.option(form.Value, 'listen', _('Listen'), _('Listen address, required parameter')); + o.default = '192.168.1.1:5053'; + o.depends('enabled', '1'); + + o = s.option(widgets.DeviceSelect, 'VPN_name', _('VPN name'), _('Interface name, required parameter')); + o.depends('enabled', '1'); + + o = s.option(form.Value, 'output', _('Output'), _('Log or statistics output folder, optional parameter')); + o.depends('enabled', '1'); + + o = s.option(form.Flag, 'log', _('Log'), _('Show operations log, optional parameter')); + o.depends({ output: '/', '!contains': true }); + + o = s.option(form.Flag, 'stat', _('Stat'), _('Show statistics data, optional parameter')); + o.depends({ output: '/', '!contains': true }); + + return m.render(); + }, +}); diff --git a/applications/luci-app-antiblock/root/usr/libexec/rpcd/luci.antiblock b/applications/luci-app-antiblock/root/usr/libexec/rpcd/luci.antiblock new file mode 100755 index 00000000000..0ccb43926e1 --- /dev/null +++ b/applications/luci-app-antiblock/root/usr/libexec/rpcd/luci.antiblock @@ -0,0 +1,85 @@ +#!/bin/sh + +# ubus -v list luci.antiblock +# ubus -S call luci.antiblock read_domains +# ubus -S call luci.antiblock write_domains '{"domains":["test0.com","test1.com","test2.com"]}' + +. /lib/functions.sh +. /usr/share/libubox/jshn.sh + +get_file_path() { + file_path="$(uci -q get antiblock.config.file)" +} + +read_domains() { + get_file_path + + json_init + if [ -n "$file_path" ]; then + if [ ! -f "$file_path" ]; then + touch "$file_path" + fi + + json_add_array "domains" + file_data=$(cat $file_path) + for domain in $file_data; do + json_add_string "" "$domain" + done + json_close_array + else + json_add_array "empty" + json_close_array + fi + json_dump + json_cleanup +} + +write_domains() { + get_file_path + + if [ -n "$file_path" ]; then + if [ ! -f "$file_path" ]; then + touch "$file_path" + fi + + json_load "$1" + json_get_values values "domains" + >$file_path + for key in $values; do + echo "$key" >>$file_path + done + json_cleanup + + /etc/init.d/antiblock restart + fi +} + +case "$1" in +list) + json_init + json_add_object "read_domains" + json_close_object + json_add_object "write_domains" + json_add_string 'domains' "domains" + json_close_object + json_dump + json_cleanup + ;; +call) + case "$2" in + read_domains) + read_domains + ;; + write_domains) + read -r input + write_domains "$input" + ;; + *) + return 0 + ;; + esac + ;; +*) + return 0 + ;; +esac diff --git a/applications/luci-app-antiblock/root/usr/share/luci/menu.d/luci-app-antiblock.json b/applications/luci-app-antiblock/root/usr/share/luci/menu.d/luci-app-antiblock.json new file mode 100644 index 00000000000..cc05d6c216f --- /dev/null +++ b/applications/luci-app-antiblock/root/usr/share/luci/menu.d/luci-app-antiblock.json @@ -0,0 +1,30 @@ +{ + "admin/services/antiblock": { + "title": "AntiBlock", + "order": 90, + "action": { + "type": "firstchild" + }, + "depends": { + "acl": [ + "luci-app-antiblock" + ] + } + }, + "admin/services/antiblock/form": { + "title": "Args View", + "order": 1, + "action": { + "type": "view", + "path": "antiblock/form" + } + }, + "admin/services/antiblock/domains": { + "title": "Domains file View", + "order": 2, + "action": { + "type": "view", + "path": "antiblock/domains" + } + } +} diff --git a/applications/luci-app-antiblock/root/usr/share/rpcd/acl.d/luci-app-antiblock.json b/applications/luci-app-antiblock/root/usr/share/rpcd/acl.d/luci-app-antiblock.json new file mode 100644 index 00000000000..231fffdf920 --- /dev/null +++ b/applications/luci-app-antiblock/root/usr/share/rpcd/acl.d/luci-app-antiblock.json @@ -0,0 +1,21 @@ +{ + "luci-app-antiblock": { + "description": "Grant UCI and RPC access to LuCI app AntiBlock", + "read": { + "ubus": { + "luci.antiblock": [ + "read_domains", + "write_domains" + ] + }, + "uci": [ + "antiblock" + ] + }, + "write": { + "uci": [ + "antiblock" + ] + } + } +}