Skip to content

Commit

Permalink
접속자 Browscap 적용 기능 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
chicpro committed Nov 13, 2015
1 parent aebfc70 commit 158d904
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 42 deletions.
11 changes: 8 additions & 3 deletions adm/admin.menu100.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
array('100900', '캐시파일 일괄삭제',G5_ADMIN_URL.'/cache_file_delete.php', 'cf_cache', 1),
array('100910', '캡챠파일 일괄삭제',G5_ADMIN_URL.'/captcha_file_delete.php', 'cf_captcha', 1),
array('100920', '썸네일파일 일괄삭제',G5_ADMIN_URL.'/thumbnail_file_delete.php', 'cf_thumbnail', 1),
array('100500', 'phpinfo()', G5_ADMIN_URL.'/phpinfo.php', 'cf_phpinfo'),
array('100510', 'Browscap 업데이트', G5_ADMIN_URL.'/browscap.php', 'cf_browscap'),
array('100400', '부가서비스', G5_ADMIN_URL.'/service.php', 'cf_service')
array('100500', 'phpinfo()', G5_ADMIN_URL.'/phpinfo.php', 'cf_phpinfo')
);

if(version_compare(phpversion(), '5.3.0', '>=') && defined('G5_BROWSCAP_USE') && G5_BROWSCAP_USE) {
$menu['menu100'][] = array('100510', 'Browscap 업데이트', G5_ADMIN_URL.'/browscap.php', 'cf_browscap');
$menu['menu100'][] = array('100520', '접속로그 변환', G5_ADMIN_URL.'/browscap_convert.php', 'cf_visit_cnvrt');
}

$menu['menu100'][] = array('100400', '부가서비스', G5_ADMIN_URL.'/service.php', 'cf_service');
?>
3 changes: 3 additions & 0 deletions adm/browscap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
$sub_menu = "100510";
include_once('./_common.php');

if(!(version_compare(phpversion(), '5.3.0', '>=') && defined('G5_BROWSCAP_USE') && G5_BROWSCAP_USE))
alert('사용할 수 없는 기능입니다.', G5_ADMIN_URL);

if ($is_admin != 'super')
alert('최고관리자만 접근 가능합니다.');

Expand Down
46 changes: 46 additions & 0 deletions adm/browscap_convert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
$sub_menu = "100520";
include_once('./_common.php');

if(!(version_compare(phpversion(), '5.3.0', '>=') && defined('G5_BROWSCAP_USE') && G5_BROWSCAP_USE))
alert('사용할 수 없는 기능입니다.', G5_ADMIN_URL);

if ($is_admin != 'super')
alert('최고관리자만 접근 가능합니다.');

$rows = preg_replace('#[^0-9]#', '', $_GET['rows']);
if(!$rows)
$rows = 100;

$g5['title'] = '접속로그 변환';
include_once('./admin.head.php');
?>

<div id="processing">
<p>접속로그 정보를 Browscap 정보로 변환하시려면 아래 업데이트 버튼을 클릭해 주세요.</p>
<button type="button" id="run_update">업데이트</button>
</div>

<script>
$(function() {
$(document).on("click", "#run_update", function() {
$("#processing").html('<div class="update_processing"></div><p>Browscap 정보로 변환 중입니다.</p>');

$.ajax({
method: "GET",
url: "./browscap_converter.php",
data: { rows: "<?php echo $rows; ?>" },
async: true,
cache: false,
dataType: "html",
success: function(data) {
$("#processing").html(data);
}
});
});
});
</script>

<?php
include_once('./admin.tail.php');
?>
75 changes: 75 additions & 0 deletions adm/browscap_converter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
ini_set('memory_limit', '-1');
include_once('./_common.php');

// clean the output buffer
ob_end_clean();

if(!(version_compare(phpversion(), '5.3.0', '>=') && defined('G5_BROWSCAP_USE') && G5_BROWSCAP_USE))
die('사용할 수 없는 기능입니다.');

if($is_admin != 'super')
die('최고관리자로 로그인 후 실행해 주세요.');

// browscap cache 파일 체크
if(!is_file(G5_DATA_PATH.'/cache/browscap_cache.php')) {
echo '<p>Browscap 정보가 없습니다. 아래 링크로 이동해 Browscap 정보를 업데이트 하세요.</p>'.PHP_EOL;
echo '<p><a href="'.G5_ADMIN_URL.'/browscap.php">Browscap 업데이트</a></p>'.PHP_EOL;
exit;
}

include_once(G5_PLUGIN_PATH.'/browscap/Browscap.php');
$browscap = new phpbrowscap\Browscap(G5_DATA_PATH.'/cache');
$browscap->doAutoUpdate = false;
$browscap->cacheFilename = 'browscap_cache.php';

// 데이터 변환
$rows = preg_replace('#[^0-9]#', '', $_GET['rows']);
if(!$rows)
$rows = 100;

$sql_common = " from {$g5['visit_table']} where vi_agent <> '' and ( vi_browser = '' or vi_os = '' or vi_device = '' ) ";
$sql_order = " order by vi_id desc ";
$sql_limit = " limit 0, $rows ";

