Gro├čes Update:
[ipfire-2.x.git] / html / cgi-bin / services.cgi
CommitLineData
ac1cfefa
MT
1#!/usr/bin/perl
2#
78331e30 3# This file is part of the IPFire Firewall.
ac1cfefa 4#
78331e30 5# IPFire is free software; you can redistribute it and/or modify
ac1cfefa
MT
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
78331e30 10# IPFire is distributed in the hope that it will be useful,
ac1cfefa
MT
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
78331e30 16# along with IPFire; if not, write to the Free Software
ac1cfefa
MT
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18#
19# Copyright (C) 2003-09-22 Darren Critchley <darrenc@telus.net>
20#
21# $Id: services.cgi,v 1.2.2.3 2005/04/29 23:37:07 franck78 Exp $
22#
23
24use strict;
25
26require 'CONFIG_ROOT/general-functions.pl';
27require "${General::swroot}/lang.pl";
28require "${General::swroot}/header.pl";
29
30my @icmptypes = &get_icmptypes();
31
32&Header::showhttpheaders();
33
34my %cgiparams=();
35my %selected=();
36my %checked=();
37my $filename = "${General::swroot}/firewall/customservices";
38my $key = 0; # used for finding last sequence number used
39
40# Darren Critchley - vars for setting up sort order
41my $sort_col = '1';
42my $sort_type = 'a';
43my $sort_dir = 'asc';
44
45if ($ENV{'QUERY_STRING'} ne '') {
46 my ($item1, $item2, $item3) = split(/\&/,$ENV{'QUERY_STRING'});
47 if ($item1 ne '') {
48 ($junk, $sort_col) = split(/\=/,$item1)
49 }
50 if ($item2 ne '') {
51 ($junk, $sort_type) = split(/\=/,$item2)
52 }
53 if ($item3 ne '') {
54 ($junk, $sort_dir) = split(/\=/,$item3)
55 }
56}
57
58$cgiparams{'KEY'} = '';
59$cgiparams{'PORTS'} = '';
60$cgiparams{'PROTOCOL'} = '6';
61$cgiparams{'NAME'} = '';
62$cgiparams{'PORT_INVERT'} = 'off';
63$cgiparams{'PROTOCOL_INVERT'} = 'off';
64$cgiparams{'ICMP'} = 'BLANK';
65
66&Header::getcgihash(\%cgiparams);
67
68if ($cgiparams{'ACTION'} eq $Lang::tr{'add'}){
69
70 &validateparams();
71 unless($errormessage){
72 $key++; # Add one to last sequence number
73 open(FILE,">>$filename") or die 'Unable to open config file.';
74 flock FILE, 2;
75 print FILE "$key,$cgiparams{'NAME'},$cgiparams{'PORTS'},$cgiparams{'PROTOCOL'},$cgiparams{'PORT_INVERT'},$cgiparams{'PROTOCOL_INVERT'},$cgiparams{'ICMP'}\n";
76 close(FILE);
77 &General::log("$Lang::tr{'service added'}: $cgiparams{'NAME'}");
78 undef %cgiparams;
79 }
80}
81
82if ($cgiparams{'ACTION'} eq $Lang::tr{'update'})
83{
84 &validateparams();
85 # Darren Critchley - If there is an error don't waste any more processing time
86 if ($errormessage) { $cgiparams{'ACTION'} = $Lang::tr{'edit'}; goto UPD_ERROR; }
87
88 unless($errormessage){
89 open(FILE, $filename) or die 'Unable to open custom services file.';
90 my @current = <FILE>;
91 close(FILE);
92 my $line;
93 open(FILE, ">$filename") or die 'Unable to open config file.';
94 flock FILE, 2;
95 foreach $line (@current) {
96 chomp($line);
97 my @temp = split(/\,/,$line);
98 if ($cgiparams{'KEY'} eq $temp[0]) {
99 print FILE "$cgiparams{'KEY'},$cgiparams{'NAME'},$cgiparams{'PORTS'},$cgiparams{'PROTOCOL'},$cgiparams{'PORT_INVERT'},$cgiparams{'PROTOCOL_INVERT'},$cgiparams{'ICMP'}\n";
100 } else {
101 print FILE "$line\n";
102 }
103 }
104 close(FILE);
105 &General::log("$Lang::tr{'service updated'}: $cgiparams{'NAME'}");
106 undef %cgiparams;
107 }
108UPD_ERROR:
109}
110
111if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'})
112{
113 open(FILE, "$filename") or die 'Unable to open custom services file.';
114 my @current = <FILE>;
115 close(FILE);
116
117 unless ($errormessage)
118 {
119 foreach my $line (@current)
120 {
121 chomp($line);
122 my @temp = split(/\,/,$line);
123 if ($cgiparams{'KEY'} eq $temp[0]) {
124 $cgiparams{'NAME'} = $temp[1];
125 $cgiparams{'PORTS'} = $temp[2];
126 $cgiparams{'PROTOCOL'} = $temp[3];
127 $cgiparams{'PORT_INVERT'} = $temp[4];
128 $cgiparams{'PROTOCOL_INVERT'} = $temp[5];
129 $cgiparams{'ICMP'} = $temp[6];
130 }
131
132 }
133 }
134}
135
136if ($cgiparams{'ACTION'} eq $Lang::tr{'remove'})
137{
138 open(FILE, $filename) or die 'Unable to open custom services file.';
139 my @current = <FILE>;
140 close(FILE);
141
142 open(FILE, ">$filename") or die 'Unable to open custom services file.';
143 flock FILE, 2;
144 foreach my $line (@current)
145 {
146 chomp($line);
147 if ($line ne '') {
148 my @temp = split(/\,/,$line);
149 if ($cgiparams{'KEY'} eq $temp[0]) {
150 &General::log("$Lang::tr{'service removed'}: $temp[1]");
151 } else {
152 print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6]\n";
153 }
154 }
155 }
156 close(FILE);
157 undef %cgiparams;
158}
159
160if ($cgiparams{'ACTION'} eq $Lang::tr{'reset'})
161{
162 undef %cgiparams;
163}
164
165if ($cgiparams{'ACTION'} eq '')
166{
167 $cgiparams{'KEY'} = '';
168 $cgiparams{'PORTS'} = '';
169 $cgiparams{'PROTOCOL'} = '6';
170 $cgiparams{'NAME'} = '';
171 $cgiparams{'PORT_INVERT'} = 'off';
172 $cgiparams{'PROTOCOL_INVERT'} = 'off';
173 $cgiparams{'ICMP'} = 'BLANK';
174}
175
176# Darren Critchley - Bring in the protocols file built from /etc/protocols into hash %protocol
177require "${General::swroot}/firewall/protocols.pl";
178
179# Darren Critchley - figure out which protocol is selected
180$selected{'PROTOCOL'}{'tcpudp'}= '';
181$selected{'PROTOCOL'}{'all'}= '';
182foreach $line (keys %protocols) {
183# $selected{'PROTOCOL'}{"$protocols{$line}"}= '';
184 $selected{'PROTOCOL'}{$line}= '';
185}
186$selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED';
187
188# Darren Critchley - figure out which icmptype is selected
189$selected{'ICMP'}{$cgiparams{'ICMP'}} = 'SELECTED';
190
191$checked{'PORT_INVERT'}{'off'} = '';
192$checked{'PORT_INVERT'}{'on'} = '';
193$checked{'PORT_INVERT'}{$cgiparams{'PORT_INVERT'}} = 'CHECKED';
194$checked{'PROTOCOL_INVERT'}{'off'} = '';
195$checked{'PROTOCOL_INVERT'}{'on'} = '';
196$checked{'PROTOCOL_INVERT'}{$cgiparams{'PROTOCOL_INVERT'}} = 'CHECKED';
197
198&Header::openpage($Lang::tr{'services settings'}, 1, '');
199
200&Header::openbigbox('100%', 'LEFT', '', $errormessage);
201
202# DEBUG DEBUG
203#&Header::openbox('100%', 'LEFT', 'DEBUG');
204#foreach $line (keys %cgiparams) {
205# print "<CLASS NAME='base'>$line = $cgiparams{$line}<BR>";
206#}
207#print "$sort_col\n";
208#print "$ENV{'QUERY_STRING'}\n";
209#print "&nbsp;</CLASS>\n";
210#&Header::closebox();
211
212if ($errormessage) {
213 &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'});
214 print "<CLASS NAME='base'><FONT COLOR='${Header::colourred}'>$errormessage\n</FONT>";
215 print "&nbsp;</CLASS>\n";
216 &Header::closebox();
217}
218
219if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}){
220 &Header::openbox('100%', 'LEFT', "$Lang::tr{'edit service'}:");
221} else {
222 &Header::openbox('100%', 'LEFT', "$Lang::tr{'add service'}:");
223}
224# Darren Critchley - Show protocols with TCP, UDP, etc at the top of the list.
225print <<END
226<FORM METHOD='POST'>
227<DIV ALIGN='CENTER'>
228<TABLE WIDTH='100%' ALIGN='CENTER'>
229<TR align="center">
230 <TD><strong>$Lang::tr{'servicename'}</strong></TD>
231 <TD ALIGN='RIGHT'><strong>$Lang::tr{'invert'}</strong></TD>
232 <TD><strong>$Lang::tr{'ports'}</strong></TD>
233 <TD ALIGN='RIGHT'><strong>$Lang::tr{'invert'}</strong></TD>
234 <TD><strong>$Lang::tr{'protocol'}</strong></TD>
235 <TD>&nbsp;</TD>
236 <TD>&nbsp;</TD>
237</TR>
238<TR align="center">
239 <TD>
240 <INPUT TYPE='TEXT' NAME='NAME' VALUE='$cgiparams{'NAME'}' SIZE='20' MAXLENGTH='20'>
241 </TD>
242 <TD ALIGN='RIGHT'>
243 <INPUT TYPE='CHECKBOX' NAME='PORT_INVERT' $checked{'PORT_INVERT'}{'on'}>
244 </TD>
245 <TD>
246 <INPUT TYPE='TEXT' NAME='PORTS' VALUE='$cgiparams{'PORTS'}' SIZE='15' MAXLENGTH='11'>
247 </TD>
248 <TD ALIGN='RIGHT'>
249 <INPUT TYPE='CHECKBOX' NAME='PROTOCOL_INVERT' $checked{'PROTOCOL_INVERT'}{'on'}>
250 </TD>
251 <TD ALIGN='LEFT'>
252 <SELECT NAME='PROTOCOL'>
253 <OPTION VALUE='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</OPTION>
254 <OPTION VALUE='udp' $selected{'PROTOCOL'}{'udp'}>UDP</OPTION>
255 <OPTION VALUE='tcpudp' $selected{'PROTOCOL'}{'tcpudp'}>TCP & UDP</OPTION>
256 <OPTION VALUE='all' $selected{'PROTOCOL'}{'all'}>ALL</OPTION>
257 <OPTION VALUE='icmp' $selected{'PROTOCOL'}{'icmp'}>ICMP</OPTION>
258 <OPTION VALUE='gre' $selected{'PROTOCOL'}{'gre'}>GRE</OPTION>
259END
260;
261foreach $line (sort keys %protocols) {
262 # Darren Critchley - do not have duplicates in the list
263 if ($protocols{$line} ne '6' && $protocols{$line} ne '17' && $protocols{$line} ne '1' && $protocols{$line} ne '47'){
264# print "<OPTION VALUE='$line' $selected{'PROTOCOL'}{$protocols{$line}}>".uc($line)."</OPTION>\n";
265 print "<OPTION VALUE='$line' $selected{'PROTOCOL'}{$line}>".uc($line)."</OPTION>\n";
266 }
267}
268print <<END
269 </SELECT>
270 </TD>
271</TR>
272<TR>
273 <TD>&nbsp;</TD>
274 <TD>&nbsp;</TD>
275 <TD>&nbsp;</TD>
276 <TD><strong>$Lang::tr{'icmp type'}:</strong></TD>
277 <TD ALIGN='LEFT'>
278 <SELECT NAME='ICMP'>
279 <OPTION VALUE='BLANK' $selected{'ICMP'}{'BLANK'}>Valid ICMP Types</OPTION>
280END
281;
282foreach $line (@icmptypes) {
283 if ($cgiparams{'ICMP'} eq $line){
284 print "<OPTION VALUE='$line' SELECTED>$line</OPTION>\n";
285 } else {
286 print "<OPTION VALUE='$line' >$line</OPTION>\n";
287 }
288}
289print <<END
290 </SELECT>
291 </TD>
292</TR>
293<TR>
294END
295;
296if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}){
297 print "<TD ALIGN='CENTER'><INPUT TYPE='SUBMIT' NAME='ACTION' VALUE='$Lang::tr{'update'}'></TD>\n";
298 print "<INPUT TYPE='HIDDEN' NAME='KEY' VALUE='$cgiparams{'KEY'}'>\n";
299 print "<TD ALIGN='CENTER'><INPUT TYPE='SUBMIT' NAME='ACTION' VALUE='$Lang::tr{'reset'}'></TD>\n";
300} else {
301 print "<TD ALIGN='CENTER'><INPUT TYPE='SUBMIT' NAME='ACTION' VALUE='$Lang::tr{'add'}'></TD>\n";
302 print "<TD ALIGN='CENTER'><INPUT TYPE='SUBMIT' NAME='ACTION' VALUE='$Lang::tr{'reset'}'></TD>\n";
303}
304print <<END
305</TR>
306</TABLE>
307</DIV>
308</FORM>
309END
310;
311
312&Header::closebox();
313
314&Header::openbox('100%', 'LEFT', "$Lang::tr{'custom services'}:");
315print <<END
316<DIV ALIGN='CENTER'>
317<TABLE WIDTH='100%' ALIGN='CENTER'>
318<TR align="center">
319END
320;
321
322if ($sort_dir eq 'asc' && $sort_col eq '2') {
323 print "<TD WIDTH='25%'><strong><a href='services.cgi?sortcol=2&srtype=a&srtdir=dsc' title='$Lang::tr{'sort descending'}'>$Lang::tr{'servicename'}</a></strong></TD>\n";
324} else {
325 print "<TD WIDTH='25%'><strong><a href='services.cgi?sortcol=2&srtype=a&srtdir=asc' title='$Lang::tr{'sort ascending'}'>$Lang::tr{'servicename'}</a></strong></TD>\n";
326}
327if ($sort_dir eq 'asc' && $sort_col eq '3') {
328 print "<TD WIDTH='25%'><strong><a href='services.cgi?sortcol=3&srtype=n&srtdir=dsc' title='$Lang::tr{'sort descending'}'>$Lang::tr{'ports'}</a></strong></TD>\n";
329} else {
330 print "<TD WIDTH='25%'><strong><a href='services.cgi?sortcol=3&srtype=n&srtdir=asc' title='$Lang::tr{'sort ascending'}'>$Lang::tr{'ports'}</a></strong></TD>\n";
331}
332if ($sort_dir eq 'asc' && $sort_col eq '4') {
333 print "<TD WIDTH='25%'><strong><a href='services.cgi?sortcol=4&srtype=a&srtdir=dsc' title='$Lang::tr{'sort descending'}'>$Lang::tr{'protocol'}</a></strong></TD>\n";
334} else {
335 print "<TD WIDTH='25%'><strong><a href='services.cgi?sortcol=4&srtype=a&srtdir=asc' title='$Lang::tr{'sort ascending'}'>$Lang::tr{'protocol'}</a></strong></TD>\n";
336}
337
338print <<END
339 <TD WIDTH='25%'><strong>$Lang::tr{'icmp type'}</strong></TD>
340 <TD WIDTH='5%'>&nbsp;</TD>
341 <TD WIDTH='5%'>&nbsp;</TD>
342</TR>
343END
344;
345&display_custom_services();
346print <<END
347</TABLE>
348</DIV>
349END
350;
351&Header::closebox();
352
353&Header::openbox('100%', 'LEFT', "$Lang::tr{'default services'}:");
354print <<END
355<DIV ALIGN='CENTER'>
356<TABLE WIDTH='100%' ALIGN='CENTER'>
357<TR align="center">
358 <TD><strong>$Lang::tr{'servicename'}</strong></TD>
359 <TD><strong>$Lang::tr{'ports'}</strong></TD>
360 <TD><strong>$Lang::tr{'protocol'}</strong></TD>
361</TR>
362END
363;
364&display_default_services();
365print <<END
366</TABLE>
367</DIV>
368END
369;
370&Header::closebox();
371
372 print "$Lang::tr{'this feature has been sponsored by'} : ";
373 print "<A HREF='http://www.kdi.ca/' TARGET='_blank'>Kobelt Development Inc.</A>.\n";
374
375
376&Header::closebigbox();
377
378&Header::closepage();
379
380sub display_custom_services
381{
382
383 open(FILE, "$filename") or die 'Unable to open services file.';
384 my @current = <FILE>;
385 close(FILE);
386
387 my $id = 0;
388 my $port_inv = '';
389 my $prot_inv = '';
390 my $port_inv_tail = '';
391 my $prot_inv_tail = '';
392 my @outarray = &General::srtarray($sort_col,$sort_type,$sort_dir,@current);
393 foreach $line (@outarray)
394 {
395 chomp($line);
396 if ($line ne ''){
397 my @temp = split(/\,/,$line);
398 # Darren Critchley highlight the row we are editing
399 if ( $cgiparams{'ACTION'} eq $Lang::tr{'edit'} && $cgiparams{'KEY'} eq $temp[0] ) {
400 print "<TR BGCOLOR='${Header::colouryellow}'>\n";
401 } else {
402 if ($id % 2) {
403 print "<TR BGCOLOR='${Header::table1colour}'>\n";
404 } else {
405 print "<TR BGCOLOR='${Header::table2colour}'>\n";
406 }
407 }
408 print "<TD>$temp[1]</TD>\n";
409 if ($temp[4] eq 'on'){$port_inv = " <strong><font color='RED'>! (</font></strong>";$port_inv_tail = "<strong><font color='RED'>)</font></strong>";}else{$port_inv='';$port_inv_tail='';}
410 print "<TD ALIGN='CENTER'>" . $port_inv . &cleanport("$temp[2]") . $port_inv_tail . "</TD>\n";
411 if ($temp[5] eq 'on'){$prot_inv = " <strong><font color='RED'>! (</font></strong>";$prot_inv_tail = "<strong><font color='RED'>)</font></strong>";}else{$prot_inv='';$prot_inv_tail='';}
412 print "<TD ALIGN='CENTER'>" . $prot_inv . &cleanprotocol("$temp[3]") . $prot_inv_tail . "</TD>\n";
413 if ($temp[6] eq 'BLANK') {
414 print "<TD ALIGN='CENTER'>N/A</TD>\n";
415 } else {
416 print "<TD ALIGN='CENTER'>$temp[6]</TD>\n";
417 }
418 print <<END
419<FORM METHOD='POST' NAME='frm$temp[0]'>
420<TD ALIGN='CENTER'>
421 <INPUT TYPE='hidden' NAME='ACTION' VALUE='$Lang::tr{'edit'}'>
422 <INPUT TYPE='image' NAME='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' width='20' height='20' border='0'>
423 <INPUT TYPE='hidden' NAME='KEY' VALUE='$temp[0]'>
424</TD>
425</FORM>
426<FORM METHOD='POST' NAME='frm$temp[0]b'>
427<TD ALIGN='CENTER'>
428 <INPUT TYPE='hidden' NAME='ACTION' VALUE='$Lang::tr{'remove'}'>
429 <INPUT TYPE='image' NAME='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' width='20' height='20' border='0'>
430 <INPUT TYPE='hidden' NAME='KEY' VALUE='$temp[0]'>
431</TD>
432</FORM>
433END
434;
435 print "</TR>\n";
436 $id++;
437 }
438 }
439}
440
441sub display_default_services
442{
443 my $fname = "${General::swroot}/firewall/defaultservices";
444 my $prev = "";
445 my $newline="";
446
447 open(FILE, "$fname") or die 'Unable to open default services file.';
448 my @current = <FILE>;
449 close(FILE);
450
451 my $id = 0;
452
453 foreach my $line (sort @current)
454 {
455 my @temp = split(/\,/,$line);
456 if ($id % 2) {
457 print "<TR BGCOLOR='${Header::table1colour}'>\n";
458 } else {
459 print "<TR BGCOLOR='${Header::table2colour}'>\n";
460 }
461 print "<TD>$temp[0]</TD>\n";
462 print "<TD ALIGN='CENTER'>$temp[1]</TD>\n";
463 print "<TD ALIGN='CENTER'>" . &cleanprotocol("$temp[2]") . "</TD>\n";
464 print "</TR>\n";
465 $id++;
466 }
467}
468
469sub cleanprotocol
470{
471 my $prtcl = $_[0];
472 chomp($prtcl);
473 if ($prtcl eq 'tcpudp') {
474 $prtcl = 'TCP & UDP';
475 } else {
476 $prtcl = uc($prtcl);
477 }
478 return $prtcl;
479}
480
481sub cleanport
482{
483 my $prt = $_[0];
484 chomp($prt);
485 # Darren Critchley - Format the ports
486 $prt =~ s/-/ - /;
487 $prt =~ s/:/ - /;
488 return $prt;
489}
490
491# Validate Field Entries
492sub validateparams
493{
494 $erromessage='';
495 if ($cgiparams{'PROTOCOL'} eq 'tcp' || $cgiparams{'PROTOCOL'} eq 'udp' || $cgiparams{'PROTOCOL'} eq 'tcpudp' || $cgiparams{'PROTOCOL'} eq 'all') {
496 # Darren Critchley - Get rid of dashes in port ranges
497 $cgiparams{'PORTS'}=~ tr/-/:/;
498 # Darren Critchley - code to substitue wildcards
499 if ($cgiparams{'PORTS'} eq "*") {
500 $cgiparams{'PORTS'} = "1:65535";
501 }
502 if ($cgiparams{'PORTS'} =~ /^(\D)\:(\d+)$/) {
503 $cgiparams{'PORTS'} = "1:$2";
504 }
505 if ($cgiparams{'PORTS'} =~ /^(\d+)\:(\D)$/) {
506 $cgiparams{'PORTS'} = "$1:65535";
507 }
508 # Darren Critchley - watch the order here, the validportrange sets errormessage=''
509 $errormessage = &General::validportrange($cgiparams{'PORTS'}, 'src');
510 if ($errormessage) {return;}
511 } else {
512 $cgiparams{'PORTS'} = "";
513 }
514 if ($cgiparams{'PROTOCOL'} eq 'tcp') {
515 $cgiparams{'ICMP'} = "BLANK";
516 }
517
518 if($cgiparams{'PORTS'} eq '' && $cgiparams{'PORT_INVERT'} ne 'off'){
519 $cgiparams{'PORT_INVERT'} = 'off';
520 }
521 if ($cgiparams{'NAME'} eq '') {
522 $errormessage = $Lang::tr{'noservicename'};
523 return;
524 }
525 if ($cgiparams{'PROTOCOL'} eq 'icmp' && $cgiparams{'ICMP'} eq 'BLANK'){
526 $errormessage = $Lang::tr{'icmp selected but no type'};
527 return;
528 }
529 unless($errormessage){
530 $cgiparams{'NAME'}=&Header::cleanhtml($cgiparams{'NAME'});
531 open(FILE, $filename) or die 'Unable to open custom services file.';
532 my @current = <FILE>;
533 close(FILE);
534 foreach my $line (@current)
535 {
536 chomp($line);
537 if ($line ne '') {
538 my @temp = split(/\,/,$line);
539 if ($cgiparams{'NAME'} eq $temp[1] && $cgiparams{'KEY'} ne $temp[0]) {
540 $errormessage=$Lang::tr{'duplicate name'};
541 return;
542 }
543 $key=$temp[0];
544 }
545 }
546 unless($errormessage){
547 my $fname = "${General::swroot}/firewall/defaultservices";
548 my $prev = "";
549 my $newline="";
550
551 open(FILE, "$fname") or die 'Unable to open default services file.';
552 my @current = <FILE>;
553 close(FILE);
554
555 foreach my $line (sort @current)
556 {
557 my @temp = split(/\,/,$line);
558 if ($cgiparams{'NAME'} eq $temp[0]) {
559 $errormessage=$Lang::tr{'duplicate name'};
560 return;
561 }
562 }
563 }
564 }
565}
566
567sub get_icmptypes
568{
569 my $fname = "${General::swroot}/firewall/icmptypes";
570 my $newline="";
571 my @newarray=();
572
573 open(FILE, "$fname") or die 'Unable to open icmp file.';
574 my @current = <FILE>;
575 close(FILE);
576
577 foreach $newline (sort @current)
578 {
579 chomp ($newline);
580 if (substr($newline, 0, 1) ne "#") {
581 push (@newarray, $newline);
582 }
583 }
584 return (@newarray);
585}
586