1.7.1版
This commit is contained in:
22
.gitattributes
vendored
Normal file
22
.gitattributes
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
# Custom for Visual Studio
|
||||||
|
*.cs diff=csharp
|
||||||
|
*.sln merge=union
|
||||||
|
*.csproj merge=union
|
||||||
|
*.vbproj merge=union
|
||||||
|
*.fsproj merge=union
|
||||||
|
*.dbproj merge=union
|
||||||
|
|
||||||
|
# Standard to msysgit
|
||||||
|
*.doc diff=astextplain
|
||||||
|
*.DOC diff=astextplain
|
||||||
|
*.docx diff=astextplain
|
||||||
|
*.DOCX diff=astextplain
|
||||||
|
*.dot diff=astextplain
|
||||||
|
*.DOT diff=astextplain
|
||||||
|
*.pdf diff=astextplain
|
||||||
|
*.PDF diff=astextplain
|
||||||
|
*.rtf diff=astextplain
|
||||||
|
*.RTF diff=astextplain
|
||||||
163
.gitignore
vendored
Normal file
163
.gitignore
vendored
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
#################
|
||||||
|
## Eclipse
|
||||||
|
#################
|
||||||
|
|
||||||
|
*.pydevproject
|
||||||
|
.project
|
||||||
|
.metadata
|
||||||
|
bin/
|
||||||
|
tmp/
|
||||||
|
*.tmp
|
||||||
|
*.bak
|
||||||
|
*.swp
|
||||||
|
*~.nib
|
||||||
|
local.properties
|
||||||
|
.classpath
|
||||||
|
.settings/
|
||||||
|
.loadpath
|
||||||
|
|
||||||
|
# External tool builders
|
||||||
|
.externalToolBuilders/
|
||||||
|
|
||||||
|
# Locally stored "Eclipse launch configurations"
|
||||||
|
*.launch
|
||||||
|
|
||||||
|
# CDT-specific
|
||||||
|
.cproject
|
||||||
|
|
||||||
|
# PDT-specific
|
||||||
|
.buildpath
|
||||||
|
|
||||||
|
|
||||||
|
#################
|
||||||
|
## Visual Studio
|
||||||
|
#################
|
||||||
|
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Rr]elease/
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.vspscc
|
||||||
|
.builds
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
## TODO: If you have NuGet Package Restore enabled, uncomment this
|
||||||
|
#packages/
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish
|
||||||
|
|
||||||
|
# Others
|
||||||
|
[Bb]in
|
||||||
|
[Oo]bj
|
||||||
|
sql
|
||||||
|
TestResults
|
||||||
|
*.Cache
|
||||||
|
ClientBin
|
||||||
|
stylecop.*
|
||||||
|
~$*
|
||||||
|
*.dbmdl
|
||||||
|
Generated_Code #added for RIA/Silverlight projects
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file to a newer
|
||||||
|
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
############
|
||||||
|
## Windows
|
||||||
|
############
|
||||||
|
|
||||||
|
# Windows image file caches
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
|
||||||
|
#############
|
||||||
|
## Python
|
||||||
|
#############
|
||||||
|
|
||||||
|
*.py[co]
|
||||||
|
|
||||||
|
# Packages
|
||||||
|
*.egg
|
||||||
|
*.egg-info
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
eggs
|
||||||
|
parts
|
||||||
|
bin
|
||||||
|
var
|
||||||
|
sdist
|
||||||
|
develop-eggs
|
||||||
|
.installed.cfg
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
.coverage
|
||||||
|
.tox
|
||||||
|
|
||||||
|
#Translations
|
||||||
|
*.mo
|
||||||
|
|
||||||
|
#Mr Developer
|
||||||
|
.mr.developer.cfg
|
||||||
|
|
||||||
|
# Mac crap
|
||||||
|
.DS_Store
|
||||||
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
emlog 在线统计插件
|
||||||
|
====================
|
||||||
|
|
||||||
|
显示当前在线人数及最高纪录,后台显示当前在线列表并可自定义过滤的蜘蛛UA标记。在前台可以显示当前在线人数及最高记录,还可显示数据库查询次数。
|
||||||
|
|
||||||
|
[插件主页](http://xiaosong.org/tech/new-version-online-statistics-plugin-released)
|
||||||
113
online2.php
Normal file
113
online2.php
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: 在线统计
|
||||||
|
Version: 1.7.1
|
||||||
|
Plugin URL: http://xiaosong.org/tech/new-version-online-statistics-plugin-released
|
||||||
|
Description: 显示当前在线人数及最高纪录,后台显示当前在线列表并可自定义过滤的蜘蛛UA标记
|
||||||
|
ForEmlog:4.2.1+
|
||||||
|
Author: 小松
|
||||||
|
Author Email: sahala_2007@126.com
|
||||||
|
Author URL: http://xiaosong.org/
|
||||||
|
*/
|
||||||
|
!defined('EMLOG_ROOT') && exit('access deined!');
|
||||||
|
|
||||||
|
require_once('online2_config.php');
|
||||||
|
|
||||||
|
function is_bot(){
|
||||||
|
global $ua_block;
|
||||||
|
if (empty($ua_block)) {
|
||||||
|
return false; // Not block bot
|
||||||
|
}
|
||||||
|
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||||
|
$ua_blocks = strtolower($ua_block);
|
||||||
|
$ua_block_array = explode("|", $ua_blocks);
|
||||||
|
$botlist = $ua_block_array;
|
||||||
|
foreach($botlist as $bot){
|
||||||
|
if(strpos($ua, $bot) !== false)
|
||||||
|
return true; // Is a bot
|
||||||
|
}
|
||||||
|
return false; // Not a bot
|
||||||
|
}
|
||||||
|
|
||||||
|
function online2(){
|
||||||
|
$DB = MySql::getInstance();
|
||||||
|
$stringIp = getIp();
|
||||||
|
$useragent = addslashes($_SERVER['HTTP_USER_AGENT']);
|
||||||
|
if (!empty($stringIp) && !is_bot()) {
|
||||||
|
$inDB = $DB->query("SELECT 1 FROM ".DB_PREFIX."online2 WHERE ip='".$stringIp."'");
|
||||||
|
if (!$DB->num_rows($inDB)) {
|
||||||
|
$DB->query("INSERT INTO ".DB_PREFIX."online2 (ip, useragent) VALUES('".$stringIp."', '".$useragent."')");
|
||||||
|
} else {
|
||||||
|
$DB->query("UPDATE ".DB_PREFIX."online2 SET dt=NOW(), useragent = '".$useragent."' WHERE ip='".$stringIp."'");
|
||||||
|
}
|
||||||
|
if (ROLE == 'admin') {
|
||||||
|
$DB->query("DELETE FROM ".DB_PREFIX."online2 WHERE dt<SUBTIME(NOW(),'0 0:10:0')");
|
||||||
|
}
|
||||||
|
$nowOnline = nowOnline();
|
||||||
|
$res_max = maxOnline();
|
||||||
|
$maxOnline = $res_max['maximum'];
|
||||||
|
if ($nowOnline > $maxOnline) {
|
||||||
|
$cacheData = serialize(array('maximum' => $nowOnline, 'maxDate' => time()));
|
||||||
|
Option::updateOption('maxOnline', $cacheData);
|
||||||
|
$CACHE = Cache::getInstance();
|
||||||
|
$CACHE->updateCache('options');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addAction('index_head', 'online2');
|
||||||
|
addAction('adm_head', 'online2');
|
||||||
|
|
||||||
|
function maxOnline(){
|
||||||
|
$data = unserialize(Option::get('maxOnline'));
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function nowOnline(){
|
||||||
|
$DB = MySql::getInstance();
|
||||||
|
$res_now = $DB->once_fetch_array("SELECT count(1) AS total FROM ".DB_PREFIX."online2 WHERE dt>SUBTIME(NOW(),'0 0:10:0') ");
|
||||||
|
$nowOnline = $res_now['total'];
|
||||||
|
return $nowOnline;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onlineOutput(){
|
||||||
|
global $is_querycount, $query_template;
|
||||||
|
$DB = MySql::getInstance();
|
||||||
|
$maxOnline = maxOnline();
|
||||||
|
$nowOnline = nowOnline();
|
||||||
|
$maxOnlineTime = smartDate($maxOnline["maxDate"], 'Y-m-d');
|
||||||
|
$queryCount = $DB->getQueryCount();
|
||||||
|
$queryCountTemplate = str_replace('{queryCount}', $queryCount, $query_template);
|
||||||
|
$queryCountOutput = (isset($is_querycount) && $is_querycount == 'true') ? $queryCountTemplate : '';
|
||||||
|
echo '总计 '.$nowOnline.' 人在线 - 最高纪录是 '.$maxOnline["maximum"].' 于 '.$maxOnlineTime.$queryCountOutput.'<!-- Powered online2 plugin by xiaosong.org -->';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($is_footer == 'true') {
|
||||||
|
addAction('index_footer', 'onlineOutput');
|
||||||
|
}
|
||||||
|
|
||||||
|
//仅供后台使用
|
||||||
|
function displayOnlineList(){
|
||||||
|
$DB = MySql::getInstance();
|
||||||
|
$res_nowonline = $DB->query("SELECT ip, dt, useragent FROM ".DB_PREFIX."online2 order by dt DESC");
|
||||||
|
$output_online = '';
|
||||||
|
while($row = $DB->fetch_array($res_nowonline)){
|
||||||
|
$iplocation = function_exists('convertip') ? '[- '.convertip($row['ip']).']' : '';
|
||||||
|
$output_online .= empty($row) ? '<tr><td colspan="3">暂无在线访客</td></tr>' : '<tr><td>'.$row['ip'].$iplocation.'</td><td>'.$row['dt'].'</td><td>'.$row['useragent'].'</td></tr>';
|
||||||
|
}
|
||||||
|
return $output_online;
|
||||||
|
}
|
||||||
|
|
||||||
|
function online_backup(){
|
||||||
|
$DB = MySql::getInstance();
|
||||||
|
global $tables;
|
||||||
|
$is_exist_online2_query = $DB->query('show tables like "'.DB_PREFIX.'online2"');
|
||||||
|
if($DB->num_rows($is_exist_online2_query) != 0) array_push($tables, 'online2');
|
||||||
|
}
|
||||||
|
addAction('data_prebakup', 'online_backup');
|
||||||
|
|
||||||
|
function online_menu()
|
||||||
|
{
|
||||||
|
echo '<div class="sidebarsubmenu" id="online2"><a href="./plugin.php?plugin=online2">在线统计</a></div>';
|
||||||
|
}
|
||||||
|
addAction('adm_sidebar_ext', 'online_menu');
|
||||||
|
?>
|
||||||
52
online2_callback.php
Normal file
52
online2_callback.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 在线统计插件
|
||||||
|
* @copyright (c) xiaosong.org All Rights Reserved
|
||||||
|
*/
|
||||||
|
if(!defined('EMLOG_ROOT')) {exit('error!');}
|
||||||
|
|
||||||
|
function callback_init(){
|
||||||
|
$DB = MySql::getInstance();
|
||||||
|
$is_exist_online_query = $DB->query('show tables like "'.DB_PREFIX.'online2"');
|
||||||
|
$is_exist_maxonline_query = $DB->query('show tables like "'.DB_PREFIX.'maxonline"');
|
||||||
|
$is_exist_option = $DB->query("SELECT 1 FROM ".DB_PREFIX."options WHERE option_name='maxOnline'");
|
||||||
|
$dbcharset = 'utf8';
|
||||||
|
$type = 'MYISAM';
|
||||||
|
$add = $DB->getMysqlVersion() > '4.1' ? "ENGINE=".$type." DEFAULT CHARSET=".$dbcharset.";":"TYPE=".$type.";";
|
||||||
|
if ($DB->num_rows($is_exist_online_query) == 0) {
|
||||||
|
$sql_online = "
|
||||||
|
CREATE TABLE `".DB_PREFIX."online2` (
|
||||||
|
`id` int(10) unsigned NOT NULL auto_increment,
|
||||||
|
`ip` varchar(128) NOT NULL default '',
|
||||||
|
`dt` timestamp NOT NULL default CURRENT_TIMESTAMP,
|
||||||
|
`useragent` varchar(255) NOT NULL default '',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `ip` (`ip`)
|
||||||
|
)".$add;
|
||||||
|
$DB->query($sql_online);
|
||||||
|
}
|
||||||
|
if ($DB->num_rows($is_exist_maxonline_query) != 0) {
|
||||||
|
$res_max = $DB->once_fetch_array("SELECT maximum, DATE(dt) AS maxDate FROM ".DB_PREFIX."maxonline");
|
||||||
|
$timeUTC = emStrtotime($res_max["maxDate"]);
|
||||||
|
$cacheData = serialize(array('maximum' => $res_max["maximum"], 'maxDate' => $timeUTC));
|
||||||
|
$CACHE = Cache::getInstance();
|
||||||
|
$CACHE->cacheWrite($cacheData, 'maxOnline');
|
||||||
|
$query = $DB->query("DROP TABLE IF EXISTS ".DB_PREFIX."maxonline");
|
||||||
|
}
|
||||||
|
if (!$DB->num_rows($is_exist_option)) {
|
||||||
|
$DB->query("INSERT INTO ".DB_PREFIX."options (option_name, option_value) VALUES('maxOnline', '".serialize(array('maximum' => 0, 'maxDate' => time()))."')");
|
||||||
|
}
|
||||||
|
$cachefile = EMLOG_ROOT . '/content/cache/maxOnline.php';
|
||||||
|
if (file_exists($cachefile) && filesize($cachefile) > 0) {
|
||||||
|
$data = file_get_contents($cachefile);
|
||||||
|
$data = str_replace("<?php exit;//", '', $data);
|
||||||
|
Option::updateOption('maxOnline', $data);
|
||||||
|
unlink($cachefile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function callback_rm(){
|
||||||
|
$DB = MySql::getInstance();
|
||||||
|
$query = $DB->query("DROP TABLE IF EXISTS ".DB_PREFIX."online2");
|
||||||
|
}
|
||||||
|
?>
|
||||||
5
online2_config.php
Normal file
5
online2_config.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
$ua_block = 'UptimeRobot|Sosospider|bingbot|Googlebot|msnbot|Baiduspider|Sogou web spider|JianKongBao|SiteUptime';
|
||||||
|
$is_footer = '';
|
||||||
|
$is_footer = '';
|
||||||
|
?>
|
||||||
71
online2_setting.php
Normal file
71
online2_setting.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 在线统计插件
|
||||||
|
* @copyright (c) xiaosong.org All Rights Reserved
|
||||||
|
*/
|
||||||
|
!defined('EMLOG_ROOT') && exit('access deined!');
|
||||||
|
|
||||||
|
function plugin_setting_view() {
|
||||||
|
require_once('online2_config.php');
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#online2").addClass('sidebarsubmenu1');
|
||||||
|
</script>
|
||||||
|
<div class="containertitle"><b>在线统计</b>
|
||||||
|
<?php if(isset($_GET['setting'])):?><span class="actived">插件设置完成</span><?php endif;?>
|
||||||
|
</div>
|
||||||
|
<div class="line"></div>
|
||||||
|
<style type="text/css">
|
||||||
|
.online { max-height: 280px; overflow-y: auto; }
|
||||||
|
.online table { width: 100%; table-layout: fixed; }
|
||||||
|
.online td, .online th { text-align: center; word-wrap: break-word; word-break: break-all; vertical-align: middle; }
|
||||||
|
.online td { padding: 3px; }
|
||||||
|
#queryTemplate { width: 200px; }
|
||||||
|
</style>
|
||||||
|
<h4><?php echo onlineOutput(); ?></h4>
|
||||||
|
<div class="online">
|
||||||
|
<table cellspacing="0" cellpadding="0" border="0" class="item_list">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th style="width:38%;"><b>ip地址</b></th>
|
||||||
|
<th style="width:16%;"><b>上线时间</b></th>
|
||||||
|
<th style="width:44%;"><b>UserAgent信息</b></th>
|
||||||
|
</tr>
|
||||||
|
<?php echo displayOnlineList(); ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function(){
|
||||||
|
$(".item_list tbody tr:odd").addClass("tralt_b");
|
||||||
|
$(".item_list tbody tr")
|
||||||
|
.mouseover(function(){$(this).addClass("trover");})
|
||||||
|
.mouseout(function(){$(this).removeClass("trover");})
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
<div class="des">你可以根据上面的在线信息,添加你要排除在外的蜘蛛的特征UserAgent信息,每一个特征字符串用(|)分开,不区分大小写</div>
|
||||||
|
<form action="plugin.php?plugin=online2&action=setting" method="post">
|
||||||
|
<p><textarea name="ua_block" style="width: 500px; height: 100px"><?php echo $ua_block; ?></textarea></p>
|
||||||
|
<p><label for="is_querycount"><input type="checkbox" name="is_querycount" id="is_querycount" value="true"<?php if($is_querycount == "true"):?> checked<?php endif;?> /> 显示数据库查询次数</label> <label for="queryTemplate"> <input type="text" name="query_template" id="queryTemplate" value="<?php echo $query_template; ?>"> 显示模版</label> <span style="color:#f00">可用变量:{queryCount} -- 查询次数</span></p>
|
||||||
|
<p><label for="is_footer"><input type="checkbox" name="is_footer" id="is_footer" value="true"<?php if($is_footer == "true"):?> checked<?php endif;?> /> 通过模版自带插件钩子显示</label> <span style="color:#f00">样式和位置完全取决于主题!</span></p>
|
||||||
|
<p><input type="submit" value="保存设置" class="button"/></p>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
function plugin_setting(){
|
||||||
|
$ua_block = isset($_POST['ua_block']) ? addslashes($_POST['ua_block']) : '';
|
||||||
|
$query_template = isset($_POST['query_template']) ? addslashes($_POST['query_template']) : '';
|
||||||
|
$is_querycount = isset($_POST['is_querycount']) ? addslashes(trim($_POST['is_querycount'])) : '';
|
||||||
|
$is_footer = isset($_POST['is_footer']) ? addslashes(trim($_POST['is_footer'])) : '';
|
||||||
|
$data = "<?php
|
||||||
|
\$ua_block = '".$ua_block."';
|
||||||
|
\$query_template = '".$query_template."';
|
||||||
|
\$is_querycount = '".$is_querycount."';
|
||||||
|
\$is_footer = '".$is_footer."';
|
||||||
|
?>";
|
||||||
|
$file = EMLOG_ROOT.'/content/plugins/online2/online2_config.php';
|
||||||
|
@ $fp = fopen($file, 'wb') OR emMsg('读取文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/online2/online2_config.php的权限为755或777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
||||||
|
@ $fw = fwrite($fp,$data) OR emMsg('写入文件失败,如果您使用的是Unix/Linux主机,请修改文件/content/plugins/online2/online2_config.php的权限为755或777。如果您使用的是Windows主机,请联系管理员,将该文件设为everyone可写');
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user