home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20110725.etc.tar.gz / bradford.20110725.etc.tar / etc / sysconfig / scripts / SuSEfirewall2-open < prev    next >
Text File  |  2006-04-22  |  1KB  |  70 lines

  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4.  
  5. my $config = '/etc/sysconfig/SuSEfirewall2';
  6. my $tmpconfig = $config.'.new';
  7.  
  8. my %zones = map { $_ => 1} ( 'INT', 'EXT', 'DMZ' );
  9. my %types = map { $_ => 1} ( 'TCP', 'UDP', 'IP', 'RPC' );
  10.  
  11. if($#ARGV < 2)
  12. {
  13.     print "USAGE: $0 <ZONE> <TYPE> <services...>\n\n";
  14.     print "where ZONE is one of ".join(' ', keys %zones)."\n";
  15.     print "and TYPE is one of ".join(' ', keys %types)."\n";
  16.     exit 1
  17. }
  18.  
  19. my ($zone, $type);
  20.  
  21. $zone = shift;
  22. $type = shift;
  23.  
  24. if(!exists $zones{$zone})
  25. {
  26.     print "$zone is not a valid zone, must be one of ".join(' ', keys %zones)."\n";
  27.     exit 1
  28. }
  29.  
  30. if(!exists $types{$type})
  31. {
  32.     print "$type is not a valid type, must be one of ".join(' ', keys %types)."\n";
  33.     exit 1
  34. }
  35.  
  36. my $var = 'FW_SERVICES_'.$zone.'_'.$type;
  37.  
  38. open(CONF,"<$config") or die "Unable to open file $config";
  39. open(OUT,">$tmpconfig") or die "Unable to open file $tmpconfig";
  40.  
  41. while(<CONF>)
  42. {
  43.     if(/^$var=/)
  44.     {
  45.         s/^$var=//;
  46.         my $fc = '';
  47.         if(/^(['"])/)
  48.         {
  49.             $fc = substr $_, 0, 1;
  50.             $_ = substr $_, 1;
  51.         }
  52.         foreach my $service (@ARGV)
  53.         {
  54.             $_ = $service.' '.$_ unless ($_ =~ /\W$service\W/)
  55.         }
  56.         print OUT "$var=$fc$_";
  57.     }
  58.     else
  59.     {
  60.         print OUT;
  61.     }
  62. }
  63.  
  64. close OUT;
  65. close CONF;
  66.  
  67. rename $tmpconfig, $config or die "can't rename file $tmpconfig to $config";
  68.  
  69. exit 0
  70.