묻고답하기

<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 남기남
초보에요^^* 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 우주인
forumclip 게시판 이동 시 분류 항목 오류 문제..  
초보자 xe폴더 url기본설치가 어떻게 되나요?  
소양강 레이아웃편집에 로그인위젯 적용방법 알려 주세요. [2] 2009.09.03 by 소양강
해미 레이아웃 수정하고 오류가 자꾸 뜹니다 [2] 2009.09.03 by 해미
날씨좋음 계정옮기고 복구시키니 Error has occurred while connecting DB 에러가 왜생기는거에요? [2] 2009.09.03 by 유샤인
그대미소 이런 최신글위젯 어디서...? file  
acleds 기본 URL은 상대주소로 안되는지요?  
씨엘 FTP로 전체폴더 복사후 관리자페이지에 오류가 납니다. [3] 2009.09.03 by 씨엘
슬픈동화 황당.. 게시판 내용.. 언어별로 수정?? [7] 2009.09.03 by 백성찬
WhiteStorm 갤러리 형식의 레이아웃으로 수정하려는데.. [5] file 2009.09.03 by WhiteStorm
요피르 ㅠㅠ 등록만 누르면 되는데 아시는분 알려주세요! [6] file 2009.09.03 by 어쭈구리メ