Did some final steps for the outgoing fw, this should be working now.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / outgoinggrp.cgi
CommitLineData
fdeaa057
CS
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2005-2010 IPTifre 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
22use strict;
23# enable only the following on debugging purpose
24#use warnings;
25#use CGI::Carp 'fatalsToBrowser';
26
27require '/var/ipfire/general-functions.pl';
28require "${General::swroot}/lang.pl";
29require "${General::swroot}/header.pl";
30
31my %outgrpsettings = ();
32my %netsettings = ();
33my %selected= () ;
34my $errormessage = "";
35
36my $configpath = "/var/ipfire/outgoing/groups/";
37my $servicefile = "/var/ipfire/outgoing/defaultservices";
38
39my %color = ();
40my %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{'portgroup'} = 'none';
52
53&Header::getcgihash(\%outgrpsettings);
54delete $outgrpsettings{'__CGI__'};delete $outgrpsettings{'x'};delete $outgrpsettings{'y'};
55
56$selected{'ipgroup'}{$outgrpsettings{'ipgroup'}} = "selected='selected'";
57$selected{'portgroup'}{$outgrpsettings{'portgroup'}} = "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
78if ($errormessage)
79{
80 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
81 print "<class name='base'>$errormessage\n";
82 print "&nbsp;</class>\n";
83 &Header::closebox();
84}
85
86if ($outgrpsettings{'ACTION'} eq 'newipgroup')
87{
88 &newipgroup();
89} elsif ($outgrpsettings{'ACTION'} eq 'deleteipgroup' ) {
90 unlink("$configpath/ipgroups/$outgrpsettings{'ipgroup'}");
91} elsif ($outgrpsettings{'ACTION'} eq 'addipgroup') {
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############################################################################################################################
100
101my @ipgroups = qx(ls $configpath/ipgroups/);
102if ($outgrpsettings{'ipgroup'} eq "none" and $#ipgroups >= 0 ){ $outgrpsettings{'ipgroup'} = $ipgroups[0];}
103
104my $ipgroupcontent = `cat $configpath/ipgroups/$outgrpsettings{'ipgroup'} 2>/dev/null`;
105$ipgroupcontent =~ s/\n/<br \/>/g;
106
107&Header::openbox('100%', 'center', $Lang::tr{'outgoing firewall ip groups'});
108
109print <<END
110<a name="outgoing showipgroup"</a>
111<br />
112<form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
113<table width='95%' cellspacing='0'>
114 <tr>
115 <td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'outgoing firewall ip groups'}</b></td>
116 </tr>
117 <tr>
118 <td colspan='3' align='left'><br /></td>
119 </tr>
120 <tr>
121 <td align='left' colspan='2'><select name='ipgroup' style="width: 200px">
122END
123;
124foreach my $member (@ipgroups) {chomp $member;print" <option value='$member' $selected{'ipgroup'}{$member}>$member</option>\n";}
125print <<END
126 </select></td>
127 <td align='left'>
128 <input type='hidden' name='ACTION' value='showipgroup' />
129 <input type='image' alt='$Lang::tr{'outgoing firewall view group'}' title='$Lang::tr{'outgoing firewall view group'}' src='/images/format-justify-fill.png' />
130 </td>
131 </tr>
132 <tr>
133 <td colspan='3' align='left'><br /></td>
134 </tr>
135 <tr>
136 <td colspan='3' align='left'><font size=1>$ipgroupcontent</font></td>
137 </tr>
138 <tr>
139 <td colspan='3' align='left'><br /></td>
140 </tr>
141 <tr>
142 <td colspan='3' align='center'><font size=1>$Lang::tr{'outgoing firewall ip groups'} - $outgrpsettings{'ipgroup'}</font></td>
143 </tr>
144</table>
145</form>
146<table width='10%' cellspacing='0'>
147<tr>
148 <td align='center'>
149 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
150 <input type='hidden' name='ACTION' value='newipgroup' />
151 <input type='image' alt='$Lang::tr{'new'}' title='$Lang::tr{'new'}' src='/images/list-add.png' />
152 </form>
153 </td>
154 <td align='center'>
155 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
156 <input type='hidden' name='ACTION' value='saveipgroup' />
157 <input type='hidden' name='ipgroup' value='$outgrpsettings{'ipgroup'}' />
158 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' />
159 </form>
160 </td>
161 <td align='center'>
162 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
163 <input type='hidden' name='ACTION' value='deleteipgroup' />
164 <input type='hidden' name='ipgroup' value='$outgrpsettings{'ipgroup'}' />
165 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
166 </form>
167 </td>
168</tr>
169</table>
170
171END
172;
173&Header::closebox();
174
175&Header::closebigbox();
176&Header::closepage();
177
178sub newipgroup
179{
180 &Header::openbox('100%', 'center', $Lang::tr{'outgoing firewall add ip group'});
181
182print <<END
183 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
184 <table width='95%' cellspacing='0'>
185 <tr>
186 <td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'outgoing firewall add ip group'}</b></td>
187 </tr>
188 <tr>
189 <td colspan='3' align='left'><br /></td>
190 </tr>
191 <tr>
192 <td align='left' colspan='2'>
193 <input type='text' name='ipgroup' value='newgroup' size="30" />
194 </td>
195 <td align='left'>
196 <input type='hidden' name='ACTION' value='addipgroup' />
197 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' />
198 </td>
199 </tr>
200 <tr>
201 <td align='left' colspan='3'>
202 <textarea name="ipgroupcontent" cols="20" rows="5" Wrap="off">192.168.1.0/14\n192.168.0.1\n192.168.0.2\n</textarea>
203 </td>
204 </tr>
205 </table>
206 </form>
207END
208;
209 &Header::closebox();
210 &Header::closebigbox();
211 &Header::closepage();
212 exit 0;
213}