묻고답하기
트래픽 보는 거요,,,ㅠ
2009.09.03 10:04
<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
이렇게 뜨는 이유좀 알려주세요;;
회원님께서 사용하고자 하시는 소스는 mod_cband 트래픽 모듈에 적용되는 소스이며
회원님께서 세팅된 서버에 설치된 트래픽 관리모듈은 Throttle Status 입니다.
트래픽 관리 모듈이 서로 틀리기 때문에 회원님 서버에 소스를 올리셔도 적용이 안되시는 겁니다.^^
미리내는 안된다네 ;;;;;;;;;;;;;ㅠ