]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/time.cgi
5 # This file is part of the IPCop Project
7 # This code is distributed under the terms of the GPL
9 # (c) Eric Oberlander June 2002
11 # (c) Darren Critchley June 2003 - added real time clock setting, etc
13 # $Id: time.cgi,v 1.4.2.11 2005/05/28 12:16:18 eoberlander Exp $
18 # enable only the following on debugging purpose
20 #use CGI::Carp 'fatalsToBrowser';
22 require 'CONFIG_ROOT/general-functions.pl';
23 require "${General::swroot}/lang.pl";
24 require "${General::swroot}/header.pl";
27 my $errormessage = '';
29 &Header
::showhttpheaders
();
31 $timesettings{'ACTION'} = '';
32 $timesettings{'VALID'} = '';
34 $timesettings{'ENABLENTP'} = 'off';
35 $timesettings{'NTP_ADDR_1'} = '';
36 $timesettings{'NTP_ADDR_2'} = '';
37 $timesettings{'UPDATE_METHOD'} = 'manually';
38 $timesettings{'UPDATE_VALUE'} = '0';
39 $timesettings{'UPDATE_PERIOD'} = '';
40 $timesettings{'ENABLECLNTP'} = 'off';
41 $timesettings{'SETHOUR'} = '';
42 $timesettings{'SETMINUTES'} = '';
43 $timesettings{'SETDAY'} = '';
44 $timesettings{'SETMONTH'} = '';
45 $timesettings{'SETYEAR'} = '';
47 &Header
::getcgihash
(\
%timesettings);
49 if ($timesettings{'ACTION'} eq $Lang::tr
{'instant update'})
51 if ($timesettings{'SETHOUR'} eq '' || $timesettings{'SETHOUR'} < 0 || $timesettings{'SETHOUR'} > 23) {
52 $errormessage = $Lang::tr
{'invalid time entered'};
55 if ($timesettings{'SETMINUTES'} eq '' || $timesettings{'SETMINUTES'} < 0 || $timesettings{'SETMINUTES'} > 59) {
56 $errormessage = $Lang::tr
{'invalid time entered'};
59 if ($timesettings{'SETDAY'} eq '' || $timesettings{'SETDAY'} < 1 || $timesettings{'SETDAY'} > 31) {
60 $errormessage = $Lang::tr
{'invalid date entered'};
63 if ($timesettings{'SETMONTH'} eq '' || $timesettings{'SETMONTH'} < 1 || $timesettings{'SETMONTH'} > 12) {
64 $errormessage = $Lang::tr
{'invalid date entered'};
67 if ($timesettings{'SETYEAR'} eq '' || $timesettings{'SETYEAR'} < 2003 || $timesettings{'SETYEAR'} > 2030) {
68 $errormessage = $Lang::tr
{'invalid date entered'};
74 $timesettings{'VALID'} = 'no'; }
76 $timesettings{'VALID'} = 'yes'; }
78 if ($timesettings{'VALID'} eq 'yes') {
79 # we want date in YYYY-MM-DD HH:MM format for date command
80 # EAO changed datestring to ISO 6801 format 2003-08-11
81 my $datestring = "$timesettings{'SETYEAR'}-$timesettings{'SETMONTH'}-$timesettings{'SETDAY'}";
82 my $timestring = "$timesettings{'SETHOUR'}:$timesettings{'SETMINUTES'}";
83 # EAO setdate.c also revised for ISO 6801 date format 2003-08-11
84 system ('/usr/local/bin/setdate', $datestring, $timestring);
85 &General
::log("$Lang::tr{'time date manually reset'} $datestring $timestring");
87 unless ($errormessage) {
92 if ($timesettings{'ACTION'} eq $Lang::tr
{'save'})
94 if ($timesettings{'ENABLENTP'} eq 'on')
96 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_1'}) ||
97 &General
::validip
($timesettings{'NTP_ADDR_1'})))
99 $errormessage = $Lang::tr
{'invalid primary ntp'};
103 if ($timesettings{'NTP_ADDR_2'})
105 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_2'}) ||
106 &General
::validip
($timesettings{'NTP_ADDR_2'})))
108 $errormessage = $Lang::tr
{'invalid secondary ntp'};
112 if (!($timesettings{'NTP_ADDR_1'}) && $timesettings{'NTP_ADDR_2'})
114 $errormessage = $Lang::tr
{'cannot specify secondary ntp without specifying primary'};
118 if (!($timesettings{'UPDATE_VALUE'} =~ /^\d+$/) || $timesettings{'UPDATE_VALUE'} <= 0)
120 $errormessage = $Lang::tr
{'invalid time period'};
124 if ($timesettings{'ENABLENTP'} ne "on" && $timesettings{'ENABLECLNTP'} eq "on")
126 $errormessage = $Lang::tr
{'ntp must be enabled to have clients'};
129 if ($timesettings{'ENABLENTP'} eq "on" && !($timesettings{'NTP_ADDR_1'}) && !($timesettings{'NTP_ADDR_2'}))
131 $errormessage = $Lang::tr
{'cannot enable ntp without specifying primary'};
136 $timesettings{'VALID'} = 'no'; }
138 $timesettings{'VALID'} = 'yes'; }
140 &General
::writehash
("${General::swroot}/time/settings", \
%timesettings);
141 open(FILE
, ">/${General::swroot}/time/settime.conf") or die "Unable to write settime.conf file";
143 print FILE
"$timesettings{'NTP_ADDR_1'} $timesettings{'NTP_ADDR_2'}\n";
148 if ($timesettings{'UPDATE_PERIOD'} eq 'daily') {
149 $updateperiod = $timesettings{'UPDATE_VALUE'} * 1440; }
150 elsif ($timesettings{'UPDATE_PERIOD'} eq 'weekly') {
151 $updateperiod = $timesettings{'UPDATE_VALUE'} * 10080; }
152 elsif ($timesettings{'UPDATE_PERIOD'} eq 'monthly') {
153 $updateperiod = $timesettings{'UPDATE_VALUE'} * 40320; }
155 $updateperiod = $timesettings{'UPDATE_VALUE'} * 60; }
157 $updateperiod = $updateperiod - 5;
159 if ($updateperiod <= 5) {
162 open(FILE
, ">/${General::swroot}/time/counter.conf") or die "Unable to write counter.conf file";
164 print FILE
"$updateperiod\n";
167 if ($timesettings{'ENABLENTP'} eq 'on' && $timesettings{'VALID'} eq 'yes')
169 system ('/bin/touch', "${General::swroot}/time/enable");
170 &General
::log($Lang::tr
{'ntp syncro enabled'});
171 unlink "${General::swroot}/time/counter";
172 if ($timesettings{'UPDATE_METHOD'} eq 'periodically')
174 open(FILE
, ">/${General::swroot}/time/counter") or die "Unable to write counter file";
176 print FILE
"$updateperiod\n";
179 if ($timesettings{'ENABLECLNTP'} eq 'on') # DPC added to 1.3.1
181 system ('/bin/touch', "${General::swroot}/time/allowclients"); # DPC added to 1.3.1
182 &General
::log($Lang::tr
{'ntpd restarted'}); # DPC added to 1.3.1
184 unlink "${General::swroot}/time/allowclients";
190 unlink "${General::swroot}/time/enable";
191 unlink "${General::swroot}/time/settimenow";
192 unlink "${General::swroot}/time/allowclients"; # DPC added to 1.3.1
193 &General
::log($Lang::tr
{'ntp syncro disabled'})
195 if (! $errormessage) {
196 system ('/usr/local/bin/restartntpd'); # DPC added to 1.3.1
200 # To enter an ' into a pushbutton solution is to use ' in it's definition
201 # but returned value when pressed is ' not the code. Cleanhtml recode the ' to enable comparison.
202 $timesettings{'ACTION'} = &Header
::cleanhtml
($timesettings{'ACTION'});
203 if ($timesettings{'ACTION'} eq $Lang::tr
{'set time now'} && $timesettings{'ENABLENTP'} eq 'on')
205 system ('/bin/touch', "${General::swroot}/time/settimenow");
208 &General
::readhash
("${General::swroot}/time/settings", \
%timesettings);
210 if ($timesettings{'VALID'} eq '')
212 $timesettings{'ENABLENTP'} = 'off';
213 $timesettings{'UPDATE_METHOD'} = 'manually';
214 $timesettings{'UPDATE_VALUE'} = '1';
215 $timesettings{'UPDATE_PERIOD'} = 'daily';
216 $timesettings{'NTP_ADDR_1'} = 'pool.ntp.org';
217 $timesettings{'NTP_ADDR_2'} = 'pool.ntp.org';
220 unless ($errormessage) {
221 $timesettings{'SETMONTH'} = `date +'%m %e %Y %H %M'|cut -c 1-2`;
222 $timesettings{'SETDAY'} = `date +'%m %e %Y %H %M'|cut -c 4-5`;
223 $timesettings{'SETYEAR'} = `date +'%m %e %Y %H %M'|cut -c 7-10`;
224 $timesettings{'SETHOUR'} = `date +'%m %e %Y %H %M'|cut -c 12-13`;
225 $timesettings{'SETMINUTES'} = `date +'%m %e %Y %H %M'|cut -c 15-16`;
226 $_=$timesettings{'SETDAY'};
227 $timesettings{'SETDAY'}=~ tr/ /0/;
233 $checked{'ENABLENTP'}{'off'} = '';
234 $checked{'ENABLENTP'}{'on'} = '';
235 $checked{'ENABLENTP'}{$timesettings{'ENABLENTP'}} = "checked='checked'";
237 $checked{'ENABLECLNTP'}{'off'} = '';
238 $checked{'ENABLECLNTP'}{'on'} = '';
239 $checked{'ENABLECLNTP'}{$timesettings{'ENABLECLNTP'}} = "checked='checked'";
241 $checked{'UPDATE_METHOD'}{'manually'} = '';
242 $checked{'UPDATE_METHOD'}{'periodically'} = '';
243 $checked{'UPDATE_METHOD'}{$timesettings{'UPDATE_METHOD'}} = "checked='checked'";
245 $selected{'UPDATE_PERIOD'}{'hourly'} = '';
246 $selected{'UPDATE_PERIOD'}{'daily'} = '';
247 $selected{'UPDATE_PERIOD'}{'weekly'} = '';
248 $selected{'UPDATE_PERIOD'}{'monthly'} = '';
249 $selected{'UPDATE_PERIOD'}{$timesettings{'UPDATE_PERIOD'}} = "selected='selected'";
251 # added to v0.0.4 to refresh screen if syncro event queued
253 if ( -e
"${General::swroot}/time/settimenow") {
254 $refresh = "<meta http-equiv='refresh' content='60;' />";
257 &Header
::openpage
($Lang::tr
{'ntp configuration'}, 1, $refresh);
259 &Header
::openbigbox
('100%', 'left', '', $errormessage);
261 # DPC move error message to top so it is seen!
263 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
264 print "<font class='base'>$errormessage </font>\n";
268 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
270 &Header
::openbox
('100%', 'left', $Lang::tr
{'network time'});
274 <td><input type='checkbox' name='ENABLENTP' $checked{'ENABLENTP'}{'on'} /></td>
275 <td width='100%' colspan='4' class='base'>$Lang::tr{'network time from'}</td>
279 <td width='100%' class='base' colspan='4'>
283 if ( -e
"${General::swroot}/time/lastset")
285 print "$Lang::tr{'clock last synchronized at'}\n";
286 my $output = `cat ${General::swroot}/time/lastset`;
291 print "$Lang::tr{'clock has not been synchronized'}\n";
298 <td width='25%' class='base'>$Lang::tr{'primary ntp server'}:</td>
299 <td width='25%'><input type='text' name='NTP_ADDR_1' value='$timesettings{'NTP_ADDR_1'}' /></td>
300 <td width='25%' class='base'>$Lang::tr{'secondary ntp server'}: <img src='/blob.gif' align='top' alt='*' /></td>
301 <td width='25%'><input type='text' name='NTP_ADDR_2' value='$timesettings{'NTP_ADDR_2'}' /></td>
305 <td class='base' colspan='4'><input type='checkbox' name='ENABLECLNTP' $checked{'ENABLECLNTP'}{'on'} /> $Lang::tr{'clenabled'}</td>
310 <td colspan='4'><hr /><b>$Lang::tr{'update time'}</b></td>
314 <td class='base' colspan='2'>$Lang::tr{'set time now help'}</td>
317 <td class='base'><input type='radio' name='UPDATE_METHOD' value='periodically' $checked{'UPDATE_METHOD'}{'periodically'} /></td>
318 <td width='15%'>$Lang::tr{'every'}: </td>
319 <td width='35%'><input type='text' name='UPDATE_VALUE' size='3' maxlength='3' value='$timesettings{'UPDATE_VALUE'}' />
320 <select name='UPDATE_PERIOD'>
321 <option value='hourly' $selected{'UPDATE_PERIOD'}{'hourly'}>$Lang::tr{'hours'}</option>
322 <option value='daily' $selected{'UPDATE_PERIOD'}{'daily'}>$Lang::tr{'days'}</option>
323 <option value='weekly' $selected{'UPDATE_PERIOD'}{'weekly'}>$Lang::tr{'weeks'}</option>
324 <option value='monthly' $selected{'UPDATE_PERIOD'}{'monthly'}>$Lang::tr{'months'}</option>
326 <td width='50%'> </td>
329 <td class='base'><input type='radio' name='UPDATE_METHOD' value='manually' $checked{'UPDATE_METHOD'}{'manually'} /></td>
330 <td colspan='2'>$Lang::tr{'manually'}</td>
335 if ( -e
"${General::swroot}/time/settimenow") {
336 print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n";
337 print "<td colspan='2'><font color='red'>$Lang::tr{'waiting to synchronize clock'}...</font></td></tr>\n";
345 <td width='30%'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td>
346 <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'set time now'}' /></td>
347 <td width='25%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
348 <td width='5%' align='right'>
349 <a href='${General::adminmanualurl}/services.html#services_time' target='_blank'><img src='/images/web-support.png' title='$Lang::tr{'online help en'}' /></a>
358 &Header
::openbox
('100%', 'left', $Lang::tr
{'update time'});
363 <td width='65%' class='base'>
366 <td>$Lang::tr{'year'}: </td>
367 <td><input type='text' name='SETYEAR' size='4' maxlength='4' value='$timesettings{'SETYEAR'}' /></td>
368 <td> $Lang::tr{'month'}: </td>
369 <td><input type='text' name='SETMONTH' size='2' maxlength='2' value='$timesettings{'SETMONTH'}' /></td>
370 <td> $Lang::tr{'day'}: </td>
371 <td><input type='text' name='SETDAY' size='2' maxlength='2' value='$timesettings{'SETDAY'}' /></td>
372 <td> $Lang::tr{'hours2'}: </td>
373 <td><input type='text' name='SETHOUR' size='2' maxlength='2' value='$timesettings{'SETHOUR'}' /></td>
374 <td> $Lang::tr{'minutes'}: </td>
375 <td><input type='text' name='SETMINUTES' size='2' maxlength='2' value='$timesettings{'SETMINUTES'}' /></td>
379 <td width='35%' align='center' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'instant update'}' /></td>
388 &Header
::closebigbox
();
390 &Header
::closepage
();