묻고답하기

<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 남기남
apollos 서브메뉴를 가로로 놓는 방법은 어떻게 하나요 ? file  
마에야히 moduleModel::getModuleInfoXml() 이거 어떻게 쓰나요;;  
공방 (홈)페이지가 갑자기 안나옵니다. [3] 2009.09.03 by 백성찬
zartin 이모티콘이 왜 안나오지요? [1] 2009.09.03 by apollos
불패의초인 트래픽 보는 거요,,,ㅠ [1] 2009.09.03 by 불패의초인
류태일 전에 보이던 자료 페이지가 안보이는데 혹시 사라졌나요.. [2] 2009.09.03 by 류태일
어쭈구리メ 확장변수에는 생일처럼 나오게 할수 없나요? [3] file 2009.09.03 by 백성찬
apollos 다시한번 메뉴에 대해서 질문드립니다. [1] file 2009.09.03 by apollos
apollos 이런 오류는 어떻게 잡나요 ? file  
김태운555 첨부화일 에러 [1] file 2009.09.03 by 백성찬
잘살아 awstats 웹로그분석 결과 추출가능한지요?  
홍차 회원 등급을 더 나눌 순 없나요? [1] 2009.09.03 by 어쭈구리メ
배근배 안녕하세요. 미치겠네요 ㅠㅠ [1] 2009.09.03 by 백성찬
초보 레이아웃 등록하려는데 자꾸 오류가 뜹니다 !!  
우주인 급질문...xe설치  
겨레사랑 게시판 분류에서 xe처럼 상위분류 선택되지 않게 하는 방법??? [2] file 2009.09.03 by 겨레사랑
쥐엉 getBasePath()라는 함수를 쓰고싶습니다...  
김선정298 오류 페이지 배경색 바꾸기 [2] 2009.09.03 by 궁금이2
sungjaeq ### 방명록에 글쓴후에도 입력폼에 정보가 남아있어요 ㅠㅠ##  
우정훈762 앞으로 업데이트 할 땐 모듈별로 다 따로 확인해야되는건가요? [2] 2009.09.03 by 우정훈762
왜만지냐 !$comment->get(''member_srl'') 이건 무엇을 의미하나요? [3] 2009.09.03 by 왜만지냐
초보에요^^* xe v2 레이아웃 로그인 디자인 변경과 관련해서 질문드립니다. file  
해미 도와주세요 !!!!!!!!!! 정말 급합니다 !!  
교육컨설팅 지금 현제 해빌 레이아웃 문제 생겼네염;;;;  
토리s 레이아웃에 대해 질문입니다. [2] file 2009.09.03 by 토리s
우주인 하나의 서버에 두개의 도메인...xe설치시 [2] 2009.09.03 by 우주인
네팅 에러메세지 좀 봐주세요 ㅜㅜWarning: Attempt to assign property of non-object in  
Cityhunter 카페 설정 기능 에서 페이지를 19개 이상 설정 할 수 없나요? [4] 2009.09.03 by reon
피콜로 조회수 관련 질문드립니다.  
tio2 도메인만 aaa.com에서 bbb.com으로 바꿀때 [2] 2009.09.03 by 우주인