From 004928833456ce91c7b1f61cbf048efa1243d98a Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Wed, 3 Aug 2022 21:17:59 -0500 Subject: [PATCH] Add warning and info about support and premium+ subscriptions --- rootfs/standard/var/pynode/device_info.py | 40 +++++++++++++++++++ rootfs/standard/var/www/mynode/mynode.py | 16 ++++++-- rootfs/standard/var/www/mynode/settings.py | 18 +++++---- .../mynode/templates/includes/info_table.html | 25 ++++++++++++ .../includes/main_page_messages.html | 38 ++++++++++++++++++ .../templates/includes/status_table.html | 4 +- .../www/mynode/templates/premium_plus.html | 4 +- .../var/www/mynode/thread_functions.py | 5 --- rootfs/standard/var/www/mynode/vpn.py | 4 +- 9 files changed, 131 insertions(+), 23 deletions(-) diff --git a/rootfs/standard/var/pynode/device_info.py b/rootfs/standard/var/pynode/device_info.py index 1960a84b..6ac962b7 100644 --- a/rootfs/standard/var/pynode/device_info.py +++ b/rootfs/standard/var/pynode/device_info.py @@ -752,8 +752,48 @@ def delete_product_key_error(): def recheck_product_key(): delete_product_key_error() + restart_check_in() + +#================================== +# Check In Functions +#================================== +def restart_check_in(): os.system("systemctl restart check_in") +def get_check_in_data(): + data = [] + try: + with open("/tmp/check_in_response.json", "r") as f: + data = json.load(f) + except Exception as e: + data = None + return data + +def dismiss_expiration_warning(): + touch("/tmp/dismiss_expiration_warning") + +def is_expiration_warning_dismissed(): + return os.path.isfile("/tmp/dismiss_expiration_warning") + +def is_support_near_expiration(): + data = get_check_in_data() + if data != None and "support" in data: + support = data["support"] + if "days_remaining" in support: + days_remaining = int(support["days_remaining"]) + if days_remaining >= -60 and days_remaining <= 45: + return True + return False + +def is_premium_plus_near_expiration(): + data = get_check_in_data() + if data != None and "premium_plus" in data: + premium_plus = data["premium_plus"] + if "days_remaining" in premium_plus: + days_remaining = int(premium_plus["days_remaining"]) + if days_remaining >= -60 and days_remaining <= 45: + return True + return False #================================== # Premium+ Token Functions diff --git a/rootfs/standard/var/www/mynode/mynode.py b/rootfs/standard/var/www/mynode/mynode.py index 4132aeb3..32c254c6 100644 --- a/rootfs/standard/var/www/mynode/mynode.py +++ b/rootfs/standard/var/www/mynode/mynode.py @@ -139,8 +139,8 @@ def index(): bitcoin_block_height = get_bitcoin_block_height() mynode_block_height = get_mynode_block_height() uptime_in_seconds = get_system_uptime_in_seconds() - pk_skipped = skipped_product_key() - pk_error = not is_valid_product_key() + product_key_skipped = skipped_product_key() + product_key_error = not is_valid_product_key() # Show uploader page if we are marked as an uploader if is_uploader(): @@ -551,8 +551,10 @@ def index(): "is_testnet_enabled": is_testnet_enabled(), "is_installing_docker_images": is_installing_docker_images(), "is_device_from_reseller": is_device_from_reseller(), - "product_key_skipped": pk_skipped, - "product_key_error": pk_error, + "is_expiration_warning_dismissed": is_expiration_warning_dismissed(), + "check_in_data": get_check_in_data(), + "product_key_skipped": product_key_skipped, + "product_key_error": product_key_error, "premium_plus_has_access_token": has_premium_plus_token(), "premium_plus_is_connected": get_premium_plus_is_connected(), "fsck_error": has_fsck_error(), @@ -664,6 +666,12 @@ def page_clear_fsck_error(): clear_fsck_error() return redirect("/") +@app.route("/dismiss-expiration-warning") +def page_dismiss_expiration_warning(): + check_logged_in() + dismiss_expiration_warning() + return redirect("/") + @app.route("/login", methods=["GET","POST"]) def page_login(): templateData = { diff --git a/rootfs/standard/var/www/mynode/settings.py b/rootfs/standard/var/www/mynode/settings.py index 312fac9b..88000ebd 100644 --- a/rootfs/standard/var/www/mynode/settings.py +++ b/rootfs/standard/var/www/mynode/settings.py @@ -36,8 +36,8 @@ def page_settings(): device_arch = get_device_arch() device_ram = get_device_ram() product_key = get_product_key() - pk_skipped = skipped_product_key() - pk_error = not is_valid_product_key() + product_key_skipped = skipped_product_key() + product_key_error = not is_valid_product_key() uptime = get_system_uptime() date = get_system_date() local_ip = get_local_ip() @@ -71,9 +71,10 @@ def page_settings(): "device_arch": device_arch, "device_ram": device_ram, "swap_size": get_swap_size(), + "check_in_data": get_check_in_data(), "product_key": product_key, - "product_key_skipped": pk_skipped, - "product_key_error": pk_error, + "product_key_skipped": product_key_skipped, + "product_key_error": product_key_error, "changelog": changelog, "is_https_forced": is_https_forced(), "logout_time_days": logout_time_days, @@ -134,8 +135,8 @@ def page_status(): device_arch = get_device_arch() device_ram = get_device_ram() product_key = get_product_key() - pk_skipped = skipped_product_key() - pk_error = not is_valid_product_key() + product_key_skipped = skipped_product_key() + product_key_error = not is_valid_product_key() uptime = get_system_uptime() date = get_system_date() local_ip = get_local_ip() @@ -193,9 +194,10 @@ def page_status(): "device_type": device_type, "device_arch": device_arch, "device_ram": device_ram, + "check_in_data": get_check_in_data(), "product_key": product_key, - "product_key_skipped": pk_skipped, - "product_key_error": pk_error, + "product_key_skipped": product_key_skipped, + "product_key_error": product_key_error, "changelog": changelog, "lnd_wallet_exists": lnd_wallet_exists(), "lnd_ready": is_lnd_ready(), diff --git a/rootfs/standard/var/www/mynode/templates/includes/info_table.html b/rootfs/standard/var/www/mynode/templates/includes/info_table.html index c77ba6d8..93f7154d 100644 --- a/rootfs/standard/var/www/mynode/templates/includes/info_table.html +++ b/rootfs/standard/var/www/mynode/templates/includes/info_table.html @@ -19,6 +19,31 @@ {% endif %} + {% if not product_key_skipped and check_in_data %} + + + Support + + {% if check_in_data.support is defined and check_in_data.support.active is defined and check_in_data.support.days_remaining is defined %} + {% if check_in_data.support.active %} + + {% if check_in_data.support.days_remaining|int < 45 %} + + Extend + {% endif %} + {% else %} + + {% if check_in_data.support.days_remaining|int > -45 %} + + {% endif %} + Extend + {% endif %} + {% else %} + Unknown - Missing Data + {% endif %} + + + {% endif %} Device Type diff --git a/rootfs/standard/var/www/mynode/templates/includes/main_page_messages.html b/rootfs/standard/var/www/mynode/templates/includes/main_page_messages.html index 6408ddb0..a60a7556 100644 --- a/rootfs/standard/var/www/mynode/templates/includes/main_page_messages.html +++ b/rootfs/standard/var/www/mynode/templates/includes/main_page_messages.html @@ -73,6 +73,44 @@ {% endif %} +{% if not is_expiration_warning_dismissed and check_in_data %} + {% set showing_expiration_warning = False %} + {% if check_in_data.premium_plus is defined and check_in_data.premium_plus.active is defined and check_in_data.premium_plus.days_remaining is defined %} + {% if not showing_expiration_warning and check_in_data.premium_plus.days_remaining|int <= 45 and check_in_data.premium_plus.days_remaining|int >= -45 %} + {% set showing_expiration_warning = True %} +
+

