Add warning and info about support and premium+ subscriptions

This commit is contained in:
Taylor Helsper 2022-08-03 21:17:59 -05:00
parent 901ed34adc
commit 0049288334
9 changed files with 131 additions and 23 deletions

View File

@ -752,8 +752,48 @@ def delete_product_key_error():
def recheck_product_key(): def recheck_product_key():
delete_product_key_error() delete_product_key_error()
restart_check_in()
#==================================
# Check In Functions
#==================================
def restart_check_in():
os.system("systemctl 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 # Premium+ Token Functions

View File

@ -139,8 +139,8 @@ def index():
bitcoin_block_height = get_bitcoin_block_height() bitcoin_block_height = get_bitcoin_block_height()
mynode_block_height = get_mynode_block_height() mynode_block_height = get_mynode_block_height()
uptime_in_seconds = get_system_uptime_in_seconds() uptime_in_seconds = get_system_uptime_in_seconds()
pk_skipped = skipped_product_key() product_key_skipped = skipped_product_key()
pk_error = not is_valid_product_key() product_key_error = not is_valid_product_key()
# Show uploader page if we are marked as an uploader # Show uploader page if we are marked as an uploader
if is_uploader(): if is_uploader():
@ -551,8 +551,10 @@ def index():
"is_testnet_enabled": is_testnet_enabled(), "is_testnet_enabled": is_testnet_enabled(),
"is_installing_docker_images": is_installing_docker_images(), "is_installing_docker_images": is_installing_docker_images(),
"is_device_from_reseller": is_device_from_reseller(), "is_device_from_reseller": is_device_from_reseller(),
"product_key_skipped": pk_skipped, "is_expiration_warning_dismissed": is_expiration_warning_dismissed(),
"product_key_error": pk_error, "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_has_access_token": has_premium_plus_token(),
"premium_plus_is_connected": get_premium_plus_is_connected(), "premium_plus_is_connected": get_premium_plus_is_connected(),
"fsck_error": has_fsck_error(), "fsck_error": has_fsck_error(),
@ -664,6 +666,12 @@ def page_clear_fsck_error():
clear_fsck_error() clear_fsck_error()
return redirect("/") 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"]) @app.route("/login", methods=["GET","POST"])
def page_login(): def page_login():
templateData = { templateData = {

View File

@ -36,8 +36,8 @@ def page_settings():
device_arch = get_device_arch() device_arch = get_device_arch()
device_ram = get_device_ram() device_ram = get_device_ram()
product_key = get_product_key() product_key = get_product_key()
pk_skipped = skipped_product_key() product_key_skipped = skipped_product_key()
pk_error = not is_valid_product_key() product_key_error = not is_valid_product_key()
uptime = get_system_uptime() uptime = get_system_uptime()
date = get_system_date() date = get_system_date()
local_ip = get_local_ip() local_ip = get_local_ip()
@ -71,9 +71,10 @@ def page_settings():
"device_arch": device_arch, "device_arch": device_arch,
"device_ram": device_ram, "device_ram": device_ram,
"swap_size": get_swap_size(), "swap_size": get_swap_size(),
"check_in_data": get_check_in_data(),
"product_key": product_key, "product_key": product_key,
"product_key_skipped": pk_skipped, "product_key_skipped": product_key_skipped,
"product_key_error": pk_error, "product_key_error": product_key_error,
"changelog": changelog, "changelog": changelog,
"is_https_forced": is_https_forced(), "is_https_forced": is_https_forced(),
"logout_time_days": logout_time_days, "logout_time_days": logout_time_days,
@ -134,8 +135,8 @@ def page_status():
device_arch = get_device_arch() device_arch = get_device_arch()
device_ram = get_device_ram() device_ram = get_device_ram()
product_key = get_product_key() product_key = get_product_key()
pk_skipped = skipped_product_key() product_key_skipped = skipped_product_key()
pk_error = not is_valid_product_key() product_key_error = not is_valid_product_key()
uptime = get_system_uptime() uptime = get_system_uptime()
date = get_system_date() date = get_system_date()
local_ip = get_local_ip() local_ip = get_local_ip()
@ -193,9 +194,10 @@ def page_status():
"device_type": device_type, "device_type": device_type,
"device_arch": device_arch, "device_arch": device_arch,
"device_ram": device_ram, "device_ram": device_ram,
"check_in_data": get_check_in_data(),
"product_key": product_key, "product_key": product_key,
"product_key_skipped": pk_skipped, "product_key_skipped": product_key_skipped,
"product_key_error": pk_error, "product_key_error": product_key_error,
"changelog": changelog, "changelog": changelog,
"lnd_wallet_exists": lnd_wallet_exists(), "lnd_wallet_exists": lnd_wallet_exists(),
"lnd_ready": is_lnd_ready(), "lnd_ready": is_lnd_ready(),

View File

@ -19,6 +19,31 @@
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
{% if not product_key_skipped and check_in_data %}
<!-- Only show support and not P+, it would be redundant in most cases -->
<tr>
<th>Support</th>
<td>
{% 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 %}
<i class='fas fa-check' style="vertical-align: middle;" data-toggle='tooltip' data-placement='bottom' title='Active - Expires in {{check_in_data.support.days_remaining}} days'></i>
{% if check_in_data.support.days_remaining|int < 45 %}
<i class='fas fa-exclamation' style="color: red; vertical-align: middle; margin-left: 5px;" data-toggle='tooltip' data-placement='bottom' title='Expiring Soon! {{check_in_data.support.days_remaining}} days remaining.'></i>
<a href="https://mynodebtc.com/order/premium_plus" target="_blank" style="margin-left: 5px;" class="ui-button ui-widget ui-corner-all settings_button_small">Extend</a>
{% endif %}
{% else %}
<i class='fas fa-times' style="vertical-align: middle;" data-toggle='tooltip' data-placement='bottom' title='Inactive - Expired {{check_in_data.support.days_remaining|int|abs}} days ago'></i>
{% if check_in_data.support.days_remaining|int > -45 %}
<i class='fas fa-exclamation' style="color: red; vertical-align: middle; margin-left: 5px;" data-toggle='tooltip' data-placement='bottom' title='Expired recently! Expired {{check_in_data.support.days_remaining|int|abs}} days ago.'></i>
{% endif %}
<a href="https://mynodebtc.com/order/premium_plus" target="_blank" style="margin-left: 5px;" class="ui-button ui-widget ui-corner-all settings_button_small">Extend</a>
{% endif %}
{% else %}
Unknown - Missing Data
{% endif %}
</td>
</tr>
{% endif %}
<tr> <tr>
<th>Device Type</th> <th>Device Type</th>
<td> <td>

View File

@ -73,6 +73,44 @@
</div> </div>
{% endif %} {% 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 %}
<div class="main_page_warning_block">
<p style="text-align: center;"><b>Warning!</b></p>
{% if check_in_data.premium_plus.active %}
<p style="text-align: center;">Your Premium+ subscription will expire in {{check_in_data.premium_plus.days_remaining}} days! It can easily be extended via the button below.</p>
{% else %}
<p style="text-align: center;">Your Premium+ subscription expired {{check_in_data.premium_plus.days_remaining|int|abs}} days ago! It can easily be extended via the button below.</p>
{% endif %}
<p style="text-align: center;">
<a href="https://mynodebtc.com/order/premium_plus" target="_blank" style="margin: 5px;" class="ui-button ui-widget ui-corner-all settings_button_small">Extend</a>
<a href="/dismiss-expiration-warning" style="margin: 5px;" class="ui-button ui-widget ui-corner-all settings_button_small">Dismiss</a>
</p>
</div>
{% 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 %}
<div class="main_page_warning_block">
<p style="text-align: center;"><b>Warning!</b></p>
{% if check_in_data.support.active %}
<p style="text-align: center;">Your support subscription will expire in {{check_in_data.support.days_remaining}} days! It can easily be extended via the button below.</p>
{% else %}
<p style="text-align: center;">Your support subscription expired {{check_in_data.support.days_remaining|int|abs}} days ago! It can easily be extended via the button below.</p>
{% endif %}
<p style="text-align: center;">
<a href="https://mynodebtc.com/order/premium_plus" target="_blank" style="margin: 5px;" class="ui-button ui-widget ui-corner-all settings_button_small">Extend</a>
<a href="/dismiss-expiration-warning" style="margin: 5px;" class="ui-button ui-widget ui-corner-all settings_button_small">Dismiss</a>
</p>
</div>
{% endif %}
{% endif %}
{% endif %}
<!-- Make sure blocks are syncing, otherwise on startup block 0 may show halving --> <!-- Make sure blocks are syncing, otherwise on startup block 0 may show halving -->
{% if current_block > 100000 %} {% if current_block > 100000 %}
{% set blocks_until_halving = 210000 - (current_block % 210000) %} {% set blocks_until_halving = 210000 - (current_block % 210000) %}

View File

@ -29,7 +29,7 @@
{{data_drive_usage}} {{data_drive_usage}}
{% set data_drive_usage_num = data_drive_usage | replace("%", "") | int %} {% set data_drive_usage_num = data_drive_usage | replace("%", "") | int %}
{% if data_drive_usage_num >= 90 %} {% if data_drive_usage_num >= 90 %}
<i class="fas fa-exclamation-triangle" title="Drive is nearly full!"></i> <i class="fas fa-exclamation" style="color: red; vertical-align: middle;" title="Drive is nearly full!"></i>
{% endif %} {% endif %}
<button id="show_data_drive_usage_details" class="ui-button ui-widget ui-corner-all settings_button_small" style="margin-left: 20px;">Show Details</button> <button id="show_data_drive_usage_details" class="ui-button ui-widget ui-corner-all settings_button_small" style="margin-left: 20px;">Show Details</button>
<span id="data_drive_usage_details" style="display: none"> <span id="data_drive_usage_details" style="display: none">
@ -44,7 +44,7 @@
{{os_drive_usage}} {{os_drive_usage}}
{% set os_drive_usage_num = os_drive_usage | replace("%", "") | int %} {% set os_drive_usage_num = os_drive_usage | replace("%", "") | int %}
{% if os_drive_usage_num >= 90 %} {% if os_drive_usage_num >= 90 %}
<i class="fas fa-exclamation-triangle" title="Drive is nearly full!"></i> <i class="fas fa-exclamation" style="color: red; vertical-align: middle;" title="Drive is nearly full!"></i>
{% endif %} {% endif %}
<button id="show_os_drive_usage_details" class="ui-button ui-widget ui-corner-all settings_button_small" style="margin-left: 20px;">Show Details</button> <button id="show_os_drive_usage_details" class="ui-button ui-widget ui-corner-all settings_button_small" style="margin-left: 20px;">Show Details</button>
<span id="os_drive_usage_details" style="display: none"> <span id="os_drive_usage_details" style="display: none">

View File

@ -200,13 +200,13 @@
{% if "days_remaining" in response_data.subscription and response_data.subscription.days_remaining|int < 45 %} {% if "days_remaining" in response_data.subscription and response_data.subscription.days_remaining|int < 45 %}
<br/> <br/>
<small> <small>
Expiring Soon! {{response_data.subscription.days_remaining}} days remaining <i class="fas fa-exclamation-triangle" style="color: orange;"></i> Expiring Soon! {{response_data.subscription.days_remaining}} days remaining. <i class="fas fa-exclamation" style="color: orange;"></i>
<br/> <br/>
<a href="https://mynodebtc.com/order/premium_plus" target="_blank" style="margin-top: 10px;" class="ui-button ui-widget ui-corner-all mynode_button_small">Extend</a> <a href="https://mynodebtc.com/order/premium_plus" target="_blank" style="margin-top: 10px;" class="ui-button ui-widget ui-corner-all mynode_button_small">Extend</a>
</small> </small>
{% endif %} {% endif %}
{% else %} {% else %}
Expired! <i class="fas fa-exclamation-triangle" style="color: red;"></i> Expired! <i class="fas fa-exclamation" style="color: red;"></i>
<br/> <br/>
<a href="https://mynodebtc.com/order/premium_plus" target="_blank" style="margin-top: 10px;" class="ui-button ui-widget ui-corner-all mynode_button_small">Renew</a> <a href="https://mynodebtc.com/order/premium_plus" target="_blank" style="margin-top: 10px;" class="ui-button ui-widget ui-corner-all mynode_button_small">Renew</a>
{% endif %} {% endif %}

View File

@ -174,11 +174,6 @@ def find_public_ip():
public_ip = "Failed to find public IP. " public_ip = "Failed to find public IP. "
# Updated: Check ins now happen in different process. This will just restart the service to force a new check in.
def check_in():
os.system("systemctl restart check_in")
def dmesg_log_clear(): def dmesg_log_clear():
f = open("/tmp/dmesg", "w") f = open("/tmp/dmesg", "w")
f.write("") f.write("")

View File

@ -1,5 +1,5 @@
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, 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 thread_functions import get_public_ip, find_public_ip
from device_info import is_community_edition, read_ui_settings from device_info import is_community_edition, read_ui_settings
from user_management import check_logged_in from user_management import check_logged_in
from utilities import * from utilities import *
@ -85,7 +85,7 @@ def page_download_ovpn():
return download_file(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") @mynode_vpn.route("/vpn-info/find-public-ip")
def check_in_page(): def find_public_ip_page():
check_logged_in() check_logged_in()
find_public_ip() find_public_ip()
return redirect("/vpn-info") return redirect("/vpn-info")