Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
Location:
trunk/Modules/NetworkConfigRouterOS
Files:
16 edited

Legend:

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

    r738 r873  
    11<?php
    22
    3 if(isset($_SERVER['REMOTE_ADDR'])) die();
     3if (isset($_SERVER['REMOTE_ADDR'])) die();
    44include_once(dirname(__FILE__).'/../../../Common/Global.php');
    55include_once(dirname(__FILE__).'/../Routerboard.php');
     
    1111{
    1212  $TimeParts = explode(':', $Time);
    13   return($TimeParts[0] * 3600 + $TimeParts[1] * 60 + $TimeParts[2]);
     13  return ($TimeParts[0] * 3600 + $TimeParts[1] * 60 + $TimeParts[2]);
    1414}
    1515
     
    1919
    2020$DbResult3 = $System->Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` = 0 GROUP BY `DHCP`');
    21 while($Subnet = $DbResult3->fetch_assoc())
     21while ($Subnet = $DbResult3->fetch_assoc())
    2222{
    2323  echo($Subnet['AddressRange'].'/'.$Subnet['Mask'].' on router '.$Subnet['DHCP']."\n");
    2424  $Routerboard->HostName = $Subnet['DHCP'];
    2525  $List = $Routerboard->ListGet($Path, array('address', 'active-mac-address', 'active-address', 'expires-after', 'server', 'dynamic'));
    26   foreach($List as $Properties)
     26  foreach ($List as $Properties)
    2727  {
    28     if($Properties['dynamic'] == 'true')
     28    if ($Properties['dynamic'] == 'true')
    2929    //and ($Properties['address'] != $Properties['active-address']))
    3030    {
     
    3232      echo('MAC: '.$Properties['active-mac-address']."\n");
    3333      $DbRows2 = $System->Database->query('SELECT `Id` FROM `NetworkInterface` WHERE `MAC`="'.$Properties['active-mac-address'].'"');
    34       if($DbRows2->num_rows > 0)
     34      if ($DbRows2->num_rows > 0)
    3535      {
    3636        $Interface = $DbRows2->fetch_assoc();
    3737        $InterfaceId = $Interface['Id'];
    3838        $DbRows2 = $System->Database->query('SELECT `Id` FROM `NetworkInterfacePortable` WHERE `NetworkInterface`='.$InterfaceId);
    39         if($DbRows2->num_rows > 0)
     39        if ($DbRows2->num_rows > 0)
    4040        {
    4141          $System->Database->update('NetworkInterfacePortable', '`Time` < "'.TimeToMysqlDateTime($Properties['expires-after']).'" AND `NetworkInterface`='.$InterfaceId, array('DynamicIP' => $Properties['active-address'], 'Update' => 1));
     
    5353$NATRule = array();
    5454$DbRows = $System->Database->query('SELECT NetworkDevice.Name AS DeviceName, NetworkInterface.Name AS InterfaceName, DynamicIP FROM `NetworkInterfacePortable` JOIN NetworkInterface ON NetworkInterface.Id=NetworkInterfacePortable.NetworkInterface JOIN NetworkDevice ON NetworkDevice.Id = NetworkInterface.Device WHERE `Update`=1');
    55 while($Portable = $DbRows->fetch_assoc())
     55while ($Portable = $DbRows->fetch_assoc())
    5656{
    5757  $Name = $Portable['DeviceName'];
    58   if($Portable['InterfaceName'] != '') $Name .= '-'.$Portable['InterfaceName'];
     58  if ($Portable['InterfaceName'] != '') $Name .= '-'.$Portable['InterfaceName'];
    5959  array_push($NATRule, implode(' ', $PathNAT).' set [find comment="'.$Name.'-in"] to-addresses='.$Portable['DynamicIP']);
    6060  array_push($NATRule, implode(' ', $PathNAT).' set [find comment="'.$Name.'-out"] src-address='.$Portable['DynamicIP']);
  • trunk/Modules/NetworkConfigRouterOS/Generators/Common.php

    r870 r873  
    66
    77  $DbResult = $Database->query('SELECT `Id` FROM `NetworkMark` WHERE `Comment`="'.$Comment.'"');
    8   if($DbResult->num_rows > 0)
     8  if ($DbResult->num_rows > 0)
    99  {
    1010    $DbRow = $DbResult->fetch_assoc();
    11     return($DbRow['Id']);
     11    return ($DbRow['Id']);
    1212  } else
    1313  {
    1414    $DbResult = $Database->query('INSERT INTO `NetworkMark` (`Comment`) VALUES ("'.$Comment.'")');
    15     return($Database->insert_id);
     15    return ($Database->insert_id);
    1616  }
    1717}
     
    2222
    2323  $DbResult = $Database->query('SELECT `Id` FROM `NetworkMangleSubgroup` WHERE `AddressRange`="'.$AddressRange.'"');
    24   if($DbResult->num_rows > 0)
     24  if ($DbResult->num_rows > 0)
    2525  {
    2626    $DbRow = $DbResult->fetch_assoc();
    27     return($DbRow['Id']);
     27    return ($DbRow['Id']);
    2828  } else
    2929  {
    3030    $DbResult = $Database->query('INSERT INTO `NetworkMangleSubgroup` (`AddressRange`) VALUES ("'.$AddressRange.'")');
    31     return($Database->insert_id);
     31    return ($Database->insert_id);
    3232  }
    3333}
     
    3838
    3939  $Found = false;
    40   foreach($Tree['Items'] as $Index => $Node)
     40  foreach ($Tree['Items'] as $Index => $Node)
    4141  {
    42     if($Node['Address']->Contain($Address))
     42    if ($Node['Address']->Contain($Address))
    4343    {
    4444      InsertToAddressTreeIPv4($Tree['Items'][$Index], $Address, $Name, true);
     
    4646    }
    4747  }
    48   if($Found == false)
     48  if ($Found == false)
    4949  {
    50     if($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and
     50    if ($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and
    5151    ($Address->Prefix > ($Tree['Address']->Prefix + 1)))
    5252    {
     
    6262      // Should be existed items placed under new node?
    6363      $Found = false;
    64       foreach($Tree['Items'] as $Index => $Node)
     64      foreach ($Tree['Items'] as $Index => $Node)
    6565      {
    66         if(($Node['Address']->Address == $NewNode['Address']->Address) and
     66        if (($Node['Address']->Address == $NewNode['Address']->Address) and
    6767        ($Node['Address']->Prefix == $NewNode['Address']->Prefix)) $Found = true;
    6868
    69         if($Address->Contain($Node['Address']))
     69        if ($Address->Contain($Node['Address']))
    7070        {
    7171          $NewNode['Items'][] = $Node;
     
    7373        }
    7474      }
    75       if($Found == false) $Tree['Items'][] = $NewNode;
     75      if ($Found == false) $Tree['Items'][] = $NewNode;
    7676    }
    7777  }
     
    8383
    8484  $Found = false;
    85   foreach($Tree['Items'] as $Index => $Node)
     85  foreach ($Tree['Items'] as $Index => $Node)
    8686  {
    87     if($Node['Address']->Contain($Address))
     87    if ($Node['Address']->Contain($Address))
    8888    {
    8989      InsertToAddressTreeIPv6($Tree['Items'][$Index], $Address, $Name, true);
     
    9191    }
    9292  }
    93   if($Found == false)
     93  if ($Found == false)
    9494  {
    95     if($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and
     95    if ($InterSubnets and ($Tree['Address']->Prefix < $Config['MainRouter']['MangleRuleSubgroupMinPrefix']) and
    9696    ($Address->Prefix > ($Tree['Address']->Prefix + 1)))
    9797    {
     
    107107      // Should be existed items placed under new node?
    108108      $Found = false;
    109       foreach($Tree['Items'] as $Index => $Node)
     109      foreach ($Tree['Items'] as $Index => $Node)
    110110      {
    111         if(($Node['Address']->Address == $NewNode['Address']->Address) and
     111        if (($Node['Address']->Address == $NewNode['Address']->Address) and
    112112        ($Node['Address']->Prefix == $NewNode['Address']->Prefix)) $Found = true;
    113113
    114         if($Address->Contain($Node['Address']))
     114        if ($Address->Contain($Node['Address']))
    115115        {
    116116          $NewNode['Items'][] = $Node;
     
    118118        }
    119119      }
    120       if($Found == false) $Tree['Items'][] = $NewNode;
     120      if ($Found == false) $Tree['Items'][] = $NewNode;
    121121    }
    122122  }
     
    126126{
    127127  echo(str_repeat('  ', $Indent).$Node['Address']->AddressToString().'/'.$Node['Address']->Prefix.' '.$Node['Name']."\n");
    128   foreach($Node['Items'] as $Index => $Item)
     128  foreach ($Node['Items'] as $Index => $Item)
    129129  {
    130130    ShowSubnetNode($Item, $Indent + 1);
  • trunk/Modules/NetworkConfigRouterOS/Generators/DHCP.php

    r861 r873  
    1414
    1515    $DbResult = $this->Database->query('SELECT * FROM `NetworkSubnet` WHERE `Configure`=1');
    16     while($Subnet = $DbResult->fetch_assoc())
     16    while ($Subnet = $DbResult->fetch_assoc())
    1717    {
    1818      echo($Subnet['DHCP']);
     
    2424        'WHERE CompareNetworkPrefix(INET_ATON(`LocalIP`), INET_ATON("'.$Subnet['AddressRange'].'"), '.$Subnet['Mask'].') '.
    2525        'AND (`MAC` != "00:00:00:00:00:00") ORDER BY `LocalIP`');
    26       while($Interface = $DbResult2->fetch_assoc())
     26      while ($Interface = $DbResult2->fetch_assoc())
    2727      {
    2828        $Name = $Interface['DeviceName'];
    29         if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     29        if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    3030        $Items[] = array('mac-address' => $Interface['MAC'], 'address' => $Interface['LocalIP'], 'server' => $Server, 'comment' => $Name, 'lease-time' => '1d');
    3131      }
  • trunk/Modules/NetworkConfigRouterOS/Generators/DNS.php

    r781 r873  
    1313
    1414    $DbResult = $this->Database->query('SELECT * FROM `NetworkDomain`');
    15     while($Domain = $DbResult->fetch_assoc())
     15    while ($Domain = $DbResult->fetch_assoc())
    1616    {
    1717      $DomainName = $Domain['Name'];
     
    1919      // Get full domain name from parent items
    2020      $CurrentDomain = $Domain;
    21       while($CurrentDomain['Parent'] > 0)
     21      while ($CurrentDomain['Parent'] > 0)
    2222      {
    2323        $DbResult2 = $this->Database->query('SELECT * FROM `NetworkDomain` WHERE `Id`='.$CurrentDomain['Parent']);
     
    3232          'JOIN `NetworkDevice` ON `NetworkInterface`.`Device`=`NetworkDevice`.`Id` '.
    3333          'WHERE (`NetworkDevice`.`Used`=1)');
    34       while($Interface = $DbResult2->fetch_assoc())
     34      while ($Interface = $DbResult2->fetch_assoc())
    3535      {
    3636        $Name = $Interface['DeviceName'];
    37         if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     37        if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    3838        $NameFull = $Name.'.'.$DomainName;
    3939        $NameExtFull = $Name.'-ext.'.$DomainName;
    40         if($Interface['LocalIP'] != '')
     40        if ($Interface['LocalIP'] != '')
    4141          $Items[] = array('name' => $NameFull, 'address' => $Interface['LocalIP']);
    42         if($Interface['IPv6'] != '')
     42        if ($Interface['IPv6'] != '')
    4343          $Items[] = array('name' => $NameFull, 'address' => $Interface['IPv6']);
    44         if($Interface['ExternalIP'] != '')
     44        if ($Interface['ExternalIP'] != '')
    4545          $Items[] = array('name' => $NameExtFull, 'address' => $Interface['ExternalIP']);
    4646      }
     
    5353          'WHERE (`NetworkDevice`.`Used`=1) AND '.
    5454          '(CONCAT_WS("-", `NetworkDevice`.`Name`, NULLIF(`NetworkInterface`.`Name`, "")) = `NetworkDomainAlias`.`Target`)');
    55       while($Alias = $DbResult2->fetch_assoc())
     55      while ($Alias = $DbResult2->fetch_assoc())
    5656      {
    5757        $Name = $Alias['Name'];
    5858        $NameFull = $Name.'.'.$DomainName;
    5959        $NameExtFull = $Name.'-ext.'.$DomainName;
    60         if($Alias['LocalIP'] != '')
     60        if ($Alias['LocalIP'] != '')
    6161          $Items[] = array('name' => $NameFull, 'address' => $Alias['LocalIP']);
    62         if($Alias['IPv6'] != '')
     62        if ($Alias['IPv6'] != '')
    6363          $Items[] = array('name' => $NameFull, 'address' => $Alias['IPv6']);
    64         if($Alias['ExternalIP'] != '')
     64        if ($Alias['ExternalIP'] != '')
    6565          $Items[] = array('name' => $NameExtFull, 'address' => $Alias['ExternalIP']);
    6666      }
    6767
    6868      $DbResult2 = $this->Database->query('SELECT * FROM `NetworkDomainServer` WHERE `Domain`='.$Domain['Id']);
    69       while($Server = $DbResult2->fetch_assoc())
     69      while ($Server = $DbResult2->fetch_assoc())
    7070      {
    7171        $Routerboard->HostName = $Server['Address'];
  • trunk/Modules/NetworkConfigRouterOS/Generators/FirewallFilter.php

    r831 r873  
    4242    // Insert blocked addresses
    4343    $DbResult = $this->Database->query('SELECT Member.*, Subject.Name FROM Member JOIN Subject ON Member.Subject = Subject.Id WHERE Member.Blocked=1');
    44     while($Member = $DbResult->fetch_assoc())
     44    while ($Member = $DbResult->fetch_assoc())
    4545    {
    4646      echo($Member['Name'].': ');
    4747      // Hosts
    4848      $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');
    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'].'), ');
     
    5959      // Subnets
    6060      $DbResult2 = $this->Database->select('NetworkSubnet', '*', 'Member='.$Member['Id']);
    61       while($Subnet = $DbResult2->fetch_assoc())
     61      while ($Subnet = $DbResult2->fetch_assoc())
    6262      {
    6363        $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
     
    6767        $NewAddress->Prefix = $Subnet['ExtMask'];
    6868        $Range = $NewAddress->GetRange();
    69         if($Subnet['ExtMask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();
     69        if ($Subnet['ExtMask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();
    7070        else $Range = $Range['From']->AddressToString();
    71         if($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange'];
     71        if ($Subnet['Mask'] == 32) $Src = $Subnet['AddressRange'];
    7272        else $Src = $Subnet['AddressRange'].'/'.$Subnet['Mask'];
    7373        $Items[] = array('chain' => 'forward', 'out-interface' => $InetInterface, 'src-address' => $Src, 'action' => 'drop','comment' => $Subnet['Name'].'-out-drop');
     
    7777        $NewAddress->Prefix = $Subnet['Mask'];
    7878        $Range = $NewAddress->GetRange();
    79         if($Subnet['Mask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();
     79        if ($Subnet['Mask'] != 32) $Range = $Range['From']->AddressToString().'-'.$Range['To']->AddressToString();
    8080        else $Range = $Range['From']->AddressToString();
    81         if($Subnet['ExtMask'] == 32) $Dest = $Subnet['ExtAddressRange'];
     81        if ($Subnet['ExtMask'] == 32) $Dest = $Subnet['ExtAddressRange'];
    8282        else $Dest = $Subnet['ExtAddressRange'].'/'.$Subnet['ExtMask'];
    8383        $Items[] = array('chain' => 'forward', 'in-interface' => $InetInterface, 'dst-address' => $Dest, 'action' => 'drop', 'comment' => $Subnet['Name'].'-in-drop');
  • trunk/Modules/NetworkConfigRouterOS/Generators/FirewallMangle.php

    r870 r873  
    77    global $InetInterface, $ItemsFirewall;
    88
    9     foreach($Node['Items'] as $Index => $Item)
    10     {
    11       if(count($Item['Items']) == 0)
     9    foreach ($Node['Items'] as $Index => $Item)
     10    {
     11      if (count($Item['Items']) == 0)
    1212      {
    1313        // Hosts
    1414        $ParentSubnetId = GetSubgroupByRange($Node['Address']->AddressToString().'/'.$Node['Address']->Prefix);
    1515        $Address = $Item['Address']->AddressToString();
    16         if($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix;
     16        if ($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix;
    1717
    1818        $PacketMark = GetMarkByComment($Item['Name'].'-out');
     
    2828
    2929        $Address = $Item['Address']->AddressToString();
    30         if($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix;
     30        if ($Item['Address']->Prefix != 32) $Address .= '/'.$Item['Address']->Prefix;
    3131
    3232        $ItemsFirewall[] = array('chain' => 'inet-'.$ParentSubnetId.'-out', 'src-address' => $Address, 'out-interface' => $InetInterface, 'action' => 'jump', 'jump-target' => 'inet-'.$SubnetId.'-out', 'comment' => $Item['Name'].'-out');
     
    3636      }
    3737    }
    38     if($Node['ForceMark'] == true)
     38    if ($Node['ForceMark'] == true)
    3939    {
    4040      // Mark member subnets
     
    7272    // Divide rules by subnet number
    7373    $DbResult = $this->System->Database->query('SELECT `Id`, `Name`, `AddressRange`, `Mask` FROM `NetworkSubnet` WHERE `Member` IS NULL');
    74     while($Subnet = $DbResult->fetch_assoc())
     74    while ($Subnet = $DbResult->fetch_assoc())
    7575    {
    7676      $NewAddress = new NetworkAddressIPv4();
     
    8484        'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` '.
    8585        'WHERE `Member`.`Blocked` = 0');
    86     while($Member = $DbResult->fetch_assoc())
     86    while ($Member = $DbResult->fetch_assoc())
    8787    {
    8888      $Member['Name'] = RouterOSIdent($Member['Name'].'-'.$Member['Id'] );
     
    9090
    9191      $DbResult2 = $this->System->Database->select('NetworkDevice', '*', '`Used` = 1 AND `Member` = '.$Member['Id']);
    92       while($Device = $DbResult2->fetch_assoc())
     92      while ($Device = $DbResult2->fetch_assoc())
    9393      {
    9494        $DbResult3 = $this->Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `LocalIP` != ""');
    95         while($Interface = $DbResult3->fetch_assoc())
     95        while ($Interface = $DbResult3->fetch_assoc())
    9696        {
    9797          $Name = $Device['Name'];
    98           if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     98          if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    9999          $Name = RouterOSIdent($Name);
    100100          echo($Name.', ');
     
    107107
    108108      $DbResult2 = $this->Database->select('NetworkSubnet', '*', '(`Member`='.$Member['Id'].') AND (AddressRange != "")');
    109       while($Subnet = $DbResult2->fetch_assoc())
     109      while ($Subnet = $DbResult2->fetch_assoc())
    110110      {
    111111        $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
     
    114114        $NewAddress->AddressFromString($Subnet['AddressRange']);
    115115        $NewAddress->Prefix = $Subnet['Mask'];
    116         if($Subnet['Member'] != 0) $ForceMark = true;
     116        if ($Subnet['Member'] != 0) $ForceMark = true;
    117117        else $ForceMark = false;
    118118        echo($ForceMark.', ');
     
    169169    $DbResult = $this->System->Database->query('SELECT `Id`, `Name`, `AddressRangeIPv6`, `MaskIPv6` FROM `NetworkSubnet` '.
    170170      'WHERE (`Member` IS NULL) AND (`AddressRangeIPv6` != "")');
    171     while($Subnet = $DbResult->fetch_assoc())
     171    while ($Subnet = $DbResult->fetch_assoc())
    172172    {
    173173      $NewAddress = new NetworkAddressIPv6();
     
    181181        'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` '.
    182182        'WHERE `Member`.`Blocked` = 0');
    183     while($Member = $DbResult->fetch_assoc())
     183    while ($Member = $DbResult->fetch_assoc())
    184184    {
    185185      $Member['Name'] = RouterOSIdent($Member['Name'].'-'.$Member['Id'] );
     
    187187
    188188      $DbResult2 = $this->System->Database->select('NetworkDevice', '*', '`Used` = 1 AND `Member` = '.$Member['Id']);
    189       while($Device = $DbResult2->fetch_assoc())
     189      while ($Device = $DbResult2->fetch_assoc())
    190190      {
    191191        $DbResult3 = $this->Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `IPv6` != ""');
    192         while($Interface = $DbResult3->fetch_assoc())
     192        while ($Interface = $DbResult3->fetch_assoc())
    193193        {
    194194          $Name = $Device['Name'];
    195           if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     195          if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    196196          $Name = RouterOSIdent($Name);
    197197          echo($Name.', ');
     
    204204
    205205      $DbResult2 = $this->Database->select('NetworkSubnet', '*', '(`Member`='.$Member['Id'].') AND (AddressRangeIPv6 != "")');
    206       while($Subnet = $DbResult2->fetch_assoc())
     206      while ($Subnet = $DbResult2->fetch_assoc())
    207207      {
    208208        $Subnet['Name'] = RouterOSIdent('subnet-'.$Subnet['Name']);
     
    211211        $NewAddress->AddressFromString($Subnet['AddressRangeIPv6']);
    212212        $NewAddress->Prefix = $Subnet['MaskIPv6'];
    213         if($Subnet['Member'] != 0) $ForceMark = true;
     213        if ($Subnet['Member'] != 0) $ForceMark = true;
    214214        else $ForceMark = false;
    215215        echo($ForceMark.', ');
  • 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'].'), ');
  • trunk/Modules/NetworkConfigRouterOS/Generators/Netwatch.php

    r835 r873  
    1313
    1414    $DbResult3 = $this->Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` WHERE `Configure` = 1'); // WHERE `Member` = 0');
    15     while($Router = $DbResult3->fetch_assoc())
     15    while ($Router = $DbResult3->fetch_assoc())
    1616    {
    1717      echo($Router['DHCP']."\n");
     
    1919      $Items = array();
    2020      $DbResult = $this->Database->query('SELECT * FROM `NetworkSubnet` WHERE (`Configure` = 1) AND (`DHCP`="'.$Router['DHCP'].'")');
    21       while($Subnet = $DbResult->fetch_assoc())
     21      while ($Subnet = $DbResult->fetch_assoc())
    2222      {
    2323        $I = explode('.', $Subnet['AddressRange']);
     
    2626            ' LEFT JOIN `NetworkDevice` ON `NetworkDevice`.`Id` = `NetworkInterface`.`Device` WHERE CompareNetworkPrefix(INET_ATON(`LocalIP`), INET_ATON("'.$Subnet['AddressRange'].'"), '.$Subnet['Mask'].')'.
    2727            ' AND (`NetworkDevice`.`Used` = 1) ORDER BY `NetworkInterface`.`LocalIP`');
    28         while($Interface = $DbResult2->fetch_assoc())
     28        while ($Interface = $DbResult2->fetch_assoc())
    2929        {
    3030          $Name = $Interface['DeviceName'];
    31           if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
     31          if ($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    3232          echo($Name.', ');
    3333          $Items[] = array('host' => $Interface['LocalIP'], 'interval' => '00:00:10', 'comment' => $Name);
  • trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php

    r863 r873  
    1010    $Interfaces = array();
    1111    $DbResult = $this->Database->select('NetworkInterface', '`Id`, `LocalIP` AS `IP`, `Online`, 0 AS `NewOnline`');
    12     while($DbRow = $DbResult->fetch_assoc())
     12    while ($DbRow = $DbResult->fetch_assoc())
    1313      $Interfaces[$DbRow['IP']] = $DbRow;
    1414
     
    1616    $DbResult3 = $this->Database->query('SELECT `DHCP` FROM `NetworkSubnet` '.
    1717      'WHERE (`Configure` = 1) AND (`Member` IS NULL) GROUP BY `DHCP`');
    18     while($Subnet = $DbResult3->fetch_assoc())
     18    while ($Subnet = $DbResult3->fetch_assoc())
    1919    {
    2020      echo('router '.$Subnet['DHCP']."\n");
     
    2222      $Routerboard->Connect($Subnet['DHCP'], $this->System->Config['API']['UserName'],
    2323        $this->System->Config['API']['Password']);
    24       if(!$Routerboard->Connected) continue;
     24      if (!$Routerboard->Connected) continue;
    2525      $Routerboard->Write('/tool/netwatch/getall', false);
    2626      $Routerboard->Write('=.proplist=host,status');
    2727      $Read = $Routerboard->Read(false);
    2828      $List = $Routerboard->ParseResponse($Read);
    29       foreach($List as $Properties)
     29      foreach ($List as $Properties)
    3030      {
    3131        $IP = $Properties['host'];
    32         if($Properties['status'] == 'up') $Online = 1;
     32        if ($Properties['status'] == 'up') $Online = 1;
    3333          else $Online = 0;
    3434
    35         if($Online)
     35        if ($Online)
    3636        {
    37           if(array_key_exists($IP, $Interfaces))
     37          if (array_key_exists($IP, $Interfaces))
    3838            $Interfaces[$IP]['NewOnline'] = 1;
    3939            else echo('IP '.$IP.' not found.'."\n");
     
    4444    $Queries = array();
    4545    $QueriesInsert = array();
    46     foreach($Interfaces as $Index => $Interface)
     46    foreach ($Interfaces as $Index => $Interface)
    4747    {
    4848      // Update last online time if still online
    49       if($Interface['NewOnline'])
     49      if ($Interface['NewOnline'])
    5050        $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = '.$Interface['Id'],
    5151          array('LastOnline' => TimeToMysqlDateTime($StartTime)));
    5252
    53       if($Interface['Online'] != $Interface['NewOnline'])
     53      if ($Interface['Online'] != $Interface['NewOnline'])
    5454      {
    5555        // Online state changed
     
    7878    $DbResult = $this->Database->select('NetworkInterface', '*', '(`Online` = 1) AND '.
    7979      '(`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'")');
    80     while($DbRow = $DbResult->fetch_assoc())
     80    while ($DbRow = $DbResult->fetch_assoc())
    8181    {
    8282      echo('IP '.$DbRow['LocalIP'].' online but time not updated.'."\n");
     
    8484    $DbResult = $this->Database->select('NetworkInterface', '*', '(`Online` = 0) AND '.
    8585      '(`LastOnline` >= "'.TimeToMysqlDateTime($StartTime).'")');
    86     while($DbRow = $DbResult->fetch_assoc())
     86    while ($DbRow = $DbResult->fetch_assoc())
    8787    {
    8888      echo('IP '.$DbRow['LocalIP'].' not online but time updated.'."\n");
     
    9292    // Update device online state
    9393    $DbResult = $this->Database->select('NetworkInterface', '`Device`, SUM(`Online`) AS `SumOnline`', '`Online` = 1 GROUP BY `Device`');
    94     while($Device = $DbResult->fetch_assoc())
     94    while ($Device = $DbResult->fetch_assoc())
    9595    {
    96       if($Device['SumOnline'] > 0)
     96      if ($Device['SumOnline'] > 0)
    9797        $Queries[] = $this->Database->GetUpdate('NetworkDevice', 'Id='.$Device['Device'], array('LastOnline' => TimeToMysqlDateTime($StartTime), 'Online' => 1));
    9898    }
  • trunk/Modules/NetworkConfigRouterOS/Generators/Queue.php

    r869 r873  
    4848  function CheckName($Name, &$UsedNames)
    4949  {
    50     if(in_array($Name, $UsedNames)) die("\n".'Duplicate name: '.$Name);
     50    if (in_array($Name, $UsedNames)) die("\n".'Duplicate name: '.$Name);
    5151      else $UsedNames[] = $Name;
    5252  }
     
    189189    $DbResult = $this->Database->query('SELECT `Member`.*, `Subject`.`Name` FROM `Member` '.
    190190      'LEFT JOIN `Subject` ON `Subject`.`Id` = `Member`.`Subject` WHERE `Member`.`Blocked`=0');
    191     while($Member = $DbResult->fetch_assoc())
     191    while ($Member = $DbResult->fetch_assoc())
    192192    {
    193193      $ServiceIndex = 1;
     
    198198        'WHERE (`ServiceCustomerRel`.`Customer` = '.$Member['Id'].') AND (`ServiceCustomerRel`.`ChangeAction` IS NULL) '.
    199199        'AND (`Service`.`InternetSpeedMax` > 0) AND (`Service`.`InternetSpeedMin` > 0)');
    200       while($Service = $DbResult4->fetch_assoc())
     200      while ($Service = $DbResult4->fetch_assoc())
    201201      {
    202202        echo('Služba '.$Service['Name'].': ');
     
    231231        $Row = $DbResult2->fetch_row();
    232232        $HostCount = $Row[0];
    233         if($HostCount > 0)
     233        if ($HostCount > 0)
    234234        {
    235235          $HostSpeedIn = round($SpeedIn / $HostCount);
     
    242242
    243243        $DbResult2 = $this->Database->select('NetworkDevice', '*', $Filter);
    244         while($Device = $DbResult2->fetch_assoc())
     244        while ($Device = $DbResult2->fetch_assoc())
    245245        {
    246246          $DbResult3 = $this->Database->select('NetworkInterface', '*', '`Device` = '.$Device['Id'].' AND `LocalIP` != ""');
    247           while($Interface = $DbResult3->fetch_assoc())
     247          while ($Interface = $DbResult3->fetch_assoc())
    248248          {
    249249            $DeviceName = $Device['Name'];
    250             if($Interface['Name'] != '') $DeviceName .= '-'.$Interface['Name'];
     250            if ($Interface['Name'] != '') $DeviceName .= '-'.$Interface['Name'];
    251251            $DeviceName = RouterOSIdent($DeviceName);
    252252            echo($DeviceName.', ');
     
    258258
    259259        $DbResult2 = $this->Database->select('NetworkSubnet', '*', '`Service`='.$Service['RelId']);
    260         while($Subnet = $DbResult2->fetch_assoc())
     260        while ($Subnet = $DbResult2->fetch_assoc())
    261261        {
    262262          $SubnetName = RouterOSIdent('subnet-'.$Subnet['Name']);
     
    329329  {
    330330    $MinSpeed = 0;
    331     foreach($this->Devices[$DeviceId]['Childs'] as $DeviceChild)
     331    foreach ($this->Devices[$DeviceId]['Childs'] as $DeviceChild)
    332332    {
    333333      $this->UpdateMinSpeed($DeviceChild);
     
    335335    }
    336336    $this->Devices[$DeviceId]['MinSpeed'] = $MinSpeed;
    337     if($this->Devices[$DeviceId]['DeviceCount'] > 0)
     337    if ($this->Devices[$DeviceId]['DeviceCount'] > 0)
    338338      $this->Devices[$DeviceId]['MinSpeed'] += round($this->Devices[$DeviceId]['InternetSpeedMin'] / $this->Devices[$DeviceId]['DeviceCount']);
    339339  }
     
    349349      'LEFT JOIN `ServiceCustomerRel` ON `ServiceCustomerRel`.`Id`=`NetworkDevice`.`Service` '.
    350350      'LEFT JOIN `Service` ON `Service`.`Id` = `ServiceCustomerRel`.`Service`');
    351     while($Device = $DbResult->fetch_assoc())
     351    while ($Device = $DbResult->fetch_assoc())
    352352    {
    353353      $Device['Interfaces'] = array();
     
    364364    $Interfaces = array();
    365365    $DbResult = $this->Database->query('SELECT `Device`,`Name`,`Id` FROM `NetworkInterface`');
    366     while($Interface = $DbResult->fetch_assoc())
     366    while ($Interface = $DbResult->fetch_assoc())
    367367    {
    368368      $Interface['Links'] = array();
     
    376376      '`NetworkLink`.`Interface2`,`NetworkLinkType`.`MaxRealSpeed` FROM `NetworkLink` '.
    377377      'LEFT JOIN `NetworkLinkType` ON `NetworkLinkType`.`Id`=`NetworkLink`.`Type`');
    378     while($Link = $DbResult->fetch_assoc())
     378    while ($Link = $DbResult->fetch_assoc())
    379379    {
    380380      $Links[$Link['Id']] = $Link;
     
    388388    $this->Devices[$RootDeviceId]['Calculated'] = true;
    389389
    390     while(count($DevicesToCheck) > 0)
     390    while (count($DevicesToCheck) > 0)
    391391    {
    392392      //echo('Pass'."\n");
    393393      $NewDevicesToCheck = array();
    394       foreach($DevicesToCheck as $DeviceId)
     394      foreach ($DevicesToCheck as $DeviceId)
    395395      {
    396396        //echo($this->Devices[$DeviceId]['Name'].': ');
    397         foreach($this->Devices[$DeviceId]['Interfaces'] as $InterfaceId)
     397        foreach ($this->Devices[$DeviceId]['Interfaces'] as $InterfaceId)
    398398        {
    399           foreach($Interfaces[$InterfaceId]['Links'] as $LinkId)
     399          foreach ($Interfaces[$InterfaceId]['Links'] as $LinkId)
    400400          {
    401401            $Link = $Links[$LinkId];
    402402            $Interface2Id = $Link['Interface1'];
    403             if($Interface2Id == $InterfaceId) $Interface2Id = $Links[$LinkId]['Interface2'];
     403            if ($Interface2Id == $InterfaceId) $Interface2Id = $Links[$LinkId]['Interface2'];
    404404
    405405            $Device2Id = $Interfaces[$Interface2Id]['Device'];
    406             if($this->Devices[$Device2Id]['Calculated'] == false)
     406            if ($this->Devices[$Device2Id]['Calculated'] == false)
    407407            {
    408408              $this->Devices[$Device2Id]['Calculated'] = true;
    409409              $NewMaxSpeed = $this->Devices[$DeviceId]['MaxSpeed'];
    410               if($NewMaxSpeed > $Link['MaxRealSpeed'])
     410              if ($NewMaxSpeed > $Link['MaxRealSpeed'])
    411411                $NewMaxSpeed = $Link['MaxRealSpeed'];
    412412              //echo($this->Devices[$Device2Id]['Name'].' '.$Device2Id.', ');
     
    431431
    432432    echo('Not linked network devices: ');
    433     foreach($this->Devices as $Device)
    434     {
    435       if($Device['MaxSpeed'] == 0) echo($Device['Name'].', ');
     433    foreach ($this->Devices as $Device)
     434    {
     435      if ($Device['MaxSpeed'] == 0) echo($Device['Name'].', ');
    436436    }
    437437    echo("\n");
     
    455455    $DbResult3 = $this->Database->select('NetworkInterface', '*', '`Device` = '.$DeviceId.' AND `LocalIP` != ""');
    456456    $IntCount = $DbResult3->num_rows;
    457     while($Interface = $DbResult3->fetch_assoc())
     457    while ($Interface = $DbResult3->fetch_assoc())
    458458    {
    459459      $InterfaceName = $Device['Name'];
    460       if($Interface['Name'] != '') $InterfaceName .= '-'.$Interface['Name'];
     460      if ($Interface['Name'] != '') $InterfaceName .= '-'.$Interface['Name'];
    461461        else $InterfaceName .= '-';
    462462      $InterfaceName = RouterOSIdent($InterfaceName);
     
    469469
    470470    // Process childs
    471     foreach($Device['Childs'] as $DeviceChild)
     471    foreach ($Device['Childs'] as $DeviceChild)
    472472    {
    473473      $this->BuildQueueItems($DeviceChild, $LimitDevice);
     
    505505
    506506    $DbResult = $this->Database->select('Service', '*', '(`ChangeAction` IS NULL) AND (`Id`='.TARIFF_FREE.')');
    507     if($DbResult->num_rows == 1)
     507    if ($DbResult->num_rows == 1)
    508508    {
    509509      $Service = $DbResult->fetch_array();
  • trunk/Modules/NetworkConfigRouterOS/Generators/Signal.php

    r851 r873  
    1212        '(SELECT `LocalIP` FROM `NetworkInterface` WHERE `NetworkInterface`.`Device` = `NetworkDevice`.`Id` LIMIT 1) AS `LocalIP` '.
    1313        'FROM `NetworkDevice` WHERE (`API` = 1) AND (`Used` = 1)');
    14     while($Device = $DbResult3->fetch_assoc())
     14    while ($Device = $DbResult3->fetch_assoc())
    1515    {
    1616      echo($Device['LocalIP']."\n");
     
    1919      //$Routerboard->Port = 8729;
    2020      $Routerboard->Connect($Device['LocalIP'], $this->System->Config['API']['UserName'], $this->System->Config['API']['Password']);
    21       if(!$Routerboard->Connected) continue;
     21      if (!$Routerboard->Connected) continue;
    2222      $Routerboard->Write('/interface/wireless/registration-table/getall', false);
    2323      $Routerboard->Write('=.proplist=signal-strength,mac-address,rx-rate,tx-rate', false);
     
    2525      $Read = $Routerboard->Read(false);
    2626      $Array = $Routerboard->ParseResponse($Read);
    27       foreach($Array as $Properties)
     27      foreach ($Array as $Properties)
    2828      {
    2929        $DbResult = $this->Database->select('NetworkInterface', 'Id', 'MAC="'.$Properties['mac-address'].'"');
    30         if($DbResult->num_rows > 0)
     30        if ($DbResult->num_rows > 0)
    3131        {
    3232          $DbRow = $DbResult->fetch_assoc();
     
    3434        } else $Interface = 'NULL';
    3535
    36         if(strpos($Properties['signal-strength'], '@') === false)
     36        if (strpos($Properties['signal-strength'], '@') === false)
    3737        {
    3838          $Strength = $Properties['signal-strength'];
    3939        } else {
    4040          $Parts = explode('@', $Properties['signal-strength']);
    41           if(substr($Parts[0], -3) == 'dBm')
     41          if (substr($Parts[0], -3) == 'dBm')
    4242            $Strength = substr($Parts[0], 0, -3); // without dBm
    4343            else $Strength = $Parts[0];
     
    5050        /*
    5151         $DbResult = $this->Database->select('Measure', 'Id', '`Name` = "'.$Properties['mac-address'].'"');
    52          if($DbResult->num_rows > 0)
     52         if ($DbResult->num_rows > 0)
    5353         {
    5454         $this->Database->insert('Measure', array('Name' => $Properties['mac-address']));
     
    7474    if (substr($Value, -3, 3) == "Mbp") $Value = substr($Value, 0, -3); // without Mbp unit   
    7575    if (substr($Value, -1, 1) == "M") $Value = substr($Value, 0, -1); // without M unit
    76     return($Value);
     76    return ($Value);
    7777  }
    7878
  • trunk/Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php

    r860 r873  
    7070    $IPAddress = GetRemoteAddress();
    7171    $Output = 'Vaše IP adresa je: '.$IPAddress.'<br/>';
    72     if(IsInternetAddr($IPAddress)) {
     72    if (IsInternetAddr($IPAddress)) {
    7373      $Output .= '<p>Internet zdarma je dostupný pouze z vnitřní sítě.</p>';
    74       return($Output);
     74      return ($Output);
    7575    }
    7676    $Time = time();
     
    7878    $DbResult = $this->Database->select('NetworkFreeAccess', '*', '(IPAddress="'.$IPAddress.
    7979      '") ORDER BY Time DESC LIMIT 1');
    80     if($DbResult->num_rows > 0)
     80    if ($DbResult->num_rows > 0)
    8181    {
    8282      $DbRow = $DbResult->fetch_assoc();
    8383      $ActivationTime = MysqlDateTimeToTime($DbRow['Time']);
    84       if(($ActivationTime + $this->Timeout) < $Time)
     84      if (($ActivationTime + $this->Timeout) < $Time)
    8585      {
    8686        $Activated = false;
     
    8888    } else $Activated = false;
    8989
    90     if(array_key_exists('a', $_GET))
     90    if (array_key_exists('a', $_GET))
    9191    {
    92       if($_GET['a'] == 'activate')
     92      if ($_GET['a'] == 'activate')
    9393      {
    94         if($Activated == false)
     94        if ($Activated == false)
    9595        {
    9696          $DbResult = $this->Database->insert('NetworkFreeAccess',
     
    108108
    109109    $PrefixMultiplier = new PrefixMultiplier();
    110     if($Activated) $Output .= 'Aktivováno. Vyprší za '.$PrefixMultiplier->Add($ActivationTime + $this->Timeout - $Time, '', 4, 'Time');
     110    if ($Activated) $Output .= 'Aktivováno. Vyprší za '.$PrefixMultiplier->Add($ActivationTime + $this->Timeout - $Time, '', 4, 'Time');
    111111      else $Output .= '<a href="?a=activate">Aktivovat</a>';
    112112
    113     return($Output);
     113    return ($Output);
    114114  }
    115115}
     
    122122    $Commands = array();
    123123    $DbResult = $this->Database->select('NetworkFreeAccess', '`Id`, `IPAddress`', '(`Configured`=0)');
    124     while($DbRow = $DbResult->fetch_assoc())
     124    while ($DbRow = $DbResult->fetch_assoc())
    125125    {
    126126      $Commands[] = '/ip firewall address-list add address='.$DbRow['IPAddress'].
     
    135135    $Routerboard->ExecuteBatch(implode(';', $Commands));
    136136
    137     return($Output);
     137    return ($Output);
    138138  }
    139139}
  • trunk/Modules/NetworkConfigRouterOS/Routerboard.php

    r860 r873  
    2222  {
    2323    $Output = array();
    24     if(is_array($Commands))
     24    if (is_array($Commands))
    2525    {
    2626      $I = 0;
    2727      $Batch = array();
    28       while($I < count($Commands))
    29       {
    30         if(($I % $this->MaxBurstLineCount) == 0)
    31         {
    32           if(count($Batch) > 0)
     28      while ($I < count($Commands))
     29      {
     30        if (($I % $this->MaxBurstLineCount) == 0)
     31        {
     32          if (count($Batch) > 0)
    3333            $Output = array_merge($Output, $this->ExecuteBatch(implode(';', $Batch)));
    3434          $Batch = array();
     
    3737        $I++;
    3838      }
    39       if(count($Batch) > 0)
     39      if (count($Batch) > 0)
    4040       $Output = array_merge($Output, $this->ExecuteBatch(implode(';', $Batch)));
    4141    } else
    4242      $Output = array_merge($Output, $this->ExecuteBatch($Commands));
    43     return($Output);
     43    return ($Output);
    4444  }
    4545
     
    4747  {
    4848    $Commands = trim($Commands);
    49     if($Commands != '')
     49    if ($Commands != '')
    5050    {
    5151      $Commands = addslashes($Commands);
     
    5757      $Command = $this->SSHPath.' -oBatchMode=no -o ConnectTimeout='.$this->Timeout.' -l '.$this->UserName.
    5858        $PrivKey.' '.$this->HostName.' "'.$Commands.'"';
    59       if($this->Debug) echo($Command);
     59      if ($this->Debug) echo($Command);
    6060      $Output = array();
    6161      exec($Command, $Output);
    6262    } else $Output = '';
    63     if($this->Debug) print_r($Output);
    64     return($Output);
     63    if ($this->Debug) print_r($Output);
     64    return ($Output);
    6565  }
    6666
     
    7070    array_pop($Result);
    7171    $List = array();
    72     foreach($Result as $ResultLine)
     72    foreach ($Result as $ResultLine)
    7373    {
    7474      $ResultLineParts = explode(' ', trim($ResultLine));
    75       if(count($ResultLineParts) > 1)
    76       {
    77         if($ResultLineParts[1]{0} == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes
     75      if (count($ResultLineParts) > 1)
     76      {
     77        if ($ResultLineParts[1]{0} == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes
    7878        $List[substr($ResultLineParts[0], 0, -1)] = $ResultLineParts[1];
    7979      } else $List[substr($ResultLineParts[0], 0, -1)] = '';
    8080    }
    81     return($List);
     81    return ($List);
    8282  }
    8383
     
    8585  {
    8686    $PropertyList = '"';
    87     foreach($Properties as $Index => $Property)
     87    foreach ($Properties as $Index => $Property)
    8888    {
    8989      $PropertyList .= $Index.'=".[get $i '.$Property.']." ';
     
    9292
    9393    $ConditionList = '';
    94     foreach($Conditions as $Index => $Item)
    95     {
    96       if($Item == 'no') $ConditionList .= $Index.'='.$Item.' ';
     94    foreach ($Conditions as $Index => $Item)
     95    {
     96      if ($Item == 'no') $ConditionList .= $Index.'='.$Item.' ';
    9797      else $ConditionList .= $Index.'="'.$Item.'" ';
    9898    }
     
    101101    $Result = $this->Execute(implode(' ', $Path).' {:foreach i in=[find '.$ConditionList.'] do={:put ('.$PropertyList.')}}');
    102102    $List = array();
    103     foreach($Result as $ResultLine)
     103    foreach ($Result as $ResultLine)
    104104    {
    105105      $ResultLineParts = explode(' ', $ResultLine);
    106106      $ListItem = array();
    107       foreach($ResultLineParts as $ResultLinePart)
     107      foreach ($ResultLineParts as $ResultLinePart)
    108108      {
    109109        $Value = explode('=', $ResultLinePart);
    110         if(count($Value) > 1) $ListItem[$Properties[$Value[0]]] = $Value[1];
     110        if (count($Value) > 1) $ListItem[$Properties[$Value[0]]] = $Value[1];
    111111          else $ListItem[$Properties[$Value[0]]] = '';
    112112      }
    113113      $List[] = $ListItem;
    114114    }
    115     return($List);
     115    return ($List);
    116116  }
    117117
     
    119119  {
    120120    $ConditionList = '';
    121     foreach($Conditions as $Index => $Item)
     121    foreach ($Conditions as $Index => $Item)
    122122    {
    123123      $ConditionList .= $Index.'="'.$Item.'" ';
    124124    }
    125125    $ConditionList = substr($ConditionList, 0, -1);
    126     if(trim($ConditionList) != '')
     126    if (trim($ConditionList) != '')
    127127      $ConditionList = ' where '.$ConditionList;
    128128
    129129    $Result = $this->Execute(implode(' ', $Path).' print terse'.$ConditionList);
    130130    $List = array();
    131     foreach($Result as $ResultLine)
     131    foreach ($Result as $ResultLine)
    132132    {
    133133      $ResultLineParts = explode(' ', $ResultLine);
    134134      $ListItem = array();
    135       foreach($ResultLineParts as $ResultLinePart)
     135      foreach ($ResultLineParts as $ResultLinePart)
    136136      {
    137137        $Value = explode('=', $ResultLinePart);
    138         if(in_array($Value[0], $Properties))
    139         {
    140           if(count($Value) > 1)
     138        if (in_array($Value[0], $Properties))
     139        {
     140          if (count($Value) > 1)
    141141          {
    142             if($Value[1]{0} == '"') $Value[1] = substr($Value[1], 1, -1);
    143             //if(strlen($Value[1]) > 0)
     142            if ($Value[1]{0} == '"') $Value[1] = substr($Value[1], 1, -1);
     143            //if (strlen($Value[1]) > 0)
    144144            $ListItem[$Value[0]] = $Value[1];
    145145          } else $ListItem[$Value[0]] = '';
    146146        }
    147147      }
    148       if(count($ListItem) > 0) $List[] = $ListItem;
    149     }
    150     return($List);
     148      if (count($ListItem) > 0) $List[] = $ListItem;
     149    }
     150    return ($List);
    151151  }
    152152
     
    159159  {
    160160    // Get current list from routerboard
    161     if($UsePrint == 0)
     161    if ($UsePrint == 0)
    162162    {
    163163      $List = $this->ListGet($Path, $Properties, $Condition);
    164164      // Change boolean values yes/no to true/false
    165       foreach($List as $Index => $ListItem)
    166       {
    167         foreach($ListItem as $Index2 => $Item2)
    168         {
    169           if($Item2 == 'true') $List[$Index][$Index2] = 'yes';
    170           if($Item2 == 'false') $List[$Index][$Index2] = 'no';
     165      foreach ($List as $Index => $ListItem)
     166      {
     167        foreach ($ListItem as $Index2 => $Item2)
     168        {
     169          if ($Item2 == 'true') $List[$Index][$Index2] = 'yes';
     170          if ($Item2 == 'false') $List[$Index][$Index2] = 'no';
    171171        }
    172172      }
     
    178178
    179179    // Add empty properties to values
    180     foreach($Values as $Index => $Item)
    181     {
    182       foreach($Properties as $Property)
    183       {
    184         if(!array_key_exists($Property, $Item))
     180    foreach ($Values as $Index => $Item)
     181    {
     182      foreach ($Properties as $Property)
     183      {
     184        if (!array_key_exists($Property, $Item))
    185185           $Item[$Property] = '';
    186186      }
    187187      $Values[$Index] = $Item;
    188188    }
    189     foreach($List as $Index => $Item)
    190     {
    191       foreach($Properties as $Property)
    192       {
    193         if(!array_key_exists($Property, $Item))
     189    foreach ($List as $Index => $Item)
     190    {
     191      foreach ($Properties as $Property)
     192      {
     193        if (!array_key_exists($Property, $Item))
    194194           $Item[$Property] = '';
    195195      }
     
    198198
    199199    // Sort properties
    200     foreach($Values as $Index => $Item)
     200    foreach ($Values as $Index => $Item)
    201201    {
    202202      ksort($Values[$Index]);
    203203    }
    204     foreach($List as $Index => $Item)
     204    foreach ($List as $Index => $Item)
    205205    {
    206206      ksort($List[$Index]);
    207207    }
    208     if($this->Debug) print_r($List);
    209     if($this->Debug) print_r($Values);
     208    if ($this->Debug) print_r($List);
     209    if ($this->Debug) print_r($Values);
    210210
    211211    // Erase all items not existed in $Values
    212     foreach($List as $Index => $ListItem)
    213     {
    214       if(!in_array($ListItem, $Values))
     212    foreach ($List as $Index => $ListItem)
     213    {
     214      if (!in_array($ListItem, $Values))
    215215      {
    216216        $Prop = '';
    217         foreach($ListItem as $Index => $Property)
    218         {
    219           if($Property != '')
     217        foreach ($ListItem as $Index => $Property)
     218        {
     219          if ($Property != '')
    220220          {
    221             if(($Property == 'yes') or ($Property == 'no')) $Prop .= $Index.'='.$Property.' ';
     221            if (($Property == 'yes') or ($Property == 'no')) $Prop .= $Index.'='.$Property.' ';
    222222              else $Prop .= $Index.'="'.$Property.'" ';
    223223          }
    224224        }
    225225        $Prop = substr($Prop, 0, -1);
    226         if(trim($Prop) != '')
     226        if (trim($Prop) != '')
    227227          $Commands[] = implode(' ', $Path).' remove [find '.$Prop.']';
    228228      }
     
    230230
    231231    // Add new items
    232     foreach($Values as $ListItem)
    233     {
    234       if(!in_array($ListItem, $List))
     232    foreach ($Values as $ListItem)
     233    {
     234      if (!in_array($ListItem, $List))
    235235      {
    236236        $Prop = '';
    237         foreach($ListItem as $Index => $Property)
    238         {
    239           if($Property != '') $Prop .= $Index.'="'.$Property.'" ';
     237        foreach ($ListItem as $Index => $Property)
     238        {
     239          if ($Property != '') $Prop .= $Index.'="'.$Property.'" ';
    240240        }
    241241        $Prop = substr($Prop, 0, -1);
     
    243243      }
    244244    }
    245     if($this->Debug) print_r($Commands);
    246     return($this->Execute($Commands));
     245    if ($this->Debug) print_r($Commands);
     246    return ($this->Execute($Commands));
    247247  }
    248248}
  • trunk/Modules/NetworkConfigRouterOS/Routerboard2.php

    r738 r873  
    1313  function Execute($Commands)
    1414  {
    15     if(is_array($Commands)) $Commands = implode(';', $Commands);
    16     return(parent::Execute($Commands));
     15    if (is_array($Commands)) $Commands = implode(';', $Commands);
     16    return (parent::Execute($Commands));
    1717  }
    1818
     
    2222    array_pop($Result);
    2323    $List = array();
    24     foreach($Result as $ResultLine)
     24    foreach ($Result as $ResultLine)
    2525    {
    2626      $ResultLineParts = explode(' ', trim($ResultLine));
    27       if($ResultLineParts[1]{0} == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes
     27      if ($ResultLineParts[1]{0} == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes
    2828      $List[substr($ResultLineParts[0], 0, -1)] = $ResultLineParts[1];
    2929    }
    30     return($List);
     30    return ($List);
    3131  }
    3232
     
    3434  {
    3535    $PropertyList = '"';
    36     foreach($Properties as $Property)
     36    foreach ($Properties as $Property)
    3737    {
    3838      $PropertyList .= $Property.'=".[get $i '.$Property.']." ';
     
    4141    $Result = $this->Execute($Command.' {:foreach i in=[find] do={:put ('.$PropertyList.')}}');
    4242    $List = array();
    43     foreach($Result as $ResultLine)
     43    foreach ($Result as $ResultLine)
    4444    {
    4545      $ResultLineParts = explode(' ', $ResultLine);
    4646      $ListItem = array();
    47       foreach($ResultLineParts as $ResultLinePart)
     47      foreach ($ResultLineParts as $ResultLinePart)
    4848      {
    4949        $Value = explode('=', $ResultLinePart);
     
    5252      $List[] = $ListItem;
    5353    }
    54     return($List);
     54    return ($List);
    5555  }
    5656
    5757  function GetSystemResource()
    5858  {
    59     return($this->GetItem('/system resource print'));
     59    return ($this->GetItem('/system resource print'));
    6060  }
    6161
    6262  function GetFirewallFilterList()
    6363  {
    64     return($this->GetList('/ip firewall nat', array('src-address', 'dst-address', 'bytes')));
     64    return ($this->GetList('/ip firewall nat', array('src-address', 'dst-address', 'bytes')));
    6565  }
    6666
    6767  function GetDHCPServerLeasesList()
    6868  {
    69     return($this->GetList('/ip dhcp-server lease', array('address', 'active-address', 'comment', 'lease-time', 'status', 'host-name')));
     69    return ($this->GetList('/ip dhcp-server lease', array('address', 'active-address', 'comment', 'lease-time', 'status', 'host-name')));
    7070  }
    7171}
  • trunk/Modules/NetworkConfigRouterOS/RouterboardAPI.php

    r861 r873  
    4040    } else if ($Length >= 0x10000000)
    4141      $Length = chr(0xF0).chr(($Length >> 24) & 0xFF).chr(($Length >> 16) & 0xFF).chr(($Length >> 8) & 0xFF).chr($Length & 0xFF);
    42     return($Length);
     42    return ($Length);
    4343  }
    4444
    4545  function ConnectOnce($IP, $Login, $Password)
    4646  {
    47     if($this->Connected) $this->Disconnect();
    48     if($this->SSL)
     47    if ($this->Connected) $this->Disconnect();
     48    if ($this->SSL)
    4949    {
    5050      $IP = 'ssl://'.$IP;
    5151    }
    5252    $this->Socket = @fsockopen($IP, $this->Port, $this->ErrorNo, $this->ErrorStr, $this->Timeout);
    53     if($this->Socket)
     53    if ($this->Socket)
    5454    {
    5555      socket_set_timeout($this->Socket, $this->Timeout);
     
    5858      $this->Write('=password='.$Password);
    5959      $Response = $this->Read(false);
    60       if((count($Response) > 0) and ($Response[0] == '!done')) $this->Connected = true;
    61       if(!$this->Connected) fclose($this->Socket);
     60      if ((count($Response) > 0) and ($Response[0] == '!done')) $this->Connected = true;
     61      if (!$this->Connected) fclose($this->Socket);
    6262    }
    6363  }
     
    6565  function Connect($IP, $Login, $Password)
    6666  {
    67     for($Attempt = 1; $Attempt <= $this->Attempts; $Attempt++)
     67    for ($Attempt = 1; $Attempt <= $this->Attempts; $Attempt++)
    6868    {
    6969      $this->ConnectOnce($IP, $Login, $Password);
    70       if($this->Connected) break;
     70      if ($this->Connected) break;
    7171      sleep($this->Delay);
    7272    }
    73     return($this->Connected);
     73    return ($this->Connected);
    7474  }
    7575
    7676  function Disconnect()
    7777  {
    78     if($this->Connected)
     78    if ($this->Connected)
    7979    {
    8080      fclose($this->Socket);
     
    183183        $Response[] = $Line;
    184184      }
    185       if($this->Debug) echo($Line);
     185      if ($this->Debug) echo($Line);
    186186      // If we get a !done, make a note of it.
    187187      if ($Line == "!done") $ReceivedDone = true;
     
    192192        break;
    193193    }
    194     if($Parse) $Response = $this->ParseResponse($Response);
     194    if ($Parse) $Response = $this->ParseResponse($Response);
    195195    return $Response;
    196196  }
     
    198198  function Write($Command, $Param2 = true)
    199199  {
    200     if($Command)
     200    if ($Command)
    201201    {
    202202      $Data = explode("\n", $Command);
     
    234234      $this->Write($el, $Last);
    235235    }
    236     return($this->Read());
     236    return ($this->Read());
    237237  }
    238238}
  • trunk/Modules/NetworkConfigRouterOS/SSH.php

    r738 r873  
    1818  {
    1919    echo($Commands);
    20     if(!function_exists("ssh2_connect")) die("Function ssh2_connect doesn't exist");
    21     if(!($this->Session = ssh2_connect($this->HostName, 22, $this->Methods))) echo("Fail: Unable to establish connection to host\n");
     20    if (!function_exists("ssh2_connect")) die("Function ssh2_connect doesn't exist");
     21    if (!($this->Session = ssh2_connect($this->HostName, 22, $this->Methods))) echo("Fail: Unable to establish connection to host\n");
    2222    else
    2323    {
    24       if(!ssh2_auth_password($this->Session, $this->UserName, $this->Password)) echo("Fail: unable to authenticate\n");
     24      if (!ssh2_auth_password($this->Session, $this->UserName, $this->Password)) echo("Fail: unable to authenticate\n");
    2525      else
    2626      {
    27         //if(!($Stream = ssh2_shell($this->Session, 'xterm', null, 80, 40, SSH2_TERM_UNIT_CHARS))) echo("Fail: unable to execute command\n");
    28         if(!($Stream = ssh2_exec($this->Session, $Commands))) echo("Fail: unable to execute command\n");
     27        //if (!($Stream = ssh2_shell($this->Session, 'xterm', null, 80, 40, SSH2_TERM_UNIT_CHARS))) echo("Fail: unable to execute command\n");
     28        if (!($Stream = ssh2_exec($this->Session, $Commands))) echo("Fail: unable to execute command\n");
    2929        else
    3030        {
    3131          $Response = '';
    3232          stream_set_blocking($Stream, true);
    33           while($Buffer = fread($Stream, 4000))
     33          while ($Buffer = fread($Stream, 4000))
    3434          {
    3535            $Response .= $Buffer;
     
    3737            /*
    3838            //echo(') '.strlen($Buffer).' '.ord($Buffer{0}).'(');
    39             for($I = 0; $I < strlen($Buffer); $I++)
     39            for ($I = 0; $I < strlen($Buffer); $I++)
    4040            {
    41               if(((ord($Buffer{$I}) >= 32) and (ord($Buffer{$I}) <= 128)) or ($Buffer{$I} = "\n") or ($Buffer{$I} = "\r")) echo($Buffer{$I});
    42               if($Buffer{$I} == '>')
     41              if (((ord($Buffer{$I}) >= 32) and (ord($Buffer{$I}) <= 128)) or ($Buffer{$I} = "\n") or ($Buffer{$I} = "\r")) echo($Buffer{$I});
     42              if ($Buffer{$I} == '>')
    4343              {
    4444                fwrite($Stream, $Commands."\n\r");
     
    5454    }
    5555    echo($Response);
    56     return(explode("\n", substr($Response, 0, -1)));
     56    return (explode("\n", substr($Response, 0, -1)));
    5757  }
    5858}
Note: See TracChangeset for help on using the changeset viewer.