luci-app-ruantiblock: info.js - ipset dnsmasq

This commit is contained in:
gSpot
2022-05-12 01:56:19 +03:00
parent c9330e4fa8
commit bed3a91236
10 changed files with 140 additions and 19 deletions
+3 -3
View File
@@ -8,9 +8,9 @@ LUA_MODULE=1
LUCI_APP=1
OWRT_VERSION="current"
RUAB_VERSION="0.9.4-0"
RUAB_MOD_LUA_VERSION="0.9.4-0"
RUAB_LUCI_APP_VERSION="0.9.4-0"
RUAB_VERSION="0.9.4-1"
RUAB_MOD_LUA_VERSION="0.9.4-1"
RUAB_LUCI_APP_VERSION="0.9.4-1"
BASE_URL="https://raw.githubusercontent.com/gSpotx2f/packages-openwrt/master"
PKG_DIR="/tmp"
+1 -1
View File
@@ -4,7 +4,7 @@
include $(TOPDIR)/rules.mk
PKG_VERSION:=0.9.4-0
PKG_VERSION:=0.9.4-1
LUCI_TITLE:=LuCI support for ruantiblock
LUCI_DEPENDS:=+ruantiblock
LUCI_PKGARCH:=all
@@ -6,6 +6,69 @@
'require view.ruantiblock.tools as tools';
return view.extend({
secToTimeString: function(value) {
let string = '';
if(/^\d+$/.test(value)) {
value = Number(value);
let hours = 0, mins = 0, sec = 0, rest = value;
if(value >= 3600) {
hours = Math.floor(value / 3600);
rest = value % 3600;
};
if(rest >= 60) {
mins = Math.floor(rest / 60);
rest = rest % 60;
};
sec = rest;
if(hours > 0) {
string = string + hours + _('h');
};
if(mins > 0) {
string = string + ' ' + mins + _('m');
};
string = string + ' ' + sec + _('s');
};
return string;
},
makeDnsmasqTable: function(ipDataArray) {
let lines = `<tr class="tr"><td class="td center">${_('No entries available...')}</td></tr>`;
let ipTable = E('table', { 'id': 'ipTable', 'class': 'table' });
if(ipDataArray.length > 1) {
lines = [];
ipDataArray.forEach((e, i) => {
if(e) {
lines.push(
`<tr class="tr"><td class="td left" data-title="${_('IP address')}">${e[0]}</td>` +
((e[1]) ? `<td class="td left" data-title="${_('Timeout')}">${this.secToTimeString(e[1])}</td>` : '') +
`</tr>`
);
};
});
lines = lines.join('');
ipTable.append(
E('tr', { 'class': 'tr table-titles' }, [
E('th', { 'class': 'th left', 'style': 'min-width:33%' }, _('IP address')),
(ipDataArray[0][1]) ? E('th', { 'class': 'th left' }, _('Timeout')) : ''
])
);
};
try {
ipTable.insertAdjacentHTML('beforeend', lines);
} catch(err) {
if(err.name === 'SyntaxError') {
ui.addNotification(null,
E('p', {}, _('HTML/XML error') + ': ' + err.message), 'error');
};
throw err;
};
return ipTable;
},
infoPoll: function() {
return fs.exec_direct(tools.execPath, [ 'html-info' ], 'json').catch(e => {
ui.addNotification(null, E('p', _('Unable to execute or read contents')
@@ -72,6 +135,12 @@ return view.extend({
};
};
};
if(data.dnsmasq) {
let rdTableWrapper = document.getElementById('rdTableWrapper');
rdTableWrapper.innerHTML = '';
rdTableWrapper.append(this.makeDnsmasqTable(data.dnsmasq));
};
} else {
if(poll.active()) {
poll.stop();
@@ -99,7 +168,8 @@ return view.extend({
let update_status = null,
iptables = null,
ipset = null;
ipset = null,
dnsmasq = null;
if(data) {
if(data.status === 'enabled') {
update_status = E('table', { 'class': 'table' });
@@ -153,6 +223,7 @@ return view.extend({
for(let [k, v] of Object.entries(data.iptables)) {
if(k === '_dummy') continue;
table_iptables.append(
E('tr', { 'class': 'tr' }, [
E('td', {
@@ -215,7 +286,19 @@ return view.extend({
]);
};
poll.add(this.infoPoll);
if(data.dnsmasq) {
let rdTableWrapper = E('div', {
'id' : 'rdTableWrapper',
'style': 'width:100%'
}, this.makeDnsmasqTable(data.dnsmasq));
dnsmasq = E([
E('h3', {}, _('Dnsmasq')),
rdTableWrapper,
]);
};
poll.add(L.bind(this.infoPoll, this));
} else {
update_status = E('em', {}, _('Status') + ' : ' + _('disabled'));
};
@@ -234,6 +317,10 @@ return view.extend({
E('div', { 'class': 'cbi-section fade-in' },
E('div', { 'class': 'cbi-section-node' }, ipset)
),
E('div', { 'class': 'cbi-section fade-in' },
E('div', { 'class': 'cbi-section-node' }, dnsmasq)
),
]);
},
+7 -1
View File
@@ -161,8 +161,11 @@ msgstr "Фильтр хостов"
msgid "Hour"
msgstr "Час"
msgid "IP address"
msgstr "IP-адрес"
msgid "IP addresses of hosts"
msgstr "IP адреса хостов"
msgstr "IP-адреса хостов"
msgid "IP filter"
msgstr "Фильтр IP"
@@ -380,6 +383,9 @@ msgstr ""
msgid "Time"
msgstr "Время"
msgid "Timeout"
msgstr "Таймаут"
msgid "Timestamp"
msgstr "Время"
@@ -144,6 +144,9 @@ msgstr ""
msgid "Hour"
msgstr ""
msgid "IP address"
msgstr ""
msgid "IP addresses of hosts"
msgstr ""
@@ -344,6 +347,9 @@ msgstr ""
msgid "Time"
msgstr ""
msgid "Timeout"
msgstr ""
msgid "Timestamp"
msgstr ""
+1 -1
View File
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=ruantiblock-mod-lua
PKG_VERSION:=0.9.4
PKG_RELEASE:=0
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
include $(INCLUDE_DIR)/package.mk
+1 -1
View File
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=ruantiblock-mod-py
PKG_VERSION:=0.9.4
PKG_RELEASE:=0
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
include $(INCLUDE_DIR)/package.mk
+1 -1
View File
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=ruantiblock
PKG_VERSION:=0.9.4
PKG_RELEASE:=0
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
include $(INCLUDE_DIR)/package.mk
@@ -25,19 +25,41 @@ Info() {
printf "\"_dummy\":false},";
}'
printf "\"ipset\":{";
for _set in "$IPSET_ALLOWED_HOSTS" "$IPSET_ONION" "$IPSET_CIDR_TMP" "$IPSET_CIDR" "$IPSET_IP_TMP" "$IPSET_IP" "$IPSET_DNSMASQ"
for _set in "$IPSET_ALLOWED_HOSTS" "$IPSET_ONION" "$IPSET_CIDR_TMP" "$IPSET_CIDR" "$IPSET_IP_TMP" "$IPSET_IP"
do
$IPSET_CMD list "$_set" -terse | $AWK_CMD -F ": " '
{
if($1 ~ /^Name/)
if($1 ~ /^Name/) {
printf "\""$2"\":[";
else if($1 ~ /^Size in memory/)
}
else if($1 ~ /^Size in memory/) {
printf "\""$2"\",";
else if($1 ~ /^Number of entries/)
}
else if($1 ~ /^Number of entries/) {
printf "\""$2"\"],";
};
}'
done
printf "\"_dummy\":false}}"
$IPSET_CMD list "$IPSET_DNSMASQ" | $AWK_CMD -F ": " '
{
if($1 ~ /^Name/) {
printf "\""$2"\":[";
}
else if($1 ~ /^Size in memory/) {
printf "\""$2"\",";
}
else if($1 ~ /^Number of entries/) {
printf "\""$2"\"]},\"dnsmasq\":[";
}
else if($0 ~ /^[0-9]/) {
split($0, a, " ");
printf "[\"" a[1] "\",\"" a[3] "\"],";
};
}
END {
printf "false],";
}'
printf "\"_dummy\":false}"
else
printf "{\"status\": \"disabled\"}"
fi
Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 KiB

After

Width:  |  Height:  |  Size: 187 KiB