<?php
include_once('../global.php');

//$Config['Web']['ShowErrors'] = 1;

$Commands = array();
$Commands[] = '/ip firewall filter {:foreach i in=[find] do={:put (\"src-address=\".[get \$i src-address].\" dst-address=\".[get \$i dst-address].\" bytes=\".[get \$i bytes])}}';
$Commands = implode(';', $Commands);
$Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa rt-hajda-0 "'.$Commands.'"';
echo($Command."\n");
//echo('Output: '.shell_exec($Command));
exec($Command, $Output);
//array_pop($Output);
print_r($Output);
/*

foreach($Output as $Row)
{
  $Row = substr($Row, 6);
  $RowParts = explode(' ', $Row);
  $Properties = array();
  foreach($RowParts as $Index => $Item)
  {
    if(strpos($Item, '=') !== false) 
    {
      $ItemParts = explode('=', $Item);
      $Properties[$ItemParts[0]] = $ItemParts[1];
    }
  }
  if($Properties['status'] == 'up') $Online = 1; else $Online = 0;

  $DbResult = $Database->update('hosts', 'IP="'.$Properties['host'].'"', array('online' => $Online));
  if($Online == 1)
  {
    $DbResult = $Database->select('hosts', 'id', 'IP="'.$Properties['host'].'"');
    $DbRow = $DbResult->fetch_array();
    $HostId = $DbRow['id'];
    $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
    if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO stat_hosts (host_id, time) VALUES ("'.$HostId.'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');          
    $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
  }
}
*/

?>
