Complete noob questions about js and LuCi

Hi

I'll say in advance that I know very little about js (not even syntax), and even less about LuCi+js. I'm currently just experimenting to get a taste of the thing before deciding if I want to learn it more thoroughly.

So my initial goal is to get an output of some shell command in LuCi. The shell command happens to be '/usr/bin/geoip-shell status'

So far I have this js code:

'use strict';
'require view';
'require poll';
'require fs';
'require ui';
'require uci';
'require form';

return view.extend({
	render: function(result) {
		var m, s, o;
		m = new form.Map('firewall', 'geoip-shell', _('Bruh!'));
		var statusRes

		poll.add(function() {
			L.resolveDefault(fs.exec_direct('/usr/bin/geoip-shell', ['status'])).then(
				function(result) {
					if (result) {
						statusRes = document.getElementById('status');
						if (statusRes) {
							statusRes.textContent = result || 'bruhhhhh';
						}
					} else {
						poll.stop();
			}});

		}, 1);

		s = m.section(form.NamedSection, 'StatusSection');
		s.render = L.bind(function(view, section_id) {
			return E('div', {
				'class': 'cbi-section'
			}, [E('h3', _('Status')), E('div', {
				'class': 'cbi-value'
			}, [E('div', {
				'class': 'cbi-value-field',
				'id': 'status'
			}, '')])
		]);
		}, o, this);
		this.pollData;
		return m.render();
	},
});

This produces the expected output (although it doesn't display newlines and colors correctly but that's not my focus rn).

My problem is that LuCi.form.map wants a UCI config for its first parameter. I don't need that config at all. For now, to make it happy, I'm just pointing it to the firewall config. However I'd like to do this properly, without loading config which I don't need. Probably I should use some other class to achieve this? If so then which (a basic example would be appreciated as well)?

(also if parts of the code don't make sense then please correct me)

Do you work for an Internet blocking company? If so, I hope no one can tell you ))

Dear @fkl7834456, I'm developing an open-source project, completely unrelated to my work.

1 Like