source: trunk/system/netwatch_import.php@ 176

Last change on this file since 176 was 168, checked in by george, 16 years ago
  • Přidáno: Ukládání poslední otevřené stránky do tabulky online uživatelů.
  • Opraveno: Nesledovat online uživatele pokud je skript spuštěn místně.
  • Opraveno: Chyba zobrazování odkazů na hlavní stránce dle práv uživatelů.
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1<?php
2include_once('../global.php');
3
4$UserName = 'admin-ssh';
5$Config['Web']['ShowErrors'] = 1;
6
7$DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet`');
8while($Router = $DbResult3->fetch_assoc())
9{
10 $Commands = array();
11 $Commands[] = '/tool netwatch print terse';
12 $Commands = implode(';', $Commands);
13 $Command = '/usr/bin/ssh -l '.$UserName.' -i generators/id_dsa '.$Router['DHCP'].' "'.$Commands.'"';
14 //echo($Command."\n");
15 $Output = '';
16 exec($Command, $Output);
17 array_pop($Output);
18 //print_r($Output);
19 foreach($Output as $Row)
20 {
21 $Row = substr($Row, 6);
22 $RowParts = explode(' ', $Row);
23 $Properties = array();
24 foreach($RowParts as $Index => $Item)
25 {
26 if(strpos($Item, '=') !== false)
27 {
28 $ItemParts = explode('=', $Item);
29 $Properties[$ItemParts[0]] = $ItemParts[1];
30 }
31 }
32 if($Properties['status'] == 'up')
33 {
34 $Online = 1;
35 $Values = array('online' => $Online, 'last_online' => 'NOW()');
36 } else
37 {
38 $Online = 0;
39 $Values = array('online' => $Online);
40 }
41
42 $DbResult = $Database->update('hosts', 'IP="'.$Properties['host'].'"', $Values);
43 if($Online == 1)
44 {
45 $DbResult = $Database->select('hosts', 'id', 'IP="'.$Properties['host'].'"');
46 $DbRow = $DbResult->fetch_array();
47 $HostId = $DbRow['id'];
48 $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
49 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"))');
50 $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
51 }
52 }
53}
54
55?>
Note: See TracBrowser for help on using the repository browser.