]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/time.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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';
48 &Header
::getcgihash
(\
%timesettings);
50 if ($timesettings{'ACTION'} eq $Lang::tr
{'save'})
52 if ($timesettings{'ENABLENTP'} eq 'on')
54 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_1'}) ||
55 &General
::validip
($timesettings{'NTP_ADDR_1'})))
57 $errormessage = $Lang::tr
{'invalid primary ntp'};
61 if ($timesettings{'NTP_ADDR_2'})
63 if ( ! ( &General
::validfqdn
($timesettings{'NTP_ADDR_2'}) ||
64 &General
::validip
($timesettings{'NTP_ADDR_2'})))
66 $errormessage = $Lang::tr
{'invalid secondary ntp'};
70 if (!($timesettings{'NTP_ADDR_1'}) && $timesettings{'NTP_ADDR_2'})
72 $errormessage = $Lang::tr
{'cannot specify secondary ntp without specifying primary'};
76 if (!($timesettings{'UPDATE_VALUE'} =~ /^\d+$/) || $timesettings{'UPDATE_VALUE'} <= 0)
78 $errormessage = $Lang::tr
{'invalid time period'};
82 if ($timesettings{'ENABLENTP'} ne "on" && $timesettings{'ENABLECLNTP'} eq "on")
84 $errormessage = $Lang::tr
{'ntp must be enabled to have clients'};
87 if ($timesettings{'ENABLENTP'} eq "on" && !($timesettings{'NTP_ADDR_1'}) && !($timesettings{'NTP_ADDR_2'}))
89 $errormessage = $Lang::tr
{'cannot enable ntp without specifying primary'};
94 $timesettings{'VALID'} = 'no'; }
96 $timesettings{'VALID'} = 'yes'; }
98 &General
::writehash
("${General::swroot}/time/settings", \
%timesettings);
99 open(FILE
, ">/${General::swroot}/time/settime.conf") or die "Unable to write settime.conf file";
101 print FILE
"$timesettings{'NTP_ADDR_1'} $timesettings{'NTP_ADDR_2'}\n";
106 if ($timesettings{'UPDATE_PERIOD'} eq 'daily') {
107 $updateperiod = $timesettings{'UPDATE_VALUE'} * 1440; }
108 elsif ($timesettings{'UPDATE_PERIOD'} eq 'weekly') {
109 $updateperiod = $timesettings{'UPDATE_VALUE'} * 10080; }
110 elsif ($timesettings{'UPDATE_PERIOD'} eq 'monthly') {
111 $updateperiod = $timesettings{'UPDATE_VALUE'} * 40320; }
113 $updateperiod = $timesettings{'UPDATE_VALUE'} * 60; }
115 $updateperiod = $updateperiod - 5;
117 if ($updateperiod <= 5) {
120 open(FILE
, ">/${General::swroot}/time/counter.conf") or die "Unable to write counter.conf file";
122 print FILE
"$updateperiod\n";
125 if ($timesettings{'ENABLENTP'} eq 'on' && $timesettings{'VALID'} eq 'yes')
127 system ('/usr/bin/touch', "${General::swroot}/time/enable");
128 system ('/usr/local/bin/timectrl enable >/dev/null 2>&1');
129 &General
::log($Lang::tr
{'ntp syncro enabled'});
130 unlink "${General::swroot}/time/counter";
131 if ($timesettings{'UPDATE_METHOD'} eq 'periodically')
133 open(FILE
, ">/${General::swroot}/time/counter") or die "Unable to write counter file";
135 print FILE
"$updateperiod\n";
138 if ($timesettings{'ENABLECLNTP'} eq 'on') # DPC added to 1.3.1
140 system ('/usr/bin/touch', "${General::swroot}/time/allowclients"); # DPC added to 1.3.1
141 &General
::log($Lang::tr
{'ntpd restarted'}); # DPC added to 1.3.1
143 unlink "${General::swroot}/time/allowclients";
149 unlink "${General::swroot}/time/enable";
150 unlink "${General::swroot}/time/settimenow";
151 unlink "${General::swroot}/time/allowclients"; # DPC added to 1.3.1
152 system ('/usr/local/bin/timectrl disable >/dev/null 2>&1');
153 &General
::log($Lang::tr
{'ntp syncro disabled'})
155 if (! $errormessage) {
156 system ('/usr/local/bin/timectrl restart >/dev/null 2>&1'); # DPC added to 1.3.1
160 # To enter an ' into a pushbutton solution is to use ' in it's definition
161 # but returned value when pressed is ' not the code. Cleanhtml recode the ' to enable comparison.
162 $timesettings{'ACTION'} = &Header
::cleanhtml
($timesettings{'ACTION'});
163 if ($timesettings{'ACTION'} eq $Lang::tr
{'set time now'} && $timesettings{'ENABLENTP'} eq 'on')
165 system ('/usr/bin/touch', "${General::swroot}/time/settimenow");
168 &General
::readhash
("${General::swroot}/time/settings", \
%timesettings);
170 if ($timesettings{'VALID'} eq '')
172 $timesettings{'ENABLENTP'} = 'off';
173 $timesettings{'UPDATE_METHOD'} = 'manually';
174 $timesettings{'UPDATE_VALUE'} = '1';
175 $timesettings{'UPDATE_PERIOD'} = 'daily';
176 $timesettings{'NTP_ADDR_1'} = 'de.pool.ntp.org';
177 $timesettings{'NTP_ADDR_2'} = 'pool.ntp.org';
180 unless ($errormessage) {
181 $timesettings{'SETMONTH'} = `date +'%m %e %Y %H %M'|cut -c 1-2`;
182 $timesettings{'SETDAY'} = `date +'%m %e %Y %H %M'|cut -c 4-5`;
183 $timesettings{'SETYEAR'} = `date +'%m %e %Y %H %M'|cut -c 7-10`;
184 $timesettings{'SETHOUR'} = `date +'%m %e %Y %H %M'|cut -c 12-13`;
185 $timesettings{'SETMINUTES'} = `date +'%m %e %Y %H %M'|cut -c 15-16`;
186 $_=$timesettings{'SETDAY'};
187 $timesettings{'SETDAY'}=~ tr/ /0/;
193 $checked{'ENABLENTP'}{'off'} = '';
194 $checked{'ENABLENTP'}{'on'} = '';
195 $checked{'ENABLENTP'}{$timesettings{'ENABLENTP'}} = "checked='checked'";
197 $checked{'ENABLECLNTP'}{'off'} = '';
198 $checked{'ENABLECLNTP'}{'on'} = '';
199 $checked{'ENABLECLNTP'}{$timesettings{'ENABLECLNTP'}} = "checked='checked'";
201 $checked{'UPDATE_METHOD'}{'manually'} = '';
202 $checked{'UPDATE_METHOD'}{'periodically'} = '';
203 $checked{'UPDATE_METHOD'}{$timesettings{'UPDATE_METHOD'}} = "checked='checked'";
205 $selected{'UPDATE_PERIOD'}{'hourly'} = '';
206 $selected{'UPDATE_PERIOD'}{'daily'} = '';
207 $selected{'UPDATE_PERIOD'}{'weekly'} = '';
208 $selected{'UPDATE_PERIOD'}{'monthly'} = '';
209 $selected{'UPDATE_PERIOD'}{$timesettings{'UPDATE_PERIOD'}} = "selected='selected'";
211 # added to v0.0.4 to refresh screen if syncro event queued
213 if ( -e
"${General::swroot}/time/settimenow") {
214 $refresh = "<meta http-equiv='refresh' content='60;' />";
217 &Header
::openpage
($Lang::tr
{'ntp configuration'}, 1, $refresh);
219 &Header
::openbigbox
('100%', 'left', '', $errormessage);
221 # DPC move error message to top so it is seen!
223 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
224 print "<font class='base'>$errormessage </font>\n";
228 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
230 &Header
::openbox
('100%', 'left', $Lang::tr
{'network time'});
234 <td><input type='checkbox' name='ENABLENTP' $checked{'ENABLENTP'}{'on'} /></td>
235 <td width='100%' colspan='4' class='base'>$Lang::tr{'network time from'}</td>
239 <td width='100%' class='base' colspan='4'>
243 if ( -e
"${General::swroot}/time/lastset")
245 print "$Lang::tr{'clock last synchronized at'}\n";
246 my $output = `cat ${General::swroot}/time/lastset`;
251 print "$Lang::tr{'clock has not been synchronized'}\n";
258 <td width='25%' class='base'>$Lang::tr{'primary ntp server'}:</td>
259 <td width='25%'><input type='text' name='NTP_ADDR_1' value='$timesettings{'NTP_ADDR_1'}' /></td>
260 <td width='25%' class='base'>$Lang::tr{'secondary ntp server'}: <img src='/blob.gif' align='top' alt='*' /></td>
261 <td width='25%'><input type='text' name='NTP_ADDR_2' value='$timesettings{'NTP_ADDR_2'}' /></td>
265 <td class='base' colspan='4'><input type='checkbox' name='ENABLECLNTP' $checked{'ENABLECLNTP'}{'on'} /> $Lang::tr{'clenabled'}</td>
270 <td colspan='4'><hr /><b>$Lang::tr{'update time'}</b></td>
274 <td class='base' colspan='2'>$Lang::tr{'set time now help'}</td>
277 <td class='base'><input type='radio' name='UPDATE_METHOD' value='periodically' $checked{'UPDATE_METHOD'}{'periodically'} /></td>
278 <td width='15%'>$Lang::tr{'every'}: </td>
279 <td width='35%'><input type='text' name='UPDATE_VALUE' size='3' maxlength='3' value='$timesettings{'UPDATE_VALUE'}' />
280 <select name='UPDATE_PERIOD'>
281 <option value='hourly' $selected{'UPDATE_PERIOD'}{'hourly'}>$Lang::tr{'hours'}</option>
282 <option value='daily' $selected{'UPDATE_PERIOD'}{'daily'}>$Lang::tr{'days'}</option>
283 <option value='weekly' $selected{'UPDATE_PERIOD'}{'weekly'}>$Lang::tr{'weeks'}</option>
284 <option value='monthly' $selected{'UPDATE_PERIOD'}{'monthly'}>$Lang::tr{'months'}</option>
286 <td width='50%'> </td>
289 <td class='base'><input type='radio' name='UPDATE_METHOD' value='manually' $checked{'UPDATE_METHOD'}{'manually'} /></td>
290 <td colspan='2'>$Lang::tr{'manually'}</td>
295 if ( -e
"${General::swroot}/time/settimenow") {
296 print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n";
297 print "<td colspan='2'><font color='red'>$Lang::tr{'waiting to synchronize clock'}...</font></td></tr>\n";
305 <td width='30%'><img src='/blob.gif' alt='*' /> $Lang::tr{'this field may be blank'}</td>
306 <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'set time now'}' /></td>
307 <td width='25%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
308 <td width='5%' align='right'> </td>
318 &Header
::closebigbox
();
320 &Header
::closepage
();