luci-app-internet-detector v0.5-1

This commit is contained in:
gSpot
2022-02-20 18:17:27 +03:00
parent a02e46cd19
commit e8a3430571
5 changed files with 234 additions and 176 deletions

View File

@@ -24,9 +24,9 @@ Internet-detector is an application for checking the availability of the Interne
/etc/init.d/internet-detector start
/etc/init.d/internet-detector enable
wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.5-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/19.07/luci-app-internet-detector_0.5-0_all.ipk
opkg install /tmp/luci-app-internet-detector_0.5-0_all.ipk
rm /tmp/luci-app-internet-detector_0.5-0_all.ipk
wget --no-check-certificate -O /tmp/luci-app-internet-detector_0.5-1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/19.07/luci-app-internet-detector_0.5-1_all.ipk
opkg install /tmp/luci-app-internet-detector_0.5-1_all.ipk
rm /tmp/luci-app-internet-detector_0.5-1_all.ipk
/etc/init.d/rpcd restart
Email notification:
@@ -35,9 +35,9 @@ Email notification:
i18n-ru:
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.5-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/19.07/luci-i18n-internet-detector-ru_0.5-0_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_0.5-0_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_0.5-0_all.ipk
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_0.5-1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/19.07/luci-i18n-internet-detector-ru_0.5-1_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_0.5-1_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_0.5-1_all.ipk
## Screenshots:

View File

@@ -31,7 +31,7 @@ config module 'mod_network_restart'
config module 'mod_modem_restart'
option enabled '0'
option dead_period '600'
option any_band '1'
option any_band '0'
config module 'mod_email'
option enabled '0'

View File

@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_VERSION:=0.5
PKG_RELEASE:=0
PKG_RELEASE:=1
LUCI_TITLE:=LuCI support for internet-detector
LUCI_DEPENDS:=+internet-detector
LUCI_PKGARCH:=all

View File

