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