Fix downloading files when UI uses python3

This commit is contained in:
Taylor Helsper 2022-02-09 23:50:58 -06:00
parent 18a2b37d29
commit 1e9058fc14
13 changed files with 37 additions and 24 deletions

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template, session, send_from_directory, abort, Markup, request, redirect, flash
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, flash
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from pprint import pprint, pformat
from bitcoin_info import *
@ -141,12 +141,12 @@ def bitcoin_download_wallet():
t = Timer(3.0, cleanup_download_wallets)
t.start()
return send_from_directory(directory="/tmp/download_wallets/", filename=wallet_name, as_attachment=True)
return download_file(directory="/tmp/download_wallets/", filename=wallet_name)
@mynode_bitcoin.route("/bitcoin/bitcoin_whitepaper.pdf")
def bitcoin_whitepaper_pdf():
check_logged_in()
return send_from_directory(directory="/mnt/hdd/mynode/bitcoin/", filename="bitcoin_whitepaper.pdf")
return download_file(directory="/mnt/hdd/mynode/bitcoin/", filename="bitcoin_whitepaper.pdf")
@mynode_bitcoin.route("/bitcoin/reset_config")
def bitcoin_reset_config_page():

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template, redirect, request, flash, send_from_directory
from flask import Blueprint, render_template, redirect, request, flash
from user_management import check_logged_in
from device_info import read_ui_settings
from systemctl_info import *

View File

@ -1,7 +1,8 @@
from flask import Blueprint, render_template, redirect, request, flash, send_from_directory
from flask import Blueprint, render_template, redirect, request, flash
from user_management import check_logged_in
from device_info import read_ui_settings
from systemctl_info import *
from utilities import *
import os
import time
import subprocess
@ -53,4 +54,4 @@ def joininbox_download_wallet():
flash("Error finding wallet to download!", category="error")
return redirect("/joininbox")
return send_from_directory(directory=wallet_folder, filename=wallet_name, as_attachment=True)
return download_file(directory=wallet_folder, filename=wallet_name)

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, send_from_directory, url_for, flash
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, url_for, flash
from pprint import pprint, pformat
from threading import Timer
from bitcoin_info import *
@ -243,7 +243,7 @@ def lnd_regen_tls_cert():
@mynode_lnd.route("/lnd/tls.cert")
def lnd_tls_cert():
check_logged_in()
return send_from_directory(directory="/mnt/hdd/mynode/lnd/", filename="tls.cert")
return download_file(directory="/mnt/hdd/mynode/lnd/", filename="tls.cert")
@mynode_lnd.route("/lnd/admin.macaroon")
def lnd_admin_macaroon():
@ -254,7 +254,7 @@ def lnd_admin_macaroon():
folder = "testnet"
# Download macaroon
return send_from_directory(directory="/mnt/hdd/mynode/lnd/data/chain/bitcoin/{}/".format(folder), filename="admin.macaroon")
return download_file(directory="/mnt/hdd/mynode/lnd/data/chain/bitcoin/{}/".format(folder), filename="admin.macaroon")
@mynode_lnd.route("/lnd/readonly.macaroon")
def lnd_readonly_macaroon():
@ -265,7 +265,7 @@ def lnd_readonly_macaroon():
folder = "testnet"
# Download macaroon
return send_from_directory(directory="/mnt/hdd/mynode/lnd/data/chain/bitcoin/{}/".format(folder), filename="readonly.macaroon")
return download_file(directory="/mnt/hdd/mynode/lnd/data/chain/bitcoin/{}/".format(folder), filename="readonly.macaroon")
@mynode_lnd.route("/lnd/channel.backup")
def lnd_channel_backup():
@ -274,7 +274,7 @@ def lnd_channel_backup():
scb_location = get_lnd_channel_backup_file()
parts = os.path.split(scb_location)
return send_from_directory(directory=parts[0]+"/", filename=parts[1])
return download_file(directory=parts[0]+"/", filename=parts[1])
@mynode_lnd.route("/lnd/create_wallet")
def page_lnd_create_wallet():

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template, redirect, request, flash, send_from_directory
from flask import Blueprint, render_template, redirect, request, flash
from user_management import check_logged_in
from device_info import read_ui_settings
from systemctl_info import *

