webstats 配置

pull/139/head
midoks 3 years ago
parent c31c549300
commit b10ee951f6
  1. 2
      class/core/config_api.py
  2. 20
      plugins/webstats/conf/init.sql
  3. 2
      plugins/webstats/conf/webstats.conf
  4. BIN
      plugins/webstats/ico.png
  5. 18
      plugins/webstats/index.html
  6. 158
      plugins/webstats/index.py
  7. 17
      plugins/webstats/info.json
  8. 93
      plugins/webstats/install.sh
  9. 0
      plugins/webstats/js/stats.js
  10. 49
      plugins/webstats/lua/web_stats_log.lua

@ -17,7 +17,7 @@ class config_api:
# 进行中. # 进行中.
# 兼容主流Linux系统 # 兼容主流Linux系统
__version = '0.8.6.9' __version = '0.8.6.10'
def __init__(self): def __init__(self):
pass pass

@ -0,0 +1,20 @@
CREATE TABLE IF NOT EXISTS `web_logs` (
`time` INTEGER,
`ip` TEXT,
`domain` TEXT,
`server_name` TEXT,
`method` TEXT,
`status_code` INTEGER,
`uri` TEXT,
`body_length` INTEGER,
`referer` TEXT DEFAULT "",
`user_agent` TEXT,
`is_spider` INTEGER DEFAULT 0,
`protocol` TEXT,
`request_time` INTEGER,
`request_headers` TEXT DEFAULT "",
`ip_list` TEXT DEFAULT "",
`client_port` INTEGER DEFAULT -1
);
CREATE INDEX time_inx ON web_logs(`time`);

@ -0,0 +1,2 @@
lua_shared_dict mw_total 50m;
include {$SERVER_APP}/lua/web_stats_log.lua;

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 B

@ -0,0 +1,18 @@
<div class="bt-form">
<div class="bt-w-main">
<div class="bt-w-menu">
<p class="bgw" onclick="pluginService('webstats');">服务</p>
<p onclick="pluginConfig('webstats');">概览</p>
<p onclick="pluginConfig('webstats');">全局设置</p>
</div>
<div class="bt-w-con pd15">
<div class="soft-man-con"></div>
</div>
</div>
</div>
<script type="text/javascript">
resetPluginWinWidth(800);
$.getScript( "/plugins/file?name=webstats&f=js/stats.js", function(){
pluginService('webstats');
});
</script>

@ -0,0 +1,158 @@
# coding:utf-8
import sys
import io
import os
import time
sys.path.append(os.getcwd() + "/class/core")
import mw
app_debug = False
if mw.isAppleSystem():
app_debug = True
def getPluginName():
return 'webstats'
def getPluginDir():
return mw.getPluginDir() + '/' + getPluginName()
def getServerDir():
return mw.getServerDir() + '/' + getPluginName()
def getArgs():
args = sys.argv[2:]
tmp = {}
args_len = len(args)
if args_len == 1:
t = args[0].strip('{').strip('}')
t = t.split(':')
tmp[t[0]] = t[1]
elif args_len > 1:
for i in range(len(args)):
t = args[i].split(':')
tmp[t[0]] = t[1]
return tmp
def checkArgs(data, ck=[]):
for i in range(len(ck)):
if not ck[i] in data:
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
return (True, mw.returnJson(True, 'ok'))
def luaConf():
return mw.getServerDir() + '/web_conf/nginx/vhost/webstats.conf'
def status():
path = luaConf()
if not os.path.exists(path):
return 'stop'
return 'start'
def pSqliteDb(dbname='web_logs'):
file = getServerDir() + '/webstats.db'
name = 'webstats'
if not os.path.exists(file):
conn = mw.M(dbname).dbPos(getServerDir(), name)
sql = mw.readFile(getPluginDir() + '/conf/init.sql')
sql_list = sql.split(';')
for index in range(len(sql_list)):
conn.execute(sql_list[index], ())
else:
conn = mw.M(dbname).dbPos(getServerDir(), name)
return conn
def initDreplace():
service_path = getServerDir()
pSqliteDb()
path = luaConf()
path_tpl = getPluginDir() + '/conf/webstats.conf'
if not os.path.exists(path):
content = mw.readFile(path_tpl)
content = content.replace('{$SERVER_APP}', service_path)
content = content.replace('{$ROOT_PATH}', mw.getServerDir())
mw.writeFile(path, content)
lua_dir = getServerDir() + "/lua"
lua_dst = lua_dir + "/web_stats_log.lua"
if not os.path.exists(lua_dst):
mw.execShell('mkdir -p ' + lua_dir)
lua_tpl = getPluginDir() + '/lua/web_stats_log.lua'
content = mw.readFile(lua_tpl)
content = content.replace('{$SERVER_APP}', service_path)
content = content.replace('{$ROOT_PATH}', mw.getServerDir())
mw.writeFile(lua_dst, content)
debug_log = getServerDir() + "/debug.log"
if not os.path.exists(debug_log):
mw.execShell('mkdir -p ' + lua_dir)
mw.writeFile(debug_log, '')
return 'ok'
def start():
initDreplace()
mw.restartWeb()
return 'ok'
def stop():
path = luaConf()
os.remove(path)
mw.restartWeb()
return 'ok'
def restart():
initDreplace()
return 'ok'
def reload():
initDreplace()
lua_dir = getServerDir() + "/lua"
lua_dst = lua_dir + "/web_stats_log.lua"
lua_tpl = getPluginDir() + '/lua/web_stats_log.lua'
content = mw.readFile(lua_tpl)
content = content.replace('{$SERVER_APP}', getServerDir())
content = content.replace('{$ROOT_PATH}', mw.getServerDir())
mw.writeFile(lua_dst, content)
mw.restartWeb()
return 'ok'
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
print(status())
elif func == 'start':
print(start())
elif func == 'stop':
print(stop())
elif func == 'restart':
print(restart())
elif func == 'reload':
print(reload())
elif func == 'run_info':
print(runInfo())
elif func == 'conf':
print(getConf())
else:
print('error')