$sql = " select count(vi_id) as cnt $sql_common ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];

$sql = " select vi_id, vi_agent, vi_browser, vi_os, vi_device
$sql_common
$sql_order
$sql_limit ";
$result = sql_query($sql);

$cnt = 0;
for($i=0; $row=sql_fetch_array($result); $i++) {
$info = $browscap->getBrowser($row['vi_agent']);

$brow = $row['vi_browser'];
if(!$brow)
$brow = $info->Comment;

$os = $row['vi_os'];
if(!$os)
$os = $info->Platform;

$device = $row['vi_device'];
if(!$device)
$device = $info->Device_Type;

$sql2 = " update {$g5['visit_table']}
set vi_browser = '$brow',
vi_os = '$os',
vi_device = '$device'
where vi_id = '{$row['vi_id']}' ";
sql_query($sql2);

$cnt++;
}

if(($total_count - $cnt) == 0 || $total_count == 0)
echo '<div class="check_processing"></div><p>변환완료</p>';
else
echo '<p>총 '.number_format($total_count).'건 중 '.number_format($cnt).'건 변환완료<br><br>접속로그를 추가로 변환하시려면 아래 업데이트 버튼을 클릭해 주세요.</p><button type="button" id="run_update">업데이트</button>';
?>
3 changes: 3 additions & 0 deletions adm/browscap_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// clean the output buffer
ob_end_clean();

if(!(version_compare(phpversion(), '5.3.0', '>=') && defined('G5_BROWSCAP_USE') && G5_BROWSCAP_USE))
die('사용할 수 없는 기능입니다.');

if ($is_admin != 'super')
die('최고관리자만 접근 가능합니다.');

Expand Down
2 changes: 2 additions & 0 deletions adm/visit.sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
<li><a href="./visit_domain.php<?php echo $query_string ?>">도메인</a></li>
<li><a href="./visit_browser.php<?php echo $query_string ?>">브라우저</a></li>
<li><a href="./visit_os.php<?php echo $query_string ?>">운영체제</a></li>
<?php if(version_compare(phpversion(), '5.3.0', '>=') && defined('G5_BROWSCAP_USE') && G5_BROWSCAP_USE) { ?>
<li><a href="./visit_device.php<?php echo $query_string ?>">접속기기</a></li>
<?php } ?>
<li><a href="./visit_hour.php<?php echo $query_string ?>">시간</a></li>
<li><a href="./visit_week.php<?php echo $query_string ?>">요일</a></li>
<li><a href="./visit_date.php<?php echo $query_string ?>">일</a></li>
Expand Down
4 changes: 2 additions & 2 deletions adm/visit_device.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
while ($row=sql_fetch_array($result)) {
$s = $row['vi_device'];
if(!$s)
$s = get_device($row['vi_agent']);
$s = '기타';

$arr[$s]++;

Expand Down Expand Up @@ -65,7 +65,7 @@
}

if (!$key) {
$key = 'Unknown';
$key = '기타';
}

$rate = ($count / $sum_count * 100);
Expand Down
2 changes: 0 additions & 2 deletions adm/visit_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
$os = get_os($row['vi_agent']);

$device = $row['vi_device'];
if(!$device)
$device = get_device($row['vi_agent']);

$link = '';
$link2 = '';
Expand Down
2 changes: 0 additions & 2 deletions adm/visit_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@
$os = get_os($row['vi_agent']);

$device = $row['vi_device'];
if(!$device)
$device = get_device($row['vi_agent']);

$link = "";
$referer = "";
Expand Down
21 changes: 21 additions & 0 deletions bbs/visit_browscap.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

if(!(version_compare(phpversion(), '5.3.0', '>=') && defined('G5_BROWSCAP_USE') && G5_BROWSCAP_USE))
return;

