Advertisement
jldalla

Zentyal firewall RedirectsTable

Sep 2nd, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.52 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use EBox;
  7. use EBox::Global;
  8. EBox::init();
  9.  
  10. my $timeout = 60;
  11. my $global = EBox::Global->getInstance(0);
  12. $global->modExists("firewall") or exit(0);
  13. my $firewall = $global->modInstance("firewall");
  14. exit (0) unless ($firewall->isEnabled());
  15.  
  16. my $redirectsTable = $firewall->model('RedirectsTable');
  17.  
  18. my $action = shift || '';
  19.  
  20. if ($action eq "show") {
  21.     my $ambito = shift || '';
  22.  
  23.     if ($ambito eq "RedirectsTable") {
  24.         foreach my $rowId (@{$redirectsTable->ids()}) {
  25.             my $row = $redirectsTable->row($rowId);
  26.             my $interface = $row->valueByName('interface');
  27.             my $origDest = $row->valueByName('origDest');
  28.             my $protocol = $row->valueByName('protocol');
  29.             my $external_port = $row->valueByName('external_port');
  30.             my $source = $row->valueByName('source');
  31.             my $destination = $row->valueByName('destination');
  32.             my $destination_port = $row->valueByName('destination_port');
  33.             my $snat = $row->valueByName('snat');
  34.             my $log = $row->valueByName('log');
  35.             my $description = $row->valueByName('description');
  36.  
  37.             print "$ambito: $interface:$external_port -> $destination:$destination_port # $description (id:$rowId, origDest:$origDest, protocol:$protocol, source:$source, snat:$snat, log:$log)\n";
  38.         }
  39.         exit 0;
  40.     }
  41. } elsif ($action eq "remove") {
  42.     my $ambito = shift || '';
  43.  
  44.     if ($ambito eq "RedirectsTable") {
  45.         # Parametros necesarios: interface, external_port, destination y destination port
  46.         my $interface = shift || exit(1);
  47.         my $external_port = shift || exit(1);
  48.         my $destination = shift || exit(1);
  49.         my $destination_port = shift || exit(1);
  50.  
  51.         foreach my $rowId (@{$redirectsTable->ids()}) {
  52.             my $row = $redirectsTable->row($rowId);
  53.  
  54.             if ($interface eq $row->valueByName('interface') and
  55.                 $external_port eq $row->valueByName('external_port') and
  56.                 $destination eq $row->valueByName('destination') and
  57.                 $destination_port eq $row->valueByName('destination_port')) {
  58.                 $redirectsTable->removeRow($rowId);
  59.             }
  60.         }
  61.  
  62.         $global->saveAllModules();
  63.         exit 0;
  64.     }
  65. }
  66.  
  67. print "Modo de uso: $0 show|remove RedirectsTable|ToInternetRuleTable\n";
  68. print "Para remove RedirectsTable los parĂ¡metros obligatorios son: interface, external_port, destination y destination port.\n";
  69. exit 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement