#!/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"; require '/var/ipfire/connscheduler/lib.pl'; my %color = (); my %mainsettings = (); &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); my $buttontext = $Lang::tr{'add'}; my $hiddenvalue = 'add'; my $day; my $hour; my $minute; my %temppppsettings=(); my @profilenames=(); # # defaults for settings # my $selected_hour = '00'; my $selected_minute = '00'; my $checked_connect = "checked='checked'"; my $checked_profile = ''; my %selected = (); $selected{'reconnect'} = ''; $selected{'dial'} = ''; $selected{'hangup'} = ''; $selected{'reboot'} = ''; $selected{'shutdown'} = ''; $selected{'ipsecstart'} = ''; $selected{'ipsecstop'} = ''; my $selected_profile = 1; my $checked_days = "checked='checked'"; my $selected_daystart = 1; my $selected_dayend = 31; my $checked_weekdays = ''; my $checked_mon = "checked='checked'"; my $checked_tue = "checked='checked'"; my $checked_wed = "checked='checked'"; my $checked_thu = "checked='checked'"; my $checked_fri = "checked='checked'"; my $checked_sat = "checked='checked'"; my $checked_sun = "checked='checked'"; my $comment = ''; my %cgiparams = (); $cgiparams{'ACTION'} = ''; # add/edit/update/remove/wakeup $cgiparams{'ACTION_ACTION'} = ''; # CONNECT/PROFILE $cgiparams{'ACTION_CONNECT'} = ''; # connect/disconnect/reconnect $cgiparams{'ACTION_PROFILENR'} = 0; $cgiparams{'ACTION_HOUR'} = ''; $cgiparams{'ACTION_MINUTE'} = ''; $cgiparams{'ACTION_DAYSTYPE'} = ''; $cgiparams{'ACTION_DAYSTART'} = 1; $cgiparams{'ACTION_DAYEND'} = 31; $cgiparams{'Mon'} = ''; $cgiparams{'Tue'} = ''; $cgiparams{'Wed'} = ''; $cgiparams{'Thu'} = ''; $cgiparams{'Fri'} = ''; $cgiparams{'Sat'} = ''; $cgiparams{'Sun'} = ''; $cgiparams{'ACTION_COMMENT'} = ''; &Header::getcgihash(\%cgiparams); # read the profile names my $i=0; for ($i = 1; $i <= $CONNSCHED::maxprofiles; $i++) { %temppppsettings = (); $temppppsettings{'PROFILENAME'} = $Lang::tr{'empty'}; &General::readhash("${General::swroot}/ppp/settings-$i", \%temppppsettings); $profilenames[$i] = $temppppsettings{'PROFILENAME'}; } &Header::showhttpheaders(); &Header::openpage($Lang::tr{'connscheduler'}, 1, ''); &Header::openbigbox('100%', 'left', '', ''); # Found this usefull piece of code in BlockOutTraffic AddOn 8-) # fwrules.cgi ############### # DEBUG DEBUG #&Header::openbox('100%', 'left', 'DEBUG'); #my $debugCount = 0; #foreach my $line (sort keys %cgiparams) { # print "$line = $cgiparams{$line}
\n"; # $debugCount++; #} #print " Count: $debugCount\n"; #&Header::closebox(); # DEBUG DEBUG ############### if ( $cgiparams{'ACTION'} eq 'toggle' ) { if ( $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} eq 'on' ) { $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} = 'off'; } else { $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} = 'on'; } &CONNSCHED::WriteConfig; } if ( ($cgiparams{'ACTION'} eq 'add') || ($cgiparams{'ACTION'} eq 'update') ) { my $l_action = $cgiparams{'ACTION_CONNECT'}; my $l_profilenr = ''; my $l_days = ''; my $l_weekdays = ''; if ( $cgiparams{'ACTION'} eq 'add' ) { $i = $#CONNSCHED::config + 1; $CONNSCHED::config[$i]{'ACTIVE'} = 'on'; } else { $i = $cgiparams{'UPDATE_ID'}; } if ( $cgiparams{'ACTION_ACTION'} eq 'PROFILE') { $l_action = 'select profile'; $l_profilenr = $cgiparams{'ACTION_PROFILENR'}; } if ( $cgiparams{'ACTION_DAYSTYPE'} eq 'WEEKDAYS' ) { if ( $cgiparams{'Mon'} eq 'on' ) { $l_weekdays .= 'Mon '; } if ( $cgiparams{'Tue'} eq 'on' ) { $l_weekdays .= 'Tue '; } if ( $cgiparams{'Wed'} eq 'on' ) { $l_weekdays .= 'Wed '; } if ( $cgiparams{'Thu'} eq 'on' ) { $l_weekdays .= 'Thu '; } if ( $cgiparams{'Fri'} eq 'on' ) { $l_weekdays .= 'Fri '; } if ( $cgiparams{'Sat'} eq 'on' ) { $l_weekdays .= 'Sat '; } if ( $cgiparams{'Sun'} eq 'on' ) { $l_weekdays .= 'Sun '; } } else { $l_days = "$cgiparams{'ACTION_DAYSTART'} - $cgiparams{'ACTION_DAYEND'}"; } $CONNSCHED::config[$i]{'ACTION'} = $l_action; $CONNSCHED::config[$i]{'PROFILENR'} = $l_profilenr; $CONNSCHED::config[$i]{'TIME'} = "$cgiparams{'ACTION_HOUR'}:$cgiparams{'ACTION_MINUTE'}"; $CONNSCHED::config[$i]{'DAYSTYPE'} = lc($cgiparams{'ACTION_DAYSTYPE'}); $CONNSCHED::config[$i]{'DAYS'} = $l_days; $CONNSCHED::config[$i]{'WEEKDAYS'} = $l_weekdays; $CONNSCHED::config[$i]{'COMMENT'} = &Header::cleanhtml($cgiparams{'ACTION_COMMENT'}); &CONNSCHED::WriteConfig; } if ( $cgiparams{'ACTION'} eq 'edit' ) { $i = $cgiparams{'ID'}; $selected_hour = substr($CONNSCHED::config[$i]{'TIME'},0,2); $selected_minute = substr($CONNSCHED::config[$i]{'TIME'},3,2); if ( $CONNSCHED::config[$i]{'ACTION'} eq 'select profile' ) { $checked_connect = ''; $checked_profile = "checked='checked'"; $selected_profile = $CONNSCHED::config[$i]{'PROFILENR'}; } else { $selected{"$CONNSCHED::config[$i]{'ACTION'}"} = "selected='selected'"; } if ( $CONNSCHED::config[$i]{'DAYSTYPE'} eq 'days' ) { my @temp = split(/-/,$CONNSCHED::config[$i]{'DAYS'},2); $selected_daystart = substr($temp[0], 0, -1); $selected_dayend = substr($temp[1], 1); } else { my $wd = $CONNSCHED::config[$i]{'WEEKDAYS'}; $checked_mon = '' if ( index($wd, 'Mon') == -1 ) ; $checked_tue = '' if ( index($wd, 'Tue') == -1 ) ; $checked_wed = '' if ( index($wd, 'Wed') == -1 ) ; $checked_thu = '' if ( index($wd, 'Thu') == -1 ) ; $checked_fri = '' if ( index($wd, 'Fri') == -1 ) ; $checked_sat = '' if ( index($wd, 'Sat') == -1 ) ; $checked_sun = '' if ( index($wd, 'Sun') == -1 ) ; $checked_days = ''; $checked_weekdays = "checked='checked'"; } $comment = $CONNSCHED::config[$cgiparams{'ID'}]{'COMMENT'}; $buttontext = $Lang::tr{'update'}; $hiddenvalue = 'update'; } if ( $cgiparams{'ACTION'} eq 'remove' ) { # simply set ACTIVE to empty, WriteConfig will handle the gory details $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} = ''; &CONNSCHED::WriteConfig; } if ( ($cgiparams{'ACTION'} eq 'down') || ($cgiparams{'ACTION'} eq 'up') ) { my $action = @CONNSCHED::config[$cgiparams{'ID'}]; my $newpos = 0; splice(@CONNSCHED::config, $cgiparams{'ID'}, 1); if ( ($cgiparams{'ACTION'} eq 'down') ) { $newpos = $cgiparams{'ID'} + 1; } else { $newpos = $cgiparams{'ID'} - 1; } splice(@CONNSCHED::config, $newpos, 0, $action); &CONNSCHED::WriteConfig; } # # Add / Edit Box # &Header::openbox('100%', 'left', $Lang::tr{'ConnSched add action'}); print <
$Lang::tr{'ConnSched time'}  : 


