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