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