1 | <?php
|
---|
2 | include('../global.php');
|
---|
3 | //$Database->select_db('share');
|
---|
4 | echo("\n====================== Kontrola online pocitacu ============================\n\n");
|
---|
5 | //while (true)
|
---|
6 | {
|
---|
7 | echo('Nacitam strom sdileni...');
|
---|
8 | $Output = array();
|
---|
9 | exec('smbtree -N -S',$Output,$Return);
|
---|
10 | //echo($Return."\n");
|
---|
11 | echo("OK\n\nSeznam online pocitacu:\n");
|
---|
12 | array_shift($Output);
|
---|
13 | $Online = array(); // Seznam online pocitacu
|
---|
14 | foreach ($Output as $Radek)
|
---|
15 | {
|
---|
16 | if (ord($Radek[0])!=9) continue;
|
---|
17 | $Host = explode(' ',substr($Radek,3));
|
---|
18 | $Host = $Host[0];
|
---|
19 | // echo($Host);
|
---|
20 | $Section = 0;
|
---|
21 | // Zjisti IP a MAC adresu
|
---|
22 | if ($Host=='CENTRALA')
|
---|
23 | {
|
---|
24 | $MAC = '00:E0:4C:20:64:22';
|
---|
25 | $IP = '192.168.0.1';
|
---|
26 | $Section = 0;
|
---|
27 | } else
|
---|
28 | if ($Host=='CENTRALA2')
|
---|
29 | {
|
---|
30 | $MAC = '00:E0:4C:20:64:22';
|
---|
31 | $IP = '192.168.0.11';
|
---|
32 | $Section = 0;
|
---|
33 | } else
|
---|
34 | {
|
---|
35 | $Output = array();
|
---|
36 |
|
---|
37 | //echo('arping -c 1 '.$Host);
|
---|
38 | exec('arping -c 1 '.$Host,$Output);
|
---|
39 | if (count($Output)!=4)
|
---|
40 | {
|
---|
41 | $Output = array();
|
---|
42 | exec('arping -I wlan0 -c 1 '.$Host,$Output);
|
---|
43 | if (count($Output)!=4)
|
---|
44 | {
|
---|
45 | $Output = array();
|
---|
46 | exec('arping -I wlan1 -c 1 '.$Host,$Output);
|
---|
47 | if (count($Output)!=4)
|
---|
48 | {
|
---|
49 | $Output = array();
|
---|
50 | exec('arping -I wlan2 -c 1 '.$Host,$Output);
|
---|
51 | if (count($Output)!=4)
|
---|
52 | {
|
---|
53 | $Output = array();
|
---|
54 | exec('arping -I eth2 -c 1 '.$Host,$Output);
|
---|
55 | if (count($Output)!=4) continue;
|
---|
56 | else $Section = 4;
|
---|
57 | } else $Section = 3;
|
---|
58 | } else $Section = 2;
|
---|
59 | } else $Section = 1;
|
---|
60 | } else $Section = 0;
|
---|
61 | $Output = explode(' ',$Output[1]);
|
---|
62 | $MAC = substr($Output[4],1,-1);
|
---|
63 | $IP = $Output[3];
|
---|
64 | }
|
---|
65 | echo($Host.": IP:".$IP." MAC:".$MAC." Sekce:".$Section."\n");
|
---|
66 | array_push($Online, array('host' => $Host, 'IP' => $IP, 'MAC' => $MAC, 'section' => $Section));
|
---|
67 | }
|
---|
68 |
|
---|
69 | // Deaktivuj predchozi online pocitace
|
---|
70 | $Database->update('hosts', 1, array('online' => 0));
|
---|
71 |
|
---|
72 | // Aktivuj online pocitace
|
---|
73 | foreach ($Online as $Item)
|
---|
74 | {
|
---|
75 | $DbResult = $Database->query("SELECT * FROM hosts WHERE name='".$Item['host']."'");
|
---|
76 | if ($DbResult->num_rows > 0)
|
---|
77 | {
|
---|
78 | $Database->update('hosts',"name='".$Item['host']."'",array( 'IP' => $Item['IP'], 'MAC' => $Item['MAC'], 'online' => 1, 'lastdate' => 'NOW()', 'section' => $Section));
|
---|
79 | } else $Database->insert('hosts',array('name' => $Item['host'], 'IP' => $Item['IP'], 'MAC' => $Item['MAC'], 'online' => 1,'date' => 'NOW()','lastdate' => 'NOW()', 'section' => $Section));
|
---|
80 | }
|
---|
81 |
|
---|
82 | echo("\nSeznam offline pocitacu:\n");
|
---|
83 | $DbResult = $Database->query("SELECT * FROM hosts WHERE online=0");
|
---|
84 | while ($Row = $DbResult->fetch_array())
|
---|
85 | {
|
---|
86 | echo($Row['name'].", ");
|
---|
87 | }
|
---|
88 | // sleep(1000);
|
---|
89 | //echo("\nCekam minutu...");
|
---|
90 | //sleep(60);
|
---|
91 | //echo("OK\n\n");
|
---|
92 | }
|
---|
93 | echo("\n\nKontrola dokoncena\n\n");
|
---|