-
+
From b5af06708d2e428647b1af48fcbdc1a8b07323df Mon Sep 17 00:00:00 2001
From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com>
Date: Fri, 23 May 2025 12:16:58 +0330
Subject: [PATCH 3/6] feat: add API endpoint to fetch IP Limiter configuration
---
core/cli_api.py | 18 +++++
.../routers/api/v1/config/hysteria.py | 10 ++-
.../routers/api/v1/schema/response.py | 10 ++-
core/scripts/webpanel/templates/settings.html | 79 +++++++++++++------
4 files changed, 88 insertions(+), 29 deletions(-)
diff --git a/core/cli_api.py b/core/cli_api.py
index ad7a8e2..d491288 100644
--- a/core/cli_api.py
+++ b/core/cli_api.py
@@ -630,4 +630,22 @@ def config_ip_limiter(block_duration: int = None, max_ips: int = None):
cmd_args.append('')
run_cmd(cmd_args)
+
+def get_ip_limiter_config() -> dict[str, int | None]:
+ '''Retrieves the current IP Limiter configuration from .configs.env.'''
+ try:
+ if not os.path.exists(CONFIG_ENV_FILE):
+ return {"block_duration": None, "max_ips": None}
+
+ env_vars = dotenv_values(CONFIG_ENV_FILE)
+ block_duration_str = env_vars.get('BLOCK_DURATION')
+ max_ips_str = env_vars.get('MAX_IPS')
+
+ block_duration = int(block_duration_str) if block_duration_str and block_duration_str.isdigit() else None
+ max_ips = int(max_ips_str) if max_ips_str and max_ips_str.isdigit() else None
+
+ return {"block_duration": block_duration, "max_ips": max_ips}
+ except Exception as e:
+ print(f"Error reading IP Limiter config from .configs.env: {e}")
+ return {"block_duration": None, "max_ips": None}
# endregion
diff --git a/core/scripts/webpanel/routers/api/v1/config/hysteria.py b/core/scripts/webpanel/routers/api/v1/config/hysteria.py
index 20535ea..2f08f59 100644
--- a/core/scripts/webpanel/routers/api/v1/config/hysteria.py
+++ b/core/scripts/webpanel/routers/api/v1/config/hysteria.py
@@ -1,6 +1,6 @@
from fastapi import APIRouter, BackgroundTasks, HTTPException, UploadFile, File
from ..schema.config.hysteria import ConfigFile, GetPortResponse, GetSniResponse
-from ..schema.response import DetailResponse, IPLimitConfig, SetupDecoyRequest, DecoyStatusResponse
+from ..schema.response import DetailResponse, IPLimitConfig, SetupDecoyRequest, DecoyStatusResponse, IPLimitConfigResponse
from fastapi.responses import FileResponse
import shutil
import zipfile
@@ -335,6 +335,14 @@ async def config_ip_limit_api(config: IPLimitConfig):
except Exception as e:
raise HTTPException(status_code=400, detail=f'Error configuring IP Limiter: {str(e)}')
+@router.get('/ip-limit/config', response_model=IPLimitConfigResponse, summary='Get IP Limiter Configuration')
+async def get_ip_limit_config_api():
+ """Retrieves the current IP Limiter configuration."""
+ try:
+ config = cli_api.get_ip_limiter_config()
+ return IPLimitConfigResponse(**config)
+ except Exception as e:
+ raise HTTPException(status_code=500, detail=f'Error retrieving IP Limiter configuration: {str(e)}')
def run_setup_decoy_background(domain: str, decoy_path: str):
"""Function to run decoy setup in the background."""
diff --git a/core/scripts/webpanel/routers/api/v1/schema/response.py b/core/scripts/webpanel/routers/api/v1/schema/response.py
index 22ebbd2..acacc20 100644
--- a/core/scripts/webpanel/routers/api/v1/schema/response.py
+++ b/core/scripts/webpanel/routers/api/v1/schema/response.py
@@ -6,8 +6,12 @@ class DetailResponse(BaseModel):
detail: str
class IPLimitConfig(BaseModel):
- block_duration: Optional[int] = None
- max_ips: Optional[int] = None
+ block_duration: Optional[int] = Field(None, example=60)
+ max_ips: Optional[int] = Field(None, example=1)
+
+class IPLimitConfigResponse(BaseModel):
+ block_duration: Optional[int] = Field(None, description="Current block duration in seconds for IP Limiter")
+ max_ips: Optional[int] = Field(None, description="Current maximum IPs per user for IP Limiter")
class SetupDecoyRequest(BaseModel):
domain: str = Field(..., description="Domain name associated with the web panel")
@@ -15,4 +19,4 @@ class SetupDecoyRequest(BaseModel):
class DecoyStatusResponse(BaseModel):
active: bool = Field(..., description="Whether the decoy site is currently configured and active")
- path: Optional[str] = Field(None, description="The configured path for the decoy site, if active")
+ path: Optional[str] = Field(None, description="The configured path for the decoy site, if active")
\ No newline at end of file
diff --git a/core/scripts/webpanel/templates/settings.html b/core/scripts/webpanel/templates/settings.html
index 5f0d733..c4c5c58 100644
--- a/core/scripts/webpanel/templates/settings.html
+++ b/core/scripts/webpanel/templates/settings.html
@@ -451,7 +451,9 @@
} else if (id === 'decoy_path') {
fieldValid = isValidPath(input.val());
} else {
- fieldValid = input.val().trim() !== "";
+ if (input.attr('placeholder') && input.attr('placeholder').includes('Enter') && !input.attr('id').startsWith('ipv')) {
+ fieldValid = input.val().trim() !== "";
+ }
}
if (!fieldValid) {
@@ -521,22 +523,22 @@
};
Object.keys(servicesMap).forEach(service => {
- let formSelector = servicesMap[service];
+ let targetSelector = servicesMap[service];
let isRunning = data[service];
if (service === "hysteria_normal_sub") {
- const $normalFormGroups = $("#normal_sub_service_form .form-group");
+ const $normalForm = $("#normal_sub_service_form");
+ const $normalFormGroups = $normalForm.find(".form-group");
const $normalStartBtn = $("#normal_start");
const $normalStopBtn = $("#normal_stop");
- const $normalAlert = $("#normal_sub_service_form .alert-info");
const $normalSubConfigTabLi = $(".normal-sub-config-tab-li");
if (isRunning) {
$normalFormGroups.hide();
$normalStartBtn.hide();
$normalStopBtn.show();
- if ($normalAlert.length === 0) {
- $("#normal_sub_service_form").prepend(`NormalSub service is running. You can stop it or configure its subpath.
`);
+ if ($normalForm.find(".alert-info").length === 0) {
+ $normalForm.prepend(`NormalSub service is running. You can stop it or configure its subpath.
`);
}
$normalSubConfigTabLi.show();
fetchNormalSubPath();
@@ -544,7 +546,7 @@
$normalFormGroups.show();
$normalStartBtn.show();
$normalStopBtn.hide();
- $("#normal_sub_service_form .alert-info").remove();
+ $normalForm.find(".alert-info").remove();
$normalSubConfigTabLi.hide();
if ($('#normal-sub-config-link-tab').hasClass('active')) {
$('#normal-tab').tab('show');
@@ -553,31 +555,40 @@
$("#normal_subpath_input").removeClass('is-invalid');
}
} else if (service === "hysteria_iplimit") {
+ const $ipLimitServiceForm = $("#ip_limit_service_form");
+ const $configTabLi = $(".ip-limit-config-tab-li");
if (isRunning) {
$("#ip_limit_start").hide();
$("#ip_limit_stop").show();
- $(".ip-limit-config-tab-li").show();
- // TODO: Fetch IP Limit Config and populate fields
+ $configTabLi.show();
+ fetchIpLimitConfig();
+ if ($ipLimitServiceForm.find(".alert-info").length === 0) {
+ $ipLimitServiceForm.prepend(`IP-Limit service is running. You can stop it if needed.
`);
+ }
} else {
$("#ip_limit_start").show();
$("#ip_limit_stop").hide();
- $(".ip-limit-config-tab-li").hide();
+ $configTabLi.hide();
$('#ip-limit-service-tab').tab('show');
- // TODO: Clear IP Limit Config fields
+ $ipLimitServiceForm.find(".alert-info").remove();
+ $("#block_duration").val("");
+ $("#max_ips").val("");
+ $("#block_duration, #max_ips").removeClass('is-invalid');
}
} else {
+ const $formSelector = $(targetSelector);
if (isRunning) {
- $(formSelector + " .form-group").hide();
- $(formSelector + " .btn-success").hide();
- $(formSelector + " .btn-danger").show();
- if ($(formSelector + " .alert-info").length === 0) {
- $(formSelector).prepend(`Service is running. You can stop it if needed.
`);
+ $formSelector.find(".form-group").hide();
+ $formSelector.find(".btn-success").hide();
+ $formSelector.find(".btn-danger").show();
+ if ($formSelector.find(".alert-info").length === 0) {
+ $formSelector.prepend(`Service is running. You can stop it if needed.
`);
}
} else {
- $(formSelector + " .form-group").show();
- $(formSelector + " .btn-success").show();
- $(formSelector + " .btn-danger").hide();
- $(formSelector + " .alert-info").remove();
+ $formSelector.find(".form-group").show();
+ $formSelector.find(".btn-success").show();
+ $formSelector.find(".btn-danger").hide();
+ $formSelector.find(".alert-info").remove();
}
}
});
@@ -596,7 +607,24 @@
error: function (xhr, status, error) {
console.error("Failed to fetch NormalSub subpath:", error, xhr.responseText);
$("#normal_subpath_input").val("");
- // Swal.fire("Error!", "Could not fetch NormalSub subpath.", "error"); // Avoid too many popups during init
+ }
+ });
+ }
+
+ function fetchIpLimitConfig() {
+ $.ajax({
+ url: "{{ url_for('get_ip_limit_config_api') }}",
+ type: "GET",
+ success: function (data) {
+ $("#block_duration").val(data.block_duration || "");
+ $("#max_ips").val(data.max_ips || "");
+ if (data.block_duration) $("#block_duration").removeClass('is-invalid');
+ if (data.max_ips) $("#max_ips").removeClass('is-invalid');
+ },
+ error: function (xhr, status, error) {
+ console.error("Failed to fetch IP Limit config:", error, xhr.responseText);
+ $("#block_duration").val("");
+ $("#max_ips").val("");
}
});
}
@@ -883,7 +911,7 @@
}
function configIPLimit() {
- if (!validateForm('ip_limit_config_form')) return; // Ensure correct form ID
+ if (!validateForm('ip_limit_config_form')) return;
const blockDuration = $("#block_duration").val();
const maxIps = $("#max_ips").val();
confirmAction("save the IP Limit configuration", function () {
@@ -893,7 +921,8 @@
{ block_duration: parseInt(blockDuration), max_ips: parseInt(maxIps) },
"IP Limit configuration saved successfully!",
"#ip_limit_change_config",
- false
+ false,
+ fetchIpLimitConfig
);
});
}
@@ -977,8 +1006,8 @@
$(this).removeClass('is-invalid');
} else if ($(this).val().trim() !== "") {
$(this).addClass('is-invalid');
- } else {
- $(this).removeClass('is-invalid');
+ } else {
+ $(this).addClass('is-invalid');
}
});
From c7ed9b3aef1dadca04326a533f02dcf5ae6a43b9 Mon Sep 17 00:00:00 2001
From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com>
Date: Fri, 23 May 2025 13:01:22 +0330
Subject: [PATCH 4/6] feat: add reset webpanel admin credentials
---
core/cli.py | 22 +++++++++
core/cli_api.py | 12 +++++
core/scripts/webpanel/webpanel_shell.sh | 65 +++++++++++++++++++++++++
3 files changed, 99 insertions(+)
diff --git a/core/cli.py b/core/cli.py
index 6672e5b..ab0c9f7 100644
--- a/core/cli.py
+++ b/core/cli.py
@@ -523,6 +523,28 @@ def get_web_panel_api_token():
except Exception as e:
click.echo(f'{e}', err=True)
+@cli.command('reset-webpanel-creds')
+@click.option('--new-username', '-u', required=False, help='New admin username for WebPanel', type=str)
+@click.option('--new-password', '-p', required=False, help='New admin password for WebPanel', type=str)
+def reset_webpanel_creds(new_username: str | None, new_password: str | None):
+ """Resets the WebPanel admin username and/or password."""
+ try:
+ if not new_username and not new_password:
+ raise click.UsageError('Error: You must provide either --new-username or --new-password, or both.')
+
+ cli_api.reset_webpanel_credentials(new_username, new_password)
+
+ message_parts = []
+ if new_username:
+ message_parts.append(f"username to '{new_username}'")
+ if new_password:
+ message_parts.append("password")
+
+ click.echo(f'WebPanel admin {" and ".join(message_parts)} updated successfully.')
+ click.echo('WebPanel service has been restarted.')
+ except Exception as e:
+ click.echo(f'{e}', err=True)
+
@cli.command('get-webpanel-services-status')
def get_web_panel_services_status():
diff --git a/core/cli_api.py b/core/cli_api.py
index d491288..834da6c 100644
--- a/core/cli_api.py
+++ b/core/cli_api.py
@@ -588,6 +588,18 @@ def get_webpanel_api_token() -> str | None:
'''Gets the API token of WebPanel.'''
return run_cmd(['bash', Command.SHELL_WEBPANEL.value, 'api-token'])
+def reset_webpanel_credentials(new_username: str | None = None, new_password: str | None = None):
+ '''Resets the WebPanel admin username and/or password.'''
+ if not new_username and not new_password:
+ raise InvalidInputError('Error: At least new username or new password must be provided.')
+
+ cmd_args = ['bash', Command.SHELL_WEBPANEL.value, 'resetcreds']
+ if new_username:
+ cmd_args.extend(['-u', new_username])
+ if new_password:
+ cmd_args.extend(['-p', new_password])
+
+ run_cmd(cmd_args)
def get_services_status() -> dict[str, bool] | None:
'''Gets the status of all project services.'''
diff --git a/core/scripts/webpanel/webpanel_shell.sh b/core/scripts/webpanel/webpanel_shell.sh
index 629d127..05c8200 100644
--- a/core/scripts/webpanel/webpanel_shell.sh
+++ b/core/scripts/webpanel/webpanel_shell.sh
@@ -3,6 +3,7 @@ source /etc/hysteria/core/scripts/utils.sh
define_colors
CADDY_CONFIG_FILE="/etc/hysteria/core/scripts/webpanel/Caddyfile"
+WEBPANEL_ENV_FILE="/etc/hysteria/core/scripts/webpanel/.env"
install_dependencies() {
# Update system
@@ -365,6 +366,65 @@ EOL
fi
}
+reset_credentials() {
+ local new_username_val=""
+ local new_password_val=""
+ local changes_made=false
+
+ if [ ! -f "$WEBPANEL_ENV_FILE" ]; then
+ echo -e "${red}Error: Web panel .env file not found. Is the web panel configured?${NC}"
+ exit 1
+ fi
+
+ OPTIND=1
+ while getopts ":u:p:" opt; do
+ case $opt in
+ u) new_username_val="$OPTARG" ;;
+ p) new_password_val="$OPTARG" ;;
+ \?) echo -e "${red}Invalid option: -$OPTARG${NC}" >&2; exit 1 ;;
+ :) echo -e "${red}Option -$OPTARG requires an argument.${NC}" >&2; exit 1 ;;
+ esac
+ done
+
+ if [ -z "$new_username_val" ] && [ -z "$new_password_val" ]; then
+ echo -e "${red}Error: At least one option (-u or -p ) must be provided.${NC}"
+ echo -e "${yellow}Usage: $0 resetcreds [-u new_username] [-p new_password]${NC}"
+ exit 1
+ fi
+
+ if [ -n "$new_username_val" ]; then
+ echo "Updating username to: $new_username_val"
+ if sudo sed -i "s|^ADMIN_USERNAME=.*|ADMIN_USERNAME=$new_username_val|" "$WEBPANEL_ENV_FILE"; then
+ changes_made=true
+ else
+ echo -e "${red}Failed to update username in $WEBPANEL_ENV_FILE${NC}"
+ exit 1
+ fi
+ fi
+
+ if [ -n "$new_password_val" ]; then
+ echo "Updating password..."
+ local new_password_hash=$(echo -n "$new_password_val" | sha256sum | cut -d' ' -f1)
+ if sudo sed -i "s|^ADMIN_PASSWORD=.*|ADMIN_PASSWORD=$new_password_hash|" "$WEBPANEL_ENV_FILE"; then
+ changes_made=true
+ else
+ echo -e "${red}Failed to update password in $WEBPANEL_ENV_FILE${NC}"
+ exit 1
+ fi
+ fi
+
+ if [ "$changes_made" = true ]; then
+ echo "Restarting web panel service to apply changes..."
+ if systemctl restart hysteria-webpanel.service; then
+ echo -e "${green}Web panel credentials updated successfully.${NC}"
+ else
+ echo -e "${red}Failed to restart hysteria-webpanel service. Please restart it manually.${NC}"
+ fi
+ else
+ echo -e "${yellow}No changes were specified.${NC}"
+ fi
+}
+
show_webpanel_url() {
source /etc/hysteria/core/scripts/webpanel/.env
local webpanel_url="https://$DOMAIN:$PORT/$ROOT_PATH/"
@@ -413,6 +473,10 @@ case "$1" in
stopdecoy)
stop_decoy_site
;;
+ resetcreds)
+ shift
+ reset_credentials "$@"
+ ;;
url)
show_webpanel_url
;;
@@ -425,6 +489,7 @@ case "$1" in
echo -e "${yellow}stop${NC}"
echo -e "${yellow}decoy ${NC}"
echo -e "${yellow}stopdecoy${NC}"
+ echo -e "${yellow} resetcreds [-u new_username] [-p new_password]${NC}"
echo -e "${yellow}url${NC}"
echo -e "${yellow}api-token${NC}"
exit 1
From 078714856b53bb24aadc6694153eff29d2129943 Mon Sep 17 00:00:00 2001
From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com>
Date: Fri, 23 May 2025 13:09:29 +0330
Subject: [PATCH 5/6] feat: add reset webpanel credentials option to menu
---
menu.sh | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/menu.sh b/menu.sh
index a85c1f9..e189cbd 100644
--- a/menu.sh
+++ b/menu.sh
@@ -598,7 +598,7 @@ normalsub_handler() {
}
webpanel_handler() {
- service_status=$(python3 $CLI_PATH get-webpanel-services-status)
+ service_status=$(python3 "$CLI_PATH" get-webpanel-services-status)
echo -e "${cyan}Services Status:${NC}"
echo "$service_status"
echo ""
@@ -608,6 +608,7 @@ webpanel_handler() {
echo -e "${red}2.${NC} Stop WebPanel service"
echo -e "${cyan}3.${NC} Get WebPanel URL"
echo -e "${cyan}4.${NC} Show API Token"
+ echo -e "${yellow}5.${NC} Reset WebPanel Credentials"
echo "0. Back"
read -p "Choose an option: " option
@@ -676,6 +677,34 @@ webpanel_handler() {
echo "$api_token"
echo "-------------------------------"
;;
+ 5)
+ if ! systemctl is-active --quiet hysteria-webpanel.service; then
+ echo -e "${red}WebPanel service is not running. Cannot reset credentials.${NC}"
+ else
+ read -e -p "Enter new admin username (leave blank to keep current): " new_username
+ read -e -p "Enter new admin password (leave blank to keep current): " new_password
+ echo
+
+ if [ -z "$new_username" ] && [ -z "$new_password" ]; then
+ echo -e "${yellow}No changes specified. Aborting.${NC}"
+ else
+ local cmd_args=("-u" "$new_username")
+ if [ -n "$new_password" ]; then
+ cmd_args+=("-p" "$new_password")
+ fi
+
+ if [ -z "$new_username" ]; then
+ cmd_args=()
+ if [ -n "$new_password" ]; then
+ cmd_args+=("-p" "$new_password")
+ fi
+ fi
+
+ echo "Attempting to reset credentials..."
+ python3 "$CLI_PATH" reset-webpanel-creds "${cmd_args[@]}"
+ fi
+ fi
+ ;;
0)
break
;;
From d99eff0317474e3ad1678963019c556cfb2f8263 Mon Sep 17 00:00:00 2001
From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com>
Date: Sat, 24 May 2025 20:40:32 +0330
Subject: [PATCH 6/6] Update changelog
---
changelog | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/changelog b/changelog
index 4145713..2ed5cf2 100644
--- a/changelog
+++ b/changelog
@@ -1,23 +1,15 @@
-# [1.10.0] - 2025-05-18
+# [1.10.1] - 2025-05-24
## โจ New Features
-### โ๏ธ NormalSub Configuration Enhancements
+* ๐ **feat:** Add option to reset Web Panel admin credentials via CLI
+* ๐งฉ **feat:** Add "Reset Web Panel credentials" option to Bash menu
+* ๐ **feat:** Add API endpoint to fetch IP Limiter configuration
-* ๐ ๏ธ **feat:** Add NormalSub subpath editing via Settings UI
- - New 'Configure' tab in the Settings panel (visible only if NormalSub is active)
- - Real-time client-side validation and live subpath editing
+## ๐๏ธ UI Improvements
-* ๐ **feat:** Add API endpoints
- - `GET /api/v1/config/normalsub/subpath`: Fetch current subpath
- - `PUT /api/v1/config/normalsub/edit_subpath`: Update the subpath securely
+* ๐งผ **clean:** Removed shield icons from footer for a cleaner look
-* ๐ฅ๏ธ **feat:** Add CLI command support
- - `edit_subpath` option added to CLI and `normal-sub` command
- - Automatically restarts the service after applying changes
+## ๐ Fixes
-* ๐ง **feat:** Add backend CLI + shell logic to update `.env` subpath for NormalSub
-
-## ๐ Documentation
-
-* ๐ **docs:** Add sponsorship section with referral link to README
+* ๐ **fix:** Align memory usage reporting with `free -m` in `server_info.py`