]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/time.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 IPFire Team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
33 my $errormessage = '';
35 &Header
::showhttpheaders
();
37 $timesettings{'ACTION'} = '';
38 $timesettings{'VALID'} = '';
40 $timesettings{'ENABLENTP'} = 'off';
41 $timesettings{'NTP_ADDR_1'} = '';
42 $timesettings{'NTP_ADDR_2'} = '';
43 $timesettings{'UPDATE_METHOD'} = 'manually';
44 $timesettings{'UPDATE_VALUE'} = '0';
45 $timesettings{'UPDATE_PERIOD'} = '';
46 $timesettings{'ENABLECLNTP'} = 'off';
47 $timesettings{'ENABLESETONBOOT'} = 'off';
49 &Header
::getcgihash
(\
%timesettings);
51 if ($timesettings{'ACTION'} eq $Lang::tr
{'save'})
53 if ($timesettings{'ENABLENTP'} eq 'on')
55 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_1'}) ||
56 &General
::validip
($timesettings{'NTP_ADDR_1'})))
58 $errormessage = $Lang::tr
{'invalid primary ntp'};
62 if ($timesettings{'NTP_ADDR_2'})
64 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_2'}) ||
65 &General
::validip
($timesettings{'NTP_ADDR_2'})))
67 $errormessage = $Lang::tr
{'invalid secondary ntp'};
71 if (!($timesettings{'NTP_ADDR_1'}) && $timesettings{'NTP_ADDR_2'})
73 $errormessage = $Lang::tr
{'cannot specify secondary ntp without specifying primary'};
77 if (!($timesettings{'UPDATE_VALUE'} =~ /^\d+$/) || $timesettings{'UPDATE_VALUE'} <= 0)
79 $errormessage = $Lang::tr
{'invalid time period'};
83 if ($timesettings{'ENABLENTP'} ne "on" && $timesettings{'ENABLECLNTP'} eq "on")
85 $errormessage = $Lang::tr
{'ntp must be enabled to have clients'};
88 if ($timesettings{'ENABLENTP'} eq "on" && !($timesettings{'NTP_ADDR_1'}) && !($timesettings{'NTP_ADDR_2'}))
90 $errormessage = $Lang::tr
{'cannot enable ntp without specifying primary'};
95 $timesettings{'VALID'} = 'no'; }
97 $timesettings{'VALID'} = 'yes'; }
99 &General
::writehash
("${General::swroot}/time/settings", \
%timesettings);
100 open(FILE
, ">/${General::swroot}/time/settime.conf") or die "Unable to write settime.conf file";
102 print FILE
"$timesettings{'NTP_ADDR_1'} $timesettings{'NTP_ADDR_2'}\n";
107 if ($timesettings{'UPDATE_PERIOD'} eq 'daily') {
108 $updateperiod = $timesettings{'UPDATE_VALUE'} * 1440; }
109 elsif ($timesettings{'UPDATE_PERIOD'} eq 'weekly') {
110 $updateperiod = $timesettings{'UPDATE_VALUE'} * 10080; }
111 elsif ($timesettings{'UPDATE_PERIOD'} eq 'monthly') {
112 $updateperiod = $timesettings{'UPDATE_VALUE'} * 40320; }
114 $updateperiod = $timesettings{'UPDATE_VALUE'} * 60; }
116 $updateperiod = $updateperiod - 5;
118 if ($updateperiod <= 5) {
121 open(FILE
, ">/${General::swroot}/time/counter.conf") or die "Unable to write counter.conf file";
123 print FILE
"$updateperiod\n";
126 if ($timesettings{'ENABLENTP'} eq 'on' && $timesettings{'VALID'} eq 'yes')
128 system ('/usr/bin/touch', "${General::swroot}/time/enable");
129 system ('/usr/local/bin/timectrl enable >/dev/null 2>&1');
130 &General
::log($Lang::tr
{'ntp syncro enabled'});
131 unlink "/var/lock/time/counter";
132 if ($timesettings{'UPDATE_METHOD'} eq 'periodically')
134 open(FILE
, ">/var/lock/time/counter") or die "Unable to write counter file";
136 print FILE
"$updateperiod\n";
139 if ($timesettings{'ENABLECLNTP'} eq 'on') # DPC added to 1.3.1
141 system ('/usr/bin/touch', "${General::swroot}/time/allowclients"); # DPC added to 1.3.1
142 &General
::log($Lang::tr
{'ntpd restarted'}); # DPC added to 1.3.1
144 unlink "${General::swroot}/time/allowclients";
150 unlink "${General::swroot}/time/enable";
151 unlink "/var/lock/time/settimenow";
152 unlink "${General::swroot}/time/allowclients"; # DPC added to 1.3.1
153 system ('/usr/local/bin/timectrl disable >/dev/null 2>&1');
154 &General
::log($Lang::tr
{'ntp syncro disabled'})
156 if (! $errormessage) {
157 system ('/usr/local/bin/timectrl restart >/dev/null 2>&1'); # DPC added to 1.3.1
161 # To enter an ' into a pushbutton solution is to use ' in it's definition
162 # but returned value when pressed is ' not the code. Cleanhtml recode the ' to enable comparison.
163 $timesettings{'ACTION'} = &Header
::cleanhtml
($timesettings{'ACTION'});
164 if ($timesettings{'ACTION'} eq $Lang::tr
{'set time now'} && $timesettings{'ENABLENTP'} eq 'on')
166 system ('/usr/bin/touch', "/var/lock/time/settimenow");
169 &General
::readhash
("${General::swroot}/time/settings", \
%timesettings);
171 if ($timesettings{'VALID'} eq '')
173 $timesettings{'ENABLENTP'} = 'off';
174 $timesettings{'UPDATE_METHOD'} = 'manually';
175 $timesettings{'UPDATE_VALUE'} = '1';
176 $timesettings{'UPDATE_PERIOD'} = 'daily';
177 $timesettings{'NTP_ADDR_1'} = '0.ipfire.pool.ntp.org';
178 $timesettings{'NTP_ADDR_2'} = '1.ipfire.pool.ntp.org';
179 $timesettings{'ENABLESETONBOOT'} = 'off';
182 unless ($errormessage) {
183 $timesettings{'SETMONTH'} = `date +'%m %e %Y %H %M'|cut -c 1-2`;
184 $timesettings{'SETDAY'} = `date +'%m %e %Y %H %M'|cut -c 4-5`;
185 $timesettings{'SETYEAR'} = `date +'%m %e %Y %H %M'|cut -c 7-10`;
186 $timesettings{'SETHOUR'} = `date +'%m %e %Y %H %M'|cut -c 12-13`;
187 $timesettings{'SETMINUTES'} = `date +'%m %e %Y %H %M'|cut -c 15-16`;
188 $_=$timesettings{'SETDAY'};
189 $timesettings{'SETDAY'}=~ tr/ /0/;
195 $checked{'ENABLENTP'}{'off'} = '';
196 $checked{'ENABLENTP'}{'on'} = '';
197 $checked{'ENABLENTP'}{$timesettings{'ENABLENTP'}} = "checked='checked'";
199 $checked{'ENABLECLNTP'}{'off'} = '';
200 $checked{'ENABLECLNTP'}{'on'} = '';
201 $checked{'ENABLECLNTP'}{$timesettings{'ENABLECLNTP'}} = "checked='checked'";
203 $checked{'ENABLESETONBOOT'}{'off'} = '';
204 $checked{'ENABLESETONBOOT'}{'on'} = '';
205 $checked{'ENABLESETONBOOT'}{$timesettings{'ENABLESETONBOOT'}} = "checked='checked'";
207 $checked{'UPDATE_METHOD'}{'manually'} = '';
208 $checked{'UPDATE_METHOD'}{'periodically'} = '';
209 $checked{'UPDATE_METHOD'}{$timesettings{'UPDATE_METHOD'}} = "checked='checked'";
211 $selected{'UPDATE_PERIOD'}{'hourly'} = '';
212 $selected{'UPDATE_PERIOD'}{'daily'} = '';
213 $selected{'UPDATE_PERIOD'}{'weekly'} = '';
214 $selected{'UPDATE_PERIOD'}{'monthly'} = '';
215 $selected{'UPDATE_PERIOD'}{$timesettings{'UPDATE_PERIOD'}} = "selected='selected'";
217 # added to v0.0.4 to refresh screen if syncro event queued
219 if ( -e
"/var/lock/time/settimenow") {
220 $refresh = "<meta http-equiv='refresh' content='60;' />";
223 &Header
::openpage
($Lang::tr
{'ntp configuration'}, 1, $refresh);
225 &Header
::openbigbox
('100%', 'left', '', $errormessage);
227 # DPC move error message to top so it is seen!
229 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
230 print "<font class='base'>$errormessage </font>\n";
234 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
236 &Header
::openbox
('100%', 'left', $Lang::tr
{'ntp common settings'});
240 <td><input type='checkbox' name='ENABLENTP' $checked{'ENABLENTP'}{'on'} /></td>
241 <td width='100%' colspan='4' class='base'>$Lang::tr{'network time from'}</td>
245 <td width='100%' class='base' colspan='4'>
249 if ( -e
"/var/lock/time/lastset")
251 print "$Lang::tr{'clock last synchronized at'}\n";
252 open(FILE
, "</var/lock/time/lastset") or die "Unable to read lastset";
259 print "$Lang::tr{'clock has not been synchronized'}\n";
266 <td width='25%' class='base'>$Lang::tr{'primary ntp server'}:</td>
267 <td width='25%'><input type='text' name='NTP_ADDR_1' value='$timesettings{'NTP_ADDR_1'}' /></td>
268 <td width='25%' class='base'>$Lang::tr{'secondary ntp server'}: <img src='/blob.gif' align='top' alt='*' /></td>
269 <td width='25%'><input type='text' name='NTP_ADDR_2' value='$timesettings{'NTP_ADDR_2'}' /></td>
273 <td class='base' colspan='4'><input type='checkbox' name='ENABLECLNTP' $checked{'ENABLECLNTP'}{'on'} /> $Lang::tr{'clenabled'}</td>
277 <td class='base' colspan='4'><input type='checkbox' name='ENABLESETONBOOT' $checked{'ENABLESETONBOOT'}{'on'} /> $Lang::tr{'Set time on boot'}</td>
283 &Header
::openbox
('100%',1,$Lang::tr
{'ntp sync'});
287 <td class='base'><input type='radio' name='UPDATE_METHOD' value='periodically' $checked{'UPDATE_METHOD'}{'periodically'} /></td>
288 <td width='10%'>$Lang::tr{'every'}</td>
289 <td width='45%'><input type='text' name='UPDATE_VALUE' size='3' maxlength='3' value='$timesettings{'UPDATE_VALUE'}' />
290 <select name='UPDATE_PERIOD'>
291 <option value='hourly' $selected{'UPDATE_PERIOD'}{'hourly'}>$Lang::tr{'hours'}</option>
292 <option value='daily' $selected{'UPDATE_PERIOD'}{'daily'}>$Lang::tr{'days'}</option>
293 <option value='weekly' $selected{'UPDATE_PERIOD'}{'weekly'}>$Lang::tr{'weeks'}</option>
294 <option value='monthly' $selected{'UPDATE_PERIOD'}{'monthly'}>$Lang::tr{'months'}</option>
296 <td width='50%'> </td>
299 <td class='base'><input type='radio' name='UPDATE_METHOD' value='manually' $checked{'UPDATE_METHOD'}{'manually'} /></td>
300 <td colspan='2'>$Lang::tr{'manually'}</td>
303 <td colspan='4'><br><br><strong>$Lang::tr{'update time'}</strong></td>
307 <td class='base' colspan='3'>$Lang::tr{'set time now help'}</td>
312 if ( -e
"/var/lock/time/settimenow") {
313 print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n";
314 print "<td colspan='2'><font color='red'>$Lang::tr{'waiting to synchronize clock'}...</font></td></tr>\n";
322 <td width='30%'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td>
323 <td width='65%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'set time now'}' /></td>
324 <td width='5%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
334 &Header
::closebigbox
();
336 &Header
::closepage
();