#!/usr/bin/perl
-#
-# IPCop CGIs
-#
-# This file is part of the IPCop 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;
+use POSIX qw(strftime);
# enable only the following on debugging purpose
#use warnings;
#use CGI::Carp 'fatalsToBrowser';
-require 'CONFIG_ROOT/general-functions.pl';
+require '/var/ipfire/general-functions.pl';
require "${General::swroot}/lang.pl";
require "${General::swroot}/header.pl";
$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);
-if ($timesettings{'ACTION'} eq $Lang::tr{'instant update'})
-{
- if ($timesettings{'SETHOUR'} eq '' || $timesettings{'SETHOUR'} < 0 || $timesettings{'SETHOUR'} > 23) {
- $errormessage = $Lang::tr{'invalid time entered'};
- goto UPDTERROR;
- }
- if ($timesettings{'SETMINUTES'} eq '' || $timesettings{'SETMINUTES'} < 0 || $timesettings{'SETMINUTES'} > 59) {
- $errormessage = $Lang::tr{'invalid time entered'};
- goto UPDTERROR;
- }
- if ($timesettings{'SETDAY'} eq '' || $timesettings{'SETDAY'} < 1 || $timesettings{'SETDAY'} > 31) {
- $errormessage = $Lang::tr{'invalid date entered'};
- goto UPDTERROR;
- }
- if ($timesettings{'SETMONTH'} eq '' || $timesettings{'SETMONTH'} < 1 || $timesettings{'SETMONTH'} > 12) {
- $errormessage = $Lang::tr{'invalid date entered'};
- goto UPDTERROR;
- }
- if ($timesettings{'SETYEAR'} eq '' || $timesettings{'SETYEAR'} < 2003 || $timesettings{'SETYEAR'} > 2030) {
- $errormessage = $Lang::tr{'invalid date entered'};
- goto UPDTERROR;
- }
-
-UPDTERROR:
- if ($errormessage) {
- $timesettings{'VALID'} = 'no'; }
- else {
- $timesettings{'VALID'} = 'yes'; }
-
- if ($timesettings{'VALID'} eq 'yes') {
- # we want date in YYYY-MM-DD HH:MM format for date command
- # EAO changed datestring to ISO 6801 format 2003-08-11
- my $datestring = "$timesettings{'SETYEAR'}-$timesettings{'SETMONTH'}-$timesettings{'SETDAY'}";
- my $timestring = "$timesettings{'SETHOUR'}:$timesettings{'SETMINUTES'}";
- # EAO setdate.c also revised for ISO 6801 date format 2003-08-11
- system ('/usr/local/bin/setdate', $datestring, $timestring);
- &General::log("$Lang::tr{'time date manually reset'} $datestring $timestring");
- }
- unless ($errormessage) {
- undef %timesettings;
- }
-}
-
if ($timesettings{'ACTION'} eq $Lang::tr{'save'})
-{
+{
if ($timesettings{'ENABLENTP'} eq 'on')
{
if ( ! ( &General::validfqdn($timesettings{'NTP_ADDR_1'}) ||
if ($timesettings{'ENABLENTP'} eq 'on' && $timesettings{'VALID'} eq 'yes')
{
- system ('/bin/touch', "${General::swroot}/time/enable");
+ &General::system('/usr/bin/touch', "${General::swroot}/time/enable");
+ &General::system('/usr/local/bin/timectrl', 'enable');
&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;
}
if ($timesettings{'ENABLECLNTP'} eq 'on') # DPC added to 1.3.1
{
- system ('/bin/touch', "${General::swroot}/time/allowclients"); # DPC added to 1.3.1
+ &General::system('/usr/bin/touch', "${General::swroot}/time/allowclients"); # DPC added to 1.3.1
&General::log($Lang::tr{'ntpd restarted'}); # DPC added to 1.3.1
} else {
unlink "${General::swroot}/time/allowclients";
}
-
+
}
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
+ &General::system('/usr/local/bin/timectrl', 'disable');
&General::log($Lang::tr{'ntp syncro disabled'})
}
if (! $errormessage) {
- system ('/usr/local/bin/restartntpd'); # DPC added to 1.3.1
+ &General::system('/usr/local/bin/timectrl', 'restart'); # DPC added to 1.3.1
}
}
$timesettings{'ACTION'} = &Header::cleanhtml ($timesettings{'ACTION'});
if ($timesettings{'ACTION'} eq $Lang::tr{'set time now'} && $timesettings{'ENABLENTP'} eq 'on')
{
- system ('/bin/touch', "${General::swroot}/time/settimenow");
+ &General::system('/usr/bin/touch', "/var/lock/time/settimenow");
}
&General::readhash("${General::swroot}/time/settings", \%timesettings);
$timesettings{'UPDATE_METHOD'} = 'manually';
$timesettings{'UPDATE_VALUE'} = '1';
$timesettings{'UPDATE_PERIOD'} = 'daily';
- $timesettings{'NTP_ADDR_1'} = 'pool.ntp.org';
- $timesettings{'NTP_ADDR_2'} = 'pool.ntp.org';
+ $timesettings{'NTP_ADDR_1'} = '0.ipfire.pool.ntp.org';
+ $timesettings{'NTP_ADDR_2'} = '1.ipfire.pool.ntp.org';
+ $timesettings{'ENABLESETONBOOT'} = 'off';
}
unless ($errormessage) {
- $timesettings{'SETMONTH'} = `date +'%m %e %Y %H %M'|cut -c 1-2`;
- $timesettings{'SETDAY'} = `date +'%m %e %Y %H %M'|cut -c 4-5`;
- $timesettings{'SETYEAR'} = `date +'%m %e %Y %H %M'|cut -c 7-10`;
- $timesettings{'SETHOUR'} = `date +'%m %e %Y %H %M'|cut -c 12-13`;
- $timesettings{'SETMINUTES'} = `date +'%m %e %Y %H %M'|cut -c 15-16`;
+ # Get date and time.
+ my $date = strftime("%m %e %Y %H %M", localtime);
+
+ # Split date string into single values.
+ my ($month, $day, $year, $hour, $minute) = split(/ /, $date);
+
+ # Assign values to the hash.
+ $timesettings{'SETMONTH'} = $month;
+ $timesettings{'SETDAY'} = $day;
+ $timesettings{'SETYEAR'} = $year;
+ $timesettings{'SETHOUR'} = $hour;
+ $timesettings{'SETMINUTES'} = $minute;
$_=$timesettings{'SETDAY'};
$timesettings{'SETDAY'}=~ tr/ /0/;
}
$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'";
$selected{'UPDATE_PERIOD'}{'monthly'} = '';
$selected{'UPDATE_PERIOD'}{$timesettings{'UPDATE_PERIOD'}} = "selected='selected'";
-# added to v0.0.4 to refresh screen if syncro event queued
+# 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;' />";
}
print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
-&Header::openbox('100%', 'left', $Lang::tr{'network time'});
+&Header::openbox('100%', 'left', $Lang::tr{'ntp common settings'});
print <<END
<table width='100%'>
<tr>
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
</td></tr>
<tr>
<td> </td>
- <td width='25%' class='base'>$Lang::tr{'primary ntp server'}:</td>
+ <td width='25%' class='base'>$Lang::tr{'primary ntp server'}: <img src='/blob.gif' alt='*' /></td>
<td width='25%'><input type='text' name='NTP_ADDR_1' value='$timesettings{'NTP_ADDR_1'}' /></td>
- <td width='25%' class='base'>$Lang::tr{'secondary ntp server'}: <img src='/blob.gif' align='top' alt='*' /></td>
+ <td width='25%' class='base'>$Lang::tr{'secondary ntp server'}:</td>
<td width='25%'><input type='text' name='NTP_ADDR_2' value='$timesettings{'NTP_ADDR_2'}' /></td>
</tr>
<tr>
<td> </td>
<td class='base' colspan='4'><input type='checkbox' name='ENABLECLNTP' $checked{'ENABLECLNTP'}{'on'} /> $Lang::tr{'clenabled'}</td>
</tr>
-</table>
-<table width='100%'>
-<tr>
- <td colspan='4'><hr /><b>$Lang::tr{'update time'}</b></td>
-</tr>
<tr>
<td> </td>
- <td class='base' colspan='2'>$Lang::tr{'set time now help'}</td>
+ <td class='base' colspan='4'><input type='checkbox' name='ENABLESETONBOOT' $checked{'ENABLESETONBOOT'}{'on'} /> $Lang::tr{'Set time on boot'}</td>
</tr>
+</table>
+END
+;
+&Header::closebox();
+&Header::openbox('100%',1,$Lang::tr{'ntp sync'});
+print <<END
+<table width='100%'>
<tr>
<td class='base'><input type='radio' name='UPDATE_METHOD' value='periodically' $checked{'UPDATE_METHOD'}{'periodically'} /></td>
- <td width='15%'>$Lang::tr{'every'}: </td>
- <td width='35%'><input type='text' name='UPDATE_VALUE' size='3' maxlength='3' value='$timesettings{'UPDATE_VALUE'}' />
+ <td width='10%'>$Lang::tr{'every'}</td>
+ <td width='45%'><input type='text' name='UPDATE_VALUE' size='3' maxlength='3' value='$timesettings{'UPDATE_VALUE'}' />
<select name='UPDATE_PERIOD'>
<option value='hourly' $selected{'UPDATE_PERIOD'}{'hourly'}>$Lang::tr{'hours'}</option>
<option value='daily' $selected{'UPDATE_PERIOD'}{'daily'}>$Lang::tr{'days'}</option>
<td class='base'><input type='radio' name='UPDATE_METHOD' value='manually' $checked{'UPDATE_METHOD'}{'manually'} /></td>
<td colspan='2'>$Lang::tr{'manually'}</td>
</tr>
+<tr>
+ <td colspan='4'><br><br><strong>$Lang::tr{'update time'}</strong></td>
+</tr>
+<tr>
+ <td> </td>
+ <td class='base' colspan='3'>$Lang::tr{'set time now help'}</td>
+</tr>
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";
}
<hr />
<table width='100%'>
<tr>
- <td width='30%'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td>
- <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'set time now'}' /></td>
- <td width='25%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
- <td width='5%' align='right'>
- <a href='${General::adminmanualurl}/services.html#services_time' target='_blank'><img src='/images/web-support.png' title='$Lang::tr{'online help en'}' /></a>
- </td>
+ <td width='30%'><img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td>
+ <td width='65%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'set time now'}' /></td>
+ <td width='5%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
</tr>
</table>
END
&Header::closebox();
-&Header::openbox('100%', 'left', $Lang::tr{'update time'});
-
-print <<END
-<table width='100%'>
-<tr>
- <td width='65%' class='base'>
- <table>
- <tr>
- <td>$Lang::tr{'year'}: </td>
- <td><input type='text' name='SETYEAR' size='4' maxlength='4' value='$timesettings{'SETYEAR'}' /></td>
- <td> $Lang::tr{'month'}: </td>
- <td><input type='text' name='SETMONTH' size='2' maxlength='2' value='$timesettings{'SETMONTH'}' /></td>
- <td> $Lang::tr{'day'}: </td>
- <td><input type='text' name='SETDAY' size='2' maxlength='2' value='$timesettings{'SETDAY'}' /></td>
- <td> $Lang::tr{'hours2'}: </td>
- <td><input type='text' name='SETHOUR' size='2' maxlength='2' value='$timesettings{'SETHOUR'}' /></td>
- <td> $Lang::tr{'minutes'}: </td>
- <td><input type='text' name='SETMINUTES' size='2' maxlength='2' value='$timesettings{'SETMINUTES'}' /></td>
- </tr>
- </table>
- </td>
- <td width='35%' align='center' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'instant update'}' /></td>
-</tr>
-</table>
-END
-;
-&Header::closebox();
-
print "</form>\n";
&Header::closebigbox();