Changeset 861


Ignore:
Timestamp:
Oct 2, 2019, 12:15:16 AM (5 years ago)
Author:
chronos
Message:
  • Modified: Optimized netwatch inport for inserting data ti database.
  • Fixed: RouterOS API to work with RouterOS newer than 6.43.
Location:
trunk
Files:
4 edited

Legend:

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

    r860 r861  
    2828        $Name = $Interface['DeviceName'];
    2929        if($Interface['Name'] != '') $Name .= '-'.$Interface['Name'];
    30         $Items[] = array('mac-address' => $Interface['MAC'], 'address' => $Interface['LocalIP'], 'server' => $Server, 'comment' => $Name, 'lease-time' => '24h');
     30        $Items[] = array('mac-address' => $Interface['MAC'], 'address' => $Interface['LocalIP'], 'server' => $Server, 'comment' => $Name, 'lease-time' => '1d');
    3131      }
    3232
  • trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php

    r860 r861  
    4343
    4444    $Queries = array();
     45    $QueriesInsert = array();
     46    $QueriesUpdate = array();
    4547    foreach($Interfaces as $Index => $Interface)
    4648    {
    4749      // Update last online time if still online
    4850      if($Interface['NewOnline'])
    49         $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = "'.$Interface['Id'].'"',
     51        $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = '.$Interface['Id'],
    5052          array('LastOnline' => TimeToMysqlDateTime($StartTime)));
    5153
     
    5355      {
    5456        // Online state changed
    55         $Queries[] = 'INSERT INTO `NetworkInterfaceUpDown` (`Interface`,
    56          `State`, `Time`, `Duration`) VALUES ('.$Interface['Id'].', '.$Interface['NewOnline'].', "'.
     57        $QueriesInsert[] = 'INSERT INTO `NetworkInterfaceUpDown` (`Interface`,'.
     58          '`State`, `Time`, `Duration`) VALUES ('.$Interface['Id'].', '.$Interface['NewOnline'].', "'.
    5759          TimeToMysqlDateTime($StartTime).'", NULL)';
    5860        // Update previous record duration in UpDown table
    59         $Queries[] = 'UPDATE `NetworkInterfaceUpDown` AS `TM` SET `Duration` = TIMESTAMPDIFF(SECOND, '.
     61        $QueriesUpdate[] = 'UPDATE `NetworkInterfaceUpDown` AS `TM` SET `Duration` = TIMESTAMPDIFF(SECOND, '.
    6062          '`TM`.`Time`, (SELECT `Time` FROM (SELECT * FROM `NetworkInterfaceUpDown`) AS `TA` WHERE (`TA`.`Time` > `TM`.`Time`) '.
    6163          'AND (`TA`.`Interface`=`TM`.`Interface`) ORDER BY `TA`.`Time` ASC LIMIT 1)) '.
     
    6567      }
    6668    }
     69    echo("transakce insert\n");
     70    $this->Database->Transaction($QueriesInsert);
     71    echo("done\n");
    6772    echo("transakce\n");
    6873    $this->Database->Transaction($Queries);
     74    echo("done\n");
     75    echo("transakce\n");
     76    $this->Database->Transaction($QueriesUpdate);
    6977    echo("done\n");
    7078
  • trunk/Modules/NetworkConfigRouterOS/RouterboardAPI.php

    r738 r861  
    5454    {
    5555      socket_set_timeout($this->Socket, $this->Timeout);
    56       $this->Write('/login');
     56      $this->Write('/login', false);
     57      $this->Write('=name=' . $Login, false);
     58      $this->Write('=password='.$Password);
    5759      $Response = $this->Read(false);
    58       if ((count($Response) > 1) and ($Response[0] == '!done')) {
    59         if (preg_match_all('/[^=]+/i', $Response[1], $Matches)) {
    60           if ($Matches[0][0] == 'ret' && strlen($Matches[0][1]) == 32) {
    61             $this->Write('/login', false);
    62             $this->Write('=name=' . $Login, false);
    63             $this->Write('=response=00'.md5(chr(0).$Password.pack('H*', $Matches[0][1])));
    64             $Response = $this->Read(false);
    65             if((count($Response) > 0) and ($Response[0] == '!done')) $this->Connected = true;
    66           }
    67         }
    68       }
     60      if((count($Response) > 0) and ($Response[0] == '!done')) $this->Connected = true;
    6961      if(!$this->Connected) fclose($this->Socket);
    7062    }
  • trunk/Packages/Common/Database.php

    r858 r861  
    9696    //echo('a'.$this->ShowSQLQuery.'<'.$QueryStartTime.', '.microtime_float());
    9797    if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
    98       $Duration = ' ; '.round(microtime_float() - $QueryStartTime, 4). ' s';
    99     if($this->LogSQLQuery == true)
     98    {
     99      $Time = round(microtime_float() - $QueryStartTime, 4);
     100      $Duration = ' ; '.$Time. ' s';
     101    }
     102    if(($this->LogSQLQuery == true) and ($Time != 0))
    100103      file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
    101104    if($this->ShowSQLQuery == true)
     
    222225  public function Transaction($Queries)
    223226  {
    224       $this->PDO->beginTransaction();
    225       foreach ($Queries as $Query)
    226       {
    227         $Statement = $this->PDO->prepare($Query);
    228         $Statement->execute();
    229       }         
    230       $this->PDO->commit();
     227    //echo('|'."\n");
     228    $this->PDO->beginTransaction();
     229    foreach ($Queries as $Query)
     230    {
     231      //echo('|'.$Query."\n");
     232      $Statement = $this->PDO->prepare($Query);
     233      $Statement->execute();
     234    }
     235    $this->PDO->commit();
    231236  }
    232237}
Note: See TracChangeset for help on using the changeset viewer.