1 | <?php
|
---|
2 |
|
---|
3 | if(isset($_SERVER['REMOTE_ADDR'])) die();
|
---|
4 | include('../../global.php');
|
---|
5 | include('../routerboard.php');
|
---|
6 | $Path = array('tool', 'netwatch');
|
---|
7 |
|
---|
8 | $DbResult3 = $Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` = 0');
|
---|
9 | while($Subnet = $DbResult3->fetch_assoc())
|
---|
10 | {
|
---|
11 | echo($Subnet['AddressRange'].'/'.$Subnet['Mask'].' on router '.$Subnet['DHCP']."\n");
|
---|
12 | $Routerboard = new Routerboard();
|
---|
13 | $Routerboard->UserName = $Config['MainRouter']['UserName'];
|
---|
14 | $Routerboard->Timeout = $Config['MainRouter']['ConnectTimeout'];
|
---|
15 | $Routerboard->HostName = $Subnet['DHCP'];
|
---|
16 | $List = $Routerboard->ListGetPrint($Path, array('host', 'status'));
|
---|
17 |
|
---|
18 | //print_r($List);
|
---|
19 | foreach($List as $Properties)
|
---|
20 | {
|
---|
21 | if(IsAddressInSubnet($Properties['host'], $Subnet['AddressRange'], $Subnet['Mask']))
|
---|
22 | {
|
---|
23 | if($Properties['status'] == 'up')
|
---|
24 | {
|
---|
25 | $Online = 1;
|
---|
26 | $Values = array('Online' => $Online, 'LastOnline' => 'NOW()');
|
---|
27 | } else
|
---|
28 | {
|
---|
29 | $Online = 0;
|
---|
30 | $Values = array('Online' => $Online);
|
---|
31 | }
|
---|
32 |
|
---|
33 | $DbResult = $Database->update('NetworkInterface', 'LocalIP = "'.$Properties['host'].'"', $Values);
|
---|
34 | if($Online == 1)
|
---|
35 | {
|
---|
36 | $DbResult = $Database->select('NetworkInterface', 'Id', 'LocalIP = "'.$Properties['host'].'"');
|
---|
37 | $DbRow = $DbResult->fetch_assoc();
|
---|
38 | $HostId = $DbRow['Id'];
|
---|
39 | $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
|
---|
40 | 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"))');
|
---|
41 | $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | // Update device online state
|
---|
48 | $DbResult = $Database->select('NetworkDevice', 'Id', 'Used=1');
|
---|
49 | while($Device = $DbResult->fetch_assoc())
|
---|
50 | {
|
---|
51 | $DbResult2 = $Database->select('NetworkInterface', 'SUM(Online)', 'Device='.$Device['Id']);
|
---|
52 | $DbRow = $DbResult2->fetch_array();
|
---|
53 | if($DbRow['SUM(Online)'] > 0) $Online = 1; else $Online = 0;
|
---|
54 | $Database->update('NetworkDevice', 'Id='.$Device['Id'], array('Online' => $Online));
|
---|
55 | }
|
---|
56 |
|
---|
57 | ?>
|
---|