1
0
mirror of https://github.com/j-a-n/raspberrymatic-addon-rmupdate.git synced 2023-10-10 13:37:40 +02:00
raspberrymatic-addon-rmupdate/addon/www/index.html

504 lines
20 KiB
HTML
Raw Normal View History

2017-03-24 19:57:23 +01:00
<!DOCTYPE HTML>
<!--
RaspMatic update addon
Copyright (C) 2017 Jan Schneider <oss@janschneider.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
2018-01-23 00:34:09 +01:00
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/8.1.0/i18next.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-i18next/1.2.0/jquery-i18next.min.js" ></script>
2017-03-24 19:57:23 +01:00
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.css" integrity="sha256-wT6CFc7EKRuf7uyVfi+MQNHUzojuHN2pSw0YWFt2K5E=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.js" integrity="sha256-flVaeawsBV96vCHiLmXn03IRJym7+ZfcLVvUWONCas8=" crossorigin="anonymous"></script>
<style>
</style>
2018-01-23 00:34:09 +01:00
<title data-i18n="title">RaspberryMatic Update Addon</title>
2017-03-24 19:57:23 +01:00
<script>
2018-01-23 00:34:09 +01:00
var language = navigator.language || navigator.userLanguage;
2017-03-25 01:45:39 +01:00
var message_timer_id = null;
var running_installation = "";
2017-03-26 20:25:01 +02:00
var current_firmware = '?';
var latest_firmware = '?';
2017-03-25 01:45:39 +01:00
function display_message(type, html, millis) {
clear_message();
$('#message').html(html);
$('#message').attr('class', 'ui ' + type + ' message visible');
2017-03-26 00:26:39 +01:00
$('#message-log').html(html);
$('#message-log').attr('class', 'ui ' + type + ' message visible');
2017-03-25 01:45:39 +01:00
message_timer_id = setTimeout(clear_message, millis);
}
function clear_message() {
if (message_timer_id != null) {
clearTimeout(message_timer_id);
}
message_timer_id = null;
$('#message').html('');
$('#message').attr('class', 'ui message hidden');
2017-03-26 00:26:39 +01:00
$('#message-log').html('');
$('#message-log').attr('class', 'ui message hidden');
}
function default_error_callback(xhr, ajaxOptions, thrownError) {
console.error(xhr);
err = thrownError;
try {
obj = JSON.parse(xhr.responseText);
if (obj.error != null) {
err = obj.error;
}
}
catch(e) {
}
2018-01-23 00:34:09 +01:00
display_message('error', i18next.t('error_occurred', {'error': err}), 6000000);
2017-03-25 01:45:39 +01:00
}
function rest(method, path, data, success_callback, error_callback) {
if (!error_callback) {
2017-03-26 00:26:39 +01:00
error_callback = default_error_callback
2017-03-25 01:45:39 +01:00
}
$.ajax({
url: "rest.cgi?" + path,
type: method,
data: data,
context: document.body,
success: success_callback,
error: error_callback
});
}
2018-01-23 00:34:09 +01:00
function set_running_installation(installation_info, error) {
//console.info("set_running_installation: |" + installation_info + "|" + running_installation + "|" + error);
var firmware_regex = /firmware\s+(.*)/i;
if (running_installation && (!installation_info)) {
// Running installation finished
var match = firmware_regex.exec(running_installation);
if (match != null) {
var version = match[1];
$('[data-install-firmware-version="' + version + '"]').removeClass('loading');
$('[data-delete-version="' + version + '"]').removeClass('disabled');
}
2018-01-23 00:34:09 +01:00
if (error) {
$('#install-progress').progress("set error");
2018-01-23 00:34:09 +01:00
display_message('error', i18next.t('installation_failed', {'what': running_installation, 'error': error}), 6000000);
}
else {
$('#install-progress').progress("set success");
2018-01-23 00:34:09 +01:00
display_message('success', i18next.t('installation_success', {'what': running_installation}), 6000000);
}
$('#modal-log').modal('refresh');
$('#log-content').scrollTop($('#log-content').prop("scrollHeight"));
}
running_installation = installation_info;
if (running_installation) {
var match = firmware_regex.exec(running_installation);
if (match != null) {
var version = match[1];
$('[data-install-firmware-version="' + version + '"]').addClass('loading');
$('[data-delete-version="' + version + '"]').addClass('disabled');
}
}
}
2017-03-26 00:26:39 +01:00
function update_install_log() {
rest("GET", "/get_running_installation", null, function(installation_info) {
if (running_installation) {
if ($('#install-progress').progress("get percent") >= 95) {
$('#install-progress').progress("set percent", 20);
2018-01-23 00:34:09 +01:00
}
$('#install-progress').progress('increment');
if (installation_info != running_installation) {
if (installation_info == "") {
// Wait a while to handle potential errors
setTimeout(function() {
set_running_installation(installation_info);
}, 3000);
}
else {
set_running_installation(installation_info);
}
2018-01-23 00:34:09 +01:00
}
}
});
2017-03-26 00:26:39 +01:00
rest("GET", "/read_install_log", null, function(data) {
$('#log-content').html(data.replace(/\n/g, '<br />'));
2018-01-23 00:34:09 +01:00
//$('#modal-log').modal('refresh');
2017-03-26 00:26:39 +01:00
$('#log-content').scrollTop($('#log-content').prop("scrollHeight"));
if (running_installation) {
2017-03-26 00:26:39 +01:00
setTimeout(update_install_log, 1000);
}
});
}
2017-03-26 20:25:01 +02:00
function delete_firmware_image(version) {
rest("POST", "/delete_firmware_image", JSON.stringify({"version":version}),
function(data) {
2018-01-23 00:34:09 +01:00
display_message('success', i18next.t('delete_firmware_img_success', {'version': version}), 5000);
2017-03-26 20:25:01 +02:00
get_firmware_info();
}
);
}
2017-03-25 01:45:39 +01:00
function install_firmware(version) {
2017-03-26 00:26:39 +01:00
$('#log-content').html('');
$('#install-progress').progress("reset");
2017-03-25 01:45:39 +01:00
$('#modal-log').modal('show');
if (!running_installation) {
var reboot = $('#reboot-after-install').is(':checked');
var dryrun = $('#dryrun').is(':checked');
2018-01-23 00:34:09 +01:00
display_message('info', i18next.t('installing_firmware', {'version': version}), 6000000);
clear_message();
2018-01-23 00:34:09 +01:00
set_running_installation("Firmware " + version);
rest("POST", "/start_install_firmware", JSON.stringify({"language": language, "version":version, "reboot":reboot, "dryrun":dryrun}),
function(data) {
// We are not expecting a response
},
function(xhr, ajaxOptions, thrownError) {
2018-01-21 01:47:07 +01:00
console.error("Firmware installation error: " + thrownError + ": " + xhr.responseText);
//$('#modal-log').modal('hide');
2018-01-23 00:34:09 +01:00
set_running_installation("", thrownError + ": " + xhr.responseText);
2017-03-26 20:25:01 +02:00
}
);
}
2017-03-26 00:26:39 +01:00
setTimeout(update_install_log, 1000);
2017-03-25 01:45:39 +01:00
}
2017-03-26 20:25:01 +02:00
function install_latest_firmware() {
if (latest_firmware && latest_firmware != '?') {
install_firmware(latest_firmware);
}
}
function get_firmware_info() {
2018-01-21 01:47:07 +01:00
$('#dimmer-firmware-info').addClass('active');
2017-03-25 01:45:39 +01:00
rest("GET", "/get_firmware_info", null, function(data) {
2018-01-21 01:47:07 +01:00
$('#firmware-info tbody').empty();
2017-03-25 01:45:39 +01:00
data.forEach(function(fw) {
2017-03-26 20:25:01 +02:00
if (fw.latest) latest_firmware = fw.version;
if (fw.installed) current_firmware = fw.version;
var color = 'yellow';
if (fw.latest) color = 'green';
if (fw.installed) color = 'gray';
2017-03-25 01:45:39 +01:00
var disabled = (fw.image || fw.url ? '' : 'disabled');
2018-01-23 00:34:09 +01:00
var binstall = $('<div class="ui '+ color +' basic '+ disabled +' button">').attr('data-install-firmware-version', fw.version).append($('<i class="sign in icon">'), i18next.t('install'));
2017-03-25 01:45:39 +01:00
binstall.click(function() {
install_firmware(this.getAttribute('data-install-firmware-version'));
2017-03-25 01:45:39 +01:00
});
2017-03-26 20:25:01 +02:00
var bcls = '';
if (!fw.image) bcls = 'disabled';
if (fw.version == running_installation) bcls = 'loading';
2018-01-23 00:34:09 +01:00
var bdelete = $('<div class="ui orange basic '+ bcls +' button">').attr('data-delete-version', fw.version).append($('<i class="delete icon">'), i18next.t('delete_download'));
2017-03-26 20:25:01 +02:00
bdelete.click(function() {
delete_firmware_image(this.getAttribute('data-delete-version'));
});
2017-03-25 01:45:39 +01:00
var available = (fw.url ? 'checked=""' : '')
var downloaded = (fw.image ? 'checked=""' : '')
2017-03-26 20:25:01 +02:00
var cls = '';
if (fw.installed) cls = ' class="warning"';
if (fw.latest) cls = ' class="positive"';
2018-01-21 01:47:07 +01:00
$("#firmware-info tbody").append($('<tr' + cls + '>').append(
2018-01-23 00:34:09 +01:00
$('<td>').append($('<a>', {text: fw.version, title: i18next.t('open_release_info'), href: fw.info_url, target: "_blank"})),
2017-03-25 01:45:39 +01:00
$('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+available+'>'),$('<label></label>'))),
$('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" '+downloaded+'>'),$('<label></label>'))),
2017-03-26 20:25:01 +02:00
$('<td class="center aligned">').append(bdelete, binstall)
2017-03-25 01:45:39 +01:00
));
});
2017-03-26 20:25:01 +02:00
var color = "#d01919";
if (current_firmware == latest_firmware) {
color = "#21BA45";
}
$("#firmware-summary").empty();
$("#firmware-summary").append(
2018-01-23 00:34:09 +01:00
$('<div class="sub header">').html(i18next.t('current_installed_version') + ': <span style="color:'+ color +'">' + current_firmware + '</span>'),
$('<div class="sub header">').html(i18next.t('latest_available_version') + ': ' + latest_firmware)
2017-03-26 20:25:01 +02:00
);
if (current_firmware != latest_firmware) {
$("#firmware-summary").append(
2018-01-23 00:34:09 +01:00
$('<div class="ui green basic button" style="margin-top:20px; margin-bottom:20px;">').click(install_latest_firmware).append($('<i class="sign in icon">'), i18next.t('install_latest_firmware'))
2017-03-26 20:25:01 +02:00
);
}
rest("GET", "/get_running_installation", null, function(installation_info) {
set_running_installation(installation_info);
});
2018-01-21 01:47:07 +01:00
$('#dimmer-firmware-info').removeClass('active');
2017-03-25 01:45:39 +01:00
});
2017-03-26 20:25:01 +02:00
}
function get_system_info() {
rest("GET", "/get_system_info", null, function(data) {
$("#system-info").empty();
$("#system-info").append(
2018-01-23 00:34:09 +01:00
$('<div class="sub header">').html(i18next.t('current_root_partiton', {'root_partition': data.root_partition}))
);
});
}
2018-01-21 01:47:07 +01:00
function install_addon(addon_id) {
if (!running_installation) {
display_message('info', 'Installing addon ' + addon_id + '.', 6000000);
$('[data-update-addon-id="' + addon_id + '"]').addClass('loading');
$('[data-update-addon-id="' + addon_id + '"]').addClass('disabled');
rest("POST", "/install_addon", JSON.stringify({"addon_id":addon_id}),
function(data) {
//console.info(data);
$('[data-update-addon-id="' + addon_id + '"]').removeClass('loading');
$('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled');
$('#tr-' + addon_id).removeClass('warning');
$('#tr-' + addon_id).addClass('positive');
$('#button-update-' + addon_id).removeClass('green');
$('#button-update-' + addon_id).addClass('gray');
$('#label-version-' + addon_id).text($('#label-available-version-' + addon_id).text());
display_message('success', data, 6000000);
},
function(xhr, ajaxOptions, thrownError) {
console.error("Addon installation error: " + thrownError + ": " + xhr.responseText);
$('[data-update-addon-id="' + addon_id + '"]').removeClass('loading');
$('[data-update-addon-id="' + addon_id + '"]').removeClass('disabled');
default_error_callback(xhr, ajaxOptions, thrownError);
}
);
}
}
function get_addon_info() {
2018-01-21 01:47:07 +01:00
$('#dimmer-addon-info').addClass('active');
rest("GET", "/get_addon_info", null, function(data) {
2018-01-21 01:47:07 +01:00
$('#addon-info tbody').empty();
data.forEach(function(addon) {
2018-01-21 01:47:07 +01:00
var color = 'gray';
if (addon.available_version && (addon.version != addon.available_version)) color = 'green';
var disabled = ((addon.available_version && addon.download_url) ? '' : 'disabled');
var bupdate = $('<div class="ui '+ color +' basic '+ disabled +' button" id="button-update-' + addon.id + '">')
.attr('data-update-addon-id', addon.id)
.attr('data-update-addon-available-version', addon.available_version)
2018-01-23 00:34:09 +01:00
.append($('<i class="sign in icon">'), (addon.version == addon.available_version) ? i18next.t('reinstall') : i18next.t('update'));
2018-01-21 01:47:07 +01:00
bupdate.click(function() {
install_addon(this.getAttribute('data-update-addon-id'));
});
disabled = ((addon.config_url) ? '' : 'disabled');
var bconfig = $('<div class="ui blue basic '+ disabled +' button">')
.attr('data-addon-config-url', addon.config_url)
2018-01-23 00:34:09 +01:00
.append($('<i class="setting icon">'), i18next.t('open_config'));
2018-01-21 01:47:07 +01:00
bconfig.click(function() {
var win = window.open(this.getAttribute('data-addon-config-url'), '_blank');
win.focus();
});
var cls = (((!addon.available_version) || (addon.version == addon.available_version)) ? "positive" : "warning");
var available_version = ((addon.available_version) ? addon.available_version : "?");
$("#addon-info tbody").append($('<tr class="' + cls + '" id="tr-' + addon.id + '">').append(
$('<td>').append($('<label>' + addon.name + '</label>')),
2018-01-21 01:47:07 +01:00
$('<td>').append($('<label id="label-version-' + addon.id + '">' + addon.version + '</label>')),
$('<td>').append($('<label id="label-available-version-' + addon.id + '">' + available_version + '</label>')),
$('<td class="center aligned">').append(bupdate, bconfig)
));
});
2018-01-21 01:47:07 +01:00
$('#dimmer-addon-info').removeClass('active');
});
}
2017-03-26 20:25:01 +02:00
$(document).ready(function() {
2018-01-23 00:34:09 +01:00
i18next.init({
lng: language,
fallbackLng: 'en',
resources: {
en: {
translation: {
title: 'System update',
system_info: 'System information',
current_root_partiton: 'Current root partition: {{root_partition}}',
firmwares: 'Firmwares',
current_installed_version: 'Current installed version',
latest_available_version: 'Latest available version',
loading: 'Loading',
version: 'Version',
available: 'Available',
downloaded: 'Downloaded',
action: 'Action',
delete_download: 'Delete download',
install: 'Install',
installation_log: 'Installation log',
open_release_info: 'Open release info',
perform_trial_run: 'Perform a trial run with no changes made',
reboot_after_install: 'Reboot system after installation',
addons: 'Addons',
addon_name: 'Addon name',
installed_version: 'Installed version',
available_version: 'Available version',
reinstall: 'Reinstall',
update: 'Update',
open_config: 'Open config',
error_occurred: 'An error occurred: {{error}}',
installation_failed: 'Failed to install {{what}}: {{error}}',
installation_success: '{{what}} successfully installed.',
delete_firmware_img_success: 'Firmware image {{version}} successfully deleted.',
installing_firmware: 'Installing firmware {{version}}.',
install_latest_firmware: 'Install latest firmware',
system_not_upgradeable: 'System not upgradeable or filesystem to small!'
}
},
de: {
translation: {
title: 'System-Aktualisierung',
system_info: 'System-Informationen',
current_root_partiton: 'Aktuelle Root-Partition: {{root_partition}}',
firmwares: 'Firmwares',
current_installed_version: 'Momentan installierte Version',
latest_available_version: 'Aktuellste verfügbare Version',
loading: 'Lade',
version: 'Version',
available: 'Verfügbar',
downloaded: 'Heruntergeladen',
action: 'Aktion',
delete_download: 'Download löschen',
install: 'Installieren',
installation_log: 'Installations-Protokoll',
open_release_info: 'Release-Informationen öffnen',
perform_trial_run: 'Testlauf durchführen ohne Änderungen durchzuführen',
reboot_after_install: 'System nach Installation neu starten',
addons: 'Zusatzsoftware',
addon_name: 'Name des Addons',
installed_version: 'Installierte Version',
available_version: 'Verfügbare Version',
reinstall: 'Neu installieren',
update: 'Aktualisieren',
open_config: 'Konfiguration öffnen',
error_occurred: 'Ein Fehler ist aufgetreten: {{error}}',
installation_failed: 'Fehler beim Installieren von {{what}}: {{error}}',
installation_success: '{{what}} erfolgreich installiert.',
delete_firmware_img_success: 'Firmware-Image {{version}} erfolgreich gelöscht.',
installing_firmware: 'Installiere Firmware {{version}}.',
install_latest_firmware: 'Aktuellste Firmware installieren',
system_not_upgradeable: 'System nicht aktualisierbar oder Dateisystem zu klein!'
}
}
}
}, function(err, t) {
jqueryI18next.init(i18next, $);
$('title').localize();
$('h1').localize();
$('h2').localize();
$('div').localize();
$('th').localize();
$('label').localize();
});
2017-03-26 20:25:01 +02:00
rest("GET", "/version", null, function(version) {
document.title = document.title + " " + version;
});
rest("GET", "/is_system_upgradeable", null, function(upgradeable) {
if (!upgradeable) {
2018-01-23 00:34:09 +01:00
display_message('error', i18next.t('system_not_upgradeable'), 6000000);
2017-03-26 20:25:01 +02:00
}
});
get_system_info();
2017-03-26 20:25:01 +02:00
get_firmware_info();
2018-01-21 01:47:07 +01:00
get_addon_info();
2017-03-25 01:45:39 +01:00
});
2017-03-24 19:57:23 +01:00
</script>
</head>
<body>
<div style="padding-top: 5vw; padding-bottom: 5vw" class="ui container">
2018-01-23 00:34:09 +01:00
<h1 class="ui header" data-i18n="title"></h1>
2017-03-25 01:45:39 +01:00
<div id="message" class="ui message hidden">
</div>
2018-01-23 00:34:09 +01:00
<h2 class="ui dividing header" data-i18n="system_info"></h2>
<div class="content" id="system-info">
</div>
2018-01-23 00:34:09 +01:00
<h2 class="ui dividing header" data-i18n="firmwares"></h2>
2017-03-26 20:25:01 +02:00
<div class="content" id="firmware-summary">
</div>
2018-01-21 01:47:07 +01:00
<div class="dimmable">
<div id="dimmer-firmware-info" class="ui active inverted dimmer">
2018-01-23 00:34:09 +01:00
<div class="ui loader" data-i18n="loading"></div>
2018-01-21 01:47:07 +01:00
</div>
<table id="firmware-info" class="ui celled stackable table">
<thead>
<tr>
2018-01-23 00:34:09 +01:00
<th data-i18n="version"></th>
<th class="center aligned" data-i18n="available"></th>
<th class="center aligned" data-i18n="downloaded"></th>
<th class="center aligned" data-i18n="action"></th>
2018-01-21 01:47:07 +01:00
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="ui checkbox">
<input id="dryrun" type="checkbox">
2018-01-23 00:34:09 +01:00
<label data-i18n="perform_trial_run"></label>
2018-01-21 01:47:07 +01:00
</div>
<br />
<div class="ui checkbox">
<input id="reboot-after-install" type="checkbox" checked="checked">
2018-01-23 00:34:09 +01:00
<label data-i18n="reboot_after_install"></label>
2018-01-21 01:47:07 +01:00
</div>
2017-06-16 22:18:28 +02:00
</div>
2018-01-21 01:47:07 +01:00
2018-01-23 00:34:09 +01:00
<h2 class="ui dividing header" data-i18n="addons"></h2>
2018-01-21 01:47:07 +01:00
<div class="dimmable">
<div id="dimmer-addon-info" class="ui active inverted dimmer">
2018-01-23 00:34:09 +01:00
<div class="ui loader" data-i18n="loading"></div>
2018-01-21 01:47:07 +01:00
</div>
<table id="addon-info" class="ui celled stackable table">
<thead>
<tr>
2018-01-23 00:34:09 +01:00
<th data-i18n="addon_name"></th>
<th data-i18n="installed_version"></th>
<th data-i18n="available_version"></th>
<th class="center aligned" data-i18n="action"></th>
2018-01-21 01:47:07 +01:00
</tr>
</thead>
<tbody>
</tbody>
</table>
2017-03-26 20:25:01 +02:00
</div>
2018-01-21 01:47:07 +01:00
2017-03-25 01:45:39 +01:00
</div>
2018-01-23 00:34:09 +01:00
<div style="height:60vh;" id="modal-log" class="ui modal">
2017-03-25 01:45:39 +01:00
<i class="close icon"></i>
2018-01-23 00:34:09 +01:00
<div class="header" data-i18n="installation_log">
2017-03-25 01:45:39 +01:00
</div>
<div class="ui bottom attached progress" data-value="0" data-total="25" id="install-progress">
<div class="bar"></div>
</div>
2017-03-26 00:26:39 +01:00
<div class="content">
<div id="message-log" class="ui message hidden">
</div>
<div class="content">
<pre style="height:25vh; overflow-x:hidden; overflow-y:auto; white-space: pre-wrap;" id="log-content">
</pre>
</div>
2017-03-25 01:45:39 +01:00
</div>
</div>
2017-03-24 19:57:23 +01:00
</body>
</html>