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 >
< 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 >
2017-03-25 01:45:39 +01:00
var message_timer_id = null;
2017-03-26 20:25:01 +02:00
var installation_running = "";
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) {
}
display_message('error', 'An error occurred: ' + 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
});
}
2017-06-18 23:27:29 +02:00
function installation_finished() {
if (installation_running) {
var version = installation_running;
$('[data-install-version="' + version + '"]').removeClass('loading');
installation_running = "";
msg = 'Firmware ' + version + ' successfully installed.'
display_message('success', msg, 6000000);
}
}
2017-03-26 00:26:39 +01:00
function update_install_log() {
rest("GET", "/read_install_log", null, function(data) {
2017-06-18 23:27:29 +02:00
var regex_success = /INSTALL_FIRMWARE_SUCCESS\n/g;
if (regex_success.test(data)) {
installation_finished();
}
data = data.replace(regex_success, "");
2017-03-26 00:26:39 +01:00
$('#log-content').html(data.replace(/\n/g, '< br / > '));
$('#modal-log').modal('refresh');
$('#log-content').scrollTop($('#log-content').prop("scrollHeight"));
2017-03-26 20:25:01 +02:00
if (installation_running) {
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) {
display_message('success', 'Firmware image ' + version + ' successfully deleted.', 5000);
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('');
2017-03-25 01:45:39 +01:00
$('#modal-log').modal('show');
2017-03-26 20:25:01 +02:00
if (installation_running) {
return false;
}
installation_running = version;
$('[data-install-version="' + installation_running + '"]').addClass('loading');
var reboot = $('#reboot-after-install').is(':checked');
2017-06-16 22:18:28 +02:00
var dryrun = $('#dryrun').is(':checked');
2017-03-26 20:25:01 +02:00
display_message('info', 'Installing firmware ' + version + '.', 6000000);
clear_message();
2017-06-16 22:18:28 +02:00
rest("POST", "/start_install_firmware", JSON.stringify({"version":version, "reboot":reboot, "dryrun":dryrun}),
2017-03-26 00:26:39 +01:00
function(data) {
2017-06-20 02:01:21 +02:00
// We are not expecting a response
console.log("Firmware installation finished.")
2017-06-18 23:27:29 +02:00
installation_finished();
2017-03-26 00:26:39 +01:00
},
function(xhr, ajaxOptions, thrownError) {
2017-06-20 02:01:21 +02:00
console.error("Firmware installation error.")
2017-03-26 20:25:01 +02:00
$('[data-install-version="' + installation_running + '"]').removeClass('loading');
2017-03-26 00:26:39 +01:00
//$('#modal-log').modal('hide');
2017-06-18 23:27:29 +02:00
if (installation_running) {
//get_firmware_info();
2017-03-26 20:25:01 +02:00
default_error_callback(xhr, ajaxOptions, thrownError);
2017-06-19 00:21:07 +02:00
installation_running = "";
2017-03-26 20:25:01 +02:00
}
2017-03-25 01:45:39 +01: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() {
2017-03-25 01:45:39 +01:00
rest("GET", "/get_firmware_info", null, function(data) {
$('#firmware_info tbody').empty();
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');
2017-03-26 20:25:01 +02:00
var binstall = $('< div class = "ui '+ color +' basic '+ disabled +' button" > ').attr('data-install-version', fw.version).append($('< i class = "sign in icon" > '), 'install');
2017-03-25 01:45:39 +01:00
binstall.click(function() {
2017-03-26 20:25:01 +02:00
install_firmware(this.getAttribute('data-install-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 == installation_running) 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'));
});
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"';
$("#firmware_info tbody").append($('< tr ' + cls + ' > ').append(
2017-05-02 21:53:23 +02:00
$('< td > ').append($('< a > ', {text: fw.version, title: '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(
$('< div class = "sub header" > ').html('Current installed version: < span style = "color:'+ color +'" > ' + current_firmware + '< / span > '),
2017-06-20 02:01:21 +02:00
$('< div class = "sub header" > ').html('Latest available version: ' + latest_firmware)
2017-03-26 20:25:01 +02:00
);
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')
);
}
2017-03-25 01:45:39 +01:00
});
2017-03-26 20:25:01 +02:00
}
2017-06-20 02:01:21 +02:00
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)
);
});
}
2017-03-26 20:25:01 +02:00
$(document).ready(function() {
rest("GET", "/version", null, function(version) {
document.title = document.title + " " + version;
});
rest("GET", "/is_system_upgradeable", null, function(upgradeable) {
if (!upgradeable) {
2017-06-20 02:01:21 +02:00
var message = 'System not upgradeable or filesystem to small!< br / > ';
2017-03-26 20:59:14 +02:00
message += 'Please download and install adjusted RaspMatic image from < a href = "https://github.com/j-a-n/raspberrymatic-addon-rmupdate" > RaspMatic image< / a > first.';
2017-03-26 20:25:01 +02:00
display_message('error', message, 6000000);
}
});
2017-06-20 02:01:21 +02:00
get_system_info();
2017-03-26 20:25:01 +02:00
get_firmware_info();
2017-03-25 01:45:39 +01:00
});
2017-03-24 19:57:23 +01:00
< / script >
< / head >
< body >
2017-03-25 01:45:39 +01:00
< div style = "padding-top: 5vw" class = "ui container" >
< h1 class = "ui header" > RaspberryMatic Update< / h1 >
< div id = "message" class = "ui message hidden" >
< / div >
2017-06-20 02:01:21 +02:00
< h2 class = "ui dividing header" > System info< / h2 >
< div class = "content" id = "system-info" >
< / div >
2017-03-25 01:45:39 +01:00
< h2 class = "ui dividing header" > Firmwares< / h2 >
2017-03-26 20:25:01 +02:00
< div class = "content" id = "firmware-summary" >
< / div >
2017-03-25 01:45:39 +01:00
< 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 >
2017-06-16 22:18:28 +02:00
< div class = "ui checkbox" >
< input id = "dryrun" type = "checkbox" >
< label > Perform a trial run with no changes made< / label >
< / div >
< br / >
2017-06-20 02:01:21 +02:00
< div class = "ui checkbox" >
2017-03-26 20:25:01 +02:00
< input id = "reboot-after-install" type = "checkbox" checked = "checked" >
< label > Reboot system after installation< / label >
< / div >
2017-03-25 01:45:39 +01:00
< / div >
2017-03-26 00:26:39 +01:00
< div style = "height:80%" id = "modal-log" class = "ui modal" >
2017-03-25 01:45:39 +01:00
< i class = "close icon" > < / i >
< div class = "header" >
2017-03-26 20:25:01 +02:00
Installation log
2017-03-25 01:45:39 +01:00
< / div >
2017-03-26 00:26:39 +01:00
< 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 >
2017-03-25 01:45:39 +01:00
< / div >
< / div >
2017-03-24 19:57:23 +01:00
< / body >
< / html >