@ -0,0 +1,17 @@
{
"sort": 7,
"ps": "【DEV】网站统计报表",
"name": "webstats",
"title": "网站统计报表",
"shell": "install.sh",
"versions":["0.0.1"],
"tip": "soft",
"checks": "server/webstats",
"path": "server/webstats",
"display": 1,
"author": "midoks",
"date": "2022-07-18",
"home": "https://github.com/midoks/mdserver-web",
"type": 0,
"pid": "1"
}

@ -0,0 +1,93 @@
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
## https://www.yangshuaibin.com/detail/392251
curPath=`pwd`
rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
install_tmp=${rootPath}/tmp/mw_install.pl
VERSION=$2
Install_App()
{
echo '正在安装脚本文件...' > $install_tmp
mkdir -p $serverPath/source/webstats
mkdir -p $serverPath/webstats
# 下载源码安装包
# curl -O $serverPath/source/webstats/lua-5.1.5.tar.gz https://www.lua.org/ftp/lua-5.1.5.tar.gz
# cd $serverPath/source/webstats && tar xvf lua-5.1.5.tar.gz
# cd lua-5.1.5
# make linux test && make install
# luarocks
if [ ! -f $serverPath/source/webstats/luarocks-3.5.0.tar.gz ];then
wget -O $serverPath/source/webstats/luarocks-3.5.0.tar.gz https://luarocks.org/releases/luarocks-3.5.0.tar.gz
fi
# which luarocks
# if [ "$?" != "0" ];then
if [ ! -d $serverPath/webstats/luarocks ];then
cd $serverPath/source/webstats && tar xvf luarocks-3.5.0.tar.gz
# cd luarocks-3.9.1 && ./configure && make bootstrap
cd luarocks-3.5.0 && ./configure --prefix=$serverPath/webstats/luarocks --with-lua-include=$serverPath/openresty/luajit/include/luajit-2.1 --with-lua-bin=$serverPath/openresty/luajit/bin
make -I${serverPath}/openresty/luajit/bin
make install
fi
if [ ! -f $serverPath/source/webstats/lsqlite3_fsl09y.zip ];then
wget -O $serverPath/source/webstats/lsqlite3_fsl09y.zip http://lua.sqlite.org/index.cgi/zip/lsqlite3_fsl09y.zip?uuid=fsl_9y
cd $serverPath/source/webstats && unzip lsqlite3_fsl09y.zip
fi
# PATH=${serverPath}/openresty/luajit:${serverPath}/openresty/luajit/include/luajit-2.1:$PATH
# export PATH=$PATH:$serverPath/webstats/luarocks/bin
# cd $serverPath/source/webstats/lsqlite3_fsl09y && make
# if [ ! -d $serverPath/source/webstats/luasql-2.6.0 ];then
# wget -O $serverPath/source/webstats/luasql_2.6.0.tar.gz https://github.com/keplerproject/luasql/archive/refs/tags/2.6.0.tar.gz
# cd $serverPath/source/webstats && tar xvf luasql_2.6.0.tar.gz
# fi
# PATH=${serverPath}/openresty/luajit:${serverPath}/openresty/luajit/include/luajit-2.1:$PATH
# export PATH
# export LUA_INCDIR=${serverPath}/openresty/luajit/include/luajit-2.1
# cd $serverPath/source/webstats/luasql-2.6.0 && make sqlite3
# $serverPath/webstats/luarocks/bin/luarocks config --scope user lib_modules_path ${serverPath}/openresty/luajit/lib
# $serverPath/webstats/luarocks/bin/luarocks config --scope user lib_modules_path
# $serverPath/webstats/luarocks/bin/luarocks install lua-sqlite3
$serverPath/webstats/luarocks/bin/luarocks install luasql-sqlite3 SQLITE_DIR=$serverPath/webstats/lua
echo "${VERSION}" > $serverPath/webstats/version.pl
echo '安装完成' > $install_tmp
# cd $rootPath && python3 ${rootPath}/plugins/webstats/index.py start
}
Uninstall_App()
{
rm -rf $serverPath/webstats
echo "Uninstall_redis" > $install_tmp
}
action=$1
if [ "${1}" == 'install' ];then
Install_App
else
Uninstall_App
fi

@ -0,0 +1,49 @@
log_by_lua_block {
local ver = '0.0.1'
local debug_mode = true
local server_name,ip,today,day,body_length,method,config,cache_count
local db = nil
local cache = ngx.shared.mw_total
local function D(msg)
if not debug_mode then return true end
local fp = io.open('{$SERVER_APP}/debug.log', 'ab')
if fp == nil then
return nil
end
local localtime = os.date("%Y-%m-%d %H:%M:%S")
if server_name then
fp:write(tostring(msg) .. "\n")
else
fp:write(localtime..":"..tostring(msg) .. "\n")
end
fp:flush()
fp:close()
return true
end
local function run_app()
D("debug start")
local presult, err = pcall(
function()
json = require "cjson"
sqlite3 = require "lsqlite3"
end
)
if not presult then
D("depend on :"..tostring(err))
return true
end
D("debug end")
end
return run_app()
}
Loading…
Cancel
Save