source: trunk/system/netwatch_import.php@ 214

Last change on this file since 214 was 214, checked in by george, 16 years ago
  • Opraveno: Nezobrazovat nepoužité počítač v seznamu uživatelů.
  • Opraveno: Aktualizovat online stav zařízení dle stavu rozhraní.
  • Opraveno: Nepoužívané zařízení nezařazovat do systému omezování rychlosti.
  • Property svn:executable set to *
File size: 2.3 KB
Line 
1<?php
2
3include_once('../global.php');
4
5$Config['Web']['ShowErrors'] = 1;
6
7$DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` WHERE `Member` = 0');
8while($Router = $DbResult3->fetch_assoc())
9{
10 echo($Router['DHCP']."\n");
11 $Commands = array();
12 $Commands[] = '/tool netwatch print terse';
13 $Commands = implode(';', $Commands);
14 $Command = '/usr/bin/ssh -o ConnectTimeout=5 -l '.$Config['MainRouter']['UserName'].' -i generators/id_dsa '.$Router['DHCP'].' "'.$Commands.'"';
15 //echo($Command."\n");
16 $Output = '';
17 exec($Command, $Output);
18 array_pop($Output);
19 //print_r($Output);
20 foreach($Output as $Row)
21 {
22 $Row = substr($Row, 6);
23 $RowParts = explode(' ', $Row);
24 $Properties = array();
25 foreach($RowParts as $Index => $Item)
26 {
27 if(strpos($Item, '=') !== false)
28 {
29 $ItemParts = explode('=', $Item);
30 $Properties[$ItemParts[0]] = $ItemParts[1];
31 }
32 }
33 if($Properties['status'] == 'up')
34 {
35 $Online = 1;
36 $Values = array('Online' => $Online, 'LastOnline' => 'NOW()');
37 } else
38 {
39 $Online = 0;
40 $Values = array('Online' => $Online);
41 }
42
43 $DbResult = $Database->update('NetworkInterface', 'LocalIP = "'.$Properties['host'].'"', $Values);
44 if($Online == 1)
45 {
46 $DbResult = $Database->select('NetworkInterface', 'Id', 'LocalIP = "'.$Properties['host'].'"');
47 $DbRow = $DbResult->fetch_assoc();
48 $HostId = $DbRow['Id'];
49 $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
50 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"))');
51 $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
52 }
53 }
54}
55
56// Update device online state
57$DbResult = $Database->select('NetworkDevice', 'Id', 'Used=1');
58while($Device = $DbResult->fetch_assoc())
59{
60 $DbResult2 = $Database->select('NetworkInterface', 'SUM(Online)', 'Device='.$Device['Id']);
61 $DbRow = $DbResult2->fetch_array();
62 if($DbRow['SUM(Online)'] > 0) $Online = 1; else $Online = 0;
63 $Database->update('NetworkDevice', 'Id='.$Device['Id'], array('Online' => $Online));
64}
65
66?>
Note: See TracBrowser for help on using the repository browser.