mirror of
https://github.com/mynodebtc/mynode.git
synced 2024-12-25 14:08:07 +00:00
Add toggle for web ui python3; add functions for touch and delete_file
This commit is contained in:
parent
adc55a90df
commit
2201dd5f8a
|
@ -15,7 +15,8 @@ RestartSec=10
|
|||
Nice=-15
|
||||
IOAccounting=true
|
||||
IOWeight=2000
|
||||
ExecStart=/usr/bin/python2.7 /var/www/mynode/mynode.py
|
||||
ExecStart=/usr/bin/mynode_www.sh
|
||||
#ExecStart=/usr/bin/python2.7 /var/www/mynode/mynode.py
|
||||
# Future
|
||||
#ExecStart=python3 /var/www/mynode/mynode.py
|
||||
User=root
|
||||
|
|
7
rootfs/standard/usr/bin/mynode_www.sh
Executable file
7
rootfs/standard/usr/bin/mynode_www.sh
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -f /home/bitcoin/.mynode/.www_use_python3 ]; then
|
||||
exec /usr/local/bin/python3 /var/www/mynode/mynode.py
|
||||
else
|
||||
exec /usr/bin/python2.7 /var/www/mynode/mynode.py
|
||||
fi
|
|
@ -22,8 +22,7 @@ def reinstall_app(app):
|
|||
# Clear app data
|
||||
clear_application_cache()
|
||||
|
||||
os.system("touch /tmp/skip_base_upgrades")
|
||||
os.system("sync")
|
||||
touch("/tmp/skip_base_upgrades")
|
||||
|
||||
# Reinstall
|
||||
os.system("mkdir -p /home/admin/upgrade_logs")
|
||||
|
@ -169,8 +168,7 @@ def clear_application_cache():
|
|||
mynode_applications = None
|
||||
|
||||
def trigger_application_refresh():
|
||||
os.system("touch /tmp/need_application_refresh")
|
||||
os.system("sync")
|
||||
touch("/tmp/need_application_refresh")
|
||||
|
||||
def need_application_refresh():
|
||||
global mynode_applications
|
||||
|
|
|
@ -249,9 +249,7 @@ def is_bip158_enabled():
|
|||
return False
|
||||
|
||||
def enable_bip158():
|
||||
os.system("touch /mnt/hdd/mynode/settings/.bip158_enabled")
|
||||
os.system("sync")
|
||||
touch("/mnt/hdd/mynode/settings/.bip158_enabled")
|
||||
|
||||
def disable_bip158():
|
||||
os.system("rm /mnt/hdd/mynode/settings/.bip158_enabled")
|
||||
os.system("sync")
|
||||
delete_file("/mnt/hdd/mynode/settings/.bip158_enabled")
|
|
@ -76,7 +76,7 @@ def check_and_mark_reboot_action(tmp_marker):
|
|||
if os.path.isfile("/tmp/{}".format(tmp_marker)):
|
||||
flash(u'Refresh prevented - action already triggered', category="error")
|
||||
raise RequestRedirect("/")
|
||||
os.system("touch /tmp/{}".format(tmp_marker))
|
||||
otouch("/tmp/{}".format(tmp_marker))
|
||||
|
||||
def reload_throttled_data():
|
||||
global cached_data
|
||||
|
@ -150,8 +150,7 @@ def get_latest_beta_version():
|
|||
return beta_version
|
||||
|
||||
def mark_upgrade_started():
|
||||
os.system("touch /tmp/upgrade_started")
|
||||
os.system("sync")
|
||||
touch("/tmp/upgrade_started")
|
||||
|
||||
def is_upgrade_running():
|
||||
return os.path.isfile("/tmp/upgrade_started")
|
||||
|
@ -294,8 +293,8 @@ def get_device_type():
|
|||
if "device_type" in cached_data:
|
||||
return cached_data["device_type"]
|
||||
|
||||
device = subprocess.check_output("mynode-get-device-type", shell=True).strip()
|
||||
cached_data["device_type"] = to_string(device)
|
||||
device = to_string(subprocess.check_output("mynode-get-device-type", shell=True).strip())
|
||||
cached_data["device_type"] = device
|
||||
return device
|
||||
|
||||
def get_device_arch():
|
||||
|
@ -303,8 +302,8 @@ def get_device_arch():
|
|||
if "device_arch" in cached_data:
|
||||
return cached_data["device_arch"]
|
||||
|
||||
arch = subprocess.check_output("uname -m", shell=True).decode("utf-8").strip()
|
||||
cached_data["device_arch"] = to_string(arch)
|
||||
arch = to_string(subprocess.check_output("uname -m", shell=True).decode("utf-8").strip())
|
||||
cached_data["device_arch"] = arch
|
||||
return arch
|
||||
|
||||
def get_device_ram():
|
||||
|
@ -312,8 +311,8 @@ def get_device_ram():
|
|||
if "ram" in cached_data:
|
||||
return cached_data["ram"]
|
||||
|
||||
ram = subprocess.check_output("free --giga | grep Mem | awk '{print $2}'", shell=True).strip()
|
||||
cached_data["ram"] = to_string(ram)
|
||||
ram = to_string(subprocess.check_output("free --giga | grep Mem | awk '{print $2}'", shell=True).strip())
|
||||
cached_data["ram"] = ram
|
||||
return ram
|
||||
|
||||
def get_local_ip():
|
||||
|
@ -550,9 +549,9 @@ def is_https_forced():
|
|||
|
||||
def force_https(force):
|
||||
if force:
|
||||
os.system("touch /home/bitcoin/.mynode/https_forced")
|
||||
touch("/home/bitcoin/.mynode/https_forced")
|
||||
else:
|
||||
os.system("rm -f /home/bitcoin/.mynode/https_forced")
|
||||
delete_file("/home/bitcoin/.mynode/https_forced")
|
||||
|
||||
# Regen cert
|
||||
def regen_https_cert():
|
||||
|
@ -594,9 +593,18 @@ def get_randomize_balances():
|
|||
|
||||
def set_randomize_balances(randomize):
|
||||
if randomize:
|
||||
os.system("touch /home/bitcoin/.mynode/randomize_balances")
|
||||
touch("touch /home/bitcoin/.mynode/randomize_balances")
|
||||
else:
|
||||
os.system("rm -f /home/bitcoin/.mynode/randomize_balances")
|
||||
delete_file("rm -f /home/bitcoin/.mynode/randomize_balances")
|
||||
|
||||
def is_www_python3():
|
||||
return os.path.isfile('/home/bitcoin/.mynode/.www_use_python3')
|
||||
|
||||
def set_www_python3(use_python3):
|
||||
if use_python3:
|
||||
touch("/home/bitcoin/.mynode/.www_use_python3")
|
||||
else:
|
||||
delete_file("/home/bitcoin/.mynode/.www_use_python3")
|
||||
|
||||
#==================================
|
||||
# Web Server Functions
|
||||
|
@ -611,9 +619,9 @@ def restart_flask():
|
|||
def is_uploader():
|
||||
return os.path.isfile("/mnt/hdd/mynode/settings/uploader")
|
||||
def set_uploader():
|
||||
os.system("touch /mnt/hdd/mynode/settings/uploader")
|
||||
touch("/mnt/hdd/mynode/settings/uploader")
|
||||
def unset_uploader():
|
||||
os.system("rm -rf /mnt/hdd/mynode/settings/uploader")
|
||||
delete_file("/mnt/hdd/mynode/settings/uploader")
|
||||
|
||||
|
||||
#==================================
|
||||
|
@ -622,10 +630,9 @@ def unset_uploader():
|
|||
def is_quicksync_enabled():
|
||||
return not os.path.isfile("/mnt/hdd/mynode/settings/quicksync_disabled")
|
||||
def disable_quicksync():
|
||||
os.system("touch /mnt/hdd/mynode/settings/quicksync_disabled")
|
||||
os.system("sync")
|
||||
touch("/mnt/hdd/mynode/settings/quicksync_disabled")
|
||||
def enable_quicksync():
|
||||
os.system("rm -rf /mnt/hdd/mynode/settings/quicksync_disabled")
|
||||
delete_file("/mnt/hdd/mynode/settings/quicksync_disabled")
|
||||
|
||||
def settings_disable_quicksync():
|
||||
disable_quicksync()
|
||||
|
@ -675,11 +682,11 @@ def get_quicksync_log():
|
|||
# Product Key Functions
|
||||
#==================================
|
||||
def set_skipped_product_key():
|
||||
os.system("touch /home/bitcoin/.mynode/.product_key_skipped")
|
||||
os.system("touch /mnt/hdd/mynode/settings/.product_key_skipped")
|
||||
touch("/home/bitcoin/.mynode/.product_key_skipped")
|
||||
touch("/mnt/hdd/mynode/settings/.product_key_skipped")
|
||||
def unset_skipped_product_key():
|
||||
os.system("rm -rf /home/bitcoin/.mynode/.product_key_skipped")
|
||||
os.system("rm -rf /mnt/hdd/mynode/settings/.product_key_skipped")
|
||||
delete_file("/home/bitcoin/.mynode/.product_key_skipped")
|
||||
delete_file("/mnt/hdd/mynode/settings/.product_key_skipped")
|
||||
def skipped_product_key():
|
||||
return os.path.isfile("/home/bitcoin/.mynode/.product_key_skipped") or \
|
||||
os.path.isfile("/mnt/hdd/mynode/settings/.product_key_skipped")
|
||||
|
@ -687,8 +694,8 @@ def is_community_edition():
|
|||
return skipped_product_key()
|
||||
|
||||
def delete_product_key():
|
||||
os.system("rm -rf /home/bitcoin/.mynode/.product_key")
|
||||
os.system("rm -rf /mnt/hdd/mynode/settings/.product_key")
|
||||
delete_file("/home/bitcoin/.mynode/.product_key")
|
||||
delete_file("/mnt/hdd/mynode/settings/.product_key")
|
||||
def has_product_key():
|
||||
return os.path.isfile("/home/bitcoin/.mynode/.product_key")
|
||||
def get_product_key():
|
||||
|
@ -739,10 +746,9 @@ def get_fsck_results():
|
|||
|
||||
def set_skip_fsck(skip):
|
||||
if skip:
|
||||
os.system("touch /home/bitcoin/.mynode/skip_fsck")
|
||||
touch("/home/bitcoin/.mynode/skip_fsck")
|
||||
else:
|
||||
os.system("rm -f /home/bitcoin/.mynode/skip_fsck")
|
||||
os.system("sync")
|
||||
delete_file("/home/bitcoin/.mynode/skip_fsck")
|
||||
def skip_fsck():
|
||||
return os.path.isfile("/home/bitcoin/.mynode/skip_fsck")
|
||||
|
||||
|
@ -756,10 +762,10 @@ def has_sd_rw_error():
|
|||
def has_oom_error():
|
||||
return os.path.isfile("/tmp/oom_error")
|
||||
def clear_oom_error():
|
||||
os.system("rm -f /tmp/oom_error")
|
||||
os.system("rm -f /tmp/oom_info")
|
||||
delete_file("/tmp/oom_error")
|
||||
delete_file("/tmp/oom_info")
|
||||
def set_oom_error(oom_error):
|
||||
os.system("touch /tmp/oom_error")
|
||||
touch("/tmp/oom_error")
|
||||
set_file_contents("/tmp/oom_info", oom_error)
|
||||
def get_oom_error_info():
|
||||
try:
|
||||
|
@ -797,7 +803,7 @@ def get_docker_image_build_status_color():
|
|||
|
||||
def reset_docker():
|
||||
# Delete docker data
|
||||
os.system("touch /home/bitcoin/reset_docker")
|
||||
touch("/home/bitcoin/reset_docker")
|
||||
|
||||
# Reset marker files
|
||||
os.system("rm -f /mnt/hdd/mynode/settings/webssh2_version")
|
||||
|
@ -896,11 +902,9 @@ def delete_lnd_data():
|
|||
def is_testnet_enabled():
|
||||
return os.path.isfile("/mnt/hdd/mynode/settings/.testnet_enabled")
|
||||
def enable_testnet():
|
||||
os.system("touch /mnt/hdd/mynode/settings/.testnet_enabled")
|
||||
os.system("sync")
|
||||
touch("/mnt/hdd/mynode/settings/.testnet_enabled")
|
||||
def disable_testnet():
|
||||
os.system("rm -f /mnt/hdd/mynode/settings/.testnet_enabled")
|
||||
os.system("sync")
|
||||
delete_file("/mnt/hdd/mynode/settings/.testnet_enabled")
|
||||
def toggle_testnet():
|
||||
if is_testnet_enabled():
|
||||
disable_testnet()
|
||||
|
@ -983,15 +987,13 @@ def is_btcrpcexplorer_token_enabled():
|
|||
return True
|
||||
|
||||
def enable_btcrpcexplorer_token():
|
||||
os.system("rm -rf /mnt/hdd/mynode/settings/.btcrpcexplorer_disable_token")
|
||||
os.system("sync")
|
||||
delete_file("/mnt/hdd/mynode/settings/.btcrpcexplorer_disable_token")
|
||||
if is_service_enabled("btcrpcexplorer"):
|
||||
restart_service("btcrpcexplorer")
|
||||
|
||||
|
||||
def disable_btcrpcexplorer_token():
|
||||
os.system("touch /mnt/hdd/mynode/settings/.btcrpcexplorer_disable_token")
|
||||
os.system("sync")
|
||||
touch("/mnt/hdd/mynode/settings/.btcrpcexplorer_disable_token")
|
||||
if is_service_enabled("btcrpcexplorer"):
|
||||
restart_service("btcrpcexplorer")
|
||||
|
||||
|
@ -1009,23 +1011,19 @@ def is_btc_lnd_tor_enabled():
|
|||
return os.path.isfile("/mnt/hdd/mynode/settings/.btc_lnd_tor_enabled")
|
||||
|
||||
def enable_btc_lnd_tor():
|
||||
os.system("touch /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled")
|
||||
os.system("sync")
|
||||
touch("/mnt/hdd/mynode/settings/.btc_lnd_tor_enabled")
|
||||
|
||||
def disable_btc_lnd_tor():
|
||||
os.system("rm -f /mnt/hdd/mynode/settings/.btc_lnd_tor_enabled")
|
||||
os.system("sync")
|
||||
delete_file("/mnt/hdd/mynode/settings/.btc_lnd_tor_enabled")
|
||||
|
||||
def is_aptget_tor_enabled():
|
||||
return os.path.isfile("/mnt/hdd/mynode/settings/torify_apt_get")
|
||||
|
||||
def enable_aptget_tor():
|
||||
os.system("touch /mnt/hdd/mynode/settings/torify_apt_get")
|
||||
os.system("sync")
|
||||
touch("/mnt/hdd/mynode/settings/torify_apt_get")
|
||||
|
||||
def disable_aptget_tor():
|
||||
os.system("rm -f /mnt/hdd/mynode/settings/torify_apt_get")
|
||||
os.system("sync")
|
||||
delete_file("/mnt/hdd/mynode/settings/torify_apt_get")
|
||||
|
||||
def get_onion_url_ssh():
|
||||
if is_community_edition(): return "not_available"
|
||||
|
|
|
@ -47,7 +47,7 @@ def is_warning_skipped(warning):
|
|||
def skip_warning(warning):
|
||||
global warning_data
|
||||
init_warning_data()
|
||||
os.system("touch /tmp/warning_skipped_{}".format(warning))
|
||||
touch("/tmp/warning_skipped_{}".format(warning))
|
||||
|
||||
def is_warning_present():
|
||||
global warning_data
|
||||
|
|
|
@ -33,7 +33,7 @@ def update_electrs_info():
|
|||
bitcoin_block_height = get_bitcoin_block_height()
|
||||
if electrum_server_current_block != None and bitcoin_block_height != None:
|
||||
if electrum_server_current_block > bitcoin_block_height - 2:
|
||||
os.system("touch /tmp/electrs_up_to_date")
|
||||
touch("/tmp/electrs_up_to_date")
|
||||
electrs_active = True
|
||||
except:
|
||||
pass
|
||||
|
|
|
@ -612,9 +612,7 @@ def is_watchtower_enabled():
|
|||
return False
|
||||
|
||||
def enable_watchtower():
|
||||
os.system("touch /mnt/hdd/mynode/settings/.watchtower_enabled")
|
||||
os.system("sync")
|
||||
touch("/mnt/hdd/mynode/settings/.watchtower_enabled")
|
||||
|
||||
def disable_watchtower():
|
||||
os.system("rm /mnt/hdd/mynode/settings/.watchtower_enabled")
|
||||
os.system("sync")
|
||||
delete_file("/mnt/hdd/mynode/settings/.watchtower_enabled")
|
||||
|
|
|
@ -205,7 +205,7 @@ def index():
|
|||
return render_template('state.html', **templateData)
|
||||
elif status == STATE_DRIVE_CONFIRM_FORMAT:
|
||||
if request.args.get('format'):
|
||||
os.system("touch /tmp/format_ok")
|
||||
touch("/tmp/format_ok")
|
||||
time.sleep(1)
|
||||
return redirect("/")
|
||||
|
||||
|
@ -291,11 +291,11 @@ def index():
|
|||
elif clone_state == CLONE_STATE_NEED_CONFIRM:
|
||||
# Clone was confirmed
|
||||
if request.args.get('clone_confirm'):
|
||||
os.system("touch /tmp/.clone_confirm")
|
||||
touch("/tmp/.clone_confirm")
|
||||
time.sleep(3)
|
||||
return redirect("/")
|
||||
if request.args.get('clone_rescan'):
|
||||
os.system("touch /tmp/.clone_rescan")
|
||||
touch("/tmp/.clone_rescan")
|
||||
time.sleep(3)
|
||||
return redirect("/")
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ def page_settings():
|
|||
upload_rate = 100
|
||||
download_rate = 100
|
||||
try:
|
||||
upload_rate = subprocess.check_output(["cat","/mnt/hdd/mynode/settings/quicksync_upload_rate"])
|
||||
download_rate = subprocess.check_output(["cat","/mnt/hdd/mynode/settings/quicksync_background_download_rate"])
|
||||
upload_rate = to_string(subprocess.check_output(["cat","/mnt/hdd/mynode/settings/quicksync_upload_rate"]))
|
||||
download_rate = to_string(subprocess.check_output(["cat","/mnt/hdd/mynode/settings/quicksync_background_download_rate"]))
|
||||
except:
|
||||
upload_rate = 100
|
||||
download_rate = 100
|
||||
|
@ -85,6 +85,7 @@ def page_settings():
|
|||
"is_testnet_enabled": is_testnet_enabled(),
|
||||
"is_quicksync_disabled": not is_quicksync_enabled(),
|
||||
"netdata_enabled": is_service_enabled("netdata"),
|
||||
"www_python3": is_www_python3(),
|
||||
"randomize_balances": get_randomize_balances(),
|
||||
"is_uploader_device": is_uploader(),
|
||||
"download_rate": download_rate,
|
||||
|
@ -513,8 +514,7 @@ def open_clone_tool_page():
|
|||
|
||||
check_and_mark_reboot_action("open_clone_tool")
|
||||
|
||||
os.system("touch /home/bitcoin/open_clone_tool")
|
||||
os.system("sync")
|
||||
touch("/home/bitcoin/open_clone_tool")
|
||||
|
||||
# Trigger reboot
|
||||
t = Timer(1.0, reboot_device)
|
||||
|
@ -603,7 +603,7 @@ def format_external_drive_page():
|
|||
else:
|
||||
check_and_mark_reboot_action("format_external_drive")
|
||||
|
||||
os.system("touch /home/bitcoin/.mynode/force_format_prompt")
|
||||
touch("/home/bitcoin/.mynode/force_format_prompt")
|
||||
|
||||
templateData = {
|
||||
"title": "myNode",
|
||||
|
@ -1080,6 +1080,23 @@ def page_clear_oom_error():
|
|||
flash("Warning Cleared", category="message")
|
||||
return redirect("/settings")
|
||||
|
||||
@mynode_settings.route("/settings/enable_www_python3")
|
||||
def page_enable_enable_www_python3():
|
||||
check_logged_in()
|
||||
|
||||
enable = request.args.get('enable')
|
||||
if enable == "1":
|
||||
set_www_python3(True)
|
||||
else:
|
||||
set_www_python3(False)
|
||||
|
||||
# Restart web server
|
||||
t = Timer(3.0, restart_service, ["www"])
|
||||
t.start()
|
||||
|
||||
flash("WWW Python 3 Setting Updated", category="message")
|
||||
return redirect("/settings")
|
||||
|
||||
@mynode_settings.route("/settings/enable_randomize_balances")
|
||||
def page_enable_enable_randomize_balances():
|
||||
check_logged_in()
|
||||
|
|
|
@ -430,6 +430,21 @@
|
|||
}
|
||||
});
|
||||
|
||||
$('#www_python3_checkbox').change(function () {
|
||||
$("#www_python3_button").show();
|
||||
});
|
||||
$("#www_python3_button").on("click", function() {
|
||||
enabled=$('#www_python3_checkbox').is(":checked")
|
||||
if (enabled)
|
||||
{
|
||||
window.location.href='/settings/enable_www_python3?enable=1'
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href='/settings/enable_www_python3?enable=0'
|
||||
}
|
||||
});
|
||||
|
||||
$('#randomize_balances_checkbox').change(function () {
|
||||
$("#randomize_balances_button").show();
|
||||
});
|
||||
|
@ -1158,6 +1173,18 @@
|
|||
<div class="divider"></div>
|
||||
{% endif %}
|
||||
|
||||
<div class="settings_block_subheader">Use Python 3 for Web Interface</div>
|
||||
This will use the beta version of the web UI, which relies on python 3.
|
||||
<br/><br/>
|
||||
<label class="switch">
|
||||
<input type="checkbox" id="www_python3_checkbox" {% if www_python3 %}checked{% endif %}>
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
<br/><br/>
|
||||
<button id="www_python3_button" style="display: none;" class="ui-button ui-widget ui-corner-all settings_button_small">Save</button>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="settings_block_subheader">Randomize Balances</div>
|
||||
This shows random balances for taking screenshots and testing the interface.
|
||||
<br/><br/>
|
||||
|
|
|
@ -41,6 +41,26 @@ def unquote_plus(s):
|
|||
#==================================
|
||||
# Utilities
|
||||
#==================================
|
||||
def touch(file_path):
|
||||
# In rare cases, touch seems to fail, so try both python and system call
|
||||
# Touch via python
|
||||
if os.path.exists(file_path):
|
||||
os.utime(file_path, None)
|
||||
else:
|
||||
open(file_path, 'a').close()
|
||||
# Touch via system
|
||||
os.system("touch {}".format(file_path))
|
||||
# Sync
|
||||
os.system("sync")
|
||||
|
||||
def delete_file(file_path):
|
||||
try:
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
os.system("rm -f {}".format(file_path))
|
||||
except Exception as e:
|
||||
log_message("FAILED TO DELETE {}".format(file_path))
|
||||
|
||||
def get_file_contents(filename):
|
||||
contents = "UNKNOWN"
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue
Block a user