View File

@ -1,6 +1,6 @@
from config import *
from flask import Flask, render_template, Markup, send_from_directory, redirect, request, url_for
from flask import Flask, render_template, Markup, redirect, request, url_for
from user_management import *
from api import mynode_api
from bitcoin import mynode_bitcoin

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template, redirect, request, flash, send_from_directory
from flask import Blueprint, render_template, redirect, request, flash
from user_management import check_logged_in
from device_info import read_ui_settings
from systemctl_info import *

View File

@ -1,5 +1,5 @@
from config import *
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, send_from_directory, url_for, flash
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, url_for, flash
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from bitcoin import is_bitcoin_synced
from bitcoin_info import using_bitcoin_custom_config
@ -835,16 +835,16 @@ def download_logs_page():
os.system("/usr/bin/mynode_gen_debug_tarball.sh")
return send_from_directory(directory="/tmp/", filename="mynode_logs.tar.gz")
return download_file(directory="/tmp/", filename="mynode_logs.tar.gz")
@mynode_settings.route("/settings/mynode_web.cert")
def download_https_cert_page():
check_logged_in()
if os.path.isfile("/mnt/hdd/mynode/settings/https/myNode.local.crt"):
return send_from_directory(directory="/mnt/hdd/mynode/settings/https/", filename="myNode.local.crt")
return download_file(directory="/mnt/hdd/mynode/settings/https/", filename="myNode.local.crt")
if os.path.isfile("/home/bitcoin/.mynode/https/myNode.local.crt"):
return send_from_directory(directory="/home/bitcoin/.mynode/https/", filename="myNode.local.crt")
return download_file(directory="/home/bitcoin/.mynode/https/", filename="myNode.local.crt")
return "error_missing_file"
@mynode_settings.route("/settings/regen-https-certs")

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template, redirect, request, flash, send_from_directory
from flask import Blueprint, render_template, redirect, request, flash
from user_management import check_logged_in
from device_info import read_ui_settings, get_usb_extras
from systemctl_info import *

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, send_from_directory, url_for, flash
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, url_for, flash
from config import *
import time
import pam

View File

@ -1,3 +1,4 @@
from flask import send_from_directory
import os
import subprocess
import sys
@ -141,4 +142,14 @@ def format_sat_amount(amount):
r = "{:,}".format(int(amount))
except:
r = amount
return r
return r
#==================================
# Flask Functions
#==================================
def download_file(directory, filename, downloaded_file_name=None, as_attachment=True):
if isPython3():
return send_from_directory(directory=directory, path=filename, filename=None, as_attachment=as_attachment)
else:
return send_from_directory(directory=directory, filename=filename, as_attachment=as_attachment)

View File

@ -1,7 +1,8 @@
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, send_from_directory, url_for, flash
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, url_for, flash
from thread_functions import get_public_ip, check_in, find_public_ip
from device_info import is_community_edition, read_ui_settings
from user_management import check_logged_in
from utilities import *
import subprocess
import pam
import os
@ -81,7 +82,7 @@ def page_download_ovpn():
return redirect(url_for(".page_vpn_info"))
# Download ovpn
return send_from_directory(directory="/home/pivpn/ovpns/", filename="mynode_vpn.ovpn")
return download_file(directory="/home/pivpn/ovpns/", filename="mynode_vpn.ovpn")
@mynode_vpn.route("/vpn-info/find-public-ip")
def check_in_page():

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template, redirect, request, flash, send_from_directory
from flask import Blueprint, render_template, redirect, request, flash
from user_management import check_logged_in
from device_info import read_ui_settings
from systemctl_info import *