|
|
Строка 1: |
Строка 1: |
| | |
|
| |
|
|
| |
|
Строка 668: |
Строка 669: |
| '''Данная версия index.php предельно упрощена специально для wiki и может содержать ошибки.''' | | '''Данная версия index.php предельно упрощена специально для wiki и может содержать ошибки.''' |
|
| |
|
| index.php :
| | https://os.mos.ru/git/andreyka648/adminka/src/master/index.php |
| | |
| <syntaxhighlight lang="php">
| |
| <?php
| |
| | |
| $myip=$_SERVER['SERVER_ADDR'];
| |
| $webroot="/var/www/html/";
| |
| $base=$webroot."base/";
| |
| #ссылка на установленный webssh
| |
| $webssh="http://".$myip.":8081";
| |
| #ссылка на установленный novnc
| |
| $novnc="http://".$myip.":6080";
| |
| #Список компьютерных классов
| |
| $cc=array("КАБ34" => "m648-1-34a","КАБ21"=>"m648-1-21a","КАБ41"=>"m648-1-41","КАБ42"=>"m648-1-42");
| |
| #файл токенов novnc
| |
| $confignovnc="/etc/novnc/token.list";
| |
| #пароль к vnc
| |
| $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 "";
| |
| };
| |
| | |
| | |
| #сохранение именив "базе"
| |
| function save_name($nm,$ip)
| |
| {
| |
| global $base;
| |
| global $webroot;
| |
| $val=file_get_contents($webroot."reg.sh");
| |
| $mac=arp($ip);
| |
| file_put_contents($base.$nm,$ip." ".$mac);
| |
| return;
| |
| };
| |
| | |
| #вернуть текстовый файл
| |
| function rettext($text,$name){
| |
| header("Content-Type: text/plain");
| |
| header("Content-Transfer-Encoding: Binary");
| |
| header("Content-Length:".strlen($text));
| |
| header("Content-Disposition: attachment; filename=\"".$name."\"");
| |
| echo str_replace("\r","",$text);
| |
| exit();
| |
| };
| |
| | |
| #вывод одного раздела таблицф
| |
| function print_table($mask)
| |
| {
| |
| global $base;
| |
| global $webssh;
| |
| global $novnc;
| |
| global $vncpass;
| |
| 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`;
| |
| foreach (explode("\n",$dir) as $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";
| |
| $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));
| |
| | |
| $ping="<img id=\"state$name\" style=\"width:32px;height:32px;\" src=\"/?ping=$ip\" />";
| |
| | |
| if($name !="")
| |
| {
| |
| 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";
| |
| };
| |
| };
| |
| echo "</table>";
| |
| };
| |
| | |
| | |
| #обновление таблицы novnc
| |
| function renewvnc()
| |
| {
| |
| global $confignovnc;
| |
| global $base;
| |
| $dir=`ls $base/?*`;
| |
| | |
| foreach (explode("\n",$dir) as $n) {
| |
| $name=basename($n);
| |
| $ip=file_get_contents($base.$name);
| |
| $ar[]=$name.": ".$ip.":5900";
| |
| };
| |
| | |
| asort($ar);$s=join("\n",$ar);
| |
| $x=file_get_contents($confignovnc);
| |
| if($s!=$x) { file_put_contents($confignovnc,$s); };
| |
| };
| |
| | |
| | |
| 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();
| |
| };
| |
| | |
| | |
| if(isset($_REQUEST['start'])) {
| |
| $name=$_REQUEST['start'];
| |
| $a=explode("-",$name);
| |
| $val=file_get_contents($webroot."start.sh");
| |
| save_name($name,$_SERVER['REMOTE_ADDR']);
| |
| rettext($val,'start.sh');
| |
| };
| |
| | |
| if(isset($_REQUEST['reg'])) {
| |
| $name=$_REQUEST['reg'];
| |
| $a=explode("-",$name);
| |
| $val=file_get_contents($webroot."reg.sh");
| |
| save_name($name,$_SERVER['REMOTE_ADDR']);
| |
| rettext($val,'reg.sh');
| |
| };
| |
| | |
| if(isset($_REQUEST['player'])) {
| |
| echo "<!DOCTYPE html>
| |
| <html>
| |
| <head>
| |
| </head>
| |
| <body>
| |
| <video id=\"video\" controls preload=\"auto\" controls=\"controls\" style='width:80%; height:80%; max-height:100%;' autoplay >
| |
| <source src='http://".$_REQUEST['player']."/' type='video/mp4'>
| |
| </video>
| |
| </body>
| |
| </html>";
| |
| exit();
| |
| };
| |
| | |
| | |
| renewvnc();
| |
| | |
| ?>
| |
| | |
| | |
| <!DOCTYPE html><html>
| |
| <head lang="ru">
| |
| <meta charset="utf-8">
| |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
| |
| <meta name="viewport" content="width=device-width, initial-scale=1">
| |
| <title>Admin</title>
| |
| <style>
| |
| table,tr,td,th {
| |
| border-collapse: collapse;
| |
| text-align: left;
| |
| border: 1px solid black;
| |
| margin: 20px;
| |
| padding: 2px;
| |
| }
| |
| | |
| </style>
| |
| </head>
| |
| <body>
| |
| | |
| <?php
| |
| echo "<h1>Ссылки на оборудование</h1>";
| |
| echo "<h2>Доски</h2>";
| |
| print_table("p*");
| |
| echo "<h2>Моноблоки</h2>";
| |
| foreach ($cc as $k=>$v) {
| |
| echo "<h3>$k</h3>";
| |
| print_table($v."*");
| |
| }
| |
| echo "<h2>Ноутбуки</h2>";
| |
| print_table("n*");
| |
| | |
| ?>
| |
| </body>
| |
| </html>
| |
| </syntaxhighlight>
| |
|
| |
|
| Необходимо создать каталог /var/www/html/base/ и дать ему права на доступ от php | | Необходимо создать каталог /var/www/html/base/ и дать ему права на доступ от php |