diff --git a/src/ui/app/routes/plugins.py b/src/ui/app/routes/plugins.py index 5fd5eeaa7..f2b373f16 100644 --- a/src/ui/app/routes/plugins.py +++ b/src/ui/app/routes/plugins.py @@ -457,6 +457,12 @@ def upload_plugin(): return {"status": "ok"}, 201 +@plugins.route("/plugins/", methods=["GET"]) +@login_required +def custom_plugin_page(plugin: str): + return render_template("plugin_page.html") + + # @plugins.route("/plugins/", methods=["GET", "POST"]) # @login_required # def custom_plugin(plugin: str): diff --git a/src/ui/app/routes/pro.py b/src/ui/app/routes/pro.py index 60186cf1c..a9db8c424 100644 --- a/src/ui/app/routes/pro.py +++ b/src/ui/app/routes/pro.py @@ -1,11 +1,88 @@ -from flask import Blueprint, render_template +from datetime import datetime +from threading import Thread +from time import time +from typing import Dict +from flask import Blueprint, redirect, render_template, request, url_for from flask_login import login_required +from app.dependencies import BW_CONFIG, DATA, DB +from app.routes.utils import get_remain, handle_error, manage_bunkerweb, verify_data_in_form, wait_applying +from app.utils import LOGGER, flash + pro = Blueprint("pro", __name__) -@pro.route("/pro") +@pro.route("/pro", methods=["GET"]) @login_required def pro_page(): - return render_template("pro.html") + online_services = 0 + draft_services = 0 + for service in DB.get_services(with_drafts=True): + if service["is_draft"]: + draft_services += 1 + continue + online_services += 1 + + metadata = DB.get_metadata() + current_day = datetime.now().astimezone().replace(hour=0, minute=0, second=0, microsecond=0) + pro_expires_in = "Unknown" + if metadata["pro_expire"]: + exp = (metadata["pro_expire"].astimezone() - current_day).total_seconds() + remain = ("Unknown", "Unknown") if exp <= 0 else get_remain(exp) + pro_expires_in = remain[0] + + return render_template( + "pro.html", + online_services=online_services, + draft_services=draft_services, + pro_expires_in=pro_expires_in, + ) + + +@pro.route("/pro/key", methods=["POST"]) +@login_required +def pro_key(): + if DB.readonly: + return handle_error("Database is in read-only mode", "pro") + + verify_data_in_form( + data={"PRO_LICENSE_KEY": None}, + err_message="Missing license key parameter on /pro/key.", + redirect_url="pro", + next=True, + ) + license_key = request.form["PRO_LICENSE_KEY"] + if not license_key: + return handle_error("Invalid license key", "pro") + + global_config = DB.get_config(global_only=True, methods=True, filtered_settings=("PRO_LICENSE_KEY")) + variables = BW_CONFIG.check_variables({"PRO_LICENSE_KEY": license_key}, global_config, global_config=True) + + if not variables: + flash("The license key is the same as the current one.", "warning") + return redirect(url_for("pro.pro_page")) + + DATA.load_from_file() + + def update_license_key(license_key: str): + wait_applying() + manage_bunkerweb("global_config", {"PRO_LICENSE_KEY": license_key}, threaded=True) + + DATA.update( + { + "RELOADING": True, + "LAST_RELOAD": time(), + "CONFIG_CHANGED": True, + "PRO_LOADING": True, + } + ) + flash("Checking license key.") + Thread(target=update_license_key, args=(license_key,)).start() + return redirect( + url_for( + "loading", + next=url_for("pro.pro_page"), + message="Updating license key", + ) + ) diff --git a/src/ui/app/static/css/overrides.css b/src/ui/app/static/css/overrides.css index 33bffd754..2f0ec9a29 100644 --- a/src/ui/app/static/css/overrides.css +++ b/src/ui/app/static/css/overrides.css @@ -747,7 +747,8 @@ a.text-white-80:hover { padding-bottom: 0.625rem !important; } -.footer-container .footer-link:hover { +.footer-container .footer-link:hover, +a.courier-prime:hover { font-style: italic; text-decoration: underline; } diff --git a/src/ui/app/static/js/pages/bans.js b/src/ui/app/static/js/pages/bans.js index ecb9cf14f..f2c091b50 100644 --- a/src/ui/app/static/js/pages/bans.js +++ b/src/ui/app/static/js/pages/bans.js @@ -41,7 +41,7 @@ $(document).ready(function () { } // Select the Flatpickr input elements - const flatpickrDatetime = $("[type='flapickr-datetime']"); + const flatpickrDatetime = $("[type='flatpickr-datetime']"); // Get the current date and times const currentDatetime = new Date(); diff --git a/src/ui/app/static/js/pages/pro.js b/src/ui/app/static/js/pages/pro.js new file mode 100644 index 000000000..a227f000f --- /dev/null +++ b/src/ui/app/static/js/pages/pro.js @@ -0,0 +1,9 @@ +$(document).ready(function () { + // Select the Flatpickr input elements + const $flatpickrDate = $("#flatpickr-date"); + + // Initialize Flatpickr with altInput and altFormat + $flatpickrDate.flatpickr({ + inline: true, + }); +}); diff --git a/src/ui/app/templates/bans.html b/src/ui/app/templates/bans.html index 127c8c24f..71705eb7a 100644 --- a/src/ui/app/templates/bans.html +++ b/src/ui/app/templates/bans.html @@ -118,7 +118,7 @@ required />
- diff --git a/src/ui/app/templates/base.html b/src/ui/app/templates/base.html index b8f0fe213..e98a7d46f 100644 --- a/src/ui/app/templates/base.html +++ b/src/ui/app/templates/base.html @@ -57,7 +57,7 @@ href="{{ url_for('static', filename='libs/datatables/datatables.min.css') }}" nonce="{{ style_nonce }}" /> {% endif %} - {% if current_endpoint == "bans" or current_endpoint != "plugins" and "plugins" in request.path %} + {% if current_endpoint in ("bans", "pro") or current_endpoint != "plugins" and "plugins" in request.path %} {% endif %} - {% if current_endpoint == "bans" or current_endpoint != "plugins" and "plugins" in request.path %} + {% if current_endpoint in ("bans", "pro") or current_endpoint != "plugins" and "plugins" in request.path %} + {% elif current_endpoint == "pro" %} + {% endif %} diff --git a/src/ui/app/templates/cache.html b/src/ui/app/templates/cache.html index cad2063c7..05140719f 100644 --- a/src/ui/app/templates/cache.html +++ b/src/ui/app/templates/cache.html @@ -3,12 +3,14 @@
+ - + id="cache_service_selection" + value="{{ cache_service }}" /> - +
+ + - - + id="configs_service_selection" + value="{{ config_service }}" /> - Upgrade to Pro + Upgrade to PRO
{% endif %}
diff --git a/src/ui/app/templates/flash.html b/src/ui/app/templates/flash.html index 0226d9217..8a5d37466 100644 --- a/src/ui/app/templates/flash.html +++ b/src/ui/app/templates/flash.html @@ -2,7 +2,7 @@ class="toast-container position-fixed bottom-0 end-0 mb-3 me-3"> {% with messages = get_flashed_messages(with_categories=true) %} - {% if pro_overlapped %} + {% if pro_overlapped and current_endpoint != "pro" %} {% if messages.append(('error', 'You have more services than allowed by your pro license. Upgrade your license or move some services to draft mode to unlock your pro license.')) %} {% endif %} {% endif %} diff --git a/src/ui/app/templates/home.html b/src/ui/app/templates/home.html index 6177c91a3..f189e5d2a 100644 --- a/src/ui/app/templates/home.html +++ b/src/ui/app/templates/home.html @@ -3,9 +3,16 @@
-
- -

+

+ {% if is_pro_version %} + Pro plugin + {% else %} + + {% endif %} +

Plan
@@ -16,8 +23,13 @@ {% endif %}

- Upgrade? + + {% if is_pro_version %} + More info + {% else %} + Upgrade? + {% endif %} +
diff --git a/src/ui/app/templates/menu.html b/src/ui/app/templates/menu.html index 2d20d1038..5204a86b8 100644 --- a/src/ui/app/templates/menu.html +++ b/src/ui/app/templates/menu.html @@ -79,7 +79,7 @@