Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkConfigRouterOS/Generators/FirewallNAT.php

    r860 r873  
    3939        'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` '.
    4040        'WHERE `Member`.`Blocked` = 0');
    41     while($Member = $DbResult->fetch_assoc())
     41    while ($Member = $DbResult->fetch_assoc())
    4242    {
    4343      echo($Member['Name'].': ');
     
    4747          ' AND (`NetworkInterface`.`LocalIP` <> "")'.
    4848          ' AND (`NetworkDevice`.`Member` = '.$Member['Id'].') AND (`NetworkInterface`.`LocalIP` != `NetworkInterface`.`ExternalIP`) ORDER BY `id` DESC');
    49       while($Interface = $DbResult2->fetch_assoc())
     49      while ($Interface = $DbResult2->fetch_assoc())
    5050      {
    5151        $Name = $Interface['DeviceName'];
    52         if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     52        if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    5353        $Name = RouterOSIdent($Name);
    5454        echo($Name.'('.$Interface['LocalIP'].'), ');
    55         if($Member['Blocked'] == 0)
     55        if ($Member['Blocked'] == 0)
    5656        {
    5757          $Items[] = array('chain' => 'inet-out', 'src-address' => $Interface['LocalIP'], 'action' => 'src-nat',  'to-addresses' => $Interface['ExternalIP'], 'comment' => $Name.'-out');
    58           if($Interface['InboundNATPriority'] > 0)
     58          if ($Interface['InboundNATPriority'] > 0)
    5959            $Items[] = array('chain' => 'inet-in', 'dst-address' => $Interface['ExternalIP'], 'action' => 'dst-nat', 'to-addresses' => $Interface['LocalIP'], 'comment' => $Name.'-in');
    6060        } else
     
    6666      // Subnets
    6767      $DbResult2 = $this->Database->select('NetworkSubnet', '*', '`Member`='.$Member['Id']);
    68       while($Subnet = $DbResult2->fetch_assoc())
     68      while ($Subnet = $DbResult2->fetch_assoc())
    6969      {
    7070        $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
    7171        echo($Subnet['Name'].'('.$Subnet['AddressRange'].'/'.$Subnet['Mask'].'), ');
    72         if($Member['Blocked'] == 0)
     72        if ($Member['Blocked'] == 0)
    7373        {
    7474          $NewAddress = new NetworkAddressIPv4();
     
    7676          $NewAddress->Prefix = $Subnet['ExtMask'];
    7777          $Range = $NewAddress->GetRange();
    78           if($Subnet['ExtMask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();
     78          if ($Subnet['ExtMask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();
    7979          else $Range = $Range['From']->AddressToString();
    80           if($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange'];
     80          if ($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange'];
    8181          else $Src = $Subnet['AddressRange'].'/'.$Subnet['Mask'];
    8282          $Items[] = array('chain' => 'inet-out', 'src-address' => $Src, 'action' => 'src-nat', 'to-addresses' => $Range, 'comment' => $Subnet['Name'].'-out');
     
    8686          $NewAddress->Prefix = $Subnet['Mask'];
    8787          $Range = $NewAddress->GetRange();
    88           if($Subnet['Mask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();
     88          if ($Subnet['Mask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();
    8989          else $Range = $Range['From']->AddressToString();
    90           if($Subnet['ExtMask'] == 32) $Dest = $Subnet['ExtAddressRange'];
     90          if ($Subnet['ExtMask'] == 32) $Dest = $Subnet['ExtAddressRange'];
    9191          else $Dest = $Subnet['ExtAddressRange'].'/'.$Subnet['ExtMask'];
    9292          $Items[] = array('chain' => 'inet-in', 'dst-address' => $Dest, 'action' => 'dst-nat', 'to-addresses' => $Range, 'comment' => $Subnet['Name'].'-in');
    9393        } else
    9494        {
    95           if($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange'];
     95          if ($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange'];
    9696          else $Src = $Subnet['AddressRange'].'/'.$Subnet['Mask'];
    9797          $Items[] = array('chain' => 'dstnat', 'src-address' => $Src, 'protocol' => 'tcp', 'dst-port' => 80, 'action' => 'dst-nat',  'to-addresses' => $IPCentrala, 'to-ports' => 81, 'comment' => $Subnet['Name'].'-out');
     
    124124     // Route public addresses localy
    125125     $DbResult = $this->Database->query('SELECT Member.*, Subject.Name FROM Member JOIN Subject ON Member.Subject = Subject.Id');
    126      while($Member = $DbResult->fetch_assoc())
     126     while ($Member = $DbResult->fetch_assoc())
    127127     {
    128128     echo($Member['Name'].': ');
    129129     // Hosts
    130130     $DbResult2 = $this->Database->query('SELECT NetworkInterface.*, NetworkDevice.Name AS DeviceName FROM NetworkInterface LEFT JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE (NetworkInterface.ExternalIP <> "") AND (NetworkDevice.Member = '.$Member['Id'].') AND (NetworkInterface.LocalIP != NetworkInterface.ExternalIP) ORDER BY id DESC');
    131      while($Interface = $DbResult2->fetch_assoc())
     131     while ($Interface = $DbResult2->fetch_assoc())
    132132     {
    133133     $Name = $Interface['DeviceName'];
    134      if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     134     if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    135135     $Name = RouterOSIdent($Name);
    136136     echo($Name.'('.$Interface['LocalIP'].'), ');
Note: See TracChangeset for help on using the changeset viewer.