UserName = $Config['MainRouter']['UserName']; $Routerboard->Timeout = $Config['MainRouter']['ConnectTimeout']; $DbResult3 = $System->Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` = 0 GROUP BY `DHCP`'); while ($Subnet = $DbResult3->fetch_assoc()) { echo($Subnet['AddressRange'].'/'.$Subnet['Mask'].' on router '.$Subnet['DHCP']."\n"); $Routerboard->HostName = $Subnet['DHCP']; $List = $Routerboard->ListGet($Path, array('address', 'active-mac-address', 'active-address', 'expires-after', 'server', 'dynamic')); foreach ($List as $Properties) { if ($Properties['dynamic'] == 'true') //and ($Properties['address'] != $Properties['active-address'])) { $Properties['expires-after'] = time() - (24 * 3600 - ConvertExpireTime2($Properties['expires-after'])); echo('MAC: '.$Properties['active-mac-address']."\n"); $DbRows2 = $System->Database->query('SELECT `Id` FROM `NetworkInterface` WHERE `MAC`="'.$Properties['active-mac-address'].'"'); if ($DbRows2->num_rows > 0) { $Interface = $DbRows2->fetch_assoc(); $InterfaceId = $Interface['Id']; $DbRows2 = $System->Database->query('SELECT `Id` FROM `NetworkInterfacePortable` WHERE `NetworkInterface`='.$InterfaceId); if ($DbRows2->num_rows > 0) { $System->Database->update('NetworkInterfacePortable', '`Time` < "'.TimeToMysqlDateTime($Properties['expires-after']).'" AND `NetworkInterface`='.$InterfaceId, array('DynamicIP' => $Properties['active-address'], 'Update' => 1)); } else $System->Database->insert('NetworkInterfacePortable', array('NetworkInterface' => $InterfaceId, 'DynamicIP' => $Properties['active-address'], 'Time' => TimeToMysqlDateTime($Properties['expires-after']), 'Update' => 1)); } else echo('Not registred'."\n"); } } } // Update mangle and NAT $PathNAT = array('ip', 'firewall', 'nat'); $PathMangle = array('ip', 'firewall', 'mangle'); $MangleRule = array(); $NATRule = array(); $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'); while ($Portable = $DbRows->fetch_assoc()) { $Name = $Portable['DeviceName']; if ($Portable['InterfaceName'] != '') $Name .= '-'.$Portable['InterfaceName']; array_push($NATRule, implode(' ', $PathNAT).' set [find comment="'.$Name.'-in"] to-addresses='.$Portable['DynamicIP']); array_push($NATRule, implode(' ', $PathNAT).' set [find comment="'.$Name.'-out"] src-address='.$Portable['DynamicIP']); array_push($MangleRule, implode(' ', $PathMangle).' set [find comment="'.$Name.'-in"] dst-address='.$Portable['DynamicIP']); array_push($MangleRule, implode(' ', $PathMangle).' set [find comment="'.$Name.'-out"] src-address='.$Portable['DynamicIP']); } $Routerboard->HostName = $Config['MainRouter']['HostName']; print_r($NATRule); print_r($MangleRule); $Routerboard->ExecuteBatch($NATRule); $Routerboard->ExecuteBatch($MangleRule); $System->Database->query('UPDATE NetworkInterfacePortable SET Update=0');