]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/time.cgi
Enabled force setting system time on boot.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / time.cgi
index 7fef11f468a9f74f392fe8f73f022928491da406..fb69aa39e44af4f67e4903bdb9ca01af777304b0 100644 (file)
@@ -1,17 +1,23 @@
 #!/usr/bin/perl
-#
-# IPFire CGIs
-#
-# This file is part of the IPFire Project
-# 
-# This code is distributed under the terms of the GPL
-#
-# (c) Eric Oberlander June 2002
-#
-# (c) Darren Critchley June 2003 - added real time clock setting, etc
-#
-# $Id: time.cgi,v 1.4.2.11 2005/05/28 12:16:18 eoberlander Exp $
-#
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2010  IPFire Team                                             #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 use strict;
 
@@ -38,11 +44,7 @@ $timesettings{'UPDATE_METHOD'} = 'manually';
 $timesettings{'UPDATE_VALUE'} = '0';
 $timesettings{'UPDATE_PERIOD'} = '';
 $timesettings{'ENABLECLNTP'} = 'off';
-$timesettings{'SETHOUR'} = '';
-$timesettings{'SETMINUTES'} = '';
-$timesettings{'SETDAY'} = '';
-$timesettings{'SETMONTH'} = '';
-$timesettings{'SETYEAR'} = '';
+$timesettings{'ENABLESETONBOOT'} = 'off';
 
 &Header::getcgihash(\%timesettings);
 
@@ -124,11 +126,12 @@ ERROR:
        if ($timesettings{'ENABLENTP'} eq 'on' && $timesettings{'VALID'} eq 'yes')
        {
                system ('/usr/bin/touch', "${General::swroot}/time/enable");
+               system ('/usr/local/bin/timectrl enable >/dev/null 2>&1');
                &General::log($Lang::tr{'ntp syncro enabled'});
-               unlink "${General::swroot}/time/counter";
+               unlink "/var/lock/time/counter";
                if ($timesettings{'UPDATE_METHOD'} eq 'periodically')
                {
-                       open(FILE, ">/${General::swroot}/time/counter") or die "Unable to write counter file";
+                       open(FILE, ">/var/lock/time/counter") or die "Unable to write counter file";
                        flock(FILE, 2);
                        print FILE "$updateperiod\n";
                        close FILE;
@@ -145,12 +148,13 @@ ERROR:
        else
        {
                unlink "${General::swroot}/time/enable";
-               unlink "${General::swroot}/time/settimenow";
+               unlink "/var/lock/time/settimenow";
                unlink "${General::swroot}/time/allowclients"; # DPC added to 1.3.1
+               system ('/usr/local/bin/timectrl disable >/dev/null 2>&1');
                &General::log($Lang::tr{'ntp syncro disabled'})
        }
        if (! $errormessage) {
-               system ('/usr/local/bin/restartntpd'); # DPC added to 1.3.1
+               system ('/usr/local/bin/timectrl restart >/dev/null 2>&1'); # DPC added to 1.3.1
        }
 }
 
@@ -159,8 +163,7 @@ ERROR:
 $timesettings{'ACTION'} = &Header::cleanhtml ($timesettings{'ACTION'});
 if ($timesettings{'ACTION'} eq $Lang::tr{'set time now'} && $timesettings{'ENABLENTP'} eq 'on')
 {
-       system ('/usr/bin/touch', "${General::swroot}/time/settimenow");
-       system ('/usr/local/bin/timecheckctrl >& /dev/null');
+       system ('/usr/bin/touch', "/var/lock/time/settimenow");
 }
 
 &General::readhash("${General::swroot}/time/settings", \%timesettings);
@@ -173,6 +176,7 @@ if ($timesettings{'VALID'} eq '')
        $timesettings{'UPDATE_PERIOD'} = 'daily';
        $timesettings{'NTP_ADDR_1'} = 'de.pool.ntp.org';
        $timesettings{'NTP_ADDR_2'} = 'pool.ntp.org';
+       $timesettings{'ENABLESETONBOOT'} = 'off';
 }
 
 unless ($errormessage) {
@@ -196,6 +200,10 @@ $checked{'ENABLECLNTP'}{'off'} = '';
 $checked{'ENABLECLNTP'}{'on'} = '';
 $checked{'ENABLECLNTP'}{$timesettings{'ENABLECLNTP'}} = "checked='checked'";
 
+$checked{'ENABLESETONBOOT'}{'off'} = '';
+$checked{'ENABLESETONBOOT'}{'on'} = '';
+$checked{'ENABLESETONBOOT'}{$timesettings{'ENABLESETONBOOT'}} = "checked='checked'";
+
 $checked{'UPDATE_METHOD'}{'manually'} = '';
 $checked{'UPDATE_METHOD'}{'periodically'} = '';
 $checked{'UPDATE_METHOD'}{$timesettings{'UPDATE_METHOD'}} = "checked='checked'";
@@ -208,7 +216,7 @@ $selected{'UPDATE_PERIOD'}{$timesettings{'UPDATE_PERIOD'}} = "selected='selected
 
 # added to v0.0.4 to refresh screen if syncro event queued 
 my $refresh = '';
-if ( -e "${General::swroot}/time/settimenow") {
+if ( -e "/var/lock/time/settimenow") {
        $refresh = "<meta http-equiv='refresh' content='60;' />";
 }
 
@@ -238,10 +246,12 @@ print <<END
 END
 ;
 
-if ( -e "${General::swroot}/time/lastset")
+if ( -e "/var/lock/time/lastset")
 {
        print "$Lang::tr{'clock last synchronized at'}\n";
-       my $output = `cat ${General::swroot}/time/lastset`;
+       open(FILE, "</var/lock/time/lastset") or die "Unable to read lastset";
+       my $output = <FILE>;
+       close FILE;
        print $output;
 }
 else
@@ -269,7 +279,10 @@ print <<END
 </tr>
 <tr>
        <td>&nbsp;</td>
-       <td class='base' colspan='2'>$Lang::tr{'set time now help'}</td>
+       <td class='base' colspan='3'>$Lang::tr{'set time now help'}</td>
+</tr>
+<tr>
+       <td class='base' colspan='4'><input type='checkbox' name='ENABLESETONBOOT' $checked{'ENABLESETONBOOT'}{'on'} /> $Lang::tr{'Set time on boot'}</td>
 </tr>
 <tr>
        <td class='base'><input type='radio' name='UPDATE_METHOD' value='periodically' $checked{'UPDATE_METHOD'}{'periodically'} /></td>
@@ -290,7 +303,7 @@ print <<END
 END
 ;
 
-if ( -e "${General::swroot}/time/settimenow") {
+if ( -e "/var/lock/time/settimenow") {
        print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n";
        print "<td colspan='2'><font color='red'>$Lang::tr{'waiting to synchronize clock'}...</font></td></tr>\n";
 }