Add abililty to view all upgrade logs

This commit is contained in:
Taylor Helsper 2021-10-09 19:27:50 -05:00
parent 11cd86a4f8
commit f663eeb916
3 changed files with 117 additions and 32 deletions

View File

@ -16,6 +16,7 @@ import subprocess
import random
import string
import redis
import re
try:
import qrcode
@ -204,20 +205,43 @@ def upgrade_device_beta():
def did_upgrade_fail():
return os.path.isfile("/mnt/hdd/mynode/settings/upgrade_error")
def get_recent_upgrade_logs():
logs=""
current_version = get_current_version()
for i in range(1,6):
filename = "/home/admin/upgrade_logs/upgrade_log_{}_post_{}.txt".format(current_version, i)
try:
with open(filename, "r") as f:
logs = logs + "===========================================================\n"
logs = logs + "=== Upgrade Attempt #{}\n".format(i)
logs = logs + "===========================================================\n\n\n"
logs = logs + f.read().decode("utf8")
except:
pass
return logs
def cleanup_log(log):
log = re.sub("(product_key|PRODUCT_KEY)=[0-9A-Z]+", "product_key=************", log)
return log
def get_recent_upgrade_log():
log = get_file_contents("/home/admin/upgrade_logs/upgrade_log_latest.txt").decode("utf8")
return cleanup_log(log)
def get_all_upgrade_logs():
log_list = []
folder = "/home/admin/upgrade_logs/"
log_id = 0
# Add latest upgrade log
if os.path.isfile( os.path.join(folder, "upgrade_log_latest.txt") ):
log = {}
log["id"] = log_id
log["name"] = "Latest Upgrade"
modTimeSeconds = os.path.getmtime( os.path.join(folder, "upgrade_log_latest.txt") )
log["date"] = time.strftime('%Y-%m-%d', time.localtime(modTimeSeconds))
log["log"] = get_recent_upgrade_log()
log_list.append( log )
log_id += 1
# Add file logs
for f in os.listdir(folder):
fullpath = os.path.join(folder, f)
if os.path.isfile( fullpath ):
log = {}
log["id"] = log_id
log["name"] = f
modTimeSeconds = os.path.getmtime(fullpath)
log["date"] = time.strftime('%Y-%m-%d', time.localtime(modTimeSeconds))
log["log"] = cleanup_log( get_file_contents(fullpath).decode("utf8") )
log_list.append( log )
log_id += 1
return log_list
def has_checkin_error():
return os.path.isfile("/tmp/check_in_error")

View File

