#!/usr/bin/perl

### Skrypt do mac listy :)
### wykonany przez dhapollo
### Mozna wykozystać pozostawiajac powuższe nagłówki :)



  $lp = 1;


open (PLIK_PORT_ETH1, "/etc/serwer/port/port-eth1.list") or die "open $alert_file: $!\n";
{
  sleep 1;
    if (seek(PLIK_PORT_ETH1,0,1))
      {

          print "--------------------------------------------- \n";
          print "                 Otwarte porty eth1 \n";
          print "--------------------------------------------- \n";

    while (<PLIK_PORT_ETH1>)
        {
    chop;
  next if (/^\s*$/); # wyjazd z pustymi liniami
  next if (/^#/);    # wyjazd z #
     if (/(\d+) \; (\S+) \; (\d+\.\d+\.\d+\.\d+) \; (\S+)/)
        {

  print " $lp -> Nazwa: $2 PORT: $1 Siec: $3/24\n";
system "iptables -A INPUT -s $3/24 -p $4 --dport $1 -j MACCONTROL";
  $lp = $lp + 1;
}

} # end while
     } # end if seek
 } # end for

close PLIK_PORT_ETH1;

##### PORTY DLA ETH0


  $lp = 1;


open (PLIK_PORT_ETH0, "/etc/serwer/port/port-eth0.list") or die "open $alert_file: $!\n";
{
  sleep 1;
    if (seek(PLIK_PORT_ETH0,0,1))
      {

          print "--------------------------------------------- \n";
          print "                 Otwarte porty eth0 \n";
          print "--------------------------------------------- \n";

    while (<PLIK_PORT_ETH0>)
        {
    chop;
  next if (/^\s*$/); # wyjazd z pustymi liniami
  next if (/^#/);    # wyjazd z #
     if (/(\d+) \; (\S+) \; (\S+)/)
        {

  print " $lp -> Nazwa: $2 PORT: $1 \n";
system "iptables -A INPUT -i eth0 -p $3 --dport $1 -j ACCEPT";
  $lp = $lp + 1;
}

} # end while
     } # end if seek
 } # end for

close PLIK_PORT_ETH0;
