Merge branch 'next' of ssh://arne_f@git.ipfire.org/pub/git/ipfire-2.x into next
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / outgoinggrp.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2010 IPFire Team #
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 ###############################################################################
21
22 use strict;
23 # enable only the following on debugging purpose
24 #use warnings;
25 #use CGI::Carp 'fatalsToBrowser';
26
27 require '/var/ipfire/general-functions.pl';
28 require "${General::swroot}/lang.pl";
29 require "${General::swroot}/header.pl";
30
31 my %outgrpsettings = ();
32 my %netsettings = ();
33 my %selected= () ;
34 my $errormessage = "";
35
36 my $configpath = "/var/ipfire/outgoing/groups/";
37 my $servicefile = "/var/ipfire/outgoing/defaultservices";
38
39 my %color = ();
40 my %mainsettings = ();
41 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
42 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
43
44 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
45
46 &Header::showhttpheaders();
47
48 ### Values that have to be initialized
49 $outgrpsettings{'ACTION'} = '';
50 $outgrpsettings{'ipgroup'} = 'none';
51 $outgrpsettings{'macgroup'} = 'none';
52
53 &Header::getcgihash(\%outgrpsettings);
54 delete $outgrpsettings{'__CGI__'};delete $outgrpsettings{'x'};delete $outgrpsettings{'y'};
55
56 $selected{'ipgroup'}{$outgrpsettings{'ipgroup'}} = "selected='selected'";
57 $selected{'macgroup'}{$outgrpsettings{'macgroup'}} = "selected='selected'";
58
59 &Header::openpage($Lang::tr{'outgoing firewall groups'}, 1, '');
60 &Header::openbigbox('100%', 'left', '', $errormessage);
61
62 ###############
63 # DEBUG DEBUG
64 # &Header::openbox('100%', 'left', 'DEBUG');
65 # my $debugCount = 0;
66 # foreach my $line (sort keys %outgrpsettings) {
67 # print "$line = $outgrpsettings{$line}<br />\n";
68 # $debugCount++;
69 # }
70 # print "&nbsp;Count: $debugCount\n";
71 # &Header::closebox();
72 # DEBUG DEBUG
73 ###############
74
75 ############################################################################################################################
76 ############################################################################################################################
77
78 if ($outgrpsettings{'ACTION'} eq 'newipgroup')
79 {
80 &newipgroup();
81 } elsif ($outgrpsettings{'ACTION'} eq 'deleteipgroup' ) {
82 unlink("$configpath/ipgroups/$outgrpsettings{'ipgroup'}");
83 } elsif ($outgrpsettings{'ACTION'} eq 'addipgroup') {
84
85 if ( -e "$configpath/macgroups/$outgrpsettings{'ipgroup'}" ){
86 $errormessage = "$Lang::tr{'outgoing firewall group error'}";
87 } elsif ( $outgrpsettings{'ipgroup'} eq "all" || $outgrpsettings{'ipgroup'} eq "red" || $outgrpsettings{'ipgroup'} eq "blue" ||
88 $outgrpsettings{'ipgroup'} eq "green" || $outgrpsettings{'ipgroup'} eq "orange" || $outgrpsettings{'ipgroup'} eq "ip" ||
89 $outgrpsettings{'ipgroup'} eq "mac" || $outgrpsettings{'ipgroup'} eq "ovpn" || $outgrpsettings{'ipgroup'} eq "ipsec" ) {
90 $errormessage = "$Lang::tr{'outgoing firewall reserved groupname'}";
91 } else {
92 open (FILE, ">$configpath/ipgroups/$outgrpsettings{'ipgroup'}") or die "Can't save $outgrpsettings{'ipgroup'} settings $!";
93 flock (FILE, 2);
94 print FILE $outgrpsettings{'ipgroupcontent'}."\n";
95 close FILE;
96 }
97 }
98
99 if ($outgrpsettings{'ACTION'} eq 'newmacgroup')
100 {
101 &newmacgroup();
102 } elsif ($outgrpsettings{'ACTION'} eq 'deletemacgroup' ) {
103 unlink("$configpath/macgroups/$outgrpsettings{'macgroup'}");
104 } elsif ($outgrpsettings{'ACTION'} eq 'addmacgroup') {
105
106 if ( -e "$configpath/ipgroups/$outgrpsettings{'macgroup'}" ){
107 $errormessage = "$Lang::tr{'outgoing firewall group error'}";
108 } elsif ( $outgrpsettings{'macgroup'} eq "all" || $outgrpsettings{'macgroup'} eq "red" || $outgrpsettings{'macgroup'} eq "blue" ||
109 $outgrpsettings{'macgroup'} eq "green" || $outgrpsettings{'macgroup'} eq "orange" || $outgrpsettings{'macgroup'} eq "ip" ||
110 $outgrpsettings{'macgroup'} eq "mac" || $outgrpsettings{'macgroup'} eq "ovpn" || $outgrpsettings{'macgroup'} eq "ipsec" ) {
111 $errormessage = "$Lang::tr{'outgoing firewall reserved groupname'}";
112 } else {
113 open (FILE, ">$configpath/macgroups/$outgrpsettings{'macgroup'}") or die "Can't save $outgrpsettings{'macgroup'} settings $!";
114 flock (FILE, 2);
115 print FILE $outgrpsettings{'macgroupcontent'}."\n";
116 close FILE;
117 }
118 }
119
120 if ($errormessage)
121 {
122 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
123 print "<class name='base'><font color=red>$errormessage\n</font>";
124 print "&nbsp;</class>\n";
125 &Header::closebox();
126 }
127
128 ############################################################################################################################
129 ############################################################################################################################
130
131 my @ipgroups = qx(ls $configpath/ipgroups/);
132 if ($outgrpsettings{'ipgroup'} eq "none" and $#ipgroups >= 0 ){ $outgrpsettings{'ipgroup'} = $ipgroups[0];}
133
134 my $ipgroupcontent = `cat $configpath/ipgroups/$outgrpsettings{'ipgroup'} 2>/dev/null`;
135 $ipgroupcontent =~ s/\n/<br \/>/g;
136
137 &Header::openbox('100%', 'center', $Lang::tr{'outgoing firewall ip groups'});
138
139 print <<END
140 <a name="outgoing showipgroup"></a>
141 <br />
142 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
143 <table width='95%' cellspacing='0'>
144 <tr>
145 <td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'outgoing firewall ip groups'}</b></td>
146 </tr>
147 <tr>
148 <td colspan='3' align='left'><br /></td>
149 </tr>
150 <tr>
151 <td align='left' colspan='2'><select name='ipgroup' style="width: 200px">
152 END
153 ;
154 foreach my $member (@ipgroups) {chomp $member;print" <option value='$member' $selected{'ipgroup'}{$member}>$member</option>\n";}
155 print <<END
156 </select></td>
157 <td align='left'>
158 <input type='hidden' name='ACTION' value='showipgroup' />
159 <input type='image' alt='$Lang::tr{'outgoing firewall view group'}' title='$Lang::tr{'outgoing firewall view group'}' src='/images/format-justify-fill.png' />
160 </td>
161 </tr>
162 <tr>
163 <td colspan='3' align='left'><br /></td>
164 </tr>
165 <tr>
166 <td colspan='3' align='left'><font size=1>$ipgroupcontent</font></td>
167 </tr>
168 <tr>
169 <td colspan='3' align='left'><br /></td>
170 </tr>
171 <tr>
172 <td colspan='3' align='center'><font size=1>$Lang::tr{'outgoing firewall ip groups'} - $outgrpsettings{'ipgroup'}</font></td>
173 </tr>
174 </table>
175 </form>
176 <table width='10%' cellspacing='0'>
177 <tr>
178 <td align='center'>
179 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
180 <input type='hidden' name='ACTION' value='newipgroup' />
181 <input type='image' alt='$Lang::tr{'new'}' title='$Lang::tr{'new'}' src='/images/list-add.png' />
182 </form>
183 </td>
184 <td align='center'>
185 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
186 <input type='hidden' name='ACTION' value='saveipgroup' />
187 <input type='hidden' name='ipgroup' value='$outgrpsettings{'ipgroup'}' />
188 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' />
189 </form>
190 </td>
191 <td align='center'>
192 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
193 <input type='hidden' name='ACTION' value='deleteipgroup' />
194 <input type='hidden' name='ipgroup' value='$outgrpsettings{'ipgroup'}' />
195 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
196 </form>
197 </td>
198 </tr>
199 </table>
200
201 END
202 ;
203 &Header::closebox();
204
205 ############################################################################################################################
206 ############################################################################################################################
207
208 my @macgroups = qx(ls $configpath/macgroups/);
209 if ($outgrpsettings{'macgroup'} eq "none" and $#macgroups >= 0 ){ $outgrpsettings{'macgroup'} = $macgroups[0];}
210
211 my $macgroupcontent = `cat $configpath/macgroups/$outgrpsettings{'macgroup'} 2>/dev/null`;
212 $macgroupcontent =~ s/\n/<br \/>/g;
213
214 &Header::openbox('100%', 'center', $Lang::tr{'outgoing firewall mac groups'});
215
216 print <<END
217 <a name="outgoing showmacgroup"></a>
218 <br />
219 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showmacgroup'>
220 <table width='95%' cellspacing='0'>
221 <tr>
222 <td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'outgoing firewall mac groups'}</b></td>
223 </tr>
224 <tr>
225 <td colspan='3' align='left'><br /></td>
226 </tr>
227 <tr>
228 <td align='left' colspan='2'><select name='macgroup' style="width: 200px">
229 END
230 ;
231 foreach my $member (@macgroups) {chomp $member;print" <option value='$member' $selected{'macgroup'}{$member}>$member</option>\n";}
232 print <<END
233 </select></td>
234 <td align='left'>
235 <input type='hidden' name='ACTION' value='showmacgroup' />
236 <input type='image' alt='$Lang::tr{'outgoing firewall view group'}' title='$Lang::tr{'outgoing firewall view group'}' src='/images/format-justify-fill.png' />
237 </td>
238 </tr>
239 <tr>
240 <td colspan='3' align='left'><br /></td>
241 </tr>
242 <tr>
243 <td colspan='3' align='left'><font size=1>$macgroupcontent</font></td>
244 </tr>
245 <tr>
246 <td colspan='3' align='left'><br /></td>
247 </tr>
248 <tr>
249 <td colspan='3' align='center'><font size=1>$Lang::tr{'outgoing firewall mac groups'} - $outgrpsettings{'macgroup'}</font></td>
250 </tr>
251 </table>
252 </form>
253 <table width='10%' cellspacing='0'>
254 <tr>
255 <td align='center'>
256 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showmacgroup'>
257 <input type='hidden' name='ACTION' value='newmacgroup' />
258 <input type='image' alt='$Lang::tr{'new'}' title='$Lang::tr{'new'}' src='/images/list-add.png' />
259 </form>
260 </td>
261 <td align='center'>
262 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showmacgroup'>
263 <input type='hidden' name='ACTION' value='savemacgroup' />
264 <input type='hidden' name='macgroup' value='$outgrpsettings{'macgroup'}' />
265 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' />
266 </form>
267 </td>
268 <td align='center'>
269 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showmacgroup'>
270 <input type='hidden' name='ACTION' value='deletemacgroup' />
271 <input type='hidden' name='macgroup' value='$outgrpsettings{'macgroup'}' />
272 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
273 </form>
274 </td>
275 </tr>
276 </table>
277
278 END
279 ;
280 &Header::closebox();
281
282 &Header::closebigbox();
283 &Header::closepage();
284
285
286 ############################################################################################################################
287 ############################################################################################################################
288
289
290 sub newipgroup
291 {
292 &Header::openbox('100%', 'center', $Lang::tr{'outgoing firewall add ip group'});
293
294 print <<END
295 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
296 <table width='95%' cellspacing='0'>
297 <tr>
298 <td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'outgoing firewall add ip group'}</b></td>
299 </tr>
300 <tr>
301 <td colspan='3' align='left'><br /></td>
302 </tr>
303 <tr>
304 <td align='left' colspan='2'>
305 <input type='text' name='ipgroup' value='newgroup' size="30" />
306 </td>
307 <td align='left'>
308 <input type='hidden' name='ACTION' value='addipgroup' />
309 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' />
310 </td>
311 </tr>
312 <tr>
313 <td align='left' colspan='3'>
314 <textarea name="ipgroupcontent" cols="20" rows="5" Wrap="off">192.168.1.0/24\n192.168.3.0/255.255.255.0\n192.168.0.1\n192.168.0.2\n</textarea>
315 </td>
316 </tr>
317 </table>
318 </form>
319 END
320 ;
321 &Header::closebox();
322 &Header::closebigbox();
323 &Header::closepage();
324 exit 0;
325 }
326
327 sub newmacgroup
328 {
329 &Header::openbox('100%', 'center', $Lang::tr{'outgoing firewall add mac group'});
330
331 print <<END
332 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showmacgroup'>
333 <table width='95%' cellspacing='0'>
334 <tr>
335 <td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'outgoing firewall add mac group'}</b></td>
336 </tr>
337 <tr>
338 <td colspan='3' align='left'><br /></td>
339 </tr>
340 <tr>
341 <td align='left' colspan='2'>
342 <input type='text' name='macgroup' value='newgroup' size="30" />
343 </td>
344 <td align='left'>
345 <input type='hidden' name='ACTION' value='addmacgroup' />
346 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' />
347 </td>
348 </tr>
349 <tr>
350 <td align='left' colspan='3'>
351 <textarea name="macgroupcontent" cols="20" rows="5" Wrap="off">00:24:F6:04:5F:2b\n14:26:36:5A:5F:2B\n</textarea>
352 </td>
353 </tr>
354 </table>
355 </form>
356 END
357 ;
358 &Header::closebox();
359 &Header::closebigbox();
360 &Header::closepage();
361 exit 0;
362 }