Changeset 921 for trunk


Ignore:
Timestamp:
Feb 25, 2022, 9:30:55 AM (3 years ago)
Author:
chronos
Message:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UpdateTrace.php

    r911 r921  
    21752175{
    21762176  $Manager->Execute('ALTER TABLE `NetworkSignal` ADD `Remote` INT NOT NULL DEFAULT "0" AFTER `Device`;');
     2177}
     2178
     2179function UpdateTo921(UpdateManager $Manager): void
     2180{
     2181  $Manager->Execute('CREATE TABLE `NetworkMac` (
     2182    `Id` int(11) NOT NULL,
     2183    `MAC` varchar(17) NOT NULL
     2184  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
     2185  $Manager->Execute('ALTER TABLE `NetworkMac` ADD PRIMARY KEY (`Id`), ADD KEY `MAC` (`MAC`);');
     2186  $Manager->Execute('ALTER TABLE `NetworkMac` MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT;'); 
     2187
     2188  // Convert NetworkSignal MAC from string into reference
     2189  $Manager->Execute('INSERT INTO `NetworkMac` (`MAC`) SELECT DISTINCT(`MAC`) FROM `NetworkSignal`;');
     2190  $Manager->Execute('ALTER TABLE `NetworkSignal` ADD `MACTemp` INT NOT NULL AFTER `Remote`;');
     2191  $Manager->Execute('UPDATE `NetworkSignal` SET `MACTemp` = (SELECT `Id` FROM `NetworkMac` WHERE `NetworkMac`.`MAC` = `NetworkSignal`.`MAC`);');
     2192  $Manager->Execute('ALTER TABLE `NetworkSignal` DROP `MAC`;');
     2193  $Manager->Execute('ALTER TABLE `NetworkSignal` CHANGE `MACTemp` `MAC` INT(11) NOT NULL;');
     2194  $Manager->Execute('ALTER TABLE `NetworkSignal` ADD KEY `MAC` (`MAC`);');
     2195  $Manager->Execute('ALTER TABLE `NetworkSignal` ADD FOREIGN KEY (`MAC`) REFERENCES `NetworkMac`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
     2196
     2197  // IS menu item
     2198  $Manager->Execute('INSERT INTO `Action` (`Id` ,`Name` ,`Title` ,`Type` ,`URL` ,
     2199    `Group` ,`Icon` ,`PermissionOperation` ,`Enable`) VALUES (
     2200    NULL , "", "Fyzické adresy", "1", "/is/?t=NetworkMac&a=list", NULL , NULL , NULL , "1");');
     2201  $ActionId = $Manager->Database->insert_id;
     2202  $DbResult = $Manager->Execute('SELECT `Id` FROM `MenuItem` WHERE `Name`="Síť"');
     2203  if ($DbResult->num_rows > 0)
     2204  {
     2205    $DbRow = $DbResult->fetch_assoc();
     2206    $Manager->Execute("INSERT INTO `MenuItem` (`Id` ,`Name` ,`Parent` ,`Action` ,`Menu`) ".
     2207        "VALUES (NULL , 'Fyzické adresy', ".$DbRow['Id'].", '".$ActionId."', '1');");
     2208  }
    21772209}
    21782210
     
    22842316      901 => array('Revision' => 907, 'Function' => 'UpdateTo907'),
    22852317      907 => array('Revision' => 911, 'Function' => 'UpdateTo911'),
     2318      911 => array('Revision' => 921, 'Function' => 'UpdateTo921'),
    22862319    );
    22872320  }
  • trunk/Application/Version.php

    r920 r921  
    11<?php
    22
    3 $Revision = 920; // Subversion revision
    4 $DatabaseRevision = 911; // SQL structure revision
    5 $ReleaseTime = strtotime('2022-02-23');
     3$Revision = 921; // Subversion revision
     4$DatabaseRevision = 921; // SQL structure revision
     5$ReleaseTime = strtotime('2022-02-24');
  • trunk/Modules/Network/Network.php

    r917 r921  
    120120      NetworkDomain::GetClassName(), NetworkDomainServer::GetClassName(), NetworkDomainView::GetClassName(),
    121121      NetworkDomainItemFilter::GetClassName(), DeviceAPIType::GetClassName(), NetworkInterfaceWireless::GetClassName(),
    122       NetworkInterfaceUpDown::GetClassName(), NetworkPortUpDown::GetClassName());
     122      NetworkInterfaceUpDown::GetClassName(), NetworkPortUpDown::GetClassName(), NetworkMac::GetClassName());
    123123
    124124    // TODO: Make notify time configurable
     
    380380      'Items' => array(
    381381        'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => ''),
    382         'MAC' => array('Type' => 'MacAddress', 'Caption' => 'Fyzická adresa (MAC)', 'Default' => ''),
     382        'MAC' => array('Type' => 'TNetworkMac', 'Caption' => 'Fyzická adresa (MAC)', 'Default' => ''),
    383383        'Interface' => array('Type' => 'TNetworkInterface', 'Caption' => 'Rozhraní', 'Default' => '', 'Null' => true),
    384384        'Value' => array('Type' => 'Integer', 'Caption' => 'Signál', 'Default' => '0', 'Suffix' => 'dBm'),
     
    608608        'Duration' => array('Type' => 'TimeDiff', 'Caption' => 'Trvání', 'Default' => '', 'ReadOnly' => true),
    609609      ),
     610    ));
     611    $this->System->FormManager->RegisterClass('NetworkMac', array(
     612      'Title' => 'Fyzická síťová adresa',
     613      'Table' => 'NetworkMac',
     614      'Items' => array(
     615        'MAC' => array('Type' => 'String', 'Caption' => 'Fyzická adresa', 'Default' => ''),
     616        'Signal' => array('Type' => 'TNetworkSignalListMac', 'Caption' => 'Signál rozhraní', 'Default' => ''),       
     617      ),
     618    ));
     619    $this->System->FormManager->RegisterFormType('TNetworkMac', array(
     620      'Type' => 'Reference',
     621      'Table' => 'NetworkMac',
     622      'Id' => 'Id',
     623      'Name' => 'MAC',
     624      'Filter' => '1',
     625    ));
     626    $this->System->FormManager->RegisterFormType('TNetworkSignalListMac', array(
     627      'Type' => 'ManyToOne',
     628      'Table' => 'NetworkSignal',
     629      'Id' => 'Id',
     630      'Ref' => 'Mac',
     631      'Filter' => '1',
    610632    ));
    611633    $this->System->FormManager->RegisterFormType('TNetworkProtocol', array(
  • trunk/Modules/Network/NetworkModels.php

    r911 r921  
    192192    $Desc = new ModelDesc(self::GetClassName());
    193193    $Desc->AddDateTime('Time');
    194     $Desc->AddString('MAC');
     194    $Desc->AddReference('MAC', NetworkMac::GetClassName());
    195195    $Desc->AddReference('Interface', NetworkInterface::GetClassName());
    196196    $Desc->AddInteger('Value');
     
    342342  }
    343343}
     344
     345class NetworkMac extends Model
     346{
     347  static function GetModelDesc(): ModelDesc
     348  {
     349    $Desc = new ModelDesc(self::GetClassName());
     350    $Desc->AddString('MAC'); // size=17
     351    return $Desc;
     352  }
     353
     354  function GetIndex(string $MAC)
     355  {
     356    $DbResult = $this->Database->select('NetworkMac', 'Id', 'MAC="'.$MAC.'"');
     357    if ($DbResult->num_rows > 0)
     358    {
     359      $DbRow = $DbResult->fetch_assoc();
     360      return $DbRow['Id'];
     361    } else
     362    {
     363      return $this->Database->insert('NetworkMac', array('MAC' => $MAC));
     364    }
     365  }
     366}
  • trunk/Modules/NetworkConfigAirOS/Generators/Signal.php

    r911 r921  
    88  {
    99    $Time = time();
     10    $NetworkMac = new NetworkMac($this->System);
    1011
    1112    // Load netwatch status from all DHCP routers
     
    3839          $RateRx = $Properties['rx'];
    3940          $RateTx = $Properties['tx'];
    40           $this->Database->insert('NetworkSignal', array('MAC' => $Properties['mac'],
     41          $MacRef = $NetworkMac->GetIndex($Properties['mac']);
     42          $this->Database->insert('NetworkSignal', array('MAC' => $MacRef,
    4143            'Value' => $Strength, 'Remote' => $RemoteSignal, 'RateRx' => $RateRx, 'RateTx' => $RateTx,
    4244            'Time' => TimeToMysqlDateTime($Time), 'Interface' => $Interface, 'Device' => $Device['Id']));
  • trunk/Modules/NetworkConfigRouterOS/Generators/Signal.php

    r917 r921  
    3939    $Read = $Routerboard->Read(false);
    4040    $Array = $Routerboard->ParseResponse($Read);
     41    $NetworkMac = new NetworkMac($this->System);
    4142    foreach ($Array as $Properties)
    4243    {
     
    7576      $RateRx = $this->StripUnits($Properties['rx-rate']);
    7677      $RateTx = $this->StripUnits($Properties['tx-rate']);
     78      $MacRef = $NetworkMac->GetIndex($Properties['mac-address']);
    7779      $Queries[] = 'INSERT INTO `NetworkSignal` (`MAC`, `Value`, `Remote`, `RateRx`, `RateTx`, `Time`, `Interface`, `Device`) VALUES '.
    78         '("'.$Properties['mac-address'].'", '.$Strength.', '.$RemoteSignal.', '.$RateRx.', '.$RateTx.', "'.
     80        '('.$MacRef.', '.$Strength.', '.$RemoteSignal.', '.$RateRx.', '.$RateTx.', "'.
    7981        TimeToMysqlDateTime($this->Time).'", '.$Interface.', '.$Device['Id'].')';             
    8082    }
     
    98100      return array();
    99101    }   
     102    $NetworkMac = new NetworkMac($this->System);
    100103    foreach ($Array as $Properties)
    101104    {
     
    119122
    120123      $RateTx = $this->StripUnits($Properties['tx-phy-rate']);
     124     
     125      $MacRef = $NetworkMac->GetIndex($Properties['remote-address']);
    121126      $Queries[] = 'INSERT INTO `NetworkSignal` (`MAC`, `Value`, `Remote`, `RateRx`, `RateTx`, `Time`, `Interface`, `Device`) VALUES '.
    122         '("'.$Properties['remote-address'].'", '.$Strength.', 0, 0, '.round($RateTx / 1000000).', "'.
     127        '('.$MacRef.', '.$Strength.', 0, 0, '.round($RateTx / 1000000).', "'.
    123128        TimeToMysqlDateTime($this->Time).'", '.$Interface.', '.$Device['Id'].')';             
    124129    }
Note: See TracChangeset for help on using the changeset viewer.