]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/outgoinggrp.cgi
Merge branch 'master' of ssh://earl@git.ipfire.org/pub/git/ipfire-2.x
[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{'portgroup'} = '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{'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
78 if ($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
86 if ($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
101 my @ipgroups = qx(ls $configpath/ipgroups/);
102 if ($outgrpsettings{'ipgroup'} eq "none" and $#ipgroups >= 0 ){ $outgrpsettings{'ipgroup'} = $ipgroups[0];}
103
104 my $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
109 print <<END
110 <br />
111 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
112 <table width='95%' cellspacing='0'>
113 <tr>
114 <td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'outgoing firewall ip groups'}</b></td>
115 </tr>
116 <tr>
117 <td colspan='3' align='left'><br /></td>
118 </tr>
119 <tr>
120 <td align='left' colspan='2'><select name='ipgroup' style="width: 200px">
121 END
122 ;
123 foreach my $member (@ipgroups) {chomp $member;print" <option value='$member' $selected{'ipgroup'}{$member}>$member</option>\n";}
124 print <<END
125 </select></td>
126 <td align='left'>
127 <input type='hidden' name='ACTION' value='showipgroup' />
128 <input type='image' alt='$Lang::tr{'outgoing firewall view group'}' title='$Lang::tr{'outgoing firewall view group'}' src='/images/format-justify-fill.png' />
129 </td>
130 </tr>
131 <tr>
132 <td colspan='3' align='left'><br /></td>
133 </tr>
134 <tr>
135 <td colspan='3' align='left'><font size=1>$ipgroupcontent</font></td>
136 </tr>
137 <tr>
138 <td colspan='3' align='left'><br /></td>
139 </tr>
140 <tr>
141 <td colspan='3' align='center'><font size=1>$Lang::tr{'outgoing firewall ip groups'} - $outgrpsettings{'ipgroup'}</font></td>
142 </tr>
143 </table>
144 </form>
145 <table width='10%' cellspacing='0'>
146 <tr>
147 <td align='center'>
148 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
149 <input type='hidden' name='ACTION' value='newipgroup' />
150 <input type='image' alt='$Lang::tr{'new'}' title='$Lang::tr{'new'}' src='/images/list-add.png' />
151 </form>
152 </td>
153 <td align='center'>
154 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
155 <input type='hidden' name='ACTION' value='saveipgroup' />
156 <input type='hidden' name='ipgroup' value='$outgrpsettings{'ipgroup'}' />
157 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' />
158 </form>
159 </td>
160 <td align='center'>
161 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
162 <input type='hidden' name='ACTION' value='deleteipgroup' />
163 <input type='hidden' name='ipgroup' value='$outgrpsettings{'ipgroup'}' />
164 <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/user-trash.png' />
165 </form>
166 </td>
167 </tr>
168 </table>
169
170 END
171 ;
172 &Header::closebox();
173
174 &Header::closebigbox();
175 &Header::closepage();
176
177 sub newipgroup
178 {
179 &Header::openbox('100%', 'center', $Lang::tr{'outgoing firewall add ip group'});
180
181 print <<END
182 <form method='post' action='$ENV{'SCRIPT_NAME'}#outgoing showipgroup'>
183 <table width='95%' cellspacing='0'>
184 <tr>
185 <td bgcolor='$color{'color20'}' colspan='3' align='left'><b>$Lang::tr{'outgoing firewall add ip group'}</b></td>
186 </tr>
187 <tr>
188 <td colspan='3' align='left'><br /></td>
189 </tr>
190 <tr>
191 <td align='left' colspan='2'>
192 <input type='text' name='ipgroup' value='newgroup' size="30" />
193 </td>
194 <td align='left'>
195 <input type='hidden' name='ACTION' value='addipgroup' />
196 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' />
197 </td>
198 </tr>
199 <tr>
200 <td align='left' colspan='3'>
201 <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>
202 </td>
203 </tr>
204 </table>
205 </form>
206 END
207 ;
208 &Header::closebox();
209 &Header::closebigbox();
210 &Header::closepage();
211 exit 0;
212 }