@@ -86,9 +86,8 @@ return L.view.extend({
initStatus : null,
inetStatus : null,
inetStatusLabel : E('span', { 'class': 'label' }),
inetStatusSpinner : E('span', { 'class': 'spinning', 'style': 'margin-top:1em' }, ' '),
inetStatusSpinner : E('span', { 'style': 'margin-top:1em' }, ' '),
serviceStatusLabel : E('em'),
serviceButton : null,
initButton : null,
uiPollCounter : 0,
uiPollState : null,
@@ -138,6 +137,90 @@ return L.view.extend({
});
},
setInetStatusSpinner: function() {
this.inetStatusSpinner.className = 'spinning';
},
unsetInetStatusSpinner: function() {
this.inetStatusSpinner.className = '';
},
setInternetStatus: function() {
if(this.inetStatus === 'up') {
this.inetStatusLabel.style.background = '#46a546';
this.inetStatusLabel.textContent = _('Connected');
this.inetStatusLabel.style.color = '#ffffff';
this.unsetInetStatusSpinner();
}
else if(this.inetStatus === 'down') {
this.inetStatusLabel.textContent = _('Disconnected');
this.inetStatusLabel.style.background = '#ff4953';
this.inetStatusLabel.style.color = '#ffffff';
this.unsetInetStatusSpinner();
}
else {
this.inetStatusLabel.textContent = _('Undefined');
this.inetStatusLabel.style.background = '#9b9b9b';
this.inetStatusLabel.style.color = '#ffffff';
if(this.currentAppMode !== '0' && this.appStatus !== 'stoped') {
this.setInetStatusSpinner();
};
};
if(this.appStatus === 'running') {
this.serviceStatusLabel.textContent = _('Running');
} else {
this.serviceStatusLabel.textContent = _('Stopped');
};
},
servicePoll: function() {
return Promise.all([
fs.exec(this.execPath, [ 'status' ]),
fs.exec(this.execPath, [ 'inet-status' ]),
]).then(stat => {
let curAppStatus = (stat[0].code === 0) ? stat[0].stdout.trim() : null;
let curInetStatus = (stat[1].code === 0) ? stat[1].stdout.trim() : null;
if(this.inetStatus === curInetStatus && this.appStatus === curAppStatus) {
return;
};
this.appStatus = curAppStatus;
this.inetStatus = curInetStatus;
this.setInternetStatus();
}).catch(e => {
this.appStatus = 'stoped';
this.inetStatus = null;
});
},
uiPoll: function() {
let curInetStatus = null;
this.uiPollCounter = ++this.uiPollCounter;
if((this.uiPollState === 0 && this.uiPollCounter % this.uiCheckIntervalUp) ||
(this.uiPollState === 1 && this.uiPollCounter % this.uiCheckIntervalDown)) {
return;
};
this.uiPollCounter = 0;
return fs.exec(this.execPath, [ 'inet-status' ]).then(res => {
this.uiPollState = (res.code === 0 && res.stdout.trim() === 'up') ? 0 : 1;
if(this.uiPollState === 0) {
curInetStatus = 'up';
} else {
curInetStatus = 'down';
};
if(this.inetStatus !== curInetStatus) {
this.inetStatus = (this.currentAppMode === '0') ? null : curInetStatus;
this.setInternetStatus();
};
});
},
serviceRestart: function(ev) {
L.Poll.stop();
return this.handleServiceAction('restart').then(() => {
@@ -170,10 +253,10 @@ return L.view.extend({
},
}),
CBIBlockService: form.Value.extend({
__name__ : 'CBI.BlockService',
CBIBlockInetStatus: form.Value.extend({
__name__ : 'CBI.BlockInetStatus',
__init__ : function(map, section, ctx) {
__init__ : function(map, section, ctx) {
this.map = map;
this.section = section;
this.ctx = ctx;
@@ -182,11 +265,56 @@ return L.view.extend({
},
renderWidget: function(section_id, option_index, cfgvalue) {
this.ctx.serviceButton = E('button', {
'class': btnStyleApply,
'click': ui.createHandlerFn(this.ctx, this.ctx.serviceRestart),
}, _('Restart'));
this.ctx.initButton = E('button', {
this.ctx.setInternetStatus();
return E([
E('label', { 'class': 'cbi-value-title' },
_('Internet status')
),
E('div', { 'class': 'cbi-value-field' }, [
this.ctx.inetStatusLabel,
this.ctx.inetStatusSpinner
]),
])
},
}),
CBIBlockServiceStatus: form.Value.extend({
__name__ : 'CBI.BlockServiceStatus',
__init__ : function(map, section, ctx) {
this.map = map;
this.section = section;
this.ctx = ctx;
this.optional = true;
this.rmempty = true;
},
renderWidget: function(section_id, option_index, cfgvalue) {
return E([
E('label', { 'class': 'cbi-value-title' },
_('Service')
),
E('div', { 'class': 'cbi-value-field' },
this.ctx.serviceStatusLabel
),
]);
},
}),
CBIBlockInitButton: form.Value.extend({
__name__ : 'CBI.BlockInitButton',
__init__ : function(map, section, ctx) {
this.map = map;
this.section = section;
this.ctx = ctx;
this.optional = true;
this.rmempty = true;
},
renderWidget: function(section_id, option_index, cfgvalue) {
this.ctx.initButton = E('button', {
'class': (!this.ctx.initStatus) ? btnStyleDisabled : btnStyleEnabled,
'click': ui.createHandlerFn(this, () => {
return this.ctx.handleServiceAction(
@@ -209,56 +337,14 @@ return L.view.extend({
}),
}, (!this.ctx.initStatus) ? _('Disabled') : _('Enabled'));
this.ctx.setInternetStatus(true);
let serviceItems = '';
if(this.ctx.currentAppMode === '2') {
serviceItems = E([
E('div', { 'class': 'cbi-value' }, [
E('label', { 'class': 'cbi-value-title' },
_('Service')
),
E('div', { 'class': 'cbi-value-field' },
this.ctx.serviceStatusLabel
),
]),
E('div', { 'class': 'cbi-value' }, [
E('label', { 'class': 'cbi-value-title' },
_('Restart service')
),
E('div', { 'class': 'cbi-value-field' },
this.ctx.serviceButton
),
]),
E('div', { 'class': 'cbi-value' }, [
E('label', { 'class': 'cbi-value-title' },
_('Run service at startup')
),
E('div', { 'class': 'cbi-value-field' },
this.ctx.initButton
),
]),
]);
};
let internetStatus = (this.ctx.currentAppMode !== '0') ?
E('div', { 'class': 'cbi-value' }, [
E('label', { 'class': 'cbi-value-title' },
_('Internet status')
),
E('div', { 'class': 'cbi-value-field' }, [
this.ctx.inetStatusLabel,
(!this.ctx.inetStatus) ? this.ctx.inetStatusSpinner : '',
]),
])
: '';
return E('div', { 'class': 'cbi-section' },
E('div', { 'class': 'cbi-section-node' }, [
internetStatus,
serviceItems,
])
);
return E( [
E('label', { 'class': 'cbi-value-title' },
_('Run service at startup')
),
E('div', { 'class': 'cbi-value-field' },
this.ctx.initButton
),
]);
},
}),
@@ -282,11 +368,11 @@ return L.view.extend({
E('div', { 'class': 'cbi-section' },
E('p', {},
E('textarea', {
'id': 'widget.modal_content',
'id' : 'widget.modal_content',
'class': 'cbi-input-textarea',
'style': 'width:100% !important',
'rows': 10,
'wrap': 'off',
'rows' : 10,
'wrap' : 'off',
'spellcheck': 'false',
},
content)
@@ -310,7 +396,7 @@ return L.view.extend({
handleSave: function(ev) {
let textarea = document.getElementById('widget.modal_content');
let value = textarea.value.trim().replace(/\r\n/g, '\n') + '\n';
let value = textarea.value.trim().replace(/\r\n/g, '\n') + '\n';
return fs.write(this.file, value).then(rc => {
textarea.value = value;
@@ -360,77 +446,6 @@ return L.view.extend({
},
}),
setInternetStatus: function(initial=false) {
if(this.inetStatus === 'up') {
this.inetStatusLabel.style.background = '#46a546';
this.inetStatusLabel.textContent = _('Connected');
}
else if(this.inetStatus === 'down') {
this.inetStatusLabel.textContent = _('Disconnected');
this.inetStatusLabel.style.background = '#ff6c74';
}
else {
this.inetStatusLabel.textContent = _('Undefined');
this.inetStatusLabel.style.background = '#cccccc';
};
if(!initial && this.inetStatusSpinner) {
this.inetStatusSpinner.remove();
};
if(this.appStatus === 'running') {
this.serviceStatusLabel.textContent = _('Running');
} else {
this.serviceStatusLabel.textContent = _('Stopped');
};
},
servicePoll: function() {
return Promise.all([
fs.exec(this.execPath, [ 'status' ]),
fs.exec(this.execPath, [ 'inet-status' ]),
]).then(stat => {
let curAppStatus = (stat[0].code === 0) ? stat[0].stdout.trim() : null;
let curInetStatus = (stat[1].code === 0) ? stat[1].stdout.trim() : null;
if(this.inetStatus === curInetStatus && this.appStatus === curAppStatus) {
return;
};
this.appStatus = curAppStatus;
this.inetStatus = curInetStatus;
this.setInternetStatus();
}).catch(e => {
this.appStatus = 'stoped';
this.inetStatus = null;
});
},
uiPoll: function() {
let curInetStatus = null;
this.uiPollCounter = ++this.uiPollCounter;
if((this.uiPollState === 0 && this.uiPollCounter % this.uiCheckIntervalUp) ||
(this.uiPollState === 1 && this.uiPollCounter % this.uiCheckIntervalDown)) {
return;
};
this.uiPollCounter = 0;
return fs.exec(this.execPath, [ 'inet-status' ]).then(res => {
this.uiPollState = (res.code === 0 && res.stdout.trim() === 'up') ? 0 : 1;
if(this.uiPollState === 0) {
curInetStatus = 'up';
} else {
curInetStatus = 'down';
};
if(this.inetStatus !== curInetStatus) {
this.inetStatus = (this.currentAppMode === '0') ? null : curInetStatus;
this.setInternetStatus();
};
});
},
load: function() {
return Promise.all([
fs.exec(this.execPath, [ 'status' ]),
@@ -469,13 +484,28 @@ return L.view.extend({
/* Service widget */
s = m.section(form.NamedSection, 'config', 'main');
o = s.option(this.CBIBlockService, this);
s = m.section(form.NamedSection, 'config', 'main');
o = s.option(this.CBIBlockInetStatus, this);
if(this.currentAppMode === '2') {
o = s.option(this.CBIBlockServiceStatus, this);
// restart button
o = s.option(form.Button,
'_restart_btn', _('Restart service')
);
o.onclick = () => this.serviceRestart();
o.inputtitle = _('Restart');
o.inputstyle = btnStyleApply;
// init button
o = s.option(this.CBIBlockInitButton, this);
};
/* Main settings */
s = m.section(form.NamedSection, 'config', 'main');
s = m.section(form.NamedSection, 'config', 'main');
s.tab('main_configuration', _('Main settings'));
@@ -650,7 +680,7 @@ return L.view.extend({
/* Modules */
s = m.section(form.NamedSection, 'config', 'main',
s = m.section(form.NamedSection, 'mod_led_control', 'module',
_('Service modules'),
_('Performing actions when connecting and disconnecting the Internet (available in the "Service" mode).'));
@@ -658,27 +688,27 @@ return L.view.extend({
s.tab('led_control', _('LED control'));
o = s.taboption('led_control', form.SectionValue, 'mod_led_control', form.NamedSection,
'mod_led_control', 'mod_led_control',
_('<abbr title="Light Emitting Diode">LED</abbr> control'),
_('<abbr title="Light Emitting Diode">LED</abbr> is on when Internet is available.'))
ss = o.subsection;
o = s.taboption('led_control', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('<abbr title="Light Emitting Diode">LED</abbr> is on when Internet is available.') +
'</div>';
if(this.leds.length > 0) {
// enabled
o = ss.option(form.Flag, 'enabled',
o = s.taboption('led_control', form.Flag, 'enabled',
_('Enable'));
o.rmempty = false;
// led_name
o = ss.option(form.ListValue, 'led_name',
o = s.taboption('led_control', form.ListValue, 'led_name',
_('<abbr title="Light Emitting Diode">LED</abbr> Name'));
o.depends({ enabled: '1' });
this.leds.sort((a, b) => a.name > b.name);
this.leds.forEach(e => o.value(e.name));
} else {
o = ss.option(form.DummyValue, '_dummy');
o = s.taboption('led_control', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<label class="cbi-value-title"></label><div class="cbi-value-field"><em>' +
_('No <abbr title="Light Emitting Diode">LED</abbr>s available...') +
@@ -689,10 +719,15 @@ return L.view.extend({
s.tab('reboot_device', _('Reboot device'));
o = s.taboption('reboot_device', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Device will be rebooted when the Internet is disconnected.') +
'</div>';
o = s.taboption('reboot_device', form.SectionValue, 'mod_reboot', form.NamedSection,
'mod_reboot', 'mod_reboot',
_('Reboot device'),
_('Device will be rebooted when the Internet is disconnected.'));
'mod_reboot', 'mod_reboot'
);
ss = o.subsection;
// enabled
@@ -724,10 +759,15 @@ return L.view.extend({
s.tab('restart_network', _('Restart network'));
o = s.taboption('restart_network', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Network will be restarted when the Internet is disconnected.') +
'</div>';
o = s.taboption('restart_network', form.SectionValue, 'mod_network_restart', form.NamedSection,
'mod_network_restart', 'mod_network_restart',
_('Restart network'),
_('Network will be restarted when the Internet is disconnected.'));
'mod_network_restart', 'mod_network_restart'
);
ss = o.subsection;
// enabled
@@ -779,10 +819,15 @@ return L.view.extend({
s.tab('restart_modem', _('Restart modem'));
o = s.taboption('restart_modem', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Modem will be restarted when the Internet is disconnected.') +
'</div>';
o = s.taboption('restart_modem', form.SectionValue, 'mod_modem_restart', form.NamedSection,
'mod_modem_restart', 'mod_modem_restart',
_('Restart modem'),
_('Modem will be restarted when the Internet is disconnected.'));
'mod_modem_restart', 'mod_modem_restart'
);
ss = o.subsection;
if(this.mm) {
@@ -827,10 +872,15 @@ return L.view.extend({
s.tab('email', _('Email notification'));
o = s.taboption('email', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('An email will be sent when the internet connection is restored after being disconnected.') +
'</div>';
o = s.taboption('email', form.SectionValue, 'mod_email', form.NamedSection,
'mod_email', 'mod_email',
_('Email notification'),
_('An email will be sent when the internet connection is restored after being disconnected.'));
'mod_email', 'mod_email'
);
ss = o.subsection;
if(this.mta) {
@@ -920,10 +970,15 @@ return L.view.extend({
s.tab('user_scripts', _('User scripts'));
o = s.taboption('user_scripts', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('Shell commands to run when connected or disconnected from the Internet.') +
'</div>';
o = s.taboption('user_scripts', form.SectionValue, 'mod_user_scripts', form.NamedSection,
'mod_user_scripts', 'mod_user_scripts',
_('User scripts'),
_('Shell commands to run when connected or disconnected from the Internet.'));
'mod_user_scripts', 'mod_user_scripts'
);
ss = o.subsection;
// enabled
@@ -971,9 +1026,9 @@ return L.view.extend({
);
};
let map_promise = m.render();
map_promise.then(node => node.classList.add('fade-in'));
return map_promise;
let mapPromise = m.render();
mapPromise.then(node => node.classList.add('fade-in'));
return mapPromise;
},
handleSaveApply: function(ev, mode) {

View File

@@ -67,14 +67,17 @@ return L.Class.extend({
if(window.internetDetectorState === 0) {
internetStatus.textContent = _('Connected');
internetStatus.style.background = '#46a546';
internetStatus.style.color = '#ffffff';
}
else if(window.internetDetectorState === 1) {
internetStatus.textContent = _('Disconnected');
internetStatus.style.background = '#ff6c74';
internetStatus.style.background = '#ff4953';
internetStatus.style.color = '#ffffff';
}
else {
internetStatus.textContent = _('Undefined');
internetStatus.background = '#cccccc';
internetStatus.textContent = _('Undefined');
internetStatus.style.background = '#9b9b9b';
internetStatus.style.color = '#ffffff';
};
return E('div', {