Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use EBox;
- use EBox::Global;
- EBox::init();
- my $timeout = 60;
- my $global = EBox::Global->getInstance(0);
- $global->modExists("firewall") or exit(0);
- my $firewall = $global->modInstance("firewall");
- exit (0) unless ($firewall->isEnabled());
- my $redirectsTable = $firewall->model('RedirectsTable');
- my $action = shift || '';
- if ($action eq "show") {
- my $ambito = shift || '';
- if ($ambito eq "RedirectsTable") {
- foreach my $rowId (@{$redirectsTable->ids()}) {
- my $row = $redirectsTable->row($rowId);
- my $interface = $row->valueByName('interface');
- my $origDest = $row->valueByName('origDest');
- my $protocol = $row->valueByName('protocol');
- my $external_port = $row->valueByName('external_port');
- my $source = $row->valueByName('source');
- my $destination = $row->valueByName('destination');
- my $destination_port = $row->valueByName('destination_port');
- my $snat = $row->valueByName('snat');
- my $log = $row->valueByName('log');
- my $description = $row->valueByName('description');
- print "$ambito: $interface:$external_port -> $destination:$destination_port # $description (id:$rowId, origDest:$origDest, protocol:$protocol, source:$source, snat:$snat, log:$log)\n";
- }
- exit 0;
- }
- } elsif ($action eq "remove") {
- my $ambito = shift || '';
- if ($ambito eq "RedirectsTable") {
- # Parametros necesarios: interface, external_port, destination y destination port
- my $interface = shift || exit(1);
- my $external_port = shift || exit(1);
- my $destination = shift || exit(1);
- my $destination_port = shift || exit(1);
- foreach my $rowId (@{$redirectsTable->ids()}) {
- my $row = $redirectsTable->row($rowId);
- if ($interface eq $row->valueByName('interface') and
- $external_port eq $row->valueByName('external_port') and
- $destination eq $row->valueByName('destination') and
- $destination_port eq $row->valueByName('destination_port')) {
- $redirectsTable->removeRow($rowId);
- }
- }
- $global->saveAllModules();
- exit 0;
- }
- }
- print "Modo de uso: $0 show|remove RedirectsTable|ToInternetRuleTable\n";
- print "Para remove RedirectsTable los parĂ¡metros obligatorios son: interface, external_port, destination y destination port.\n";
- exit 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement