From 72a96999dfb1d4f28040349b4b3dc3154d52fc23 Mon Sep 17 00:00:00 2001
From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com>
Date: Tue, 11 Mar 2025 01:01:08 +0330
Subject: [PATCH 01/16] feat: Add version checking and display Integrated
version checking into `cli_api.py` and `cli.py`
---
core/cli.py | 25 ++++++++++++++
core/cli_api.py | 12 +++++++
core/scripts/hysteria2/version.sh | 57 +++++++++++++++++++++++++++++++
3 files changed, 94 insertions(+)
create mode 100644 core/scripts/hysteria2/version.sh
diff --git a/core/cli.py b/core/cli.py
index 779e3a6..5679ea0 100644
--- a/core/cli.py
+++ b/core/cli.py
@@ -485,6 +485,31 @@ def get_services_status():
click.echo('Error: Services status not available.')
except Exception as e:
click.echo(f'{e}', err=True)
+
+
+@cli.command('show-version')
+def show_version():
+ """Displays the currently installed version of the panel."""
+ try:
+ if version_info := cli_api.show_version():
+ click.echo(version_info)
+ else:
+ click.echo("Error retrieving version")
+ except Exception as e:
+ click.echo(f"An unexpected error occurred: {e}", err=True)
+
+
+@cli.command('check-version')
+def check_version():
+ """Checks if the current version is up-to-date and displays changelog if not."""
+ try:
+ if version_info := cli_api.check_version():
+ click.echo(version_info)
+ else:
+ click.echo("Error retrieving version")
+ except Exception as e:
+ click.echo(f"An unexpected error occurred: {e}", err=True)
+
# endregion
diff --git a/core/cli_api.py b/core/cli_api.py
index d602d17..3615905 100644
--- a/core/cli_api.py
+++ b/core/cli_api.py
@@ -47,6 +47,7 @@ class Command(Enum):
CONFIGURE_WARP = os.path.join(SCRIPT_DIR, 'warp', 'configure.sh')
STATUS_WARP = os.path.join(SCRIPT_DIR, 'warp', 'status.sh')
SERVICES_STATUS = os.path.join(SCRIPT_DIR, 'services_status.sh')
+ VERSION = os.path.join(SCRIPT_DIR, 'hysteria2', 'version.sh')
# region Custom Exceptions
@@ -500,5 +501,16 @@ def get_services_status() -> dict[str, bool] | None:
'''Gets the status of all project services.'''
if res := run_cmd(['bash', Command.SERVICES_STATUS.value]):
return json.loads(res)
+
+
+def show_version() -> str | None:
+ """Displays the currently installed version of the panel."""
+ return run_cmd(['bash', Command.VERSION.value, 'show-version'])
+
+
+def check_version() -> str | None:
+ """Checks if the current version is up-to-date and displays changelog if not."""
+ return run_cmd(['bash', Command.VERSION.value, 'check-version'])
+
# endregion
# endregion
diff --git a/core/scripts/hysteria2/version.sh b/core/scripts/hysteria2/version.sh
new file mode 100644
index 0000000..754307c
--- /dev/null
+++ b/core/scripts/hysteria2/version.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+source /etc/hysteria/core/scripts/path.sh
+
+version_greater_equal() {
+ IFS='.' read -r -a local_version_parts <<< "$1"
+ IFS='.' read -r -a latest_version_parts <<< "$2"
+
+ for ((i=0; i<${#local_version_parts[@]}; i++)); do
+ if [[ -z ${latest_version_parts[i]} ]]; then
+ latest_version_parts[i]=0
+ fi
+
+ if ((10#${local_version_parts[i]} > 10#${latest_version_parts[i]})); then
+ return 0
+ elif ((10#${local_version_parts[i]} < 10#${latest_version_parts[i]})); then
+ return 1
+ fi
+ done
+
+ return 0
+}
+
+check_version() {
+ local_version=$(cat $LOCALVERSION)
+ latest_version=$(curl -s $LATESTVERSION)
+ latest_changelog=$(curl -s $LASTESTCHANGE)
+
+
+ if version_greater_equal "$local_version" "$latest_version"; then
+ echo "Panel Version: $local_version"
+ else
+ echo "Panel Version: $local_version"
+ echo "Latest Version: $latest_version"
+ echo "${yellow}$latest_version Version Change Log:"
+ echo "$latest_changelog"
+ fi
+}
+
+show_version() {
+
+ local_version=$(cat "$LOCALVERSION")
+ echo "Panel Version: $local_version"
+
+}
+
+
+if [ "$1" == "check-version" ]; then
+ check_version
+elif [ "$1" == "show-version" ]; then
+ show_version
+else
+ echo "Usage: $0 [check|show]" >&2
+ exit 1
+fi
+
+exit 0
\ No newline at end of file
From 3439503f8d9ecb5a457f44f1757847c7f139567f Mon Sep 17 00:00:00 2001
From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com>
Date: Tue, 11 Mar 2025 01:02:26 +0330
Subject: [PATCH 02/16] Created Pydantic schemas for version API responses
---
core/scripts/webpanel/routers/api/v1/schema/server.py | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/core/scripts/webpanel/routers/api/v1/schema/server.py b/core/scripts/webpanel/routers/api/v1/schema/server.py
index 9372c52..393f0bc 100644
--- a/core/scripts/webpanel/routers/api/v1/schema/server.py
+++ b/core/scripts/webpanel/routers/api/v1/schema/server.py
@@ -23,3 +23,13 @@ class ServerServicesStatusResponse(BaseModel):
hysteria_normal_sub: bool
hysteria_telegram_bot: bool
hysteria_warp: bool
+
+class VersionInfoResponse(BaseModel):
+ current_version: str
+
+
+class VersionCheckResponse(BaseModel):
+ is_latest: bool
+ current_version: str
+ latest_version: str
+ changelog: str
\ No newline at end of file
From 1f8bc93aa98bb5be19da4938bf7dc9f0d68c335a Mon Sep 17 00:00:00 2001
From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com>
Date: Tue, 11 Mar 2025 01:03:23 +0330
Subject: [PATCH 03/16] Added API endpoints for getting version info and
checking for updates
---
.../scripts/webpanel/routers/api/v1/server.py | 39 ++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/core/scripts/webpanel/routers/api/v1/server.py b/core/scripts/webpanel/routers/api/v1/server.py
index 2ef99b0..5639d9b 100644
--- a/core/scripts/webpanel/routers/api/v1/server.py
+++ b/core/scripts/webpanel/routers/api/v1/server.py
@@ -1,6 +1,6 @@
from fastapi import APIRouter, HTTPException
import cli_api
-from .schema.server import ServerStatusResponse, ServerServicesStatusResponse
+from .schema.server import ServerStatusResponse, ServerServicesStatusResponse, VersionCheckResponse, VersionInfoResponse
router = APIRouter()
@@ -144,3 +144,40 @@ def __parse_services_status(services_status: dict[str, bool]) -> ServerServicesS
elif 'wg-quick' in service:
parsed_services_status['hysteria_warp'] = status
return ServerServicesStatusResponse(**parsed_services_status)
+
+@router.get('/version', response_model=VersionInfoResponse)
+async def get_version_info():
+ """Retrieves the current version of the panel."""
+ try:
+ version_output = cli_api.show_version()
+ if version_output:
+ current_version = version_output.split(": ")[1].strip()
+ return VersionInfoResponse(current_version=current_version)
+ raise HTTPException(status_code=404, detail="Version information not found")
+ except Exception as e:
+ raise HTTPException(status_code=500, detail=str(e))
+
+
+@router.get('/version/check', response_model=VersionCheckResponse)
+async def check_version_info():
+ """Checks for updates and retrieves version information."""
+ try:
+ check_output = cli_api.check_version()
+ if check_output:
+ lines = check_output.splitlines()
+ current_version = lines[0].split(": ")[1].strip()
+
+ if len(lines) > 1 and "Latest Version" in lines[1]:
+ latest_version = lines[1].split(": ")[1].strip()
+ is_latest = current_version == latest_version
+ changelog_start_index = 3
+ changelog = "\n".join(lines[changelog_start_index:]).strip()
+ return VersionCheckResponse(is_latest=is_latest, current_version=current_version,
+ latest_version=latest_version, changelog=changelog)
+ else:
+ return VersionCheckResponse(is_latest=True, current_version=current_version)
+
+ raise HTTPException(status_code=404, detail="Version information not found")
+
+ except Exception as e:
+ raise HTTPException(status_code=500, detail=str(e))
\ No newline at end of file
From 4274a20b05149666b66e27e5e7c7c38406bfd707 Mon Sep 17 00:00:00 2001
From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com>
Date: Tue, 11 Mar 2025 01:09:26 +0330
Subject: [PATCH 04/16] Improved footer design and add version display
Updated `base.html` to display current version and show update notifications
Adde github and telegram link in footer
---
core/scripts/webpanel/templates/base.html | 81 +++++++++++++++++++----
1 file changed, 69 insertions(+), 12 deletions(-)
diff --git a/core/scripts/webpanel/templates/base.html b/core/scripts/webpanel/templates/base.html
index f327d32..f3115b1 100644
--- a/core/scripts/webpanel/templates/base.html
+++ b/core/scripts/webpanel/templates/base.html
@@ -15,6 +15,8 @@
+
+
{% block stylesheets %}{% endblock %}
@@ -114,11 +116,26 @@
{% block content %}{% endblock %}
-
-
+
+
@@ -127,16 +144,18 @@
+
+
{% block javascripts %}{% endblock %}