From d7d1ade12db52c41978d0895fa5ff1dfb3a99252 Mon Sep 17 00:00:00 2001 From: knylbyte <40831653+knylbyte@users.noreply.github.com> Date: Wed, 17 Dec 2025 20:28:03 +0100 Subject: [PATCH] fix: ensure the received exp_date is valid --- backend/src/api/panel_api.rs | 28 +++++++++++++++++++++++-- backend/src/utils/file/config_reader.rs | 4 ++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/backend/src/api/panel_api.rs b/backend/src/api/panel_api.rs index 22b16fd28..99ead3f40 100644 --- a/backend/src/api/panel_api.rs +++ b/backend/src/api/panel_api.rs @@ -28,6 +28,19 @@ fn parse_boolish(value: &Value) -> bool { } } +fn is_date_only_yyyy_mm_dd(value: &str) -> bool { + let value = value.trim(); + if value.len() != 10 { + return false; + } + let bytes = value.as_bytes(); + bytes[4] == b'-' + && bytes[7] == b'-' + && bytes[0..4].iter().all(u8::is_ascii_digit) + && bytes[5..7].iter().all(u8::is_ascii_digit) + && bytes[8..10].iter().all(u8::is_ascii_digit) +} + fn first_json_object(value: &Value) -> Option<&serde_json::Map> { match value { Value::Array(arr) => arr.first().and_then(|v| v.as_object()), @@ -276,8 +289,19 @@ async fn panel_client_info(app_state: &AppState, cfg: &PanelApiConfigDto, userna if !status_ok { return create_tuliprox_error_result!(TuliproxErrorKind::Info, "panel_api: client_info status=false"); } - let expire = obj.get("expire").and_then(|v| v.as_str()).unwrap_or_default(); - Ok(parse_timestamp(expire).ok().flatten()) + let expire = obj.get("expire").and_then(|v| v.as_str()).unwrap_or_default().trim(); + let parsed = parse_timestamp(expire).ok().flatten(); + if parsed.is_some() { + return Ok(parsed); + } + + // Some panels return only a date ("YYYY-MM-DD") without time. Normalize to midnight. + if is_date_only_yyyy_mm_dd(expire) { + let normalized = format!("{expire} 00:00:00"); + return Ok(parse_timestamp(&normalized).ok().flatten()); + } + + Ok(None) } fn extract_account_creds_from_input(input: &ConfigInput) -> Option<(String, String)> { diff --git a/backend/src/utils/file/config_reader.rs b/backend/src/utils/file/config_reader.rs index ce5a49b43..4a046d0d9 100644 --- a/backend/src/utils/file/config_reader.rs +++ b/backend/src/utils/file/config_reader.rs @@ -471,7 +471,7 @@ mod tests { #[test] fn test_sources_yaml_panel_api_query_params_flow_style() { - let input = r#"sources: + let input = r"sources: - inputs: - name: demo panel_api: @@ -485,7 +485,7 @@ mod tests { client_new: - key: type value: m3u -"#; +"; let out = format_sources_yaml_panel_api_query_params_flow_style(input); assert!(out.contains("- { key: api_key, value: auto }")); assert!(out.contains("- { key: sub, value: '1' }"));