]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/time.cgi
5 # This file is part of the IPFire 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 '/var/ipfire/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
{'save'})
51 if ($timesettings{'ENABLENTP'} eq 'on')
53 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_1'}) ||
54 &General
::validip
($timesettings{'NTP_ADDR_1'})))
56 $errormessage = $Lang::tr
{'invalid primary ntp'};
60 if ($timesettings{'NTP_ADDR_2'})
62 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_2'}) ||
63 &General
::validip
($timesettings{'NTP_ADDR_2'})))
65 $errormessage = $Lang::tr
{'invalid secondary ntp'};
69 if (!($timesettings{'NTP_ADDR_1'}) && $timesettings{'NTP_ADDR_2'})
71 $errormessage = $Lang::tr
{'cannot specify secondary ntp without specifying primary'};
75 if (!($timesettings{'UPDATE_VALUE'} =~ /^\d+$/) || $timesettings{'UPDATE_VALUE'} <= 0)
77 $errormessage = $Lang::tr
{'invalid time period'};
81 if ($timesettings{'ENABLENTP'} ne "on" && $timesettings{'ENABLECLNTP'} eq "on")
83 $errormessage = $Lang::tr
{'ntp must be enabled to have clients'};
86 if ($timesettings{'ENABLENTP'} eq "on" && !($timesettings{'NTP_ADDR_1'}) && !($timesettings{'NTP_ADDR_2'}))
88 $errormessage = $Lang::tr
{'cannot enable ntp without specifying primary'};
93 $timesettings{'VALID'} = 'no'; }
95 $timesettings{'VALID'} = 'yes'; }
97 &General
::writehash
("${General::swroot}/time/settings", \
%timesettings);
98 open(FILE
, ">/${General::swroot}/time/settime.conf") or die "Unable to write settime.conf file";
100 print FILE
"$timesettings{'NTP_ADDR_1'} $timesettings{'NTP_ADDR_2'}\n";
105 if ($timesettings{'UPDATE_PERIOD'} eq 'daily') {
106 $updateperiod = $timesettings{'UPDATE_VALUE'} * 1440; }
107 elsif ($timesettings{'UPDATE_PERIOD'} eq 'weekly') {
108 $updateperiod = $timesettings{'UPDATE_VALUE'} * 10080; }
109 elsif ($timesettings{'UPDATE_PERIOD'} eq 'monthly') {
110 $updateperiod = $timesettings{'UPDATE_VALUE'} * 40320; }
112 $updateperiod = $timesettings{'UPDATE_VALUE'} * 60; }
114 $updateperiod = $updateperiod - 5;
116 if ($updateperiod <= 5) {
119 open(FILE
, ">/${General::swroot}/time/counter.conf") or die "Unable to write counter.conf file";
121 print FILE
"$updateperiod\n";
124 if ($timesettings{'ENABLENTP'} eq 'on' && $timesettings{'VALID'} eq 'yes')
126 system ('/usr/bin/touch', "${General::swroot}/time/enable");
127 &General
::log($Lang::tr
{'ntp syncro enabled'});
128 unlink "${General::swroot}/time/counter";
129 if ($timesettings{'UPDATE_METHOD'} eq 'periodically')
131 open(FILE
, ">/${General::swroot}/time/counter") or die "Unable to write counter file";
133 print FILE
"$updateperiod\n";
136 if ($timesettings{'ENABLECLNTP'} eq 'on') # DPC added to 1.3.1
138 system ('/usr/bin/touch', "${General::swroot}/time/allowclients"); # DPC added to 1.3.1
139 &General
::log($Lang::tr
{'ntpd restarted'}); # DPC added to 1.3.1
141 unlink "${General::swroot}/time/allowclients";
147 unlink "${General::swroot}/time/enable";
148 unlink "${General::swroot}/time/settimenow";
149 unlink "${General::swroot}/time/allowclients"; # DPC added to 1.3.1
150 &General
::log($Lang::tr
{'ntp syncro disabled'})
152 if (! $errormessage) {
153 system ('/usr/local/bin/restartntpd'); # DPC added to 1.3.1
157 # To enter an ' into a pushbutton solution is to use ' in it's definition
158 # but returned value when pressed is ' not the code. Cleanhtml recode the ' to enable comparison.
159 $timesettings{'ACTION'} = &Header
::cleanhtml
($timesettings{'ACTION'});
160 if ($timesettings{'ACTION'} eq $Lang::tr
{'set time now'} && $timesettings{'ENABLENTP'} eq 'on')
162 system ('/usr/bin/touch', "${General::swroot}/time/settimenow");
163 system ('/usr/local/bin/timecheckctrl >& /dev/null');
166 &General
::readhash
("${General::swroot}/time/settings", \
%timesettings);
168 if ($timesettings{'VALID'} eq '')
170 $timesettings{'ENABLENTP'} = 'off';
171 $timesettings{'UPDATE_METHOD'} = 'manually';
172 $timesettings{'UPDATE_VALUE'} = '1';
173 $timesettings{'UPDATE_PERIOD'} = 'daily';
174 $timesettings{'NTP_ADDR_1'} = 'de.pool.ntp.org';
175 $timesettings{'NTP_ADDR_2'} = 'pool.ntp.org';
178 unless ($errormessage) {
179 $timesettings{'SETMONTH'} = `date +'%m %e %Y %H %M'|cut -c 1-2`;
180 $timesettings{'SETDAY'} = `date +'%m %e %Y %H %M'|cut -c 4-5`;
181 $timesettings{'SETYEAR'} = `date +'%m %e %Y %H %M'|cut -c 7-10`;
182 $timesettings{'SETHOUR'} = `date +'%m %e %Y %H %M'|cut -c 12-13`;
183 $timesettings{'SETMINUTES'} = `date +'%m %e %Y %H %M'|cut -c 15-16`;
184 $_=$timesettings{'SETDAY'};
185 $timesettings{'SETDAY'}=~ tr/ /0/;
191 $checked{'ENABLENTP'}{'off'} = '';
192 $checked{'ENABLENTP'}{'on'} = '';
193 $checked{'ENABLENTP'}{$timesettings{'ENABLENTP'}} = "checked='checked'";
195 $checked{'ENABLECLNTP'}{'off'} = '';
196 $checked{'ENABLECLNTP'}{'on'} = '';
197 $checked{'ENABLECLNTP'}{$timesettings{'ENABLECLNTP'}} = "checked='checked'";
199 $checked{'UPDATE_METHOD'}{'manually'} = '';
200 $checked{'UPDATE_METHOD'}{'periodically'} = '';
201 $checked{'UPDATE_METHOD'}{$timesettings{'UPDATE_METHOD'}} = "checked='checked'";
203 $selected{'UPDATE_PERIOD'}{'hourly'} = '';
204 $selected{'UPDATE_PERIOD'}{'daily'} = '';
205 $selected{'UPDATE_PERIOD'}{'weekly'} = '';
206 $selected{'UPDATE_PERIOD'}{'monthly'} = '';
207 $selected{'UPDATE_PERIOD'}{$timesettings{'UPDATE_PERIOD'}} = "selected='selected'";
209 # added to v0.0.4 to refresh screen if syncro event queued
211 if ( -e
"${General::swroot}/time/settimenow") {
212 $refresh = "<meta http-equiv='refresh' content='60;' />";
215 &Header
::openpage
($Lang::tr
{'ntp configuration'}, 1, $refresh);
217 &Header
::openbigbox
('100%', 'left', '', $errormessage);
219 # DPC move error message to top so it is seen!
221 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
222 print "<font class='base'>$errormessage </font>\n";
226 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
228 &Header
::openbox
('100%', 'left', $Lang::tr
{'network time'});
232 <td><input type='checkbox' name='ENABLENTP' $checked{'ENABLENTP'}{'on'} /></td>
233 <td width='100%' colspan='4' class='base'>$Lang::tr{'network time from'}</td>
237 <td width='100%' class='base' colspan='4'>
241 if ( -e
"${General::swroot}/time/lastset")
243 print "$Lang::tr{'clock last synchronized at'}\n";
244 my $output = `cat ${General::swroot}/time/lastset`;
249 print "$Lang::tr{'clock has not been synchronized'}\n";
256 <td width='25%' class='base'>$Lang::tr{'primary ntp server'}:</td>
257 <td width='25%'><input type='text' name='NTP_ADDR_1' value='$timesettings{'NTP_ADDR_1'}' /></td>
258 <td width='25%' class='base'>$Lang::tr{'secondary ntp server'}: <img src='/blob.gif' align='top' alt='*' /></td>
259 <td width='25%'><input type='text' name='NTP_ADDR_2' value='$timesettings{'NTP_ADDR_2'}' /></td>
263 <td class='base' colspan='4'><input type='checkbox' name='ENABLECLNTP' $checked{'ENABLECLNTP'}{'on'} /> $Lang::tr{'clenabled'}</td>
268 <td colspan='4'><hr /><b>$Lang::tr{'update time'}</b></td>
272 <td class='base' colspan='2'>$Lang::tr{'set time now help'}</td>
275 <td class='base'><input type='radio' name='UPDATE_METHOD' value='periodically' $checked{'UPDATE_METHOD'}{'periodically'} /></td>
276 <td width='15%'>$Lang::tr{'every'}: </td>
277 <td width='35%'><input type='text' name='UPDATE_VALUE' size='3' maxlength='3' value='$timesettings{'UPDATE_VALUE'}' />
278 <select name='UPDATE_PERIOD'>
279 <option value='hourly' $selected{'UPDATE_PERIOD'}{'hourly'}>$Lang::tr{'hours'}</option>
280 <option value='daily' $selected{'UPDATE_PERIOD'}{'daily'}>$Lang::tr{'days'}</option>
281 <option value='weekly' $selected{'UPDATE_PERIOD'}{'weekly'}>$Lang::tr{'weeks'}</option>
282 <option value='monthly' $selected{'UPDATE_PERIOD'}{'monthly'}>$Lang::tr{'months'}</option>
284 <td width='50%'> </td>
287 <td class='base'><input type='radio' name='UPDATE_METHOD' value='manually' $checked{'UPDATE_METHOD'}{'manually'} /></td>
288 <td colspan='2'>$Lang::tr{'manually'}</td>
293 if ( -e
"${General::swroot}/time/settimenow") {
294 print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n";
295 print "<td colspan='2'><font color='red'>$Lang::tr{'waiting to synchronize clock'}...</font></td></tr>\n";
303 <td width='30%'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td>
304 <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'set time now'}' /></td>
305 <td width='25%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
306 <td width='5%' align='right'> </td>
316 &Header
::closebigbox
();
318 &Header
::closepage
();