|
22 | 22 | branch: get_branch(promises[1].release.version), |
23 | 23 | revision: promises[1].release.revision, |
24 | 24 | efi: promises[2], |
25 | | -@@ -745,13 +751,271 @@ |
| 25 | +@@ -745,13 +751,218 @@ |
26 | 26 | E( |
27 | 27 | 'button', |
28 | 28 | { |
|
202 | 202 | + } |
203 | 203 | + |
204 | 204 | + if (data.success) { |
205 | | -+ // Firmware is already downloaded to /tmp/firmware.bin |
206 | | -+ // Verify the SHA256 hash if available |
207 | | -+ if (data.sha256) { |
208 | | -+ // Calculate the SHA256 hash of the downloaded file |
209 | | -+ L.resolveDefault(callFileExec('sha256sum', ['/tmp/firmware.bin']), {}) |
210 | | -+ .then(result => { |
211 | | -+ if (result && result.stdout) { |
212 | | -+ // Extract the hash from the command output (first 64 characters) |
213 | | -+ const calculatedHash = result.stdout.trim().substring(0, 64); |
214 | | -+ |
215 | | -+ if (calculatedHash.toLowerCase() === data.sha256.toLowerCase()) { |
216 | | -+ // Hashes match, proceed with installation |
217 | | -+ ui.showModal(_('Installing...'), [ |
218 | | -+ E('div', { class: 'spinning' }, [ |
219 | | -+ E('p', _('Installing the sysupgrade image...')), |
220 | | -+ E('p', |
221 | | -+ _('Once the image is written, the system will reboot.') |
222 | | -+ + ' ' + |
223 | | -+ _('This should take at least a minute, so please wait for the login screen.') |
224 | | -+ ), |
225 | | -+ E('b', _('While you are waiting, do not unpower device!')), |
226 | | -+ ]), |
227 | | -+ ]); |
228 | | -+ |
229 | | -+ L.resolveDefault(callUpgradeStart(keep), {}).then((response) => { |
230 | | -+ // Wait 10 seconds before we try to reconnect... |
231 | | -+ let hosts = keep ? [] : ['192.168.1.1', 'openwrt.lan']; |
232 | | -+ setTimeout(() => { ui.awaitReconnect(...hosts); }, 10000); |
233 | | -+ }); |
234 | | -+ } else { |
235 | | -+ // Hashes don't match, show error |
236 | | -+ ui.showModal(_('Wrong checksum'), [ |
237 | | -+ E('p', _('Calculated SHA256: %s').format(calculatedHash)), |
238 | | -+ E('p', _('Expected SHA256: %s').format(data.sha256)), |
239 | | -+ E('p', _('Error during verification of the downloaded firmware. Please try again')), |
240 | | -+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')), |
241 | | -+ ]); |
242 | | -+ } |
243 | | -+ } else { |
244 | | -+ // Could not calculate hash, show error |
245 | | -+ ui.showModal(_('Verification Error'), [ |
246 | | -+ E('p', _('Could not calculate SHA256 hash of the downloaded firmware')), |
247 | | -+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')), |
248 | | -+ ]); |
249 | | -+ } |
250 | | -+ }) |
251 | | -+ .catch(error => { |
252 | | -+ ui.showModal(_('Verification Error'), [ |
253 | | -+ E('p', _('Error calculating SHA256 hash: %s').format(error.message)), |
254 | | -+ E('div', { class: 'btn', click: ui.hideModal }, _('Close')), |
255 | | -+ ]); |
256 | | -+ }); |
257 | | -+ } else { |
258 | | -+ // No hash to verify, proceed with installation |
259 | | -+ ui.showModal(_('Installing...'), [ |
260 | | -+ E('div', { class: 'spinning' }, [ |
261 | | -+ E('p', _('Installing the sysupgrade image...')), |
262 | | -+ E('p', |
263 | | -+ _('Once the image is written, the system will reboot.') |
264 | | -+ + ' ' + |
265 | | -+ _('This should take at least a minute, so please wait for the login screen.') |
266 | | -+ ), |
267 | | -+ E('b', _('While you are waiting, do not unpower device!')), |
268 | | -+ ]), |
269 | | -+ ]); |
| 205 | ++ // Firmware is already downloaded to the device and SHA256 verified by the CGI script |
| 206 | ++ // Path returned by the CGI script: ${data.path || '/tmp/firmware.bin'} |
| 207 | ++ ui.showModal(_('Installing...'), [ |
| 208 | ++ E('div', { class: 'spinning' }, [ |
| 209 | ++ E('p', _('Installing the sysupgrade image...')), |
| 210 | ++ E('p', |
| 211 | ++ _('Once the image is written, the system will reboot.') |
| 212 | ++ + ' ' + |
| 213 | ++ _('This should take at least a minute, so please wait for the login screen.') |
| 214 | ++ ), |
| 215 | ++ E('b', _('While you are waiting, do not unpower device!')), |
| 216 | ++ ]), |
| 217 | ++ ]); |
270 | 218 | + |
271 | | -+ L.resolveDefault(callUpgradeStart(keep), {}).then((response) => { |
272 | | -+ // Wait 10 seconds before we try to reconnect... |
273 | | -+ let hosts = keep ? [] : ['192.168.1.1', 'openwrt.lan']; |
274 | | -+ setTimeout(() => { ui.awaitReconnect(...hosts); }, 10000); |
275 | | -+ }); |
276 | | -+ } |
| 219 | ++ L.resolveDefault(callUpgradeStart(keep), {}).then((response) => { |
| 220 | ++ // Wait 10 seconds before we try to reconnect... |
| 221 | ++ let hosts = keep ? [] : ['192.168.1.1', 'openwrt.lan']; |
| 222 | ++ setTimeout(() => { ui.awaitReconnect(...hosts); }, 10000); |
| 223 | ++ }); |
277 | 224 | + } else { |
278 | 225 | + ui.showModal(_('Error'), [ |
279 | 226 | + E('p', _('Unexpected response from firmware download script')), |
|
0 commit comments