Warning!

+ {% if check_in_data.premium_plus.active %} +

Your Premium+ subscription will expire in {{check_in_data.premium_plus.days_remaining}} days! It can easily be extended via the button below.

+ {% else %} +

Your Premium+ subscription expired {{check_in_data.premium_plus.days_remaining|int|abs}} days ago! It can easily be extended via the button below.

+ {% endif %} +

+ Extend + Dismiss +

+
+ {% endif %} + {% endif %} + {% if not showing_expiration_warning and check_in_data.support is defined and check_in_data.support.active is defined and check_in_data.support.days_remaining is defined %} + {% if check_in_data.support.days_remaining|int <= 45 and check_in_data.support.days_remaining|int >= -45 %} + {% set showing_expiration_warning = True %} +
+

Warning!

+ {% if check_in_data.support.active %} +

Your support subscription will expire in {{check_in_data.support.days_remaining}} days! It can easily be extended via the button below.

+ {% else %} +

Your support subscription expired {{check_in_data.support.days_remaining|int|abs}} days ago! It can easily be extended via the button below.

+ {% endif %} +

+ Extend + Dismiss +

+
+ {% endif %} + {% endif %} +{% endif %} + {% if current_block > 100000 %} {% set blocks_until_halving = 210000 - (current_block % 210000) %} diff --git a/rootfs/standard/var/www/mynode/templates/includes/status_table.html b/rootfs/standard/var/www/mynode/templates/includes/status_table.html index d6433d19..fed43a9d 100644 --- a/rootfs/standard/var/www/mynode/templates/includes/status_table.html +++ b/rootfs/standard/var/www/mynode/templates/includes/status_table.html @@ -29,7 +29,7 @@ {{data_drive_usage}} {% set data_drive_usage_num = data_drive_usage | replace("%", "") | int %} {% if data_drive_usage_num >= 90 %} - + {% endif %}