Hello Brain Trust!
So I am making some progress and decided to try and implement a rudimentary update functionality to update the database. I think I have all the required files/config in place (going by what's in the repo), but I am getting a 403 status when the update is attempted:
403 Access to command denied by ACL
I have the following in /www/luci-static/resources/view/bwl/bwl.js:
'use strict';
'require view';
'require form';
'require uci';
'require fs';
'require validation';
'require tools.widgets as widgets';
'require poll';
var timer
function handleAction(ev) {
clearTimeout(timer)
timer = setTimeout(function() {
var varName = ev.target.getAttribute('id')
var varValue = ev.target.value
L.resolveDefault(fs.exec_direct('/etc/init.d/bwl', ['upd_config_var', varName, varValue]))
}, 3000)
}
return view.extend({
//load: function() { return Promise.all(L.resolveDefault(fs.exec_direct('/etc/init.d/bwl' ['config', 'downloadLimit']), '')), uci.load('bwl'); },
render: function() {
var varNames = ['downloadLimit', 'uploadLimit', 'interfaces', 'sleep', 'maxBandwidth', 'tcCommand', 'resetTime', 'chainName']
var container = E('div', { class: 'cbi-section' }, [
E('div', { class: 'cbi-section-descr' }, _('The syslog output, pre-filtered for adblock related messages only.'), [])
])
function renderVar(varName, index) {
var cfgItem = E('div', { class: 'cbi-value' }, [
E('label', { class: 'cbi-value-title' }, _(varName)),
E('input', { 'id': varName, 'class': 'cbi-input-text', 'input': handleAction })
])
container.appendChild(cfgItem)
}
function setVar(varName, index) {
var log = document.getElementById(varName);
L.resolveDefault(fs.exec_direct('/etc/init.d/bwl', ['get_config_var', varName])).then(function(res) {
var log = document.getElementById(varName);
if (res) { log.value = res; } else { log.value = _('No adblock related logs yet!'); }
});
}
varNames.forEach(setVar)
varNames.forEach(renderVar)
var root = E('div', { class: 'cbi-map' },
container
);
return root
},
handleSaveApply: null,
handleSave: null,
handleReset: null
});
The following in /usr/share/rpcd/acl.d/luci-app-bwl.json:
{
"luci-app-bwl": {
"description": "Grant UCI access for luci-app-bwl",
"write": {
"file": {
"/etc/init.d/bwl upd_config_var [a-zA-Z]* +": ["exec"]
}
},
"read": {
"file": {
"/etc/init.d/bwl get_config_var [a-zA-Z]*": ["exec"]
},
"uci": ["bwl"]
}
}
}
Finally, the following in /etc/init.d/bwl:
if [ -n "$(type -t extra_command)" ]
then
extra_command "get_config_var" "Suspend adblock processing"
extra_command "upd_config_var" "Suspend adblock processing"
fi
SCRIPT_HOME='/root'
DB_FILE="${SCRIPT_HOME}/bandwidth_limit.db"
SQLITE='/usr/bin/sqlite3'
get_config_var()
{
local var_name=$1
local result=`${SQLITE} ${DB_FILE} "select configValue from config where configName='${var_name}';"`
echo ${result}
}
upd_config_var()
{
local var_name=$1
local var_value=$2
local result=`${SQLITE} ${DB_FILE} "update config set configValue = '${var_value}' where configName='${var_name}';"`
echo ${result}
}
I have tested upd_config_var from the command line and it works without issue, so it's not that. What have I missed?!
Cheers
Tim