]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/connscheduler.cgi
bind: Update to 9.11.4
[ipfire-2.x.git] / html / cgi-bin / connscheduler.cgi
CommitLineData
4e565351 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
4e565351
MT
21
22use strict;
23
24# enable only the following on debugging purpose
cb5e9c6c
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
4e565351
MT
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
31
0937506a 32require '/var/ipfire/connscheduler/lib.pl';
4e565351 33
f2fdd0c1
CS
34my %color = ();
35my %mainsettings = ();
36&General::readhash("${General::swroot}/main/settings", \%mainsettings);
37&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
38
4e565351
MT
39my $buttontext = $Lang::tr{'add'};
40my $hiddenvalue = 'add';
41my $day;
42my $hour;
43my $minute;
44my %temppppsettings=();
45my @profilenames=();
46
47
48#
49# defaults for settings
50#
51my $selected_hour = '00';
52my $selected_minute = '00';
53my $checked_connect = "checked='checked'";
54my $checked_profile = '';
55my %selected = ();
56$selected{'reconnect'} = '';
57$selected{'dial'} = '';
58$selected{'hangup'} = '';
59$selected{'reboot'} = '';
60$selected{'shutdown'} = '';
957fb958
MT
61$selected{'ipsecstart'} = '';
62$selected{'ipsecstop'} = '';
4e565351
MT
63my $selected_profile = 1;
64my $checked_days = "checked='checked'";
65my $selected_daystart = 1;
66my $selected_dayend = 31;
67my $checked_weekdays = '';
68my $checked_mon = "checked='checked'";
69my $checked_tue = "checked='checked'";
70my $checked_wed = "checked='checked'";
71my $checked_thu = "checked='checked'";
72my $checked_fri = "checked='checked'";
73my $checked_sat = "checked='checked'";
74my $checked_sun = "checked='checked'";
75my $comment = '';
76
77my %cgiparams = ();
78
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'} = '';
96
97&Header::getcgihash(\%cgiparams);
98
99
100# read the profile names
101my $i=0;
102for ($i = 1; $i <= $CONNSCHED::maxprofiles; $i++)
103{
104 %temppppsettings = ();
105 $temppppsettings{'PROFILENAME'} = $Lang::tr{'empty'};
106 &General::readhash("${General::swroot}/ppp/settings-$i", \%temppppsettings);
107 $profilenames[$i] = $temppppsettings{'PROFILENAME'};
108}
109
110&Header::showhttpheaders();
111&Header::openpage($Lang::tr{'connscheduler'}, 1, '');
112&Header::openbigbox('100%', 'left', '', '');
113
114
115# Found this usefull piece of code in BlockOutTraffic AddOn 8-)
116# fwrules.cgi
117###############
118# DEBUG DEBUG
119#&Header::openbox('100%', 'left', 'DEBUG');
120#my $debugCount = 0;
121#foreach my $line (sort keys %cgiparams) {
122# print "$line = $cgiparams{$line}<br />\n";
123# $debugCount++;
124#}
125#print "&nbsp;Count: $debugCount\n";
126#&Header::closebox();
127# DEBUG DEBUG
128###############
129
130
131if ( $cgiparams{'ACTION'} eq 'toggle' )
132{
133 if ( $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} eq 'on' )
134 {
135 $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} = 'off';
136 }
137 else
138 {
139 $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} = 'on';
140 }
141
142 &CONNSCHED::WriteConfig;
143}
144
145if ( ($cgiparams{'ACTION'} eq 'add') || ($cgiparams{'ACTION'} eq 'update') )
146{
147 my $l_action = $cgiparams{'ACTION_CONNECT'};
148 my $l_profilenr = '';
149 my $l_days = '';
150 my $l_weekdays = '';
151
152 if ( $cgiparams{'ACTION'} eq 'add' )
153 {
154 $i = $#CONNSCHED::config + 1;
155 $CONNSCHED::config[$i]{'ACTIVE'} = 'on';
156 }
157 else
158 {
159 $i = $cgiparams{'UPDATE_ID'};
160 }
161
162 if ( $cgiparams{'ACTION_ACTION'} eq 'PROFILE')
163 {
164 $l_action = 'select profile';
165 $l_profilenr = $cgiparams{'ACTION_PROFILENR'};
166 }
167
168 if ( $cgiparams{'ACTION_DAYSTYPE'} eq 'WEEKDAYS' )
169 {
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 '; }
177 }
178 else
179 {
180 $l_days = "$cgiparams{'ACTION_DAYSTART'} - $cgiparams{'ACTION_DAYEND'}";
181 }
182
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'});
190
191 &CONNSCHED::WriteConfig;
192}
193
194if ( $cgiparams{'ACTION'} eq 'edit' )
195{
196 $i = $cgiparams{'ID'};
197
198 $selected_hour = substr($CONNSCHED::config[$i]{'TIME'},0,2);
199 $selected_minute = substr($CONNSCHED::config[$i]{'TIME'},3,2);
200
201 if ( $CONNSCHED::config[$i]{'ACTION'} eq 'select profile' )
202 {
203 $checked_connect = '';
204 $checked_profile = "checked='checked'";
205 $selected_profile = $CONNSCHED::config[$i]{'PROFILENR'};
206 }
207 else
208 {
209 $selected{"$CONNSCHED::config[$i]{'ACTION'}"} = "selected='selected'";
210 }
211
212 if ( $CONNSCHED::config[$i]{'DAYSTYPE'} eq 'days' )
213 {
214 my @temp = split(/-/,$CONNSCHED::config[$i]{'DAYS'},2);
215
216 $selected_daystart = substr($temp[0], 0, -1);
217 $selected_dayend = substr($temp[1], 1);
218 }
219 else
220 {
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 ) ;
229
230 $checked_days = '';
231 $checked_weekdays = "checked='checked'";
232 }
233
234 $comment = $CONNSCHED::config[$cgiparams{'ID'}]{'COMMENT'};
235
236 $buttontext = $Lang::tr{'update'};
237 $hiddenvalue = 'update';
238}
239
240if ( $cgiparams{'ACTION'} eq 'remove' )
241{
242 # simply set ACTIVE to empty, WriteConfig will handle the gory details
243 $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} = '';
244 &CONNSCHED::WriteConfig;
245}
246if ( ($cgiparams{'ACTION'} eq 'down') || ($cgiparams{'ACTION'} eq 'up') )
247{
248 my $action = @CONNSCHED::config[$cgiparams{'ID'}];
249 my $newpos = 0;
250
251 splice(@CONNSCHED::config, $cgiparams{'ID'}, 1);
252
253 if ( ($cgiparams{'ACTION'} eq 'down') )
254 {
255 $newpos = $cgiparams{'ID'} + 1;
256 }
257 else
258 {
259 $newpos = $cgiparams{'ID'} - 1;
260 }
261
262 splice(@CONNSCHED::config, $newpos, 0, $action);
263
264 &CONNSCHED::WriteConfig;
265}
266
267
268#
269# Add / Edit Box
270#
271
957fb958 272&Header::openbox('100%', 'left', $Lang::tr{'ConnSched add action'});
4e565351
MT
273
274print <<END
275<form method='post' name='addevent' action='$ENV{'SCRIPT_NAME'}'>
276<table width='100%' border='0' cellspacing='6' cellpadding='0'>
277<tr>
e3edceeb 278<td width='15%' class='base'>$Lang::tr{'ConnSched time'}&nbsp;<img src='/blob.gif' alt='*' /></td>
4e565351
MT
279<td><select name='ACTION_HOUR'>
280END
281;
282for ($hour = 0; $hour <= 23; $hour++)
283{
284 my $hour00 = $hour < 10 ? "0$hour" : $hour;
285 if ( $hour00 eq $selected_hour )
286 {
287 print "<option value='$hour00' selected='selected'>$hour00</option>";
288 }
289 else
290 {
291 print "<option value='$hour00'>$hour00</option>";
292 }
293}
294print "</select>&nbsp;:&nbsp;<select name='ACTION_MINUTE'>";
295for ($minute = 0; $minute <= 55; $minute += 5)
296{
297 my $minute00 = $minute < 10 ? "0$minute" : $minute;
298 if ( $minute00 eq $selected_minute )
299 {
300 print "<option value='$minute00' selected='selected'>$minute00</option>";
301 }
302 else
303 {
304 print "<option value='$minute00'>$minute00</option>";
305 }
306}
307
308print <<END
309</select></td></tr>
84394ec6 310<tr><td colspan='2'><br><br></td></tr>
e3edceeb 311<tr><td width='15%' class='base'>$Lang::tr{'ConnSched action'}&nbsp;<img src='/blob.gif' alt='*' /></td><td>
4e565351 312<input type='radio' value='CONNECT' name='ACTION_ACTION' $checked_connect />&nbsp;<select name='ACTION_CONNECT'>
957fb958 313<option value='reconnect' $selected{'reconnect'}>$Lang::tr{'ConnSched reconnect'}</option>
62ff8d96
MT
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>
957fb958
MT
318<option value='ipsecstart' $selected{'ipsecstart'}>$Lang::tr{'ConnSched ipsecstart'}</option>
319<option value='ipsecstop' $selected{'ipsecstop'}>$Lang::tr{'ConnSched ipsecstop'}</option>
4e565351
MT
320</select></td></tr>
321<tr><td width='15%' class='base'>&nbsp;</td>
957fb958 322<td><input type='radio' value='PROFILE' name='ACTION_ACTION' $checked_profile />&nbsp;$Lang::tr{'ConnSched change profile title'}&nbsp;<select name='ACTION_PROFILENR'>
4e565351
MT
323END
324;
325for ($i = 1; $i <= $CONNSCHED::maxprofiles; $i++)
326{
327 if ( $i == $selected_profile )
328 {
329 print "<option value='$i' selected='selected'>$i. $profilenames[$i]</option>";
330 }
331 else
332 {
333 print "<option value='$i'>$i. $profilenames[$i]</option>";
334 }
335}
336print <<END
337</select></td></tr>
84394ec6 338<tr><td colspan='2'><br><br></td></tr>
e3edceeb 339<tr><td width='15%' class='base'>$Lang::tr{'ConnSched days'}&nbsp;<img src='/blob.gif' alt='*' /></td>
4e565351
MT
340<td><input type='radio' value='DAYS' name='ACTION_DAYSTYPE' $checked_days />&nbsp;<select name='ACTION_DAYSTART'>
341END
342;
343for ($day = 1; $day <= 31; $day++)
344{
345 if ( $day == $selected_daystart )
346 {
347 print "<option value='$day' selected='selected'>$day</option>";
348 }
349 else
350 {
351 print "<option value='$day'>$day</option>";
352 }
353}
354print "</select>&nbsp;-&nbsp;<select name='ACTION_DAYEND'>";
355for ($day = 1; $day <= 31; $day++)
356{
357 if ( $day == $selected_dayend )
358 {
359 print "<option value='$day' selected='selected'>$day</option>";
360 }
361 else
362 {
363 print "<option value='$day'>$day</option>";
364 }
365}
366
367print <<END
368</select></td></tr>
957fb958 369<tr><td width='15%' class='base'>&nbsp;</td><td><input type='radio' value='WEEKDAYS' name='ACTION_DAYSTYPE' $checked_weekdays />&nbsp;$Lang::tr{'ConnSched weekdays'}<br />
4e565351
MT
370&nbsp;&nbsp;<input type='checkbox' name='Mon' $checked_mon />$Lang::tr{'monday'}<br />
371&nbsp;&nbsp;<input type='checkbox' name='Tue' $checked_tue />$Lang::tr{'tuesday'}<br />
372&nbsp;&nbsp;<input type='checkbox' name='Wed' $checked_wed />$Lang::tr{'wednesday'}<br />
373&nbsp;&nbsp;<input type='checkbox' name='Thu' $checked_thu />$Lang::tr{'thursday'}<br />
374&nbsp;&nbsp;<input type='checkbox' name='Fri' $checked_fri />$Lang::tr{'friday'}<br />
375&nbsp;&nbsp;<input type='checkbox' name='Sat' $checked_sat />$Lang::tr{'saturday'}<br />
376&nbsp;&nbsp;<input type='checkbox' name='Sun' $checked_sun />$Lang::tr{'sunday'}
377</td></tr>
84394ec6 378<tr><td colspan='2'><br></td></tr>
e3edceeb 379<tr><td width='15%' class='base'>$Lang::tr{'remark title'}</td>
4e565351 380<td><input type='text' name='ACTION_COMMENT' size='40' value='$comment' /></td></tr></table>
84394ec6
AM
381<br>
382<hr>
4e565351
MT
383<table width='100%'><tr>
384 <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
e3edceeb 385 <td width='55%' class='base'>$Lang::tr{'required field'}</td>
84394ec6 386 <td width='40%' align='right'><input type='submit' name='SUBMIT' value='$buttontext' />
4e565351
MT
387 <input type='hidden' name='ACTION' value='$hiddenvalue' /></td>
388 <input type='hidden' name='UPDATE_ID' value='$cgiparams{'ID'}' /></td>
389</tr></table>
390</form>
391
392END
393;
394
395&Header::closebox();
396
397#
398# Box with List of events
399#
400
957fb958 401&Header::openbox('100%', 'left', $Lang::tr{'ConnSched scheduled actions'});
4e565351 402print <<END
ce8c87bd 403<table width='100%' cellspacing='1' cellpadding='0' class='tbl'>
4e565351 404<tr>
ce8c87bd
AM
405<th align='center' width='10%'><b>$Lang::tr{'time'}</b></th>
406<th width='15%'>&nbsp;</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>
4e565351
MT
409</tr>
410END
411;
ce8c87bd 412my $col="";
4e565351
MT
413for my $id ( 0 .. $#CONNSCHED::config )
414{
4e565351
MT
415 if ( ($cgiparams{'ACTION'} eq 'edit') && ($id == $cgiparams{'ID'}) )
416 {
ce8c87bd
AM
417 print "<tr>";
418 $col="bgcolor='${Header::colouryellow}'";
4e565351
MT
419 }
420 elsif ( $id % 2 )
421 {
ce8c87bd
AM
422 print "<tr>";
423 $col="bgcolor='$color{'color20'}'";
4e565351
MT
424 }
425 else
426 {
ce8c87bd
AM
427 print "<tr>";
428 $col="bgcolor='$color{'color22'}'";
4e565351
MT
429 }
430
431print <<END
ce8c87bd
AM
432<td align='center' $col>$CONNSCHED::config[$id]{'TIME'}</td>
433<td $col>$Lang::tr{"ConnSched $CONNSCHED::config[$id]{'ACTION'}"}&nbsp;$CONNSCHED::config[$id]{'PROFILENR'}</td>
434<td $col>$CONNSCHED::config[$id]{'COMMENT'}</td>
435<td align='center' $col>
4e565351
MT
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' />
440 </form>
441</td>
ce8c87bd 442<td align='center' $col>
4e565351
MT
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' />
447 </form>
448</td>
ce8c87bd 449<td align='center' $col>
4e565351
MT
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' />
454 </form>
455</td>
ce8c87bd 456<td align='center' $col>
4e565351
MT
457 <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
458 <input type='hidden' name='ACTION' value='up' />
15f635cc 459 <input type='image' name='$Lang::tr{'ConnSched up'}' src='/images/up.gif' alt='$Lang::tr{'ConnSched up'}' title='$Lang::tr{'ConnSched up'}' />
4e565351
MT
460 <input type='hidden' name='ID' value='$id' />
461 </form>
462</td>
ce8c87bd 463<td align='center' $col>
4e565351
MT
464 <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
465 <input type='hidden' name='ACTION' value='down' />
15f635cc 466 <input type='image' name='$Lang::tr{'ConnSched down'}' src='/images/down.gif' alt='$Lang::tr{'ConnSched down'}' title='$Lang::tr{'ConnSched down'}' />
4e565351
MT
467 <input type='hidden' name='ID' value='$id' />
468 </form>
469</td>
470</tr>
ce8c87bd
AM
471<tr>
472<td $col>&nbsp;</td>
473<td colspan='7' $col>$CONNSCHED::config[$id]{'DAYS'}$CONNSCHED::config[$id]{'WEEKDAYS_PR'}&nbsp;</td>
4e565351
MT
474</tr>
475END
476;
477}
478
479print <<END
480</table>
481<br />
482<hr />
4e565351
MT
483END
484;
485
486
487&Header::closebox();
488
489&Header::closebigbox();
490&Header::closepage();