// Browscap 캐시 파일이 있으면 실행
if(defined('G5_VISIT_BROWSCAP_USE') && G5_VISIT_BROWSCAP_USE && is_file(G5_DATA_PATH.'/cache/browscap_cache.php')) {
include_once(G5_PLUGIN_PATH.'/browscap/Browscap.php');

$browscap = new phpbrowscap\Browscap(G5_DATA_PATH.'/cache');
$browscap->doAutoUpdate = false;
$browscap->cacheFilename = 'browscap_cache.php';

$info = $browscap->getBrowser($_SERVER['HTTP_USER_AGENT']);

$vi_browser = $info->Comment;
$vi_os = $info->Platform;
$vi_device = $info->Device_Type;
}
?>
11 changes: 5 additions & 6 deletions bbs/visit_insert.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
if (isset($_SERVER['HTTP_REFERER']))
$referer = escape_trim(clean_xss_tags($_SERVER['HTTP_REFERER']));
$user_agent = escape_trim(clean_xss_tags($_SERVER['HTTP_USER_AGENT']));
// Browscap 캐시 파일이 있으면 실행
if(is_file(G5_DATA_PATH.'/cache/browscap_cache.php')) {
$browscap = get_browscap_info($_SERVER['HTTP_USER_AGENT']);
$vi_browser = $browscap->Comment;
$vi_os = $browscap->Platform;
$vi_device = $browscap->Device_Type;
$vi_browser = '';
$vi_os = '';
$vi_device = '';
if(version_compare(phpversion(), '5.3.0', '>=') && defined('G5_BROWSCAP_USE') && G5_BROWSCAP_USE) {
include_once(G5_BBS_PATH.'/visit_browscap.inc.php');
}
$sql = " insert {$g5['visit_table']} ( vi_id, vi_ip, vi_date, vi_time, vi_referer, vi_agent, vi_browser, vi_os, vi_device ) values ( '{$vi_id}', '{$remote_addr}', '".G5_TIME_YMD."', '".G5_TIME_HIS."', '{$referer}', '{$user_agent}', '{$vi_browser}', '{$vi_os}', '{$vi_device}' ) ";

Expand Down
6 changes: 6 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
// MySQLi 사용여부를 설정합니다.
define('G5_MYSQLI_USE', true);

// Browscap 사용여부를 설정합니다.
define('G5_BROWSCAP_USE', true);

// 접속자 기록 때 Browscap 사용여부를 설정합니다.
define('G5_VISIT_BROWSCAP_USE', false);

// ip 숨김방법 설정
/* 123.456.789.012 ip의 숨김 방법을 변경하는 방법은
\\1 은 123, \\2는 456, \\3은 789, \\4는 012에 각각 대응되므로
Expand Down
18 changes: 0 additions & 18 deletions lib/common.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3173,22 +3173,4 @@ function check_vaild_callback($callback){
return true;
}
}

// Browscap 정보 얻기
function get_browscap_info($agent)
{
if(!$agent)
return false;

include_once(G5_PLUGIN_PATH.'/browscap/Browscap.php');

$browscap = new phpbrowscap\Browscap(G5_DATA_PATH.'/cache');
$browscap->updateMethod = 'cURL';
$browscap->doAutoUpdate = false;
$browscap->cacheFilename = 'browscap_cache.php';

$info = $browscap->getBrowser($agent);

return $info;
}
?>
47 changes: 38 additions & 9 deletions lib/visit.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,51 @@ function visit($skin_dir='basic')
// get_browser() 함수는 이미 있음
function get_brow($agent)
{
$info = get_browscap_info($agent);
$agent = strtolower($agent);

return $info->Comment;
//echo $agent; echo "<br/>";

if (preg_match("/msie ([1-9][0-9]\.[0-9]+)/", $agent, $m)) { $s = 'MSIE '.$m[1]; }
else if(preg_match("/firefox/", $agent)) { $s = "FireFox"; }
else if(preg_match("/chrome/", $agent)) { $s = "Chrome"; }
else if(preg_match("/x11/", $agent)) { $s = "Netscape"; }
else if(preg_match("/opera/", $agent)) { $s = "Opera"; }
else if(preg_match("/gec/", $agent)) { $s = "Gecko"; }
else if(preg_match("/bot|slurp/", $agent)) { $s = "Robot"; }
else if(preg_match("/internet explorer/", $agent)) { $s = "IE"; }
else if(preg_match("/mozilla/", $agent)) { $s = "Mozilla"; }
else { $s = "기타"; }

return $s;
}

function get_os($agent)
{
$info = get_browscap_info($agent);
$agent = strtolower($agent);

return $info->Platform;
}
//echo $agent; echo "<br/>";

function get_device($agent)
{
$info = get_browscap_info($agent);
if (preg_match("/windows 98/", $agent)) { $s = "98"; }
else if(preg_match("/windows 95/", $agent)) { $s = "95"; }
else if(preg_match("/windows nt 4\.[0-9]*/", $agent)) { $s = "NT"; }
else if(preg_match("/windows nt 5\.0/", $agent)) { $s = "2000"; }
else if(preg_match("/windows nt 5\.1/", $agent)) { $s = "XP"; }
else if(preg_match("/windows nt 5\.2/", $agent)) { $s = "2003"; }
else if(preg_match("/windows nt 6\.0/", $agent)) { $s = "Vista"; }
else if(preg_match("/windows nt 6\.1/", $agent)) { $s = "Windows7"; }
else if(preg_match("/windows nt 6\.2/", $agent)) { $s = "Windows8"; }
else if(preg_match("/windows 9x/", $agent)) { $s = "ME"; }
else if(preg_match("/windows ce/", $agent)) { $s = "CE"; }
else if(preg_match("/mac/", $agent)) { $s = "MAC"; }
else if(preg_match("/linux/", $agent)) { $s = "Linux"; }
else if(preg_match("/sunos/", $agent)) { $s = "sunOS"; }
else if(preg_match("/irix/", $agent)) { $s = "IRIX"; }
else if(preg_match("/phone/", $agent)) { $s = "Phone"; }
else if(preg_match("/bot|slurp/", $agent)) { $s = "Robot"; }
else if(preg_match("/internet explorer/", $agent)) { $s = "IE"; }
else if(preg_match("/mozilla/", $agent)) { $s = "Mozilla"; }
else { $s = "기타"; }

return $info->Device_Type;
return $s;
}
?>

0 comments on commit 158d904

Please sign in to comment.