묻고답하기

<style type="text/css">
@import url("white.css");
</style>

<?php
class trafficInfo {
 function xml_info($xml, $domain) {
  $fileArr = explode("\n", $xml);
  $fileCnt = count($fileArr);
  for($i=0; $i<$fileCnt; $i++) {
   if(strpos($fileArr[$i], '<domain-'.$domain.'>') !== false) {
    $get = true;
   }
   if($get) {
    $z[] = preg_replace(";\t*;", "", $fileArr[$i]);$fileArr[$i];
   }
   if(strpos($fileArr[$i], '</domain-'.$domain.'>') !== false) {
    break;
   }
  }
  if($z && is_array($z)) {
   //print_r($z);
   $file = implode("", $z);
   $xmlParser = xml_parser_create();
   xml_parse_into_struct($xmlParser, $file, $vals, $index);
   xml_parser_free($xmlParser);

   $params = array();
   $level = array();
   foreach ($vals as $xmlElem) {
    if ($xmlElem['type'] == 'open') {
     if (array_key_exists('attributes',$xmlElem)) {
      list($level[$xmlElem['level']],$extra) = array_values($xmlElem['attributes']);
     } else {
      $level[$xmlElem['level'+ '+ ']] = $xmlElem['tag'];
     }
    }
    if ($xmlElem['type'] == 'complete') {
     $start_level = 1;
     $php_stmt = '$params';
     while($start_level < $xmlElem['level']) {
      $php_stmt .= '[$level['.$start_level.']]';
      $start_level++;
     }
     $php_stmt .= '[$xmlElem[\'tag\']] = $xmlElem[\'value\'];';
     eval($php_stmt);
    }
   }
  } else {
   exit(" <font color=\"red\">에러 : XML 정보 불러오기 실패</font>\n<br />\n");
  }
  $this->usageTraffic = $this->kb_to_mb(str_replace('KiB', '', $params['DOMAIN-'.strtoupper($domain)]['USAGES']['TOTAL']));
  $this->totalTraffic = $this->kb_to_mb(str_replace('KB', '', $params['DOMAIN-'.strtoupper($domain)]['LIMITS']['TOTAL']));
  $this->percent = round($this->usageTraffic / $this->totalTraffic * 1000) / 1000 * 100;
  return $params;
 }
 function hosting_traffic($html, $domain) {
  $file = explode("\n", $html);
  $flags = 0;
  for($i=0, $fileNum=count($file); $i<$fileNum; $i++) {
   if(strpos($file[$i], $domain) !== false) {
    if($flags < 2) {
     $flags++;
    } else {
     break;
    }
   }
  }
  for($ii=$i+1, $userInfo=$i+11; $ii<$userInfo; $ii++) {
   $file_ .=  $file[$ii]."\n";
  }
  preg_match_all(';<td class="(red|critical|green|yellow)">([^<]+)</td>;', $file_, $match);
  $this->usageTraffic = $match[2][3];
  $this->totalTraffic = $match[2][7];
  $this->percent = round($this->usageTraffic / $this->totalTraffic * 1000) / 1000 * 100;
  return $match;
 }
 function kb_to_mb($kb) {
  return $kb/1000;
 }
 function get_traffic($domain, $accountId, $accountPass, $trafficPath) {
  $fp = fsockopen($domain, 80, $errstr, $errno, 30);
  if($trafficPath != 'traffic' && $trafficPath != 'traffic?xml') {
   exit('정확히 적어주시길 바랍니다.');
  }
  if(!$fp) {
   exit('정확히 적어주시길 바랍니다. ('.$errstr.")");
  } else {
   $data = "GET /".$trafficPath." HTTP/1.0\r\n";
   $data .= "Host: ".$domain."\r\n";
   $data .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
   $data .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,image/jpeg,image/gif,*/*\r\n";
   $data .= "Accept-encoding: gzip\r\n";
   $data .= "Accept-language: ko-kr\r\n";
   $data .= "Authorization: BASIC ".base64_encode($accountId.':'.$accountPass)."\r\n\r\n";
   fwrite($fp, $data);
   $inHeaders = true;
   $atStart = true;
   while (!feof($fp)) {
    $line = fgets($fp, 4096);
    if ($atStart) {
     $atStart = false;
     if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
      echo "정보를 정상적으로 받아오지 못했습니다.1(".htmlentities($line).')';
      exit();
     }
     if($m[2] != 200) {
      echo "정보를 정상적으로 받아오지 못했습니다.2(".htmlentities($line).')';
      exit();
     }
     continue;
    }
    if ($inHeaders) {
     if (trim($line) == '') {
      $inHeaders = false;
      continue;
     }
     if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) {
      continue;
     }
     continue;
    }
    $trafficPage .= $line;
   }
   fclose($fp);
  }
  if($trafficPath == 'traffic') {
   return $this->hosting_traffic($trafficPage, $domain);
  } else if($trafficPath == 'traffic?xml') {
   return $this->xml_info($trafficPage, $domain);
  }
 }
}

$domain = 'lamborghini.mireene.com'; // 도메인(ex : mireene.com)
$accountId = 'lamborghini'; // 계정아이디
$accountPass = '+ '********'; // 계정암호
$trafficPath = 'traffic'; // 일반서버의 경우 traffic, cent서버는 traffic?xml

$traffic = new trafficInfo();
$trafficInfo = $traffic->get_traffic($domain, $accountId, $accountPass, $trafficPath);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> 트래픽 정보보기 </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Mireene" />
<meta name="keywords" content="traffic" />
<meta name="description" content="traffic" />
</head>

<body>

 
  <div class="HG_trafficViewer">
    <h2 class="title"><span>트래픽 사용량</span></h2>
        <div class="description">Traffic = <?php echo $traffic->percent; ?>% (<?php echo $traffic->usageTraffic; ?>MB / <?php echo $traffic->totalTraffic; ?>MB)</div>
        <div class="graph">
            <div class="used" style="width:<?php echo $traffic->percent; ?>%;"></div>
            <div class="rest" style="width:<?php echo 100 - $traffic->percent; ?>%;"></div>
            <div class="clear"></div>
        </div>

</div>

</body>
</html>

 

 

 

http://www.xpressengine.com/17123904

 **********************************여기 글에 있는거 보고했어요~

http://lamborghini.mireene.com/xe/traffic/traffic.php

이렇게 뜨는 이유좀 알려주세요;;

글쓴이 제목 최종 글
XE 공지 글 쓰기,삭제 운영방식 변경 공지 [16] 2019.03.05 by 남기남
홍경완 쉬운설치 리스트가 로드가 안됩니다..ㅠㅠ도와주세요 file  
타피님 외부페이지에서 로그인정보랑 URL 받기 [1] 2010.04.22 by 카르마
kuroseki_黑跡 레이아웃에서 한글이 출력돼게 하려면 어찌해야하나요? [1] 2010.04.22 by 현원
teryboy 회원 추가 정보 출력  
KSJade 이미지 갤러리(확장컴포넌트) 세로 사이즈 지정 방법 file  
김을동685 위젯에 포함된 이미지들이 나타나지 않는 문제  
타나토스971 xe 폴더 한방에 지우는 방법은?? [1] 2010.04.23 by serendip
황비 진짜 고수님의 도움을 간절히 바랍니다. [1] file 2010.04.23 by 현원
정소영548 제로보드 구식 사용하다가 유학다녀왓는데 [1] 2010.04.23 by 현원
이진적사고 layout_info에 저장되어 있는 값을 랜덤으로 표현하고 싶습니다. [1] 2010.04.23 by 현원
무실 현원님! 질문입니다. [1] 2010.04.23 by 현원
NOKORK 캐시파일 재생성시 Unexpected error 가 발생합니다. [1] file 2010.04.23 by 쥬시쿨
burster 1.4.0.11 업뎃이후........아 ! 미치겠네. [1] file 2010.04.23 by 현원
ㅊㅊㅋ 게시판 데이터추출툴을 이용할려고 하는데요... file  
바람과비 태그 검색에 관해서 질문드립니다. file  
토마토맨 xe에서 게시판 생성, 메뉴생성등등을 할때 한글만 입력하고 저장하면 글이 깨집니다 [2] file 2010.04.23 by 앙띠2
moog 회원정보 프로필에 나오는 목록 바꾸려면 어떻게 해야하나요? [1] 2010.04.23 by 블루파티
스카이피아 위젯 상단 공백생기는 문제 입니다. 소스 수정시.. [1] file 2010.04.23 by 앙띠2
스카이피아 위젯 상단 공백생기는거 때문에 질문드립니다. [2] file 2010.04.23 by 앙띠2
아아악내눈 게시판 설정-스킨관리에서 업로드한 배경이미지를 불러오는 방법을 알고 싶습니다. [1] file 2010.04.23 by 앙띠2