@ -53,8 +53,13 @@ def page_settings():
logout_time_days, logout_time_hours = get_flask_session_timeout()
t1 = get_system_time_in_ms()
all_logs = get_all_upgrade_logs()
t2 = get_system_time_in_ms()
templateData = {
"title": "myNode Settings",
"load_time": t2-t1,
"apps": get_all_applications(order_by="alphabetic"),
"password_message": "",
"current_version": current_version,
@ -63,7 +68,8 @@ def page_settings():
"latest_beta_version": latest_beta_version,
"has_checkin_error": has_checkin_error(),
"upgrade_error": did_upgrade_fail(),
"upgrade_logs": get_recent_upgrade_logs(),
"upgrade_log": get_recent_upgrade_log(),
"upgrade_logs": get_all_upgrade_logs(),
"serial_number": serial_number,
"device_type": device_type,
"device_arch": device_arch,
@ -174,7 +180,7 @@ def page_status():
"latest_beta_version": latest_beta_version,
"has_checkin_error": has_checkin_error(),
"upgrade_error": did_upgrade_fail(),
"upgrade_logs": get_recent_upgrade_logs(),
"upgrade_logs": get_recent_upgrade_log(),
"serial_number": serial_number,
"device_type": device_type,
"device_arch": device_arch,
@ -332,12 +338,22 @@ def upgrade_beta_page():
def get_upgrade_log_page():
check_logged_in()
log = get_file_contents("/home/admin/upgrade_logs/upgrade_log_latest.txt")
log = get_file_contents("/home/admin/upgrade_logs/upgrade_log_latest.txt").decode("utf8")
if (log == "ERROR"):
log = "No log file found"
log = cleanup_log(log)
return log
@mynode_settings.route("/settings/clear-upgrade-logs")
def clear_upgrade_logs_page():
check_logged_in()
os.system("rm -f /home/admin/upgrade_logs/*")
flash("Upgrade Logs Cleared", category="message")
return redirect("/settings")
@mynode_settings.route("/settings/upgrade-test")
def upgrade_page_test():
check_logged_in()

View File

@ -241,31 +241,36 @@
});
showing_upgrade_log=0;
$("#show_upgrade_status").on("click", function() {
$("#show_upgrade_logs").on("click", function() {
if (showing_upgrade_log == 0) {
$("#show_upgrade_status").html("Hide Upgrade Log");
$("#upgrade_status").show();
$("#show_upgrade_logs").html("Hide Upgrade Logs");
$("#upgrade_logs").show();
showing_upgrade_log = 1;
} else {
$("#show_upgrade_status").html("Show Upgrade Log");
$("#upgrade_status").hide();
$("#show_upgrade_logs").html("Show Upgrade Logs");
$("#upgrade_logs").hide();
showing_upgrade_log = 0;
}
});
showUpgradeLog(0);
showing_upgrade_beta_log=0;
$("#show_upgrade_status_beta").on("click", function() {
$("#show_upgrade_log_beta").on("click", function() {
if (showing_upgrade_beta_log == 0) {
$("#show_upgrade_status_beta").html("Hide Upgrade Log");
$("#upgrade_status_beta").show();
$("#show_upgrade_log_beta").html("Hide Upgrade Log");
$("#upgrade_log_beta").show();
showing_upgrade_beta_log = 1;
} else {
$("#show_upgrade_status_beta").html("Show Upgrade Log");
$("#upgrade_status_beta").hide();
$("#show_upgrade_log_beta").html("Show Upgrade Log");
$("#upgrade_log_beta").hide();
showing_upgrade_beta_log = 0;
}
});
$("#clear_upgrade_logs").on("click", function() {
window.location.href='/settings/clear-upgrade-logs';
});
$("#upgrade_changelog").on("click", function() {
$.get("https://raw.githubusercontent.com/mynodebtc/mynode/master/CHANGELOG")
.done(function( data ) {
@ -444,6 +449,18 @@
}
});
});
function hideAllUpgradeLogs() {
{% for f in upgrade_logs %}
$("#upgrade_log_{{f.id}}").hide();
$("#show_upgrade_log_{{f.id}}").html("Show");
{% endfor %}
}
function showUpgradeLog(id) {
hideAllUpgradeLogs()
$("#upgrade_log_"+id).show();
$("#show_upgrade_log_"+id).html("Showing");
}
</script>
</head>
@ -474,7 +491,7 @@
<td>{{latest_version}}</td>
<td>
&nbsp;<a href="/settings/get-latest-version" class="ui-button ui-widget ui-corner-all settings_button_small">Check for Updates</a>
&nbsp;<button id="show_upgrade_status" class="ui-button ui-widget ui-corner-all settings_button_small">Show Upgrade Log</button>
&nbsp;<button id="show_upgrade_logs" class="ui-button ui-widget ui-corner-all settings_button_small">Show Upgrade Log</button>
</td>
</tr>
</table>
@ -489,7 +506,35 @@
<p style="color: red;">It appears a recent upgrade may not have fully completed.</p>
<button id="upgrade" class="ui-button ui-widget ui-corner-all settings_button">Retry Upgrade</button>
{% endif %}
<div id="upgrade_status" style='text-align: left; font-size: 12px; width: 800px; display: none;'><pre>{{upgrade_logs}}</pre></div>
<div id="upgrade_logs" style='text-align: left; font-size: 12px; width: 800px; display: none;'>
<br/><br/>
<table style="font-size: 12px;">
<tr>
<th></th>
<th>Log</th>
<th>Date</th>
</tr>
{% for f in upgrade_logs %}
<tr>
<td><button onclick="showUpgradeLog({{f.id}})" id="show_upgrade_log_{{f.id}}" class="ui-button ui-widget ui-corner-all settings_button_small">Show</button></td>
<td>{{f.name}}</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;{{f.date}}</td>
</tr>
{% endfor %}
<tr>
<td colspan="3" style="margin: auto;">
<center><button id="clear_upgrade_logs" class="ui-button ui-widget ui-corner-all settings_button_small">Clear All Logs</button></center>
</td>
</tr>
</table>
{% for f in upgrade_logs %}
<div id="upgrade_log_{{f.id}}" style='text-align: left; font-size: 12px; width: 800px; display: none;'><pre>{{f.log}}</pre></div>
{% endfor %}
</div>
<div class="divider"></div>
@ -1018,8 +1063,8 @@
{% elif upgrade_error %}
<p style="color: red;">It appears a recent upgrade may not have fully completed.</p>
<button id="upgrade" class="ui-button ui-widget ui-corner-all settings_button">Retry Upgrade</button>
<button id="show_upgrade_status_beta" class="ui-button ui-widget ui-corner-all settings_button">Show Upgrade Logs</button>
<div id="upgrade_status_beta" style='text-align: left; font-size: 12px; width: 800px; display: none;'><pre>{{upgrade_logs}}</pre></div>
<button id="show_upgrade_log_beta" class="ui-button ui-widget ui-corner-all settings_button">Show Upgrade Log</button>
<div id="upgrade_log_beta" style='text-align: left; font-size: 12px; width: 800px; display: none;'><pre>{{upgrade_log}}</pre></div>
{% endif %}
<div class="divider"></div>