]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/connscheduler.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";
32 require '/var/ipfire/connscheduler/lib.pl';
35 my %mainsettings = ();
36 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
37 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
39 my $buttontext = $Lang::tr
{'add'};
40 my $hiddenvalue = 'add';
44 my %temppppsettings=();
49 # defaults for settings
51 my $selected_hour = '00';
52 my $selected_minute = '00';
53 my $checked_connect = "checked='checked'";
54 my $checked_profile = '';
56 $selected{'reconnect'} = '';
57 $selected{'dial'} = '';
58 $selected{'hangup'} = '';
59 $selected{'reboot'} = '';
60 $selected{'shutdown'} = '';
61 $selected{'ipsecstart'} = '';
62 $selected{'ipsecstop'} = '';
63 my $selected_profile = 1;
64 my $checked_days = "checked='checked'";
65 my $selected_daystart = 1;
66 my $selected_dayend = 31;
67 my $checked_weekdays = '';
68 my $checked_mon = "checked='checked'";
69 my $checked_tue = "checked='checked'";
70 my $checked_wed = "checked='checked'";
71 my $checked_thu = "checked='checked'";
72 my $checked_fri = "checked='checked'";
73 my $checked_sat = "checked='checked'";
74 my $checked_sun = "checked='checked'";
79 $cgiparams{'ACTION'} = ''; # add/edit/update/remove/wakeup
80 $cgiparams{'ACTION_ACTION'} = ''; # CONNECT/PROFILE
81 $cgiparams{'ACTION_CONNECT'} = ''; # connect/disconnect/reconnect
82 $cgiparams{'ACTION_PROFILENR'} = 0;
83 $cgiparams{'ACTION_HOUR'} = '';
84 $cgiparams{'ACTION_MINUTE'} = '';
85 $cgiparams{'ACTION_DAYSTYPE'} = '';
86 $cgiparams{'ACTION_DAYSTART'} = 1;
87 $cgiparams{'ACTION_DAYEND'} = 31;
88 $cgiparams{'Mon'} = '';
89 $cgiparams{'Tue'} = '';
90 $cgiparams{'Wed'} = '';
91 $cgiparams{'Thu'} = '';
92 $cgiparams{'Fri'} = '';
93 $cgiparams{'Sat'} = '';
94 $cgiparams{'Sun'} = '';
95 $cgiparams{'ACTION_COMMENT'} = '';
97 &Header
::getcgihash
(\
%cgiparams);
100 # read the profile names
102 for ($i = 1; $i <= $CONNSCHED::maxprofiles
; $i++)
104 %temppppsettings = ();
105 $temppppsettings{'PROFILENAME'} = $Lang::tr
{'empty'};
106 &General
::readhash
("${General::swroot}/ppp/settings-$i", \
%temppppsettings);
107 $profilenames[$i] = $temppppsettings{'PROFILENAME'};
110 &Header
::showhttpheaders
();
111 &Header
::openpage
($Lang::tr
{'connscheduler'}, 1, '');
112 &Header
::openbigbox
('100%', 'left', '', '');
115 # Found this usefull piece of code in BlockOutTraffic AddOn 8-)
119 #&Header::openbox('100%', 'left', 'DEBUG');
121 #foreach my $line (sort keys %cgiparams) {
122 # print "$line = $cgiparams{$line}<br />\n";
125 #print " Count: $debugCount\n";
126 #&Header::closebox();
131 if ( $cgiparams{'ACTION'} eq 'toggle' )
133 if ( $CONNSCHED::config
[$cgiparams{'ID'}]{'ACTIVE'} eq 'on' )
135 $CONNSCHED::config
[$cgiparams{'ID'}]{'ACTIVE'} = 'off';
139 $CONNSCHED::config
[$cgiparams{'ID'}]{'ACTIVE'} = 'on';
142 &CONNSCHED
::WriteConfig
;
145 if ( ($cgiparams{'ACTION'} eq 'add') || ($cgiparams{'ACTION'} eq 'update') )
147 my $l_action = $cgiparams{'ACTION_CONNECT'};
148 my $l_profilenr = '';
152 if ( $cgiparams{'ACTION'} eq 'add' )
154 $i = $#CONNSCHED::config
+ 1;
155 $CONNSCHED::config
[$i]{'ACTIVE'} = 'on';
159 $i = $cgiparams{'UPDATE_ID'};
162 if ( $cgiparams{'ACTION_ACTION'} eq 'PROFILE')
164 $l_action = 'select profile';
165 $l_profilenr = $cgiparams{'ACTION_PROFILENR'};
168 if ( $cgiparams{'ACTION_DAYSTYPE'} eq 'WEEKDAYS' )
170 if ( $cgiparams{'Mon'} eq 'on' ) { $l_weekdays .= 'Mon '; }
171 if ( $cgiparams{'Tue'} eq 'on' ) { $l_weekdays .= 'Tue '; }
172 if ( $cgiparams{'Wed'} eq 'on' ) { $l_weekdays .= 'Wed '; }
173 if ( $cgiparams{'Thu'} eq 'on' ) { $l_weekdays .= 'Thu '; }
174 if ( $cgiparams{'Fri'} eq 'on' ) { $l_weekdays .= 'Fri '; }
175 if ( $cgiparams{'Sat'} eq 'on' ) { $l_weekdays .= 'Sat '; }
176 if ( $cgiparams{'Sun'} eq 'on' ) { $l_weekdays .= 'Sun '; }
180 $l_days = "$cgiparams{'ACTION_DAYSTART'} - $cgiparams{'ACTION_DAYEND'}";
183 $CONNSCHED::config
[$i]{'ACTION'} = $l_action;
184 $CONNSCHED::config
[$i]{'PROFILENR'} = $l_profilenr;
185 $CONNSCHED::config
[$i]{'TIME'} = "$cgiparams{'ACTION_HOUR'}:$cgiparams{'ACTION_MINUTE'}";
186 $CONNSCHED::config
[$i]{'DAYSTYPE'} = lc($cgiparams{'ACTION_DAYSTYPE'});
187 $CONNSCHED::config
[$i]{'DAYS'} = $l_days;
188 $CONNSCHED::config
[$i]{'WEEKDAYS'} = $l_weekdays;
189 $CONNSCHED::config
[$i]{'COMMENT'} = &Header
::cleanhtml
($cgiparams{'ACTION_COMMENT'});
191 &CONNSCHED
::WriteConfig
;
194 if ( $cgiparams{'ACTION'} eq 'edit' )
196 $i = $cgiparams{'ID'};
198 $selected_hour = substr($CONNSCHED::config
[$i]{'TIME'},0,2);
199 $selected_minute = substr($CONNSCHED::config
[$i]{'TIME'},3,2);
201 if ( $CONNSCHED::config
[$i]{'ACTION'} eq 'select profile' )
203 $checked_connect = '';
204 $checked_profile = "checked='checked'";
205 $selected_profile = $CONNSCHED::config
[$i]{'PROFILENR'};
209 $selected{"$CONNSCHED::config[$i]{'ACTION'}"} = "selected='selected'";
212 if ( $CONNSCHED::config
[$i]{'DAYSTYPE'} eq 'days' )
214 my @temp = split(/-/,$CONNSCHED::config
[$i]{'DAYS'},2);
216 $selected_daystart = substr($temp[0], 0, -1);
217 $selected_dayend = substr($temp[1], 1);
221 my $wd = $CONNSCHED::config
[$i]{'WEEKDAYS'};
222 $checked_mon = '' if ( index($wd, 'Mon') == -1 ) ;
223 $checked_tue = '' if ( index($wd, 'Tue') == -1 ) ;
224 $checked_wed = '' if ( index($wd, 'Wed') == -1 ) ;
225 $checked_thu = '' if ( index($wd, 'Thu') == -1 ) ;
226 $checked_fri = '' if ( index($wd, 'Fri') == -1 ) ;
227 $checked_sat = '' if ( index($wd, 'Sat') == -1 ) ;
228 $checked_sun = '' if ( index($wd, 'Sun') == -1 ) ;
231 $checked_weekdays = "checked='checked'";
234 $comment = $CONNSCHED::config
[$cgiparams{'ID'}]{'COMMENT'};
236 $buttontext = $Lang::tr
{'update'};
237 $hiddenvalue = 'update';
240 if ( $cgiparams{'ACTION'} eq 'remove' )
242 # simply set ACTIVE to empty, WriteConfig will handle the gory details
243 $CONNSCHED::config
[$cgiparams{'ID'}]{'ACTIVE'} = '';
244 &CONNSCHED
::WriteConfig
;
246 if ( ($cgiparams{'ACTION'} eq 'down') || ($cgiparams{'ACTION'} eq 'up') )
248 my $action = @CONNSCHED::config
[$cgiparams{'ID'}];
251 splice(@CONNSCHED::config
, $cgiparams{'ID'}, 1);
253 if ( ($cgiparams{'ACTION'} eq 'down') )
255 $newpos = $cgiparams{'ID'} + 1;
259 $newpos = $cgiparams{'ID'} - 1;
262 splice(@CONNSCHED::config
, $newpos, 0, $action);
264 &CONNSCHED
::WriteConfig
;
272 &Header
::openbox
('100%', 'left', $Lang::tr
{'ConnSched add action'});
275 <form method='post' name='addevent' action='$ENV{'SCRIPT_NAME'}'>
276 <table width='100%' border='0' cellspacing='6' cellpadding='0'>
278 <td width='15%' class='base'>$Lang::tr{'ConnSched time'}</td>
279 <td><select name='ACTION_HOUR'>
282 for ($hour = 0; $hour <= 23; $hour++)
284 my $hour00 = $hour < 10 ?
"0$hour" : $hour;
285 if ( $hour00 eq $selected_hour )
287 print "<option value='$hour00' selected='selected'>$hour00</option>";
291 print "<option value='$hour00'>$hour00</option>";
294 print "</select> : <select name='ACTION_MINUTE'>";
295 for ($minute = 0; $minute <= 55; $minute += 5)
297 my $minute00 = $minute < 10 ?
"0$minute" : $minute;
298 if ( $minute00 eq $selected_minute )
300 print "<option value='$minute00' selected='selected'>$minute00</option>";
304 print "<option value='$minute00'>$minute00</option>";
310 <tr><td colspan='2'><br><br></td></tr>
311 <tr><td width='15%' class='base'>$Lang::tr{'ConnSched action'}</td><td>
312 <input type='radio' value='CONNECT' name='ACTION_ACTION' $checked_connect /> <select name='ACTION_CONNECT'>
313 <option value='reconnect' $selected{'reconnect'}>$Lang::tr{'ConnSched reconnect'}</option>
314 <option value='dial' $selected{'dial'}>$Lang::tr{'ConnSched dial'}</option>
315 <option value='hangup' $selected{'hangup'}>$Lang::tr{'ConnSched hangup'}</option>
316 <option value='reboot' $selected{'reboot'}>$Lang::tr{'ConnSched reboot'}</option>
317 <option value='shutdown' $selected{'shutdown'}>$Lang::tr{'ConnSched shutdown'}</option>
318 <option value='ipsecstart' $selected{'ipsecstart'}>$Lang::tr{'ConnSched ipsecstart'}</option>
319 <option value='ipsecstop' $selected{'ipsecstop'}>$Lang::tr{'ConnSched ipsecstop'}</option>
321 <tr><td width='15%' class='base'> </td>
322 <td><input type='radio' value='PROFILE' name='ACTION_ACTION' $checked_profile /> $Lang::tr{'ConnSched change profile title'} <select name='ACTION_PROFILENR'>
325 for ($i = 1; $i <= $CONNSCHED::maxprofiles
; $i++)
327 if ( $i == $selected_profile )
329 print "<option value='$i' selected='selected'>$i. $profilenames[$i]</option>";
333 print "<option value='$i'>$i. $profilenames[$i]</option>";
338 <tr><td colspan='2'><br><br></td></tr>
339 <tr><td width='15%' class='base'>$Lang::tr{'ConnSched days'}</td>
340 <td><input type='radio' value='DAYS' name='ACTION_DAYSTYPE' $checked_days /> <select name='ACTION_DAYSTART'>
343 for ($day = 1; $day <= 31; $day++)
345 if ( $day == $selected_daystart )
347 print "<option value='$day' selected='selected'>$day</option>";
351 print "<option value='$day'>$day</option>";
354 print "</select> - <select name='ACTION_DAYEND'>";
355 for ($day = 1; $day <= 31; $day++)
357 if ( $day == $selected_dayend )
359 print "<option value='$day' selected='selected'>$day</option>";
363 print "<option value='$day'>$day</option>";
369 <tr><td width='15%' class='base'> </td><td><input type='radio' value='WEEKDAYS' name='ACTION_DAYSTYPE' $checked_weekdays /> $Lang::tr{'ConnSched weekdays'}<br />
370 <input type='checkbox' name='Mon' $checked_mon />$Lang::tr{'monday'}<br />
371 <input type='checkbox' name='Tue' $checked_tue />$Lang::tr{'tuesday'}<br />
372 <input type='checkbox' name='Wed' $checked_wed />$Lang::tr{'wednesday'}<br />
373 <input type='checkbox' name='Thu' $checked_thu />$Lang::tr{'thursday'}<br />
374 <input type='checkbox' name='Fri' $checked_fri />$Lang::tr{'friday'}<br />
375 <input type='checkbox' name='Sat' $checked_sat />$Lang::tr{'saturday'}<br />
376 <input type='checkbox' name='Sun' $checked_sun />$Lang::tr{'sunday'}
378 <tr><td colspan='2'><br></td></tr>
379 <tr><td width='15%' class='base'>$Lang::tr{'remark title'} <img src='/blob.gif' alt='*' /></td>
380 <td><input type='text' name='ACTION_COMMENT' size='40' value='$comment' /></td></tr></table>
383 <table width='100%'><tr>
384 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
385 <td width='55%' class='base'>$Lang::tr{'this field may be blank'}</td>
386 <td width='40%' align='right'><input type='submit' name='SUBMIT' value='$buttontext' />
387 <input type='hidden' name='ACTION' value='$hiddenvalue' /></td>
388 <input type='hidden' name='UPDATE_ID' value='$cgiparams{'ID'}' /></td>
398 # Box with List of events
401 &Header
::openbox
('100%', 'left', $Lang::tr
{'ConnSched scheduled actions'});
403 <table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
405 <th align='center' width='10%'><b>$Lang::tr{'time'}</b></th>
406 <th width='15%'> </th>
407 <th align='center' width='60%'><b>$Lang::tr{'remark'}</b></th>
408 <th align='center' colspan='5' width='5%'><b>$Lang::tr{'action'}</b></th>
413 for my $id ( 0 .. $#CONNSCHED::config
)
415 if ( ($cgiparams{'ACTION'} eq 'edit') && ($id == $cgiparams{'ID'}) )
418 $col="bgcolor='${Header::colouryellow}'";
423 $col="bgcolor='$color{'color20'}'";
428 $col="bgcolor='$color{'color22'}'";
432 <td align='center' $col>$CONNSCHED::config[$id]{'TIME'}</td>
433 <td $col>$Lang::tr{"ConnSched $CONNSCHED::config[$id]{'ACTION'}"} $CONNSCHED::config[$id]{'PROFILENR'}</td>
434 <td $col>$CONNSCHED::config[$id]{'COMMENT'}</td>
435 <td align='center' $col>
436 <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
437 <input type='hidden' name='ACTION' value='toggle' />
438 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$CONNSCHED::config[$id]{'ACTIVE'}.gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' />
439 <input type='hidden' name='ID' value='$id' />
442 <td align='center' $col>
443 <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
444 <input type='hidden' name='ACTION' value='edit' />
445 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
446 <input type='hidden' name='ID' value='$id' />
449 <td align='center' $col>
450 <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
451 <input type='hidden' name='ACTION' value='remove' />
452 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
453 <input type='hidden' name='ID' value='$id' />
456 <td align='center' $col>
457 <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
458 <input type='hidden' name='ACTION' value='up' />
459 <input type='image' name='$Lang::tr{'ConnSched up'}' src='/images/up.gif' alt='$Lang::tr{'ConnSched up'}' title='$Lang::tr{'ConnSched up'}' />
460 <input type='hidden' name='ID' value='$id' />
463 <td align='center' $col>
464 <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
465 <input type='hidden' name='ACTION' value='down' />
466 <input type='image' name='$Lang::tr{'ConnSched down'}' src='/images/down.gif' alt='$Lang::tr{'ConnSched down'}' title='$Lang::tr{'ConnSched down'}' />
467 <input type='hidden' name='ID' value='$id' />
473 <td colspan='7' $col>$CONNSCHED::config[$id]{'DAYS'}$CONNSCHED::config[$id]{'WEEKDAYS_PR'} </td>
489 &Header
::closebigbox
();
490 &Header
::closepage
();