Add options to format or re-mount external drive

This commit is contained in:
Taylor Helsper 2021-01-11 17:36:06 -06:00
parent 20b1e402ec
commit 1d0c751cc3
5 changed files with 114 additions and 10 deletions

View File

@ -20,12 +20,16 @@ proc checkPartitionForExistingMyNodeFs {partition} {
proc checkPartitionsForExistingMyNodeFs {partitionsName} {
upvar $partitionsName partitions
runCommand mkdir -p /mnt/hdd
# Check if we are skipping the check (to reformat drive)
if { [file exists /home/bitcoin/.mynode/force_format_prompt] } {
return 0
}
# Check each partition
foreach partition $partitions {
if [checkPartitionForExistingMyNodeFs $partition] {
# Remove this partition from the list so we don't try to
# use it as the config drive later on.
set partitions [lsearch -all -inline -not -exact $partitions $partition]
# set partitions [lsearch -all -inline -not -exact $partitions $partition]
return 1
}
}

View File

@ -59,6 +59,9 @@ def is_shutting_down():
return os.path.isfile("/tmp/shutting_down")
def factory_reset():
# Try and make sure drive is r/w
os.system("mount -o remount,rw /mnt/hdd")
# Reset subsystems that have local data
delete_quicksync_data()

View File

@ -412,6 +412,25 @@ def reboot_device_page():
}
return render_template('reboot.html', **templateData)
@mynode_settings.route("/settings/reboot-device-no-format")
def reboot_device_no_format_page():
check_logged_in()
os.system("rm -f /home/bitcoin/.mynode/force_format_prompt")
# Trigger reboot
t = Timer(1.0, reboot_device)
t.start()
# Wait until device is restarted
templateData = {
"title": "myNode Reboot",
"header_text": "Restarting",
"subheader_text": "This will take several minutes...",
"ui_settings": read_ui_settings()
}
return render_template('reboot.html', **templateData)
@mynode_settings.route("/settings/shutdown-device")
def shutdown_device_page():
check_logged_in()
@ -491,6 +510,33 @@ def reset_firewall_page():
flash("Firewall Reset", category="message")
return redirect("/settings")
@mynode_settings.route("/settings/remount-external-drive")
def remount_external_drive_page():
os.system("mount -o remount,rw /mnt/hdd")
flash("Remounted External Drive", category="message")
return redirect("/settings")
@mynode_settings.route("/settings/format-external-drive", methods=['POST'])
def format_external_drive_page():
check_logged_in()
p = pam.pam()
pw = request.form.get('password_format_external_drive')
if pw == None or p.authenticate("admin", pw) == False:
flash("Invalid Password", category="error")
return redirect(url_for(".page_settings"))
else:
check_and_mark_reboot_action("format_external_drive")
os.system("touch /home/bitcoin/.mynode/force_format_prompt")
templateData = {
"title": "myNode",
"header_text": "Rebooting",
"subheader_text": "This will take several minutes...",
"ui_settings": read_ui_settings()
}
return render_template('reboot.html', **templateData)
@mynode_settings.route("/settings/factory-reset", methods=['POST'])
def factory_reset_page():
check_logged_in()

View File

@ -11,7 +11,7 @@
window.location.href="/?format=1"
});
$("#reboot-device").on("click", function() {
window.location.href="/settings/reboot-device"
window.location.href="/settings/reboot-device-no-format"
});
});
</script>

View File

@ -162,7 +162,6 @@
$("#factory_reset_form").submit();
factory_reset_dialog.dialog( "close" );
}
factory_reset_dialog = $( "#factory-reset-dialog" ).dialog({
autoOpen: false,
resizable: false,
@ -180,11 +179,35 @@
$("#password_factory_reset").val("")
}
});
$("#factory-reset").on("click", function() {
factory_reset_dialog.dialog( "open" );
});
function formatExternalDrive() {
$("#format_external_drive_form").submit();
format_external_drive_dialog.dialog( "close" );
}
format_external_drive_dialog = $( "#format-external-drive-dialog" ).dialog({
autoOpen: false,
resizable: false,
height: "auto",
width: 600,
modal: true,
position: { my: "center top", at: "center top", of: window, collision: "none" },
buttons: {
"Format Drive": formatExternalDrive,
Cancel: function() {
format_external_drive_dialog.dialog( "close" );
}
},
open: function() {
$("#password_factory_reset").val("")
}
});
$("#format-external-drive").on("click", function() {
format_external_drive_dialog.dialog( "open" );
});
$("#reset_docker_button").button();
$("#reset_docker_button").on("click", function() {
if (confirm("Are you sure you want to reset docker?")) {
@ -837,10 +860,23 @@
<div class="divider"></div>
<div class="settings_block_subheader">Factory Reset</div>
This will factory reset your mynode and all storage will be completely reset.
<div class="settings_block_subheader">Remount External Drive</div>
This will attempt to remount your external drive as read/write if it is read-only.
<br/>
Make sure you have backed up all your keys and wallets!
<a href="/settings/remount-external-drive" class="ui-button ui-widget ui-corner-all settings_button">Remount Drive</a>
<div class="divider"></div>
<div class="settings_block_subheader">Format External Drive</div>
This will reboot your device and re-prompt for formatting the drive. If your external drive has been corrupted, this
may help and will be slightly less destructive than a factory reset. Make sure you have backed up all your keys and wallets!
<br/>
<button id="format-external-drive" class="ui-button ui-widget ui-corner-all settings_button">Format Drive</button>
<div class="divider"></div>
<div class="settings_block_subheader">Factory Reset</div>
This will factory reset your mynode and all storage will be completely reset. Make sure you have backed up all your keys and wallets!
<br/>
<button id="factory-reset" class="ui-button ui-widget ui-corner-all settings_button">Factory Reset</button>
</div>
@ -950,6 +986,21 @@
</form>
</div>
<div id="format-external-drive-dialog" title="Format Drive" style="display:none;">
<form id="format_external_drive_form" name="format_external_drive_form" action="/settings/format-external-drive" method="POST">
<p>Formatting your drive will revert most storage to the initial state.</p>
<p class='red_text'>BACKUP ALL KEYS AND WALLETS BEFORE RESETTING YOUR DEVICE!</p>
<p>This will reboot your device.</p>
<p>Would you still like to format the external drive?</p>
<b>Password:</b>
<br/>
<input type="password" name="password_format_external_drive" id="password_format_external_drive" value="" class="text ui-widget-content ui-corner-all">
<!-- Allow form submission with keyboard without duplicating the dialog button -->
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</form>
</div>
{% include 'includes/footer.html' %}
</body>
</html>