]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/JSONSchema.pm
schema: register 'timezone' format and add verification method
[pve-common.git] / 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 {