<?php
///////////////////////////////////////////////////
//2010 (C)
//Карпухин Павел
///////////////////////////////////////////////////

$lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../lang/".$lang."/".$lang.".php")) include "../lang/".$lang."/".$lang.".php";
     else include "../lang/ru/ru.php";

if(!isset($title)) $title = $TEXT['menu-btn22-title'];

require_once "../config_a.php";
require_once "../utils/functions.php";
require_once "../utils/top_adm.php";
$delimiter = ".";

if($result2['administrator'] == 0 && $result2['user'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm.php"; exit();}

if(strlen($_POST['srv_id'])>5) {puterror($result2['skin'],$TEXT['error-srv22']); require_once "../utils/bottom_adm.php"; exit();}
if(strlen($_POST['srv_ch'])>5) {puterror($result2['skin'],$TEXT['error-srv15']); require_once "../utils/bottom_adm.php"; exit();}

$_POST['srv_id'] = rep($_POST['srv_id']);
$_POST['srv_ch'] = rep($_POST['srv_ch']);

if(empty($_POST['srv_id'])) $srv = "";
 else {
     if($_POST['srv_ch'] == "on") $srv ="";
      else $srv = " AND tbl_ip.srv_id = '".$_POST['srv_id']."'";
 }

//*************************************
$ip = $_SERVER['REMOTE_ADDR'];
$doing = $TEXT['log-addr14'];
$what = $TEXT['menu-btn22-title'];
$who = $result2['familiya']." ".$result2['name'];
//*************************************
$querylog = mysql_query("INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')");

echo "<table align='center' width='50%'>
      <thead><tr class='tableheadercat'>
      <td>".$TEXT['analiz-msg-text2']."</td>
      <td>".$TEXT['addr-ip-addr']."</td>
      <td>".$TEXT['addr-mac']."</td>
      <td>".$TEXT['addr-descr']."</td>
      </tr></thead><tbody id='tab'>";

$query_ip = "SELECT tbl_ip.*, tbl_srv.vkl, tbl_srv.ping_ok
    FROM tbl_ip
    JOIN tbl_srv ON tbl_ip.srv_id=tbl_srv.srv_id
    WHERE tbl_ip.vkl_ip ='1' AND tbl_srv.vkl = '1' AND tbl_srv.ping_ok = 'yes' $srv ORDER BY tbl_ip.ip_addr ";
 $res_ip = mysql_query($query_ip);
  if(!$res_ip) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
   while($result_ip = mysql_fetch_array($res_ip,MYSQL_ASSOC))
    {
    $addr = explode($delimiter,$result_ip['ip_addr'],4);
    $oct1 = substr($addr['0'],0,1);
     if($oct1 == '0')
      {
       $oct_res1 = substr($addr['0'],1,1);
        if($oct_res1 == '0')
         {
          $oct_result1 = substr($addr['0'],2,3);
         } else $oct_result1 = substr($addr['0'],1,3);
      } else $oct_result1 = $addr['0'];

    $oct2 = substr($addr['1'],0,1);
     if($oct2 == '0')
      {
       $oct_res2 = substr($addr['1'],1,1);
        if($oct_res2 == '0')
         {
          $oct_result2 = substr($addr['1'],2,3);
         } else $oct_result2 = substr($addr['1'],1,3);
      } else $oct_result2 = $addr['1'];

    $oct3 = substr($addr['2'],0,1);
     if($oct3 == '0')
      {
       $oct_res3 = substr($addr['2'],1,1);
        if($oct_res3 == '0')
         {
          $oct_result3 = substr($addr['2'],2,3);
         } else $oct_result3 = substr($addr['2'],1,3);
      } else $oct_result3 = $addr['2'];

     $oct4 = substr($addr['3'],0,1);
      if($oct4 == '0')
       {
        $oct_res4 = substr($addr['3'],1,1);
         if($oct_res4 == '0')
          {
           $oct_result4 = substr($addr['3'],2,3);
          } else $oct_result4 = substr($addr['3'],1,3);
        } else $oct_result4 = $addr['3'];
     $ip_addres = $oct_result1.".".$oct_result2.".".$oct_result3.".".$oct_result4;

    $check_ip = @exec("ping -c 1 -i 0.2 ".$ip_addres, $errno, $status);
     if($status == 1)
     {
     $connect_ip = "<img src='../skins/".$result2['skin']."/vikl.png'>";
      $query_off = "UPDATE tbl_ip SET state_addr='1', data = CURRENT_DATE() WHERE ip_id = ".$result_ip['ip_id']." AND state_addr='0'";
       $res_off = mysql_query($query_off);
        if (!$res_off) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
     }
      else
       {
       $connect_ip = "<img src='../skins/".$result2['skin']."/vkl.png'>";
       $query_on = "UPDATE tbl_ip SET state_addr='0', data = CURRENT_DATE(), last_acc = CURRENT_DATE() WHERE ip_id = ".$result_ip['ip_id']." AND state_addr='1'";
        $res_on = mysql_query($query_on);
         if (!$res_on) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
       }
       ?>
      <tr>
       <td><?php echo $connect_ip; ?></td>
       <td class="bold_it" ><?php echo $ip_addres; ?></td>
       <td class="bold_it" ><?php echo substr(chunk_split($result_ip['hw'],2,":"),0,-1); ?></td>
       <td class="bold_it" ><?php echo $result_ip['descr']; ?></td>
      </tr>
       <?php
    }
    echo "</tbody></table>";
require_once "../utils/bottom_adm.php";
?>