Skip to content
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

Add firmware upgrade notification to status page #7597

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
'require baseclass';
'require fs';
'require rpc';
'require uci'
'require ui';

var callLuciVersion = rpc.declare({
object: 'luci',
Expand All @@ -18,17 +20,85 @@ var callSystemInfo = rpc.declare({
method: 'info'
});

function showUpgradeModal(type, current_version, new_version) {
ui.showModal(_('New Firmware Available'), [
E('p', _('A new %s version of OpenWrt is available: %s').format(type, new_version)),
E('p', _('Your current version is: %s').format(current_version)),
E('p', _('Please check the https://firmware-selector.openwrt.org/ for the firmware upgrade image')),
E('div', { class: 'btn', click: ui.hideModal }, _('Close')),
]);
};

function checkDeviceAvailable(boardinfo, new_version) {
const profile_url = 'https://downloads.openwrt.org/releases/%s/targets/%s/profiles.json'.format(new_version, boardinfo.release.target);
return fetch(profile_url)
.then(response => response.json())
.then(data => {
// special case for x86 and armsr
if (Object.keys(data.profiles).length == 1 && Object.keys(data.profiles)[0] == "generic") {
return true;
}

for (var i = 0; i < data.profiles.length; i++) {
if (data.profiles[i].profile == boardinfo.board_name) {
return true;
}
for (var j = 0; j < data.profiles[i].supported_devices.length; j++) {
if (data.profiles[i].supported_devices[j] == boardinfo.board_name) {
return true;
}
}
}
})
.catch(error => {
console.error('Failed to fetch profile information:', error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding more context to the error. A user who doesn't know about this feature might be confused by this err string, even though it's a console message.

return false;
});
};


return baseclass.extend({
title: _('System'),

load: function() {
return Promise.all([
L.resolveDefault(callSystemBoard(), {}),
L.resolveDefault(callSystemInfo(), {}),
L.resolveDefault(callLuciVersion(), { revision: _('unknown version'), branch: 'LuCI' })
L.resolveDefault(callLuciVersion(), { revision: _('unknown version'), branch: 'LuCI' }),
uci.load('luci')
]);
},

oneshot: function(data) {
var boardinfo = data[0];
var check_upgrades = uci.get_first('luci', 'core', 'check_firmware_version') || false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but I think that should be 'main' and not 'core', assuming the js versions work like the cli tool:

$ uci show luci.core
uci: Entry not found

$ uci show luci.main
luci.main=core
luci.main.lang='auto'
luci.main.mediaurlbase='/luci-static/openwrt2020'
luci.main.resourcebase='/luci-static/resources'
luci.main.ubuspath='/ubus/'

console.log(check_upgrades)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop


if (check_upgrades == '1' || check_upgrades == 'true') {
fetch('https://downloads.openwrt.org/.versions.json')
.then(response => response.json())
.then(data => {
if (data.oldstable_version
&& data.oldstable_version > boardinfo.release.version
&& checkDeviceAvailable(boardinfo, data.oldstable_version)) {
showUpgradeModal("oldstable", boardinfo.release.version, data.oldstable_version)
} else if (data.stable_version
&& data.stable_version > boardinfo.release.version
&& checkDeviceAvailable(boardinfo, data.stable_version)) {
showUpgradeModal("stable", boardinfo.release.version, data.stable_version)
} else if (data.upcoming_version
&& boardinfo.release.version > data.stable_version
&& data.upcoming_version > boardinfo.release.version
&& checkDeviceAvailable(boardinfo, data.upcoming_version)) {
showUpgradeModal("upcomming", boardinfo.release.version, data.upcoming_version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upcoming (or just new?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe "release candidate"? since I think that's the only thing ever to populate the upcoming_release field in .versions.json...

}
})
.catch(error => {
console.error('Failed to fetch version information:', error);
});
}
},

render: function(data) {
var boardinfo = data[0],
systeminfo = data[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ function startPolling(includes, containers) {
else if (includes[i].content != null)
content = includes[i].content;

if (typeof (includes[i].oneshot) == 'function') {
includes[i].oneshot(results ? results[i] : null);
includes[i].oneshot = null;
}

if (content != null) {
containers[i].parentNode.style.display = '';
containers[i].parentNode.classList.add('fade-in');
Expand Down