]>
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';
42 &Header
::getcgihash
(\
%timesettings);
44 if ($timesettings{'ACTION'} eq $Lang::tr
{'save'})
46 if ($timesettings{'ENABLENTP'} eq 'on')
48 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_1'}) ||
49 &General
::validip
($timesettings{'NTP_ADDR_1'})))
51 $errormessage = $Lang::tr
{'invalid primary ntp'};
55 if ($timesettings{'NTP_ADDR_2'})
57 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_2'}) ||
58 &General
::validip
($timesettings{'NTP_ADDR_2'})))
60 $errormessage = $Lang::tr
{'invalid secondary ntp'};
64 if (!($timesettings{'NTP_ADDR_1'}) && $timesettings{'NTP_ADDR_2'})
66 $errormessage = $Lang::tr
{'cannot specify secondary ntp without specifying primary'};
70 if (!($timesettings{'UPDATE_VALUE'} =~ /^\d+$/) || $timesettings{'UPDATE_VALUE'} <= 0)
72 $errormessage = $Lang::tr
{'invalid time period'};
76 if ($timesettings{'ENABLENTP'} ne "on" && $timesettings{'ENABLECLNTP'} eq "on")
78 $errormessage = $Lang::tr
{'ntp must be enabled to have clients'};
81 if ($timesettings{'ENABLENTP'} eq "on" && !($timesettings{'NTP_ADDR_1'}) && !($timesettings{'NTP_ADDR_2'}))
83 $errormessage = $Lang::tr
{'cannot enable ntp without specifying primary'};
88 $timesettings{'VALID'} = 'no'; }
90 $timesettings{'VALID'} = 'yes'; }
92 &General
::writehash
("${General::swroot}/time/settings", \
%timesettings);
93 open(FILE
, ">/${General::swroot}/time/settime.conf") or die "Unable to write settime.conf file";
95 print FILE
"$timesettings{'NTP_ADDR_1'} $timesettings{'NTP_ADDR_2'}\n";
100 if ($timesettings{'UPDATE_PERIOD'} eq 'daily') {
101 $updateperiod = $timesettings{'UPDATE_VALUE'} * 1440; }
102 elsif ($timesettings{'UPDATE_PERIOD'} eq 'weekly') {
103 $updateperiod = $timesettings{'UPDATE_VALUE'} * 10080; }
104 elsif ($timesettings{'UPDATE_PERIOD'} eq 'monthly') {
105 $updateperiod = $timesettings{'UPDATE_VALUE'} * 40320; }
107 $updateperiod = $timesettings{'UPDATE_VALUE'} * 60; }
109 $updateperiod = $updateperiod - 5;
111 if ($updateperiod <= 5) {
114 open(FILE
, ">/${General::swroot}/time/counter.conf") or die "Unable to write counter.conf file";
116 print FILE
"$updateperiod\n";
119 if ($timesettings{'ENABLENTP'} eq 'on' && $timesettings{'VALID'} eq 'yes')
121 system ('/usr/bin/touch', "${General::swroot}/time/enable");
122 system ('/usr/local/bin/timectrl enable >/dev/null 2>&1');
123 &General
::log($Lang::tr
{'ntp syncro enabled'});
124 unlink "${General::swroot}/time/counter";
125 if ($timesettings{'UPDATE_METHOD'} eq 'periodically')
127 open(FILE
, ">/${General::swroot}/time/counter") or die "Unable to write counter file";
129 print FILE
"$updateperiod\n";
132 if ($timesettings{'ENABLECLNTP'} eq 'on') # DPC added to 1.3.1
134 system ('/usr/bin/touch', "${General::swroot}/time/allowclients"); # DPC added to 1.3.1
135 &General
::log($Lang::tr
{'ntpd restarted'}); # DPC added to 1.3.1
137 unlink "${General::swroot}/time/allowclients";
143 unlink "${General::swroot}/time/enable";
144 unlink "${General::swroot}/time/settimenow";
145 unlink "${General::swroot}/time/allowclients"; # DPC added to 1.3.1
146 system ('/usr/local/bin/timectrl disable >/dev/null 2>&1');
147 &General
::log($Lang::tr
{'ntp syncro disabled'})
149 if (! $errormessage) {
150 system ('/usr/local/bin/timectrl restart >/dev/null 2>&1'); # DPC added to 1.3.1
154 # To enter an ' into a pushbutton solution is to use ' in it's definition
155 # but returned value when pressed is ' not the code. Cleanhtml recode the ' to enable comparison.
156 $timesettings{'ACTION'} = &Header
::cleanhtml
($timesettings{'ACTION'});
157 if ($timesettings{'ACTION'} eq $Lang::tr
{'set time now'} && $timesettings{'ENABLENTP'} eq 'on')
159 system ('/usr/bin/touch', "${General::swroot}/time/settimenow");
162 &General
::readhash
("${General::swroot}/time/settings", \
%timesettings);
164 if ($timesettings{'VALID'} eq '')
166 $timesettings{'ENABLENTP'} = 'off';
167 $timesettings{'UPDATE_METHOD'} = 'manually';
168 $timesettings{'UPDATE_VALUE'} = '1';
169 $timesettings{'UPDATE_PERIOD'} = 'daily';
170 $timesettings{'NTP_ADDR_1'} = 'de.pool.ntp.org';
171 $timesettings{'NTP_ADDR_2'} = 'pool.ntp.org';
174 unless ($errormessage) {
175 $timesettings{'SETMONTH'} = `date +'%m %e %Y %H %M'|cut -c 1-2`;
176 $timesettings{'SETDAY'} = `date +'%m %e %Y %H %M'|cut -c 4-5`;
177 $timesettings{'SETYEAR'} = `date +'%m %e %Y %H %M'|cut -c 7-10`;
178 $timesettings{'SETHOUR'} = `date +'%m %e %Y %H %M'|cut -c 12-13`;
179 $timesettings{'SETMINUTES'} = `date +'%m %e %Y %H %M'|cut -c 15-16`;
180 $_=$timesettings{'SETDAY'};
181 $timesettings{'SETDAY'}=~ tr/ /0/;
187 $checked{'ENABLENTP'}{'off'} = '';
188 $checked{'ENABLENTP'}{'on'} = '';
189 $checked{'ENABLENTP'}{$timesettings{'ENABLENTP'}} = "checked='checked'";
191 $checked{'ENABLECLNTP'}{'off'} = '';
192 $checked{'ENABLECLNTP'}{'on'} = '';
193 $checked{'ENABLECLNTP'}{$timesettings{'ENABLECLNTP'}} = "checked='checked'";
195 $checked{'UPDATE_METHOD'}{'manually'} = '';
196 $checked{'UPDATE_METHOD'}{'periodically'} = '';
197 $checked{'UPDATE_METHOD'}{$timesettings{'UPDATE_METHOD'}} = "checked='checked'";
199 $selected{'UPDATE_PERIOD'}{'hourly'} = '';
200 $selected{'UPDATE_PERIOD'}{'daily'} = '';
201 $selected{'UPDATE_PERIOD'}{'weekly'} = '';
202 $selected{'UPDATE_PERIOD'}{'monthly'} = '';
203 $selected{'UPDATE_PERIOD'}{$timesettings{'UPDATE_PERIOD'}} = "selected='selected'";
205 # added to v0.0.4 to refresh screen if syncro event queued
207 if ( -e
"${General::swroot}/time/settimenow") {
208 $refresh = "<meta http-equiv='refresh' content='60;' />";
211 &Header
::openpage
($Lang::tr
{'ntp configuration'}, 1, $refresh);
213 &Header
::openbigbox
('100%', 'left', '', $errormessage);
215 # DPC move error message to top so it is seen!
217 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
218 print "<font class='base'>$errormessage </font>\n";
222 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
224 &Header
::openbox
('100%', 'left', $Lang::tr
{'network time'});
228 <td><input type='checkbox' name='ENABLENTP' $checked{'ENABLENTP'}{'on'} /></td>
229 <td width='100%' colspan='4' class='base'>$Lang::tr{'network time from'}</td>
233 <td width='100%' class='base' colspan='4'>
237 if ( -e
"${General::swroot}/time/lastset")
239 print "$Lang::tr{'clock last synchronized at'}\n";
240 my $output = `cat ${General::swroot}/time/lastset`;
245 print "$Lang::tr{'clock has not been synchronized'}\n";
252 <td width='25%' class='base'>$Lang::tr{'primary ntp server'}:</td>
253 <td width='25%'><input type='text' name='NTP_ADDR_1' value='$timesettings{'NTP_ADDR_1'}' /></td>
254 <td width='25%' class='base'>$Lang::tr{'secondary ntp server'}: <img src='/blob.gif' align='top' alt='*' /></td>
255 <td width='25%'><input type='text' name='NTP_ADDR_2' value='$timesettings{'NTP_ADDR_2'}' /></td>
259 <td class='base' colspan='4'><input type='checkbox' name='ENABLECLNTP' $checked{'ENABLECLNTP'}{'on'} /> $Lang::tr{'clenabled'}</td>
264 <td colspan='4'><hr /><b>$Lang::tr{'update time'}</b></td>
268 <td class='base' colspan='2'>$Lang::tr{'set time now help'}</td>
271 <td class='base'><input type='radio' name='UPDATE_METHOD' value='periodically' $checked{'UPDATE_METHOD'}{'periodically'} /></td>
272 <td width='15%'>$Lang::tr{'every'}: </td>
273 <td width='35%'><input type='text' name='UPDATE_VALUE' size='3' maxlength='3' value='$timesettings{'UPDATE_VALUE'}' />
274 <select name='UPDATE_PERIOD'>
275 <option value='hourly' $selected{'UPDATE_PERIOD'}{'hourly'}>$Lang::tr{'hours'}</option>
276 <option value='daily' $selected{'UPDATE_PERIOD'}{'daily'}>$Lang::tr{'days'}</option>
277 <option value='weekly' $selected{'UPDATE_PERIOD'}{'weekly'}>$Lang::tr{'weeks'}</option>
278 <option value='monthly' $selected{'UPDATE_PERIOD'}{'monthly'}>$Lang::tr{'months'}</option>
280 <td width='50%'> </td>
283 <td class='base'><input type='radio' name='UPDATE_METHOD' value='manually' $checked{'UPDATE_METHOD'}{'manually'} /></td>
284 <td colspan='2'>$Lang::tr{'manually'}</td>
289 if ( -e
"${General::swroot}/time/settimenow") {
290 print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n";
291 print "<td colspan='2'><font color='red'>$Lang::tr{'waiting to synchronize clock'}...</font></td></tr>\n";
299 <td width='30%'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td>
300 <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'set time now'}' /></td>
301 <td width='25%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
302 <td width='5%' align='right'> </td>
312 &Header
::closebigbox
();
314 &Header
::closepage
();