$Lang::tr{'ConnSched action'}  
   $Lang::tr{'ConnSched change profile title'} 


$Lang::tr{'ConnSched days'}   - 
  $Lang::tr{'ConnSched weekdays'}
  $Lang::tr{'monday'}
  $Lang::tr{'tuesday'}
  $Lang::tr{'wednesday'}
  $Lang::tr{'thursday'}
  $Lang::tr{'friday'}
  $Lang::tr{'saturday'}
  $Lang::tr{'sunday'}

$Lang::tr{'remark title'} *


* $Lang::tr{'this field may be blank'}
END ; &Header::closebox(); # # Box with List of events # &Header::openbox('100%', 'left', $Lang::tr{'ConnSched scheduled actions'}); print < $Lang::tr{'time'}   $Lang::tr{'remark'} $Lang::tr{'action'} END ; my $col=""; for my $id ( 0 .. $#CONNSCHED::config ) { if ( ($cgiparams{'ACTION'} eq 'edit') && ($id == $cgiparams{'ID'}) ) { print ""; $col="bgcolor='${Header::colouryellow}'"; } elsif ( $id % 2 ) { print ""; $col="bgcolor='$color{'color20'}'"; } else { print ""; $col="bgcolor='$color{'color22'}'"; } print <$CONNSCHED::config[$id]{'TIME'} $Lang::tr{"ConnSched $CONNSCHED::config[$id]{'ACTION'}"} $CONNSCHED::config[$id]{'PROFILENR'} $CONNSCHED::config[$id]{'COMMENT'}
  $CONNSCHED::config[$id]{'DAYS'}$CONNSCHED::config[$id]{'WEEKDAYS_PR'}  END ; } print <

END ; &Header::closebox(); &Header::closebigbox(); &Header::closepage();