Handle hostnames with upper-case letters
[webmin.git] / time / freebsd-lib.pl
1 # Functions for getting and setting the timezone on Linux
2
3 $timezones_file = "/usr/share/zoneinfo/zone.tab";
4 $currentzone_link = "/etc/localtime";
5 $timezones_dir = "/usr/share/zoneinfo";
6
7 # list_timezones()
8 sub list_timezones
9 {
10 local @rv;
11 &open_readfile(ZONE, $timezones_file) || return ( );
12 while(<ZONE>) {
13         s/\r|\n//g;
14         s/^\s*#.*$//;
15         if (/^(\S+)\s+(\S+)\s+(\S+)\s+(\S.*)/) {
16                 push(@rv, [ $3, $4 ]);
17                 }
18         elsif (/^(\S+)\s+(\S+)\s+(\S+)/) {
19                 push(@rv, [ $3, undef ]);
20                 }
21         }
22 close(ZONE);
23 return sort { $a->[0] cmp $b->[0] } @rv;
24 }
25
26 # get_current_timezone()
27 sub get_current_timezone
28 {
29 local $lnk = readlink(&translate_filename($currentzone_link));
30 if ($lnk) {
31         # Easy - it a link
32         $lnk =~ s/$timezones_dir\///;
33         return $lnk;
34         }
35 else {
36         # Need to compare with all timezone files!
37         return &find_same_zone($currentzone_link);
38         }
39 }
40
41 # set_current_timezone(zone)
42 sub set_current_timezone
43 {
44 &lock_file($currentzone_link);
45 unlink(&translate_filename($currentzone_link));
46 symlink(&translate_filename("$timezones_dir/$_[0]"),
47         &translate_filename($currentzone_link));
48 &unlock_file($currentzone_link);
49 }
50
51 sub os_has_timezones
52 {
53 return -r $timezones_file;
54 }
55
56 sub timezone_files
57 {
58 return ( $currentzone_link );
59 }
60
61 1;
62