<?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";}

$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 = mysqli_query($dbcnx,"INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')");
//snmpget system stats
$host = '172.22.0.58';
$community = 'public';

//system description
$sysdesc = snmpget($host, $community, "sysDescr.0");
$sysdesc2 = eregi_replace("STRING:","",$sysdesc);


//system location
$sysloc = snmpget($host, $community, "sysLocation.0");
$sysloc2 = eregi_replace("STRING:","",$sysloc);


//get system name
$sysname = snmpget($host, $community, "system.sysName.0");
$sysname2 = eregi_replace("STRING:","",$sysname);

////get system uptime
$sysup = snmpget($host, $community, "system.sysUpTime.0");
$sysupre = eregi_replace("([0-9]{3})","",$sysup);
$sysupre2 = eregi_replace("Timeticks:","",$sysupre);
$sysupre3 = eregi_replace("[()]","",$sysupre2);

////get tcp connections
$tcpcon = snmpget($host, $community,"tcp.tcpCurrEstab.0");
$tcpconre = eregi_replace("Gauge32:","",$tcpcon);

////get tcp connections
$tcpcon2 = snmpwalk($host, $community, "interfaces.ifTable.");
//$tcpconre2 = eregi_replace("Gauge32:","",$tcpcon);
//.1.3.6.1.2.1.17.4.3
////get tcp connections
//$portstat = snmprealwalk($host, $community,"IF-MIB::ifOperStatus. 43");
//$portstat2 = eregi_replace("INTEGER: ","",$portstat);
////get tcp connections
//$macstat = snmprealwalk($host, $community,"IF-MIB::ifPhysAddress");
//$macstat2 = eregi_replace("STRING: ","",$macstat);

//[EtherLike-MIB::dot3StatsDuplexStatus.47] => INTEGER: fullDuplex(3)
//

//echo '
//System Name: '.$sysname2.'<br>
//
//System Uptime: '.$sysupre3.'<br>
//Current Tcp Connections: '.$tcpconre.'<br>
//System Description: '.$sysdesc2.'<br>
//System Location: '.$sysloc2.'<br>
//Test Connections: '.$tcpconre.'<br>
echo 'System Location: '.print_r($tcpcon2).'<br><hr />';
//Port status: '.print_r($portstat).'<br><hr />
//MAC-s: '.print_r($macstat).'<br>
//    ';

$ifDescr = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifDescr");
$ifIndex = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifIndex");
$ifAdminStatus = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifPhysAddress");
$ifOperStatus = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifOperStatus");
$ifLastChange = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifLastChange");

print "<table border=1 bgcolor=#ffffff><tr><td>$host</td></tr></table><br>";
print "<table border=1 bgcolor=#ffffff><tr><td>$sysDescr</td></tr></table><br>";
print "<table border=1 bgcolor=#ffffff>";
print "<tr>
        <td>ifIndex</td>
        <td>ifDescr</td>
        <td>ifAdminStatus</td>
        <td>ifOperStatus</td>
        <td>ifLastChange</td>
        </tr>";

for ($i=0; $i<count($ifIndex); $i++) {
        print "<tr>";
        print "<td>$ifIndex[$i]</td>";
        print "<td>$ifDescr[$i]</td>";
        print "<td>$ifAdminStatus[$i]</td>";
        print "<td>$ifOperStatus[$i]</td>";
        print "<td>$ifLastChange[$i]</td>";
        print "</tr>";
}
print "</table>";
//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
//    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' $srv ORDER BY tbl_ip.ip_addr ";
// $res_ip = mysqli_query($dbcnx,$query_ip);
//  if(!$res_ip) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
//   while($result_ip = mysqli_fetch_array($res_ip,MYSQLI_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 = mysqli_query($dbcnx,$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 = mysqli_query($dbcnx,$query_on);
//         if (!$res_on) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
//       }
//    }
//    echo "</tbody></table>";
require_once "../utils/bottom_adm.php";
?>