<?php


$error5="error5 Przykro nam, serwis jest dostepny wylacznie dla
autoryzowanych uzytkownikow $REMOTE_ADDR";

//error_reporting(E_ALL);

if(file_exists(".config.php")) include(".config.php");

//echo "<br>komputery_arr:".$komputery_arr."<br>";
require("$komputery_arr");
//echo $DUPA . "dopa";
if(in_array("$REMOTE_ADDR",$KOMPUTERY))  $czy_error_5=1 ;


//echo "$REMOTE_ADDR $czy_error_5 <br>" ;
if($czy_error_5) {



foreach ($_GET as $k => $v) {
 $_GET[$k]=addslashes($_GET[$k]);
 $v=addslashes($v);
// $v=ereg_replace(';','',$v);
 eval(" \$$k = \"$v\" ;");
}
foreach ($_POST as $k => $v) {
 $_POST[$k]=addslashes($_POST[$k]);
 $v=addslashes($v);
// $v=ereg_replace(';','',$v);
 eval(" \$$k = \"$v\" ;");
}



function GDATE($timestamp) {
$today=getdate($timestamp);
return "Updated " . $today[year] ."-" . $today[mon] . "-" . $today[mday] . " " .
 $today[hours] . ":" . $today[minutes] . "." . $today[seconds] ;
}




function FORMATER($VAR) {
if( $VAR > 1000000000 ) {
$VAR= $VAR / 1000000000 ;
$UNIT=G;
 } else if( $VAR > 1000000 ) {
$VAR= $VAR / 1000000 ;
$UNIT=M;
 } else if( $VAR > 1000 ) {
$VAR= $VAR / 1000 ;
$UNIT=k;
 }
$VAR=number_format($VAR,2,".","");
$UNIT=$VAR ."_" . $UNIT;
return $UNIT; 
}

function TFORMATER($VAR) {
if( $VAR > 2592000 ) {
$VAR= $VAR / 2592000 ;
$UNIT=Months;
 } else if( $VAR > 86400 ) {
$VAR= $VAR / 86400 ;
$UNIT=Days;
 } else if( $VAR > 3600 ) {
$VAR= $VAR / 3600 ;
$UNIT=Hours;
 } else if( $VAR > 60 ) {
$VAR= $VAR / 60 ;
$UNIT=Minutes;
 } else {
$UNIT=secs;
 } 
$VAR=number_format($VAR,2,".","");
$UNIT=$VAR ."_" . $UNIT;
return $UNIT; 
}



function VARDEF() {
global $SPEED , $SPEED2 ;
  { 
echo "* N_AVG_TRAFFIC = { 
";
for (;(key($SPEED[key($SPEED)])); next($SPEED[key($SPEED)])) {
if($SPEED["TT"][key($SPEED["TB"])]==0) $SPEED["TT"][key($SPEED["TB"])]=1 ;
$MDATE = $SPEED["TS"][key($SPEED["TB"])] + $SPEED["LD"][key($SPEED["TB"])] ;

$CURRENT_TARIFY = key($SPEED["TB"]);
$TOTAL_BYTES=$SPEED["TB"][key($SPEED["TB"])];
$TOTAL_BYTES=FORMATER($TOTAL_BYTES);
$TOTAL_TIME=$SPEED["TT"][key($SPEED["TB"])];
$TOTAL_TIME=TFORMATER($TOTAL_TIME);
$TOTAL_AVG_TRAFFIC=$SPEED["TB"][key($SPEED["TB"])] / $SPEED["TT"][key($SPEED["TB"])];
$TOTAL_AVG_TRAFFIC=FORMATER($TOTAL_AVG_TRAFFIC);
$LAST_BYTES=$SPEED["LB"][key($SPEED["TB"])];
$LAST_BYTES=FORMATER($LAST_BYTES);
$LAST_TIME=$SPEED["LD"][key($SPEED["TB"])];
$LAST_TIME=TFORMATER($LAST_TIME);
$LAST_AVG_TRAFFIC=$SPEED["LB"][key($SPEED["TB"])] / $SPEED["LD"][key($SPEED["TB"])];
$LAST_AVG_TRAFFIC=FORMATER($LAST_AVG_TRAFFIC);
$LAST_UPDATE=GDATE($MDATE);

echo "Total_BYTES(" . key($SPEED["TB"]) . ") " . 
 $TOTAL_BYTES . "bytes, during " . 
 $TOTAL_TIME . " AVG_T=" .
 $TOTAL_AVG_TRAFFIC . "bps
Last Bytes(" . $CURRENT_TARIFY . ") " . 
 $LAST_BYTES . "bytes, during " . 
 $LAST_TIME  . " L_AVG_T=" . 
 $LAST_AVG_TRAFFIC  . "bps 
 " . $LAST_UPDATE . "
" ;

$SPEED2["TB"] = $SPEED2["TB"] + $SPEED["TB"][key($SPEED["TB"])] + $SPEED["LB"][key($SPEED["TB"])] ;
$SPEED2["TT"] = $SPEED2["TT"] + $SPEED["TT"][key($SPEED["TB"])] + $SPEED["LD"][key($SPEED["TB"])] ;
   }
  }

return $VAR;
}





$VERSION="2003-12-09";



$ADM_USER=$SQL_USER ;
$ADM_USER_PASS=$SQL_USER_PASS ;


if($test) echo "OK:$VERSION"; else if($telbox_index) {
     $conn=mysql_pconnect($INTERFACE_ADDR,$ADM_USER,$ADM_USER_PASS);
     if (!$conn) die("ERROR podczas tworzenia polaczenia do bazy $SQL_DATABASE !\n");
     mysql_select_db($SQL_DATABASE) or die("ERROR podczas wyboru bazy!");
     $zapSQL="SELECT * FROM TELBOXES where T_NETWORK_SERVER='$dana1' and A_STATUS!='DELETED' limit 0,1000 ;";
//echo "$zapSQL";
     $result = mysql_query($zapSQL,$conn) or die("Blad zapytania!");
 //   $user=mysql_fetch_object($result);
 //    if ((mysql_num_rows($result)>0) && ($user->pass==$PHP_AUTH_PW))
  while ($h=mysql_fetch_object($result))
  {
   echo "$h->T_TELBOX_NAME;$h->T_TELBOX_NEIGHBOUR_IN;";
   echo "$h->A_STATUS;$h->A_STATUS_INFO;$h->A_PROBLEM;";
   echo "$h->A_PROBLEM_DESC;$h->T_TELBOX_TYPE;$h->T_TELBOX_SAVE;<br>\n";
  }
//NAME;NEI_IN;STATUS;STAT_INF;PROBLEM;OPIS;TYPE;SAVE
   } 
 else {
     $conn=mysql_pconnect($INTERFACE_ADDR,$ADM_USER,$ADM_USER_PASS);
     if (!$conn) die("ERROR podczas tworzenia polaczenia do bazy $SQL_DATABASE !\n");
     mysql_select_db($SQL_DATABASE) or die("ERROR podczas wyboru bazy!");
     $zapSQL="SELECT * FROM $SQL_TABLE_USERS where S_IP='$dana1' OR S_HOST='$dana1' OR S_HW='$dana1' OR P_NAME like '%$dana1%' OR S_ADDRESS_STREET like '$dana1%' OR T_TELBOX_ADDRESS like '$dana1%' OR P_PHONE like '%".$dana1."%' OR S_ALIAS like '$dana1'  OR ID_BILLING_USERS='$dana1' ORDER BY S_IP limit 0,100 ;";
//echo "$zapSQL";
     $result = mysql_query($zapSQL,$conn) or die("Blad zapytania!");
 //   $user=mysql_fetch_object($result);
 //    if ((mysql_num_rows($result)>0) && ($user->pass==$PHP_AUTH_PW))
while ($h=mysql_fetch_object($result))
{
echo "\n\n"; 
if(strstr($h->A_STATUS,NORMAL)) { if(strstr($h->S_HWSTAT,BLOCK)) echo " BAD_BLOCK_OPTION__REPAIR_RECORD *" ;} else echo " $h->A_STATUS *" ;

echo " $h->S_IP;";
echo " $h->P_NAME *";
echo " $h->S_HOST *";
if(!strstr($h->S_ALIAS,"192.168")) {
if(strstr($h->S_ALIAS,"@")) echo " $h->S_ALIAS *" ; else echo " <BAD ALIAS: $h->S_ALIAS> *";
} else echo " <ALIAS EMPTY> *";
$operator=ereg_replace("/.*","",$h->P_DEALNUMBER);
echo " $operator *";

echo "\n$h->P_PHONE *";
if($h->T_NETWORK_SERVER) echo " $h->T_NETWORK_SERVER *";
if(strstr($h->S_HW,BLOCK)) {
echo " BLOCK *";
} else {
if(strstr($h->S_HW,FREE)) {
echo " FREE *";
 
}  else { 
if(!$h->S_HW) echo " <HW EMPTY> *"; else echo " $h->S_HW *"; } 
}
echo " $h->S_ADDRESS_STREET " ;
if($h->T_TELBOX_ADDRESS) echo "[$h->T_TELBOX_ADDRESS] ";  
echo "*";
echo " SPD$h->P_SERVICE_QUOTA * $h->S_HWSTAT";
if($h->A_PROBLEM) echo " * $h->A_PROBLEM
* PROBLEM_DESC: $h->A_PROBLEM_DESC *"; 
if($h->L_APPOITMENT_TYPE) echo "
* SPOTKANIA: $h->L_APPOITMENT_TYPE DATA: $h->L_APPOITMENT_DATE ($h->L_APPOITMENT_PERIOD"."min) *
 PRACOWNIK:$h->L_APPOITMENT_USER INF:($h->L_APPOITMENT_INFO)"; 
if($dana2==ALL or $dana2==all) { echo "
PRECIOSION-INFORMATIONS:
* T_WHEN_CONNECTED= $h->T_WHEN_CONNECTED 
* T_WHO_CONNECTED= $h->T_WHO_CONNECTED
* A_RECORD_CREATE_DATE= $h->A_RECORD_CREATE_DATE
* A_RECORD_CREATE_AUTHOR= $h->A_RECORD_CREATE_AUTHOR
";
//-CBQ START
if($h->N_AVG_TRAFFIC) {
eval("\$SPEED = $h->N_AVG_TRAFFIC ;");
$SPEED2["TB"]=1;
$SPEED2["TT"]=1;



VARDEF();
$TOTAL_B="" ;
$TOTAL_T="" ;
//print_r($SPEED);
 $TOTAL_AVERAGE=$SPEED2["TB"] / $SPEED2["TT"];
 $TOTAL_AVERAGE=FORMATER($TOTAL_AVERAGE);
echo "                  } = TOTAL_AVERAGE " . $TOTAL_AVERAGE . "_bps";
    } else echo "* N_AVG_SPEED not reported";
//echo "nowa";
   } //if($dana2==ALL or $dana2==all) 
}
}
} else {
echo $error5 ;
}
//echo "\n";
?>

