代码拉取完成,页面将自动刷新
同步操作将从 猪猪侠/zzxia-wireguard-manage 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/bin/bash
#############################################################################
# Create By: zhf_sy
# License: GNU GPLv3
# Test On: CentOS 7
#############################################################################
#
# 每天00:00运行
# 0 0 * * * /root/zzxia-wireguard-manage/wg-daily-report-cron.sh
# sh
SH_NAME=${0##*/}
SH_PATH=$( cd "$( dirname "$0" )" && pwd )
cd ${SH_PATH}
# env
. /etc/profile #--- 计划任务需要
. ${SH_PATH}/env.sh
#WG_IF=
#TODAY_WG_USER_FIRST_LOGIN_FILE=
# 本地env
#TIME=${TIME:-`date +%Y-%m-%dT%H:%M:%S`}
#TIME_START=${TIME}
#DATE_TIME=`date -d "${TIME}" +%Y%m%dt%H%M%S`
YESTERDAY_DATE=`date -d "yesterday" +%Y-%m-%d`
WG_DAILY_STATUS_FILE="/tmp/wg-daily-status.txt"
#
[ -d "${SH_PATH}/report" ] || mkdir "${SH_PATH}/report"
YESTERDAY_WG_REPORT_FILE="${SH_PATH}/report/wg-daily-report---${YESTERDAY_DATE}.md"
WG_REPORT_FILE="${SH_PATH}/report/wg-report.list"
# sh
FORMAT_TABLE_SH="${SH_PATH}/format_table.sh"
# 采集
wg show "${WG_IF}" dump > "${WG_DAILY_STATUS_FILE}"
sed -i '1d' "${WG_DAILY_STATUS_FILE}"
echo '|日期|姓名|总流量MiB|IN流量MiB|OUT流量MiB|用户IP|远程IP|' > ${YESTERDAY_WG_REPORT_FILE}
#echo '| -- | -- | ------- | ------- | -------- | ---- | ---- |' >> ${YESTERDAY_WG_REPORT_FILE}
#
while read LINE
do
USER_PEER=`echo $LINE | awk '{print $1}'`
USER_PRESHARED_KEY=`echo $LINE | awk '{print $2}'`
USER_ENDPOINT=`echo $LINE | awk '{print $3}'`
USER_ENDPOINT_IP=`echo ${USER_ENDPOINT} | cut -d ':' -f 1`
USER_ALLOWED_IPS=`echo $LINE | awk '{print $4}'`
USER_LATEST_HAND=`echo $LINE | awk '{print $5}'`
USER_NET_IN=`echo $LINE | awk '{print $6}'`
USER_NET_OUT=`echo $LINE | awk '{print $7}'`
USER_KEEPALIVE=`echo $LINE | awk '{print $8}'`
# 计算MiB
USER_NET_IN_MiB=`echo "scale=1; ${USER_NET_IN} / 1024 / 1024" | bc -l`
USER_NET_OUT_MiB=`echo "scale=1; ${USER_NET_OUT} / 1024 / 1024" | bc -l`
USER_NET_TOTAL_MiB=`echo "scale=1; ${USER_NET_IN_MiB} + ${USER_NET_OUT_MiB}" | bc -l`
#
# 查用户
USER_XINGMING=`grep -B 2 ${USER_PEER} ${SERVER_CONF_FILE} | head -n 1 | awk '{print $2}'`
USER_IP=`grep -B 2 ${USER_PEER} ${SERVER_CONF_FILE} | head -n 1 | awk '{print $3}'`
# 是否有握手信息
if [ ${USER_LATEST_HAND} -ne 0 ]; then
# 有握手信息
USER_LATEST_HAND_TIME=`date -d @${USER_LATEST_HAND} +%H:%M:%S`
# 昨日报表
echo "| ${YESTERDAY_DATE} | ${USER_XINGMING} | ${USER_NET_TOTAL_MiB} | ${USER_NET_IN_MiB} | ${USER_NET_OUT_MiB} | ${USER_IP} | ${USER_ENDPOINT_IP} | " >> ${YESTERDAY_WG_REPORT_FILE}
# 写入总报表
echo "| ${YESTERDAY_DATE} | ${USER_XINGMING} | ${USER_NET_TOTAL_MiB} | ${USER_NET_IN_MiB} | ${USER_NET_OUT_MiB} | ${USER_IP} | ${USER_ENDPOINT_IP} | " >> ${WG_REPORT_FILE}
fi
done < ${WG_DAILY_STATUS_FILE}
#
echo "昨日wg用户使用报告:"
#${FORMAT_TABLE_SH} --delimeter '|' --title '|日期|姓名|总流量MiB|IN流量MiB|OUT流量MiB|用户IP|远程IP|' --file ${YESTERDAY_WG_REPORT_FILE}
${FORMAT_TABLE_SH} --delimeter '|' --file ${YESTERDAY_WG_REPORT_FILE}
# 重启wg
wg-quick down ${WG_IF}
wg-quick up ${WG_IF}
# clean
> ${TODAY_WG_USER_FIRST_LOGIN_FILE}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。