source: trunk/system/generators/netwatch_import.php@ 507

Last change on this file since 507 was 507, checked in by chronos, 12 years ago
  • Opraveno: Generování nastavení sítě. Generování front Queue nyní pracuje s přiřazením služeb k zařízením a podsítím.
  • Opraveno: Zjišťování adresáře souborů na disku dle id adresáře.
File size: 2.8 KB
Line 
1<?php
2
3if(isset($_SERVER['REMOTE_ADDR'])) die();
4include('../../Common/Global.php');
5include('../routerboard.php');
6include('common.php');
7$Path = array('tool', 'netwatch');
8$Period = 60; // every 60 seconds
9$Database = &$System->Database;
10
11while(1)
12{
13 $StartTime = time();
14
15 $DbResult3 = $Database->query('SELECT DHCP, AddressRange, Mask FROM `NetworkSubnet` WHERE (`Configure` = 1) AND (`Member` IS NULL) GROUP BY DHCP');
16 //echo($DbResult3->num_rows);
17 while($Subnet = $DbResult3->fetch_assoc())
18 {
19 echo($Subnet['AddressRange'].'/'.$Subnet['Mask'].' on router '.$Subnet['DHCP']."\n");
20 $Routerboard = new Routerboard();
21 $Routerboard->UserName = $Config['MainRouter']['UserName'];
22 $Routerboard->Timeout = $Config['MainRouter']['ConnectTimeout'];
23 $Routerboard->HostName = $Subnet['DHCP'];
24 $List = $Routerboard->ListGetPrint($Path, array('host', 'status'));
25 foreach($List as $Properties)
26 {
27 //echo($Properties['host'].', ');
28 if($Properties['status'] == 'up')
29 {
30 $Online = 1;
31 $Values = array('Online' => $Online, 'LastOnline' => 'NOW()');
32 //echo($Properties['host']." up\n");
33 } else
34 {
35 $Online = 0;
36 $Values = array('Online' => $Online);
37 //echo($Properties['host']." down\n");
38 }
39
40 $DbResult = $Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"', $Values);
41 }
42 }
43
44 // Update device online state
45 $DbResult = $Database->select('NetworkDevice', 'Id', '`Used`=1');
46 while($Device = $DbResult->fetch_assoc())
47 {
48 $DbResult2 = $Database->select('NetworkInterface', 'SUM(`Online`) AS `SumOnline`', '`Device`='.$Device['Id']);
49 $DbRow = $DbResult2->fetch_array();
50 if($DbRow['SumOnline'] > 0) $Online = 1;
51 else $Online = 0;
52 $Values = array('Online' => $Online);
53 if($Online == 1) $Values['LastOnline'] = 'NOW()';
54 $Database->update('NetworkDevice', 'Id='.$Device['Id'], $Values);
55 }
56
57 // Update interface online statistics
58 $DbResult = $Database->select('NetworkInterface', 'Id', '`Online` = 1');
59 while($Interface = $DbResult->fetch_assoc())
60 {
61 $DbResult2 = $Database->select('NetworkInterfaceStat', '*', '(`NetworkInterface`="'.$Interface['Id'].'") AND (`Time` = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
62 if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO `NetworkInterfaceStat` (`NetworkInterface`, `Time`, `PingCount`) VALUES ("'.$Interface['Id'].'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"), 1)');
63 else $Database->query('UPDATE `NetworkInterfaceStat` SET `PingCount` = `PingCount` + 1 WHERE (`NetworkInterface`="'.$Interface['Id'].'") AND (`Time` = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
64 }
65
66 $EndTime = time();
67 $Delay = $Period - ($EndTime - $StartTime);
68 if($Delay < 0) $Delay = 0;
69
70 echo('Waiting '.$Delay.' seconds...'."\n");
71 sleep($Delay);
72}
73
74?>
Note: See TracBrowser for help on using the repository browser.