]> git.proxmox.com Git - pve-common.git/commitdiff
schema: register 'timezone' format and add verification method
authorOguz Bektas <o.bektas@proxmox.com>
Wed, 17 Jun 2020 13:32:29 +0000 (15:32 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 26 Jun 2020 07:50:26 +0000 (09:50 +0200)
/usr/share/zoneinfo/zone.tab has the valid list of time zones.

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/JSONSchema.pm

index 84fb694fcc1b2ce920036cdda2955667c1c229f5..15a498c019293682b7639aecc850d5021c4e4047 100644 (file)
@@ -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 {