Skip to content

Commit

Permalink
luci-app-antiblock: Add luci-app-antiblock package
Browse files Browse the repository at this point in the history
Adding LuCI web interface for antiblock package

Signed-off-by: Khachatryan Karen <[email protected]>
  • Loading branch information
karen07 committed Jan 31, 2025
1 parent 300d746 commit 2bd9131
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 0 deletions.
14 changes: 14 additions & 0 deletions applications/luci-app-antiblock/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-antiblock
PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Khachatryan Karen <[email protected]>

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
Original file line number Diff line number Diff line change
@@ -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
});
Original file line number Diff line number Diff line change
@@ -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();
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/sh

# ubus -v list luci.antiblock
# ubus -S call luci.antiblock read_domains
# ubus -S call luci.antiblock write_domains '{"domains":["ytimg.com","youtube.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
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
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
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
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"
;;
esac
;;
esac
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}

0 comments on commit 2bd9131

Please sign in to comment.