X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Ftime.cgi;h=988a1484cc10fdb6a77180b120d55bf4c9cda6e1;hp=4f4a739f32abd0dee1d2ca93a9c2e1d7fa307d4d;hb=0b09e72214df3d4d62c1a061f1e8866020877017;hpb=cd1a2927226c734d96478e12bb768256fb64a06a diff --git a/html/cgi-bin/time.cgi b/html/cgi-bin/time.cgi index 4f4a739f32..988a1484cc 100644 --- a/html/cgi-bin/time.cgi +++ b/html/cgi-bin/time.cgi @@ -1,391 +1,323 @@ -#!/usr/bin/perl -# -# IPCop CGIs -# -# This file is part of the IPCop Project -# -# This code is distributed under the terms of the GPL -# -# (c) Eric Oberlander June 2002 -# -# (c) Darren Critchley June 2003 - added real time clock setting, etc -# -# $Id: time.cgi,v 1.4.2.11 2005/05/28 12:16:18 eoberlander Exp $ -# - -use strict; - -# enable only the following on debugging purpose -#use warnings; -#use CGI::Carp 'fatalsToBrowser'; - -require 'CONFIG_ROOT/general-functions.pl'; -require "${General::swroot}/lang.pl"; -require "${General::swroot}/header.pl"; - -my %timesettings=(); -my $errormessage = ''; - -&Header::showhttpheaders(); - -$timesettings{'ACTION'} = ''; -$timesettings{'VALID'} = ''; - -$timesettings{'ENABLENTP'} = 'off'; -$timesettings{'NTP_ADDR_1'} = ''; -$timesettings{'NTP_ADDR_2'} = ''; -$timesettings{'UPDATE_METHOD'} = 'manually'; -$timesettings{'UPDATE_VALUE'} = '0'; -$timesettings{'UPDATE_PERIOD'} = ''; -$timesettings{'ENABLECLNTP'} = 'off'; -$timesettings{'SETHOUR'} = ''; -$timesettings{'SETMINUTES'} = ''; -$timesettings{'SETDAY'} = ''; -$timesettings{'SETMONTH'} = ''; -$timesettings{'SETYEAR'} = ''; - -&Header::getcgihash(\%timesettings); - -if ($timesettings{'ACTION'} eq $Lang::tr{'instant update'}) -{ - if ($timesettings{'SETHOUR'} eq '' || $timesettings{'SETHOUR'} < 0 || $timesettings{'SETHOUR'} > 23) { - $errormessage = $Lang::tr{'invalid time entered'}; - goto UPDTERROR; - } - if ($timesettings{'SETMINUTES'} eq '' || $timesettings{'SETMINUTES'} < 0 || $timesettings{'SETMINUTES'} > 59) { - $errormessage = $Lang::tr{'invalid time entered'}; - goto UPDTERROR; - } - if ($timesettings{'SETDAY'} eq '' || $timesettings{'SETDAY'} < 1 || $timesettings{'SETDAY'} > 31) { - $errormessage = $Lang::tr{'invalid date entered'}; - goto UPDTERROR; - } - if ($timesettings{'SETMONTH'} eq '' || $timesettings{'SETMONTH'} < 1 || $timesettings{'SETMONTH'} > 12) { - $errormessage = $Lang::tr{'invalid date entered'}; - goto UPDTERROR; - } - if ($timesettings{'SETYEAR'} eq '' || $timesettings{'SETYEAR'} < 2003 || $timesettings{'SETYEAR'} > 2030) { - $errormessage = $Lang::tr{'invalid date entered'}; - goto UPDTERROR; - } - -UPDTERROR: - if ($errormessage) { - $timesettings{'VALID'} = 'no'; } - else { - $timesettings{'VALID'} = 'yes'; } - - if ($timesettings{'VALID'} eq 'yes') { - # we want date in YYYY-MM-DD HH:MM format for date command - # EAO changed datestring to ISO 6801 format 2003-08-11 - my $datestring = "$timesettings{'SETYEAR'}-$timesettings{'SETMONTH'}-$timesettings{'SETDAY'}"; - my $timestring = "$timesettings{'SETHOUR'}:$timesettings{'SETMINUTES'}"; - # EAO setdate.c also revised for ISO 6801 date format 2003-08-11 - system ('/usr/local/bin/setdate', $datestring, $timestring); - &General::log("$Lang::tr{'time date manually reset'} $datestring $timestring"); - } - unless ($errormessage) { - undef %timesettings; - } -} - -if ($timesettings{'ACTION'} eq $Lang::tr{'save'}) -{ - if ($timesettings{'ENABLENTP'} eq 'on') - { - if ( ! ( &General::validfqdn($timesettings{'NTP_ADDR_1'}) || - &General::validip ($timesettings{'NTP_ADDR_1'}))) - { - $errormessage = $Lang::tr{'invalid primary ntp'}; - goto ERROR; - } - } - if ($timesettings{'NTP_ADDR_2'}) - { - if ( ! ( &General::validfqdn($timesettings{'NTP_ADDR_2'}) || - &General::validip ($timesettings{'NTP_ADDR_2'}))) - { - $errormessage = $Lang::tr{'invalid secondary ntp'}; - goto ERROR; - } - } - if (!($timesettings{'NTP_ADDR_1'}) && $timesettings{'NTP_ADDR_2'}) - { - $errormessage = $Lang::tr{'cannot specify secondary ntp without specifying primary'}; - goto ERROR; - } - - if (!($timesettings{'UPDATE_VALUE'} =~ /^\d+$/) || $timesettings{'UPDATE_VALUE'} <= 0) - { - $errormessage = $Lang::tr{'invalid time period'}; - goto ERROR; - } - - if ($timesettings{'ENABLENTP'} ne "on" && $timesettings{'ENABLECLNTP'} eq "on") - { - $errormessage = $Lang::tr{'ntp must be enabled to have clients'}; - goto ERROR; - } - if ($timesettings{'ENABLENTP'} eq "on" && !($timesettings{'NTP_ADDR_1'}) && !($timesettings{'NTP_ADDR_2'})) - { - $errormessage = $Lang::tr{'cannot enable ntp without specifying primary'}; - goto ERROR; - } -ERROR: - if ($errormessage) { - $timesettings{'VALID'} = 'no'; } - else { - $timesettings{'VALID'} = 'yes'; } - - &General::writehash("${General::swroot}/time/settings", \%timesettings); - open(FILE, ">/${General::swroot}/time/settime.conf") or die "Unable to write settime.conf file"; - flock(FILE, 2); - print FILE "$timesettings{'NTP_ADDR_1'} $timesettings{'NTP_ADDR_2'}\n"; - close FILE; - - my $updateperiod=0; - - if ($timesettings{'UPDATE_PERIOD'} eq 'daily') { - $updateperiod = $timesettings{'UPDATE_VALUE'} * 1440; } - elsif ($timesettings{'UPDATE_PERIOD'} eq 'weekly') { - $updateperiod = $timesettings{'UPDATE_VALUE'} * 10080; } - elsif ($timesettings{'UPDATE_PERIOD'} eq 'monthly') { - $updateperiod = $timesettings{'UPDATE_VALUE'} * 40320; } - else { - $updateperiod = $timesettings{'UPDATE_VALUE'} * 60; } - - $updateperiod = $updateperiod - 5; - - if ($updateperiod <= 5) { - $updateperiod = 5; } - - open(FILE, ">/${General::swroot}/time/counter.conf") or die "Unable to write counter.conf file"; - flock(FILE, 2); - print FILE "$updateperiod\n"; - close FILE; - - if ($timesettings{'ENABLENTP'} eq 'on' && $timesettings{'VALID'} eq 'yes') - { - system ('/bin/touch', "${General::swroot}/time/enable"); - &General::log($Lang::tr{'ntp syncro enabled'}); - unlink "${General::swroot}/time/counter"; - if ($timesettings{'UPDATE_METHOD'} eq 'periodically') - { - open(FILE, ">/${General::swroot}/time/counter") or die "Unable to write counter file"; - flock(FILE, 2); - print FILE "$updateperiod\n"; - close FILE; - } - if ($timesettings{'ENABLECLNTP'} eq 'on') # DPC added to 1.3.1 - { - system ('/bin/touch', "${General::swroot}/time/allowclients"); # DPC added to 1.3.1 - &General::log($Lang::tr{'ntpd restarted'}); # DPC added to 1.3.1 - } else { - unlink "${General::swroot}/time/allowclients"; - } - - } - else - { - unlink "${General::swroot}/time/enable"; - unlink "${General::swroot}/time/settimenow"; - unlink "${General::swroot}/time/allowclients"; # DPC added to 1.3.1 - &General::log($Lang::tr{'ntp syncro disabled'}) - } - if (! $errormessage) { - system ('/usr/local/bin/restartntpd'); # DPC added to 1.3.1 - } -} - -# To enter an ' into a pushbutton solution is to use ' in it's definition -# but returned value when pressed is ' not the code. Cleanhtml recode the ' to enable comparison. -$timesettings{'ACTION'} = &Header::cleanhtml ($timesettings{'ACTION'}); -if ($timesettings{'ACTION'} eq $Lang::tr{'set time now'} && $timesettings{'ENABLENTP'} eq 'on') -{ - system ('/bin/touch', "${General::swroot}/time/settimenow"); -} - -&General::readhash("${General::swroot}/time/settings", \%timesettings); - -if ($timesettings{'VALID'} eq '') -{ - $timesettings{'ENABLENTP'} = 'off'; - $timesettings{'UPDATE_METHOD'} = 'manually'; - $timesettings{'UPDATE_VALUE'} = '1'; - $timesettings{'UPDATE_PERIOD'} = 'daily'; - $timesettings{'NTP_ADDR_1'} = 'pool.ntp.org'; - $timesettings{'NTP_ADDR_2'} = 'pool.ntp.org'; -} - -unless ($errormessage) { - $timesettings{'SETMONTH'} = `date +'%m %e %Y %H %M'|cut -c 1-2`; - $timesettings{'SETDAY'} = `date +'%m %e %Y %H %M'|cut -c 4-5`; - $timesettings{'SETYEAR'} = `date +'%m %e %Y %H %M'|cut -c 7-10`; - $timesettings{'SETHOUR'} = `date +'%m %e %Y %H %M'|cut -c 12-13`; - $timesettings{'SETMINUTES'} = `date +'%m %e %Y %H %M'|cut -c 15-16`; - $_=$timesettings{'SETDAY'}; - $timesettings{'SETDAY'}=~ tr/ /0/; -} - -my %selected=(); -my %checked=(); - -$checked{'ENABLENTP'}{'off'} = ''; -$checked{'ENABLENTP'}{'on'} = ''; -$checked{'ENABLENTP'}{$timesettings{'ENABLENTP'}} = "checked='checked'"; - -$checked{'ENABLECLNTP'}{'off'} = ''; -$checked{'ENABLECLNTP'}{'on'} = ''; -$checked{'ENABLECLNTP'}{$timesettings{'ENABLECLNTP'}} = "checked='checked'"; - -$checked{'UPDATE_METHOD'}{'manually'} = ''; -$checked{'UPDATE_METHOD'}{'periodically'} = ''; -$checked{'UPDATE_METHOD'}{$timesettings{'UPDATE_METHOD'}} = "checked='checked'"; - -$selected{'UPDATE_PERIOD'}{'hourly'} = ''; -$selected{'UPDATE_PERIOD'}{'daily'} = ''; -$selected{'UPDATE_PERIOD'}{'weekly'} = ''; -$selected{'UPDATE_PERIOD'}{'monthly'} = ''; -$selected{'UPDATE_PERIOD'}{$timesettings{'UPDATE_PERIOD'}} = "selected='selected'"; - -# added to v0.0.4 to refresh screen if syncro event queued -my $refresh = ''; -if ( -e "${General::swroot}/time/settimenow") { - $refresh = ""; -} - -&Header::openpage($Lang::tr{'ntp configuration'}, 1, $refresh); - -&Header::openbigbox('100%', 'left', '', $errormessage); - -# DPC move error message to top so it is seen! -if ($errormessage) { - &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); - print "$errormessage \n"; - &Header::closebox(); - } - -print "
\n"; - -&Header::openbox('100%', 'left', $Lang::tr{'network time'}); -print < - - - $Lang::tr{'network time from'} - - -   - -END -; - -if ( -e "${General::swroot}/time/lastset") -{ - print "$Lang::tr{'clock last synchronized at'}\n"; - my $output = `cat ${General::swroot}/time/lastset`; - print $output; -} -else -{ - print "$Lang::tr{'clock has not been synchronized'}\n"; -} - -print < - -   - $Lang::tr{'primary ntp server'}: - - $Lang::tr{'secondary ntp server'}:  * - - - -   - $Lang::tr{'clenabled'} - - - - - - - - - - - - - - - - - - - - -END -; - -if ( -e "${General::swroot}/time/settimenow") { - print "\n\n"; - print "\n"; -} -print < -
-
-

