Skip to content

Commit

Permalink
升级 v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cdwangtao committed Aug 16, 2021
1 parent 4026209 commit 6c69f68
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 75 deletions.
16 changes: 11 additions & 5 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
Koolshare Nps Changelog
===========================================
2020-08-13: v0.26.10.1
2020-08-13: v1.0.1 (nps版本:v0.26.10)
- 第一个beta版本
2020-08-13: v0.26.10.2
2020-08-13: v1.0.2
- 添加端口防火墙设置
2020-08-13: v0.26.10.3
2020-08-13: v1.0.3
- 添加自定义端口范围以及自定端口的自动添加防火墙放行、允许多用户登录、允许用户注册的配置
2020-08-14: v0.26.10.4
- 添加配置文件自动备份任务(同步时间可自定义),解决路由器重启后,配置丢失的问题
2020-08-14: v1.0.4
- 添加配置文件自动备份任务(同步时间可自定义),解决路由器重启后,配置丢失的问题
2020-08-14: v1.0.5
- 添加配置文件自动备份任务(同步时间可自定义),解决路由器重启后,配置丢失的问题(优化)
2020-08-16: v1.1.1
- 完美解决/etc/nps/在重启路由器丢失的问题
1.软件停止时,检测配置文件是否变化,如果有变化实时备份配置文件。在软件启动时,还原配置文件到/etc/nps/。
2.建议开启[定时备份配置]功能,开启后,会定时检查配置文件是否变化,如果有变化实时备份配置文件。
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,35 @@

nps server for Koolshare

# 说明
## 说明

