Handle hostnames with upper-case letters
[webmin.git] / time / apply.cgi
1 #!/usr/local/bin/perl
2
3 local $format;
4 local $out;
5
6 require "./time-lib.pl";
7 require 'timelocal.pl';
8
9 &ReadParse();
10
11 if (!$in{'action'}) {
12         # user probably hit return in the time server field
13         $in{'action'} = $text{ 'action_timeserver_sys' };
14         }
15 $mode = "time";
16
17 if( $in{ 'action' } eq $text{ 'action_apply' } )
18 {
19   # Setting the system time
20   &error( $text{ 'acl_nosys' } ) if( $access{ 'sysdate' } );
21   $err = &set_system_time($in{ 'second' }, $in{'minute'}, $in{'hour'},
22                    $in{'date'}, $in{'month'}-1, $in{'year'}-1900);
23   &error($err) if ($err);
24   &webmin_log("set", "date", time(), \%in);
25
26 } elsif ( $in{ 'action' } eq $text{ 'action_save' } ) {
27   # Setting the hardware time
28   &error( $text{ 'acl_nohw' } ) if( $access{ 'hwdate' } );
29   $err = &set_hardware_time($in{ 'second' }, $in{'minute'}, $in{'hour'},
30                    $in{'date'}, $in{'month'}-1, $in{'year'}-1900);
31   &error( &text( 'error_hw', $err ) ) if ($err);
32   local $hwtime = timelocal($in{'second'}, $in{'minute'}, $in{'hour'},
33                             $in{'date'}, $in{'month'}-1, $in{'year'} < 200 ?
34                             $in{'year'} : $in{'year'}-1900);
35   &webmin_log("set", "hwclock", $hwtime, \%in);
36
37 } elsif( $in{ 'action' } eq $text{ 'action_sync' } ) {
38   # Set system time to hardware time
39   &error( $text{ 'acl_nosys' } ) if( $access{ 'sysdate' } );
40   $out = &backquote_logged("hwclock --hctosys");
41   &error( &text( 'error_sync', $out ) ) if( $out ne "" );
42   &webmin_log("sync");
43
44 } elsif( $in{ 'action' } eq $text{ 'action_sync_s' } ) {
45   # Set hardware time to system time
46   &error( $text{ 'acl_nohw' } ) if( $access{ 'hwdate' } && $access{'sysdate'} );
47   $out = &backquote_logged("hwclock --systohc");
48   &error( &text( 'error_sync', $out ) ) if( $out ne "" );
49   &webmin_log("sync_s");
50
51 } elsif( $in{ 'action' } eq $text{ 'index_sync' }) {
52   # Sync with a time server
53   $access{'ntp'} || &error($text{'acl_nontp'});
54   $in{'timeserver'} =~ /\S/ || &error($text{'error_etimeserver'});
55   $err = &sync_time($in{'timeserver'}, $in{'hardware'});
56   &error($err) if ($err);
57
58   # Save settings in module config
59   &lock_file($module_config_file);
60   $config{'timeserver'} = $in{'timeserver'};
61   $config{'timeserver_hardware'} = $in{'hardware'};
62   &save_module_config();
63   &unlock_file($module_config_file);
64
65   # Create, update or delete the syncing cron job
66   $job = &find_webmin_cron_job();
67   if ($in{'sched'}) {
68         $job ||= { 'module' => $module_name,
69                      'func' => 'sync_time_cron' };
70         &webmincron::parse_times_input($job, \%in);
71         &webmincron::create_webmin_cron($job);
72         }
73   elsif ($job) {
74         &webmincron::delete_webmin_cron($job);
75         }
76   &webmin_log("remote", $in{'action'} eq $text{'action_timeserver_sys'} ?  "date" : "hwclock", $rawtime, \%in);
77   $mode = "sync";
78 }
79
80 &redirect("index.cgi?mode=$mode");
81