ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(system): report IANA timezone_id; guard chart formatting against bad zones
Juan Denise3249fbd52a0
diff --git a/backend/app/services/system_service.py b/backend/app/services/system_service.pyindex 25367237..c56af33a 100644--- a/backend/app/services/system_service.py+++ b/backend/app/services/system_service.py@@ -272,6 +272,20 @@ class SystemService:return ' '.join(parts) if parts else '0m'+ @classmethod+ @staticmethod+ def _is_iana_timezone(value):+ """True if `value` looks like an IANA zone key (Area/Location or a small+ set of bare names), i.e. something Intl/zoneinfo will accept. Excludes+ platform display names like 'Eastern Daylight Time' (they contain spaces+ and no slash)."""+ if not value or not isinstance(value, str):+ return False+ v = value.strip()+ if v in ('UTC', 'GMT', 'Zulu'):+ return True+ return '/' in v and ' ' not in v+@classmethoddef get_server_time(cls):"""Get current server time and timezone info."""@@ -305,6 +319,23 @@ class SystemService:except Exception:pass+ # Cross-platform fallback (works on Windows/macOS dev boxes that have+ # neither /etc/timezone nor timedatectl): resolve the local IANA zone.+ if not timezone_id:+ try:+ from tzlocal import get_localzone_name+ timezone_id = get_localzone_name()+ except Exception:+ pass++ # Only ever expose an IANA-style id. Python's time.tzname yields a+ # platform *display* name on Windows ("Eastern Daylight Time") which is+ # NOT a valid Intl/zoneinfo key and would crash time-formatting in the+ # UI. Keep the display name in timezone_name; leave timezone_id null when+ # we can't produce a real IANA zone (the UI then uses the local zone).+ if timezone_id and not cls._is_iana_timezone(timezone_id):+ timezone_id = None+# Calculate UTC offsetutc_offset_seconds = (now - utc_now).total_seconds()utc_offset_hours = int(utc_offset_seconds // 3600)@@ -316,7 +347,7 @@ class SystemService:'current_time_formatted': now.strftime('%Y-%m-%d %H:%M:%S'),'utc_time': utc_now.isoformat(),'timezone_name': tz_name,- 'timezone_id': timezone_id or tz_name,+ 'timezone_id': timezone_id, # IANA or null (never the display name)'utc_offset': utc_offset_str,'utc_offset_seconds': int(utc_offset_seconds)}diff --git a/backend/requirements.txt b/backend/requirements.txtindex 05445036..00e8f198 100644--- a/backend/requirements.txt+++ b/backend/requirements.txt@@ -65,6 +65,11 @@ boto3==1.35.0Authlib==1.6.12python3-saml==1.16.0+# Cross-platform local IANA timezone resolution (SystemService.get_server_time+# falls back to this on hosts without /etc/timezone or timedatectl, e.g. Windows+# dev boxes) so the panel never reports a non-IANA zone the UI can't format.+tzlocal>=5.0+# OpenAPI documentationapispec==6.4.0apispec-webframeworks==1.2.0diff --git a/backend/tests/test_server_time_timezone.py b/backend/tests/test_server_time_timezone.pynew file mode 100644index 00000000..efd850e8--- /dev/null+++ b/backend/tests/test_server_time_timezone.py@@ -0,0 +1,35 @@+"""SystemService.get_server_time must only ever expose an IANA timezone_id.++Regression for a Windows-dev crash: Python's time.tzname yields a platform+*display* name ("Eastern Daylight Time") which is not a valid IANA/Intl zone key+and crashed the panel's time-formatting. timezone_id must be IANA-or-null; the+human display name lives in timezone_name.+"""+from app.services.system_service import SystemService+++def test_is_iana_timezone():+ assert SystemService._is_iana_timezone('America/New_York') is True+ assert SystemService._is_iana_timezone('Europe/London') is True+ assert SystemService._is_iana_timezone('UTC') is True+ # Windows display names are rejected.+ assert SystemService._is_iana_timezone('Eastern Daylight Time') is False+ assert SystemService._is_iana_timezone('Pacific Standard Time') is False+ assert SystemService._is_iana_timezone('') is False+ assert SystemService._is_iana_timezone(None) is False+++def test_get_server_time_timezone_id_is_iana_or_null():+ t = SystemService.get_server_time()+ tzid = t.get('timezone_id')+ # Never a spaced display name; either a real IANA key or null.+ assert tzid is None or SystemService._is_iana_timezone(tzid), tzid+ # The display name is still available separately for the UI clock.+ assert 'timezone_name' in t+++def test_get_server_time_shape(app):+ t = SystemService.get_server_time()+ for key in ('current_time', 'current_time_formatted', 'utc_time',+ 'timezone_name', 'timezone_id', 'utc_offset'):+ assert key in tdiff --git a/frontend/src/components/MetricsGraph.jsx b/frontend/src/components/MetricsGraph.jsxindex 9ef37ec9..e39751a0 100644--- a/frontend/src/components/MetricsGraph.jsx+++ b/frontend/src/components/MetricsGraph.jsx@@ -17,6 +17,20 @@ const CHART_COLORS = {disk: '#f5b945' // amber (Disk)};+// Intl only accepts IANA zone names (e.g. "America/New_York"). A server on+// Windows can report a display name like "Eastern Daylight Time", which makes+// toLocale*String throw a RangeError and crash the chart. Validate once and+// fall back to the browser's local zone rather than blowing up the render.+function safeTimeZone(tz) {+ if (!tz) return undefined;+ try {+ new Intl.DateTimeFormat([], { timeZone: tz });+ return tz;+ } catch {+ return undefined;+ }+}+const MetricsGraph = ({ compact = false, timezone, serverId }) => {const [data, setData] = useState(null);const [period, setPeriod] = useState('1h');@@ -58,7 +72,7 @@ const MetricsGraph = ({ compact = false, timezone, serverId }) => {function formatTimestamp(isoString) {const date = new Date(isoString);- const tz = timezone || undefined;+ const tz = safeTimeZone(timezone);if (period === '1h' || period === '6h' || period === '24h') {return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', timeZone: tz });} else if (period === '7d') {