本插件参考了[frps插件](https://github.com/koolshare/rogsoft),根据[nps插件](https://github.com/ehang-io/nps)打好的包进行二次封装
本插件参考了[frps插件](https://github.com/koolshare/rogsoft)的代码,根据[nps插件](https://github.com/ehang-io/nps)编译好的的包,进行封装成路由器插件。

本机基于AX86U进行测试,适用于koolshare 梅林改/官改 hnd/axhnd/axhnd.675x固件平台,其他机型未测试
本机基于AX86U进行测试,适用于koolshare 梅林改/官改 hnd/axhnd/axhnd.675x固件平台,其他机型未测试

目前已经bug: nps默认的配置文件目录[/etc/nps/],在路由器重启后会丢失,待解决
这是本人第一次尝试编写路由器插件,本打算开发自用的,现在分享出来,如果能帮到大家,那就更好了。

# 更新日志:
## 更新日志:

Koolshare Nps Changelog
===========================================
- v0.26.10.1
- 第一个beta版本
- v0.26.10.2
- 添加端口防火墙设置
- v0.26.10.4
- 添加自定义端口范围以及自定端口的自动添加防火墙放行、允许多用户登录、允许用户注册的配置
-------------------------------------------
2020-08-13: v1.0.1 (nps版本:v0.26.10)
- 第一个beta版本
2020-08-13: v1.0.2
- 添加端口防火墙设置
2020-08-13: v1.0.3
- 添加自定义端口范围以及自定端口的自动添加防火墙放行、允许多用户登录、允许用户注册的配置
2020-08-14: v1.0.4
- 添加配置文件自动备份任务(同步时间可自定义),解决路由器重启后,配置丢失的问题
2020-08-14: v1.0.5
- 添加配置文件自动备份任务(同步时间可自定义),解决路由器重启后,配置丢失的问题(优化)
2020-08-16: v1.1.1
- 完美解决/etc/nps/在重启路由器丢失的问题
1.软件停止时,检测配置文件是否变化,如果有变化实时备份配置文件。在软件启动时,还原配置文件到/etc/nps/。
2.建议开启[定时备份配置]功能,开启后,会定时检查配置文件是否变化,如果有变化实时备份配置文件。



## 运行图:

![Snipaste_2021-08-16_13-08-41](doc/run.png)
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

MODULE="nps"
VERSION="v0.26.10.4"
VERSION="v1.1.1"
TITLE="nps"
DESCRIPTION="一款轻量级、高性能、功能强大的内网穿透代理服务器。"
HOME_URL="Module_nps.asp"
Expand Down
2 changes: 1 addition & 1 deletion config.json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version":"v0.26.10.4",
"version":"v1.1.1",
"md5":"a50806415e3d615822b91518a56c26d5",
"home_url":"Module_nps.asp",
"title":"nps",
Expand Down
Binary file added doc/run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified nps.tar.gz
Binary file not shown.
18 changes: 9 additions & 9 deletions nps/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ install_now(){
cp -rf /tmp/${module}/webs/* /koolshare/webs/
cp -rf /tmp/${module}/uninstall.sh /koolshare/scripts/uninstall_${module}.sh
if [ ! -d "/etc/${module}/" ];then
echo_date "文件[/etc/${module}/]不存在, 开始拷贝[/koolshare/res/${module}/]到[/etc/]"
# mkdir -p /etc/nps/
# cp -rf /koolshare/res/${module}/* /etc/nps/
cp -rf /koolshare/res/${module}/ /etc/
echo_date "nps固定的配置目录[/etc/${module}/]不存在, 开始创建[/etc/${module}/]目录,并拷贝[/koolshare/res/${module}/*]到[/etc/${module}/]"
mkdir -p /etc/${module}/
cp -rf /koolshare/res/${module}/* /etc/${module}/
# cp -rf /koolshare/res/${module}/ /etc/
fi
pause "拷贝资源完成"
# pause "拷贝资源完成"

# 5.修改文件全选
# 5.修改文件权限 添加可执行权限
# Permissions
chmod 755 /koolshare/bin/* >/dev/null 2>&1
chmod 755 /koolshare/scripts/* >/dev/null 2>&1
Expand All @@ -190,7 +190,7 @@ install_now(){
# intall different UI
install_ui

# 8.设置插件默认参数
# 8.设置插件默认参数1.软件中心参数
# dbus value
echo_date "设置插件默认参数..."
dbus set ${module}_version="${PLVER}"
Expand All @@ -200,7 +200,7 @@ install_now(){
dbus set softcenter_module_${module}_title="${TITLE}"
dbus set softcenter_module_${module}_description="${DESCR}"

# 9.设置默认参数
# 9.设置插件默认参数2.默认值 插件版本-软件版本
# defalut value
local VERSION=$(cat $DIR/version)
dbus set ${module}_version="${VERSION}"
Expand Down Expand Up @@ -256,7 +256,7 @@ install_now(){
sh /koolshare/scripts/nps_config.sh restart
fi

# 11.完成插件安装
# 11.完成插件安装 推出安装 删除临时文件
# finish
echo_date "${TITLE}插件安装完毕!"
exit_install
Expand Down
130 changes: 88 additions & 42 deletions nps/scripts/nps_config.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/sh

source /koolshare/scripts/base.sh
eval $(dbus export nps_)
CONF_FILE=/koolshare/configs/nps/nps.conf
CONF_REAL_FILE=/etc/nps/conf/nps.conf
# nps conf的备份目录 固定目录[/etc/nps/conf]
CONF_BAKALL_DIR=/koolshare/res/nps/conf
CONF_BAK_DIR=/koolshare/configs/nps
CONF_REAL_DIR=/etc/nps/conf
# nps web的备份目录 固定目录[/etc/nps/web]
WEB_BAK_DIR=/koolshare/res/nps/web
WEB_REAL_DIR=/etc/nps/web
LOG_FILE=/tmp/upload/nps_log.txt
LOCK_FILE=/var/lock/nps.lock
alias echo_date='echo 【$(TZ=UTC-8 date -R +%Y年%m月%d日\ %X)】:'
true > $LOG_FILE
# true > $LOG_FILE

# 设置 锁?
set_lock() {
Expand Down Expand Up @@ -66,12 +70,13 @@ onstart() {
fi
echo_date "当前插件nps主程序版本号:${nps_client_version}"

# nps配置文件
if [ ! -d "/koolshare/configs/nps/" ];then
mkdir -p "/koolshare/configs/nps/"
# 判断 nps 配置的备份目录是否存在 不存在则创建
if [ ! -d "${CONF_BAK_DIR}/" ];then
mkdir -p "${CONF_BAK_DIR}/"
fi
echo_date "生成nps配置文件到 ${CONF_FILE}"
cat >${CONF_FILE} <<-EOF
# 生成 nps 配置文件
echo_date "生成nps配置文件到 ${CONF_BAK_DIR}/nps.conf"
cat >"${CONF_BAK_DIR}/nps.conf" <<-EOF
appname = nps
#Boot mode(dev|pro)
runmode = pro
Expand Down Expand Up @@ -158,44 +163,45 @@ http_add_origin_header=false
#client disconnect timeout
disconnect_timeout=60
EOF
# 拷贝配置文件到 nps实际读取的 真实的配置文件位置
if [ ! -d "/etc/nps/conf/" ];then
echo_date "文件[/etc/nps/conf/]不存在, 开始拷贝[/koolshare/res/nps/conf/]到[/etc/nps/]"
mkdir -p "/etc/nps/conf/"
cp -rf /koolshare/res/nps/conf/ /etc/nps/
# 拷贝1.配置文件(conf)
if [ ! -d "${CONF_REAL_DIR}/" ];then
echo_date "nps固定的配置目录(conf)[${CONF_REAL_DIR}/]不存在, 开始创建[${CONF_REAL_DIR}/]目录,并拷贝[${CONF_BAKALL_DIR}/*]到[${CONF_REAL_DIR}/]"
mkdir -p "${CONF_REAL_DIR}"
cp -rf "${CONF_BAKALL_DIR}/*" "${CONF_REAL_DIR}/"
# cp -rf /koolshare/res/nps/conf/ /etc/nps/
fi
if [ ! -d "/etc/nps/web/" ];then
echo_date "文件[/etc/nps/web/]不存在, 开始拷贝[/koolshare/res/nps/web/]到[/etc/nps/]"
mkdir -p "/etc/nps/web/"
cp -rf /koolshare/res/nps/web/ /etc/nps/
# 拷贝2.资源文件(web)
if [ ! -d "${WEB_REAL_DIR}/" ];then
echo_date "nps固定的配置目录(web)[${WEB_REAL_DIR}/]不存在, 开始创建[${WEB_REAL_DIR}/]目录,并拷贝[${WEB_BAK_DIR}/*]到[${WEB_REAL_DIR}/]"
mkdir -p "${WEB_REAL_DIR}/"
cp -rf "${WEB_BAK_DIR}/*" "${WEB_REAL_DIR}/"
# cp -rf /koolshare/res/nps/web/ /etc/nps/
fi
cp -rf ${CONF_FILE} ${CONF_REAL_FILE}
cp -rf /koolshare/configs/nps/clients.json /etc/nps/conf/clients.json
cp -rf /koolshare/configs/nps/hosts.json /etc/nps/conf/hosts.json
cp -rf /koolshare/configs/nps/tasks.json /etc/nps/conf/tasks.json
# wt增强1.还原配置文件 参数1(是否比较时间拷贝文件 1:比较时间 0:不比较)
on_restore_conf 0

# 定时任务 1
if [ "${nps_common_cron_time}" == "0" ]; then
cru d nps_monitor >/dev/null 2>&1
else
if [ "${nps_common_cron_hour_min}" == "min" ]; then
echo_date "设置定时任务:每隔${nps_common_cron_time}分钟注册一次nps服务..."
echo_date "设置定时任务:每隔${nps_common_cron_time}分钟重启nps服务..."
cru a nps_monitor "*/"${nps_common_cron_time}" * * * * /bin/sh /koolshare/scripts/nps_config.sh restart"
elif [ "${nps_common_cron_hour_min}" == "hour" ]; then
echo_date "设置定时任务:每隔${nps_common_cron_time}小时注册一次nps服务..."
echo_date "设置定时任务:每隔${nps_common_cron_time}小时重启nps服务..."
cru a nps_monitor "0 */"${nps_common_cron_time}" * * * /bin/sh /koolshare/scripts/nps_config.sh restart"
fi
echo_date "定时任务设置完成!"
fi
# 定时任务 2 定时备份配置文件
if [ "${nps_common_cron1_time}" == "0" ]; then
if [ "${nps_common_cron2_time}" == "0" ]; then
cru d nps_monitor >/dev/null 2>&1
else
if [ "${nps_common_cron1_hour_min}" == "min" ]; then
echo_date "设置定时任务:每隔${nps_common_cron2_time}分钟备份一次nps配置文件..."
if [ "${nps_common_cron2_hour_min}" == "min" ]; then
echo_date "设置定时任务:每隔${nps_common_cron2_time}分钟备份一次nps配置文件(如果配置文件有变化)..."
cru a nps_monitor "*/"${nps_common_cron2_time}" * * * * /bin/sh /koolshare/scripts/nps_config.sh backconf"
elif [ "${nps_common_cron2_hour_min}" == "hour" ]; then
echo_date "设置定时任务:每隔${nps_common_cron2_time}小时备份一次nps配置文件..."
echo_date "设置定时任务:每隔${nps_common_cron2_time}小时备份一次nps配置文件(如果配置文件有变化)..."
cru a nps_monitor "0 */"${nps_common_cron2_time}" * * * /bin/sh /koolshare/scripts/nps_config.sh backconf"
fi
echo_date "定时任务设置完成!"
Expand Down Expand Up @@ -306,12 +312,13 @@ close_in_five() {
}
# 停止
stop() {
# wt增强2.备份配置文件 参数1(是否比较时间拷贝文件 1:比较时间 0:不比较)
on_back_conf 1
# 关闭nps进程
if [ -n "$(pidof nps)" ];then
echo_date "停止nps主进程,pid:$(pidof nps)"
killall nps >/dev/null 2>&1
fi

# 删除定时任务1
if [ -n "$(cru l|grep nps_monitor)" ];then
echo_date "删除定时任务1..."
Expand All @@ -322,20 +329,56 @@ stop() {
echo_date "删除定时任务2..."
cru d nps_monitor2 >/dev/null 2>&1
fi

# 删除开机自启动
if [ -L "/koolshare/init.d/N95nps.sh" ];then
echo_date "删除nat触发..."
rm -rf /koolshare/init.d/N95nps.sh >/dev/null 2>&1
fi
# 关闭端口
close_port
echo_date "删除nat触发..."
rm -rf /koolshare/init.d/N95nps.sh >/dev/null 2>&1
fi
# 关闭端口
close_port
}
# 执行备份配置文件
onbackconf() {
echo_date "执行备份nps配置文件"
cp -rf /etc/nps/conf/clients.json /koolshare/configs/nps/clients.json
cp -rf /etc/nps/conf/hosts.json /koolshare/configs/nps/hosts.json
cp -rf /etc/nps/conf/tasks.json /koolshare/configs/nps/tasks.json
# wt增强1.还原配置文件 参数1(是否比较时间拷贝文件 1:比较时间 0:不比较)
on_restore_conf() {
if [ "${1}" == "1" ]; then
compareTwoFileTimesAndCopy "${CONF_BAK_DIR}/nps.conf" "${CONF_REAL_DIR}/nps.conf" "还原"
compareTwoFileTimesAndCopy "${CONF_BAK_DIR}/clients.json" "${CONF_REAL_DIR}/clients.json" "还原"
compareTwoFileTimesAndCopy "${CONF_BAK_DIR}/hosts.json" "${CONF_REAL_DIR}/hosts.json" "还原"
compareTwoFileTimesAndCopy "${CONF_BAK_DIR}/tasks.json" "${CONF_REAL_DIR}/tasks.json" "还原"
else
echo_date "还原配置文件 nps.conf clients.json hosts.json tasks.json"
cp -rf "${CONF_BAK_DIR}/nps.conf" "${CONF_REAL_DIR}/nps.conf"
cp -rf "${CONF_BAK_DIR}/clients.json" "${CONF_REAL_DIR}/clients.json"
cp -rf "${CONF_BAK_DIR}/hosts.json" "${CONF_REAL_DIR}/hosts.json"
cp -rf "${CONF_BAK_DIR}/tasks.json" "${CONF_REAL_DIR}/tasks.json"
fi
}
# wt增强2.备份配置文件 参数1(是否比较时间拷贝文件 1:比较时间 0:不比较)
on_back_conf() {
if [ "${1}" == "1" ]; then
compareTwoFileTimesAndCopy "${CONF_REAL_DIR}/nps.conf" "${CONF_BAK_DIR}/nps.conf" "备份"
compareTwoFileTimesAndCopy "${CONF_REAL_DIR}/clients.json" "${CONF_BAK_DIR}/clients.json" "备份"
compareTwoFileTimesAndCopy "${CONF_REAL_DIR}/hosts.json" "${CONF_BAK_DIR}/hosts.json" "备份"
compareTwoFileTimesAndCopy "${CONF_REAL_DIR}/tasks.json" "${CONF_BAK_DIR}/tasks.json" "备份"
else
echo_date "备份配置文件 nps.conf clients.json hosts.json tasks.json"
cp -rf "${CONF_REAL_DIR}/nps.conf" "${CONF_BAK_DIR}/nps.conf"
cp -rf "${CONF_REAL_DIR}/clients.json" "${CONF_BAK_DIR}/clients.json"
cp -rf "${CONF_REAL_DIR}/hosts.json" "${CONF_BAK_DIR}/hosts.json"
cp -rf "${CONF_REAL_DIR}/tasks.json" "${CONF_BAK_DIR}/tasks.json"
fi
}
# wt增强3 比较两个文件时间并复制
compareTwoFileTimesAndCopy() {
fileTimes1=$(date +%s -r ${1})
fileTimes2=$(date +%s -r ${2})
if [[ "${fileTimes1}" \> "${fileTimes2}" ]];then
# echo_date "比较时间${3}配置文件 拷贝[${1}]到[${2}] 时间(${fileTimes1})大于时间(${fileTimes2})"
echo_date "比较时间${3}配置文件 拷贝[${1}]到[${2}] 时间(${fileTimes1})大于时间(${fileTimes2})" | tee -a $LOG_FILE
cp -rf "${1}" "${2}"
fi
# else
# echo "文件1[${1}]的时间(${fileTimes1}) 小于 文件2[${2}的时间(${fileTimes2})"
# fi
}

# 功能
Expand Down Expand Up @@ -375,7 +418,8 @@ start_nat)
backconf)
set_lock
if [ "${nps_enable}" == "1" ]; then
onbackconf
# wt增强2.备份配置文件 参数1(是否比较时间拷贝文件 1:比较时间 0:不比较)
on_back_conf 1
fi
unset_lock
;;
Expand All @@ -385,6 +429,8 @@ esac
case $2 in
web_submit)
set_lock
# 清空日志
true > $LOG_FILE
http_response "$1"
if [ "${nps_enable}" == "1" ]; then
stop | tee -a $LOG_FILE
Expand Down
2 changes: 1 addition & 1 deletion nps/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.26.10.4
v1.1.1
7 changes: 4 additions & 3 deletions nps/webs/Module_nps.asp
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,10 @@ function get_log(action){
</label>
</div>
<div style="float: right;margin-top:5px;margin-right:30px;">
<a type="button" href="https://github.com/ehang-io/nps" target="_blank" class="ks_btn" style="cursor: pointer;border:none;" >nps开源项目</a>
<!--<a type="button" href="https://koolshare.cn/thread-65379-1-1.html" target="_blank" class="ks_btn" style="cursor: pointer;margin-left:5px;border:none" >服务器搭建教程</a>-->
<!--<a type="button" href="https://raw.githubusercontent.com/koolshare/rogsoft/master/nps/Changelog.txt" target="_blank" class="ks_btn" style="cursor: pointer;margin-left:5px;border:none" >更新日志</a>-->
<a type="button" href="https://github.com/cdwangtao/koolshare_nps" target="_blank" class="ks_btn" style="cursor: pointer;border:none;" >nps插件</a>
<a type="button" href="https://github.com/ehang-io/nps" target="_blank" class="ks_btn" style="cursor: pointer;border:none;" >nps项目</a>
<a type="button" href="https://ehang-io.github.io/nps/" target="_blank" class="ks_btn" style="cursor: pointer;margin-left:5px;border:none" >手册</a>
<a type="button" href="https://raw.githubusercontent.com/cdwangtao/koolshare_nps/master/Changelog.txt" target="_blank" class="ks_btn" style="cursor: pointer;margin-left:5px;border:none" >更新日志</a>
<a type="button" class="ks_btn" href="javascript:void(0);" onclick="get_log(1)" style="cursor: pointer;margin-left:5px;border:none">查看日志</a>
</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
v0.26.10.4
v1.1.1
a50806415e3d615822b91518a56c26d5

0 comments on commit 6c69f68

Please sign in to comment.