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
2018-01-21 01:53:55 +01:00

390 lines
15 KiB
HTML

<!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>
<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>
<title>RaspberryMatic Update Addon</title>
<script>
var message_timer_id = null;
var running_installation = "";
var current_firmware = '?';
var latest_firmware = '?';
function display_message(type, html, millis) {
clear_message();
$('#message').html(html);
$('#message').attr('class', 'ui ' + type + ' message visible');
$('#message-log').html(html);
$('#message-log').attr('class', 'ui ' + type + ' message visible');
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');
$('#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) {
}
display_message('error', 'An error occurred: ' + err, 6000000);
}
function rest(method, path, data, success_callback, error_callback) {
if (!error_callback) {
error_callback = default_error_callback
}
$.ajax({
url: "rest.cgi?" + path,
type: method,
data: data,
context: document.body,
success: success_callback,
error: error_callback
});
}
function set_running_installation(installation_info) {
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');
}
msg = running_installation + ' successfully installed.'
display_message('success', msg, 6000000);
}
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');
}
}
}
function update_install_log() {
rest("GET", "/get_running_installation", null, function(installation_info) {
set_running_installation(installation_info);
});
rest("GET", "/read_install_log", null, function(data) {
$('#log-content').html(data.replace(/\n/g, '<br />'));
$('#modal-log').modal('refresh');
$('#log-content').scrollTop($('#log-content').prop("scrollHeight"));
if (running_installation) {
setTimeout(update_install_log, 1000);
}
});
}
function delete_firmware_image(version) {
rest("POST", "/delete_firmware_image", JSON.stringify({"version":version}),
function(data) {
display_message('success', 'Firmware image ' + version + ' successfully deleted.', 5000);
get_firmware_info();
}
);
}
function install_firmware(version) {
$('#log-content').html('');
$('#modal-log').modal('show');
if (!running_installation) {
var reboot = $('#reboot-after-install').is(':checked');
var dryrun = $('#dryrun').is(':checked');
display_message('info', 'Installing firmware ' + version + '.', 6000000);
clear_message();
rest("POST", "/start_install_firmware", JSON.stringify({"version":version, "reboot":reboot, "dryrun":dryrun}),
function(data) {
// We are not expecting a response
},
function(xhr, ajaxOptions, thrownError) {
console.error("Firmware installation error: " + thrownError + ": " + xhr.responseText);
$('[data-install-firmware-version="' + running_installation + '"]').removeClass('loading');
//$('#modal-log').modal('hide');
if (running_installation) {
//get_firmware_info();
default_error_callback(xhr, ajaxOptions, thrownError);
}
set_running_installation("");
}
);
}
setTimeout(update_install_log, 1000);
}
function install_latest_firmware() {
if (latest_firmware && latest_firmware != '?') {
install_firmware(latest_firmware);
}
}
function get_firmware_info() {
$('#dimmer-firmware-info').addClass('active');
rest("GET", "/get_firmware_info", null, function(data) {
$('#firmware-info tbody').empty();
data.forEach(function(fw) {
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';
var disabled = (fw.image || fw.url ? '' : 'disabled');
var binstall = $('<div class="ui '+ color +' basic '+ disabled +' button">').attr('data-install-firmware-version', fw.version).append($('<i class="sign in icon">'), 'install');
binstall.click(function() {
install_firmware(this.getAttribute('data-install-firmware-version'));
});
var bcls = '';
if (!fw.image) bcls = 'disabled';
if (fw.version == running_installation) bcls = 'loading';
var bdelete = $('<div class="ui orange basic '+ bcls +' button">').attr('data-delete-version', fw.version).append($('<i class="delete icon">'), 'delete download');
bdelete.click(function() {
delete_firmware_image(this.getAttribute('data-delete-version'));
});
var available = (fw.url ? 'checked=""' : '')
var downloaded = (fw.image ? 'checked=""' : '')
var cls = '';
if (fw.installed) cls = ' class="warning"';
if (fw.latest) cls = ' class="positive"';
$("#firmware-info tbody").append($('<tr' + cls + '>').append(
$('<td>').append($('<a>', {text: fw.version, title: 'Open release info', href: fw.info_url, target: "_blank"})),
$('<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>'))),
$('<td class="center aligned">').append(bdelete, binstall)
));
});
var color = "#d01919";
if (current_firmware == latest_firmware) {
color = "#21BA45";
}
$("#firmware-summary").empty();
$("#firmware-summary").append(
$('<div class="sub header">').html('Current installed version: <span style="color:'+ color +'">' + current_firmware + '</span>'),
$('<div class="sub header">').html('Latest available version: ' + latest_firmware)
);
if (current_firmware != latest_firmware) {
$("#firmware-summary").append(
$('<div class="ui green basic button" style="margin-top:20px; margin-bottom:20px;">').click(install_latest_firmware).append($('<i class="sign in icon">'), 'Install latest firmware')
);
}
rest("GET", "/get_running_installation", null, function(installation_info) {
set_running_installation(installation_info);
});
$('#dimmer-firmware-info').removeClass('active');
});
}
function get_system_info() {
rest("GET", "/get_system_info", null, function(data) {
$("#system-info").empty();
$("#system-info").append(
$('<div class="sub header">').html('Current root partition: ' + data.root_partition)
);
});
}
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() {
$('#dimmer-addon-info').addClass('active');
rest("GET", "/get_addon_info", null, function(data) {
$('#addon-info tbody').empty();
data.forEach(function(addon) {
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)
.append($('<i class="sign in icon">'), (addon.version == addon.available_version) ? "reinstall" : "update");
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)
.append($('<i class="setting icon">'), 'open config');
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>')),
$('<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)
));
});
$('#dimmer-addon-info').removeClass('active');
});
}
$(document).ready(function() {
rest("GET", "/version", null, function(version) {
document.title = document.title + " " + version;
});
rest("GET", "/is_system_upgradeable", null, function(upgradeable) {
if (!upgradeable) {
var message = 'System not upgradeable or filesystem to small!<br />';
message += 'Please download and install adjusted RaspMatic image from <a href="https://github.com/j-a-n/raspberrymatic-addon-rmupdate">RaspMatic image</a> first.';
display_message('error', message, 6000000);
}
});
get_system_info();
get_firmware_info();
get_addon_info();
});
</script>
</head>
<body>
<div style="padding-top: 5vw; padding-bottom: 5vw" class="ui container">
<h1 class="ui header">RaspberryMatic Update</h1>
<div id="message" class="ui message hidden">
</div>
<h2 class="ui dividing header">System info</h2>
<div class="content" id="system-info">
</div>
<h2 class="ui dividing header">Firmwares</h2>
<div class="content" id="firmware-summary">
</div>
<div class="dimmable">
<div id="dimmer-firmware-info" class="ui active inverted dimmer">
<div class="ui loader">Loading</div>
</div>
<table id="firmware-info" class="ui celled stackable table">
<thead>
<tr>
<th>Version</th>
<th class="center aligned">Available</th>
<th class="center aligned">Downloaded</th>
<th class="center aligned">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="ui checkbox">
<input id="dryrun" type="checkbox">
<label>Perform a trial run with no changes made</label>
</div>
<br />
<div class="ui checkbox">
<input id="reboot-after-install" type="checkbox" checked="checked">
<label>Reboot system after installation</label>
</div>
</div>
<h2 class="ui dividing header">Addons</h2>
<div class="dimmable">
<div id="dimmer-addon-info" class="ui active inverted dimmer">
<div class="ui loader">Loading</div>
</div>
<table id="addon-info" class="ui celled stackable table">
<thead>
<tr>
<th>Addon name</th>
<th>Installed version</th>
<th class="center aligned">Available version</th>
<th class="center aligned">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div style="height:80%" id="modal-log" class="ui modal">
<i class="close icon"></i>
<div class="header">
Installation log
</div>
<div class="content">
<div id="message-log" class="ui message hidden">
</div>
<pre style="max-height:80%; overflow-x:hidden; overflow-y:auto; white-space: pre-wrap;" id="log-content" class="content">
</pre>
</div>
</div>
</body>
</html>