-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
luci-app-smartdns: add new package #3413
Conversation
3db4ce5
to
eab97d7
Compare
Please rewrite this app in JavaScript instead of Lua. If you look at the commit history for other recently added apps they show required files. It is pretty straight forward to convert your existing Lua code to JavaScript. |
@aparcar @feckert
m.section(SimpleSection).template = "smartdns/smartdns_status";
o = s.taboption("custom", form.TextValue, "_tmpl",_(""),_("smartdns custom settings"));
o.rows = 20;
o.cfgvalue = function(section_id) {
return fs.trimmed('/etc/smartdns/custom.conf');
};
o.write = function (section_id, formvalue) {
return fs.write('/etc/smartdns/custom.conf', formvalue.trim().replace(/\r\n/g, '\n') + '\n');
}; |
@pymumu luci/applications/luci-app-ksmbd/htdocs/luci-static/resources/view/ksmbd.js Lines 47 to 52 in 1d5a2fb
https://github.com/openwrt/luci/blob/master/applications/luci-app-ksmbd/root/usr/share/rpcd/acl.d/luci-app-ksmbd.json |
@ysc3839 Problem 2 is solved, thanks. About problem 1, the feature is to display servie status, the status check function calls some shell commands (such as pidof, iptable) periodically and display the result. the code is like this, dont't knonw how to write smartdnsServiceStatus() function smartdnsServiceStatus() {
// how to get the following commands result with fs.exec() ?.
// pidof smartdns >/dev/null
// iptables -t nat -nL PREROUTING 2>/dev/null | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1
// uci get dhcp.@dnsmasq[0].server
return "return service status";
}
// section render
s.render = function (section_id) {
L.Poll.add(function () {
return L.resolveDefault(smartdnsServiceStatus()).then(function (res) {
var content = res;
var view = document.getElementById("service_status");
view.innerHTML = res;
});
});
return E('div', { class: 'cbi-map' },
E('div', { class: 'cbi-section' }, [
E('div', {id: 'service_status' },
_('Collecting data ...'))
])
);
} |
Maybe we can implement an RPC call in the ubus? |
function smartdnsServiceStatus() {
return Promise.all([
fs.exec_direct('/bin/pidof', ['smartdns']),
fs.exec_direct('/usr/sbin/iptables', ['-t', 'nat', '-n', '-L', 'PREROUTING']),
uci.get_first('dhcp', 'dnsmasq', 'server')
]);
}
// section render
s.render = function (section_id) {
L.Poll.add(function () {
return L.resolveDefault(smartdnsServiceStatus()).then(function (res) {
var pid = +res[0],
ipt = res[1],
srv = res[2];
var matching_rules = (ipt || '').split(/\n/).filter(function(rule) {
return rule.match(/REDIRECT/) && rule.match(/dpt:53/);
});
var view = document.getElementById("service_status");
view.innerHTML = _('PID of service is %s<br />Firewall rule is %s<br />DNS Server is %s').format(
isNaN(pid) ? '?' : pid,
matching_rules.length ? 'present' : 'not present',
srv);
});
});
return E('div', { class: 'cbi-map' },
E('div', { class: 'cbi-section' }, [
E('div', {id: 'service_status' },
_('Collecting data ...'))
])
);
} You need these ACL rules for the above code to work: {
"luci-app-smartdns": {
"description": "...",
"read": {
"cgi-io": [ "exec" ],
"file": {
"/usr/sbin/iptables -t nat -n -L PREROUTING": [ "exec" ],
"/bin/pidof smartdns": [ "exec" ]
}
}
}
} |
smartdns is using procd to manage process. https://github.com/pymumu/smartdns/blob/744a5409e0fb65b98a8eeb09cdc48bacc0f2a10f/package/openwrt/files/etc/init.d/smartdns#L20 Lines 12 to 17 in 1d5a2fb
Lines 140 to 147 in 1d5a2fb
|
@jow- thanks, problem solved. another problem, when only modify the content in the form.TextValue, and then click "Save&Apply", the page says "There are no changes to apply", how to solve this problem, the code is as follows. o = s.taboption("custom", form.TextValue, "custom_conf",
_(""),
_("smartdns custom settings"));
o.rows = 20;
o.cfgvalue = function (section_id) {
return fs.trimmed('/etc/smartdns/custom.conf');
};
o.write = function (section_id, formvalue) {
return fs.write('/etc/smartdns/custom.conf', formvalue.trim().replace(/\r\n/g, '\n') + '\n');
}; |
Yeah, this is a known problem - ignore it for now, it needs to be fixed on the LuCI side. |
e666bb5
to
424895e
Compare
applications/luci-app-smartdns/htdocs/luci-static/resources/view/smartdns/smartdns.js
Outdated
Show resolved
Hide resolved
applications/luci-app-smartdns/htdocs/luci-static/resources/view/smartdns/smartdns.js
Outdated
Show resolved
Hide resolved
applications/luci-app-smartdns/htdocs/luci-static/resources/view/smartdns/smartdns.js
Outdated
Show resolved
Hide resolved
applications/luci-app-smartdns/root/etc/uci-defaults/50_luci-smartdns
Outdated
Show resolved
Hide resolved
applications/luci-app-smartdns/root/usr/share/rpcd/acl.d/luci-app-smartdns.json
Outdated
Show resolved
Hide resolved
applications/luci-app-smartdns/root/usr/share/rpcd/acl.d/luci-app-smartdns.json
Outdated
Show resolved
Hide resolved
applications/luci-app-smartdns/htdocs/luci-static/resources/view/smartdns/smartdns.js
Outdated
Show resolved
Hide resolved
applications/luci-app-smartdns/htdocs/luci-static/resources/view/smartdns/smartdns.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Nick Peng <pymumu@gmail.com>
@jow- |
@jmarcet We have already an issue for that. But I think we have to add the uci permition read/write to the following uci file smartdns to https://github.com/openwrt/luci/blob/master/applications/luci-app-smartdns/root/usr/share/rpcd/acl.d/luci-app-smartdns.json |
This luci app supports smartdns.
Depends on openwrt/packages#10797.
Signed-off-by: Nick Peng pymumu@gmail.com