1006
правок
Kekaloav (обсуждение | вклад) |
Kekaloav (обсуждение | вклад) |
||
Строка 1: | Строка 1: | ||
Строка 685: | Строка 686: | ||
#пароль к vnc | #пароль к vnc | ||
$vncpass="pass"; | $vncpass="pass"; | ||
#mac -> ip | |||
function arp($ip) | |||
{ | |||
$r=shell_exec("/usr/sbin/arp -n -a ".$ip); | |||
if(preg_match_all("/[[:xdigit:]]{2}:[[:xdigit:]]{2}:[[:xdigit:]]{2}:[[:xdigit:]]{2}:[[:xdigit:]]{2}:[[:xdigit:]]{2}/su", $r, $m)) | |||
{ return $m[0][0]; } | |||
return ""; | |||
}; | |||
Строка 693: | Строка 703: | ||
global $webroot; | global $webroot; | ||
$val=file_get_contents($webroot."reg.sh"); | $val=file_get_contents($webroot."reg.sh"); | ||
file_put_contents($base.$nm,$ip); | $mac=arp($ip); | ||
file_put_contents($base.$nm,$ip." ".$mac); | |||
return; | return; | ||
}; | }; | ||
Строка 713: | Строка 724: | ||
global $webssh; | global $webssh; | ||
global $novnc; | global $novnc; | ||
global vncpass; | global $vncpass; | ||
echo "<table> <tr> <th>NAME</th> <th>IP</th> <th>LAST TIME</th><th>SSH</th> <th>VNC</th></tr>"; | echo "<table> <tr> <th>NAME</th> <th>IP</th> <th>MAC</th><th>LAST TIME</th><th>SSH</th> <th>VNC</th><th>STA</th></tr>"; | ||
$dir=`ls $base/$mask`; | $dir=`ls $base/$mask`; | ||
foreach (explode("\n",$dir) as $n) { | foreach (explode("\n",$dir) as $n) { | ||
$name=basename($n); | $name=basename($n); | ||
$ | $a=explode(" ",file_get_contents($base.$name)); | ||
$ip=$a[0]; | |||
$mac=$a[1]; | |||
$ssh=$webssh."/?hostname=$ip&username=root&privatekey=localfile"; | $ssh=$webssh."/?hostname=$ip&username=root&privatekey=localfile"; | ||
$vnc=$novnc."/vnc_lite.html?p="+ | $vnc=$novnc."/vnc_lite.html?p="+urlencode(base64_encode($vncpass))+"&scale=true&path=websockify/?token=$name"; | ||
$tm=date ("d/m H:i:s", filemtime($base.$name)); | $tm=date ("d/m H:i:s", filemtime($base.$name)); | ||
$ping="<img id=\"state$name\" style=\"width:32px;height:32px;\" src=\"/?ping=$ip\" />"; | |||
if($name !="") | if($name !="") | ||
{ | { | ||
echo "<tr> <th>$name</th> <th>$ip</th> <th>$tm</th> <th><a href=\"$ssh\">SSH</a></th> <th><a href=\"$vnc\">VNC</a></th> </tr>\n"; | echo "<tr> <th>$name</th> <th>$ip</th> <th>$mac</th> <th>$tm</th> <th><a href=\"$ssh\">SSH</a></th> <th><a href=\"$vnc\">VNC</a></th><td>$ping</td> </tr>\n"; | ||
}; | }; | ||
}; | }; | ||
Строка 749: | Строка 765: | ||
}; | }; | ||
if(isset($_REQUEST['ping'])) { | |||
$ip=$_REQUEST['ping']; | |||
$ok=0; | |||
if(strlen($ip)>5) { $ans=shell_exec("ping -W .2 -c 2 -i .3 ".$ip); if(strpos($ans,"100%")==false) $ok=1; }; | |||
header ("Content-type: image/png"); | |||
$image = imagecreate(32,32); | |||
$color = imagecolorallocate($image,$ok? 0:255,$ok? 255:0, 0); | |||
imagefill($image, 0, 0, $color); | |||
imagepng($image); | |||
exit(); | |||
}; | |||
Строка 821: | Строка 849: | ||
</body> | </body> | ||
</html> | </html> | ||
</syntaxhighlight> | </syntaxhighlight> | ||