$Lang::tr{'update time'}
 $Lang::tr{'set time now help'}
$Lang::tr{'every'}: -  
$Lang::tr{'manually'}
$Lang::tr{'waiting to synchronize clock'}...
- - - - - - -
* $Lang::tr{'this field may be blank'} - -
-END -; - -&Header::closebox(); - -&Header::openbox('100%', 'left', $Lang::tr{'update time'}); - -print < - - - - - - - - - - - - - - - -
$Lang::tr{'year'}:  $Lang::tr{'month'}:  $Lang::tr{'day'}:     $Lang::tr{'hours2'}:  $Lang::tr{'minutes'}: 
- - - - -END -; -&Header::closebox(); - -print "\n"; - -&Header::closebigbox(); - -&Header::closepage(); - +#!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007 Michael Tremer & Christian Schmidt # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +use strict; + +# enable only the following on debugging purpose +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; + +require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/lang.pl"; +require "${General::swroot}/header.pl"; + +my %timesettings=(); +my $errormessage = ''; + +&Header::showhttpheaders(); + +$timesettings{'ACTION'} = ''; +$timesettings{'VALID'} = ''; + +$timesettings{'ENABLENTP'} = 'off'; +$timesettings{'NTP_ADDR_1'} = ''; +$timesettings{'NTP_ADDR_2'} = ''; +$timesettings{'UPDATE_METHOD'} = 'manually'; +$timesettings{'UPDATE_VALUE'} = '0'; +$timesettings{'UPDATE_PERIOD'} = ''; +$timesettings{'ENABLECLNTP'} = 'off'; + +&Header::getcgihash(\%timesettings); + +if ($timesettings{'ACTION'} eq $Lang::tr{'save'}) +{ + if ($timesettings{'ENABLENTP'} eq 'on') + { + if ( ! ( &General::validfqdn($timesettings{'NTP_ADDR_1'}) || + &General::validip ($timesettings{'NTP_ADDR_1'}))) + { + $errormessage = $Lang::tr{'invalid primary ntp'}; + goto ERROR; + } + } + if ($timesettings{'NTP_ADDR_2'}) + { + if ( ! ( &General::validfqdn($timesettings{'NTP_ADDR_2'}) || + &General::validip ($timesettings{'NTP_ADDR_2'}))) + { + $errormessage = $Lang::tr{'invalid secondary ntp'}; + goto ERROR; + } + } + if (!($timesettings{'NTP_ADDR_1'}) && $timesettings{'NTP_ADDR_2'}) + { + $errormessage = $Lang::tr{'cannot specify secondary ntp without specifying primary'}; + goto ERROR; + } + + if (!($timesettings{'UPDATE_VALUE'} =~ /^\d+$/) || $timesettings{'UPDATE_VALUE'} <= 0) + { + $errormessage = $Lang::tr{'invalid time period'}; + goto ERROR; + } + + if ($timesettings{'ENABLENTP'} ne "on" && $timesettings{'ENABLECLNTP'} eq "on") + { + $errormessage = $Lang::tr{'ntp must be enabled to have clients'}; + goto ERROR; + } + if ($timesettings{'ENABLENTP'} eq "on" && !($timesettings{'NTP_ADDR_1'}) && !($timesettings{'NTP_ADDR_2'})) + { + $errormessage = $Lang::tr{'cannot enable ntp without specifying primary'}; + goto ERROR; + } +ERROR: + if ($errormessage) { + $timesettings{'VALID'} = 'no'; } + else { + $timesettings{'VALID'} = 'yes'; } + + &General::writehash("${General::swroot}/time/settings", \%timesettings); + open(FILE, ">/${General::swroot}/time/settime.conf") or die "Unable to write settime.conf file"; + flock(FILE, 2); + print FILE "$timesettings{'NTP_ADDR_1'} $timesettings{'NTP_ADDR_2'}\n"; + close FILE; + + my $updateperiod=0; + + if ($timesettings{'UPDATE_PERIOD'} eq 'daily') { + $updateperiod = $timesettings{'UPDATE_VALUE'} * 1440; } + elsif ($timesettings{'UPDATE_PERIOD'} eq 'weekly') { + $updateperiod = $timesettings{'UPDATE_VALUE'} * 10080; } + elsif ($timesettings{'UPDATE_PERIOD'} eq 'monthly') { + $updateperiod = $timesettings{'UPDATE_VALUE'} * 40320; } + else { + $updateperiod = $timesettings{'UPDATE_VALUE'} * 60; } + + $updateperiod = $updateperiod - 5; + + if ($updateperiod <= 5) { + $updateperiod = 5; } + + open(FILE, ">/${General::swroot}/time/counter.conf") or die "Unable to write counter.conf file"; + flock(FILE, 2); + print FILE "$updateperiod\n"; + close FILE; + + if ($timesettings{'ENABLENTP'} eq 'on' && $timesettings{'VALID'} eq 'yes') + { + system ('/usr/bin/touch', "${General::swroot}/time/enable"); + system ('/usr/local/bin/timectrl enable >/dev/null 2>&1'); + &General::log($Lang::tr{'ntp syncro enabled'}); + unlink "/var/lock/time/counter"; + if ($timesettings{'UPDATE_METHOD'} eq 'periodically') + { + open(FILE, ">/var/lock/time/counter") or die "Unable to write counter file"; + flock(FILE, 2); + print FILE "$updateperiod\n"; + close FILE; + } + if ($timesettings{'ENABLECLNTP'} eq 'on') # DPC added to 1.3.1 + { + system ('/usr/bin/touch', "${General::swroot}/time/allowclients"); # DPC added to 1.3.1 + &General::log($Lang::tr{'ntpd restarted'}); # DPC added to 1.3.1 + } else { + unlink "${General::swroot}/time/allowclients"; + } + + } + else + { + unlink "${General::swroot}/time/enable"; + unlink "/var/lock/time/settimenow"; + unlink "${General::swroot}/time/allowclients"; # DPC added to 1.3.1 + system ('/usr/local/bin/timectrl disable >/dev/null 2>&1'); + &General::log($Lang::tr{'ntp syncro disabled'}) + } + if (! $errormessage) { + system ('/usr/local/bin/timectrl restart >/dev/null 2>&1'); # DPC added to 1.3.1 + } +} + +# To enter an ' into a pushbutton solution is to use ' in it's definition +# but returned value when pressed is ' not the code. Cleanhtml recode the ' to enable comparison. +$timesettings{'ACTION'} = &Header::cleanhtml ($timesettings{'ACTION'}); +if ($timesettings{'ACTION'} eq $Lang::tr{'set time now'} && $timesettings{'ENABLENTP'} eq 'on') +{ + system ('/usr/bin/touch', "/var/lock/time/settimenow"); +} + +&General::readhash("${General::swroot}/time/settings", \%timesettings); + +if ($timesettings{'VALID'} eq '') +{ + $timesettings{'ENABLENTP'} = 'off'; + $timesettings{'UPDATE_METHOD'} = 'manually'; + $timesettings{'UPDATE_VALUE'} = '1'; + $timesettings{'UPDATE_PERIOD'} = 'daily'; + $timesettings{'NTP_ADDR_1'} = 'de.pool.ntp.org'; + $timesettings{'NTP_ADDR_2'} = 'pool.ntp.org'; +} + +unless ($errormessage) { + $timesettings{'SETMONTH'} = `date +'%m %e %Y %H %M'|cut -c 1-2`; + $timesettings{'SETDAY'} = `date +'%m %e %Y %H %M'|cut -c 4-5`; + $timesettings{'SETYEAR'} = `date +'%m %e %Y %H %M'|cut -c 7-10`; + $timesettings{'SETHOUR'} = `date +'%m %e %Y %H %M'|cut -c 12-13`; + $timesettings{'SETMINUTES'} = `date +'%m %e %Y %H %M'|cut -c 15-16`; + $_=$timesettings{'SETDAY'}; + $timesettings{'SETDAY'}=~ tr/ /0/; +} + +my %selected=(); +my %checked=(); + +$checked{'ENABLENTP'}{'off'} = ''; +$checked{'ENABLENTP'}{'on'} = ''; +$checked{'ENABLENTP'}{$timesettings{'ENABLENTP'}} = "checked='checked'"; + +$checked{'ENABLECLNTP'}{'off'} = ''; +$checked{'ENABLECLNTP'}{'on'} = ''; +$checked{'ENABLECLNTP'}{$timesettings{'ENABLECLNTP'}} = "checked='checked'"; + +$checked{'UPDATE_METHOD'}{'manually'} = ''; +$checked{'UPDATE_METHOD'}{'periodically'} = ''; +$checked{'UPDATE_METHOD'}{$timesettings{'UPDATE_METHOD'}} = "checked='checked'"; + +$selected{'UPDATE_PERIOD'}{'hourly'} = ''; +$selected{'UPDATE_PERIOD'}{'daily'} = ''; +$selected{'UPDATE_PERIOD'}{'weekly'} = ''; +$selected{'UPDATE_PERIOD'}{'monthly'} = ''; +$selected{'UPDATE_PERIOD'}{$timesettings{'UPDATE_PERIOD'}} = "selected='selected'"; + +# added to v0.0.4 to refresh screen if syncro event queued +my $refresh = ''; +if ( -e "/var/lock/time/settimenow") { + $refresh = ""; +} + +&Header::openpage($Lang::tr{'ntp configuration'}, 1, $refresh); + +&Header::openbigbox('100%', 'left', '', $errormessage); + +# DPC move error message to top so it is seen! +if ($errormessage) { + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "$errormessage \n"; + &Header::closebox(); + } + +print "
\n"; + +&Header::openbox('100%', 'left', $Lang::tr{'network time'}); +print < + + + $Lang::tr{'network time from'} + + +   + +END +; + +if ( -e "/var/lock/time/lastset") +{ + print "$Lang::tr{'clock last synchronized at'}\n"; + open(FILE, "; + close FILE; + print $output; +} +else +{ + print "$Lang::tr{'clock has not been synchronized'}\n"; +} + +print < + +   + $Lang::tr{'primary ntp server'}: + + $Lang::tr{'secondary ntp server'}:  * + + + +   + $Lang::tr{'clenabled'} + + + + + + + + + + + + + + + + + + + + +END +; + +if ( -e "/var/lock/time/settimenow") { + print "\n\n"; + print "\n"; +} +print < +
+
+

$Lang::tr{'update time'}
 $Lang::tr{'set time now help'}
$Lang::tr{'every'}: +  
$Lang::tr{'manually'}
$Lang::tr{'waiting to synchronize clock'}...
+ + + + + + +
* $Lang::tr{'this field may be blank'} 
+END +; + +&Header::closebox(); + +print "\n"; + +&Header::closebigbox(); + +&Header::closepage(); +