From: Oguz Bektas Date: Wed, 17 Jun 2020 13:32:29 +0000 (+0200) Subject: schema: register 'timezone' format and add verification method X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=e76308e6eb5ad2129dc7fec6092f9b23dcb47fda schema: register 'timezone' format and add verification method /usr/share/zoneinfo/zone.tab has the valid list of time zones. Signed-off-by: Oguz Bektas Signed-off-by: Thomas Lamprecht --- diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 84fb694..15a498c 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -482,6 +482,25 @@ sub pve_verify_dns_name { return $name; } +register_format('timezone', \&pve_verify_timezone); +sub pve_verify_timezone { + my ($timezone, $noerr) = @_; + + my $zonetab = "/usr/share/zoneinfo/zone.tab"; + return $timezone if $timezone eq 'UTC'; + open(my $fh, "<", $zonetab); + while(my $line = <$fh>) { + next if $line =~ /^#/; + chomp $line; + return $timezone if $timezone eq (split /\t/, $line)[2]; # found + } + close $fh; + + return undef if $noerr; + die "invalid time zone '$timezone'\n"; + +} + # network interface name register_format('pve-iface', \&pve_verify_iface); sub pve_verify_iface {