From 4cd8e02d2c3ae83c9b748391602e78b2917bfde2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 3 Mar 2023 19:12:20 +0800 Subject: [PATCH] update 2023-03-03 19:12:20 --- autoupdate/Makefile | 32 + autoupdate/files/bin/autoupdate | 1427 +++++++++++++++++ autoupdate/files/etc/autoupdate/default | 2 + luci-app-adguardhome/Makefile | 71 - luci-app-adguardhome/README.md | 17 - .../luasrc/controller/AdGuardHome.lua | 130 -- .../luasrc/model/cbi/AdGuardHome/base.lua | 316 ---- .../luasrc/model/cbi/AdGuardHome/log.lua | 16 - .../luasrc/model/cbi/AdGuardHome/manual.lua | 100 -- .../view/AdGuardHome/AdGuardHome_check.htm | 78 - .../view/AdGuardHome/AdGuardHome_chpass.htm | 49 - .../view/AdGuardHome/AdGuardHome_status.htm | 27 - .../luasrc/view/AdGuardHome/log.htm | 110 -- .../luasrc/view/AdGuardHome/yamleditor.htm | 39 - luci-app-adguardhome/po/zh-cn/AdGuardHome.po | 275 ---- .../po/zh_Hans/AdGuardHome.po | 275 ---- .../root/etc/config/AdGuardHome | 11 - .../root/etc/init.d/AdGuardHome | 615 ------- .../root/etc/uci-defaults/40_luci-AdGuardHome | 12 - .../AdGuardHome/AdGuardHome_template.yaml | 136 -- .../root/usr/share/AdGuardHome/addhost.sh | 33 - .../root/usr/share/AdGuardHome/firewall.start | 8 - .../root/usr/share/AdGuardHome/getsyslog.sh | 19 - .../root/usr/share/AdGuardHome/gfw2adg.sh | 86 - .../root/usr/share/AdGuardHome/links.txt | 4 - .../root/usr/share/AdGuardHome/tailto.sh | 4 - .../root/usr/share/AdGuardHome/update_core.sh | 217 --- .../root/usr/share/AdGuardHome/waitnet.sh | 34 - .../root/usr/share/AdGuardHome/watchconfig.sh | 12 - .../rpcd/acl.d/luci-app-adguardhome.json | 11 - .../codemirror/addon/fold/foldcode.js | 1 - .../codemirror/addon/fold/foldgutter.css | 1 - .../codemirror/addon/fold/foldgutter.js | 1 - .../codemirror/addon/fold/indent-fold.js | 1 - .../resources/codemirror/lib/codemirror.css | 1 - .../resources/codemirror/lib/codemirror.js | 1 - .../resources/codemirror/mode/yaml/yaml.js | 1 - .../resources/codemirror/theme/dracula.css | 1 - .../luci-static/resources/twin-bcrypt.min.js | 7 - luci-app-autoupdate/Makefile | 15 + luci-app-autoupdate/README.md | 3 + .../luasrc/controller/autoupdate.lua | 17 + .../luasrc/model/cbi/autoupdate/log.lua | 6 + .../luasrc/model/cbi/autoupdate/main.lua | 80 + .../luasrc/model/cbi/autoupdate/manual.lua | 47 + .../luasrc/view/autoupdate/autoupdate_log.htm | 20 + luci-app-autoupdate/po/zh-cn/autoupdate.po | 104 ++ luci-app-autoupdate/po/zh_Hans/autoupdate.po | 101 ++ .../root/etc/autoupdate/custom | 8 + .../root/etc/config/autoupdate | 2 + .../root/etc/init.d/autoupdate | 61 + .../root/etc/uci-defaults/luci-autoupdate | 10 + .../share/rpcd/acl.d/luci-app-autoupdate.json | 11 + luci-app-iperf3-server/Makefile | 13 + luci-app-iperf3-server/README.md | 3 + .../luasrc/controller/iperf3-server.lua | 17 + .../luasrc/model/cbi/iperf3-server.lua | 36 + .../iperf3-server/iperf3-server_status.htm | 22 + .../po/zh-cn/iperf3-server.po | 26 + .../po/zh_Hans/iperf3-server.po | 26 + .../root/etc/config/iperf3-server | 4 + .../root/etc/init.d/iperf3-server | 57 + .../root/etc/uci-defaults/iperf3-server | 10 + .../rpcd/acl.d/luci-app-iperf3-server.json | 11 + luci-app-natter/Makefile | 15 + luci-app-natter/README.md | 3 + luci-app-natter/luasrc/controller/natter.lua | 21 + .../luasrc/model/cbi/natter/base.lua | 87 + .../luasrc/model/cbi/natter/log.lua | 6 + .../luasrc/model/cbi/natter/ports.lua | 65 + .../luasrc/view/natter/natter_log.htm | 29 + luci-app-natter/po/zh-cn/natter.po | 114 ++ luci-app-natter/po/zh_Hans | 1 + luci-app-natter/root/etc/config/natter | 15 + luci-app-natter/root/etc/init.d/natter | 235 +++ .../root/etc/uci-defaults/luci-natter | 17 + .../root/usr/share/luci-app-natter/log.sh | 19 + .../usr/share/luci-app-natter/natcheck.sh | 18 + .../usr/share/rpcd/acl.d/luci-app-natter.json | 11 + luci-app-npc/Makefile | 14 + luci-app-npc/README.md | 11 + luci-app-npc/luasrc/controller/npc.lua | 17 + luci-app-npc/luasrc/model/cbi/npc.lua | 50 + luci-app-npc/luasrc/view/npc/npc_status.htm | 22 + luci-app-npc/po/zh-cn/npc.po | 56 + luci-app-npc/po/zh_Hans/npc.po | 56 + luci-app-npc/root/etc/config/npc | 6 + luci-app-npc/root/etc/init.d/npc | 67 + luci-app-npc/root/etc/uci-defaults/luci-npc | 11 + .../usr/share/rpcd/acl.d/luci-app-npc.json | 11 + luci-app-shutdown/Makefile | 13 + luci-app-shutdown/README.md | 3 + .../luasrc/controller/shutdown.lua | 5 + .../luasrc/model/cbi/shutdown.lua | 23 + luci-app-shutdown/po/zh-cn/shutdown.po | 23 + luci-app-shutdown/po/zh_Hans/shutdown.po | 23 + luci-app-webd/Makefile | 25 + luci-app-webd/README.md | 3 + luci-app-webd/luasrc/controller/webd.lua | 17 + luci-app-webd/luasrc/model/cbi/webd.lua | 82 + .../luasrc/view/webd/webd_status.htm | 27 + luci-app-webd/po/zh-cn/webd.po | 80 + luci-app-webd/po/zh_Hans/webd.po | 80 + luci-app-webd/root/etc/config/webd | 13 + luci-app-webd/root/etc/init.d/webd | 120 ++ luci-app-webd/root/etc/uci-defaults/luci-webd | 11 + .../usr/share/rpcd/acl.d/luci-app-webd.json | 11 + natter/Makefile | 40 + upx-static/Makefile | 6 +- webd/Makefile | 93 ++ 110 files changed, 3843 insertions(+), 2723 deletions(-) create mode 100755 autoupdate/Makefile create mode 100755 autoupdate/files/bin/autoupdate create mode 100755 autoupdate/files/etc/autoupdate/default delete mode 100755 luci-app-adguardhome/Makefile delete mode 100755 luci-app-adguardhome/README.md delete mode 100755 luci-app-adguardhome/luasrc/controller/AdGuardHome.lua delete mode 100755 luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua delete mode 100755 luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/log.lua delete mode 100755 luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua delete mode 100755 luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_check.htm delete mode 100755 luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_chpass.htm delete mode 100755 luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_status.htm delete mode 100755 luci-app-adguardhome/luasrc/view/AdGuardHome/log.htm delete mode 100755 luci-app-adguardhome/luasrc/view/AdGuardHome/yamleditor.htm delete mode 100755 luci-app-adguardhome/po/zh-cn/AdGuardHome.po delete mode 100644 luci-app-adguardhome/po/zh_Hans/AdGuardHome.po delete mode 100755 luci-app-adguardhome/root/etc/config/AdGuardHome delete mode 100755 luci-app-adguardhome/root/etc/init.d/AdGuardHome delete mode 100755 luci-app-adguardhome/root/etc/uci-defaults/40_luci-AdGuardHome delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/AdGuardHome_template.yaml delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/addhost.sh delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/firewall.start delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/getsyslog.sh delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/gfw2adg.sh delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/links.txt delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/tailto.sh delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/update_core.sh delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/waitnet.sh delete mode 100755 luci-app-adguardhome/root/usr/share/AdGuardHome/watchconfig.sh delete mode 100755 luci-app-adguardhome/root/usr/share/rpcd/acl.d/luci-app-adguardhome.json delete mode 100755 luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/foldcode.js delete mode 100755 luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/foldgutter.css delete mode 100755 luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/foldgutter.js delete mode 100755 luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/indent-fold.js delete mode 100755 luci-app-adguardhome/root/www/luci-static/resources/codemirror/lib/codemirror.css delete mode 100755 luci-app-adguardhome/root/www/luci-static/resources/codemirror/lib/codemirror.js delete mode 100755 luci-app-adguardhome/root/www/luci-static/resources/codemirror/mode/yaml/yaml.js delete mode 100755 luci-app-adguardhome/root/www/luci-static/resources/codemirror/theme/dracula.css delete mode 100755 luci-app-adguardhome/root/www/luci-static/resources/twin-bcrypt.min.js create mode 100755 luci-app-autoupdate/Makefile create mode 100755 luci-app-autoupdate/README.md create mode 100755 luci-app-autoupdate/luasrc/controller/autoupdate.lua create mode 100755 luci-app-autoupdate/luasrc/model/cbi/autoupdate/log.lua create mode 100755 luci-app-autoupdate/luasrc/model/cbi/autoupdate/main.lua create mode 100755 luci-app-autoupdate/luasrc/model/cbi/autoupdate/manual.lua create mode 100755 luci-app-autoupdate/luasrc/view/autoupdate/autoupdate_log.htm create mode 100755 luci-app-autoupdate/po/zh-cn/autoupdate.po create mode 100755 luci-app-autoupdate/po/zh_Hans/autoupdate.po create mode 100755 luci-app-autoupdate/root/etc/autoupdate/custom create mode 100755 luci-app-autoupdate/root/etc/config/autoupdate create mode 100755 luci-app-autoupdate/root/etc/init.d/autoupdate create mode 100755 luci-app-autoupdate/root/etc/uci-defaults/luci-autoupdate create mode 100644 luci-app-autoupdate/root/usr/share/rpcd/acl.d/luci-app-autoupdate.json create mode 100755 luci-app-iperf3-server/Makefile create mode 100755 luci-app-iperf3-server/README.md create mode 100755 luci-app-iperf3-server/luasrc/controller/iperf3-server.lua create mode 100755 luci-app-iperf3-server/luasrc/model/cbi/iperf3-server.lua create mode 100755 luci-app-iperf3-server/luasrc/view/iperf3-server/iperf3-server_status.htm create mode 100755 luci-app-iperf3-server/po/zh-cn/iperf3-server.po create mode 100755 luci-app-iperf3-server/po/zh_Hans/iperf3-server.po create mode 100755 luci-app-iperf3-server/root/etc/config/iperf3-server create mode 100755 luci-app-iperf3-server/root/etc/init.d/iperf3-server create mode 100755 luci-app-iperf3-server/root/etc/uci-defaults/iperf3-server create mode 100644 luci-app-iperf3-server/root/usr/share/rpcd/acl.d/luci-app-iperf3-server.json create mode 100755 luci-app-natter/Makefile create mode 100644 luci-app-natter/README.md create mode 100755 luci-app-natter/luasrc/controller/natter.lua create mode 100755 luci-app-natter/luasrc/model/cbi/natter/base.lua create mode 100755 luci-app-natter/luasrc/model/cbi/natter/log.lua create mode 100755 luci-app-natter/luasrc/model/cbi/natter/ports.lua create mode 100755 luci-app-natter/luasrc/view/natter/natter_log.htm create mode 100755 luci-app-natter/po/zh-cn/natter.po create mode 120000 luci-app-natter/po/zh_Hans create mode 100755 luci-app-natter/root/etc/config/natter create mode 100755 luci-app-natter/root/etc/init.d/natter create mode 100755 luci-app-natter/root/etc/uci-defaults/luci-natter create mode 100755 luci-app-natter/root/usr/share/luci-app-natter/log.sh create mode 100755 luci-app-natter/root/usr/share/luci-app-natter/natcheck.sh create mode 100644 luci-app-natter/root/usr/share/rpcd/acl.d/luci-app-natter.json create mode 100755 luci-app-npc/Makefile create mode 100755 luci-app-npc/README.md create mode 100755 luci-app-npc/luasrc/controller/npc.lua create mode 100755 luci-app-npc/luasrc/model/cbi/npc.lua create mode 100755 luci-app-npc/luasrc/view/npc/npc_status.htm create mode 100755 luci-app-npc/po/zh-cn/npc.po create mode 100755 luci-app-npc/po/zh_Hans/npc.po create mode 100755 luci-app-npc/root/etc/config/npc create mode 100755 luci-app-npc/root/etc/init.d/npc create mode 100755 luci-app-npc/root/etc/uci-defaults/luci-npc create mode 100644 luci-app-npc/root/usr/share/rpcd/acl.d/luci-app-npc.json create mode 100755 luci-app-shutdown/Makefile create mode 100755 luci-app-shutdown/README.md create mode 100755 luci-app-shutdown/luasrc/controller/shutdown.lua create mode 100755 luci-app-shutdown/luasrc/model/cbi/shutdown.lua create mode 100755 luci-app-shutdown/po/zh-cn/shutdown.po create mode 100755 luci-app-shutdown/po/zh_Hans/shutdown.po create mode 100755 luci-app-webd/Makefile create mode 100644 luci-app-webd/README.md create mode 100755 luci-app-webd/luasrc/controller/webd.lua create mode 100755 luci-app-webd/luasrc/model/cbi/webd.lua create mode 100755 luci-app-webd/luasrc/view/webd/webd_status.htm create mode 100755 luci-app-webd/po/zh-cn/webd.po create mode 100755 luci-app-webd/po/zh_Hans/webd.po create mode 100755 luci-app-webd/root/etc/config/webd create mode 100755 luci-app-webd/root/etc/init.d/webd create mode 100755 luci-app-webd/root/etc/uci-defaults/luci-webd create mode 100644 luci-app-webd/root/usr/share/rpcd/acl.d/luci-app-webd.json create mode 100755 natter/Makefile create mode 100755 webd/Makefile diff --git a/autoupdate/Makefile b/autoupdate/Makefile new file mode 100755 index 000000000..f9e8492de --- /dev/null +++ b/autoupdate/Makefile @@ -0,0 +1,32 @@ +# Copyright (C) 2020-2022 Hyy2001X + +include $(TOPDIR)/rules.mk + +PKG_NAME:=autoupdate +PKG_VERSION:=1 +PKG_RELEASE:=1 + +include $(INCLUDE_DIR)/package.mk + +define Package/$(PKG_NAME) + SECTION:=utils + CATEGORY:=Utilities + TITLE:=Upgrade OpenWrt by one-key + DEPENDS:=+bash +jq +endef + +define Package/$(PKG_NAME)/description + autoupdate - Upgrade OpenWrt by one-key +endef + +define Build/Compile +endef + +define Package/$(PKG_NAME)/install + $(INSTALL_DIR) $(1)/bin + $(INSTALL_BIN) ./files/bin/autoupdate $(1)/bin + $(INSTALL_DIR) $(1)/etc/autoupdate + $(CP) ./files/etc/autoupdate/* $(1)/etc/autoupdate +endef + +$(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/autoupdate/files/bin/autoupdate b/autoupdate/files/bin/autoupdate new file mode 100755 index 000000000..7c5d7ef47 --- /dev/null +++ b/autoupdate/files/bin/autoupdate @@ -0,0 +1,1427 @@ +#!/bin/bash +# AutoBuild Module by Hyy2001 +# AutoUpdate for Openwrt +# Dependences: wget-ssl/wget/uclient-fetch curl jq expr sysupgrade + +Version=V6.9.6 + +function TITLE() { + clear && echo "Openwrt-AutoUpdate Script by Hyy2001 ${Version}" +} + +function SHELL_HELP() { + local Next="${Grey}⌊ ...${White}" + TITLE + echo -e " +使用方法: bash $0 [-n] [-f] [-u] [-F] [-P] [-D ] [--path ] ... + bash $0 [-x] [--path ] [--url ] ... + +更新固件: + -n 不保留配置更新固件 * + -u 适用于定时更新 LUCI 的参数 * + -f 跳过版本号校验,并强制刷写固件 ${Red}(危险)${White} * + -F, --force-flash 强制刷写固件 ${Red}(危险)${White} * + -P, --proxy 优先开启镜像加速下载固件 * + -D 使用指定的下载器 * + --decompress 解压 img.gz 固件后再更新固件 * + --skip-verify 跳过固件 SHA256 校验 ${Red}(危险)${White} * + --path 固件下载到用户提供的绝对路径 * + +更新程序: + -x 更新 autoupdate 程序 + -x -path 更新 autoupdate 程序 (保存程序到用户提供的绝对路径 ) * + -x -url 更新 autoupdate 程序 (使用提供的地址 更新程序) * + +其他参数: + --help 打印 AutoUpdate 程序帮助信息 + -B, --boot-mode 指定 x86 设备下载 引导的固件 (e.g. UEFI BIOS) + -C 更改 Github 地址为提供的 + --api 打印 Github API 内容 + --backup 备份当前系统配置到当前路径 + ${Next} -path 备份当前系统配置文件到用户提供的绝对路径 + --chk 检查 AutoUpdate 运行环境 + --clean 清理 AutoUpdate 缓存 + --flag 更改固件标签为提供的 + ${Next} -reset 恢复默认的固件标签 + --fw-log < | *> 打印 <当前 | 指定> 版本的固件更新日志 + --env 打印用户指定的环境变量 + ${Next} -list 打印环境变量列表 + --log 打印 AutoUpdate 运行日志 ${Green}(问题反馈)${White} + ${Next} -clean 清空程序运行日志 + ${Next} -path 更改 AutoUpdate 运行日志保存路径到用户提供的绝对路径 + --list 打印当前系统信息 + --reset 重置 AutoUpdate 运行环境 + --verbose 打印详细下载信息 * + -v < | [Cc]loud> 打印 <当前 | 云端> autoupdate 版本 + -V < | [Cc]loud> 打印 <当前 | 云端> 固件版本 + +程序、固件更新问题反馈请到 ${Github} 反馈,并上程序运行日志与系统信息 +" + exit +} + +function SHOW_VARIABLE() { + TITLE + cat < +EOF + [[ ${TARGET_BOARD} == x86 ]] && { + echo "固件引导: ${x86_Boot_Method}" + } + echo + return 0 +} + +function MEMINFO() { + [[ ! $1 || ! $* =~ (All|Mem|Swap) ]] && return 1 + local Mem Swap All Result + Mem=$(free | grep Mem: | awk '{Mem=$7/1024} {printf("%.0f\n",Mem)}' 2> /dev/null) + Swap=$(free | grep Swap: | awk '{Swap=$4/1024} {printf("%.0f\n",Swap)}' 2> /dev/null) + All=$(expr ${Mem} + ${Swap} 2> /dev/null) + Result=$(eval echo '$'$1) + if [[ ${Result} ]] + then + LOGGER "[$1] 可用运行内存: [${Result}M]" + echo ${Result} + return 0 + else + LOGGER "[$1] 可用内存获取失败!" + return 1 + fi +} + +function SPACEINFO() { + [[ ! $1 ]] && return 1 + local Result Path + Path="$(awk -F '/' '{print $2}' <<< $1)" + Result="$(df -m /${Path} 2> /dev/null | grep -v Filesystem | awk '{print $4}')" + if [[ ${Result} ]] + then + LOGGER "[/${Path}] 可用存储空间: [${Result}M]" + echo "${Result}" + return 0 + else + LOGGER "[/${Path}] 可用存储空间获取失败!" + return 1 + fi +} + +function RM() { + for i in $@ + do + rm -r "$i" 2> /dev/null + LOGGER "删除文件: [$i]" + done +} + +function STRING() { + [[ $# -gt 3 ]] && return + case $1 in + -f) + shift + [[ ! -r $1 ]] && return + egrep -q $2 $1 2> /dev/null && echo -n $2 + ;; + *) + echo -n $1 | egrep -q $2 2> /dev/null && echo -n $2 + ;; + esac + return +} + +function LIST_ENV() { + local ENV + case $1 in + -list) + cat ${Config_Default} ${Config_Custom} 2> /dev/null | grep -v '#' | while read ENV;do + case $2 in + 1 | 2) + [[ ${ENV} ]] && eval echo ${ENV} | awk -F '=' '{print $"'$2'"}' + ;; + *) + [[ ${ENV} ]] && eval echo ${ENV} + ;; + esac + done + return 0 + ;; + *) + while [[ $1 ]];do + ENV=$1 + if [[ ! ${ENV} =~ (-) && ! ${ENV} == [0-9] && ${ENV} =~ [0-9a-zA-Z] ]] + then + if [[ $(eval echo \$\{#$ENV[@]\}) -gt 1 ]] + then + eval echo \$\{$ENV[@]\} + else + # ENV_Result="$(GET_VARIABLE $ENV ${Config_Custom})" + # [[ ! ${ENV_Result} ]] && ENV_Result="$(GET_VARIABLE $ENV ${Config_Default})" + [[ ! ${ENV_Result} ]] && ENV_Result="$(eval echo \$$(eval echo '$'{ENV}))" + echo "${ENV_Result}" + unset ENV_Result + fi + fi + shift + done + return 0 + ;; + esac +} + +function CHECK_ENV() { + while [[ $1 ]];do + if [[ $(GET_VARIABLE $1 ${Config_Default} 2> /dev/null) ]] + then + ECHO y "检查环境变量: [$1] ... 正常" + else + ECHO r "检查环境变量: [$1] ... 错误" + fi + shift + done +} + +function CHECK_PKG() { + local Result="$(command -v $1 2> /dev/null)" + if [[ ${Result} && $? == 0 ]] + then + echo true + return 0 + else + LOGGER "检查软件包: [$1] ... 错误" + echo false + return 1 + fi +} + +function ECHO() { + local Color + if [[ ! $1 ]] + then + echo -ne "\n${Grey}[$(date "+%H:%M:%S")]${White} " + else + while [[ $1 ]];do + case $1 in + r | g | b | y | x) + case $1 in + r) Color="${Red}";; + g) Color="${Green}";; + b) Color="${Blue}";; + y) Color="${Yellow}";; + x) Color="${Grey}";; + esac + shift + ;; + *) + Message=$1 + break + ;; + esac + done + echo -e "\n${Grey}[$(date "+%H:%M:%S")]${White}${Color} ${Message}${White}" + LOGGER "${Message}" + fi +} + +function LOGGER() { + if [[ ! $* =~ (--help|--log) ]] + then + [[ ! -d ${Log_Path} ]] && mkdir -p ${Log_Path} + [[ ! -f ${Log_Path}/${Log_File} ]] && touch -f ${Log_Path}/${Log_File} + echo "[$(date "+%H:%M:%S")] [$$] $*" >> ${Log_Path}/${Log_File} + fi +} + +function RANDOM() { + head -n 5 /dev/urandom | md5sum | cut -c 1-$1 +} + +function GET_SHA256SUM() { + local Result="$(sha256sum $1 2> /dev/null | cut -c1-$2)" + if [[ ${Result} && $? == 0 ]] + then + echo "${Result}" + return 0 + else + return 1 + fi +} + +function GET_VARIABLE() { + local Result="$(grep "$1=" $2 2> /dev/null | grep -v "#" | awk -F '=' '{print $2}')" + if [[ ${Result} && $? == 0 ]] + then + eval echo "${Result}" + return 0 + else + return 1 + fi +} + +function EDIT_VARIABLE() { + local Mode=$1 + shift + [[ ! -s $1 ]] && ECHO r "未检测到环境变量文件: [$1] !" && return 1 + case "${Mode}" in + edit) + if [[ ! $(GET_VARIABLE $2 $1) ]] + then + LOGGER "[EDIT_VARIABLE] 新增环境变量 [$2 = $3]" + echo -e "\n$2=$3" >> $1 + RETURN=0 + else + sed -i "s?$(GET_VARIABLE $2 $1)?$3?g" $1 2> /dev/null + if [[ $? == 0 ]] + then + LOGGER "[EDIT_VARIABLE] 环境变量 [$2 > $3] 修改成功!" + RETURN=0 + else + LOGGER "[EDIT_VARIABLE] 环境变量 [$2 > $3] 修改失败!" + RETURN=1 + fi + fi + ;; + rm) + sed -i "/$2=/d" $1 + if [[ $? == 0 ]] + then + LOGGER "[EDIT_VARIABLE] 从 $1 删除环境变量 [$2] ... 成功" + RETURN=0 + else + LOGGER "[EDIT_VARIABLE] 从 $1 删除环境变量 [$2] ... 失败" + RETURN=1 + fi + ;; + esac + cp -a ${Config_Custom} ${Tmp_Path}/custom + grep -vE "^[[:blank:]]*$" ${Tmp_Path}/custom > ${Config_Custom} + echo >> ${Config_Custom} + return ${RETURN} +} + +function LOAD_CONFIG() { + while [[ $1 ]];do + if [[ -s $1 ]] + then + chmod +x $1 + source $1 + else + LOGGER "未检测到环境变量列表: [$1]" + fi + shift + done +} + +function LOAD_VARIABLE() { + CHECK_PKG_DEPENDS -f ${PKG_DEPENDS[@]} + for i in ${ENV_DEPENDS[@]};do + local ENV="$(GET_VARIABLE ${i} $1)" + local _ENV="$(GET_VARIABLE ${i} $2)" + if [[ ${_ENV} ]] + then + ENV=${_ENV} + fi + if [[ ! ${ENV} ]] + then + ECHO r "未检测到环境变量: [${i}]" + sleep 1 + fi + eval ${i}="${ENV}" 2> /dev/null + done + unset i ENV + + [[ ! ${TARGET_PROFILE} ]] && TARGET_PROFILE="$(jq .model.id /etc/board.json 2> /dev/null)" + [[ ! ${TARGET_PROFILE} || ${TARGET_PROFILE} == null ]] && ECHO r "当前设备名称获取失败!" && exit 1 + [[ ! ${OP_VERSION} ]] && OP_VERSION="未知" + DISTRIB_TARGET="$(GET_VARIABLE DISTRIB_TARGET /etc/openwrt_release)" + TARGET_BOARD="$(cut -d '/' -f1 <<< ${DISTRIB_TARGET})" + TARGET_SUBTARGET="$(cut -d '/' -f2 <<< ${DISTRIB_TARGET})" + if [[ ! ${Github} ]] + then + _Github=$(awk '{print $4}' /proc/version | cut -d '@' -f2 2> /dev/null | cut -d ')' -f1) + if [[ $(grep -q 'http' <<< ${_Github} ; echo $?) == 0 ]] + then + Github=${_Github} + fi + fi + Firmware_Author="${Github##*com/}" + Github_Release="${Github}/releases/download/AutoUpdate" + Github_Raw="https://raw.githubusercontent.com/${Firmware_Author}/master" + Github_API="https://api.github.com/repos/${Firmware_Author}/releases/latest" + case "${TARGET_BOARD}" in + x86) + if [[ ! ${x86_Boot_Method} ]] + then + [ -d /sys/firmware/efi ] && x86_Boot_Method="UEFI" || x86_Boot_Method="BIOS" + fi + ;; + esac + Log_Full="${Log_Path}/${Log_File}" +} + +function ALTER_GITHUB() { + if [[ ! $1 =~ https://github.com/ || $# != 1 ]] + then + ECHO r "Github 地址格式错误,正确示例: [https://github.com/Hyy2001X/AutoBuild-Actions]" + return 1 + fi + UCI_Github="$(uci get autoupdate.@autoupdate[0].github 2> /dev/null)" + if [[ ${UCI_Github} && ! ${UCI_Github} == $1 ]] + then + uci set autoupdate.@autoupdate[0].github=$1 2> /dev/null + uci commit autoupdate + LOGGER "UCI Github 地址已修改为 [$1]" + fi + if [[ ! ${Github} == $1 ]] + then + EDIT_VARIABLE edit ${Config_Custom} Github $1 + if [[ $? == 0 ]] + then + ECHO y "Github 地址已修改为: [$1]" + else + ECHO y "Github 地址修改失败!" + return 1 + fi + REMOVE_CACHE + else + ECHO g "Github 地址未修改!" + fi + return 0 +} + +function ALTER_BOOT() { + [[ ${TARGET_BOARD} != x86 ]] && exit 1 + case $1 in + UEFI | BIOS) + EDIT_VARIABLE edit ${Config_Custom} x86_Boot_Method $1 + ECHO r "警告: 修改此设置后更新固件后可能导致设备无法启动!" + ECHO y "固件引导格式已修改为: [$1]" + return 0 + ;; + *) + ECHO r "错误的参数: [$1],当前支持的选项: [UEFI/BIOS]" + return 1 + ;; + esac +} + +function ALTER_FLAG() { + case $1 in + -reset) + EDIT_VARIABLE rm ${Config_Custom} TARGET_FLAG + uci set autoupdate.@autoupdate[0].flag="$(GET_VARIABLE TARGET_FLAG /rom/${Config_Default})" 2> /dev/null + uci commit autoupdate + ECHO y "固件标签已恢复为: [$(GET_VARIABLE TARGET_FLAG ${Config_Default})]" + return 0 + ;; + *) + if [[ ! $1 =~ (\"|=|-|_|\.|\#|\|) && $1 =~ [a-zA-Z0-9] ]] + then + UCI_Flag="$(uci get autoupdate.@autoupdate[0].flag 2> /dev/null)" + if [[ ${UCI_Flag} && ! ${UCI_Flag} == $1 ]] + then + uci set autoupdate.@autoupdate[0].flag=$1 2> /dev/null + uci commit autoupdate + LOGGER "UCI 固件标签已修改为: [$1]" + fi + if [[ ! ${TARGET_FLAG} == $1 ]] + then + EDIT_VARIABLE edit ${Config_Custom} TARGET_FLAG $1 + ECHO r "警告: 修改此设置后可能导致无法检测到最新固件!" + ECHO r "后续执行指令: [$0 --flag -reset] 可进行标签恢复!" + ECHO y "固件标签已修改为: [$1]" + else + ECHO g "固件标签未修改!" + fi + return 0 + else + ECHO r "错误的参数: [$1],当前仅支持 [a-zA-Z0-9] 且不能包含 <\" = - _ # |> 等特殊符号!" + return 1 + fi + ;; + esac +} + +function UPDATE_SCRIPT() { + if [[ ! -d $1 ]] + then + mkdir -p $1 2> /dev/null || { + ECHO r "程序保存路径 [$1] 创建失败!" + return 1 + } + fi + ECHO "程序保存路径: [$1]" + DOWNLOADER --file-name autoupdate --no-url-name --dl ${DL_DEPENDS[@]} --url $2 --path ${Tmp_Path} --timeout 5 --type 更新文件 + if [[ $? == 0 && -f ${Tmp_Path}/autoupdate ]] + then + chmod +x ${Tmp_Path}/autoupdate + Script_Version="$(awk -F '=' '/Version/{print $2}' ${Tmp_Path}/autoupdate | awk 'NR==1')" + Banner_Version="$(egrep -o "V[0-9.]+" /etc/banner)" + mv -f ${Tmp_Path}/autoupdate $1 + if [[ $? == 0 ]] + then + [[ ${Banner_Version} && $1 == /bin ]] && sed -i "s?${Banner_Version}?${Script_Version}?g" /etc/banner + ECHO y "[${Banner_Version} > ${Script_Version}] autoupdate 程序更新成功!" + REMOVE_CACHE + return 0 + else + ECHO r "autoupdate 程序移动失败!" + return 1 + fi + else + ECHO r "autoupdate 程序更新失败!" + return 1 + fi +} + +function CHECK_PKG_DEPENDS() { + case $1 in + -e) + shift + TITLE + printf "\n%-28s %-5s\n" 软件包 检测结果 + while [[ $1 ]];do + printf "%-25s %-5s\n" $1 $(CHECK_PKG $1) + shift + done + ECHO y "软件包检测结束,请尝试手动安装测结果为 [false] 的软件包!" + ;; + -f) + shift + while [[ $1 ]];do + CHECK_PKG $1 > /dev/null 2>&1 + if [[ $? != 0 ]] + then + ECHO r "未安装软件包: [$1]" + exit 1 + fi + shift + done + ;; + esac +} + +function CHECK_TIME() { + [[ -s $1 && -n $(find $1 -type f -mmin -$2) ]] && { + echo true + return 0 + } || { + RM $1 + echo false + return 1 + } +} + +function ANALYZE_API() { + [[ ! ${Github_Release} ]] && { + ECHO r "Github API 地址为空!" + exit 1 + } + local API_Cache=${Tmp_Path}/API_Cache + if [[ $(CHECK_TIME ${API_File} 1) == false ]] + then + DOWNLOADER --path ${Tmp_Path} --file-name API_Cache --dl ${DL_DEPENDS[@]} --url "${Github_API}@@1 $(Proxy_X ${Github_Release}/API G@@1 F@@1)" --no-url-name --timeout 5 + [[ ! $? == 0 || -z $(cat ${API_Cache} 2> /dev/null) ]] && { + ECHO r "Github API 请求错误,请检查网络后再试!" + exit 2 + } + fi + [[ -f ${API_File} ]] && RM ${API_File} + touch -a ${API_File} + LOGGER "开始解析 Github API ..." + for i in $(seq 0 $(jq ".assets | length" ${API_Cache} 2> /dev/null));do + eval name=$(jq ".assets[${i}].name" ${API_Cache} 2> /dev/null) + [[ ${name} == null ]] && continue + case ${name} in + AutoBuild-${OP_REPO}-${TARGET_PROFILE}-* | Update_Logs.json) + LOGGER "可用固件/日志: ${name}" + eval format=$(egrep -o '\.[a-z]+.+' <<< ${name} | cut -c2-10) + eval version=$(egrep -o "R[0-9.]+-[0-9]+" <<< ${name}) + eval sha256=$(egrep -o "\-[a-z0-9]+" <<< ${name} | cut -c2-6 | awk 'END{print}') + eval browser_download_url=$(jq ".assets[${i}].browser_download_url" ${API_Cache} 2> /dev/null) + eval size=$(jq ".assets[${i}].size" ${API_Cache} 2> /dev/null | awk '{a=$1/1048576} {printf("%.2f\n",a)}') + eval updated_at=$(jq ".assets[${i}].updated_at" ${API_Cache} 2> /dev/null | sed 's/[-:TZ]//g') + eval download_count=$(jq ".assets[${i}].download_count" ${API_Cache} 2> /dev/null) + [[ ! ${version} || ${version} == null ]] && version="-" + [[ ! ${browser_download_url} || ${browser_download_url} == null ]] && continue + [[ ! ${size} || ${size} == null || ${size} == 0 ]] && size="-" || size="${size}MB" + [[ ! ${updated_at} || ${updated_at} == null ]] && updated_at="-" + [[ ! ${download_count} || ${download_count} == null ]] && download_count="-" + [[ ! ${sha256} || ${sha256} == null ]] && sha256="-" + printf "%-75s %-15s %-5s %-8s %-20s %-10s %-15s %s\n" ${name} ${format} ${download_count} ${sha256} ${version} ${updated_at} ${size} ${browser_download_url} | egrep -v "${REGEX_Skip_Format}" >> ${API_File} + ;; + esac + done + unset i + if [[ ! $(cat ${API_File} 2> /dev/null) ]] + then + ECHO r "Github API 解析内容为空!" + exit 1 + else + LOGGER "Github API 解析成功!" + return 0 + fi +} + +function GET_FW_INFO() { + local Info Type Result + [[ ! -s ${API_File} ]] && { + ECHO r "未检测到 API 文件!" + exit 1 + } + Info=$(grep "AutoBuild-${OP_REPO}-${TARGET_PROFILE}" ${API_File} | grep "${x86_Boot_Method}" | grep "${TARGET_FLAG}" | awk 'BEGIN {MAX = 0} {if ($6+0 > MAX+0) {MAX=$6 ;content=$0} } END {print content}') + Result="$(awk '{print $"'${1}'"}' <<< ${Info} 2> /dev/null)" + case $1 in + 1) Type="固件名称";; + 2) Type="固件格式";; + 3) Type="下载次数";; + 4) Type="校验信息";; + 5) Type="固件版本";; + 6) Type="发布日期";; + 7) Type="固件体积";; + 8) Type="固件链接";; + *) Type="未定义信息";; + esac + [[ ! ${Result} == "-" ]] && { + LOGGER "${Type}: ${Result}" + echo -e "${Result}" + } || { + LOGGER "${Type}获取失败!" + return 1 + } +} + +function GET_CLOUD_LOG() { + local Version log_Test + [[ ! $(cat ${API_File} 2> /dev/null) =~ Update_Logs.json ]] && { + LOGGER "未检测到已部署的云端日志,跳过下载 ..." + return 1 + } + case $1 in + [Ll]ocal) + Version="${OP_VERSION}" + ;; + [Cc]loud) + Version="$(GET_FW_INFO 5)" + ;; + *) + Version=$1 + ;; + esac + [[ $(CHECK_TIME ${Tmp_Path}/Update_Logs.json 1) == false ]] && { + DOWNLOADER --path ${Tmp_Path} --file-name Update_Logs.json --dl ${DL_DEPENDS[@]} --url "$(Proxy_X ${Github_Release} G@@1)" --timeout 5 + } + [[ ! -s ${Tmp_Path}/Update_Logs.json ]] && return 1 + log_Test="$(jq '."'"${TARGET_PROFILE}"'"."'"${Version}"'"' ${Tmp_Path}/Update_Logs.json 2> /dev/null)" + if [[ ${log_Test} && ${log_Test} != null ]] + then + echo -e "\n${Grey}${Version} 固件更新日志:${Green}\n" + jq '."'"${TARGET_PROFILE}"'"."'"${Version}"'"' ${Tmp_Path}/Update_Logs.json 2> /dev/null | egrep -v "\[|\]" + echo -e "${White}" + else + LOGGER "未获取到 [${Version}] 固件的日志信息!" + fi +} + +function UPGRADE() { + TITLE + KILL_PROCESS ${Script_File} + [[ $(NETWORK_CHECK 223.5.5.5 2) == false ]] && { + ECHO r "网络连接错误,请稍后再试!" + exit 1 + } + Firmware_Path="${Tmp_Path}" + Upgrade_Option="$(command -v sysupgrade) -q" + MSG="更新固件" + while [[ $1 ]];do + case $1 in + -T) + Special_Commands="${Special_Commands} [测试模式]" + ;; + -P | --proxy) + case $2 in + F | G) + Proxy_Type=$2 + shift + ;; + *) + Proxy_Type="All" + ;; + esac + Special_Commands="${Special_Commands} [镜像加速 ${Proxy_Type}]" + ;; + -D) + DL_DEPENDS=($2) + Special_Commands="${Special_Commands} [$1 ${DL_DEPENDS[@]}]" + shift + ;; + -F | --force-flash) + Force_Flash=1 + Special_Commands="${Special_Commands} [强制刷写]" + ;; + --decompress) + Special_Commands="${Special_Commands} [优先解压固件]" + Decompress_Mode=1 + ;; + -f) + Force_Mode=1 + Force_Flash=1 + Special_Commands="${Special_Commands} [强制模式]" + ;; + -n) + Upgrade_Option="${Upgrade_Option} -n" + Special_MSG=" (不保留配置)" + ;; + --path) + Firmware_Path=$2 + ECHO g "固件保存路径: [${Firmware_Path} | $(SPACEINFO ${Firmware_Path})M]" + shift + ;; + --skip-verify) + Skip_Verify_Mode=1 + Special_Commands="${Special_Commands} [跳过 SHA256 验证]" + ;; + -u) + Nobody_Mode=1 + Special_Commands="${Special_Commands} [定时更新]" + ;; + --verbose) + Special_Commands="${Special_Commands} [详细信息]" + ;; + *) + LOGGER "跳过未知参数: [$1] ..." + shift + esac + shift + done + [[ ${Force_Flash} == 1 ]] && Upgrade_Option="${Upgrade_Option} -F" + [[ ${Special_Commands} ]] && ECHO g "特殊指令:${Special_Commands} | ${Upgrade_Option}" + ECHO g "执行: ${MSG}${Special_MSG}" + if [[ ! ${Proxy_Type} ]] + then + [[ $(GOOGLE_CHECK) != true ]] && { + ECHO r "Google 连接错误,优先使用镜像加速下载!" + Proxy_Type="All" + } + fi + ECHO "正在检查固件版本更新 ..." + ANALYZE_API + CLOUD_FW_Name=$(GET_FW_INFO 1) + CLOUD_FW_Format=$(GET_FW_INFO 2) + CLOUD_FW_Count=$(GET_FW_INFO 3) + CLOUD_FW_SHA256=$(GET_FW_INFO 4) + CLOUD_FW_Version=$(GET_FW_INFO 5) + CLOUD_FW_Date=$(GET_FW_INFO 6) + CLOUD_FW_Size=$(GET_FW_INFO 7) + CLOUD_FW_Url=$(GET_FW_INFO 8) + [[ ! ${CLOUD_FW_Name} || -z ${CLOUD_FW_Url} ]] && { + ECHO r "检查更新失败,请检查网络后再试!" + exit 2 + } + [[ ${CLOUD_FW_Version} == ${OP_VERSION} ]] && { + CURRENT_Type="${Yellow} [已是最新]${White}" + Stop_Code=1 + } || { + [[ $(cut -d - -f2 <<< ${CLOUD_FW_Version}) -gt $(cut -d - -f2 <<< ${OP_VERSION}) ]] && CHECKED_Type="${Green} [可更新]${White}" + [[ $(cut -d - -f2 <<< ${CLOUD_FW_Version}) -lt $(cut -d - -f2 <<< ${OP_VERSION}) ]] && { + CHECKED_Type="${Red} [旧版本]${White}" + Stop_Code=2 + } + } + echo -e " +${Grey}### 系统 & 云端固件详情 ###${White} + +设备名称: ${TARGET_PROFILE} +固件标签: ${TARGET_FLAG} +内核版本: $(uname -sr) +$([[ ${TARGET_BOARD} == x86 ]] && echo "固件格式: ${CLOUD_FW_Format} / ${x86_Boot_Method}" || echo "固件格式: ${CLOUD_FW_Format}") + +$(echo -e "当前固件版本: ${OP_VERSION}${CURRENT_Type}") +$(echo -e "云端固件版本: ${CLOUD_FW_Version}${CHECKED_Type}") + +云端固件名称: ${CLOUD_FW_Name} +云端固件体积: ${CLOUD_FW_Size} +固件下载次数: ${CLOUD_FW_Count}" + if [[ ${Force_Mode} != 1 ]] + then + (sync && echo 3 > /proc/sys/vm/drop_caches) 2> /dev/null + if [[ $(MEMINFO All) -lt $(echo ${CLOUD_FW_Size} | awk -F '.' '{print $1}') ]] + then + ECHO r "内存空间不足 [${CLOUD_FW_Size}],请尝试设置 Swap 交换分区或重启设备后再试!" + exit + fi + if [[ $(SPACEINFO ${Firmware_Path}) -lt $(awk -F '.' '{print $1}' <<< ${CLOUD_FW_Size}) ]] + then + ECHO r "设备空间不足 [${CLOUD_FW_Size}],请尝试更换固件保存路径后再试!" + exit + fi + fi + GET_CLOUD_LOG ${CLOUD_FW_Version} + case "${Stop_Code}" in + 1 | 2) + [[ ${Nobody_Mode} == 1 ]] && ECHO y "当前固件 [${OP_VERSION}] 已是最新版本,无需更新!" && exit 0 + [[ ${Stop_Code} == 1 ]] && err_MSG="当前固件 [${OP_VERSION}] 已是最新版本" || err_MSG="云端固件版本为旧版" + [[ ! ${Force_Mode} == 1 ]] && { + ECHO && read -p "${err_MSG},是否继续更新固件?[Y/n]:" Choose + } || Choose=Y + [[ ! ${Choose} =~ [Yy] ]] && { + ECHO x "已取消固件更新操作,退出更新程序 ..." + exit 0 + } + ;; + esac + local URL + case "${Proxy_Type}" in + F | G) + URL="$(Proxy_X ${CLOUD_FW_Url} ${Proxy_Type}@@3)" + ;; + All) + URL="$(Proxy_X ${CLOUD_FW_Url} G@@1 F@@1 X@@1)" + ;; + *) + URL="$(Proxy_X ${CLOUD_FW_Url} X@@3 G@@1 F@@1)" + ;; + esac + DOWNLOADER --file-name ${CLOUD_FW_Name} --no-url-name --dl ${DL_DEPENDS[@]} --url ${URL} --path ${Firmware_Path} --timeout 15 --type 固件 + [[ ! -s ${Firmware_Path}/${CLOUD_FW_Name} || $? != 0 ]] && { + ECHO r "固件下载失败,请检查网络后再试!" + exit 1 + } + if [[ ! ${Skip_Verify_Mode} == 1 ]];then + if [[ $(GET_SHA256SUM ${Firmware_Path}/${CLOUD_FW_Name} 5) != ${CLOUD_FW_SHA256} ]] + then + ECHO r "SHA256 校验失败!" + exit 2 + fi + ECHO y "固件完整性校验通过,即将开始更新固件 ..." + fi + case "${CLOUD_FW_Format}" in + img.gz) + if [[ ${Decompress_Mode} == 1 ]] + then + ECHO "正在解压 gizp 格式固件 ..." + gzip -d -q -f -c ${Firmware_Path}/${CLOUD_FW_Name} > ${Firmware_Path}/$(sed -r 's/(.*).gz/\1/' <<< ${CLOUD_FW_Name}) + if [[ ! $? == 0 ]] + then + ECHO r "固件解压失败!" + exit 2 + else + CLOUD_FW_Name="$(sed -r 's/(.*).gz/\1/' <<< ${CLOUD_FW_Name})" + LOGGER "固件已解压到: [${Firmware_Path}/${CLOUD_FW_Name}]" + fi + else + if [[ $(CHECK_PKG gzip) == true ]] + then + LOGGER "卸载软件包 [gzip] ..." + opkg remove gzip > /dev/null 2>&1 + fi + fi + ;; + esac + if [[ ${Test_Mode} == 1 ]] + then + ECHO x "[测试模式] ${Upgrade_Option} ${Firmware_Path}/${CLOUD_FW_Name}" + exit 0 + else + DO_UPGRADE ${Upgrade_Option} ${Firmware_Path}/${CLOUD_FW_Name} + fi +} + +function DO_UPGRADE() { + ECHO r "警告: 固件更新期间请不要断开电源或进行其他操作!" + sleep 3 + ECHO g "正在更新固件,请耐心等待 ..." + $* + if [[ $? != 0 ]] + then + ECHO r "固件更新失败,请尝试使用 [autoupdate -F] 指令更新固件,执行此命令前请备份固件配置!" + exit 1 + else + ECHO y "固件更新成功,即将重启设备 ..." + sleep 3 + reboot + fi + exit +} + +function DOWNLOADER() { + local u E DL_Downloader DL_Name DL_URL DL_Path DL_Retries DL_Timeout DL_Type DL_Final No_URL_Name Print_Mode DL_Retires_All DL_URL_Final + while [[ $1 ]] + do + case $1 in + --dl) + shift + while [[ $1 ]] + do + case $1 in + wget* | curl | uclient-fetch) + [[ $(CHECK_PKG $1) == true ]] && { + DL_Downloader=$1 + break + } + shift + ;; + *) + LOGGER "[DOWNLOADER] 跳过未知下载器: [$1] ..." + shift + ;; + esac + done + while [[ $1 ]] + do + [[ $1 =~ '--' ]] && break + [[ ! $1 =~ '--' ]] && shift + done + if [[ ! ${DL_Downloader} ]] + then + ECHO r "没有可用的下载器!" + return 1 + fi + ;; + --file-name) + shift + DL_Name=$1 + while [[ $1 ]] + do + [[ $1 =~ '--' ]] && break + [[ ! $1 =~ '--' ]] && shift + done + ;; + --url) + shift + DL_URL=($(egrep -o "https://.*@@[0-9]+|https://.*@@[0-9]+|ftp://.*@@[0-9]+" <<< $@)) + if [[ ! ${DL_URL[*]} ]] + then + DL_URL=($1) + DL_URL_Count="${#DL_URL[@]}" + DL_Retires_All="${DL_URL_Count}" + else + DL_Retires_All="$(egrep -o "@@[0-9]+" <<< ${DL_URL[*]} | egrep -o "[0-9]+" | awk '{Sum += $1};END {print Sum}')" + DL_URL_Count="${#DL_URL[@]}" + fi + while [[ $1 ]] + do + [[ $1 =~ '--' ]] && break + [[ ! $1 =~ '--' ]] && shift + done + ;; + --no-url-name) + shift + No_URL_Name=1 + ;; + --path) + shift + DL_Path=$1 + if [[ ! -d ${DL_Path} ]] + then + mkdir -p ${DL_Path} 2> /dev/null || { + ECHO r "目标下载路径 [${DL_Path}] 创建失败!" + return 1 + } + fi + while [[ $1 ]] + do + [[ $1 =~ '--' ]] && break + [[ ! $1 =~ '--' ]] && shift + done + ;; + --timeout) + shift + if [[ ! $1 =~ [1-9] ]] + then + shift + else + DL_Timeout=$1 + while [[ $1 ]] + do + [[ $1 =~ '--' ]] && break + [[ ! $1 =~ '--' ]] && shift + done + fi + ;; + --type) + shift + DL_Type=$1 + while [[ $1 ]] + do + [[ $1 =~ '--' ]] && break + [[ ! $1 =~ '--' ]] && shift + done + ;; + --print) + shift + Print_Mode=1 + ;; + *) + shift + ;; + esac + done + case "${DL_Downloader}" in + wget*) + DL_Template="${DL_Downloader} --quiet --no-check-certificate --tries 1 --timeout 10 -O" + ;; + curl) + DL_Template="${DL_Downloader} --silent --insecure -L -k --connect-timeout 10 --retry 1 -o" + ;; + uclient-fetch) + DL_Template="${DL_Downloader} --quiet --no-check-certificate -4 --timeout 10 -O" + ;; + esac + if [[ ${Test_Mode} == 1 || ${Verbose_Mode} == 1 ]] + then + DL_Template="${DL_Template/ --quiet / }" + DL_Template="${DL_Template/ --silent / }" + fi + [[ ${DL_Timeout} ]] && DL_Template="${DL_Template/-timeout 10/-timeout ${DL_Timeout}}" + local E=0 ; while [[ ${E} != ${DL_URL_Count} ]] + do + DL_URL_Cache="${DL_URL[$E]}" + DL_Retries="${DL_URL_Cache##*@@}" + [[ ! ${DL_Retries} || ! ${DL_Retries} == [0-9] ]] && DL_Retries=1 + DL_URL_Final="${DL_URL_Cache%*@@*}" + LOGGER "当前 URL: [${DL_URL_Final}] URL 重试次数: [${DL_Retries}]" + for u in $(seq ${DL_Retries}) + do + sleep 1 + if [[ ! ${Failed} ]] + then + [[ ${DL_Type} ]] && ECHO "正在下载${DL_Type},请耐心等待 ..." + else + [[ ${DL_Type} ]] && ECHO "尝试重新下载,剩余重试次数: [${DL_Retires_All}]" + fi + if [[ ! ${DL_Name} ]] + then + DL_Name="${DL_URL_Final##*/}" + DL_Final="${DL_Template} ${DL_Path}/${DL_Name} ${DL_URL_Final}" + else + [[ ${No_URL_Name} == 1 ]] && DL_Final="${DL_Template} ${DL_Path}/${DL_Name} ${DL_URL_Final}" || \ + DL_Final="${DL_Template} ${DL_Path}/${DL_Name} ${DL_URL_Final}/${DL_Name}" + fi + [[ -s ${DL_Path}/${DL_Name} ]] && \ + RM ${DL_Path}/${DL_Name} + LOGGER "执行下载指令: [${DL_Final}]" + ${DL_Final} + if [[ $? == 0 && -s ${DL_Path}/${DL_Name} ]] + then + touch -a ${DL_Path}/${DL_Name} + if [[ ${Print_Mode} == 1 ]] + then + cat ${DL_Path}/${DL_Name} 2> /dev/null + RM ${DL_Path}/${DL_Name} + return 0 + else + [[ ${DL_Type} ]] && ECHO y "${DL_Type}下载成功!" + fi + return 0 + else + [[ ! ${Failed} ]] && local Failed=1 + DL_Retires_All=$((${DL_Retires_All} - 1)) + if [[ ${u} == ${DL_Retries} ]] + then + break 1 + else + [[ ${DL_Type} ]] && ECHO r "${DL_Type}下载失败!" + u=$((${u} + 1)) + fi + fi + done ; unset u + E=$((${E} + 1)) + done + RM ${DL_Path}/${DL_Name} + [[ ${DL_Type} ]] && ECHO r "${DL_Type}下载失败!" + return 1 +} + +function REMOVE_CACHE() { + rm -r ${Tmp_Path}/API \ + ${Tmp_Path}/Update_Logs.json \ + ${Tmp_Path}/API_Cache 2> /dev/null +} + +function LOG() { + case $1 in + -path) + [[ ! $2 ]] && SHELL_HELP + if [[ $2 == ${Log_Path} ]] + then + ECHO y "AutoUpdate 日志保存路径相同,无需修改!" + return 0 + fi + if [[ ! -d $2 ]] + then + mkdir -p $2 2> /dev/null || { + ECHO r "AutoUpdate 日志保存路径错误!" + return 1 + } + fi + EDIT_VARIABLE rm ${Config_Custom} Log_Path + EDIT_VARIABLE edit ${Config_Custom} Log_Path $2 + Log_Path=${Log_Path} + uci set autoupdate.@autoupdate[0].logpath=$2 2> /dev/null + uci commit autoupdate + ECHO y "AutoUpdate 日志保存路径已修改为: [$2]!" + return 0 + ;; + -del | -rm | -clean) + RM ${Log_Path}/${Log_File} + return 0 + ;; + *) + if [[ -s ${Log_Path}/${Log_File} ]] + then + TITLE && echo + cat ${Log_Path}/${Log_File} 2> /dev/null + return 0 + else + return 1 + fi + ;; + esac +} + +function Proxy_X() { + local URL=$1 Type URL_Final + + [[ ${URL} =~ raw.githubusercontent.com ]] && Type=raw + [[ ${URL} =~ releases/download ]] && Type=release + [[ ${URL} =~ codeload.github.com ]] && Type=codeload + + case "${Type}" in + raw) + F=https://git.hyy2001.workers.dev/$(echo ${URL##*com/}) + G=https://ghproxy.com/${URL} + ;; + release) + F=https://git.hyy2001.workers.dev/$(echo ${URL##*com/}) + G=https://ghproxy.com/${URL} + ;; + codeload) + F=https://git.hyy2001.workers.dev/$(echo ${URL##*com/}) + G=https://ghproxy.com/${URL} + ;; + esac + while [[ $1 ]];do + local URL_Cache=$1 URL_Final + case $1 in + F@@*) + URL_Final="${URL_Cache/F/${F}}" + ;; + G@@*) + URL_Final="${URL_Cache/G/${G}}" + ;; + X@@*) + URL_Final="${URL_Cache/X/${URL}}" + ;; + esac + [[ ${URL_Final} ]] && { + echo "${URL_Final}" + } + unset URL_Final + shift + done +} + +function NETWORK_CHECK() { + ping $1 -c 1 -W $2 > /dev/null 2>&1 + [[ $? == 0 ]] && echo true || echo false +} + +function GOOGLE_CHECK() { + if [[ $(CHECK_PKG curl) == true ]] + then + local Result=$(curl -I -s --connect-timeout 3 google.com -w %{http_code} 2> /dev/null | tail -n1) + LOGGER "Google 连接检查结果: [${Result}]" + if [[ ${Result} == 301 ]] + then + echo true + return 0 + else + echo false + return 1 + fi + else + return 1 + fi +} + +function AutoUpdate_Main() { + LOAD_CONFIG ${Config_Custom} + if [[ ! $1 =~ (-H|--help|--chk|--log) ]] + then + LOAD_VARIABLE ${Config_Default} ${Config_Custom} + fi + [[ ! -d ${Tmp_Path} ]] && mkdir -p ${Tmp_Path} + [[ ! $* ]] && UPGRADE $* + + local Input=($@) E=0 F Custom_Path Custom_URL + while :;do + F="${Input[${E}]}" + case "${F}" in + -T) + Test_Mode=1 + ;; + --verbose) + Verbose_Mode=1 + ;; + -path) + Custom_Path="${Input[$((${E} + 1))]}" + [[ ! ${Custom_Path} ]] && { + ECHO r "请输入正确的路径!" + } + ;; + -url) + Custom_URL="${Input[$((${E} + 1))]}" + [[ ! ${Custom_URL} || ! ${Custom_URL} =~ (https://*|http://*|ftp://*) ]] && { + ECHO r "链接格式错误,请输入正确的链接!" + exit 1 + } + ;; + -D) + case "${Input[$((${E} + 1))]}" in + wget* | curl | uclient-fetch) + DL_DEPENDS=(${Input[$((${E} + 1))]}) + ;; + *) + ECHO r "暂不支持当前下载器: [${Input[$((${E} + 1))]}]" + exit 1 + ;; + esac + ;; + esac + [[ ${E} == ${#Input[@]} ]] && break + E=$((${E} + 1)) + done + + while [[ $1 ]];do + case $1 in + -n | -f | -u | -T | -P | --proxy | -F | --force-flash | --verbose | --decompress | --skip-verify | -D | --path) + UPGRADE $* + exit $? + ;; + --api) + REMOVE_CACHE + ANALYZE_API > /dev/null 2>&1 + [[ $? == 0 ]] && cat ${API_File} 2> /dev/null + exit $? + ;; + --backup) + local Backup_File="backup-$(uname -n)-$(date +%Y-%m-%d)-$(RANDOM 5).tar.gz" + shift + [[ $# -gt 1 ]] && SHELL_HELP + if [[ ! $1 ]] + then + Backup_File="$(pwd)/${Backup_File}" + else + if [[ ! -d $1 ]];then + mkdir -p $1 || { + ECHO r "备份存放路径 [$1] 创建失败!" + exit 1 + } + fi + Backup_File="$1/${Backup_File}" + fi + ECHO "正在备份系统文件到 [${Backup_File}] ..." + $(command -v sysupgrade) -b "${Backup_File}" > /dev/null 2>&1 + if [[ $? == 0 ]] + then + ECHO y "备份文件创建成功!" + exit 0 + else + ECHO r "备份文件 [${Backup_File}] 创建失败!" + exit 1 + fi + ;; + --clean) + REMOVE_CACHE + exit + ;; + --chk) + shift + CHECK_PKG_DEPENDS -e ${PKG_DEPENDS[@]} ${DL_DEPENDS[@]} + if [[ $(NETWORK_CHECK www.baidu.com 2) == false ]] + then + ECHO r "基础网络连接错误!" + else + ECHO y "基础网络连接正常!" + fi + if [[ $(GOOGLE_CHECK) == false ]] + then + ECHO r "Google 连接错误!" + else + ECHO y "Google 连接正常!" + fi + CHECK_ENV ${ENV_DEPENDS[@]} + exit $? + ;; + --env) + shift + LIST_ENV $* + exit $? + ;; + --flag) + shift + [[ -z $* || $# != 1 ]] && SHELL_HELP + ALTER_FLAG $1 + exit + ;; + -V) + shift + case $1 in + [Cc]loud) + shift + ANALYZE_API > /dev/null 2>&1 + GET_FW_INFO $* 5 + ;; + *) + echo "${OP_VERSION}" + ;; + esac + exit + ;; + --fw-log) + shift + ANALYZE_API + if [[ ! $* ]] + then + GET_CLOUD_LOG local + else + GET_CLOUD_LOG $* + fi + exit + ;; + --list) + shift + SHOW_VARIABLE + exit $? + ;; + -v) + shift + case $1 in + [Cc]loud) + URL="$(Proxy_X ${Script_Url} G@@1 X@@1)" + DOWNLOADER --dl ${DL_DEPENDS[@]} --url ${URL} --path ${Tmp_Path} --print --type 临时程序 | egrep -o "V[0-9].+" + ;; + *) + echo ${Version} + ;; + esac + exit + ;; + -x) + shift + URL="$(Proxy_X ${Script_Url} X@@1 G@@1)" + if [[ $(NETWORK_CHECK 223.5.5.5 2) == false ]] + then + ECHO r "网络连接错误,请稍后再试!" + exit 1 + fi + [[ ${Custom_Path} ]] && Script_Path="${Custom_Path}" + [[ ${Custom_URL} ]] && URL="${Custom_URL}" + UPDATE_SCRIPT ${Script_Path} ${URL} + exit $? + ;; + -B | --boot-mode) + shift + ALTER_BOOT $1 + exit $? + ;; + -C) + shift + ALTER_GITHUB $* + exit $? + ;; + --help) + SHELL_HELP + exit 0 + ;; + --log) + shift + LOG $* + exit $? + ;; + --reset) + rm -r ${Config_Default} ${Config_Custom} + cp -a /rom/$(dirname ${Config_Default})/* $(dirname ${Config_Default})/ + cp -a /rom/etc/config/autoupdate /etc/config + REMOVE_CACHE + exit 0 + ;; + *) + SHELL_HELP + exit 1 + ;; + esac + done +} + +function KILL_PROCESS() { + local i ; for i in $(ps -efww | grep -v grep | grep $1 | grep -v $$ | awk '{print $1}') + do + kill -9 ${i} 2> /dev/null & + LOGGER "Killed ${i}" + done +} + +Script_Path="$(cd $(dirname $0) 2> /dev/null ; pwd 2> /dev/null)" +Script_File="$0" +Script_Url="https://raw.githubusercontent.com/Hyy2001X/AutoBuild-Packages/master/autoupdate/files/bin/autoupdate" + +Tmp_Path=/tmp/autoupdate +Config_Path=/etc/autoupdate + +Log_Path=/tmp +Log_File=autoupdate.log + +API_File="${Tmp_Path}/API" + +Config_Default="${Config_Path}/default" +Config_Custom="${Config_Path}/custom" + +ENV_DEPENDS=( + Author + Github + TARGET_PROFILE + TARGET_FLAG + OP_VERSION + OP_AUTHOR + OP_BRANCH + OP_REPO +) +PKG_DEPENDS=( + jq + expr + sysupgrade +) +DL_DEPENDS=( + wget-ssl + curl + wget + uclient-fetch +) +REGEX_Skip_Format=".vdi|.vhdx|.vmdk|kernel|rootfs|factory" + +White="\e[0m" +Yellow="\e[33m" +Red="\e[31m" +Blue="\e[34m" +Grey="\e[36m" +Green="\e[32m" + +[[ $* ]] && COMMAND="$0 $*" || COMMAND="$0" +AutoUpdate_Main $* diff --git a/autoupdate/files/etc/autoupdate/default b/autoupdate/files/etc/autoupdate/default new file mode 100755 index 000000000..6c74bffd8 --- /dev/null +++ b/autoupdate/files/etc/autoupdate/default @@ -0,0 +1,2 @@ +## 请不要修改此文件中的内容, 自定义变量请在 custom 中添加或修改 +## 该文件将在运行 autoupdate 脚本时被读取, 且该文件中的内容优先级低于 custom diff --git a/luci-app-adguardhome/Makefile b/luci-app-adguardhome/Makefile deleted file mode 100755 index f0bbf548e..000000000 --- a/luci-app-adguardhome/Makefile +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (C) 2020-2023 Hyy2001X - -include $(TOPDIR)/rules.mk - -PKG_NAME:=luci-app-adguardhome -PKG_VERSION:=1.0 -PKG_RELEASE:=20230123 - -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) - -include $(INCLUDE_DIR)/package.mk - -define Package/luci-app-adguardhome - SECTION:=luci - CATEGORY:=LuCI - SUBMENU:=3. Applications - TITLE:=LuCI support for AdGuard Home [Modified by Hyy2001] - PKGARCH:=all - DEPENDS:=+!wget-ssl&&!curl:wget-ssl +xz-utils +xz -endef - -define Package/luci-app-adguardhome/description - LuCI support for AdGuard Home -endef - -define Build/Prepare -endef - -define Build/Compile -endef - -define Package/luci-app-adguardhome/conffiles -/usr/share/AdGuardHome/links.txt -/etc/config/AdGuardHome -endef - -define Package/luci-app-adguardhome/install - $(INSTALL_DIR) $(1)/usr/lib/lua/luci - cp -pR ./luasrc/* $(1)/usr/lib/lua/luci - $(INSTALL_DIR) $(1)/ - cp -pR ./root/* $(1)/ - $(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n - po2lmo ./po/zh-cn/AdGuardHome.po $(1)/usr/lib/lua/luci/i18n/AdGuardHome.zh-cn.lmo -endef - -define Package/luci-app-adguardhome/postinst -#!/bin/sh - /etc/init.d/AdGuardHome enable >/dev/null 2>&1 - enable=$(uci get AdGuardHome.AdGuardHome.enabled 2>/dev/null) - if [ "$enable" == "1" ]; then - /etc/init.d/AdGuardHome reload - fi - rm -f /tmp/luci-indexcache - rm -f /tmp/luci-modulecache/* -exit 0 -endef - -define Package/luci-app-adguardhome/prerm -#!/bin/sh -if [ -z "$${IPKG_INSTROOT}" ]; then - /etc/init.d/AdGuardHome disable - /etc/init.d/AdGuardHome stop -uci -q batch <<-EOF >/dev/null 2>&1 - delete ucitrack.@AdGuardHome[-1] - commit ucitrack -EOF -fi -exit 0 -endef - -$(eval $(call BuildPackage,luci-app-adguardhome)) diff --git a/luci-app-adguardhome/README.md b/luci-app-adguardhome/README.md deleted file mode 100755 index cb9e1090d..000000000 --- a/luci-app-adguardhome/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# luci-app-adguardhome - -## 修改内容 - - - 修复 本地 AdGuardHome 核心文件版本号获取 - - - 优化 AdGuardHome 核心更新以及UPX压缩流程 - - - 汉化 AdGuardHome 核心更新时显示的内容 - - - 优化 默认模板、DNS 服务器以及 DNS 封锁清单 - -## Based on - - - [rufengsuixing](https://github.com/rufengsuixing/luci-app-adguardhome) - - - [Lienol](https://github.com/Lienol) diff --git a/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua b/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua deleted file mode 100755 index 4ebd4794c..000000000 --- a/luci-app-adguardhome/luasrc/controller/AdGuardHome.lua +++ /dev/null @@ -1,130 +0,0 @@ -module("luci.controller.AdGuardHome", package.seeall) -local fs = require "nixio.fs" -local http = require "luci.http" -local uci = require"luci.model.uci".cursor() -function index() - entry({"admin", "services", "AdGuardHome"}, alias("admin", "services", "AdGuardHome", "base"), _("AdGuard Home"), 10).dependent = true - entry({"admin", "services", "AdGuardHome", "base"}, cbi("AdGuardHome/base"), _("Base Setting"), 1).leaf = true - entry({"admin", "services", "AdGuardHome", "log"}, form("AdGuardHome/log"), _("Log"), 2).leaf = true - entry({"admin", "services", "AdGuardHome", "manual"}, cbi("AdGuardHome/manual"), _("Manual Config"), 3).leaf = true - entry({"admin", "services", "AdGuardHome", "status"}, call("act_status")).leaf = true - entry({"admin", "services", "AdGuardHome", "check"}, call("check_update")) - entry({"admin", "services", "AdGuardHome", "doupdate"}, call("do_update")) - entry({"admin", "services", "AdGuardHome", "getlog"}, call("get_log")) - entry({"admin", "services", "AdGuardHome", "dodellog"}, call("do_dellog")) - entry({"admin", "services", "AdGuardHome", "reloadconfig"}, call("reload_config")) - entry({"admin", "services", "AdGuardHome", "gettemplateconfig"}, call("get_template_config")) -end - -function get_template_config() - local b - local d = "" - local file = "/tmp/resolv.conf.d/resolv.conf.auto" - if not fs.access(file) then - file = "/tmp/resolv.conf.auto" - end - for cnt in io.lines(file) do - b = string.match(cnt, "^[^#]*nameserver%s+([^%s]+)$") - if (b ~= nil) then d = d .. " - " .. b .. "\n" end - end - local f = io.open("/usr/share/AdGuardHome/AdGuardHome_template.yaml", "r+") - local tbl = {} - local a = "" - while (1) do - a = f:read("*l") - if (a == "#bootstrap_dns") then - a = d - elseif (a == "#upstream_dns") then - a = d - elseif (a == nil) then - break - end - table.insert(tbl, a) - end - f:close() - http.prepare_content("text/plain; charset=utf-8") - http.write(table.concat(tbl, "\n")) -end - -function reload_config() - fs.remove("/tmp/AdGuardHometmpconfig.yaml") - http.prepare_content("application/json") - http.write('') -end - -function act_status() - local e = {} - local binpath = uci:get("AdGuardHome", "AdGuardHome", "binpath") - e.running = luci.sys.call("pgrep " .. binpath .. " >/dev/null") == 0 - e.redirect = (fs.readfile("/var/run/AdGredir") == "1") - http.prepare_content("application/json") - http.write_json(e) -end - -function do_update() - fs.writefile("/var/run/lucilogpos", "0") - http.prepare_content("application/json") - http.write('') - local arg - if luci.http.formvalue("force") == "1" then - arg = "force" - else - arg = "" - end - if fs.access("/var/run/update_core") then - if arg == "force" then - luci.sys.exec("kill $(pgrep /usr/share/AdGuardHome/update_core.sh) ; sh /usr/share/AdGuardHome/update_core.sh " .. arg .. " >/tmp/AdGuardHome_update.log 2>&1 &") - end - else - luci.sys.exec("sh /usr/share/AdGuardHome/update_core.sh " .. arg .. " >/tmp/AdGuardHome_update.log 2>&1 &") - end -end - -function get_log() - local logfile = uci:get("AdGuardHome", "AdGuardHome", "logfile") - if (logfile == nil) then - http.write("no log available\n") - return - elseif (logfile == "syslog") then - if not fs.access("/var/run/AdGuardHomesyslog") then - luci.sys.exec("(/usr/share/AdGuardHome/getsyslog.sh &); sleep 1;") - end - logfile = "/tmp/AdGuardHometmp.log" - fs.writefile("/var/run/AdGuardHomesyslog", "1") - elseif not fs.access(logfile) then - http.write("") - return - end - http.prepare_content("text/plain; charset=utf-8") - local fdp = tonumber(fs.readfile("/var/run/lucilogpos")) or 0 - local f = io.open(logfile, "r+") - f:seek("set", fdp) - local a = f:read(2048000) or "" - fdp = f:seek() - fs.writefile("/var/run/lucilogpos", tostring(fdp)) - f:close() - http.write(a) -end - -function do_dellog() - local logfile = uci:get("AdGuardHome", "AdGuardHome", "logfile") - fs.writefile(logfile, "") - http.prepare_content("application/json") - http.write('') -end - -function check_update() - http.prepare_content("text/plain; charset=utf-8") - local fdp = tonumber(fs.readfile("/var/run/lucilogpos")) or 0 - local f = io.open("/tmp/AdGuardHome_update.log", "r+") - f:seek("set", fdp) - local a = f:read(2048000) or "" - fdp = f:seek() - fs.writefile("/var/run/lucilogpos", tostring(fdp)) - f:close() - if fs.access("/var/run/update_core") then - http.write(a) - else - http.write(a .. "\0") - end -end diff --git a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua deleted file mode 100755 index 1b7e50de0..000000000 --- a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/base.lua +++ /dev/null @@ -1,316 +0,0 @@ -require("luci.sys") -require("luci.util") -require("io") -local m, s, o, o1 -local fs = require "nixio.fs" -local uci = require"luci.model.uci".cursor() -local configpath = uci:get("AdGuardHome", "AdGuardHome", "configpath") or "/etc/config/AdGuardHome.yaml" -local binpath = uci:get("AdGuardHome", "AdGuardHome", "binpath") or "/usr/bin/AdGuardHome/AdGuardHome" -httpport = uci:get("AdGuardHome", "AdGuardHome", "httpport") or "3000" - -m = Map("AdGuardHome", "AdGuard Home") -m.description = translate("Free and open source, powerful network-wide ads & trackers blocking DNS server.") -m:section(SimpleSection).template = "AdGuardHome/AdGuardHome_status" - -s = m:section(TypedSection, "AdGuardHome") -s.anonymous = true -s.addremove = false - ----- enable -o = s:option(Flag, "enabled", translate("Enable")) -o.default = 0 -o.optional = false - ----- httpport -o = s:option(Value, "httpport", translate("Browser management port")) -o.placeholder = 3000 -o.default = 3000 -o.datatype = "port" -o.optional = false -o.description = translate("") - ----- update warning not safe -local binmtime = uci:get("AdGuardHome", "AdGuardHome", "binmtime") or "0" -local e = "" -if not fs.access(configpath) then e = e .. " " .. translate("no config") end -if not fs.access(binpath) then - e = e .. " " .. translate("no core") -else - local version = uci:get("AdGuardHome", "AdGuardHome", "version") - local testtime = fs.stat(binpath, "mtime") - if testtime ~= tonumber(binmtime) or version == nil then - -- local tmp=luci.sys.exec(binpath.." -c /dev/null --check-config 2>&1| grep -m 1 -E 'v[0-9.]+' -o") - -- version=string.sub(tmp, 1, -2) - version = luci.sys.exec(string.format("echo -n $(%s --version 2>&1 | awk -F 'version ' '{print $2}' | awk -F ',' '{print $1}')", binpath)) - if version == "" then version = "core error" end - uci:set("AdGuardHome", "AdGuardHome", "version", version) - uci:set("AdGuardHome", "AdGuardHome", "binmtime", testtime) - uci:commit("AdGuardHome") - end - e = version .. e -end - -o = s:option(ListValue, "core_version", translate("Core Version")) -o:value("latest", translate("Latest Version")) -o:value("beta", translate("Beta Version")) -o.default = "latest" - -o = s:option(Button, "restart", translate("Upgrade Core")) -o.inputtitle = translate("Update core version") -o.template = "AdGuardHome/AdGuardHome_check" -o.showfastconfig = (not fs.access(configpath)) -o.description = string.format(translate("Current core version:") .. "%s ", e) - ----- port warning not safe -local port = luci.sys.exec("awk '/ port:/{printf($2);exit;}' " .. configpath .. " 2>nul") -if (port == "") then port = "?" end - ----- Redirect -o = s:option(ListValue, "redirect", port .. translate("Redirect"), translate("AdGuardHome redirect mode")) -o.placeholder = "none" -o:value("none", translate("none")) -o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server")) -o:value("redirect", translate("Redirect 53 port to AdGuardHome")) -o:value("exchange", translate("Use port 53 replace dnsmasq")) -o.default = "none" -o.optional = true - ----- bin path -o = s:option(Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download")) -o.default = "/usr/bin/AdGuardHome/AdGuardHome" -o.datatype = "string" -o.optional = false -o.rmempty = false -o.validate = function(self, value) - if value == "" then return nil end - if fs.stat(value, "type") == "dir" then fs.rmdir(value) end - if fs.stat(value, "type") == "dir" then - if (m.message) then - m.message = m.message .. "\nerror!bin path is a dir" - else - m.message = "error!bin path is a dir" - end - return nil - end - return value -end - ---- upx -o = s:option(ListValue, "upxflag", translate("use upx to compress bin after download")) -o:value("", translate("none")) -o:value("-1", translate("compress faster")) -o:value("-9", translate("compress better")) -o:value("--best", translate("compress best(can be slow for big files)")) -o:value("--brute", translate("try all available compression methods & filters [slow]")) -o:value("--ultra-brute", translate("try even more compression variants [very slow]")) -o.default = "" -o.description = translate("bin use less space,but may have compatibility issues") -o.rmempty = true - ----- config path -o = s:option(Value, "configpath", translate("Config Path"), translate("AdGuardHome config path")) -o.default = "/etc/config/AdGuardHome.yaml" -o.datatype = "string" -o.optional = false -o.rmempty = false -o.validate = function(self, value) - if value == nil then return nil end - if fs.stat(value, "type") == "dir" then fs.rmdir(value) end - if fs.stat(value, "type") == "dir" then - if m.message then - m.message = m.message .. "\nerror!config path is a dir" - else - m.message = "error!config path is a dir" - end - return nil - end - return value -end - ----- work dir -o = s:option(Value, "workdir", translate("Work dir"), translate("AdGuardHome work dir include rules,audit log and database")) -o.default = "/usr/bin/AdGuardHome" -o.datatype = "string" -o.optional = false -o.rmempty = false -o.validate = function(self, value) - if value == "" then return nil end - if fs.stat(value, "type") == "reg" then - if m.message then - m.message = m.message .. "\nerror!work dir is a file" - else - m.message = "error!work dir is a file" - end - return nil - end - if string.sub(value, -1) == "/" then - return string.sub(value, 1, -2) - else - return value - end -end - ----- log file -o = s:option(Value, "logfile", translate("Runtime log file"), translate("AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log")) -o.datatype = "string" -o.rmempty = true -o.validate = function(self, value) - if fs.stat(value, "type") == "dir" then fs.rmdir(value) end - if fs.stat(value, "type") == "dir" then - if m.message then - m.message = m.message .. "\nerror!log file is a dir" - else - m.message = "error!log file is a dir" - end - return nil - end - return value -end - ----- debug -o = s:option(Flag, "verbose", translate("Verbose log")) -o.default = 0 -o.optional = true - ----- gfwlist -local a = luci.sys.call("grep -m 1 -q programadd " .. configpath) -if (a == 0) then - a = "Added" -else - a = "Not added" -end - -o = s:option(Button, "gfwdel", translate("Del gfwlist"), translate(a)) -o.optional = true -o.inputtitle = translate("Del") -o.write = function() - luci.sys.exec("sh /usr/share/AdGuardHome/gfw2adg.sh del 2>&1") - luci.http.redirect(luci.dispatcher.build_url("admin", "services", "AdGuardHome")) -end - -o = s:option(Button, "gfwadd", translate("Add gfwlist"), translate(a)) -o.optional = true -o.inputtitle = translate("Add") -o.write = function() - luci.sys.exec("sh /usr/share/AdGuardHome/gfw2adg.sh 2>&1") - luci.http.redirect(luci.dispatcher.build_url("admin", "services", "AdGuardHome")) -end - -o = s:option(Value, "gfwupstream", translate("Gfwlist upstream dns server"), translate("Gfwlist domain upstream dns service") .. translate(a)) -o.default = "tcp://208.67.220.220:5353" -o.datatype = "string" -o.optional = true - ----- chpass -o = s:option(Value, "hashpass", translate("Change browser management password"), translate("Press load culculate model and culculate finally save/apply")) -o.default = "" -o.datatype = "string" -o.template = "AdGuardHome/AdGuardHome_chpass" -o.optional = true - ----- upgrade protect -o = s:option(MultiValue, "upprotect", translate("Keep files when system upgrade")) -o:value("$binpath", translate("core bin")) -o:value("$configpath", translate("config file")) -o:value("$logfile", translate("log file")) -o:value("$workdir/data/sessions.db", translate("sessions.db")) -o:value("$workdir/data/stats.db", translate("stats.db")) -o:value("$workdir/data/querylog.json", translate("querylog.json")) -o:value("$workdir/data/filters", translate("filters")) -o.widget = "checkbox" -o.default = nil -o.optional = true - ----- wait net on boot -o = s:option(Flag, "waitonboot", translate("On boot when network ok restart")) -o.default = 1 -o.optional = true - ----- backup workdir on shutdown -local workdir = uci:get("AdGuardHome", "AdGuardHome", "workdir") or "/usr/bin/AdGuardHome" -o = s:option(MultiValue, "backupfile", translate("Backup workdir files when shutdown")) -o1 = s:option(Value, "backupwdpath", translate("Backup workdir path")) -local name -o:value("filters", "filters") -o:value("stats.db", "stats.db") -o:value("querylog.json", "querylog.json") -o:value("sessions.db", "sessions.db") -o1:depends("backupfile", "filters") -o1:depends("backupfile", "stats.db") -o1:depends("backupfile", "querylog.json") -o1:depends("backupfile", "sessions.db") -for name in fs.glob(workdir .. "/data/*") do - name = fs.basename(name) - if name ~= "filters" and name ~= "stats.db" and name ~= "querylog.json" and - name ~= "sessions.db" then - o:value(name, name) - o1:depends("backupfile", name) - end -end -o.widget = "checkbox" -o.default = nil -o.optional = false -o.description = translate("Will be restore when workdir/data is empty") -----backup workdir path -o1.default = "/usr/bin/AdGuardHome" -o1.datatype = "string" -o1.optional = false -o1.validate = function(self, value) - if fs.stat(value, "type") == "reg" then - if m.message then - m.message = m.message .. "\nerror!backup dir is a file" - else - m.message = "error!backup dir is a file" - end - return nil - end - if string.sub(value, -1) == "/" then - return string.sub(value, 1, -2) - else - return value - end -end - -----Crontab -o = s:option(MultiValue, "crontab", translate("Crontab task"), translate("Please change time and args in crontab")) -o:value("autoupdate", translate("Auto update core")) -o:value("cutquerylog", translate("Auto tail querylog")) -o:value("cutruntimelog", translate("Auto tail runtime log")) -o:value("autohost", translate("Auto update ipv6 hosts and restart adh")) -o:value("autogfw", translate("Auto update gfwlist and restart adh")) -o.widget = "checkbox" -o.default = nil -o.optional = true - -o = s:option(Value, "update_url", translate("Core Update URL")) -o.default = "https://github.com/AdguardTeam/AdGuardHome/releases/download/${Cloud_Version}/AdGuardHome_linux_${Arch}.tar.gz" -o.placeholder = "https://github.com/AdguardTeam/AdGuardHome/releases/download/${Cloud_Version}/AdGuardHome_linux_${Arch}.tar.gz" -o.rmempty = false -o.optional = false - -function m.on_commit(map) - if (fs.access("/var/run/AdGserverdis")) then - io.popen("/etc/init.d/AdGuardHome reload &") - return - end - local ucitracktest = uci:get("AdGuardHome", "AdGuardHome", "ucitracktest") - if ucitracktest == "1" then - return - elseif ucitracktest == "0" then - io.popen("/etc/init.d/AdGuardHome reload &") - else - if (fs.access("/var/run/AdGlucitest")) then - uci:set("AdGuardHome", "AdGuardHome", "ucitracktest", "0") - io.popen("/etc/init.d/AdGuardHome reload &") - else - fs.writefile("/var/run/AdGlucitest", "") - if (ucitracktest == "2") then - uci:set("AdGuardHome", "AdGuardHome", "ucitracktest", "1") - else - uci:set("AdGuardHome", "AdGuardHome", "ucitracktest", "2") - end - end - uci:commit("AdGuardHome") - end -end -return m diff --git a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/log.lua b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/log.lua deleted file mode 100755 index bcc86d73c..000000000 --- a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/log.lua +++ /dev/null @@ -1,16 +0,0 @@ -local fs = require "nixio.fs" -local uci = require"luci.model.uci".cursor() -local f, t -f = SimpleForm("logview") -f.reset = false -f.submit = false -t = f:field(TextValue, "conf") -t.rmempty = true -t.rows = 20 -t.template = "AdGuardHome/log" -t.readonly = "readonly" -local logfile = uci:get("AdGuardHome", "AdGuardHome", "logfile") or "" -t.timereplace = (logfile ~= "syslog" and logfile ~= "") -t.pollcheck = logfile ~= "" -fs.writefile("/var/run/lucilogpos", "0") -return f diff --git a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua b/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua deleted file mode 100755 index 297f69cd0..000000000 --- a/luci-app-adguardhome/luasrc/model/cbi/AdGuardHome/manual.lua +++ /dev/null @@ -1,100 +0,0 @@ -local m, s, o -local fs = require "nixio.fs" -local uci = require"luci.model.uci".cursor() -local sys = require "luci.sys" -require("string") -require("io") -require("table") -function gen_template_config() - local b - local d = "" - local file = "/tmp/resolv.conf.d/resolv.conf.auto" - if not fs.access(file) then - file = "/tmp/resolv.conf.auto" - end - for cnt in io.lines(file) do - b = string.match(cnt, "^[^#]*nameserver%s+([^%s]+)$") - if (b ~= nil) then d = d .. " - " .. b .. "\n" end - end - local f = io.open("/usr/share/AdGuardHome/AdGuardHome_template.yaml", "r+") - local tbl = {} - local a = "" - while (1) do - a = f:read("*l") - if (a == "#bootstrap_dns") then - a = d - elseif (a == "#upstream_dns") then - a = d - elseif (a == nil) then - break - end - table.insert(tbl, a) - end - f:close() - return table.concat(tbl, "\n") -end - -m = Map("AdGuardHome") -local configpath = uci:get("AdGuardHome", "AdGuardHome", "configpath") -local binpath = uci:get("AdGuardHome", "AdGuardHome", "binpath") -s = m:section(TypedSection, "AdGuardHome") -s.anonymous = true -s.addremove = false - ---- config -o = s:option(TextValue, "escconf") -o.rows = 66 -o.wrap = "off" -o.rmempty = true -o.cfgvalue = function(self, section) - return fs.readfile("/tmp/AdGuardHometmpconfig.yaml") or fs.readfile(configpath) or gen_template_config() or "" -end -o.validate = function(self, value) - fs.writefile("/tmp/AdGuardHometmpconfig.yaml", value:gsub("\r\n", "\n")) - if fs.access(binpath) then - if (sys.call(binpath .. " -c /tmp/AdGuardHometmpconfig.yaml --check-config 2> /tmp/AdGuardHometest.log") == 0) then return value end - else - return value - end - luci.http.redirect(luci.dispatcher.build_url("admin", "services", "AdGuardHome", "manual")) - return nil -end -o.write = function(self, section, value) - fs.move("/tmp/AdGuardHometmpconfig.yaml", configpath) -end -o.remove = function(self, section, value) fs.writefile(configpath, "") end - ---- js and reload button -o = s:option(DummyValue, "") -o.anonymous = true -o.template = "AdGuardHome/yamleditor" -if not fs.access(binpath) then - o.description = translate("WARNING!!! no bin found apply config will not be test") -end - ---- log -if (fs.access("/tmp/AdGuardHometmpconfig.yaml")) then - local c = fs.readfile("/tmp/AdGuardHometest.log") - if (c ~= "") then - o = s:option(TextValue, "") - o.readonly = true - o.rows = 5 - o.rmempty = true - o.name = "" - o.cfgvalue = function(self, section) - return fs.readfile("/tmp/AdGuardHometest.log") - end - end -end - -function m.on_commit(map) - local ucitracktest = uci:get("AdGuardHome", "AdGuardHome", "ucitracktest") - if ucitracktest == "1" then - return - elseif ucitracktest == "0" then - io.popen("/etc/init.d/AdGuardHome reload &") - else - fs.writefile("/var/run/AdGlucitest", "") - end -end -return m diff --git a/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_check.htm b/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_check.htm deleted file mode 100755 index 52315ef7e..000000000 --- a/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_check.htm +++ /dev/null @@ -1,78 +0,0 @@ -<%+cbi/valueheader%> -<%local fs=require"nixio.fs"%> - - -<% if self.showfastconfig then %> - -<%end%> - - -<%+cbi/valuefooter%> \ No newline at end of file diff --git a/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_chpass.htm b/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_chpass.htm deleted file mode 100755 index 440eafd97..000000000 --- a/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_chpass.htm +++ /dev/null @@ -1,49 +0,0 @@ -<%+cbi/valueheader%> - - 0, "data-choices", { self.keylist, self.vallist }) - %> /> - <% if self.password then %><% end %> - -<%+cbi/valuefooter%> \ No newline at end of file diff --git a/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_status.htm b/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_status.htm deleted file mode 100755 index 7e924d119..000000000 --- a/luci-app-adguardhome/luasrc/view/AdGuardHome/AdGuardHome_status.htm +++ /dev/null @@ -1,27 +0,0 @@ - - -
-

- <%:Collecting data...%> -

-
\ No newline at end of file diff --git a/luci-app-adguardhome/luasrc/view/AdGuardHome/log.htm b/luci-app-adguardhome/luasrc/view/AdGuardHome/log.htm deleted file mode 100755 index 44b3da0b1..000000000 --- a/luci-app-adguardhome/luasrc/view/AdGuardHome/log.htm +++ /dev/null @@ -1,110 +0,0 @@ -<%+cbi/valueheader%> -<%:reverse%> -<%if self.timereplace then%> -<%:localtime%>
-<%end%> - - - - -<%+cbi/valuefooter%> \ No newline at end of file diff --git a/luci-app-adguardhome/luasrc/view/AdGuardHome/yamleditor.htm b/luci-app-adguardhome/luasrc/view/AdGuardHome/yamleditor.htm deleted file mode 100755 index 639cb9988..000000000 --- a/luci-app-adguardhome/luasrc/view/AdGuardHome/yamleditor.htm +++ /dev/null @@ -1,39 +0,0 @@ -<%+cbi/valueheader%> - - - - - - - - - -<%fs=require"nixio.fs"%> -<%if fs.access("/tmp/AdGuardHometmpconfig.yaml") then%> - -<%end%> - -<%+cbi/valuefooter%> \ No newline at end of file diff --git a/luci-app-adguardhome/po/zh-cn/AdGuardHome.po b/luci-app-adguardhome/po/zh-cn/AdGuardHome.po deleted file mode 100755 index 77cc06964..000000000 --- a/luci-app-adguardhome/po/zh-cn/AdGuardHome.po +++ /dev/null @@ -1,275 +0,0 @@ -#/cgi-bin/luci/admin/services/AdGuardHome -msgid "Base Setting" -msgstr "基础设置" - -msgid "Log" -msgstr "日志" - -msgid "Manual Config" -msgstr "手动设置" - -msgid "Free and open source, powerful network-wide ads & trackers blocking DNS server." -msgstr "免费开源, 功能强大的网络广告和跟踪程序拦截 DNS 服务器" - -msgid "RUNNING" -msgstr "运行中" - -msgid "NOT RUNNING" -msgstr "未运行" - -msgid "Redirected" -msgstr "已重定向" - -msgid "Not redirect" -msgstr "未重定向" - -msgid "Collecting data..." -msgstr "获取数据中..." - -msgid "Enable" -msgstr "启用" - -msgid "Browser management port" -msgstr "网页管理端口" - -msgid "Upgrade Core" -msgstr "更新核心" - -msgid "Update core version" -msgstr "更新核心版本" - -msgid "Check..." -msgstr "检查中 ..." - -msgid "Updated" -msgstr "已更新" - -msgid "Force update" -msgstr "强制更新核心" - -msgid "Fast config" -msgstr "快速配置" - -msgid "Core Version" -msgstr "核心版本" - -msgid "Latest Version" -msgstr "最新版" - -msgid "Beta Version" -msgstr "测试版" - -msgid "Current core version:" -msgstr "当前核心版本:" - -msgid "no config" -msgstr "没有配置文件" - -msgid "no core" -msgstr "没有核心" - -msgid "Redirect" -msgstr "重定向" - -msgid "none" -msgstr "无" - -msgid "Run as dnsmasq upstream server" -msgstr "作为 dnsmasq 的上游服务器" - -msgid "Redirect 53 port to AdGuardHome" -msgstr "重定向 53 端口到 AdGuardHome" - -msgid "Use port 53 replace dnsmasq" -msgstr "使用 53 端口替换 dnsmasq" - -msgid "AdGuardHome redirect mode" -msgstr "AdGuardHome 重定向模式" - -msgid "Bin Path" -msgstr "执行文件路径" - -msgid "AdGuardHome Bin path if no bin will auto download" -msgstr "AdGuardHome 执行文件路径, 启动时如果没有检测到执行文件将自动下载" - -msgid "use upx to compress bin after download" -msgstr "UPX 压缩核心" - -msgid "compress faster" -msgstr "快速压缩" - -msgid "compress better" -msgstr "更好的压缩" - -msgid "compress best(can be slow for big files)" -msgstr "最好的压缩[大文件可能很慢]" - -msgid "try all available compression methods & filters [slow]" -msgstr "尝试所有可能的压缩方法和过滤器[慢]" - -msgid "try even more compression variants [very slow]" -msgstr "尝试更多变体压缩手段[很慢]" - -msgid "bin use less space,but may have compatibility issues" -msgstr "减小执行文件空间占用, 压缩后存在兼容性问题" - -msgid "Config Path" -msgstr "配置文件路径" - -msgid "AdGuardHome config path" -msgstr "AdGuardHome 配置文件路径" - -msgid "Work dir" -msgstr "工作目录" - -msgid "AdGuardHome work dir include rules,audit log and database" -msgstr "AdGuardHome 工作目录包含规则, 审计日志和数据库" - -msgid "Runtime log file" -msgstr "运行日志路径" - -msgid "AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log" -msgstr "AdGuardHome 运行日志, 如果填 syslog 将写入系统日志; 如果该项为空则不记录运行日志" - -msgid "Verbose log" -msgstr "输出详细日志" - -msgid "Add gfwlist" -msgstr "添加 GFW 列表" - -msgid "Add" -msgstr "添加" - -msgid "Added" -msgstr "已添加" - -msgid "Not added" -msgstr "未添加" - -msgid "Del gfwlist" -msgstr "删除 GFW 列表" - -msgid "Del" -msgstr "删除" - -msgid "Gfwlist upstream dns server" -msgstr "GFW 列表上游服务器" - -msgid "Gfwlist domain upstream dns service" -msgstr "GFW 列表域名上游服务器" - -msgid "Change browser management password" -msgstr "更改网页登录密码" - -msgid "Culculate" -msgstr "计算" - -msgid "Load culculate model" -msgstr "载入计算模块" - -msgid "loading..." -msgstr "载入中 ..." - -msgid "Please save/apply" -msgstr "请点击[保存/应用]" - -msgid "is empty" -msgstr "为空" - -msgid "Press load culculate model and culculate finally save/apply" -msgstr "先输入你想要的密码, 点击[载入计算模块], 然后点击[计算], 最后点击下方[保存&应用]" - -msgid "Keep files when system upgrade" -msgstr "系统升级时保留文件" - -msgid "core bin" -msgstr "核心执行文件" - -msgid "config file" -msgstr "配置文件" - -msgid "log file" -msgstr "日志文件" - -msgid "querylog.json" -msgstr "审计日志.json" -# -msgid "On boot when network ok restart" -msgstr "开机后网络就绪时重启" - -msgid "Backup workdir files when shutdown" -msgstr "在关机时备份以下文件" - -msgid "Will be restore when workdir/data is empty" -msgstr "备份将在 工作目录/data 为空的时候恢复" - -msgid "Backup workdir path" -msgstr "工作目录备份路径" - -msgid "Crontab task" -msgstr "计划任务" - -msgid "Auto update core" -msgstr "自动升级核心" - -msgid "Auto tail querylog" -msgstr "自动截短查询日志" - -msgid "Auto tail runtime log" -msgstr "自动截短运行日志" - -msgid "Auto update ipv6 hosts and restart adh" -msgstr "自动更新 IPv6 主机并重启 AdGuardHome" - -msgid "Auto update gfwlist and restart adh" -msgstr "自动更新 GFW 列表并重启 AdGuardHome" - -msgid "Please change time and args in crontab" -msgstr "请在计划任务中修改时间和参数" - -msgid "Core Update URL" -msgstr "核心更新地址" - -#/cgi-bin/luci/admin/services/AdGuardHome/log/ -msgid "reverse" -msgstr "逆序" - -msgid "localtime" -msgstr "本地时间" - -msgid "Please add log path in config to enable log" -msgstr "请在设置里填写运行日志路径以启用日志" - -msgid "dellog" -msgstr "删除日志" - -msgid "download log" -msgstr "下载日志" - -#/cgi-bin/luci//admin/services/AdGuardHome/manual/ -msgid "Use template" -msgstr "使用模板" - -msgid "Reload Config" -msgstr "重新载入配置" - -msgid "WARNING!!! no bin found apply config will not be test" -msgstr "警告!!! 未找到执行文件, 提交配置将不会进行校验" - -msgid "Change browser management username" -msgstr "更改网页登录用户名" - -msgid "Username" -msgstr "用户名" - -msgid "Check Config" -msgstr "检查配置" - -msgid "unknown" -msgstr "未知" - -msgid "Keep database when system upgrade" -msgstr "系统升级时保留数据" - -msgid "Boot delay until network ok" -msgstr "开机时等到网络就绪后再启动" diff --git a/luci-app-adguardhome/po/zh_Hans/AdGuardHome.po b/luci-app-adguardhome/po/zh_Hans/AdGuardHome.po deleted file mode 100644 index 77cc06964..000000000 --- a/luci-app-adguardhome/po/zh_Hans/AdGuardHome.po +++ /dev/null @@ -1,275 +0,0 @@ -#/cgi-bin/luci/admin/services/AdGuardHome -msgid "Base Setting" -msgstr "基础设置" - -msgid "Log" -msgstr "日志" - -msgid "Manual Config" -msgstr "手动设置" - -msgid "Free and open source, powerful network-wide ads & trackers blocking DNS server." -msgstr "免费开源, 功能强大的网络广告和跟踪程序拦截 DNS 服务器" - -msgid "RUNNING" -msgstr "运行中" - -msgid "NOT RUNNING" -msgstr "未运行" - -msgid "Redirected" -msgstr "已重定向" - -msgid "Not redirect" -msgstr "未重定向" - -msgid "Collecting data..." -msgstr "获取数据中..." - -msgid "Enable" -msgstr "启用" - -msgid "Browser management port" -msgstr "网页管理端口" - -msgid "Upgrade Core" -msgstr "更新核心" - -msgid "Update core version" -msgstr "更新核心版本" - -msgid "Check..." -msgstr "检查中 ..." - -msgid "Updated" -msgstr "已更新" - -msgid "Force update" -msgstr "强制更新核心" - -msgid "Fast config" -msgstr "快速配置" - -msgid "Core Version" -msgstr "核心版本" - -msgid "Latest Version" -msgstr "最新版" - -msgid "Beta Version" -msgstr "测试版" - -msgid "Current core version:" -msgstr "当前核心版本:" - -msgid "no config" -msgstr "没有配置文件" - -msgid "no core" -msgstr "没有核心" - -msgid "Redirect" -msgstr "重定向" - -msgid "none" -msgstr "无" - -msgid "Run as dnsmasq upstream server" -msgstr "作为 dnsmasq 的上游服务器" - -msgid "Redirect 53 port to AdGuardHome" -msgstr "重定向 53 端口到 AdGuardHome" - -msgid "Use port 53 replace dnsmasq" -msgstr "使用 53 端口替换 dnsmasq" - -msgid "AdGuardHome redirect mode" -msgstr "AdGuardHome 重定向模式" - -msgid "Bin Path" -msgstr "执行文件路径" - -msgid "AdGuardHome Bin path if no bin will auto download" -msgstr "AdGuardHome 执行文件路径, 启动时如果没有检测到执行文件将自动下载" - -msgid "use upx to compress bin after download" -msgstr "UPX 压缩核心" - -msgid "compress faster" -msgstr "快速压缩" - -msgid "compress better" -msgstr "更好的压缩" - -msgid "compress best(can be slow for big files)" -msgstr "最好的压缩[大文件可能很慢]" - -msgid "try all available compression methods & filters [slow]" -msgstr "尝试所有可能的压缩方法和过滤器[慢]" - -msgid "try even more compression variants [very slow]" -msgstr "尝试更多变体压缩手段[很慢]" - -msgid "bin use less space,but may have compatibility issues" -msgstr "减小执行文件空间占用, 压缩后存在兼容性问题" - -msgid "Config Path" -msgstr "配置文件路径" - -msgid "AdGuardHome config path" -msgstr "AdGuardHome 配置文件路径" - -msgid "Work dir" -msgstr "工作目录" - -msgid "AdGuardHome work dir include rules,audit log and database" -msgstr "AdGuardHome 工作目录包含规则, 审计日志和数据库" - -msgid "Runtime log file" -msgstr "运行日志路径" - -msgid "AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log" -msgstr "AdGuardHome 运行日志, 如果填 syslog 将写入系统日志; 如果该项为空则不记录运行日志" - -msgid "Verbose log" -msgstr "输出详细日志" - -msgid "Add gfwlist" -msgstr "添加 GFW 列表" - -msgid "Add" -msgstr "添加" - -msgid "Added" -msgstr "已添加" - -msgid "Not added" -msgstr "未添加" - -msgid "Del gfwlist" -msgstr "删除 GFW 列表" - -msgid "Del" -msgstr "删除" - -msgid "Gfwlist upstream dns server" -msgstr "GFW 列表上游服务器" - -msgid "Gfwlist domain upstream dns service" -msgstr "GFW 列表域名上游服务器" - -msgid "Change browser management password" -msgstr "更改网页登录密码" - -msgid "Culculate" -msgstr "计算" - -msgid "Load culculate model" -msgstr "载入计算模块" - -msgid "loading..." -msgstr "载入中 ..." - -msgid "Please save/apply" -msgstr "请点击[保存/应用]" - -msgid "is empty" -msgstr "为空" - -msgid "Press load culculate model and culculate finally save/apply" -msgstr "先输入你想要的密码, 点击[载入计算模块], 然后点击[计算], 最后点击下方[保存&应用]" - -msgid "Keep files when system upgrade" -msgstr "系统升级时保留文件" - -msgid "core bin" -msgstr "核心执行文件" - -msgid "config file" -msgstr "配置文件" - -msgid "log file" -msgstr "日志文件" - -msgid "querylog.json" -msgstr "审计日志.json" -# -msgid "On boot when network ok restart" -msgstr "开机后网络就绪时重启" - -msgid "Backup workdir files when shutdown" -msgstr "在关机时备份以下文件" - -msgid "Will be restore when workdir/data is empty" -msgstr "备份将在 工作目录/data 为空的时候恢复" - -msgid "Backup workdir path" -msgstr "工作目录备份路径" - -msgid "Crontab task" -msgstr "计划任务" - -msgid "Auto update core" -msgstr "自动升级核心" - -msgid "Auto tail querylog" -msgstr "自动截短查询日志" - -msgid "Auto tail runtime log" -msgstr "自动截短运行日志" - -msgid "Auto update ipv6 hosts and restart adh" -msgstr "自动更新 IPv6 主机并重启 AdGuardHome" - -msgid "Auto update gfwlist and restart adh" -msgstr "自动更新 GFW 列表并重启 AdGuardHome" - -msgid "Please change time and args in crontab" -msgstr "请在计划任务中修改时间和参数" - -msgid "Core Update URL" -msgstr "核心更新地址" - -#/cgi-bin/luci/admin/services/AdGuardHome/log/ -msgid "reverse" -msgstr "逆序" - -msgid "localtime" -msgstr "本地时间" - -msgid "Please add log path in config to enable log" -msgstr "请在设置里填写运行日志路径以启用日志" - -msgid "dellog" -msgstr "删除日志" - -msgid "download log" -msgstr "下载日志" - -#/cgi-bin/luci//admin/services/AdGuardHome/manual/ -msgid "Use template" -msgstr "使用模板" - -msgid "Reload Config" -msgstr "重新载入配置" - -msgid "WARNING!!! no bin found apply config will not be test" -msgstr "警告!!! 未找到执行文件, 提交配置将不会进行校验" - -msgid "Change browser management username" -msgstr "更改网页登录用户名" - -msgid "Username" -msgstr "用户名" - -msgid "Check Config" -msgstr "检查配置" - -msgid "unknown" -msgstr "未知" - -msgid "Keep database when system upgrade" -msgstr "系统升级时保留数据" - -msgid "Boot delay until network ok" -msgstr "开机时等到网络就绪后再启动" diff --git a/luci-app-adguardhome/root/etc/config/AdGuardHome b/luci-app-adguardhome/root/etc/config/AdGuardHome deleted file mode 100755 index 7e32fba84..000000000 --- a/luci-app-adguardhome/root/etc/config/AdGuardHome +++ /dev/null @@ -1,11 +0,0 @@ -config AdGuardHome 'AdGuardHome' - option enabled '0' - option httpport '3000' - option redirect 'dnsmasq-upstream' - option configpath '/etc/config/AdGuardHome.yaml' - option workdir '/usr/bin/AdGuardHome' - option logfile '/tmp/AdGuardHome.log' - option verbose '0' - option binpath '/tmp/AdGuardHome/AdGuardHome' - option upxflag '' - diff --git a/luci-app-adguardhome/root/etc/init.d/AdGuardHome b/luci-app-adguardhome/root/etc/init.d/AdGuardHome deleted file mode 100755 index 507ab2523..000000000 --- a/luci-app-adguardhome/root/etc/init.d/AdGuardHome +++ /dev/null @@ -1,615 +0,0 @@ -#!/bin/sh /etc/rc.common - -USE_PROCD=1 - -START=95 -STOP=01 - -CONFIGURATION=AdGuardHome -CRON_FILE=/etc/crontabs/root -EXTRA_COMMANDS="do_redirect testbackup test_crontab force_reload isrunning" -EXTRA_HELP=" do_redirect 0 or 1\ - testbackup backup or restore\ - test_crontab - force_reload - isrunning" -set_forward_dnsmasq() { - local PORT="$1" - addr="127.0.0.1#$PORT" - OLD_SERVER="`uci get dhcp.@dnsmasq[0].server 2>/dev/null`" - echo $OLD_SERVER | grep "^$addr" >/dev/null 2>&1 - if [ $? -eq 0 ]; then - return - fi - uci delete dhcp.@dnsmasq[0].server 2>/dev/null - uci add_list dhcp.@dnsmasq[0].server=$addr - for server in $OLD_SERVER; do - if [ "$server" = "$addr" ]; then - continue - fi - uci add_list dhcp.@dnsmasq[0].server=$server - done - uci delete dhcp.@dnsmasq[0].resolvfile 2>/dev/null - uci set dhcp.@dnsmasq[0].noresolv=1 - uci commit dhcp - /etc/init.d/dnsmasq restart -} - -stop_forward_dnsmasq() { - local OLD_PORT="$1" - addr="127.0.0.1#$OLD_PORT" - OLD_SERVER="`uci get dhcp.@dnsmasq[0].server 2>/dev/null`" - echo $OLD_SERVER | grep "^$addr" >/dev/null 2>&1 - if [ $? -ne 0 ]; then - return - fi - - uci del_list dhcp.@dnsmasq[0].server=$addr 2>/dev/null - addrlist="`uci get dhcp.@dnsmasq[0].server 2>/dev/null`" - if [ -z "$addrlist" ] ; then - resolvfile="/tmp/resolv.conf.d/resolv.conf.auto" - [ ! -f "$resolvfile" ] && resolvfile="/tmp/resolv.conf.auto" - uci set dhcp.@dnsmasq[0].resolvfile="$resolvfile" 2>/dev/null - uci delete dhcp.@dnsmasq[0].noresolv 2>/dev/null - fi - uci commit dhcp - /etc/init.d/dnsmasq restart -} - -set_iptable() { - local ipv6_server=$1 - local tcp_server=$2 - uci -q batch <<-EOF >/dev/null 2>&1 - delete firewall.AdGuardHome - set firewall.AdGuardHome=include - set firewall.AdGuardHome.type=script - set firewall.AdGuardHome.path=/usr/share/AdGuardHome/firewall.start - set firewall.AdGuardHome.reload=1 - commit firewall -EOF - - [ "$tcp_server" == "1" ] && iptables -t nat -I PREROUTING 1 -m comment --comment "AdGuardHome" -p tcp --dport 53 -j REDIRECT --to-ports $AdGuardHome_PORT - iptables -t nat -I PREROUTING 1 -m comment --comment "AdGuardHome" -p udp --dport 53 -j REDIRECT --to-ports $AdGuardHome_PORT - - [ "$ipv6_server" == 0 ] && return - - [ "$tcp_server" == "1" ] && ip6tables -t nat -I PREROUTING 1 -m comment --comment "AdGuardHome" -p tcp --dport 53 -j REDIRECT --to-ports $AdGuardHome_PORT - ip6tables -t nat -I PREROUTING 1 -m comment --comment "AdGuardHome" -p udp --dport 53 -j REDIRECT --to-ports $AdGuardHome_PORT -} - -clear_iptable() { - uci -q batch <<-EOF >/dev/null 2>&1 - delete firewall.AdGuardHome - commit firewall -EOF - - nums=$(iptables -t nat -n -L PREROUTING 2>/dev/null | grep -c "AdGuardHome") - if [ -n "$nums" ]; then - until [ "$nums" = 0 ] - do - rules=$(iptables -t nat -n -L PREROUTING --line-num 2>/dev/null | grep "AdGuardHome" | awk '{print $1}') - for rule in $rules - do - iptables -t nat -D PREROUTING $rule 2> /dev/null - break - done - nums=$(expr $nums - 1) - done - fi - - nums=$(ip6tables -t nat -n -L PREROUTING 2>/dev/null | grep -c "AdGuardHome") - if [ -n "$nums" ]; then - until [ "$nums" = 0 ] - do - rules=$(ip6tables -t nat -n -L PREROUTING --line-num 2>/dev/null | grep "AdGuardHome" | awk '{print $1}') - for rule in $rules - do - ip6tables -t nat -D PREROUTING $rule 2> /dev/null - break - done - nums=$(expr $nums - 1) - done - fi -} - -service_triggers() { - procd_add_reload_trigger "$CONFIGURATION" - [ "$(uci get AdGuardHome.AdGuardHome.redirect)" == "redirect" ] && procd_add_reload_trigger firewall -} - -isrunning() { - config_load "${CONFIGURATION}" - _isrunning - local r=$? - ([ "$r" == "0" ] && echo "running") || ([ "$r" == "1" ] && echo "not run" ) || echo "no bin" - return $r -} - -_isrunning() { - config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome/AdGuardHome" - [ ! -f "$binpath" ] && return 2 - pgrep $binpath 2>&1 >/dev/null && return 0 - return 1 -} - -force_reload() { - config_load "${CONFIGURATION}" - _isrunning && procd_send_signal "$CONFIGURATION" || start -} - -get_tz() { - SET_TZ="" - - if [ -e "/etc/localtime" ]; then - return - fi - - for tzfile in /etc/TZ /var/etc/TZ - do - if [ ! -e "$tzfile" ]; then - continue - fi - - tz="`cat $tzfile 2>/dev/null`" - done - - if [ -z "$tz" ]; then - return - fi - - SET_TZ=$tz -} - -rm_port53() { - local AdGuardHome_PORT=$(config_editor "dns.port" "" "$configpath" "1") - dnsmasq_port=$(uci get dhcp.@dnsmasq[0].port 2>/dev/null) - if [ -z "$dnsmasq_port" ]; then - dnsmasq_port="53" - fi - if [ "$dnsmasq_port" == "$AdGuardHome_PORT" ]; then - if [ "$dnsmasq_port" == "53" ]; then - dnsmasq_port="1745" - fi - elif [ "$dnsmasq_port" == "53" ]; then - return - fi - config_editor "dns.port" "$dnsmasq_port" "$configpath" - uci set dhcp.@dnsmasq[0].port="53" - uci commit dhcp - /etc/init.d/dnsmasq restart -} - -use_port53() { - local AdGuardHome_PORT=$(config_editor "dns.port" "" "$configpath" "1") - dnsmasq_port=$(uci get dhcp.@dnsmasq[0].port 2>/dev/null) - if [ -z "$dnsmasq_port" ]; then - dnsmasq_port="53" - fi - if [ "$dnsmasq_port" == "$AdGuardHome_PORT" ]; then - if [ "$dnsmasq_port" == "53" ]; then - AdGuardHome_PORT="1745" - fi - elif [ "$AdGuardHome_PORT" == "53" ]; then - return - fi - config_editor "dns.port" "53" "$configpath" - uci set dhcp.@dnsmasq[0].port="$AdGuardHome_PORT" - uci commit dhcp - /etc/init.d/dnsmasq restart -} - -do_redirect() { - config_load "${CONFIGURATION}" - _do_redirect $1 -} - -_do_redirect() { - local section="$CONFIGURATION" - args="" - ipv6_server=1 - tcp_server=0 - enabled=$1 - if [ "$enabled" == "1" ]; then - echo -n "1">/var/run/AdGredir - else - echo -n "0">/var/run/AdGredir - fi - config_get configpath $CONFIGURATION configpath "/etc/AdGuardHome.yaml" - AdGuardHome_PORT=$(config_editor "dns.port" "" "$configpath" "1") - if [ -z "$AdGuardHome_PORT" ]; then - AdGuardHome_PORT="0" - fi - config_get "redirect" "$section" "redirect" "none" - config_get "old_redirect" "$section" "old_redirect" "none" - config_get "old_port" "$section" "old_port" "0" - config_get "old_enabled" "$section" "old_enabled" "0" - uci get dhcp.@dnsmasq[0].port >/dev/null 2>&1 || uci set dhcp.@dnsmasq[0].port="53" >/dev/null 2>&1 - uci commit dhcp - if [ "$old_enabled" = "1" -a "$old_redirect" == "exchange" ]; then - AdGuardHome_PORT=$(uci get dhcp.@dnsmasq[0].port 2>/dev/null) - fi - - if [ "$old_redirect" != "$redirect" ] || [ "$old_port" != "$AdGuardHome_PORT" ] || [ "$old_enabled" = "1" -a "$enabled" = "0" ]; then - if [ "$old_redirect" != "none" ]; then - if [ "$old_redirect" == "redirect" -a "$old_port" != "0" ]; then - clear_iptable - elif [ "$old_redirect" == "dnsmasq-upstream" ]; then - stop_forward_dnsmasq "$old_port" - elif [ "$old_redirect" == "exchange" ]; then - rm_port53 - fi - fi - elif [ "$old_enabled" = "1" -a "$enabled" = "1" ]; then - if [ "$old_redirect" == "redirect" -a "$old_port" != "0" ]; then - clear_iptable - fi - fi - uci delete AdGuardHome.@AdGuardHome[0].old_redirect 2>/dev/null - uci delete AdGuardHome.@AdGuardHome[0].old_port 2>/dev/null - uci delete AdGuardHome.@AdGuardHome[0].old_enabled 2>/dev/null - uci add_list AdGuardHome.@AdGuardHome[0].old_redirect="$redirect" 2>/dev/null - uci add_list AdGuardHome.@AdGuardHome[0].old_port="$AdGuardHome_PORT" 2>/dev/null - uci add_list AdGuardHome.@AdGuardHome[0].old_enabled="$enabled" 2>/dev/null - uci commit AdGuardHome - [ "$enabled" == "0" ] && return 1 - if [ "$AdGuardHome_PORT" == "0" ]; then - return 1 - fi - if [ "$redirect" = "redirect" ]; then - set_iptable $ipv6_server $tcp_server - elif [ "$redirect" = "dnsmasq-upstream" ]; then - set_forward_dnsmasq "$AdGuardHome_PORT" - elif [ "$redirect" == "exchange" -a "$(uci get dhcp.@dnsmasq[0].port 2>/dev/null)" == "53" ]; then - use_port53 - fi -} - -get_filesystem() { -# print out path filesystem - echo $1 | awk ' - BEGIN{ - while (("mount"| getline ret) > 0) - { - split(ret,d); - fs[d[3]]=d[5]; - m=index(d[1],":") - if (m==0) - { - pt[d[3]]=d[1] - }else{ - pt[d[3]]=substr(d[1],m+1) - }}}{ - split($0,d,"/"); - if ("/" in fs) - { - result1=fs["/"]; - } - if ("/" in pt) - { - result2=pt["/"]; - } - for (i=2;i<=length(d);i++) - { - p[i]=p[i-1]"/"d[i]; - if (p[i] in fs) - { - result1=fs[p[i]]; - result2=pt[p[i]]; - } - } - if (result2 in fs){ - result=fs[result2]} - else{ - result=result1} - print(result);}' -} - -config_editor() -{ - awk -v yaml="$1" -v value="$2" -v file="$3" -v ro="$4" ' - BEGIN{split(yaml,part,"\.");s="";i=1;l=length(part);} - { - if (match($0,s""part[i]":")) - { - if (i==l) - { - split($0,t,": "); - if (ro==""){ - system("sed -i '\''"FNR"c \\"t[1]": "value"'\'' "file); - }else{ - print(t[2]); - } - exit; - } - s=s"[- ]{2}"; - i++; - } - }' $3 -} - -boot_service() { - rm /var/run/AdGserverdis >/dev/null 2>&1 - config_load "${CONFIGURATION}" - config_get waitonboot $CONFIGURATION waitonboot "0" - config_get_bool enabled $CONFIGURATION enabled 0 - config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome/AdGuardHome" - [ -f "$binpath" ] && start_service - if [ "$enabled" == "1" ] && [ "$waitonboot" == "1" ]; then - procd_open_instance "waitnet" - procd_set_param command "/usr/share/AdGuardHome/waitnet.sh" - procd_close_instance - echo "no net start pinging" - fi -} - -testbackup() { - config_load "${CONFIGURATION}" - if [ "$1" == "backup" ]; then - backup - elif [ "$1" == "restore" ]; then - restore - fi -} - -restore() { - config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome" - config_get backupwdpath $CONFIGURATION backupwdpath "/usr/bin/AdGuardHome" - cp -u -r -f $backupwdpath/data $workdir -} - -backup() { - config_get backupwdpath $CONFIGURATION backupwdpath "/usr/bin/AdGuardHome" - mkdir -p $backupwdpath/data - config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome" - config_get backupfile $CONFIGURATION backupfile "" - for one in $backupfile; - do - while : - do - if [ -d "$backupwdpath/data/$one" ]; then - cpret=$(cp -u -r -f $workdir/data/$one $backupwdpath/data 2>&1) - else - cpret=$(cp -u -r -f $workdir/data/$one $backupwdpath/data/$one 2>&1) - fi - echo "$cpret" - echo "$cpret" | grep "no space left on device" - if [ "$?" == "0" ]; then - echo "磁盘空间已满,删除 log 文件重试中 ..." - del_querylog && continue - rm -f -r $backupwdpath/data/filters - rm -f -r $workdir/data/filters && continue - echo "backup failed" - fi - break - done - done -} - -start_service() { - # Reading config - rm /var/run/AdGserverdis >/dev/null 2>&1 - config_load "${CONFIGURATION}" - # update password - config_get hashpass $CONFIGURATION hashpass "" - config_get configpath $CONFIGURATION configpath "/etc/AdGuardHome.yaml" - [ -f $configpath ] && chmod 777 $configpath - if [ -n "$hashpass" ]; then - config_editor "users.password" "$hashpass" "$configpath" - uci set $CONFIGURATION.$CONFIGURATION.hashpass="" - fi - local enabled - config_get_bool enabled $CONFIGURATION enabled 0 - # update crontab - do_crontab - if [ "$enabled" == "0" ]; then - _do_redirect 0 - return - fi - #what need to do before reload - config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome" - - config_get backupfile $CONFIGURATION backupfile "" - mkdir -p $workdir/data - if [ -n "$backupfile" ] && [ ! -d "$workdir/data" ]; then - restore - fi - local cwdfs=$(get_filesystem $workdir) - echo "文件系统: ${cwdfs}" - if [ "$cwdfs" == "jffs2" ]; then - echo "fs error ln db to tmp $workdir $cwdfs" - logger "AdGuardHome" "warning db redirect to tmp" - touch $workdir/data/stats.db - if [ ! -L $workdir/data/stats.db ]; then - mv -f $workdir/data/stats.db /tmp/stats.db 2>/dev/null - ln -s /tmp/stats.db $workdir/data/stats.db 2>/dev/null - fi - touch $workdir/data/sessions.db - if [ ! -L $workdir/data/sessions.db ]; then - mv -f $workdir/data/sessions.db /tmp/sessions.db 2>/dev/null - ln -s /tmp/sessions.db $workdir/data/sessions.db 2>/dev/null - fi - fi - local ADDITIONAL_ARGS="" - config_get binpath $CONFIGURATION binpath "/usr/bin/AdGuardHome/AdGuardHome" - - mkdir -p ${binpath%/*} - ADDITIONAL_ARGS="$ADDITIONAL_ARGS -c $configpath" - ADDITIONAL_ARGS="$ADDITIONAL_ARGS -w $workdir" - config_get httpport $CONFIGURATION httpport 3000 - ADDITIONAL_ARGS="$ADDITIONAL_ARGS -p $httpport" - - # hack to save config file when upgrade system - config_get upprotect $CONFIGURATION upprotect "" - eval upprotect=${upprotect// /\\\\n} - echo -e "$upprotect" > /lib/upgrade/keep.d/luci-app-adguardhome - - config_get logfile $CONFIGURATION logfile "" - if [ -n "$logfile" ]; then - ADDITIONAL_ARGS="$ADDITIONAL_ARGS -l $logfile" - fi - - if [ ! -f "$binpath" ]; then - _do_redirect 0 - /usr/share/AdGuardHome/update_core.sh 2>&1 >/tmp/AdGuardHome_update.log & - exit 0 - else - chmod 777 $binpath - fi - - config_get_bool verbose $CONFIGURATION verbose 0 - if [ "$verbose" -eq 1 ]; then - ADDITIONAL_ARGS="$ADDITIONAL_ARGS -v" - fi - - procd_open_instance - get_tz - if [ -n "$SET_TZ" ]; then - procd_set_param env TZ="$SET_TZ" - fi - procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} - procd_set_param limits core="unlimited" nofile="65535 65535" - procd_set_param stderr 1 - procd_set_param command $binpath $ADDITIONAL_ARGS - procd_set_param file "$configpath" "/etc/hosts" "/etc/config/AdGuardHome" - procd_close_instance - if [ -f "$configpath" ]; then - _do_redirect 1 - else - _do_redirect 0 - config_get "redirect" "AdGuardHome" "redirect" "none" - if [ "$redirect" != "none" ]; then - procd_open_instance "waitconfig" - procd_set_param command "/usr/share/AdGuardHome/watchconfig.sh" - procd_close_instance - echo "no config start watching" - fi - fi - echo "AdGuardHome 服务已启用" - (sleep 10 && [ -z "$(pgrep $binpath)" ] && logger "AdGuardHome" "no process in 10s cancel redirect" && _do_redirect 0 )& -} - -reload_service() { - rm /var/run/AdGlucitest >/dev/null 2>&1 - echo "重载 AdGuardHome 服务..." - start -} - -del_querylog() { - local btarget=$(ls $backupwdpath/data | grep -F "querylog.json" | sort -r | head -n 1) - local wtarget=$(ls $workdir/data | grep -F "querylog.json" | sort -r | head -n 1) - if [ "$btarget"x == "$wtarget"x ]; then - [ -z "$btarget" ] && return 1 - rm -f $workdir/data/$wtarget - rm -f $backupwdpath/data/$btarget - return 0 - fi - if [ "$btarget" \> "$wtarget" ]; then - rm -f $backupwdpath/data/$btarget - return 0 - else - rm -f $workdir/data/$wtarget - return 0 - fi -} -stop_service() { - config_load "${CONFIGURATION}" - _do_redirect 0 - do_crontab - if [ "$1" != "nobackup" ]; then - config_get backupfile $CONFIGURATION backupfile "0" - if [ -n "$backupfile" ]; then - backup - fi - fi - echo "AdGuardHome 服务已停止" - touch /var/run/AdGserverdis -} - -boot() { - rc_procd boot_service "$@" - if eval "type service_started" 2>/dev/null >/dev/null; then - service_started - fi -} -test_crontab() { - config_load "${CONFIGURATION}" - do_crontab -} - -do_crontab() { - config_get_bool enabled $CONFIGURATION enabled 0 - config_get crontab $CONFIGURATION crontab "" - local findstr default cronenable replace commit - local cronreload=0 - local commit=0 - findstr="/usr/share/AdGuardHome/update_core.sh" - default="30 3 * * * /usr/share/AdGuardHome/update_core.sh 2>&1" - [ "$enabled" == "0" ] || [ "${crontab//autoupdate/}" == "$crontab" ] && cronenable=0 || cronenable=1 - crontab_editor - - config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome" - config_get lastworkdir $CONFIGURATION lastworkdir "/usr/bin/AdGuardHome" - findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* \$(uci get AdGuardHome.AdGuardHome.workdir)/data/querylog.json" - #[ -n "$lastworkdir" ] && findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* $lastworkdir/data/querylog.json" && [ "$lastworkdir" != "$workdir" ] && replace="${lastworkdir//\//\\/}/${workdir//\//\\/}" - default="0 * * * * /usr/share/AdGuardHome/tailto.sh 2000 \$(uci get AdGuardHome.AdGuardHome.workdir)/data/querylog.json" - [ "$enabled" == "0" ] || [ "${crontab//cutquerylog/}" == "$crontab" ] && cronenable=0 || cronenable=1 - crontab_editor - #[ "$lastworkdir" != "$workdir" ] && uci set AdGuardHome.AdGuardHome.lastworkdir="$workdir" && commit=1 - - config_get logfile $CONFIGURATION logfile "" - config_get lastlogfile $CONFIGURATION lastlogfile "" - findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* \$(uci get AdGuardHome.AdGuardHome.logfile)" - default="30 3 * * * /usr/share/AdGuardHome/tailto.sh 2000 \$(uci get AdGuardHome.AdGuardHome.logfile)" - #[ -n "$lastlogfile" ] && findstr="/usr/share/AdGuardHome/tailto.sh [0-9]* $lastlogfile" && [ -n "$logfile" ] && [ "$lastlogfile" != "$logfile" ] && replace="${lastlogfile//\//\\/}/${logfile//\//\\/}" - [ "$logfile" == "syslog" ] || [ "$logfile" == "" ] || [ "$enabled" == "0" ] || [ "${crontab//cutruntimelog/}" == "$crontab" ] && cronenable=0 || cronenable=1 - crontab_editor - #[ -n "$logfile" ] && [ "$lastlogfile" != "$logfile" ] && uci set AdGuardHome.AdGuardHome.lastlogfile="$logfile" && commit=1 - - findstr="/usr/share/AdGuardHome/addhost.sh" - default="0 * * * * /usr/share/AdGuardHome/addhost.sh" - [ "$enabled" == "0" ] || [ "${crontab//autohost/}" == "$crontab" ] && cronenable=0 || cronenable=1 - crontab_editor - [ "$cronenable" == "0" ] && /usr/share/AdGuardHome/addhost.sh "del" "noreload" || /usr/share/AdGuardHome/addhost.sh "" "noreload" - - findstr="/usr/share/AdGuardHome/gfw2adg.sh" - default="30 3 * * * /usr/share/AdGuardHome/gfw2adg.sh" - [ "$enabled" == "0" ] || [ "${crontab//autogfw/}" == "$crontab" ] && cronenable=0 || cronenable=1 - crontab_editor - [ "$cronreload" -gt 0 ] && /etc/init.d/cron restart - #[ "$commit" -gt 0 ] && uci commit AdGuardHome -} -crontab_editor() { - #usage input: - #findstr= - #default= - #cronenable= - #replace="${last//\//\\/}/${now//\//\\/}" - #output:cronreload:if >1 please /etc/init.d/cron restart manual - local testline reload - local line="$(grep "$findstr" $CRON_FILE)" - [ -n "$replace" ] && [ -n "$line" ] && eval testline="\${line//$replace}" && [ "$testline" != "$line" ] && line="$testline" && reload="1" && replace="" - if [ "${line:0:1}" != "#" ]; then - if [ $cronenable -eq 1 ]; then - [ -z "$line" ] && line="$default" && reload="1" - if [ -n "$reload" ]; then - sed -i "\,$findstr,d" $CRON_FILE - echo "$line" >> $CRON_FILE - cronreload=$((cronreload+1)) - fi - elif [ -n "$line" ]; then - sed -i "\,$findstr,d" $CRON_FILE - echo "#$line" >> $CRON_FILE - cronreload=$((cronreload+1)) - fi - else - if [ $cronenable -eq 1 ]; then - sed -i "\,$findstr,d" $CRON_FILE - echo "${line:1}" >> $CRON_FILE - cronreload=$((cronreload+1)) - elif [ -z "$reload" ]; then - sed -i "\,$findstr,d" $CRON_FILE - echo "$line" >> $CRON_FILE - fi - fi - -} diff --git a/luci-app-adguardhome/root/etc/uci-defaults/40_luci-AdGuardHome b/luci-app-adguardhome/root/etc/uci-defaults/40_luci-AdGuardHome deleted file mode 100755 index 2d467df98..000000000 --- a/luci-app-adguardhome/root/etc/uci-defaults/40_luci-AdGuardHome +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -uci -q batch <<-EOF >/dev/null 2>&1 - delete ucitrack.@AdGuardHome[-1] - add ucitrack AdGuardHome - set ucitrack.@AdGuardHome[-1].init=AdGuardHome - commit ucitrack - delete AdGuardHome.AdGuardHome.ucitracktest -EOF - -rm -f /tmp/luci-indexcache -exit 0 diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/AdGuardHome_template.yaml b/luci-app-adguardhome/root/usr/share/AdGuardHome/AdGuardHome_template.yaml deleted file mode 100755 index 073443e68..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/AdGuardHome_template.yaml +++ /dev/null @@ -1,136 +0,0 @@ -# 使用本模板,点击下方 [保存&应用] 就可以开始正常使用 AdGuardHome 服务 -# Enhanced by Hyy2001 - -bind_host: 0.0.0.0 -bind_port: 3000 -beta_bind_port: 0 -users: -- name: root - password: $2a$10$rYaGunOdH6N62SDycg3rQO1POzr39lXF8vHZ/28wkJq3RY69DJYT2 -auth_attempts: 5 -block_auth_min: 15 -http_proxy: "" -language: "" -rlimit_nofile: 0 -debug_pprof: false -web_session_ttl: 720 -dns: - bind_hosts: - - 0.0.0.0 - port: 5553 - statistics_interval: 90 - querylog_enabled: true - querylog_file_enabled: true - querylog_interval: 1 - querylog_size_memory: 1000 - anonymize_client_ip: false - protection_enabled: true - blocking_mode: default - blocking_ipv4: "" - blocking_ipv6: "" - blocked_response_ttl: 10 - parental_block_host: family-block.dns.adguard.com - safebrowsing_block_host: standard-block.dns.adguard.com - ratelimit: 0 - ratelimit_whitelist: [] - refuse_any: true - upstream_dns: - - https://dns.alidns.com/dns-query - - tls://dns.alidns.com - - 114.114.114.114 - - 223.5.5.5 - upstream_dns_file: "" - bootstrap_dns: -#bootstrap_dns - all_servers: true - fastest_addr: false - allowed_clients: [] - disallowed_clients: [] - blocked_hosts: - - version.bind - - id.server - - hostname.bind - cache_size: 4194304 - cache_ttl_min: 0 - cache_ttl_max: 0 - bogus_nxdomain: [] - aaaa_disabled: true - enable_dnssec: true - edns_client_subnet: false - max_goroutines: 300 - ipset: [] - filtering_enabled: true - filters_update_interval: 24 - parental_enabled: false - safesearch_enabled: false - safebrowsing_enabled: false - safebrowsing_cache_size: 1048576 - safesearch_cache_size: 1048576 - parental_cache_size: 1048576 - cache_time: 30 - rewrites: [] - blocked_services: [] - local_domain_name: lan - resolve_clients: false - local_ptr_upstreams: [] -tls: - enabled: false - server_name: "" - force_https: false - port_https: 443 - port_dns_over_tls: 853 - port_dns_over_quic: 784 - port_dnscrypt: 0 - dnscrypt_config_file: "" - allow_unencrypted_doh: false - strict_sni_check: false - certificate_chain: "" - private_key: "" - certificate_path: "" - private_key_path: "" -filters: -- enabled: true - url: https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt - name: AdGuard Home - id: 1 -- enabled: true - url: https://banbendalao.coding.net/p/adgk/d/ADgk/git/raw/master/ADgk.txt - name: AD-gk - id: 2 -- enabled: false - url: https://anti-ad.net/easylist.txt - name: anti-AD - id: 4 -- enabled: true - url: https://raw.githubusercontent.com/o0HalfLife0o/list/master/ad.txt - name: HalfLife - id: 5 -whitelist_filters: [] -user_rules: -- '@@||iwx.mail.qq.com^$important' -- '@@||gm.mmstat.com^$important' -dhcp: - enabled: false - interface_name: "" - dhcpv4: - gateway_ip: "" - subnet_mask: "" - range_start: "" - range_end: "" - lease_duration: 86400 - icmp_timeout_msec: 1000 - options: [] - dhcpv6: - range_start: "" - lease_duration: 86400 - ra_slaac_only: false - ra_allow_slaac: false -clients: [] -log_compress: false -log_localtime: false -log_max_backups: 0 -log_max_size: 100 -log_max_age: 3 -log_file: "" -verbose: false -schema_version: 10 diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/addhost.sh b/luci-app-adguardhome/root/usr/share/AdGuardHome/addhost.sh deleted file mode 100755 index 2461b74dd..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/addhost.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -checkmd5(){ -local nowmd5=$(md5sum /etc/hosts) -nowmd5=${nowmd5%% *} -local lastmd5=$(uci get AdGuardHome.AdGuardHome.hostsmd5 2>/dev/null) -if [ "$nowmd5" != "$lastmd5" ]; then - uci set AdGuardHome.AdGuardHome.hostsmd5="$nowmd5" - uci commit AdGuardHome - [ "$1" == "noreload" ] || /etc/init.d/AdGuardHome reload -fi -} -[ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' /etc/hosts && checkmd5 "$2" && exit 0 -/usr/bin/awk 'BEGIN{ -while ((getline < "/tmp/dhcp.leases") > 0) -{ - a[$2]=$4; -} -while (("ip -6 neighbor show | grep -v fe80" | getline) > 0) -{ - if (a[$5]) {print $1" "a[$5] >"/tmp/tmphost"; } -} -print "#programaddend" >"/tmp/tmphost"; -}' -grep programaddstart /etc/hosts >/dev/null 2>&1 -if [ "$?" == "0" ]; then - sed -i '/programaddstart/,/programaddend/c\#programaddstart' /etc/hosts - sed -i '/programaddstart/'r/tmp/tmphost /etc/hosts -else - echo "#programaddstart" >>/etc/hosts - cat /tmp/tmphost >> /etc/hosts -fi -rm /tmp/tmphost -checkmd5 "$2" \ No newline at end of file diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/firewall.start b/luci-app-adguardhome/root/usr/share/AdGuardHome/firewall.start deleted file mode 100755 index 562117e52..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/firewall.start +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -AdGuardHome_enable=$(uci get AdGuardHome.AdGuardHome.enabled) -redirect=$(uci get AdGuardHome.AdGuardHome.redirect) - -if [ $AdGuardHome_enable -eq 1 -a "$redirect" == "redirect" ]; then - /etc/init.d/AdGuardHome do_redirect 1 -fi diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/getsyslog.sh b/luci-app-adguardhome/root/usr/share/AdGuardHome/getsyslog.sh deleted file mode 100755 index c95cc077b..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/getsyslog.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -PATH="/usr/sbin:/usr/bin:/sbin:/bin" -logread -e AdGuardHome > /tmp/AdGuardHometmp.log -logread -e AdGuardHome -f >> /tmp/AdGuardHometmp.log & -pid=$! -echo "1">/var/run/AdGuardHomesyslog -while true -do - sleep 12 - watchdog=$(cat /var/run/AdGuardHomesyslog) - if [ "$watchdog"x == "0"x ]; then - kill $pid - rm /tmp/AdGuardHometmp.log - rm /var/run/AdGuardHomesyslog - exit 0 - else - echo "0">/var/run/AdGuardHomesyslog - fi -done \ No newline at end of file diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/gfw2adg.sh b/luci-app-adguardhome/root/usr/share/AdGuardHome/gfw2adg.sh deleted file mode 100755 index 386d4307a..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/gfw2adg.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/sh -PATH="/usr/sbin:/usr/bin:/sbin:/bin" -checkmd5(){ -local nowmd5=$(md5sum /tmp/adguard.list 2>/dev/null) -nowmd5=${nowmd5%% *} -local lastmd5=$(uci get AdGuardHome.AdGuardHome.gfwlistmd5 2>/dev/null) -if [ "$nowmd5" != "$lastmd5" ]; then - uci set AdGuardHome.AdGuardHome.gfwlistmd5="$nowmd5" - uci commit AdGuardHome - [ "$1" == "noreload" ] || /etc/init.d/AdGuardHome reload -fi -} -configpath=$(uci get AdGuardHome.AdGuardHome.configpath 2>/dev/null) -[ "$1" == "del" ] && sed -i '/programaddstart/,/programaddend/d' $configpath && checkmd5 "$2" && exit 0 -gfwupstream=$(uci get AdGuardHome.AdGuardHome.gfwupstream 2>/dev/null) -if [ -z $gfwupstream ]; then -gfwupstream="tcp://208.67.220.220:5353" -fi -if [ ! -f "$configpath" ]; then - echo "please make a config first" - exit 1 -fi -wget-ssl --no-check-certificate https://cdn.jsdelivr.net/gh/gfwlist/gfwlist/gfwlist.txt -O- | base64 -d > /tmp/gfwlist.txt -cat /tmp/gfwlist.txt | awk -v upst="$gfwupstream" 'BEGIN{getline;}{ -s1=substr($0,1,1); -if (s1=="!") -{next;} -if (s1=="@"){ - $0=substr($0,3); - s1=substr($0,1,1); - white=1;} -else{ - white=0; -} - -if (s1=="|") - {s2=substr($0,2,1); - if (s2=="|") - { - $0=substr($0,3); - split($0,d,"/"); - $0=d[1]; - }else{ - split($0,d,"/"); - $0=d[3]; - }} -else{ - split($0,d,"/"); - $0=d[1]; -} -star=index($0,"*"); -if (star!=0) -{ - $0=substr($0,star+1); - dot=index($0,"."); - if (dot!=0) - $0=substr($0,dot+1); - else - next; - s1=substr($0,1,1); -} -if (s1==".") -{fin=substr($0,2);} -else{fin=$0;} -if (index(fin,".")==0) next; -if (index(fin,"%")!=0) next; -if (index(fin,":")!=0) next; -match(fin,"^[0-9\.]+") -if (RSTART==1 && RLENGTH==length(fin)) {print "ipset add gfwlist "fin>"/tmp/doipset.sh";next;} -if (fin=="" || finl==fin) next; -finl=fin; -if (white==0) - {print(" - '\''[/"fin"/]"upst"'\''");} -else{ - print(" - '\''[/"fin"/]#'\''");} -}END{print(" - '\''[/programaddend/]#'\''")}' > /tmp/adguard.list -grep programaddstart $configpath -if [ "$?" == "0" ]; then - sed -i '/programaddstart/,/programaddend/c\ - '\''\[\/programaddstart\/\]#'\''' $configpath - sed -i '/programaddstart/'r/tmp/adguard.list $configpath -else - sed -i '1i\ - '\''[/programaddstart/]#'\''' /tmp/adguard.list - sed -i '/upstream_dns:/'r/tmp/adguard.list $configpath -fi -checkmd5 "$2" -rm -f /tmp/gfwlist.txt /tmp/adguard.list \ No newline at end of file diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/links.txt b/luci-app-adguardhome/root/usr/share/AdGuardHome/links.txt deleted file mode 100755 index e97fd9a8e..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/links.txt +++ /dev/null @@ -1,4 +0,0 @@ -https://github.com/AdguardTeam/AdGuardHome/releases/download/${Cloud_Version}/AdGuardHome_linux_${Arch}.tar.gz -https://hub.fastgit.xyz/AdguardTeam/AdGuardHome/releases/download/${Cloud_Version}/AdGuardHome_linux_${Arch}.tar.gz -#https://static.adguard.com/adguardhome/release/AdGuardHome_linux_${Arch}.tar.gz -#https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_${Arch}.tar.gz diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/tailto.sh b/luci-app-adguardhome/root/usr/share/AdGuardHome/tailto.sh deleted file mode 100755 index ab70e3a6e..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/tailto.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -tail -n $1 "$2" > /var/run/tailtmp -cat /var/run/tailtmp > "$2" -rm /var/run/tailtmp \ No newline at end of file diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/update_core.sh b/luci-app-adguardhome/root/usr/share/AdGuardHome/update_core.sh deleted file mode 100755 index 0c275743e..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/update_core.sh +++ /dev/null @@ -1,217 +0,0 @@ -#!/bin/bash - -PATH="/usr/sbin:/usr/bin:/sbin:/bin" -update_mode=$1 -binpath=$(uci get AdGuardHome.AdGuardHome.binpath) -if [[ -z ${binpath} ]]; then - uci set AdGuardHome.AdGuardHome.binpath="/tmp/AdGuardHome/AdGuardHome" - binpath="/tmp/AdGuardHome/AdGuardHome" -fi -[[ ! -d ${binpath%/*} ]] && mkdir -p ${binpath%/*} -upxflag=$(uci get AdGuardHome.AdGuardHome.upxflag 2>/dev/null) -[[ -z ${upxflag} ]] && upxflag=off -enabled=$(uci get AdGuardHome.AdGuardHome.enabled 2>/dev/null) -core_version=$(uci get AdGuardHome.AdGuardHome.core_version 2>/dev/null) -update_url=$(uci get AdGuardHome.AdGuardHome.update_url 2>/dev/null) - -case "${core_version}" in -beta) - core_api_url=https://api.github.com/repos/AdguardTeam/AdGuardHome/releases -;; -*) - core_api_url=https://api.github.com/repos/AdguardTeam/AdGuardHome/releases/latest -;; -esac - -Check_Task(){ - running_tasks="$(ps -efww | grep -v grep | grep "AdGuardHome" | grep "update_core" | awk '{print $1}' | wc -l)" - case $1 in - force) - echo -e "执行: 强制更新核心" - echo -e "清除 ${running_tasks} 个进程 ..." - ps -efww | grep -v grep | grep -v $$ | grep "AdGuardHome" | grep "update_core" | awk '{print $1}' | xargs kill -9 2> /dev/null - ;; - *) - [[ ${running_tasks} -gt 2 ]] && echo -e "已经有 ${running_tasks} 个任务正在运行, 请等待其执行结束或将其强行停止!" && EXIT 2 - ;; - esac -} - -Check_Downloader(){ - which curl > /dev/null 2>&1 && PKG="curl" && return - echo -e "\n未安装 curl" - which wget-ssl > /dev/null 2>&1 && PKG="wget-ssl" && return - echo "未安装 curl 和 wget, 无法检测更新!" && EXIT 1 -} - -Check_Updates(){ - Check_Downloader - case "${PKG}" in - curl) - Downloader="curl -L -k -o" - _Downloader="curl -s" - ;; - wget-ssl) - Downloader="wget-ssl --no-check-certificate -T 5 -O" - _Downloader="wget-ssl -q -O -" - ;; - esac - echo "[${PKG}] 开始检查更新, 请耐心等待 ..." - Cloud_Version="$(${_Downloader} ${core_api_url} 2>/dev/null | grep 'tag_name' | egrep -o "v[0-9].+[0-9.]" | awk 'NR==1')" - [[ -z ${Cloud_Version} ]] && echo -e "\n检查更新失败, 请检查网络或稍后重试!" && EXIT 1 - if [[ -f ${binpath} ]]; then - Current_Version="$(${binpath} --version 2>/dev/null | egrep -o "v[0-9].+[0-9]" | sed -r 's/(.*), c(.*)/\1/')" - else - Current_Version="未知" - fi - [[ -z ${Current_Version} ]] && Current_Version="未知" - echo -e "\n执行文件路径: ${binpath%/*}\n\n正在检查更新, 请耐心等待 ..." - echo -e "\n当前 AdGuardHome 版本: ${Current_Version}\n云端 AdGuardHome 版本: ${Cloud_Version}" - if [[ ! "${Cloud_Version}" == "${Current_Version}" || "$1" == force ]]; then - Update_Core - else - echo -e "\n已是最新版本, 无需更新!" - EXIT 0 - fi - EXIT 0 -} - -UPX_Compress(){ - GET_Arch - upx_name="upx-${upx_latest_ver}-${Arch_upx}_linux.tar.xz" - echo -e "开始下载 ${upx_name} ...\n" - $Downloader /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux.tar.xz "https://github.com/upx/upx/releases/download/v${upx_latest_ver}/${upx_name}" - if [[ ! -e /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux.tar.xz ]]; then - echo -e "\n${upx_name} 下载失败!\n" - EXIT 1 - else - echo -e "\n${upx_name} 下载成功!\n" - fi - which xz > /dev/null 2>&1 || (opkg list | grep ^xz || opkg update > /dev/null 2>&1 && opkg install xz --force-depends) || (echo "软件包 xz 安装失败!" && EXIT 1) - mkdir -p /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux - echo -e "正在解压 ${upx_name} ...\n" - xz -d -c /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux.tar.xz | tar -x -C "/tmp" - [[ ! -f /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux/upx ]] && echo -e "\n${upx_name} 解压失败!" && EXIT 1 -} - -Update_Core(){ - rm -r /tmp/AdGuardHome_Update > /dev/null 2>&1 - mkdir -p "/tmp/AdGuardHome_Update" - GET_Arch - eval link="${update_url}" - echo -e "下载链接:${link}" - echo -e "文件名称:${link##*/}" - echo -e "\n开始下载 AdGuardHome 核心文件 ...\n" - $Downloader /tmp/AdGuardHome_Update/${link##*/} ${link} - if [[ $? != 0 ]];then - echo -e "\nAdGuardHome 核心下载失败 ..." - rm -r /tmp/AdGuardHome_Update - EXIT 1 - fi - if [[ ${link##*.} == gz ]]; then - echo -e "\n正在解压 AdGuardHome ..." - tar -zxf "/tmp/AdGuardHome_Update/${link##*/}" -C "/tmp/AdGuardHome_Update/" - if [[ ! -e /tmp/AdGuardHome_Update/AdGuardHome ]] - then - echo "AdGuardHome 核心解压失败!" - rm -rf "/tmp/AdGuardHome_Update" > /dev/null 2>&1 - EXIT 1 - fi - downloadbin="/tmp/AdGuardHome_Update/AdGuardHome/AdGuardHome" - else - downloadbin="/tmp/AdGuardHome_Update/${link##*/}" - fi - chmod +x ${downloadbin} - echo -e "\nAdGuardHome 核心体积: $(awk 'BEGIN{printf "%.2fMB\n",'$((`ls -l $downloadbin | awk '{print $5}'`))'/1000000}')" - if [[ ${upxflag} != off ]]; then - UPX_Compress - echo -e "使用 UPX 压缩可能会花很长时间, 期间请耐心等待!\n正在压缩 $downloadbin ..." - /tmp/upx-${upx_latest_ver}-${Arch_upx}_linux/upx $upxflag $downloadbin > /dev/null 2>&1 - echo -e "\n压缩后的核心体积: $(awk 'BEGIN{printf "%.2fMB\n",'$((`ls -l $downloadbin | awk '{print $5}'`))'/1000000}')" - else - echo "未启用 UPX 压缩, 跳过操作..." - fi - /etc/init.d/AdGuardHome stop > /dev/null 2>&1 - echo -e "\n移动 AdGuardHome 核心文件到 ${binpath%/*} ..." - mv -f ${downloadbin} ${binpath} > /dev/null 2>&1 - if [[ ! -s ${binpath} && $? != 0 ]]; then - echo -e "AdGuardHome 核心移动失败!\n可能是设备空间不足导致, 请尝试开启 UPX 压缩, 或更改 [执行文件路径] 为 /tmp/AdGuardHome" - EXIT 1 - fi - rm -f /tmp/upx*.tar.xz - rm -rf /tmp/upx* - rm -rf /tmp/AdGuardHome_Update - chmod +x ${binpath} - if [[ ${enabled} == 1 ]]; then - echo -e "\n正在重启 AdGuardHome 服务..." - /etc/init.d/AdGuardHome restart - fi - echo -e "\nAdGuardHome 核心更新成功!" -} - -GET_Arch() { - Archt="$(opkg info kernel | grep Architecture | awk -F "[ _]" '{print($2)}')" - case "${Archt}" in - i386) - Arch=i386 - ;; - i686) - Arch=i386 - ;; - x86) - Arch=amd64 - ;; - mipsel) - Arch=mipsle_softfloat - ;; - mips) - Arch=mips_softfloat - ;; - mips64el) - Arch=mips64le_softfloat - ;; - mips64) - Arch=mips64_softfloat - ;; - arm) - Arch=arm - ;; - armeb) - Arch=armeb - ;; - aarch64) - Arch=arm64 - ;; - *) - echo -e "\nAdGuardHome 暂不支持当前的设备架构: [${Archt}]!" - EXIT 1 - esac - case "${Archt}" in - mipsel) - Arch_upx="mipsel" - upx_latest_ver="3.95" - ;; - *) - Arch_upx="${Arch}" - upx_latest_ver="$(${_Downloader} https://api.github.com/repos/upx/upx/releases/latest 2>/dev/null | egrep 'tag_name' | egrep '[0-9.]+' -o 2>/dev/null)" - - esac - echo -e "\n当前设备架构: ${Arch}\n" -} - -EXIT(){ - rm -rf /var/run/update_core 2>/dev/null - [[ $1 != 0 ]] && touch /var/run/update_core_error - exit $1 -} - -main(){ - Check_Task ${update_mode} - Check_Updates ${update_mode} -} - -trap "EXIT 1" SIGTERM SIGINT -touch /var/run/update_core -rm - rf /var/run/update_core_error 2>/dev/null - -main diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/waitnet.sh b/luci-app-adguardhome/root/usr/share/AdGuardHome/waitnet.sh deleted file mode 100755 index d3d43d0df..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/waitnet.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -PATH="/usr/sbin:/usr/bin:/sbin:/bin" -count=0 -while : -do - ping -c 1 -W 1 -q www.baidu.com 1>/dev/null 2>&1 - if [ "$?" == 0 ]; then - /etc/init.d/AdGuardHome force_reload - break - fi - ping -c 1 -W 1 -q 223.5.5.5 1>/dev/null 2>&1 - if [ "$?" == 0 ]; then - /etc/init.d/AdGuardHome force_reload - break - fi - sleep 5 - ping -c 1 -W 1 -q www.github.com 1>/dev/null 2>&1 - if [ "$?" == 0 ]; then - /etc/init.d/AdGuardHome force_reload - break - fi - ping -c 1 -W 1 -q 8.8.8.8 1>/dev/null 2>&1 - if [ "$?" == 0 ]; then - /etc/init.d/AdGuardHome force_reload - break - fi - sleep 5 - count=$((count+1)) - if [ $count -gt 18 ]; then - /etc/init.d/AdGuardHome force_reload - break - fi -done -return 0 diff --git a/luci-app-adguardhome/root/usr/share/AdGuardHome/watchconfig.sh b/luci-app-adguardhome/root/usr/share/AdGuardHome/watchconfig.sh deleted file mode 100755 index c5252250b..000000000 --- a/luci-app-adguardhome/root/usr/share/AdGuardHome/watchconfig.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -PATH="/usr/sbin:/usr/bin:/sbin:/bin" -configpath=$(uci get AdGuardHome.AdGuardHome.configpath) -while : -do - sleep 10 - if [ -f "$configpath" ]; then - /etc/init.d/AdGuardHome do_redirect 1 - break - fi -done -return 0 \ No newline at end of file diff --git a/luci-app-adguardhome/root/usr/share/rpcd/acl.d/luci-app-adguardhome.json b/luci-app-adguardhome/root/usr/share/rpcd/acl.d/luci-app-adguardhome.json deleted file mode 100755 index 485aa6205..000000000 --- a/luci-app-adguardhome/root/usr/share/rpcd/acl.d/luci-app-adguardhome.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "luci-app-adguardhome": { - "description": "Grant UCI access for luci-app-adguardhome", - "read": { - "uci": [ "AdGuardHome" ] - }, - "write": { - "uci": [ "AdGuardHome" ] - } - } -} diff --git a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/foldcode.js b/luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/foldcode.js deleted file mode 100755 index f93d42b7f..000000000 --- a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/addon/fold/foldcode.js +++ /dev/null @@ -1 +0,0 @@ -!function(n){"object"==typeof exports&&"object"==typeof module?n(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],n):n(CodeMirror)}(function(n){"use strict";function e(e,o,i,t){if(i&&i.call){var l=i;i=null}else l=r(e,i,"rangeFinder");"number"==typeof o&&(o=n.Pos(o,0));var f=r(e,i,"minFoldSize");function d(n){var r=l(e,o);if(!r||r.to.line-r.from.linee.firstLine();)o=n.Pos(o.line-1,0),u=d(!1);if(u&&!u.cleared&&"unfold"!==t){var a=function(n,e){var o=r(n,e,"widget");if("string"==typeof o){var i=document.createTextNode(o);(o=document.createElement("span")).appendChild(i),o.className="CodeMirror-foldmarker"}else o&&(o=o.cloneNode(!0));return o}(e,i);n.on(a,"mousedown",function(e){c.clear(),n.e_preventDefault(e)});var c=e.markText(u.from,u.to,{replacedWith:a,clearOnEnter:r(e,i,"clearOnEnter"),__isFold:!0});c.on("clear",function(o,r){n.signal(e,"unfold",e,o,r)}),n.signal(e,"fold",e,u.from,u.to)}}n.newFoldFunction=function(n,o){return function(r,i){e(r,i,{rangeFinder:n,widget:o})}},n.defineExtension("foldCode",function(n,o,r){e(this,n,o,r)}),n.defineExtension("isFolded",function(n){for(var e=this.findMarksAt(n),o=0;o=u){if(s&&f&&s.test(f.className))return;i=r(a.indicatorOpen)}}(i||f)&&t.setGutterMarker(n,a.gutter,i)})}function i(t){return new RegExp("(^|\\s)"+t+"(?:$|\\s)\\s*")}function f(t){var o=t.getViewport(),e=t.state.foldGutter;e&&(t.operation(function(){n(t,o.from,o.to)}),e.from=o.from,e.to=o.to)}function a(t,r,n){var i=t.state.foldGutter;if(i){var f=i.options;if(n==f.gutter){var a=e(t,r);a?a.clear():t.foldCode(o(r,0),f)}}}function d(t){var o=t.state.foldGutter;if(o){var e=o.options;o.from=o.to=0,clearTimeout(o.changeUpdate),o.changeUpdate=setTimeout(function(){f(t)},e.foldOnChangeTimeSpan||600)}}function u(t){var o=t.state.foldGutter;if(o){var e=o.options;clearTimeout(o.changeUpdate),o.changeUpdate=setTimeout(function(){var e=t.getViewport();o.from==o.to||e.from-o.to>20||o.from-e.to>20?f(t):t.operation(function(){e.fromo.to&&(n(t,o.to,e.to),o.to=e.to)})},e.updateViewportTimeSpan||400)}}function l(t,o){var e=t.state.foldGutter;if(e){var r=o.line;r>=e.from&&ro))break;r=l}}return r?{from:e.Pos(i.line,t.getLine(i.line).length),to:e.Pos(r,t.getLine(r).length)}:void 0}})}); \ No newline at end of file diff --git a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/lib/codemirror.css b/luci-app-adguardhome/root/www/luci-static/resources/codemirror/lib/codemirror.css deleted file mode 100755 index 43ac1a9fa..000000000 --- a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/lib/codemirror.css +++ /dev/null @@ -1 +0,0 @@ -.CodeMirror{font-family:monospace;height:500px;color:black;direction:ltr}.CodeMirror-lines{padding:4px 0}.CodeMirror pre.CodeMirror-line,.CodeMirror pre.CodeMirror-line-like{padding:0 4px}.CodeMirror-scrollbar-filler,.CodeMirror-gutter-filler{background-color:white}.CodeMirror-gutters{border-right:1px solid #ddd;background-color:#f7f7f7;white-space:nowrap}.CodeMirror-linenumber{padding:0 3px 0 5px;min-width:20px;text-align:right;color:#999;white-space:nowrap}.CodeMirror-guttermarker{color:black}.CodeMirror-guttermarker-subtle{color:#999}.CodeMirror-cursor{border-left:1px solid black;border-right:0;width:0}.CodeMirror div.CodeMirror-secondarycursor{border-left:1px solid silver}.cm-fat-cursor .CodeMirror-cursor{width:auto;border:0 !important;background:#7e7}.cm-fat-cursor div.CodeMirror-cursors{z-index:1}.cm-fat-cursor-mark{background-color:rgba(20,255,20,0.5);-webkit-animation:blink 1.06s steps(1) infinite;-moz-animation:blink 1.06s steps(1) infinite;animation:blink 1.06s steps(1) infinite}.cm-animate-fat-cursor{width:auto;border:0;-webkit-animation:blink 1.06s steps(1) infinite;-moz-animation:blink 1.06s steps(1) infinite;animation:blink 1.06s steps(1) infinite;background-color:#7e7}@-moz-keyframes blink{50%{background-color:transparent}}@-webkit-keyframes blink{50%{background-color:transparent}}@keyframes blink{50%{background-color:transparent}}.cm-tab{display:inline-block;text-decoration:inherit}.CodeMirror-rulers{position:absolute;left:0;right:0;top:-50px;bottom:0;overflow:hidden}.CodeMirror-ruler{border-left:1px solid #ccc;top:0;bottom:0;position:absolute}.cm-s-default .cm-header{color:blue}.cm-s-default .cm-quote{color:#090}.cm-negative{color:#d44}.cm-positive{color:#292}.cm-header,.cm-strong{font-weight:bold}.cm-em{font-style:italic}.cm-link{text-decoration:underline}.cm-strikethrough{text-decoration:line-through}.cm-s-default .cm-keyword{color:#708}.cm-s-default .cm-atom{color:#219}.cm-s-default .cm-number{color:#164}.cm-s-default .cm-def{color:#00f}.cm-s-default .cm-variable-2{color:#05a}.cm-s-default .cm-variable-3,.cm-s-default .cm-type{color:#085}.cm-s-default .cm-comment{color:#a50}.cm-s-default .cm-string{color:#a11}.cm-s-default .cm-string-2{color:#f50}.cm-s-default .cm-meta{color:#555}.cm-s-default .cm-qualifier{color:#555}.cm-s-default .cm-builtin{color:#30a}.cm-s-default .cm-bracket{color:#997}.cm-s-default .cm-tag{color:#170}.cm-s-default .cm-attribute{color:#00c}.cm-s-default .cm-hr{color:#999}.cm-s-default .cm-link{color:#00c}.cm-s-default .cm-error{color:red}.cm-invalidchar{color:red}.CodeMirror-composing{border-bottom:2px solid}div.CodeMirror span.CodeMirror-matchingbracket{color:#0b0}div.CodeMirror span.CodeMirror-nonmatchingbracket{color:#a22}.CodeMirror-matchingtag{background:rgba(255,150,0,.3)}.CodeMirror-activeline-background{background:#e8f2ff}.CodeMirror{position:relative;overflow:hidden;background:white}.CodeMirror-scroll{overflow:scroll !important;margin-bottom:-30px;margin-right:-30px;padding-bottom:30px;height:100%;outline:0;position:relative}.CodeMirror-sizer{position:relative;border-right:30px solid transparent}.CodeMirror-vscrollbar,.CodeMirror-hscrollbar,.CodeMirror-scrollbar-filler,.CodeMirror-gutter-filler{position:absolute;z-index:6;display:none}.CodeMirror-vscrollbar{right:0;top:0;overflow-x:hidden;overflow-y:scroll}.CodeMirror-hscrollbar{bottom:0;left:0;overflow-y:hidden;overflow-x:scroll}.CodeMirror-scrollbar-filler{right:0;bottom:0}.CodeMirror-gutter-filler{left:0;bottom:0}.CodeMirror-gutters{position:absolute;left:0;top:0;min-height:100%;z-index:3}.CodeMirror-gutter{white-space:normal;height:100%;display:inline-block;vertical-align:top;margin-bottom:-30px}.CodeMirror-gutter-wrapper{position:absolute;z-index:4;background:none !important;border:none !important}.CodeMirror-gutter-background{position:absolute;top:0;bottom:0;z-index:4}.CodeMirror-gutter-elt{position:absolute;cursor:default;z-index:4}.CodeMirror-gutter-wrapper ::selection{background-color:transparent}.CodeMirror-gutter-wrapper ::-moz-selection{background-color:transparent}.CodeMirror-lines{cursor:text;min-height:1px}.CodeMirror pre.CodeMirror-line,.CodeMirror pre.CodeMirror-line-like{-moz-border-radius:0;-webkit-border-radius:0;border-radius:0;border-width:0;background:transparent;font-family:inherit;font-size:inherit;margin:0;white-space:pre;word-wrap:normal;line-height:inherit;color:inherit;z-index:2;position:relative;overflow:visible;-webkit-tap-highlight-color:transparent;-webkit-font-variant-ligatures:contextual;font-variant-ligatures:contextual}.CodeMirror-wrap pre.CodeMirror-line,.CodeMirror-wrap pre.CodeMirror-line-like{word-wrap:break-word;white-space:pre-wrap;word-break:normal}.CodeMirror-linebackground{position:absolute;left:0;right:0;top:0;bottom:0;z-index:0}.CodeMirror-linewidget{position:relative;z-index:2;padding:.1px}.CodeMirror-rtl pre{direction:rtl}.CodeMirror-code{outline:0}.CodeMirror-scroll,.CodeMirror-sizer,.CodeMirror-gutter,.CodeMirror-gutters,.CodeMirror-linenumber{-moz-box-sizing:content-box;box-sizing:content-box}.CodeMirror-measure{position:absolute;width:100%;height:0;overflow:hidden;visibility:hidden}.CodeMirror-cursor{position:absolute;pointer-events:none}.CodeMirror-measure pre{position:static}div.CodeMirror-cursors{visibility:hidden;position:relative;z-index:3}div.CodeMirror-dragcursors{visibility:visible}.CodeMirror-focused div.CodeMirror-cursors{visibility:visible}.CodeMirror-selected{background:#d9d9d9}.CodeMirror-focused .CodeMirror-selected{background:#d7d4f0}.CodeMirror-crosshair{cursor:crosshair}.CodeMirror-line::selection,.CodeMirror-line>span::selection,.CodeMirror-line>span>span::selection{background:#d7d4f0}.CodeMirror-line::-moz-selection,.CodeMirror-line>span::-moz-selection,.CodeMirror-line>span>span::-moz-selection{background:#d7d4f0}.cm-searching{background-color:#ffa;background-color:rgba(255,255,0,.4)}.cm-force-border{padding-right:.1px}@media print{.CodeMirror div.CodeMirror-cursors{visibility:hidden}}.cm-tab-wrap-hack:after{content:''}span.CodeMirror-selectedtext{background:0} diff --git a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/lib/codemirror.js b/luci-app-adguardhome/root/www/luci-static/resources/codemirror/lib/codemirror.js deleted file mode 100755 index d01f072ee..000000000 --- a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/lib/codemirror.js +++ /dev/null @@ -1 +0,0 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.CodeMirror=t()}(this,function(){"use strict";var e=navigator.userAgent,t=navigator.platform,r=/gecko\/\d/i.test(e),n=/MSIE \d/.test(e),i=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(e),o=/Edge\/(\d+)/.exec(e),l=n||i||o,s=l&&(n?document.documentMode||6:+(o||i)[1]),a=!o&&/WebKit\//.test(e),u=a&&/Qt\/\d+\.\d+/.test(e),c=!o&&/Chrome\//.test(e),h=/Opera\//.test(e),f=/Apple Computer/.test(navigator.vendor),d=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(e),p=/PhantomJS/.test(e),g=!o&&/AppleWebKit/.test(e)&&/Mobile\/\w+/.test(e),v=/Android/.test(e),m=g||v||/webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(e),y=g||/Mac/.test(t),b=/\bCrOS\b/.test(e),w=/win/i.test(t),x=h&&e.match(/Version\/(\d*\.\d*)/);x&&(x=Number(x[1])),x&&x>=15&&(h=!1,a=!0);var C=y&&(u||h&&(null==x||x<12.11)),S=r||l&&s>=9;function L(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}var k,T=function(e,t){var r=e.className,n=L(t).exec(r);if(n){var i=r.slice(n.index+n[0].length);e.className=r.slice(0,n.index)+(i?n[1]+i:"")}};function M(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function N(e,t){return M(e).appendChild(t)}function O(e,t,r,n){var i=document.createElement(e);if(r&&(i.className=r),n&&(i.style.cssText=n),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o=t)return l+(t-o);l+=s-o,l+=r-l%r,o=s+1}}g?P=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:l&&(P=function(e){try{e.select()}catch(e){}});var R=function(){this.id=null,this.f=null,this.time=0,this.handler=E(this.onTimeout,this)};function B(e,t){for(var r=0;r=t)return n+Math.min(l,t-i);if(i+=o-n,n=o+1,(i+=r-i%r)>=t)return n}}var Y=[""];function _(e){for(;Y.length<=e;)Y.push($(Y)+" ");return Y[e]}function $(e){return e[e.length-1]}function q(e,t){for(var r=[],n=0;n"€"&&(e.toUpperCase()!=e.toLowerCase()||J.test(e))}function te(e,t){return t?!!(t.source.indexOf("\\w")>-1&&ee(e))||t.test(e):ee(e)}function re(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}var ne=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;function ie(e){return e.charCodeAt(0)>=768&&ne.test(e)}function oe(e,t,r){for(;(r<0?t>0:tr?-1:1;;){if(t==r)return t;var i=(t+r)/2,o=n<0?Math.ceil(i):Math.floor(i);if(o==t)return e(o)?t:r;e(o)?r=o:t=o+n}}var se=null;function ae(e,t,r){var n;se=null;for(var i=0;it)return i;o.to==t&&(o.from!=o.to&&"before"==r?n=i:se=i),o.from==t&&(o.from!=o.to&&"before"!=r?n=i:se=i)}return null!=n?n:se}var ue=function(){var e="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",t="nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";var r=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,n=/[stwN]/,i=/[LRr]/,o=/[Lb1n]/,l=/[1n]/;function s(e,t,r){this.level=e,this.from=t,this.to=r}return function(a,u){var c="ltr"==u?"L":"R";if(0==a.length||"ltr"==u&&!r.test(a))return!1;for(var h,f=a.length,d=[],p=0;p-1&&(n[t]=i.slice(0,o).concat(i.slice(o+1)))}}}function ge(e,t){var r=de(e,t);if(r.length)for(var n=Array.prototype.slice.call(arguments,2),i=0;i0}function be(e){e.prototype.on=function(e,t){fe(this,e,t)},e.prototype.off=function(e,t){pe(this,e,t)}}function we(e){e.preventDefault?e.preventDefault():e.returnValue=!1}function xe(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}function Ce(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function Se(e){we(e),xe(e)}function Le(e){return e.target||e.srcElement}function ke(e){var t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),y&&e.ctrlKey&&1==t&&(t=3),t}var Te,Me,Ne=function(){if(l&&s<9)return!1;var e=O("div");return"draggable"in e||"dragDrop"in e}();function Oe(e){if(null==Te){var t=O("span","​");N(e,O("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(Te=t.offsetWidth<=1&&t.offsetHeight>2&&!(l&&s<8))}var r=Te?O("span","​"):O("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return r.setAttribute("cm-text",""),r}function Ae(e){if(null!=Me)return Me;var t=N(e,document.createTextNode("AخA")),r=k(t,0,1).getBoundingClientRect(),n=k(t,1,2).getBoundingClientRect();return M(e),!(!r||r.left==r.right)&&(Me=n.right-r.right<3)}var De,We=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,r=[],n=e.length;t<=n;){var i=e.indexOf("\n",t);-1==i&&(i=e.length);var o=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),l=o.indexOf("\r");-1!=l?(r.push(o.slice(0,l)),t+=l+1):(r.push(o),t=i+1)}return r}:function(e){return e.split(/\r\n?|\n/)},He=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(e){return!1}}:function(e){var t;try{t=e.ownerDocument.selection.createRange()}catch(e){}return!(!t||t.parentElement()!=e)&&0!=t.compareEndPoints("StartToEnd",t)},Fe="oncopy"in(De=O("div"))||(De.setAttribute("oncopy","return;"),"function"==typeof De.oncopy),Pe=null;var Ee={},Ie={};function ze(e){if("string"==typeof e&&Ie.hasOwnProperty(e))e=Ie[e];else if(e&&"string"==typeof e.name&&Ie.hasOwnProperty(e.name)){var t=Ie[e.name];"string"==typeof t&&(t={name:t}),(e=Q(t,e)).name=t.name}else{if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+xml$/.test(e))return ze("application/xml");if("string"==typeof e&&/^[\w\-]+\/[\w\-]+\+json$/.test(e))return ze("application/json")}return"string"==typeof e?{name:e}:e||{name:"null"}}function Re(e,t){t=ze(t);var r=Ee[t.name];if(!r)return Re(e,"text/plain");var n=r(e,t);if(Be.hasOwnProperty(t.name)){var i=Be[t.name];for(var o in i)i.hasOwnProperty(o)&&(n.hasOwnProperty(o)&&(n["_"+o]=n[o]),n[o]=i[o])}if(n.name=t.name,t.helperType&&(n.helperType=t.helperType),t.modeProps)for(var l in t.modeProps)n[l]=t.modeProps[l];return n}var Be={};function Ge(e,t){I(t,Be.hasOwnProperty(e)?Be[e]:Be[e]={})}function Ue(e,t){if(!0===t)return t;if(e.copyState)return e.copyState(t);var r={};for(var n in t){var i=t[n];i instanceof Array&&(i=i.concat([])),r[n]=i}return r}function Ve(e,t){for(var r;e.innerMode&&(r=e.innerMode(t))&&r.mode!=e;)t=r.state,e=r.mode;return r||{mode:e,state:t}}function Ke(e,t,r){return!e.startState||e.startState(t,r)}var je=function(e,t,r){this.pos=this.start=0,this.string=e,this.tabSize=t||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0,this.lineOracle=r};function Xe(e,t){if((t-=e.first)<0||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var r=e;!r.lines;)for(var n=0;;++n){var i=r.children[n],o=i.chunkSize();if(t=e.first&&tr?et(r,Xe(e,r).text.length):function(e,t){var r=e.ch;return null==r||r>t?et(e.line,t):r<0?et(e.line,0):e}(t,Xe(e,t.line).text.length)}function at(e,t){for(var r=[],n=0;n=this.string.length},je.prototype.sol=function(){return this.pos==this.lineStart},je.prototype.peek=function(){return this.string.charAt(this.pos)||void 0},je.prototype.next=function(){if(this.post},je.prototype.eatSpace=function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},je.prototype.skipToEnd=function(){this.pos=this.string.length},je.prototype.skipTo=function(e){var t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0},je.prototype.backUp=function(e){this.pos-=e},je.prototype.column=function(){return this.lastColumnPos0?null:(n&&!1!==t&&(this.pos+=n[0].length),n)}var i=function(e){return r?e.toLowerCase():e};if(i(this.string.substr(this.pos,e.length))==i(e))return!1!==t&&(this.pos+=e.length),!0},je.prototype.current=function(){return this.string.slice(this.start,this.pos)},je.prototype.hideFirstChars=function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}},je.prototype.lookAhead=function(e){var t=this.lineOracle;return t&&t.lookAhead(e)},je.prototype.baseToken=function(){var e=this.lineOracle;return e&&e.baseToken(this.pos)};var ut=function(e,t){this.state=e,this.lookAhead=t},ct=function(e,t,r,n){this.state=t,this.doc=e,this.line=r,this.maxLookAhead=n||0,this.baseTokens=null,this.baseTokenPos=1};function ht(e,t,r,n){var i=[e.state.modeGen],o={};wt(e,t.text,e.doc.mode,r,function(e,t){return i.push(e,t)},o,n);for(var l=r.state,s=function(n){r.baseTokens=i;var s=e.state.overlays[n],a=1,u=0;r.state=!0,wt(e,t.text,s.mode,r,function(e,t){for(var r=a;ue&&i.splice(a,1,e,i[a+1],n),a+=2,u=Math.min(e,n)}if(t)if(s.opaque)i.splice(r,a-r,e,"overlay "+t),a=r+2;else for(;re.options.maxHighlightLength&&Ue(e.doc.mode,n.state),o=ht(e,t,n);i&&(n.state=i),t.stateAfter=n.save(!i),t.styles=o.styles,o.classes?t.styleClasses=o.classes:t.styleClasses&&(t.styleClasses=null),r===e.doc.highlightFrontier&&(e.doc.modeFrontier=Math.max(e.doc.modeFrontier,++e.doc.highlightFrontier))}return t.styles}function dt(e,t,r){var n=e.doc,i=e.display;if(!n.mode.startState)return new ct(n,!0,t);var o=function(e,t,r){for(var n,i,o=e.doc,l=r?-1:t-(e.doc.mode.innerMode?1e3:100),s=t;s>l;--s){if(s<=o.first)return o.first;var a=Xe(o,s-1),u=a.stateAfter;if(u&&(!r||s+(u instanceof ut?u.lookAhead:0)<=o.modeFrontier))return s;var c=z(a.text,null,e.options.tabSize);(null==i||n>c)&&(i=s-1,n=c)}return i}(e,t,r),l=o>n.first&&Xe(n,o-1).stateAfter,s=l?ct.fromSaved(n,l,o):new ct(n,Ke(n.mode),o);return n.iter(o,t,function(r){pt(e,r.text,s);var n=s.line;r.stateAfter=n==t-1||n%5==0||n>=i.viewFrom&&nt.start)return o}throw new Error("Mode "+e.name+" failed to advance stream.")}ct.prototype.lookAhead=function(e){var t=this.doc.getLine(this.line+e);return null!=t&&e>this.maxLookAhead&&(this.maxLookAhead=e),t},ct.prototype.baseToken=function(e){if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=e;)this.baseTokenPos+=2;var t=this.baseTokens[this.baseTokenPos+1];return{type:t&&t.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-e}},ct.prototype.nextLine=function(){this.line++,this.maxLookAhead>0&&this.maxLookAhead--},ct.fromSaved=function(e,t,r){return t instanceof ut?new ct(e,Ue(e.mode,t.state),r,t.lookAhead):new ct(e,Ue(e.mode,t),r)},ct.prototype.save=function(e){var t=!1!==e?Ue(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new ut(t,this.maxLookAhead):t};var mt=function(e,t,r){this.start=e.start,this.end=e.pos,this.string=e.current(),this.type=t||null,this.state=r};function yt(e,t,r,n){var i,o,l=e.doc,s=l.mode,a=Xe(l,(t=st(l,t)).line),u=dt(e,t.line,r),c=new je(a.text,e.options.tabSize,u);for(n&&(o=[]);(n||c.pose.options.maxHighlightLength?(s=!1,l&&pt(e,t,n,h.pos),h.pos=t.length,a=null):a=bt(vt(r,h,n.state,f),o),f){var d=f[0].name;d&&(a="m-"+(a?d+" "+a:d))}if(!s||c!=a){for(;u=t:o.to>t);(n||(n=[])).push(new St(l,o.from,s?null:o.to))}}return n}(r,i,l),a=function(e,t,r){var n;if(e)for(var i=0;i=t:o.to>t)||o.from==t&&"bookmark"==l.type&&(!r||o.marker.insertLeft)){var s=null==o.from||(l.inclusiveLeft?o.from<=t:o.from0&&s)for(var b=0;bt)&&(!r||Wt(r,o.marker)<0)&&(r=o.marker)}return r}function It(e,t,r,n,i){var o=Xe(e,t),l=Ct&&o.markedSpans;if(l)for(var s=0;s=0&&h<=0||c<=0&&h>=0)&&(c<=0&&(a.marker.inclusiveRight&&i.inclusiveLeft?tt(u.to,r)>=0:tt(u.to,r)>0)||c>=0&&(a.marker.inclusiveRight&&i.inclusiveLeft?tt(u.from,n)<=0:tt(u.from,n)<0)))return!0}}}function zt(e){for(var t;t=Ft(e);)e=t.find(-1,!0).line;return e}function Rt(e,t){var r=Xe(e,t),n=zt(r);return r==n?t:qe(n)}function Bt(e,t){if(t>e.lastLine())return t;var r,n=Xe(e,t);if(!Gt(e,n))return t;for(;r=Pt(n);)n=r.find(1,!0).line;return qe(n)+1}function Gt(e,t){var r=Ct&&t.markedSpans;if(r)for(var n=void 0,i=0;it.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}var Xt=function(e,t,r){this.text=e,Ot(this,t),this.height=r?r(this):1};function Yt(e){e.parent=null,Nt(e)}Xt.prototype.lineNo=function(){return qe(this)},be(Xt);var _t={},$t={};function qt(e,t){if(!e||/^\s*$/.test(e))return null;var r=t.addModeClass?$t:_t;return r[e]||(r[e]=e.replace(/\S+/g,"cm-$&"))}function Zt(e,t){var r=A("span",null,null,a?"padding-right: .1px":null),n={pre:A("pre",[r],"CodeMirror-line"),content:r,col:0,pos:0,cm:e,trailingSpace:!1,splitSpaces:e.getOption("lineWrapping")};t.measure={};for(var i=0;i<=(t.rest?t.rest.length:0);i++){var o=i?t.rest[i-1]:t.line,l=void 0;n.pos=0,n.addToken=Jt,Ae(e.display.measure)&&(l=ce(o,e.doc.direction))&&(n.addToken=er(n.addToken,l)),n.map=[],rr(o,n,ft(e,o,t!=e.display.externalMeasured&&qe(o))),o.styleClasses&&(o.styleClasses.bgClass&&(n.bgClass=F(o.styleClasses.bgClass,n.bgClass||"")),o.styleClasses.textClass&&(n.textClass=F(o.styleClasses.textClass,n.textClass||""))),0==n.map.length&&n.map.push(0,0,n.content.appendChild(Oe(e.display.measure))),0==i?(t.measure.map=n.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(n.map),(t.measure.caches||(t.measure.caches=[])).push({}))}if(a){var s=n.content.lastChild;(/\bcm-tab\b/.test(s.className)||s.querySelector&&s.querySelector(".cm-tab"))&&(n.content.className="cm-tab-wrap-hack")}return ge(e,"renderLine",e,t.line,n.pre),n.pre.className&&(n.textClass=F(n.pre.className,n.textClass||"")),n}function Qt(e){var t=O("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function Jt(e,t,r,n,i,o,a){if(t){var u,c=e.splitSpaces?function(e,t){if(e.length>1&&!/ /.test(e))return e;for(var r=t,n="",i=0;iu&&h.from<=u);f++);if(h.to>=c)return e(r,n,i,o,l,s,a);e(r,n.slice(0,h.to-u),i,o,null,s,a),o=null,n=n.slice(h.to-u),u=h.to}}}function tr(e,t,r,n){var i=!n&&r.widgetNode;i&&e.map.push(e.pos,e.pos+t,i),!n&&e.cm.display.input.needsContentAttribute&&(i||(i=e.content.appendChild(document.createElement("span"))),i.setAttribute("cm-marker",r.id)),i&&(e.cm.display.input.setUneditable(i),e.content.appendChild(i)),e.pos+=t,e.trailingSpace=!1}function rr(e,t,r){var n=e.markedSpans,i=e.text,o=0;if(n)for(var l,s,a,u,c,h,f,d=i.length,p=0,g=1,v="",m=0;;){if(m==p){a=u=c=s="",f=null,h=null,m=1/0;for(var y=[],b=void 0,w=0;wp||C.collapsed&&x.to==p&&x.from==p)){if(null!=x.to&&x.to!=p&&m>x.to&&(m=x.to,u=""),C.className&&(a+=" "+C.className),C.css&&(s=(s?s+";":"")+C.css),C.startStyle&&x.from==p&&(c+=" "+C.startStyle),C.endStyle&&x.to==m&&(b||(b=[])).push(C.endStyle,x.to),C.title&&((f||(f={})).title=C.title),C.attributes)for(var S in C.attributes)(f||(f={}))[S]=C.attributes[S];C.collapsed&&(!h||Wt(h.marker,C)<0)&&(h=x)}else x.from>p&&m>x.from&&(m=x.from)}if(b)for(var L=0;L=d)break;for(var T=Math.min(d,m);;){if(v){var M=p+v.length;if(!h){var N=M>T?v.slice(0,T-p):v;t.addToken(t,N,l?l+a:a,c,p+N.length==m?u:"",s,f)}if(M>=T){v=v.slice(T-p),p=T;break}p=M,c=""}v=i.slice(o,o=r[g++]),l=qt(r[g++],t.cm.options)}}else for(var O=1;Or)return{map:e.measure.maps[i],cache:e.measure.caches[i],before:!0}}function Or(e,t,r,n){return Wr(e,Dr(e,t),r,n)}function Ar(e,t){if(t>=e.display.viewFrom&&t=r.lineN&&t2&&o.push((a.bottom+u.top)/2-r.top)}}o.push(r.bottom-r.top)}}(e,t.view,t.rect),t.hasHeights=!0),(o=function(e,t,r,n){var i,o=Pr(t.map,r,n),a=o.node,u=o.start,c=o.end,h=o.collapse;if(3==a.nodeType){for(var f=0;f<4;f++){for(;u&&ie(t.line.text.charAt(o.coverStart+u));)--u;for(;o.coverStart+c1}(e))return t;var r=screen.logicalXDPI/screen.deviceXDPI,n=screen.logicalYDPI/screen.deviceYDPI;return{left:t.left*r,right:t.right*r,top:t.top*n,bottom:t.bottom*n}}(e.display.measure,i))}else{var d;u>0&&(h=n="right"),i=e.options.lineWrapping&&(d=a.getClientRects()).length>1?d["right"==n?d.length-1:0]:a.getBoundingClientRect()}if(l&&s<9&&!u&&(!i||!i.left&&!i.right)){var p=a.parentNode.getClientRects()[0];i=p?{left:p.left,right:p.left+tn(e.display),top:p.top,bottom:p.bottom}:Fr}for(var g=i.top-t.rect.top,v=i.bottom-t.rect.top,m=(g+v)/2,y=t.view.measure.heights,b=0;bt)&&(i=(o=a-s)-1,t>=a&&(l="right")),null!=i){if(n=e[u+2],s==a&&r==(n.insertLeft?"left":"right")&&(l=r),"left"==r&&0==i)for(;u&&e[u-2]==e[u-3]&&e[u-1].insertLeft;)n=e[2+(u-=3)],l="left";if("right"==r&&i==a-s)for(;u=0&&(r=e[i]).left==r.right;i--);return r}function Ir(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(var t=0;t=n.text.length?(a=n.text.length,u="before"):a<=0&&(a=0,u="after"),!s)return l("before"==u?a-1:a,"before"==u);function c(e,t,r){return l(r?e-1:e,1==s[t].level!=r)}var h=ae(s,a,u),f=se,d=c(a,h,"before"==u);return null!=f&&(d.other=c(a,f,"before"!=u)),d}function Yr(e,t){var r=0;t=st(e.doc,t),e.options.lineWrapping||(r=tn(e.display)*t.ch);var n=Xe(e.doc,t.line),i=Vt(n)+Cr(e.display);return{left:r,right:r,top:i,bottom:i+n.height}}function _r(e,t,r,n,i){var o=et(e,t,r);return o.xRel=i,n&&(o.outside=n),o}function $r(e,t,r){var n=e.doc;if((r+=e.display.viewOffset)<0)return _r(n.first,0,null,-1,-1);var i=Ze(n,r),o=n.first+n.size-1;if(i>o)return _r(n.first+n.size-1,Xe(n,o).text.length,null,1,1);t<0&&(t=0);for(var l=Xe(n,i);;){var s=Jr(e,l,i,t,r),a=Et(l,s.ch+(s.xRel>0||s.outside>0?1:0));if(!a)return s;var u=a.find(1);if(u.line==i)return u;l=Xe(n,i=u.line)}}function qr(e,t,r,n){n-=Ur(t);var i=t.text.length,o=le(function(t){return Wr(e,r,t-1).bottom<=n},i,0);return{begin:o,end:i=le(function(t){return Wr(e,r,t).top>n},o,i)}}function Zr(e,t,r,n){return r||(r=Dr(e,t)),qr(e,t,r,Vr(e,t,Wr(e,r,n),"line").top)}function Qr(e,t,r,n){return!(e.bottom<=r)&&(e.top>r||(n?e.left:e.right)>t)}function Jr(e,t,r,n,i){i-=Vt(t);var o=Dr(e,t),l=Ur(t),s=0,a=t.text.length,u=!0,c=ce(t,e.doc.direction);if(c){var h=(e.options.lineWrapping?function(e,t,r,n,i,o,l){var s=qr(e,t,n,l),a=s.begin,u=s.end;/\s/.test(t.text.charAt(u-1))&&u--;for(var c=null,h=null,f=0;f=u||d.to<=a)){var p=1!=d.level,g=Wr(e,n,p?Math.min(u,d.to)-1:Math.max(a,d.from)).right,v=gv)&&(c=d,h=v)}}c||(c=i[i.length-1]);c.fromu&&(c={from:c.from,to:u,level:c.level});return c}:function(e,t,r,n,i,o,l){var s=le(function(s){var a=i[s],u=1!=a.level;return Qr(Xr(e,et(r,u?a.to:a.from,u?"before":"after"),"line",t,n),o,l,!0)},0,i.length-1),a=i[s];if(s>0){var u=1!=a.level,c=Xr(e,et(r,u?a.from:a.to,u?"after":"before"),"line",t,n);Qr(c,o,l,!0)&&c.top>l&&(a=i[s-1])}return a})(e,t,r,o,c,n,i);s=(u=1!=h.level)?h.from:h.to-1,a=u?h.to:h.from-1}var f,d,p=null,g=null,v=le(function(t){var r=Wr(e,o,t);return r.top+=l,r.bottom+=l,!!Qr(r,n,i,!1)&&(r.top<=i&&r.left<=n&&(p=t,g=r),!0)},s,a),m=!1;if(g){var y=n-g.left=w.bottom?1:0}return _r(r,v=oe(t.text,v,1),d,m,n-f)}function en(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Hr){Hr=O("pre",null,"CodeMirror-line-like");for(var t=0;t<49;++t)Hr.appendChild(document.createTextNode("x")),Hr.appendChild(O("br"));Hr.appendChild(document.createTextNode("x"))}N(e.measure,Hr);var r=Hr.offsetHeight/50;return r>3&&(e.cachedTextHeight=r),M(e.measure),r||1}function tn(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=O("span","xxxxxxxxxx"),r=O("pre",[t],"CodeMirror-line-like");N(e.measure,r);var n=t.getBoundingClientRect(),i=(n.right-n.left)/10;return i>2&&(e.cachedCharWidth=i),i||10}function rn(e){for(var t=e.display,r={},n={},i=t.gutters.clientLeft,o=t.gutters.firstChild,l=0;o;o=o.nextSibling,++l){var s=e.display.gutterSpecs[l].className;r[s]=o.offsetLeft+o.clientLeft+i,n[s]=o.clientWidth}return{fixedPos:nn(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:r,gutterWidth:n,wrapperWidth:t.wrapper.clientWidth}}function nn(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function on(e){var t=en(e.display),r=e.options.lineWrapping,n=r&&Math.max(5,e.display.scroller.clientWidth/tn(e.display)-3);return function(i){if(Gt(e.doc,i))return 0;var o=0;if(i.widgets)for(var l=0;l=e.display.viewTo)return null;if((t-=e.display.viewFrom)<0)return null;for(var r=e.display.view,n=0;nt)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Ct&&Rt(e.doc,t)i.viewFrom?hn(e):(i.viewFrom+=n,i.viewTo+=n);else if(t<=i.viewFrom&&r>=i.viewTo)hn(e);else if(t<=i.viewFrom){var o=fn(e,r,r+n,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=n):hn(e)}else if(r>=i.viewTo){var l=fn(e,t,t,-1);l?(i.view=i.view.slice(0,l.index),i.viewTo=l.lineN):hn(e)}else{var s=fn(e,t,t,-1),a=fn(e,r,r+n,1);s&&a?(i.view=i.view.slice(0,s.index).concat(ir(e,s.lineN,a.lineN)).concat(i.view.slice(a.index)),i.viewTo+=n):hn(e)}var u=i.externalMeasured;u&&(r=i.lineN&&t=n.viewTo)){var o=n.view[an(e,t)];if(null!=o.node){var l=o.changes||(o.changes=[]);-1==B(l,r)&&l.push(r)}}}function hn(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function fn(e,t,r,n){var i,o=an(e,t),l=e.display.view;if(!Ct||r==e.doc.first+e.doc.size)return{index:o,lineN:r};for(var s=e.display.viewFrom,a=0;a0){if(o==l.length-1)return null;i=s+l[o].size-t,o++}else i=s-t;t+=i,r+=i}for(;Rt(e.doc,r)!=r;){if(o==(n<0?0:l.length-1))return null;r+=n*l[o-(n<0?1:0)].size,o+=n}return{index:o,lineN:r}}function dn(e){for(var t=e.display.view,r=0,n=0;n=e.display.viewTo||s.to().linet||t==r&&l.to==t)&&(n(Math.max(l.from,t),Math.min(l.to,r),1==l.level?"rtl":"ltr",o),i=!0)}i||n(t,r,"ltr")}(g,r||0,null==n?f:n,function(e,t,i,h){var v="ltr"==i,m=d(e,v?"left":"right"),y=d(t-1,v?"right":"left"),b=null==r&&0==e,w=null==n&&t==f,x=0==h,C=!g||h==g.length-1;if(y.top-m.top<=3){var S=(u?w:b)&&C,L=(u?b:w)&&x?s:(v?m:y).left,k=S?a:(v?y:m).right;c(L,m.top,k-L,m.bottom)}else{var T,M,N,O;v?(T=u&&b&&x?s:m.left,M=u?a:p(e,i,"before"),N=u?s:p(t,i,"after"),O=u&&w&&C?a:y.right):(T=u?p(e,i,"before"):s,M=!u&&b&&x?a:m.right,N=!u&&w&&C?s:y.left,O=u?p(t,i,"after"):a),c(T,m.top,M-T,m.bottom),m.bottom0?t.blinker=setInterval(function(){return t.cursorDiv.style.visibility=(r=!r)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function wn(e){e.state.focused||(e.display.input.focus(),Cn(e))}function xn(e){e.state.delayingBlurEvent=!0,setTimeout(function(){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1,Sn(e))},100)}function Cn(e,t){e.state.delayingBlurEvent&&(e.state.delayingBlurEvent=!1),"nocursor"!=e.options.readOnly&&(e.state.focused||(ge(e,"focus",e,t),e.state.focused=!0,H(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),a&&setTimeout(function(){return e.display.input.reset(!0)},20)),e.display.input.receivedFocus()),bn(e))}function Sn(e,t){e.state.delayingBlurEvent||(e.state.focused&&(ge(e,"blur",e,t),e.state.focused=!1,T(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150))}function Ln(e){for(var t=e.display,r=t.lineDiv.offsetTop,n=0;n.005||f<-.005)&&($e(i.line,a),kn(i.line),i.rest))for(var d=0;de.display.sizerWidth){var p=Math.ceil(u/tn(e.display));p>e.display.maxLineLength&&(e.display.maxLineLength=p,e.display.maxLine=i.line,e.display.maxLineChanged=!0)}}}}function kn(e){if(e.widgets)for(var t=0;t=l&&(o=Ze(t,Vt(Xe(t,a))-e.wrapper.clientHeight),l=a)}return{from:o,to:Math.max(l,o+1)}}function Mn(e,t){var r=e.display,n=en(e.display);t.top<0&&(t.top=0);var i=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:r.scroller.scrollTop,o=Mr(e),l={};t.bottom-t.top>o&&(t.bottom=t.top+o);var s=e.doc.height+Sr(r),a=t.tops-n;if(t.topi+o){var c=Math.min(t.top,(u?s:t.bottom)-o);c!=i&&(l.scrollTop=c)}var h=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:r.scroller.scrollLeft,f=Tr(e)-(e.options.fixedGutter?r.gutters.offsetWidth:0),d=t.right-t.left>f;return d&&(t.right=t.left+f),t.left<10?l.scrollLeft=0:t.leftf+h-3&&(l.scrollLeft=t.right+(d?0:10)-f),l}function Nn(e,t){null!=t&&(Dn(e),e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+t)}function On(e){Dn(e);var t=e.getCursor();e.curOp.scrollToPos={from:t,to:t,margin:e.options.cursorScrollMargin}}function An(e,t,r){null==t&&null==r||Dn(e),null!=t&&(e.curOp.scrollLeft=t),null!=r&&(e.curOp.scrollTop=r)}function Dn(e){var t=e.curOp.scrollToPos;t&&(e.curOp.scrollToPos=null,Wn(e,Yr(e,t.from),Yr(e,t.to),t.margin))}function Wn(e,t,r,n){var i=Mn(e,{left:Math.min(t.left,r.left),top:Math.min(t.top,r.top)-n,right:Math.max(t.right,r.right),bottom:Math.max(t.bottom,r.bottom)+n});An(e,i.scrollLeft,i.scrollTop)}function Hn(e,t){Math.abs(e.doc.scrollTop-t)<2||(r||oi(e,{top:t}),Fn(e,t,!0),r&&oi(e),ei(e,100))}function Fn(e,t,r){t=Math.min(e.display.scroller.scrollHeight-e.display.scroller.clientHeight,t),(e.display.scroller.scrollTop!=t||r)&&(e.doc.scrollTop=t,e.display.scrollbars.setScrollTop(t),e.display.scroller.scrollTop!=t&&(e.display.scroller.scrollTop=t))}function Pn(e,t,r,n){t=Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth),(r?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)&&!n||(e.doc.scrollLeft=t,ai(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function En(e){var t=e.display,r=t.gutters.offsetWidth,n=Math.round(e.doc.height+Sr(e.display));return{clientHeight:t.scroller.clientHeight,viewHeight:t.wrapper.clientHeight,scrollWidth:t.scroller.scrollWidth,clientWidth:t.scroller.clientWidth,viewWidth:t.wrapper.clientWidth,barLeft:e.options.fixedGutter?r:0,docHeight:n,scrollHeight:n+kr(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:r}}var In=function(e,t,r){this.cm=r;var n=this.vert=O("div",[O("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=O("div",[O("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");n.tabIndex=i.tabIndex=-1,e(n),e(i),fe(n,"scroll",function(){n.clientHeight&&t(n.scrollTop,"vertical")}),fe(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,l&&s<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")};In.prototype.update=function(e){var t=e.scrollWidth>e.clientWidth+1,r=e.scrollHeight>e.clientHeight+1,n=e.nativeBarWidth;if(r){this.vert.style.display="block",this.vert.style.bottom=t?n+"px":"0";var i=e.viewHeight-(t?n:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+i)+"px"}else this.vert.style.display="",this.vert.firstChild.style.height="0";if(t){this.horiz.style.display="block",this.horiz.style.right=r?n+"px":"0",this.horiz.style.left=e.barLeft+"px";var o=e.viewWidth-e.barLeft-(r?n:0);this.horiz.firstChild.style.width=Math.max(0,e.scrollWidth-e.clientWidth+o)+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedZeroWidth&&e.clientHeight>0&&(0==n&&this.zeroWidthHack(),this.checkedZeroWidth=!0),{right:r?n:0,bottom:t?n:0}},In.prototype.setScrollLeft=function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")},In.prototype.setScrollTop=function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")},In.prototype.zeroWidthHack=function(){var e=y&&!d?"12px":"18px";this.horiz.style.height=this.vert.style.width=e,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new R,this.disableVert=new R},In.prototype.enableZeroWidthBar=function(e,t,r){e.style.pointerEvents="auto",t.set(1e3,function n(){var i=e.getBoundingClientRect();("vert"==r?document.elementFromPoint(i.right-1,(i.top+i.bottom)/2):document.elementFromPoint((i.right+i.left)/2,i.bottom-1))!=e?e.style.pointerEvents="none":t.set(1e3,n)})},In.prototype.clear=function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)};var zn=function(){};function Rn(e,t){t||(t=En(e));var r=e.display.barWidth,n=e.display.barHeight;Bn(e,t);for(var i=0;i<4&&r!=e.display.barWidth||n!=e.display.barHeight;i++)r!=e.display.barWidth&&e.options.lineWrapping&&Ln(e),Bn(e,En(e)),r=e.display.barWidth,n=e.display.barHeight}function Bn(e,t){var r=e.display,n=r.scrollbars.update(t);r.sizer.style.paddingRight=(r.barWidth=n.right)+"px",r.sizer.style.paddingBottom=(r.barHeight=n.bottom)+"px",r.heightForcer.style.borderBottom=n.bottom+"px solid transparent",n.right&&n.bottom?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=n.bottom+"px",r.scrollbarFiller.style.width=n.right+"px"):r.scrollbarFiller.style.display="",n.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=n.bottom+"px",r.gutterFiller.style.width=t.gutterWidth+"px"):r.gutterFiller.style.display=""}zn.prototype.update=function(){return{bottom:0,right:0}},zn.prototype.setScrollLeft=function(){},zn.prototype.setScrollTop=function(){},zn.prototype.clear=function(){};var Gn={native:In,null:zn};function Un(e){e.display.scrollbars&&(e.display.scrollbars.clear(),e.display.scrollbars.addClass&&T(e.display.wrapper,e.display.scrollbars.addClass)),e.display.scrollbars=new Gn[e.options.scrollbarStyle](function(t){e.display.wrapper.insertBefore(t,e.display.scrollbarFiller),fe(t,"mousedown",function(){e.state.focused&&setTimeout(function(){return e.display.input.focus()},0)}),t.setAttribute("cm-not-content","true")},function(t,r){"horizontal"==r?Pn(e,t):Hn(e,t)},e),e.display.scrollbars.addClass&&H(e.display.wrapper,e.display.scrollbars.addClass)}var Vn=0;function Kn(e){var t;e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:0,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Vn},t=e.curOp,or?or.ops.push(t):t.ownsGroup=or={ops:[t],delayedCallbacks:[]}}function jn(e){var t=e.curOp;t&&function(e,t){var r=e.ownsGroup;if(r)try{!function(e){var t=e.delayedCallbacks,r=0;do{for(;r=r.viewTo)||r.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new ri(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function Yn(e){var t=e.cm,r=t.display;e.updatedDisplay&&Ln(t),e.barMeasure=En(t),r.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Or(t,r.maxLine,r.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(r.scroller.clientWidth,r.sizer.offsetLeft+e.adjustWidthTo+kr(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,r.sizer.offsetLeft+e.adjustWidthTo-Tr(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=r.input.prepareSelection())}function _n(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft(window.innerHeight||document.documentElement.clientHeight)&&(i=!1),null!=i&&!p){var o=O("div","​",null,"position: absolute;\n top: "+(t.top-r.viewOffset-Cr(e.display))+"px;\n height: "+(t.bottom-t.top+kr(e)+r.barHeight)+"px;\n left: "+t.left+"px; width: "+Math.max(2,t.right-t.left)+"px;");e.display.lineSpace.appendChild(o),o.scrollIntoView(i),e.display.lineSpace.removeChild(o)}}}(t,function(e,t,r,n){var i;null==n&&(n=0),e.options.lineWrapping||t!=r||(r="before"==(t=t.ch?et(t.line,"before"==t.sticky?t.ch-1:t.ch,"after"):t).sticky?et(t.line,t.ch+1,"before"):t);for(var o=0;o<5;o++){var l=!1,s=Xr(e,t),a=r&&r!=t?Xr(e,r):s,u=Mn(e,i={left:Math.min(s.left,a.left),top:Math.min(s.top,a.top)-n,right:Math.max(s.left,a.left),bottom:Math.max(s.bottom,a.bottom)+n}),c=e.doc.scrollTop,h=e.doc.scrollLeft;if(null!=u.scrollTop&&(Hn(e,u.scrollTop),Math.abs(e.doc.scrollTop-c)>1&&(l=!0)),null!=u.scrollLeft&&(Pn(e,u.scrollLeft),Math.abs(e.doc.scrollLeft-h)>1&&(l=!0)),!l)break}return i}(t,st(n,e.scrollToPos.from),st(n,e.scrollToPos.to),e.scrollToPos.margin));var i=e.maybeHiddenMarkers,o=e.maybeUnhiddenMarkers;if(i)for(var l=0;l=e.display.viewTo)){var r=+new Date+e.options.workTime,n=dt(e,t.highlightFrontier),i=[];t.iter(n.line,Math.min(t.first+t.size,e.display.viewTo+500),function(o){if(n.line>=e.display.viewFrom){var l=o.styles,s=o.text.length>e.options.maxHighlightLength?Ue(t.mode,n.state):null,a=ht(e,o,n,!0);s&&(n.state=s),o.styles=a.styles;var u=o.styleClasses,c=a.classes;c?o.styleClasses=c:u&&(o.styleClasses=null);for(var h=!l||l.length!=o.styles.length||u!=c&&(!u||!c||u.bgClass!=c.bgClass||u.textClass!=c.textClass),f=0;!h&&fr)return ei(e,e.options.workDelay),!0}),t.highlightFrontier=n.line,t.modeFrontier=Math.max(t.modeFrontier,n.line),i.length&&qn(e,function(){for(var t=0;t=r.viewFrom&&t.visible.to<=r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo)&&r.renderedView==r.view&&0==dn(e))return!1;ui(e)&&(hn(e),t.dims=rn(e));var i=n.first+n.size,o=Math.max(t.visible.from-e.options.viewportMargin,n.first),l=Math.min(i,t.visible.to+e.options.viewportMargin);r.viewFroml&&r.viewTo-l<20&&(l=Math.min(i,r.viewTo)),Ct&&(o=Rt(e.doc,o),l=Bt(e.doc,l));var s=o!=r.viewFrom||l!=r.viewTo||r.lastWrapHeight!=t.wrapperHeight||r.lastWrapWidth!=t.wrapperWidth;!function(e,t,r){var n=e.display;0==n.view.length||t>=n.viewTo||r<=n.viewFrom?(n.view=ir(e,t,r),n.viewFrom=t):(n.viewFrom>t?n.view=ir(e,t,n.viewFrom).concat(n.view):n.viewFromr&&(n.view=n.view.slice(0,an(e,r)))),n.viewTo=r}(e,o,l),r.viewOffset=Vt(Xe(e.doc,r.viewFrom)),e.display.mover.style.top=r.viewOffset+"px";var u=dn(e);if(!s&&0==u&&!t.force&&r.renderedView==r.view&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo))return!1;var c=function(e){if(e.hasFocus())return null;var t=W();if(!t||!D(e.display.lineDiv,t))return null;var r={activeElt:t};if(window.getSelection){var n=window.getSelection();n.anchorNode&&n.extend&&D(e.display.lineDiv,n.anchorNode)&&(r.anchorNode=n.anchorNode,r.anchorOffset=n.anchorOffset,r.focusNode=n.focusNode,r.focusOffset=n.focusOffset)}return r}(e);return u>4&&(r.lineDiv.style.display="none"),function(e,t,r){var n=e.display,i=e.options.lineNumbers,o=n.lineDiv,l=o.firstChild;function s(t){var r=t.nextSibling;return a&&y&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),r}for(var u=n.view,c=n.viewFrom,h=0;h-1&&(d=!1),ur(e,f,c,r)),d&&(M(f.lineNumber),f.lineNumber.appendChild(document.createTextNode(Je(e.options,c)))),l=f.node.nextSibling}else{var p=vr(e,f,c,r);o.insertBefore(p,l)}c+=f.size}for(;l;)l=s(l)}(e,r.updateLineNumbers,t.dims),u>4&&(r.lineDiv.style.display=""),r.renderedView=r.view,function(e){if(e&&e.activeElt&&e.activeElt!=W()&&(e.activeElt.focus(),e.anchorNode&&D(document.body,e.anchorNode)&&D(document.body,e.focusNode))){var t=window.getSelection(),r=document.createRange();r.setEnd(e.anchorNode,e.anchorOffset),r.collapse(!1),t.removeAllRanges(),t.addRange(r),t.extend(e.focusNode,e.focusOffset)}}(c),M(r.cursorDiv),M(r.selectionDiv),r.gutters.style.height=r.sizer.style.minHeight=0,s&&(r.lastWrapHeight=t.wrapperHeight,r.lastWrapWidth=t.wrapperWidth,ei(e,400)),r.updateLineNumbers=null,!0}function ii(e,t){for(var r=t.viewport,n=!0;(n&&e.options.lineWrapping&&t.oldDisplayWidth!=Tr(e)||(r&&null!=r.top&&(r={top:Math.min(e.doc.height+Sr(e.display)-Mr(e),r.top)}),t.visible=Tn(e.display,e.doc,r),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)))&&ni(e,t);n=!1){Ln(e);var i=En(e);pn(e),Rn(e,i),si(e,i),t.force=!1}t.signal(e,"update",e),e.display.viewFrom==e.display.reportedViewFrom&&e.display.viewTo==e.display.reportedViewTo||(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function oi(e,t){var r=new ri(e,t);if(ni(e,r)){Ln(e),ii(e,r);var n=En(e);pn(e),Rn(e,n),si(e,n),r.finish()}}function li(e){var t=e.gutters.offsetWidth;e.sizer.style.marginLeft=t+"px"}function si(e,t){e.display.sizer.style.minHeight=t.docHeight+"px",e.display.heightForcer.style.top=t.docHeight+"px",e.display.gutters.style.height=t.docHeight+e.display.barHeight+kr(e)+"px"}function ai(e){var t=e.display,r=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var n=nn(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=n+"px",l=0;ls.clientWidth,c=s.scrollHeight>s.clientHeight;if(i&&u||o&&c){if(o&&y&&a)e:for(var f=t.target,d=l.view;f!=s;f=f.parentNode)for(var p=0;p=0&&tt(e,n.to())<=0)return r}return-1};var bi=function(e,t){this.anchor=e,this.head=t};function wi(e,t,r){var n=e&&e.options.selectionsMayTouch,i=t[r];t.sort(function(e,t){return tt(e.from(),t.from())}),r=B(t,i);for(var o=1;o0:a>=0){var u=ot(s.from(),l.from()),c=it(s.to(),l.to()),h=s.empty()?l.from()==l.head:s.from()==s.head;o<=r&&--r,t.splice(--o,2,new bi(h?c:u,h?u:c))}}return new yi(t,r)}function xi(e,t){return new yi([new bi(e,t||e)],0)}function Ci(e){return e.text?et(e.from.line+e.text.length-1,$(e.text).length+(1==e.text.length?e.from.ch:0)):e.to}function Si(e,t){if(tt(e,t.from)<0)return e;if(tt(e,t.to)<=0)return Ci(t);var r=e.line+t.text.length-(t.to.line-t.from.line)-1,n=e.ch;return e.line==t.to.line&&(n+=Ci(t).ch-t.to.ch),et(r,n)}function Li(e,t){for(var r=[],n=0;n1&&e.remove(s.line+1,p-1),e.insert(s.line+1,m)}sr(e,"change",e,t)}function Ai(e,t,r){!function e(n,i,o){if(n.linked)for(var l=0;ls-(e.cm?e.cm.options.historyEventDelay:500)||"*"==t.origin.charAt(0)))&&(o=function(e,t){return t?(Pi(e.done),$(e.done)):e.done.length&&!$(e.done).ranges?$(e.done):e.done.length>1&&!e.done[e.done.length-2].ranges?(e.done.pop(),$(e.done)):void 0}(i,i.lastOp==n)))l=$(o.changes),0==tt(t.from,t.to)&&0==tt(t.from,l.to)?l.to=Ci(t):o.changes.push(Fi(e,t));else{var a=$(i.done);for(a&&a.ranges||zi(e.sel,i.done),o={changes:[Fi(e,t)],generation:i.generation},i.done.push(o);i.done.length>i.undoDepth;)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(r),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=s,i.lastOp=i.lastSelOp=n,i.lastOrigin=i.lastSelOrigin=t.origin,l||ge(e,"historyAdded")}function Ii(e,t,r,n){var i=e.history,o=n&&n.origin;r==i.lastSelOp||o&&i.lastSelOrigin==o&&(i.lastModTime==i.lastSelTime&&i.lastOrigin==o||function(e,t,r,n){var i=t.charAt(0);return"*"==i||"+"==i&&r.ranges.length==n.ranges.length&&r.somethingSelected()==n.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}(e,o,$(i.done),t))?i.done[i.done.length-1]=t:zi(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=r,n&&!1!==n.clearRedo&&Pi(i.undone)}function zi(e,t){var r=$(t);r&&r.ranges&&r.equals(e)||t.push(e)}function Ri(e,t,r,n){var i=t["spans_"+e.id],o=0;e.iter(Math.max(e.first,r),Math.min(e.first+e.size,n),function(r){r.markedSpans&&((i||(i=t["spans_"+e.id]={}))[o]=r.markedSpans),++o})}function Bi(e){if(!e)return null;for(var t,r=0;r-1&&($(s)[h]=u[h],delete u[h])}}}return n}function Vi(e,t,r,n){if(n){var i=e.anchor;if(r){var o=tt(t,i)<0;o!=tt(r,i)<0?(i=t,t=r):o!=tt(t,r)<0&&(t=r)}return new bi(i,t)}return new bi(r||t,t)}function Ki(e,t,r,n,i){null==i&&(i=e.cm&&(e.cm.display.shift||e.extend)),$i(e,new yi([Vi(e.sel.primary(),t,r,i)],0),n)}function ji(e,t,r){for(var n=[],i=e.cm&&(e.cm.display.shift||e.extend),o=0;o=t.ch:s.to>t.ch))){if(i&&(ge(a,"beforeCursorEnter"),a.explicitlyCleared)){if(o.markedSpans){--l;continue}break}if(!a.atomic)continue;if(r){var h=a.find(n<0?1:-1),f=void 0;if((n<0?c:u)&&(h=ro(e,h,-n,h&&h.line==t.line?o:null)),h&&h.line==t.line&&(f=tt(h,r))&&(n<0?f<0:f>0))return eo(e,h,t,n,i)}var d=a.find(n<0?-1:1);return(n<0?u:c)&&(d=ro(e,d,n,d.line==t.line?o:null)),d?eo(e,d,t,n,i):null}}return t}function to(e,t,r,n,i){var o=n||1,l=eo(e,t,r,o,i)||!i&&eo(e,t,r,o,!0)||eo(e,t,r,-o,i)||!i&&eo(e,t,r,-o,!0);return l||(e.cantEdit=!0,et(e.first,0))}function ro(e,t,r,n){return r<0&&0==t.ch?t.line>e.first?st(e,et(t.line-1)):null:r>0&&t.ch==(n||Xe(e,t.line)).text.length?t.line0)){var c=[a,1],h=tt(u.from,s.from),f=tt(u.to,s.to);(h<0||!l.inclusiveLeft&&!h)&&c.push({from:u.from,to:s.from}),(f>0||!l.inclusiveRight&&!f)&&c.push({from:s.to,to:u.to}),i.splice.apply(i,c),a+=c.length-3}}return i}(e,t.from,t.to);if(n)for(var i=n.length-1;i>=0;--i)lo(e,{from:n[i].from,to:n[i].to,text:i?[""]:t.text,origin:t.origin});else lo(e,t)}}function lo(e,t){if(1!=t.text.length||""!=t.text[0]||0!=tt(t.from,t.to)){var r=Li(e,t);Ei(e,t,r,e.cm?e.cm.curOp.id:NaN),uo(e,t,r,Tt(e,t));var n=[];Ai(e,function(e,r){r||-1!=B(n,e.history)||(po(e.history,t),n.push(e.history)),uo(e,t,null,Tt(e,t))})}}function so(e,t,r){var n=e.cm&&e.cm.state.suppressEdits;if(!n||r){for(var i,o=e.history,l=e.sel,s="undo"==t?o.done:o.undone,a="undo"==t?o.undone:o.done,u=0;u=0;--d){var p=f(d);if(p)return p.v}}}}function ao(e,t){if(0!=t&&(e.first+=t,e.sel=new yi(q(e.sel.ranges,function(e){return new bi(et(e.anchor.line+t,e.anchor.ch),et(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm)){un(e.cm,e.first,e.first-t,t);for(var r=e.cm.display,n=r.viewFrom;ne.lastLine())){if(t.from.lineo&&(t={from:t.from,to:et(o,Xe(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=Ye(e,t.from,t.to),r||(r=Li(e,t)),e.cm?function(e,t,r){var n=e.doc,i=e.display,o=t.from,l=t.to,s=!1,a=o.line;e.options.lineWrapping||(a=qe(zt(Xe(n,o.line))),n.iter(a,l.line+1,function(e){if(e==i.maxLine)return s=!0,!0}));n.sel.contains(t.from,t.to)>-1&&me(e);Oi(n,t,r,on(e)),e.options.lineWrapping||(n.iter(a,o.line+t.text.length,function(e){var t=Kt(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,s=!1)}),s&&(e.curOp.updateMaxLine=!0));(function(e,t){if(e.modeFrontier=Math.min(e.modeFrontier,t),!(e.highlightFrontierr;n--){var i=Xe(e,n).stateAfter;if(i&&(!(i instanceof ut)||n+i.lookAhead1||!(this.children[0]instanceof vo))){var s=[];this.collapse(s),this.children=[new vo(s)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t50){for(var l=i.lines.length%25+25,s=l;s10);e.parent.maybeSpill()}},iterN:function(e,t,r){for(var n=0;n0||0==l&&!1!==o.clearWhenEmpty)return o;if(o.replacedWith&&(o.collapsed=!0,o.widgetNode=A("span",[o.replacedWith],"CodeMirror-widget"),n.handleMouseEvents||o.widgetNode.setAttribute("cm-ignore-events","true"),n.insertLeft&&(o.widgetNode.insertLeft=!0)),o.collapsed){if(It(e,t.line,t,r,o)||t.line!=r.line&&It(e,r.line,t,r,o))throw new Error("Inserting collapsed marker partially overlapping an existing one");Ct=!0}o.addToHistory&&Ei(e,{from:t,to:r,origin:"markText"},e.sel,NaN);var s,a=t.line,u=e.cm;if(e.iter(a,r.line+1,function(e){u&&o.collapsed&&!u.options.lineWrapping&&zt(e)==u.display.maxLine&&(s=!0),o.collapsed&&a!=t.line&&$e(e,0),function(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}(e,new St(o,a==t.line?t.ch:null,a==r.line?r.ch:null)),++a}),o.collapsed&&e.iter(t.line,r.line+1,function(t){Gt(e,t)&&$e(t,0)}),o.clearOnEnter&&fe(o,"beforeCursorEnter",function(){return o.clear()}),o.readOnly&&(xt=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),o.collapsed&&(o.id=++wo,o.atomic=!0),u){if(s&&(u.curOp.updateMaxLine=!0),o.collapsed)un(u,t.line,r.line+1);else if(o.className||o.startStyle||o.endStyle||o.css||o.attributes||o.title)for(var c=t.line;c<=r.line;c++)cn(u,c,"text");o.atomic&&Qi(u.doc),sr(u,"markerAdded",u,o)}return o}xo.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&Kn(e),ye(this,"clear")){var r=this.find();r&&sr(this,"clear",r.from,r.to)}for(var n=null,i=null,o=0;oe.display.maxLineLength&&(e.display.maxLine=u,e.display.maxLineLength=c,e.display.maxLineChanged=!0)}null!=n&&e&&this.collapsed&&un(e,n,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&Qi(e.doc)),e&&sr(e,"markerCleared",e,this,n,i),t&&jn(e),this.parent&&this.parent.clear()}},xo.prototype.find=function(e,t){var r,n;null==e&&"bookmark"==this.type&&(e=1);for(var i=0;i=0;a--)oo(this,n[a]);s?_i(this,s):this.cm&&On(this.cm)}),undo:Jn(function(){so(this,"undo")}),redo:Jn(function(){so(this,"redo")}),undoSelection:Jn(function(){so(this,"undo",!0)}),redoSelection:Jn(function(){so(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,r=0,n=0;n=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(e,t,r){e=st(this,e),t=st(this,t);var n=[],i=e.line;return this.iter(e.line,t.line+1,function(o){var l=o.markedSpans;if(l)for(var s=0;s=a.to||null==a.from&&i!=e.line||null!=a.from&&i==t.line&&a.from>=t.ch||r&&!r(a.marker)||n.push(a.marker.parent||a.marker)}++i}),n},getAllMarks:function(){var e=[];return this.iter(function(t){var r=t.markedSpans;if(r)for(var n=0;ne)return t=e,!0;e-=o,++r}),st(this,et(r,t))},indexFromPos:function(e){var t=(e=st(this,e)).ch;if(e.linet&&(t=e.from),null!=e.to&&e.to-1)return t.state.draggingText(e),void setTimeout(function(){return t.display.input.focus()},20);try{var c=e.dataTransfer.getData("Text");if(c){var h;if(t.state.draggingText&&!t.state.draggingText.copy&&(h=t.listSelections()),qi(t.doc,xi(r,r)),h)for(var f=0;f=0;t--)co(e.doc,"",n[t].from,n[t].to,"+delete");On(e)})}function _o(e,t,r){var n=oe(e.text,t+r,r);return n<0||n>e.text.length?null:n}function $o(e,t,r){var n=_o(e,t.ch,r);return null==n?null:new et(t.line,n,r<0?"after":"before")}function qo(e,t,r,n,i){if(e){var o=ce(r,t.doc.direction);if(o){var l,s=i<0?$(o):o[0],a=i<0==(1==s.level)?"after":"before";if(s.level>0||"rtl"==t.doc.direction){var u=Dr(t,r);l=i<0?r.text.length-1:0;var c=Wr(t,u,l).top;l=le(function(e){return Wr(t,u,e).top==c},i<0==(1==s.level)?s.from:s.to-1,l),"before"==a&&(l=_o(r,l,1))}else l=i<0?s.to:s.from;return new et(n,l,a)}}return new et(n,i<0?r.text.length:0,i<0?"before":"after")}Ro.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite",Esc:"singleSelection"},Ro.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},Ro.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars","Ctrl-O":"openLine"},Ro.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},Ro.default=y?Ro.macDefault:Ro.pcDefault;var Zo={selectAll:no,singleSelection:function(e){return e.setSelection(e.getCursor("anchor"),e.getCursor("head"),V)},killLine:function(e){return Yo(e,function(t){if(t.empty()){var r=Xe(e.doc,t.head.line).text.length;return t.head.ch==r&&t.head.line0)i=new et(i.line,i.ch+1),e.replaceRange(o.charAt(i.ch-1)+o.charAt(i.ch-2),et(i.line,i.ch-2),i,"+transpose");else if(i.line>e.doc.first){var l=Xe(e.doc,i.line-1).text;l&&(i=new et(i.line,1),e.replaceRange(o.charAt(0)+e.doc.lineSeparator()+l.charAt(l.length-1),et(i.line-1,l.length-1),i,"+transpose"))}r.push(new bi(i,i))}e.setSelections(r)})},newlineAndIndent:function(e){return qn(e,function(){for(var t=e.listSelections(),r=t.length-1;r>=0;r--)e.replaceRange(e.doc.lineSeparator(),t[r].anchor,t[r].head,"+input");t=e.listSelections();for(var n=0;n-1&&(tt((i=u.ranges[i]).from(),t)<0||t.xRel>0)&&(tt(i.to(),t)>0||t.xRel<0)?function(e,t,r,n){var i=e.display,o=!1,u=Zn(e,function(t){a&&(i.scroller.draggable=!1),e.state.draggingText=!1,pe(i.wrapper.ownerDocument,"mouseup",u),pe(i.wrapper.ownerDocument,"mousemove",c),pe(i.scroller,"dragstart",h),pe(i.scroller,"drop",u),o||(we(t),n.addNew||Ki(e.doc,r,null,null,n.extend),a||l&&9==s?setTimeout(function(){i.wrapper.ownerDocument.body.focus(),i.input.focus()},20):i.input.focus())}),c=function(e){o=o||Math.abs(t.clientX-e.clientX)+Math.abs(t.clientY-e.clientY)>=10},h=function(){return o=!0};a&&(i.scroller.draggable=!0);e.state.draggingText=u,u.copy=!n.moveOnDrag,i.scroller.dragDrop&&i.scroller.dragDrop();fe(i.wrapper.ownerDocument,"mouseup",u),fe(i.wrapper.ownerDocument,"mousemove",c),fe(i.scroller,"dragstart",h),fe(i.scroller,"drop",u),xn(e),setTimeout(function(){return i.input.focus()},20)}(e,n,t,o):function(e,t,r,n){var i=e.display,o=e.doc;we(t);var l,s,a=o.sel,u=a.ranges;n.addNew&&!n.extend?(s=o.sel.contains(r),l=s>-1?u[s]:new bi(r,r)):(l=o.sel.primary(),s=o.sel.primIndex);if("rectangle"==n.unit)n.addNew||(l=new bi(r,r)),r=sn(e,t,!0,!0),s=-1;else{var c=dl(e,r,n.unit);l=n.extend?Vi(l,c.anchor,c.head,n.extend):c}n.addNew?-1==s?(s=u.length,$i(o,wi(e,u.concat([l]),s),{scroll:!1,origin:"*mouse"})):u.length>1&&u[s].empty()&&"char"==n.unit&&!n.extend?($i(o,wi(e,u.slice(0,s).concat(u.slice(s+1)),0),{scroll:!1,origin:"*mouse"}),a=o.sel):Xi(o,s,l,K):(s=0,$i(o,new yi([l],0),K),a=o.sel);var h=r;function f(t){if(0!=tt(h,t))if(h=t,"rectangle"==n.unit){for(var i=[],u=e.options.tabSize,c=z(Xe(o,r.line).text,r.ch,u),f=z(Xe(o,t.line).text,t.ch,u),d=Math.min(c,f),p=Math.max(c,f),g=Math.min(r.line,t.line),v=Math.min(e.lastLine(),Math.max(r.line,t.line));g<=v;g++){var m=Xe(o,g).text,y=X(m,d,u);d==p?i.push(new bi(et(g,y),et(g,y))):m.length>y&&i.push(new bi(et(g,y),et(g,X(m,p,u))))}i.length||i.push(new bi(r,r)),$i(o,wi(e,a.ranges.slice(0,s).concat(i),s),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var b,w=l,x=dl(e,t,n.unit),C=w.anchor;tt(x.anchor,C)>0?(b=x.head,C=ot(w.from(),x.anchor)):(b=x.anchor,C=it(w.to(),x.head));var S=a.ranges.slice(0);S[s]=function(e,t){var r=t.anchor,n=t.head,i=Xe(e.doc,r.line);if(0==tt(r,n)&&r.sticky==n.sticky)return t;var o=ce(i);if(!o)return t;var l=ae(o,r.ch,r.sticky),s=o[l];if(s.from!=r.ch&&s.to!=r.ch)return t;var a,u=l+(s.from==r.ch==(1!=s.level)?0:1);if(0==u||u==o.length)return t;if(n.line!=r.line)a=(n.line-r.line)*("ltr"==e.doc.direction?1:-1)>0;else{var c=ae(o,n.ch,n.sticky),h=c-l||(n.ch-r.ch)*(1==s.level?-1:1);a=c==u-1||c==u?h<0:h>0}var f=o[u+(a?-1:0)],d=a==(1==f.level),p=d?f.from:f.to,g=d?"after":"before";return r.ch==p&&r.sticky==g?t:new bi(new et(r.line,p,g),n)}(e,new bi(st(o,C),b)),$i(o,wi(e,S,s),K)}}var d=i.wrapper.getBoundingClientRect(),p=0;function g(t){e.state.selectingText=!1,p=1/0,t&&(we(t),i.input.focus()),pe(i.wrapper.ownerDocument,"mousemove",v),pe(i.wrapper.ownerDocument,"mouseup",m),o.history.lastSelOrigin=null}var v=Zn(e,function(t){0!==t.buttons&&ke(t)?function t(r){var l=++p;var s=sn(e,r,!0,"rectangle"==n.unit);if(!s)return;if(0!=tt(s,h)){e.curOp.focus=W(),f(s);var a=Tn(i,o);(s.line>=a.to||s.lined.bottom?20:0;u&&setTimeout(Zn(e,function(){p==l&&(i.scroller.scrollTop+=u,t(r))}),50)}}(t):g(t)}),m=Zn(e,g);e.state.selectingText=m,fe(i.wrapper.ownerDocument,"mousemove",v),fe(i.wrapper.ownerDocument,"mouseup",m)}(e,n,t,o)}(t,n,o,e):Le(e)==r.scroller&&we(e):2==i?(n&&Ki(t.doc,n),setTimeout(function(){return r.input.focus()},20)):3==i&&(S?t.display.input.onContextMenu(e):xn(t)))}}function dl(e,t,r){if("char"==r)return new bi(t,t);if("word"==r)return e.findWordAt(t);if("line"==r)return new bi(et(t.line,0),st(e.doc,et(t.line+1,0)));var n=r(e,t);return new bi(n.from,n.to)}function pl(e,t,r,n){var i,o;if(t.touches)i=t.touches[0].clientX,o=t.touches[0].clientY;else try{i=t.clientX,o=t.clientY}catch(t){return!1}if(i>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;n&&we(t);var l=e.display,s=l.lineDiv.getBoundingClientRect();if(o>s.bottom||!ye(e,r))return Ce(t);o-=s.top-l.viewOffset;for(var a=0;a=i)return ge(e,r,e,Ze(e.doc,o),e.display.gutterSpecs[a].className,t),Ce(t)}}function gl(e,t){return pl(e,t,"gutterClick",!0)}function vl(e,t){xr(e.display,t)||function(e,t){if(!ye(e,"gutterContextMenu"))return!1;return pl(e,t,"gutterContextMenu",!1)}(e,t)||ve(e,t,"contextmenu")||S||e.display.input.onContextMenu(t)}function ml(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),Rr(e)}hl.prototype.compare=function(e,t,r){return this.time+400>e&&0==tt(t,this.pos)&&r==this.button};var yl={toString:function(){return"CodeMirror.Init"}},bl={},wl={};function xl(e,t,r){if(!t!=!(r&&r!=yl)){var n=e.display.dragFunctions,i=t?fe:pe;i(e.display.scroller,"dragstart",n.start),i(e.display.scroller,"dragenter",n.enter),i(e.display.scroller,"dragover",n.over),i(e.display.scroller,"dragleave",n.leave),i(e.display.scroller,"drop",n.drop)}}function Cl(e){e.options.lineWrapping?(H(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(T(e.display.wrapper,"CodeMirror-wrap"),jt(e)),ln(e),un(e),Rr(e),setTimeout(function(){return Rn(e)},100)}function Sl(e,t){var n=this;if(!(this instanceof Sl))return new Sl(e,t);this.options=t=t?I(t):{},I(bl,t,!1);var i=t.value;"string"==typeof i?i=new Mo(i,t.mode,null,t.lineSeparator,t.direction):t.mode&&(i.modeOption=t.mode),this.doc=i;var o=new Sl.inputStyles[t.inputStyle](this),u=this.display=new function(e,t,n,i){var o=this;this.input=n,o.scrollbarFiller=O("div",null,"CodeMirror-scrollbar-filler"),o.scrollbarFiller.setAttribute("cm-not-content","true"),o.gutterFiller=O("div",null,"CodeMirror-gutter-filler"),o.gutterFiller.setAttribute("cm-not-content","true"),o.lineDiv=A("div",null,"CodeMirror-code"),o.selectionDiv=O("div",null,null,"position: relative; z-index: 1"),o.cursorDiv=O("div",null,"CodeMirror-cursors"),o.measure=O("div",null,"CodeMirror-measure"),o.lineMeasure=O("div",null,"CodeMirror-measure"),o.lineSpace=A("div",[o.measure,o.lineMeasure,o.selectionDiv,o.cursorDiv,o.lineDiv],null,"position: relative; outline: none");var u=A("div",[o.lineSpace],"CodeMirror-lines");o.mover=O("div",[u],null,"position: relative"),o.sizer=O("div",[o.mover],"CodeMirror-sizer"),o.sizerWidth=null,o.heightForcer=O("div",null,null,"position: absolute; height: "+G+"px; width: 1px;"),o.gutters=O("div",null,"CodeMirror-gutters"),o.lineGutter=null,o.scroller=O("div",[o.sizer,o.heightForcer,o.gutters],"CodeMirror-scroll"),o.scroller.setAttribute("tabIndex","-1"),o.wrapper=O("div",[o.scrollbarFiller,o.gutterFiller,o.scroller],"CodeMirror"),l&&s<8&&(o.gutters.style.zIndex=-1,o.scroller.style.paddingRight=0),a||r&&m||(o.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(o.wrapper):e(o.wrapper)),o.viewFrom=o.viewTo=t.first,o.reportedViewFrom=o.reportedViewTo=t.first,o.view=[],o.renderedView=null,o.externalMeasured=null,o.viewOffset=0,o.lastWrapHeight=o.lastWrapWidth=0,o.updateLineNumbers=null,o.nativeBarWidth=o.barHeight=o.barWidth=0,o.scrollbarsClipped=!1,o.lineNumWidth=o.lineNumInnerWidth=o.lineNumChars=null,o.alignWidgets=!1,o.cachedCharWidth=o.cachedTextHeight=o.cachedPaddingH=null,o.maxLine=null,o.maxLineLength=0,o.maxLineChanged=!1,o.wheelDX=o.wheelDY=o.wheelStartX=o.wheelStartY=null,o.shift=!1,o.selForContextMenu=null,o.activeTouch=null,o.gutterSpecs=ci(i.gutters,i.lineNumbers),hi(o),n.init(o)}(e,i,o,t);for(var c in u.wrapper.CodeMirror=this,ml(this),t.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),Un(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:-1,cutIncoming:-1,selectingText:!1,draggingText:!1,highlight:new R,keySeq:null,specialChars:null},t.autofocus&&!m&&u.input.focus(),l&&s<11&&setTimeout(function(){return n.display.input.reset(!0)},20),function(e){var t=e.display;fe(t.scroller,"mousedown",Zn(e,fl)),fe(t.scroller,"dblclick",l&&s<11?Zn(e,function(t){if(!ve(e,t)){var r=sn(e,t);if(r&&!gl(e,t)&&!xr(e.display,t)){we(t);var n=e.findWordAt(r);Ki(e.doc,n.anchor,n.head)}}}):function(t){return ve(e,t)||we(t)});fe(t.scroller,"contextmenu",function(t){return vl(e,t)});var r,n={end:0};function i(){t.activeTouch&&(r=setTimeout(function(){return t.activeTouch=null},1e3),(n=t.activeTouch).end=+new Date)}function o(e,t){if(null==t.left)return!0;var r=t.left-e.left,n=t.top-e.top;return r*r+n*n>400}fe(t.scroller,"touchstart",function(i){if(!ve(e,i)&&!function(e){if(1!=e.touches.length)return!1;var t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}(i)&&!gl(e,i)){t.input.ensurePolled(),clearTimeout(r);var o=+new Date;t.activeTouch={start:o,moved:!1,prev:o-n.end<=300?n:null},1==i.touches.length&&(t.activeTouch.left=i.touches[0].pageX,t.activeTouch.top=i.touches[0].pageY)}}),fe(t.scroller,"touchmove",function(){t.activeTouch&&(t.activeTouch.moved=!0)}),fe(t.scroller,"touchend",function(r){var n=t.activeTouch;if(n&&!xr(t,r)&&null!=n.left&&!n.moved&&new Date-n.start<300){var l,s=e.coordsChar(t.activeTouch,"page");l=!n.prev||o(n,n.prev)?new bi(s,s):!n.prev.prev||o(n,n.prev.prev)?e.findWordAt(s):new bi(et(s.line,0),st(e.doc,et(s.line+1,0))),e.setSelection(l.anchor,l.head),e.focus(),we(r)}i()}),fe(t.scroller,"touchcancel",i),fe(t.scroller,"scroll",function(){t.scroller.clientHeight&&(Hn(e,t.scroller.scrollTop),Pn(e,t.scroller.scrollLeft,!0),ge(e,"scroll",e))}),fe(t.scroller,"mousewheel",function(t){return mi(e,t)}),fe(t.scroller,"DOMMouseScroll",function(t){return mi(e,t)}),fe(t.wrapper,"scroll",function(){return t.wrapper.scrollTop=t.wrapper.scrollLeft=0}),t.dragFunctions={enter:function(t){ve(e,t)||Se(t)},over:function(t){ve(e,t)||(!function(e,t){var r=sn(e,t);if(r){var n=document.createDocumentFragment();vn(e,r,n),e.display.dragCursor||(e.display.dragCursor=O("div",null,"CodeMirror-cursors CodeMirror-dragcursors"),e.display.lineSpace.insertBefore(e.display.dragCursor,e.display.cursorDiv)),N(e.display.dragCursor,n)}}(e,t),Se(t))},start:function(t){return function(e,t){if(l&&(!e.state.draggingText||+new Date-No<100))Se(t);else if(!ve(e,t)&&!xr(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.effectAllowed="copyMove",t.dataTransfer.setDragImage&&!f)){var r=O("img",null,null,"position: fixed; left: 0; top: 0;");r.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",h&&(r.width=r.height=1,e.display.wrapper.appendChild(r),r._top=r.offsetTop),t.dataTransfer.setDragImage(r,0,0),h&&r.parentNode.removeChild(r)}}(e,t)},drop:Zn(e,Oo),leave:function(t){ve(e,t)||Ao(e)}};var a=t.input.getField();fe(a,"keyup",function(t){return sl.call(e,t)}),fe(a,"keydown",Zn(e,ll)),fe(a,"keypress",Zn(e,al)),fe(a,"focus",function(t){return Cn(e,t)}),fe(a,"blur",function(t){return Sn(e,t)})}(this),Ho(),Kn(this),this.curOp.forceUpdate=!0,Di(this,i),t.autofocus&&!m||this.hasFocus()?setTimeout(E(Cn,this),20):Sn(this),wl)wl.hasOwnProperty(c)&&wl[c](n,t[c],yl);ui(this),t.finishInit&&t.finishInit(this);for(var d=0;d150)){if(!n)return;r="prev"}}else u=0,r="not";"prev"==r?u=t>o.first?z(Xe(o,t-1).text,null,l):0:"add"==r?u=a+e.options.indentUnit:"subtract"==r?u=a-e.options.indentUnit:"number"==typeof r&&(u=a+r),u=Math.max(0,u);var h="",f=0;if(e.options.indentWithTabs)for(var d=Math.floor(u/l);d;--d)f+=l,h+="\t";if(fl,a=We(t),u=null;if(s&&n.ranges.length>1)if(Tl&&Tl.text.join("\n")==t){if(n.ranges.length%Tl.text.length==0){u=[];for(var c=0;c=0;f--){var d=n.ranges[f],p=d.from(),g=d.to();d.empty()&&(r&&r>0?p=et(p.line,p.ch-r):e.state.overwrite&&!s?g=et(g.line,Math.min(Xe(o,g.line).text.length,g.ch+$(a).length)):s&&Tl&&Tl.lineWise&&Tl.text.join("\n")==t&&(p=g=et(p.line,0)));var v={from:p,to:g,text:u?u[f%u.length]:a,origin:i||(s?"paste":e.state.cutIncoming>l?"cut":"+input")};oo(e.doc,v),sr(e,"inputRead",e,v)}t&&!s&&Al(e,t),On(e),e.curOp.updateInput<2&&(e.curOp.updateInput=h),e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=-1}function Ol(e,t){var r=e.clipboardData&&e.clipboardData.getData("Text");if(r)return e.preventDefault(),t.isReadOnly()||t.options.disableInput||qn(t,function(){return Nl(t,r,0,null,"paste")}),!0}function Al(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var r=e.doc.sel,n=r.ranges.length-1;n>=0;n--){var i=r.ranges[n];if(!(i.head.ch>100||n&&r.ranges[n-1].head.line==i.head.line)){var o=e.getModeAt(i.head),l=!1;if(o.electricChars){for(var s=0;s-1){l=kl(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(Xe(e.doc,i.head.line).text.slice(0,i.head.ch))&&(l=kl(e,i.head.line,"smart"));l&&sr(e,"electricInput",e,i.head.line)}}}function Dl(e){for(var t=[],r=[],n=0;n=t.text.length?(r.ch=t.text.length,r.sticky="before"):r.ch<=0&&(r.ch=0,r.sticky="after");var o=ae(i,r.ch,r.sticky),l=i[o];if("ltr"==e.doc.direction&&l.level%2==0&&(n>0?l.to>r.ch:l.from=l.from&&f>=c.begin)){var d=h?"before":"after";return new et(r.line,f,d)}}var p=function(e,t,n){for(var o=function(e,t){return t?new et(r.line,a(e,1),"before"):new et(r.line,e,"after")};e>=0&&e0==(1!=l.level),u=s?n.begin:a(n.end,-1);if(l.from<=u&&u0?c.end:a(c.begin,-1);return null==v||n>0&&v==t.text.length||!(g=p(n>0?0:i.length-1,n,u(v)))?null:g}(e.cm,s,t,r):$o(s,t,r))){if(n||(l=t.line+r)=e.first+e.size||(t=new et(l,t.ch,t.sticky),!(s=Xe(e,l))))return!1;t=qo(i,e.cm,s,t.line,r)}else t=o;return!0}if("char"==n)a();else if("column"==n)a(!0);else if("word"==n||"group"==n)for(var u=null,c="group"==n,h=e.cm&&e.cm.getHelper(t,"wordChars"),f=!0;!(r<0)||a(!f);f=!1){var d=s.text.charAt(t.ch)||"\n",p=te(d,h)?"w":c&&"\n"==d?"n":!c||/\s/.test(d)?null:"p";if(!c||f||p||(p="s"),u&&u!=p){r<0&&(r=1,a(),t.sticky="after");break}if(p&&(u=p),r>0&&!a(!f))break}var g=to(e,t,o,l,!0);return rt(o,g)&&(g.hitSide=!0),g}function Pl(e,t,r,n){var i,o,l=e.doc,s=t.left;if("page"==n){var a=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),u=Math.max(a-.5*en(e.display),3);i=(r>0?t.bottom:t.top)+r*u}else"line"==n&&(i=r>0?t.bottom+3:t.top-3);for(;(o=$r(e,s,i)).outside;){if(r<0?i<=0:i>=l.height){o.hitSide=!0;break}i+=5*r}return o}var El=function(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new R,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null};function Il(e,t){var r=Ar(e,t.line);if(!r||r.hidden)return null;var n=Xe(e.doc,t.line),i=Nr(r,n,t.line),o=ce(n,e.doc.direction),l="left";o&&(l=ae(o,t.ch)%2?"right":"left");var s=Pr(i.map,t.ch,l);return s.offset="right"==s.collapse?s.end:s.start,s}function zl(e,t){return t&&(e.bad=!0),e}function Rl(e,t,r){var n;if(t==e.display.lineDiv){if(!(n=e.display.lineDiv.childNodes[r]))return zl(e.clipPos(et(e.display.viewTo-1)),!0);t=null,r=0}else for(n=t;;n=n.parentNode){if(!n||n==e.display.lineDiv)return null;if(n.parentNode&&n.parentNode==e.display.lineDiv)break}for(var i=0;i=t.display.viewTo||o.line=t.display.viewFrom&&Il(t,i)||{node:a[0].measure.map[2],offset:0},c=o.linen.firstLine()&&(l=et(l.line-1,Xe(n.doc,l.line-1).length)),s.ch==Xe(n.doc,s.line).text.length&&s.linei.viewTo-1)return!1;l.line==i.viewFrom||0==(e=an(n,l.line))?(t=qe(i.view[0].line),r=i.view[0].node):(t=qe(i.view[e].line),r=i.view[e-1].node.nextSibling);var a,u,c=an(n,s.line);if(c==i.view.length-1?(a=i.viewTo-1,u=i.lineDiv.lastChild):(a=qe(i.view[c+1].line)-1,u=i.view[c+1].node.previousSibling),!r)return!1;for(var h=n.doc.splitLines(function(e,t,r,n,i){var o="",l=!1,s=e.doc.lineSeparator(),a=!1;function u(){l&&(o+=s,a&&(o+=s),l=a=!1)}function c(e){e&&(u(),o+=e)}function h(t){if(1==t.nodeType){var r=t.getAttribute("cm-text");if(r)return void c(r);var o,f=t.getAttribute("cm-marker");if(f){var d=e.findMarks(et(n,0),et(i+1,0),(v=+f,function(e){return e.id==v}));return void(d.length&&(o=d[0].find(0))&&c(Ye(e.doc,o.from,o.to).join(s)))}if("false"==t.getAttribute("contenteditable"))return;var p=/^(pre|div|p|li|table|br)$/i.test(t.nodeName);if(!/^br$/i.test(t.nodeName)&&0==t.textContent.length)return;p&&u();for(var g=0;g1&&f.length>1;)if($(h)==$(f))h.pop(),f.pop(),a--;else{if(h[0]!=f[0])break;h.shift(),f.shift(),t++}for(var d=0,p=0,g=h[0],v=f[0],m=Math.min(g.length,v.length);dl.ch&&y.charCodeAt(y.length-p-1)==b.charCodeAt(b.length-p-1);)d--,p++;h[h.length-1]=y.slice(0,y.length-p).replace(/^\u200b+/,""),h[0]=h[0].slice(d).replace(/\u200b+$/,"");var x=et(t,d),C=et(a,f.length?$(f).length-p:0);return h.length>1||h[0]||tt(x,C)?(co(n.doc,h,x,C,"+input"),!0):void 0},El.prototype.ensurePolled=function(){this.forceCompositionEnd()},El.prototype.reset=function(){this.forceCompositionEnd()},El.prototype.forceCompositionEnd=function(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.updateFromDOM(),this.div.blur(),this.div.focus())},El.prototype.readFromDOMSoon=function(){var e=this;null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout(function(){if(e.readDOMTimeout=null,e.composing){if(!e.composing.done)return;e.composing=null}e.updateFromDOM()},80))},El.prototype.updateFromDOM=function(){var e=this;!this.cm.isReadOnly()&&this.pollContent()||qn(this.cm,function(){return un(e.cm)})},El.prototype.setUneditable=function(e){e.contentEditable="false"},El.prototype.onKeyPress=function(e){0==e.charCode||this.composing||(e.preventDefault(),this.cm.isReadOnly()||Zn(this.cm,Nl)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0))},El.prototype.readOnlyChanged=function(e){this.div.contentEditable=String("nocursor"!=e)},El.prototype.onContextMenu=function(){},El.prototype.resetPosition=function(){},El.prototype.needsContentAttribute=!0;var Gl=function(e){this.cm=e,this.prevInput="",this.pollingFast=!1,this.polling=new R,this.hasSelection=!1,this.composing=null};Gl.prototype.init=function(e){var t=this,r=this,n=this.cm;this.createField(e);var i=this.textarea;function o(e){if(!ve(n,e)){if(n.somethingSelected())Ml({lineWise:!1,text:n.getSelections()});else{if(!n.options.lineWiseCopyCut)return;var t=Dl(n);Ml({lineWise:!0,text:t.text}),"cut"==e.type?n.setSelections(t.ranges,null,V):(r.prevInput="",i.value=t.text.join("\n"),P(i))}"cut"==e.type&&(n.state.cutIncoming=+new Date)}}e.wrapper.insertBefore(this.wrapper,e.wrapper.firstChild),g&&(i.style.width="0px"),fe(i,"input",function(){l&&s>=9&&t.hasSelection&&(t.hasSelection=null),r.poll()}),fe(i,"paste",function(e){ve(n,e)||Ol(e,n)||(n.state.pasteIncoming=+new Date,r.fastPoll())}),fe(i,"cut",o),fe(i,"copy",o),fe(e.scroller,"paste",function(t){if(!xr(e,t)&&!ve(n,t)){if(!i.dispatchEvent)return n.state.pasteIncoming=+new Date,void r.focus();var o=new Event("paste");o.clipboardData=t.clipboardData,i.dispatchEvent(o)}}),fe(e.lineSpace,"selectstart",function(t){xr(e,t)||we(t)}),fe(i,"compositionstart",function(){var e=n.getCursor("from");r.composing&&r.composing.range.clear(),r.composing={start:e,range:n.markText(e,n.getCursor("to"),{className:"CodeMirror-composing"})}}),fe(i,"compositionend",function(){r.composing&&(r.poll(),r.composing.range.clear(),r.composing=null)})},Gl.prototype.createField=function(e){this.wrapper=Hl(),this.textarea=this.wrapper.firstChild},Gl.prototype.prepareSelection=function(){var e=this.cm,t=e.display,r=e.doc,n=gn(e);if(e.options.moveInputWithCursor){var i=Xr(e,r.sel.primary().head,"div"),o=t.wrapper.getBoundingClientRect(),l=t.lineDiv.getBoundingClientRect();n.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,i.top+l.top-o.top)),n.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,i.left+l.left-o.left))}return n},Gl.prototype.showSelection=function(e){var t=this.cm.display;N(t.cursorDiv,e.cursors),N(t.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},Gl.prototype.reset=function(e){if(!this.contextMenuPending&&!this.composing){var t=this.cm;if(t.somethingSelected()){this.prevInput="";var r=t.getSelection();this.textarea.value=r,t.state.focused&&P(this.textarea),l&&s>=9&&(this.hasSelection=r)}else e||(this.prevInput=this.textarea.value="",l&&s>=9&&(this.hasSelection=null))}},Gl.prototype.getField=function(){return this.textarea},Gl.prototype.supportsTouch=function(){return!1},Gl.prototype.focus=function(){if("nocursor"!=this.cm.options.readOnly&&(!m||W()!=this.textarea))try{this.textarea.focus()}catch(e){}},Gl.prototype.blur=function(){this.textarea.blur()},Gl.prototype.resetPosition=function(){this.wrapper.style.top=this.wrapper.style.left=0},Gl.prototype.receivedFocus=function(){this.slowPoll()},Gl.prototype.slowPoll=function(){var e=this;this.pollingFast||this.polling.set(this.cm.options.pollInterval,function(){e.poll(),e.cm.state.focused&&e.slowPoll()})},Gl.prototype.fastPoll=function(){var e=!1,t=this;t.pollingFast=!0,t.polling.set(20,function r(){t.poll()||e?(t.pollingFast=!1,t.slowPoll()):(e=!0,t.polling.set(60,r))})},Gl.prototype.poll=function(){var e=this,t=this.cm,r=this.textarea,n=this.prevInput;if(this.contextMenuPending||!t.state.focused||He(r)&&!n&&!this.composing||t.isReadOnly()||t.options.disableInput||t.state.keySeq)return!1;var i=r.value;if(i==n&&!t.somethingSelected())return!1;if(l&&s>=9&&this.hasSelection===i||y&&/[\uf700-\uf7ff]/.test(i))return t.display.input.reset(),!1;if(t.doc.sel==t.display.selForContextMenu){var o=i.charCodeAt(0);if(8203!=o||n||(n="​"),8666==o)return this.reset(),this.cm.execCommand("undo")}for(var a=0,u=Math.min(n.length,i.length);a1e3||i.indexOf("\n")>-1?r.value=e.prevInput="":e.prevInput=i,e.composing&&(e.composing.range.clear(),e.composing.range=t.markText(e.composing.start,t.getCursor("to"),{className:"CodeMirror-composing"}))}),!0},Gl.prototype.ensurePolled=function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},Gl.prototype.onKeyPress=function(){l&&s>=9&&(this.hasSelection=null),this.fastPoll()},Gl.prototype.onContextMenu=function(e){var t=this,r=t.cm,n=r.display,i=t.textarea;t.contextMenuPending&&t.contextMenuPending();var o=sn(r,e),u=n.scroller.scrollTop;if(o&&!h){r.options.resetSelectionOnContextMenu&&-1==r.doc.sel.contains(o)&&Zn(r,$i)(r.doc,xi(o),V);var c,f=i.style.cssText,d=t.wrapper.style.cssText,p=t.wrapper.offsetParent.getBoundingClientRect();if(t.wrapper.style.cssText="position: static",i.style.cssText="position: absolute; width: 30px; height: 30px;\n top: "+(e.clientY-p.top-5)+"px; left: "+(e.clientX-p.left-5)+"px;\n z-index: 1000; background: "+(l?"rgba(255, 255, 255, .05)":"transparent")+";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",a&&(c=window.scrollY),n.input.focus(),a&&window.scrollTo(null,c),n.input.reset(),r.somethingSelected()||(i.value=t.prevInput=" "),t.contextMenuPending=m,n.selForContextMenu=r.doc.sel,clearTimeout(n.detectingSelectAll),l&&s>=9&&v(),S){Se(e);var g=function(){pe(window,"mouseup",g),setTimeout(m,20)};fe(window,"mouseup",g)}else setTimeout(m,50)}function v(){if(null!=i.selectionStart){var e=r.somethingSelected(),o="​"+(e?i.value:"");i.value="⇚",i.value=o,t.prevInput=e?"":"​",i.selectionStart=1,i.selectionEnd=o.length,n.selForContextMenu=r.doc.sel}}function m(){if(t.contextMenuPending==m&&(t.contextMenuPending=!1,t.wrapper.style.cssText=d,i.style.cssText=f,l&&s<9&&n.scrollbars.setScrollTop(n.scroller.scrollTop=u),null!=i.selectionStart)){(!l||l&&s<9)&&v();var e=0,o=function(){n.selForContextMenu==r.doc.sel&&0==i.selectionStart&&i.selectionEnd>0&&"​"==t.prevInput?Zn(r,no)(r):e++<10?n.detectingSelectAll=setTimeout(o,500):(n.selForContextMenu=null,n.input.reset())};n.detectingSelectAll=setTimeout(o,200)}}},Gl.prototype.readOnlyChanged=function(e){e||this.reset(),this.textarea.disabled="nocursor"==e},Gl.prototype.setUneditable=function(){},Gl.prototype.needsContentAttribute=!1,function(e){var t=e.optionHandlers;function r(r,n,i,o){e.defaults[r]=n,i&&(t[r]=o?function(e,t,r){r!=yl&&i(e,t,r)}:i)}e.defineOption=r,e.Init=yl,r("value","",function(e,t){return e.setValue(t)},!0),r("mode",null,function(e,t){e.doc.modeOption=t,Ti(e)},!0),r("indentUnit",2,Ti,!0),r("indentWithTabs",!1),r("smartIndent",!0),r("tabSize",4,function(e){Mi(e),Rr(e),un(e)},!0),r("lineSeparator",null,function(e,t){if(e.doc.lineSep=t,t){var r=[],n=e.doc.first;e.doc.iter(function(e){for(var i=0;;){var o=e.text.indexOf(t,i);if(-1==o)break;i=o+t.length,r.push(et(n,o))}n++});for(var i=r.length-1;i>=0;i--)co(e.doc,t,r[i],et(r[i].line,r[i].ch+t.length))}}),r("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g,function(e,t,r){e.state.specialChars=new RegExp(t.source+(t.test("\t")?"":"|\t"),"g"),r!=yl&&e.refresh()}),r("specialCharPlaceholder",Qt,function(e){return e.refresh()},!0),r("electricChars",!0),r("inputStyle",m?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),r("spellcheck",!1,function(e,t){return e.getInputField().spellcheck=t},!0),r("autocorrect",!1,function(e,t){return e.getInputField().autocorrect=t},!0),r("autocapitalize",!1,function(e,t){return e.getInputField().autocapitalize=t},!0),r("rtlMoveVisually",!w),r("wholeLineUpdateBefore",!0),r("theme","default",function(e){ml(e),fi(e)},!0),r("keyMap","default",function(e,t,r){var n=Xo(t),i=r!=yl&&Xo(r);i&&i.detach&&i.detach(e,n),n.attach&&n.attach(e,i||null)}),r("extraKeys",null),r("configureMouse",null),r("lineWrapping",!1,Cl,!0),r("gutters",[],function(e,t){e.display.gutterSpecs=ci(t,e.options.lineNumbers),fi(e)},!0),r("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?nn(e.display)+"px":"0",e.refresh()},!0),r("coverGutterNextToScrollbar",!1,function(e){return Rn(e)},!0),r("scrollbarStyle","native",function(e){Un(e),Rn(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),r("lineNumbers",!1,function(e,t){e.display.gutterSpecs=ci(e.options.gutters,t),fi(e)},!0),r("firstLineNumber",1,fi,!0),r("lineNumberFormatter",function(e){return e},fi,!0),r("showCursorWhenSelecting",!1,pn,!0),r("resetSelectionOnContextMenu",!0),r("lineWiseCopyCut",!0),r("pasteLinesPerSelection",!0),r("selectionsMayTouch",!1),r("readOnly",!1,function(e,t){"nocursor"==t&&(Sn(e),e.display.input.blur()),e.display.input.readOnlyChanged(t)}),r("disableInput",!1,function(e,t){t||e.display.input.reset()},!0),r("dragDrop",!0,xl),r("allowDropFileTypes",null),r("cursorBlinkRate",530),r("cursorScrollMargin",0),r("cursorHeight",1,pn,!0),r("singleCursorHeightPerLine",!0,pn,!0),r("workTime",100),r("workDelay",100),r("flattenSpans",!0,Mi,!0),r("addModeClass",!1,Mi,!0),r("pollInterval",100),r("undoDepth",200,function(e,t){return e.doc.history.undoDepth=t}),r("historyEventDelay",1250),r("viewportMargin",10,function(e){return e.refresh()},!0),r("maxHighlightLength",1e4,Mi,!0),r("moveInputWithCursor",!0,function(e,t){t||e.display.input.resetPosition()}),r("tabindex",null,function(e,t){return e.display.input.getField().tabIndex=t||""}),r("autofocus",null),r("direction","ltr",function(e,t){return e.doc.setDirection(t)},!0),r("phrases",null)}(Sl),function(e){var t=e.optionHandlers,r=e.helpers={};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,r){var n=this.options,i=n[e];n[e]==r&&"mode"!=e||(n[e]=r,t.hasOwnProperty(e)&&Zn(this,t[e])(this,r,i),ge(this,"optionChange",this,e))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"](Xo(e))},removeKeyMap:function(e){for(var t=this.state.keyMaps,r=0;rr&&(kl(this,i.head.line,e,!0),r=i.head.line,n==this.doc.sel.primIndex&&On(this));else{var o=i.from(),l=i.to(),s=Math.max(r,o.line);r=Math.min(this.lastLine(),l.line-(l.ch?0:1))+1;for(var a=s;a0&&Xi(this.doc,n,new bi(o,u[n].to()),V)}}}),getTokenAt:function(e,t){return yt(this,e,t)},getLineTokens:function(e,t){return yt(this,et(e),t,!0)},getTokenTypeAt:function(e){e=st(this.doc,e);var t,r=ft(this,Xe(this.doc,e.line)),n=0,i=(r.length-1)/2,o=e.ch;if(0==o)t=r[2];else for(;;){var l=n+i>>1;if((l?r[2*l-1]:0)>=o)i=l;else{if(!(r[2*l+1]o&&(e=o,i=!0),n=Xe(this.doc,e)}else n=e;return Vr(this,n,{top:0,left:0},t||"page",r||i).top+(i?this.doc.height-Vt(n):0)},defaultTextHeight:function(){return en(this.display)},defaultCharWidth:function(){return tn(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,r,n,i){var o,l,s,a=this.display,u=(e=Xr(this,st(this.doc,e))).bottom,c=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),a.sizer.appendChild(t),"over"==n)u=e.top;else if("above"==n||"near"==n){var h=Math.max(a.wrapper.clientHeight,this.doc.height),f=Math.max(a.sizer.clientWidth,a.lineSpace.clientWidth);("above"==n||e.bottom+t.offsetHeight>h)&&e.top>t.offsetHeight?u=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=h&&(u=e.bottom),c+t.offsetWidth>f&&(c=f-t.offsetWidth)}t.style.top=u+"px",t.style.left=t.style.right="","right"==i?(c=a.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?c=0:"middle"==i&&(c=(a.sizer.clientWidth-t.offsetWidth)/2),t.style.left=c+"px"),r&&(o=this,l={left:c,top:u,right:c+t.offsetWidth,bottom:u+t.offsetHeight},null!=(s=Mn(o,l)).scrollTop&&Hn(o,s.scrollTop),null!=s.scrollLeft&&Pn(o,s.scrollLeft))},triggerOnKeyDown:Qn(ll),triggerOnKeyPress:Qn(al),triggerOnKeyUp:sl,triggerOnMouseDown:Qn(fl),execCommand:function(e){if(Zo.hasOwnProperty(e))return Zo[e].call(null,this)},triggerElectric:Qn(function(e){Al(this,e)}),findPosH:function(e,t,r,n){var i=1;t<0&&(i=-1,t=-t);for(var o=st(this.doc,e),l=0;l0&&l(t.charAt(r-1));)--r;for(;n.5)&&ln(this),ge(this,"refresh",this)}),swapDoc:Qn(function(e){var t=this.doc;return t.cm=null,this.state.selectingText&&this.state.selectingText(),Di(this,e),Rr(this),this.display.input.reset(),An(this,e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,sr(this,"swapDoc",this,t),t}),phrase:function(e){var t=this.options.phrases;return t&&Object.prototype.hasOwnProperty.call(t,e)?t[e]:e},getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},be(e),e.registerHelper=function(t,n,i){r.hasOwnProperty(t)||(r[t]=e[t]={_global:[]}),r[t][n]=i},e.registerGlobalHelper=function(t,n,i,o){e.registerHelper(t,n,o),r[t]._global.push({pred:i,val:o})}}(Sl);var Ul="iter insert remove copy getEditor constructor".split(" ");for(var Vl in Mo.prototype)Mo.prototype.hasOwnProperty(Vl)&&B(Ul,Vl)<0&&(Sl.prototype[Vl]=function(e){return function(){return e.apply(this.doc,arguments)}}(Mo.prototype[Vl]));return be(Mo),Sl.inputStyles={textarea:Gl,contenteditable:El},Sl.defineMode=function(e){Sl.defaults.mode||"null"==e||(Sl.defaults.mode=e),function(e,t){arguments.length>2&&(t.dependencies=Array.prototype.slice.call(arguments,2)),Ee[e]=t}.apply(this,arguments)},Sl.defineMIME=function(e,t){Ie[e]=t},Sl.defineMode("null",function(){return{token:function(e){return e.skipToEnd()}}}),Sl.defineMIME("text/plain","null"),Sl.defineExtension=function(e,t){Sl.prototype[e]=t},Sl.defineDocExtension=function(e,t){Mo.prototype[e]=t},Sl.fromTextArea=function(e,t){if((t=t?I(t):{}).value=e.value,!t.tabindex&&e.tabIndex&&(t.tabindex=e.tabIndex),!t.placeholder&&e.placeholder&&(t.placeholder=e.placeholder),null==t.autofocus){var r=W();t.autofocus=r==e||null!=e.getAttribute("autofocus")&&r==document.body}function n(){e.value=s.getValue()}var i;if(e.form&&(fe(e.form,"submit",n),!t.leaveSubmitMethodAlone)){var o=e.form;i=o.submit;try{var l=o.submit=function(){n(),o.submit=i,o.submit(),o.submit=l}}catch(e){}}t.finishInit=function(r){r.save=n,r.getTextArea=function(){return e},r.toTextArea=function(){r.toTextArea=isNaN,n(),e.parentNode.removeChild(r.getWrapperElement()),e.style.display="",e.form&&(pe(e.form,"submit",n),t.leaveSubmitMethodAlone||"function"!=typeof e.form.submit||(e.form.submit=i))}},e.style.display="none";var s=Sl(function(t){return e.parentNode.insertBefore(t,e.nextSibling)},t);return s},function(e){e.off=pe,e.on=fe,e.wheelEventPixels=vi,e.Doc=Mo,e.splitLines=We,e.countColumn=z,e.findColumn=X,e.isWordChar=ee,e.Pass=U,e.signal=ge,e.Line=Xt,e.changeEnd=Ci,e.scrollbarModel=Gn,e.Pos=et,e.cmpPos=tt,e.modes=Ee,e.mimeModes=Ie,e.resolveMode=ze,e.getMode=Re,e.modeExtensions=Be,e.extendMode=Ge,e.copyState=Ue,e.startState=Ke,e.innerMode=Ve,e.commands=Zo,e.keyMap=Ro,e.keyName=jo,e.isModifierKey=Vo,e.lookupKey=Uo,e.normalizeKeyMap=Go,e.StringStream=je,e.SharedTextMarker=So,e.TextMarker=xo,e.LineWidget=yo,e.e_preventDefault=we,e.e_stopPropagation=xe,e.e_stop=Se,e.addClass=H,e.contains=D,e.rmClass=T,e.keyNames=Po}(Sl),Sl.version="5.49.2",Sl}); \ No newline at end of file diff --git a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/mode/yaml/yaml.js b/luci-app-adguardhome/root/www/luci-static/resources/codemirror/mode/yaml/yaml.js deleted file mode 100755 index 4a5e499bf..000000000 --- a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/mode/yaml/yaml.js +++ /dev/null @@ -1 +0,0 @@ -!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("yaml",function(){var e=new RegExp("\\b(("+["true","false","on","off","yes","no"].join(")|(")+"))$","i");return{token:function(i,t){var r=i.peek(),n=t.escaped;if(t.escaped=!1,"#"==r&&(0==i.pos||/\s/.test(i.string.charAt(i.pos-1))))return i.skipToEnd(),"comment";if(i.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))return"string";if(t.literal&&i.indentation()>t.keyCol)return i.skipToEnd(),"string";if(t.literal&&(t.literal=!1),i.sol()){if(t.keyCol=0,t.pair=!1,t.pairStart=!1,i.match(/---/))return"def";if(i.match(/\.\.\./))return"def";if(i.match(/\s*-\s+/))return"meta"}if(i.match(/^(\{|\}|\[|\])/))return"{"==r?t.inlinePairs++:"}"==r?t.inlinePairs--:"["==r?t.inlineList++:t.inlineList--,"meta";if(t.inlineList>0&&!n&&","==r)return i.next(),"meta";if(t.inlinePairs>0&&!n&&","==r)return t.keyCol=0,t.pair=!1,t.pairStart=!1,i.next(),"meta";if(t.pairStart){if(i.match(/^\s*(\||\>)\s*/))return t.literal=!0,"meta";if(i.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i))return"variable-2";if(0==t.inlinePairs&&i.match(/^\s*-?[0-9\.\,]+\s?$/))return"number";if(t.inlinePairs>0&&i.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/))return"number";if(i.match(e))return"keyword"}return!t.pair&&i.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)?(t.pair=!0,t.keyCol=i.indentation(),"atom"):t.pair&&i.match(/^:\s*/)?(t.pairStart=!0,"meta"):(t.pairStart=!1,t.escaped="\\"==r,i.next(),null)},startState:function(){return{pair:!1,pairStart:!1,keyCol:0,inlinePairs:0,inlineList:0,literal:!1,escaped:!1}},lineComment:"#",fold:"indent"}}),e.defineMIME("text/x-yaml","yaml"),e.defineMIME("text/yaml","yaml")}); \ No newline at end of file diff --git a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/theme/dracula.css b/luci-app-adguardhome/root/www/luci-static/resources/codemirror/theme/dracula.css deleted file mode 100755 index 6c708c010..000000000 --- a/luci-app-adguardhome/root/www/luci-static/resources/codemirror/theme/dracula.css +++ /dev/null @@ -1 +0,0 @@ -.cm-s-dracula.CodeMirror,.cm-s-dracula .CodeMirror-gutters{background-color:#282a36 !important;color:#f8f8f2 !important;border:0}.cm-s-dracula .CodeMirror-gutters{color:#282a36}.cm-s-dracula .CodeMirror-cursor{border-left:solid thin #f8f8f0}.cm-s-dracula .CodeMirror-linenumber{color:#6d8a88}.cm-s-dracula .CodeMirror-selected{background:rgba(255,255,255,0.10)}.cm-s-dracula .CodeMirror-line::selection,.cm-s-dracula .CodeMirror-line>span::selection,.cm-s-dracula .CodeMirror-line>span>span::selection{background:rgba(255,255,255,0.10)}.cm-s-dracula .CodeMirror-line::-moz-selection,.cm-s-dracula .CodeMirror-line>span::-moz-selection,.cm-s-dracula .CodeMirror-line>span>span::-moz-selection{background:rgba(255,255,255,0.10)}.cm-s-dracula span.cm-comment{color:#6272a4}.cm-s-dracula span.cm-string,.cm-s-dracula span.cm-string-2{color:#f1fa8c}.cm-s-dracula span.cm-number{color:#bd93f9}.cm-s-dracula span.cm-variable{color:#50fa7b}.cm-s-dracula span.cm-variable-2{color:white}.cm-s-dracula span.cm-def{color:#50fa7b}.cm-s-dracula span.cm-operator{color:#ff79c6}.cm-s-dracula span.cm-keyword{color:#ff79c6}.cm-s-dracula span.cm-atom{color:#bd93f9}.cm-s-dracula span.cm-meta{color:#f8f8f2}.cm-s-dracula span.cm-tag{color:#ff79c6}.cm-s-dracula span.cm-attribute{color:#50fa7b}.cm-s-dracula span.cm-qualifier{color:#50fa7b}.cm-s-dracula span.cm-property{color:#66d9ef}.cm-s-dracula span.cm-builtin{color:#50fa7b}.cm-s-dracula span.cm-variable-3,.cm-s-dracula span.cm-type{color:#ffb86c}.cm-s-dracula .CodeMirror-activeline-background{background:rgba(255,255,255,0.1)}.cm-s-dracula .CodeMirror-matchingbracket{text-decoration:underline;color:white !important} diff --git a/luci-app-adguardhome/root/www/luci-static/resources/twin-bcrypt.min.js b/luci-app-adguardhome/root/www/luci-static/resources/twin-bcrypt.min.js deleted file mode 100755 index 6284357c6..000000000 --- a/luci-app-adguardhome/root/www/luci-static/resources/twin-bcrypt.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/* @license - * Twin-Bcrypt 2.2.0 - * https://github.com/fpirsch/twin-bcrypt - * Licence: BSD-3-Clause - */ -!function(r,n){"use strict";function e(r){return y[g]=t.apply(n,r),g++}function t(r){var e=[].slice.call(arguments,1);return function(){"function"==typeof r?r.apply(n,e):new Function(""+r)()}}function o(r){if(m)setTimeout(t(o,r),0);else{var n=y[r];if(n){m=!0;try{n()}finally{a(r),m=!1}}}}function a(r){delete y[r]}function i(){p=function(){var r=e(arguments);return process.nextTick(t(o,r)),r}}function u(){if(r.postMessage&&!r.importScripts){var n=!0,e=r.onmessage;return r.onmessage=function(){n=!1},r.postMessage("","*"),r.onmessage=e,n}}function f(){var n="setImmediate$"+Math.random()+"$",t=function(e){e.source===r&&"string"==typeof e.data&&0===e.data.indexOf(n)&&o(+e.data.slice(n.length))};r.addEventListener?r.addEventListener("message",t,!1):r.attachEvent("onmessage",t),p=function(){var t=e(arguments);return r.postMessage(n+t,"*"),t}}function c(){var r=new MessageChannel;r.port1.onmessage=function(r){var n=r.data;o(n)},p=function(){var n=e(arguments);return r.port2.postMessage(n),n}}function s(){var r=v.documentElement;p=function(){var n=e(arguments),t=v.createElement("script");return t.onreadystatechange=function(){o(n),t.onreadystatechange=null,r.removeChild(t),t=null},r.appendChild(t),n}}function l(){p=function(){var r=e(arguments);return setTimeout(t(o,r),0),r}}if(!r.setImmediate){var p,g=1,y={},m=!1,v=r.document,d=Object.getPrototypeOf&&Object.getPrototypeOf(r);d=d&&d.setTimeout?d:r,"[object process]"==={}.toString.call(r.process)?i():u()?f():r.MessageChannel?c():v&&"onreadystatechange"in v.createElement("script")?s():l(),d.setImmediate=p,d.clearImmediate=a}}(new Function("return this")()),function(r){"object"==typeof exports?r(exports,require("crypto")):r(self.TwinBcrypt={},self.crypto||self.msCrypto)}(function(r,n){"use strict";function e(r){for(var n=unescape(encodeURIComponent(r)),e=n.length,t=new Array(e),o=0;e>o;o++)t[o]=n.charCodeAt(o);return t}function t(r){for(var n=r.length,e=new Array(n),t=0;n>t;t++)e[t]=r.charCodeAt(t);return e}function o(r,n){for(var e,t,o=0,a="";n>o;){if(e=255&r[o++],a+=B[e>>2],e=(3&e)<<4,o>=n){a+=B[e];break}if(t=255&r[o++],e|=t>>4,a+=B[e],e=(15&t)<<2,o>=n){a+=B[e];break}t=255&r[o++],e|=t>>6,a+=B[e],a+=B[63&t]}return a}function a(r){for(var n,e,t=new Array(16),o=0,a=0;;){if(n=D[r.charCodeAt(o++)-46],e=D[r.charCodeAt(o++)-46],t[a++]=255&(n<<2|e>>4),22===o)break;n=e<<4,e=D[r.charCodeAt(o++)-46],t[a++]=255&(n|e>>2),n=e<<6,e=D[r.charCodeAt(o++)-46],t[a++]=255&(n|e)}return t}function i(r){for(var n=r.length,e=new Array(72),t=0,o=0;72>o;)e[o++]=r[t++],t===n&&(t=0);return e}function u(r,n,e){for(var t=0,o=e>>2;tt;)r[n++]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++]}function c(r){function n(n){for(var e=r,t=G>>2,o=t|O,f=n>>2,c=e[f]^e[t],s=e[1|f];o>t;)s^=(e[c>>>24]+e[a|c>>>16&255]^e[i|c>>>8&255])+e[u|255&c]^e[++t],c^=(e[s>>>24]+e[a|s>>>16&255]^e[i|s>>>8&255])+e[u|255&s]^e[++t];e[f]=s^e[S>>2],e[1|f]=c}function e(n){var e;for(r[L>>2]=0,r[L+4>>2]=0,e=0;M>e;e++)r[G>>2|e]^=r[(n>>2)+e];var t,o,f,c,s,l=r;for(e=0;M>e;e+=2){for(t=G>>2,o=t|O,f=L>>2,c=l[f]^l[t],s=l[1|f];o>t;)s^=(l[c>>>24]+l[a|c>>>16&255]^l[i|c>>>8&255])+l[u|255&c]^l[++t],c^=(l[s>>>24]+l[a|s>>>16&255]^l[i|s>>>8&255])+l[u|255&s]^l[++t];l[f]=s^l[S>>2],l[1|f]=c,r[G>>2|e]=l[f],r[G>>2|e+1]=c}for(e=0;T>e;e+=2){for(t=G>>2,o=t|O,f=L>>2,c=l[f]^l[t],s=l[1|f];o>t;)s^=(l[c>>>24]+l[a|c>>>16&255]^l[i|c>>>8&255])+l[u|255&c]^l[++t],c^=(l[s>>>24]+l[a|s>>>16&255]^l[i|s>>>8&255])+l[u|255&s]^l[++t];l[f]=s^l[S>>2],l[1|f]=c,r[e]=l[f],r[1|e]=c}}function t(r,n,t){for(var o=0;t>=o&&!(r>n);o++)e(R),e(j),r++;return r}var o=k>>2,a=o+256|0,i=a+256|0,u=i+256|0;return{encrypt:n,expandLoop:t}}function s(stdlib, foreign, heap) {"use asm";var HEAP32=new stdlib.Uint32Array(heap);var BLOWFISH_NUM_ROUNDS=16;var S_offset=0x0000;var S1_offset=0x0400;var S2_offset=0x0800;var S3_offset=0x0C00;var P_offset=0x1000;var P_last_offset=0x1044;var crypt_ciphertext_offset=0x1048;var LR_offset=0x01060;var password_offset=0x1068;var salt_offset=0x10b0;var P_LEN=18;var S_LEN=1024;function encrypt(offset) {offset=offset|0;var i=0;var n=0;var L=0;var R=0;var imax=0;imax=P_offset|BLOWFISH_NUM_ROUNDS<<2;L=HEAP32[offset>>2]|0;R=HEAP32[offset+4>>2]|0;L=L^HEAP32[P_offset>>2];for (i=P_offset; (i|0)<(imax|0);) {i=(i+4)>>>0;R=R^(((HEAP32[(L>>>22)>>2]>>>0) +(HEAP32[(S1_offset|(L>>>14&0x3ff))>>2]>>>0) ^(HEAP32[(S2_offset|(L>>>6&0x3ff))>>2])) +(HEAP32[(S3_offset|(L<<2&0x3ff))>>2]>>>0))^HEAP32[i>>2];i=(i+4)>>>0;L=L^(((HEAP32[(R>>>22)>>2]>>>0) +(HEAP32[(S1_offset|(R>>>14&0x3ff))>>2]>>>0) ^(HEAP32[(S2_offset|(R>>>6&0x3ff))>>2])) +(HEAP32[(S3_offset|(R<<2&0x3ff))>>2]>>>0))^HEAP32[i>>2];}HEAP32[offset>>2]=R^HEAP32[P_last_offset>>2];HEAP32[(offset+4)>>2]=L;}function expandKey(offset) {offset=offset|0;var i=0;var off=0;off=P_offset|0;for (i=0; (i|0)<(P_LEN|0); i=(i+1)|0) {HEAP32[off>>2]=HEAP32[off>>2]^HEAP32[offset>>2];offset=(offset+4)|0;off=(off+4)|0;}HEAP32[LR_offset>>2]=0;HEAP32[LR_offset+4>>2]=0;off=P_offset;for (i=0; (i|0)<(P_LEN|0); i=(i+2)|0) {encrypt(LR_offset);HEAP32[off>>2]=HEAP32[LR_offset>>2];HEAP32[off+4>>2]=HEAP32[LR_offset+4>>2];off=(off+8)|0;}off=S_offset;for (i=0; (i|0)<(S_LEN|0); i=(i+2)|0) {encrypt(LR_offset);HEAP32[off>>2]=HEAP32[LR_offset>>2];HEAP32[off+4>>2]=HEAP32[LR_offset+4>>2];off=(off+8)|0;}}function expandLoop(i, counterEnd, maxIterations) {i=i|0;counterEnd=counterEnd|0;maxIterations=maxIterations|0;var j=0;for (j=0; (j|0) <= (maxIterations|0); j=(j+1)|0) {if ((i>>>0)>(counterEnd>>>0)) break;expandKey(password_offset);expandKey(salt_offset);i=(i+1)>>>0;}return i|0;}return {encrypt: encrypt,expandLoop: expandLoop};} -function l(r,n,e,t){var o,a,i,u=L>>2,f=u+1;for(t[u]=0,t[f]=0,a=0,o=0;M>o;o++)i=n[a++]<<24|n[a++]<<16|n[a++]<<8|n[a++],t[G>>2|o]^=i;for(a=0,o=0;M>o;o+=2)i=r[a++]<<24|r[a++]<<16|r[a++]<<8|r[a++],a&=65295,t[u]^=i,i=r[a++]<<24|r[a++]<<16|r[a++]<<8|r[a++],a&=65295,t[f]^=i,e.encrypt(L),t[G>>2|o]=t[u],t[G>>2|o+1]=t[f];var c=k>>2;for(o=0;T>o;o+=2)i=r[a++]<<24|r[a++]<<16|r[a++]<<8|r[a++],a&=65295,t[u]^=i,i=r[a++]<<24|r[a++]<<16|r[a++]<<8|r[a++],a&=65295,t[f]^=i,e.encrypt(L),t[c|o]=t[u],t[c|o+1]=t[f]}function p(r,n,e,t,o,a,i){for(var u=e;t>=u;){if(u=r.expandLoop(u,t,o),a){var f=a(u/(t+1));if(f===!1)return}if(u>t){if(i)return void setImmediate(g.bind(null,r,n,i));return}if(i)return void setImmediate(p.bind(null,r,n,u,t,o,a,i))}}function g(r,n,e){u(n,x,F);var t;for(t=0;64>t;t++)r.encrypt(F+0),r.encrypt(F+8),r.encrypt(F+16);var o,a=0,i=x.length,f=new Array(4*i);for(t=0;i>t;t++)o=n[(F>>2)+t],f[a++]=o>>24,f[a++]=o>>16&255,f[a++]=o>>8&255,f[a++]=255&o;return e&&e(f),f}function y(r,n){return r+o(n,23)}function m(n,o,m,v){var d,h=o.substr(0,29),w=+o.substr(4,2),A=o.substr(7,22);if("string"==typeof n)d=r.encodingMode===r.ENCODING_UTF8?e(n):t(n);else if(Array.isArray(n))d=n.map(function(r){return 255&r});else{if(!(n instanceof Uint8Array))throw new Error("Incorrect arguments");d=Array.prototype.slice.call(n)}d.push(0);var b,E,N=a(A,C),O=31>w?1<>2,N),f(b,R>>2,d),l(N,d,E,b),v?void p(E,b,0,M,T,m,function(r){v(y(h,r))}):(p(E,b,0,M,T,m),y(h,g(E,b)))}function v(r){if(!b)throw new Error("No cryptographically secure pseudorandom number generator available.");if(null==r&&(r=N),r=0|+r,isNaN(r)||4>r||r>31)throw new Error("Invalid cost parameter.");var n="$2y$";return 10>r&&(n+="0"),n+=r+"$",n+=o(b(C),C)}function d(r,n,e){if(n&&"number"!=typeof n){if("string"!=typeof n||!z.test(n))throw new Error("Invalid salt")}else n=v(n);return m(r,n,e)}function h(r,n,e,t){if(arguments.length<2)throw new Error("Incorrect arguments");if(2===arguments.length?(t=n,n=e=null):3===arguments.length&&(t=e,e=null,"function"==typeof n&&(e=n,n=null)),n&&"number"!=typeof n){if("string"!=typeof n||!z.test(n))throw new Error("Invalid salt")}else n=v(n);if(!t||"function"!=typeof t)throw new Error("No callback function was given.");m(r,n,e,t)}function w(r,n){if("string"!=typeof n||!Z.test(n))throw new Error("Incorrect arguments");var e=n.substr(0,n.length-31),t=d(r,e);return t===n}function A(r,n,e,t){if("string"!=typeof n||!Z.test(n))throw new Error("Incorrect arguments");if(t||(t=e,e=null),!t||"function"!=typeof t)throw new Error("No callback function was given.");var o=n.substr(0,n.length-31);h(r,o,e,function(r){t(r===n)})}var b,E="undefined"!=typeof InstallTrigger,I=E;n&&(b=n.randomBytes,n.getRandomValues&&(b=function(r){var e=new Uint8Array(r);return n.getRandomValues(e)}));var C=16,N=10,O=16,$=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],U=[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946,1266315497,3048417604,3681880366,3289982499,290971e4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055,3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504,976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409e3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462],M=$.length,T=U.length,x=[1332899944,1700884034,1701343084,1684370003,1668446532,1869963892],k=0,G=4096,S=4164,F=4168,L=4192,R=4200,j=4272,B="./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",D=[0,1,54,55,56,57,58,59,60,61,62,63,-1,-1,-1,-1,-1,-1,-1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,-1,-1,-1,-1,-1,-1,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,-1,-1,-1,-1,-1],z=/^\$2[ay]\$(0[4-9]|[12][0-9]|3[01])\$[.\/A-Za-z0-9]{21}[.Oeu]/,Z=/^\$2[ay]\$(0[4-9]|[12][0-9]|3[01])\$[.\/A-Za-z0-9]{21}[.Oeu][.\/A-Za-z0-9]{30}[.CGKOSWaeimquy26]$/;r.genSalt=v,r.hashSync=d,r.hash=h,r.compareSync=w,r.compare=A,r.ENCODING_UTF8=0,r.ENCODING_RAW=1,r.encodingMode=r.ENCODING_UTF8,r.cryptoRNG=!!b,r.randomBytes=b,r.defaultCost=N,r.version="2.2.0"}); \ No newline at end of file diff --git a/luci-app-autoupdate/Makefile b/luci-app-autoupdate/Makefile new file mode 100755 index 000000000..1eade0235 --- /dev/null +++ b/luci-app-autoupdate/Makefile @@ -0,0 +1,15 @@ +# Copyright (C) 2020-2022 Hyy2001X + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-autoupdate +PKG_VERSION:=2.8 +PKG_RELEASE:=2 + +LUCI_TITLE:=LuCI Support for autoupdate +LUCI_DEPENDS:=+autoupdate +LUCI_PKGARCH:=all + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-autoupdate/README.md b/luci-app-autoupdate/README.md new file mode 100755 index 000000000..6ec0d26fc --- /dev/null +++ b/luci-app-autoupdate/README.md @@ -0,0 +1,3 @@ +# luci-app-autoupdate + +此项目需要搭配 [AutoBuild-Actions](https://github.com/Hyy2001X/AutoBuild-Actions) 使用 diff --git a/luci-app-autoupdate/luasrc/controller/autoupdate.lua b/luci-app-autoupdate/luasrc/controller/autoupdate.lua new file mode 100755 index 000000000..fdf594e70 --- /dev/null +++ b/luci-app-autoupdate/luasrc/controller/autoupdate.lua @@ -0,0 +1,17 @@ +module("luci.controller.autoupdate",package.seeall) + +function index() + if not nixio.fs.access("/etc/config/autoupdate") then + return + end + entry({"admin", "system", "autoupdate"}, alias("admin", "system", "autoupdate", "main"), _("AutoUpdate"), 99).dependent = true + entry({"admin", "system", "autoupdate", "main"}, cbi("autoupdate/main"), _("Scheduled Upgrade"), 10).leaf = true + entry({"admin", "system", "autoupdate", "manual"}, cbi("autoupdate/manual"), _("Manually Upgrade"), 20).leaf = true + entry({"admin", "system", "autoupdate", "log"}, form("autoupdate/log"), _("Upgrade Log"), 30).leaf = true + entry({"admin", "system", "autoupdate", "print_log"}, call("print_log")).leaf = true +end + +local logfile = luci.sys.exec("autoupdate --env Log_Full") +function print_log() + luci.http.write(luci.sys.exec("tail -n 50 " .. logfile .. " 2> /dev/null")) +end \ No newline at end of file diff --git a/luci-app-autoupdate/luasrc/model/cbi/autoupdate/log.lua b/luci-app-autoupdate/luasrc/model/cbi/autoupdate/log.lua new file mode 100755 index 000000000..fb6aec327 --- /dev/null +++ b/luci-app-autoupdate/luasrc/model/cbi/autoupdate/log.lua @@ -0,0 +1,6 @@ +log = SimpleForm("autoupdate") +log.reset = false +log.submit = false +log:append(Template("autoupdate/autoupdate_log")) + +return log diff --git a/luci-app-autoupdate/luasrc/model/cbi/autoupdate/main.lua b/luci-app-autoupdate/luasrc/model/cbi/autoupdate/main.lua new file mode 100755 index 000000000..4cee31cfd --- /dev/null +++ b/luci-app-autoupdate/luasrc/model/cbi/autoupdate/main.lua @@ -0,0 +1,80 @@ +m = Map("autoupdate", translate("AutoUpdate"), +translate("AutoUpdate LUCI supports scheduled upgrade & one-click firmware upgrade") +.. [[

]] +.. translate("Powered by AutoBuild-Actions") +.. [[]] +) + +s = m:section(TypedSection, "autoupdate") +s.anonymous = true + +local default_url = luci.sys.exec("autoupdate --env Github") +local default_flag = luci.sys.exec("autoupdate --env TARGET_FLAG") +local default_logpath = luci.sys.exec("autoupdate --env Log_Path") + +enable = s:option(Flag, "enable", translate("Enable"), translate("Automatically update firmware during the specified time when Enabled")) +enable.default = 0 +enable.optional = false + +proxy = s:option(Flag, "proxy", translate("Preference Mirror Speedup"), translate("Preference Mirror for speeding up downloads while upgrading (For Mainland)")) +proxy.default = 1 +proxy:depends("enable", "1") +proxy.optional = false + +proxy_type = s:option(ListValue, "proxy_type", translate("Mirror Station")) +proxy_type.default = "A" +proxy_type:value("A", translate("Automatic selection (Recommend)")) +proxy_type:value("G", translate("GitHub Proxy - Ghproxy (Maybe faster)")) +proxy_type:value("F", translate("FastGit UK")) +proxy_type:depends("proxy", "1") +proxy_type.optional = false + +advanced = s:option(Flag, "advanced", translate("Advanced Settings")) +advanced.default = 0 +advanced:depends("enable", "1") + +advanced_settings = s:option(MultiValue, "advanced_settings", translate("Advanced Settings"), translate("Supported Multi Selection")) +advanced_settings:value("--skip-verify", translate("Skip SHA256 Verify")) +advanced_settings:value("-F", translate("Force Flash Firmware")) +advanced_settings:value("--decompress", translate("Decompress [img.gz] Firmware")) +advanced_settings:value("-n", translate("Upgrade without keeping config")) +advanced_settings:depends("advanced", "1") +advanced.description = translate("Please don't select it unless you know what you're doing!") + +week = s:option(ListValue, "week", translate("Update Day"), translate("Recommend to set the AUTOUPDATE time to an uncommon time")) +week:value(7, translate("Everyday")) +week:value(1, translate("Monday")) +week:value(2, translate("Tuesday")) +week:value(3, translate("Wednesday")) +week:value(4, translate("Thursday")) +week:value(5, translate("Friday")) +week:value(6, translate("Saturday")) +week:value(0, translate("Sunday")) +week.default = 0 +week:depends("enable", "1") + +hour = s:option(Value, "hour", translate("Hour")) +hour.datatype = "range(0,23)" +hour.rmempty = true +hour.default = 0 +hour:depends("enable", "1") + +minute = s:option(Value, "minute", translate("Minute")) +minute.datatype = "range(0,59)" +minute.rmempty = true +minute.default = 30 +minute:depends("enable", "1") + +github = s:option(Value, "github", translate("Github Url"), translate("For detecting cloud version and downloading firmware")) +github.default = default_url +github.rmempty = false + +flag = s:option(Value, "flag", translate("Firmware Flag")) +flag.default = default_flag +flag.rmempty = false + +logpath = s:option(Value, "logpath", translate("Log Path")) +logpath.default = default_logpath +logpath.rmempty = false + +return m diff --git a/luci-app-autoupdate/luasrc/model/cbi/autoupdate/manual.lua b/luci-app-autoupdate/luasrc/model/cbi/autoupdate/manual.lua new file mode 100755 index 000000000..d51b8724e --- /dev/null +++ b/luci-app-autoupdate/luasrc/model/cbi/autoupdate/manual.lua @@ -0,0 +1,47 @@ +m = Map("autoupdate",translate("Manually Upgrade"),translate("Manually upgrade Firmware or Script")) +s = m:section(TypedSection,"autoupdate") +s.anonymous = true + +local local_version = luci.sys.exec ("autoupdate -V") +local local_script_version = luci.sys.exec ("autoupdate -v") + +check_updates = s:option (Button, "_check_updates", translate("Check Updates"),translate("Please wait for the page to refresh after clicking Check Updates button")) +check_updates.inputtitle = translate ("Check Updates") +check_updates.write = function() + luci.sys.call ("autoupdate -V Cloud > /tmp/Cloud_Version") + luci.sys.call ("autoupdate -v Cloud > /tmp/Cloud_Script_Version") + luci.http.redirect(luci.dispatcher.build_url("admin", "system", "autoupdate", "manual")) +end + +local cloud_version = luci.sys.exec ("cat /tmp/Cloud_Version 2> /dev/null") +local cloud_script_version = luci.sys.exec ("cat /tmp/Cloud_Script_Version 2> /dev/null") + +upgrade_fw = s:option (Button, "_upgrade_fw", translate("Upgrade Firmware"),translate("Upgrade Normally (KEEP CONFIG)") .. "

当前固件版本: " .. local_version .. "
云端固件版本: " .. cloud_version) +upgrade_fw.inputtitle = translate ("Do Upgrade") +upgrade_fw.write = function() + luci.sys.call ("autoupdate -u > /dev/null &") + luci.http.redirect(luci.dispatcher.build_url("admin", "system", "autoupdate", "log")) +end + +upgrade_fw_force = s:option (Button, "_upgrade_fw_force", translate("Upgrade Firmware"),translate("Upgrade with Force Flashing (DANGEROUS)")) +upgrade_fw_force.inputtitle = translate ("Do Upgrade") +upgrade_fw_force.write = function() + luci.sys.call ("autoupdate -u -F > /dev/null &") + luci.http.redirect(luci.dispatcher.build_url("admin", "system", "autoupdate", "log")) +end + +upgrade_fw_n = s:option (Button, "_upgrade_fw_n", translate("Upgrade Firmware"),translate("Upgrade without keeping System-Config")) +upgrade_fw_n.inputtitle = translate ("Do Upgrade") +upgrade_fw_n.write = function() + luci.sys.call ("autoupdate -u -n > /dev/null &") + luci.http.redirect(luci.dispatcher.build_url("admin", "system", "autoupdate", "log")) +end + +upgrade_script = s:option (Button, "_upgrade_script", translate("Upgrade Script"),translate("Using the latest Script may solve some compatibility problems") .. "

当前脚本版本: " .. local_script_version .. "
云端脚本版本: " .. cloud_script_version) +upgrade_script.inputtitle = translate ("Do Upgrade") +upgrade_script.write = function() + luci.sys.call ("autoupdate -x -P > /dev/null &") + luci.http.redirect(luci.dispatcher.build_url("admin", "system", "autoupdate", "log")) +end + +return m diff --git a/luci-app-autoupdate/luasrc/view/autoupdate/autoupdate_log.htm b/luci-app-autoupdate/luasrc/view/autoupdate/autoupdate_log.htm new file mode 100755 index 000000000..dc0fa2554 --- /dev/null +++ b/luci-app-autoupdate/luasrc/view/autoupdate/autoupdate_log.htm @@ -0,0 +1,20 @@ +<% local module = require "luci.dispatcher" -%> + + +
+ +
diff --git a/luci-app-autoupdate/po/zh-cn/autoupdate.po b/luci-app-autoupdate/po/zh-cn/autoupdate.po new file mode 100755 index 000000000..82253620c --- /dev/null +++ b/luci-app-autoupdate/po/zh-cn/autoupdate.po @@ -0,0 +1,104 @@ +msgid "AutoUpdate" +msgstr "固件更新" + +msgid "AutoUpdate LUCI supports scheduled upgrade & one-click firmware upgrade" +msgstr "固件更新 LUCI 支持定时更新固件 & 一键更新固件" + +msgid "Scheduled Upgrade" +msgstr "定时更新" + +msgid "Manually Upgrade" +msgstr "手动更新" + +msgid "Manually upgrade Firmware or Script" +msgstr "手动更新固件或脚本" + +msgid "Upgrade Log" +msgstr "更新日志" + +msgid "Preference Mirror Speedup" +msgstr "镜像加速" + +msgid "Mirror Station" +msgstr "镜像站" + +msgid "Automatic selection (Recommend)" +msgstr "自动选择 (推荐)" + +msgid "GitHub Proxy - Ghproxy (Maybe faster)" +msgstr "GitHub Proxy - Ghproxy (也许更快)" + +msgid "FastGit UK" +msgstr "FastGit UK" + +msgid "Preference Mirror for speeding up downloads while upgrading (For Mainland)" +msgstr "定时更新固件时优先启用镜像加速 (适用与被墙地区)" + +msgid "Advanced Settings" +msgstr "高级设置" + +msgid "Supported Multi Selection" +msgstr "支持同时勾选多个选项" + +msgid "Skip SHA256 Verify" +msgstr "跳过固件 SHA256 校验" + +msgid "Force Flash Firmware" +msgstr "强制刷写固件" + +msgid "Decompress [img.gz] Firmware" +msgstr "解压 [img.gz] 格式固件" + +msgid "Upgrade without keeping config" +msgstr "不保留配置" + +msgid "Please don't select it unless you know what you're doing!" +msgstr "请勿随意勾选除非你知道自己在做什么!" + +msgid "Recommend to set the AUTOUPDATE time to an uncommon time" +msgstr "建议设置定时更新时间为设备不常用的时间" + +msgid "Update Day" +msgstr "更新时间" + +msgid "Github Url" +msgstr "Github 地址" + +msgid "For detecting cloud version and downloading firmware" +msgstr "用于检测固件版本更新以及下载固件的地址" + +msgid "Firmware Flag" +msgstr "固件标签" + +msgid "Log Path" +msgstr "日志路径" + +msgid "Do Upgrade" +msgstr "执行更新" + +msgid "Upgrade Firmware" +msgstr "更新固件" + +msgid "Automatically update firmware during the specified time when Enabled" +msgstr "启用后,将在指定时间段自动检查并更新固件" + +msgid "Upgrade without keeping System-Config" +msgstr "更新固件 (不保留配置)" + +msgid "Upgrade with Force Flashing (DANGEROUS)" +msgstr "更新固件且强制刷入固件 (危险)" + +msgid "Upgrade Normally (KEEP CONFIG)" +msgstr "更新固件 (保留配置)" + +msgid "Using the latest Script may solve some compatibility problems" +msgstr "使用最新脚本也许能解决一些兼容性问题" + +msgid "Upgrade Script" +msgstr "更新脚本" + +msgid "Check Updates" +msgstr "检查更新" + +msgid "Please wait for the page to refresh after clicking Check Updates button" +msgstr "点击检查更新按钮后请等待页面自动刷新" diff --git a/luci-app-autoupdate/po/zh_Hans/autoupdate.po b/luci-app-autoupdate/po/zh_Hans/autoupdate.po new file mode 100755 index 000000000..a7b3b2580 --- /dev/null +++ b/luci-app-autoupdate/po/zh_Hans/autoupdate.po @@ -0,0 +1,101 @@ +msgid "AutoUpdate" +msgstr "固件更新" + +msgid "AutoUpdate LUCI supports scheduled upgrade & one-click firmware upgrade" +msgstr "固件更新 LUCI 支持定时更新固件 & 一键更新固件" + +msgid "Scheduled Upgrade" +msgstr "定时更新" + +msgid "Manually Upgrade" +msgstr "手动更新" + +msgid "Manually upgrade Firmware or Script" +msgstr "手动更新固件或脚本" + +msgid "Upgrade Log" +msgstr "更新日志" + +msgid "Preference Mirror Speedup" +msgstr "镜像加速" + +msgid "Mirror Station" +msgstr "镜像站" + +msgid "Automatic selection (Recommend)" +msgstr "自动选择 (推荐)" + +msgid "GitHub Proxy - Ghproxy (Maybe faster)" +msgstr "GitHub Proxy - Ghproxy (也许更快)" + +msgid "FastGit UK" +msgstr "FastGit UK" + +msgid "Preference Mirror for speeding up downloads while upgrading (For Mainland)" +msgstr "定时更新固件时优先启用镜像加速 (适用与被墙地区)" + +msgid "Advanced Settings" +msgstr "高级设置" + +msgid "Supported Multi Selection" +msgstr "支持同时勾选多个选项" + +msgid "Skip SHA256 Verify" +msgstr "跳过固件 SHA256 校验" + +msgid "Force Flash Firmware" +msgstr "强制刷写固件" + +msgid "Decompress [img.gz] Firmware" +msgstr "解压 [img.gz] 格式固件" + +msgid "Upgrade without keeping config" +msgstr "不保留配置" + +msgid "Please don't select it unless you know what you're doing!" +msgstr "请勿随意勾选除非你知道自己在做什么!" + +msgid "Recommend to set the AUTOUPDATE time to an uncommon time" +msgstr "建议设置定时更新时间为设备不常用的时间" + +msgid "Update Day" +msgstr "更新时间" + +msgid "Github Url" +msgstr "Github 地址" + +msgid "For detecting cloud version and downloading firmware" +msgstr "用于检测固件版本更新以及下载固件的地址" + +msgid "Firmware Flag" +msgstr "固件标签" + +msgid "Do Upgrade" +msgstr "执行更新" + +msgid "Upgrade Firmware" +msgstr "更新固件" + +msgid "Automatically update firmware during the specified time when Enabled" +msgstr "启用后,将在指定时间段自动检查并更新固件" + +msgid "Upgrade without keeping System-Config" +msgstr "更新固件 (不保留配置)" + +msgid "Upgrade with Force Flashing (DANGEROUS)" +msgstr "更新固件且强制刷入固件 (危险)" + +msgid "Upgrade Normally (KEEP CONFIG)" +msgstr "更新固件 (保留配置)" + +msgid "Using the latest Script may solve some compatibility problems" +msgstr "使用最新脚本也许能解决一些兼容性问题" + +msgid "Upgrade Script" +msgstr "更新脚本" + +msgid "Check Updates" +msgstr "检查更新" + +msgid "Please wait for the page to refresh after clicking Check Updates button" +msgstr "点击检查更新按钮后请等待页面自动刷新" diff --git a/luci-app-autoupdate/root/etc/autoupdate/custom b/luci-app-autoupdate/root/etc/autoupdate/custom new file mode 100755 index 000000000..c2aa48120 --- /dev/null +++ b/luci-app-autoupdate/root/etc/autoupdate/custom @@ -0,0 +1,8 @@ +## 请在下方输入你的自定义变量,一行填写一个变量 +## 该文件将在运行 autoupdate 脚本时被读取, 且该文件中的内容优先级高于 default +# +## 示例(添加时不含注释): +# Author=Hyy2001 +# TARGET_PROFILE=x86_64 +# Github=https://github.com/Hyy2001X/AutoBuild-Actions +# \ No newline at end of file diff --git a/luci-app-autoupdate/root/etc/config/autoupdate b/luci-app-autoupdate/root/etc/config/autoupdate new file mode 100755 index 000000000..f360536c6 --- /dev/null +++ b/luci-app-autoupdate/root/etc/config/autoupdate @@ -0,0 +1,2 @@ +config autoupdate + option enable '0' diff --git a/luci-app-autoupdate/root/etc/init.d/autoupdate b/luci-app-autoupdate/root/etc/init.d/autoupdate new file mode 100755 index 000000000..5ef0154ab --- /dev/null +++ b/luci-app-autoupdate/root/etc/init.d/autoupdate @@ -0,0 +1,61 @@ +#!/bin/sh /etc/rc.common + +START=99 +LOGGER="logger -t [AutoUpdate]" + +Script_File="$(command -v autoupdate)" +Script_Cmd="$Script_File -u" + +start() { + local basic_list="enable proxy proxy_type advanced_settings github flag logpath week minute hour" + for i in $(echo $basic_list);do + local eval $i="$(uci_get_by_type autoupdate 0 $i)" + done;unset i + if [ ! "${Script_File}" ] + then + ${LOGGER} "Unable to access autoupdate,exit ..." + stop + exit 1 + else + chmod 777 ${Script_File} 2> /dev/null + fi + if [ "$enable" == 1 ] + then + [ "$week" == 7 ] && week='*' + [ "$proxy" == 1 ] && Script_Cmd="$Script_Cmd -P $proxy_type" + Script_Cmd="$Script_Cmd $advanced_settings" + ${LOGGER} "Creating corn_task [$minute $hour * * $week $Script_Cmd] ..." + echo "$minute $hour * * $week $Script_Cmd ## AutoUpdate crontab" >> /etc/crontabs/root + /etc/init.d/cron restart + else + ${LOGGER} "AutoUpdate Service is disabled ..." + stop + fi + ${LOGGER} "Setting Github URL to $github ..." + ${LOGGER} "Setting Flag to $flag ..." + ${LOGGER} "Setting Log Path to $logpath ..." + $Script_File -C $github > /dev/null 2>&1 + $Script_File --flag $flag > /dev/null 2>&1 + $Script_File --log -path $logpath > /dev/null 2>&1 +} + +stop() { + ${LOGGER} "Removing all corn tasks ..." + sed -i '/## AutoUpdate crontab/d' /etc/crontabs/root 2> /dev/null + /etc/init.d/cron restart +} + +disable() { + ${LOGGER} "Closing AutoUpdate Service ..." + uci set autoupdate.@autoupdate[0].enable="0" 2> /dev/null + stop +} + +service_triggers() { + procd_add_reload_trigger "autoupdate" +} + +uci_get_by_type() { + local ret=$(uci get autoupdate.@$1[$2].$3 2>/dev/null) + echo ${ret:=$4} +} diff --git a/luci-app-autoupdate/root/etc/uci-defaults/luci-autoupdate b/luci-app-autoupdate/root/etc/uci-defaults/luci-autoupdate new file mode 100755 index 000000000..ca487028c --- /dev/null +++ b/luci-app-autoupdate/root/etc/uci-defaults/luci-autoupdate @@ -0,0 +1,10 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@autoupdate[-1] + add ucitrack autoupdate + set ucitrack.@autoupdate[-1].init=autoupdate + commit ucitrack +EOF + +exit 0 \ No newline at end of file diff --git a/luci-app-autoupdate/root/usr/share/rpcd/acl.d/luci-app-autoupdate.json b/luci-app-autoupdate/root/usr/share/rpcd/acl.d/luci-app-autoupdate.json new file mode 100644 index 000000000..86d43bdda --- /dev/null +++ b/luci-app-autoupdate/root/usr/share/rpcd/acl.d/luci-app-autoupdate.json @@ -0,0 +1,11 @@ +{ + "luci-app-autoupdate": { + "description": "Grant UCI access for luci-app-autoupdate", + "read": { + "uci": [ "autoupdate" ] + }, + "write": { + "uci": [ "autoupdate" ] + } + } +} diff --git a/luci-app-iperf3-server/Makefile b/luci-app-iperf3-server/Makefile new file mode 100755 index 000000000..dab9ad26b --- /dev/null +++ b/luci-app-iperf3-server/Makefile @@ -0,0 +1,13 @@ +# Copyright (C) 2020-2021 Hyy2001X + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI support for iPerf3 +LUCI_DEPENDS:=+iperf3 +LUCI_PKGARCH:=all +PKG_VERSION:=2.0 +PKG_RELEASE:=3 + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-iperf3-server/README.md b/luci-app-iperf3-server/README.md new file mode 100755 index 000000000..6cb710c0e --- /dev/null +++ b/luci-app-iperf3-server/README.md @@ -0,0 +1,3 @@ +# luci-app-iperf3-server + +一个简单的 iPerf3 服务端 diff --git a/luci-app-iperf3-server/luasrc/controller/iperf3-server.lua b/luci-app-iperf3-server/luasrc/controller/iperf3-server.lua new file mode 100755 index 000000000..02cef90c4 --- /dev/null +++ b/luci-app-iperf3-server/luasrc/controller/iperf3-server.lua @@ -0,0 +1,17 @@ +module("luci.controller.iperf3-server",package.seeall) + +function index() + if not nixio.fs.access("/etc/config/iperf3-server") then + return + end + + entry({"admin", "services", "iperf3-server"}, cbi("iperf3-server"), _("iPerf3 Server"),99) + entry({"admin", "services", "iperf3-server", "status"}, call("act_status")).leaf = true +end + +function act_status() + local e = {} + e.running = luci.sys.call("pgrep iperf3 > /dev/null") == 0 + luci.http.prepare_content("application/json") + luci.http.write_json(e) +end diff --git a/luci-app-iperf3-server/luasrc/model/cbi/iperf3-server.lua b/luci-app-iperf3-server/luasrc/model/cbi/iperf3-server.lua new file mode 100755 index 000000000..e8417dc34 --- /dev/null +++ b/luci-app-iperf3-server/luasrc/model/cbi/iperf3-server.lua @@ -0,0 +1,36 @@ +m = Map("iperf3-server", translate("iPerf3 Server"), translate("iPerf3 - The ultimate speed test tool for TCP, UDP and SCTP")) + +m:section(SimpleSection).template = "iperf3-server/iperf3-server_status" + +s = m:section(TypedSection, "iperf3-server", "") +s.addremove = false +s.anonymous = true + +main_enable = s:option(Flag, "main_enable", translate("Enable"), translate("Enable iPerf3 Servers")) +main_enable.default = "0" +main_enable.rmempty = false + +s = m:section(TypedSection, "servers", translate("Server Settings"), translate("Set up Multi-iPerf3 Servers")) +s.anonymous = true +s.addremove = true +s.template = "cbi/tblsection" + +enable_server = s:option(Flag, "enable_server", translate("Enable")) +enable_server.default = "1" +enable_server.rmempty = false + +port = s:option(Value, "port", translate("Port")) +port.datatype = "port" +port.default = "5201" +port.rmempty = false + +delay = s:option(Value, "delay", translate("Start delay (Seconds)")) +delay.default = "0" +delay.datatype = "uinteger" +delay.rmempty = false + +extra_options = s:option(Value, "extra_options", translate("Extra Options")) +extra_options.rmempty = true +extra_options.password= false + +return m diff --git a/luci-app-iperf3-server/luasrc/view/iperf3-server/iperf3-server_status.htm b/luci-app-iperf3-server/luasrc/view/iperf3-server/iperf3-server_status.htm new file mode 100755 index 000000000..c6a8378a2 --- /dev/null +++ b/luci-app-iperf3-server/luasrc/view/iperf3-server/iperf3-server_status.htm @@ -0,0 +1,22 @@ + + +
+

+ <%:Collecting data...%> +

+
diff --git a/luci-app-iperf3-server/po/zh-cn/iperf3-server.po b/luci-app-iperf3-server/po/zh-cn/iperf3-server.po new file mode 100755 index 000000000..bfbd1f951 --- /dev/null +++ b/luci-app-iperf3-server/po/zh-cn/iperf3-server.po @@ -0,0 +1,26 @@ +msgid "iPerf3 - The ultimate speed test tool for TCP, UDP and SCTP" +msgstr "iPerf3 是一款集 TCP UDP 和 SCTP 于的一身的终极速度测试工具" + +msgid "Port" +msgstr "端口" + +msgid "iPerf3 Server" +msgstr "iPerf3 服务器" + +msgid "Enable iPerf3 Servers" +msgstr "启用 iPerf3 服务器" + +msgid "Server Settings" +msgstr "服务端设置" + +msgid "Set up Multi-iPerf3 Servers" +msgstr "设置多个 iPerf3 服务端" + +msgid "Start delay" +msgstr "启动延迟 (秒)" + +msgid "iPerf3 Server listening port" +msgstr "iPerf3 服务端监听端口" + +msgid "Extra Options" +msgstr "额外参数" diff --git a/luci-app-iperf3-server/po/zh_Hans/iperf3-server.po b/luci-app-iperf3-server/po/zh_Hans/iperf3-server.po new file mode 100755 index 000000000..bfbd1f951 --- /dev/null +++ b/luci-app-iperf3-server/po/zh_Hans/iperf3-server.po @@ -0,0 +1,26 @@ +msgid "iPerf3 - The ultimate speed test tool for TCP, UDP and SCTP" +msgstr "iPerf3 是一款集 TCP UDP 和 SCTP 于的一身的终极速度测试工具" + +msgid "Port" +msgstr "端口" + +msgid "iPerf3 Server" +msgstr "iPerf3 服务器" + +msgid "Enable iPerf3 Servers" +msgstr "启用 iPerf3 服务器" + +msgid "Server Settings" +msgstr "服务端设置" + +msgid "Set up Multi-iPerf3 Servers" +msgstr "设置多个 iPerf3 服务端" + +msgid "Start delay" +msgstr "启动延迟 (秒)" + +msgid "iPerf3 Server listening port" +msgstr "iPerf3 服务端监听端口" + +msgid "Extra Options" +msgstr "额外参数" diff --git a/luci-app-iperf3-server/root/etc/config/iperf3-server b/luci-app-iperf3-server/root/etc/config/iperf3-server new file mode 100755 index 000000000..5a752470c --- /dev/null +++ b/luci-app-iperf3-server/root/etc/config/iperf3-server @@ -0,0 +1,4 @@ + +config iperf3-server + option enable '0' + option port '5201' \ No newline at end of file diff --git a/luci-app-iperf3-server/root/etc/init.d/iperf3-server b/luci-app-iperf3-server/root/etc/init.d/iperf3-server new file mode 100755 index 000000000..4999dc54c --- /dev/null +++ b/luci-app-iperf3-server/root/etc/init.d/iperf3-server @@ -0,0 +1,57 @@ +#!/bin/sh /etc/rc.common + +START=99 +USE_PROCD=1 +LOGGER="logger -t [iPerf3-Server]" + +start_service() { + stop_service + local basic_list="main_enable" + local server_list="port delay extra_options enable_server" + for i in $(echo $basic_list) + do + local eval $i="$(uci_get_by_type iperf3-server 0 $i)" + done ; unset i + if [ "$main_enable" == 1 ] + then + server_number=$(uci show iperf3-server 2> /dev/null | egrep '@servers\[[0-9]\]+=servers' | wc -l) + # server_number=$(uci show iperf3-server 2> /dev/null | egrep -o '@servers\[[0-9]\]+=servers' | awk 'END {print}' | egrep -o "[0-9]") + for u in $(seq 0 $((${server_number} - 1))) + do + { + for i in $server_list + do + eval ${i}=$(uci_get_by_type servers $u $i) + done ; unset i + if [ "$enable_server" == 1 ] + then + sleep $delay + $LOGGER "Starting iPerf3 Server [$u] with Port [$port] ..." + # $(command -v iperf3) -s -D -p $port $extra_options + procd_open_instance + procd_set_param command sleep $delay ; $(command -v iperf3) -s -D -p $port $extra_options + procd_set_param respawn 3000 3 10 + procd_close_instance + fi + unset enable_server delay + } & + done ; unset u + else + $LOGGER "iPerf3 Server is disabled ..." + stop_service + fi +} + +stop_service() { + $LOGGER "Stopping iPerf3 Server ..." + ps -efww | grep 'iperf3 -s -D' | grep -v 'grep' | awk '{print $1}' | xargs kill -9 +} + +service_triggers() { + procd_add_reload_trigger "iperf3-server" +} + +uci_get_by_type() { + local ret=$(uci get iperf3-server.@$1[$2].$3 2>/dev/null) + echo ${ret:=$4} +} diff --git a/luci-app-iperf3-server/root/etc/uci-defaults/iperf3-server b/luci-app-iperf3-server/root/etc/uci-defaults/iperf3-server new file mode 100755 index 000000000..f461250fa --- /dev/null +++ b/luci-app-iperf3-server/root/etc/uci-defaults/iperf3-server @@ -0,0 +1,10 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@iperf3-server[-1] + add ucitrack iperf3-server + set ucitrack.@iperf3-server[-1].init=iperf3-server + commit ucitrack +EOF + +exit 0 \ No newline at end of file diff --git a/luci-app-iperf3-server/root/usr/share/rpcd/acl.d/luci-app-iperf3-server.json b/luci-app-iperf3-server/root/usr/share/rpcd/acl.d/luci-app-iperf3-server.json new file mode 100644 index 000000000..4639e24c5 --- /dev/null +++ b/luci-app-iperf3-server/root/usr/share/rpcd/acl.d/luci-app-iperf3-server.json @@ -0,0 +1,11 @@ +{ + "luci-app-iperf3-server": { + "description": "Grant UCI access for luci-app-iperf3-server", + "read": { + "uci": [ "iperf3-server" ] + }, + "write": { + "uci": [ "iperf3-server" ] + } + } +} diff --git a/luci-app-natter/Makefile b/luci-app-natter/Makefile new file mode 100755 index 000000000..9c3cd6677 --- /dev/null +++ b/luci-app-natter/Makefile @@ -0,0 +1,15 @@ +# Copyright (C) 2020-2022 Hyy2001X + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-natter +PKG_VERSION:=1.1 +PKG_RELEASE:=2 + +LUCI_TITLE:=LuCI Support for Natter +LUCI_PKGARCH:=all +LUCI_DEPENDS:=+natter + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-natter/README.md b/luci-app-natter/README.md new file mode 100644 index 000000000..dded3783c --- /dev/null +++ b/luci-app-natter/README.md @@ -0,0 +1,3 @@ +# luci-app-natter + +项目地址: https://github.com/MikeWang000000/Natter diff --git a/luci-app-natter/luasrc/controller/natter.lua b/luci-app-natter/luasrc/controller/natter.lua new file mode 100755 index 000000000..787a32b5e --- /dev/null +++ b/luci-app-natter/luasrc/controller/natter.lua @@ -0,0 +1,21 @@ +module("luci.controller.natter",package.seeall) + +function index() + if not nixio.fs.access("/etc/config/natter") then + return + end + entry({"admin", "network", "natter"}, alias("admin", "network", "natter", "base"), _("Natter"), 99).dependent = true + entry({"admin", "network", "natter", "base"}, cbi("natter/base"), _("Base Settings"), 10).leaf = true + entry({"admin", "network", "natter", "ports"}, cbi("natter/ports")).leaf = true + entry({"admin", "network", "natter", "log"}, form("natter/log"), _("Log"), 20).leaf = true + entry({"admin", "network", "natter", "print_log"}, call("print_log")).leaf = true + entry({"admin", "network", "natter", "del_log"}, call("del_log")).leaf = true +end + +function print_log() + luci.http.write(luci.sys.exec("sh /usr/share/luci-app-natter/log.sh print")) +end + +function del_log() + luci.http.write(luci.sys.exec("sh /usr/share/luci-app-natter/log.sh del")) +end diff --git a/luci-app-natter/luasrc/model/cbi/natter/base.lua b/luci-app-natter/luasrc/model/cbi/natter/base.lua new file mode 100755 index 000000000..e26fd9ee4 --- /dev/null +++ b/luci-app-natter/luasrc/model/cbi/natter/base.lua @@ -0,0 +1,87 @@ +m = Map("natter", translate("Natter"), translate("Open Port under FullCone NAT (NAT 1)")) +s = m:section(TypedSection, "base") + +s.addremove = false +s.anonymous = true + +local function check_file(e) + return luci.sys.exec('ls "%s" 2> /dev/null' % e) ~= "" and true or false +end + +enable = s:option(Flag, "enable", translate("Enable")) +enable.default = 0 + +enable_fullcone_nat = s:option(Flag, "enable_fullcone_nat", translate("FullCone NAT")) +enable_fullcone_nat.default = 0 + +if check_file("/tmp/natter_nat_type") then + natter_nat_type_tcp = luci.sys.exec ("grep TCP /tmp/natter_nat_type") + natter_nat_type_udp = luci.sys.exec ("grep UDP /tmp/natter_nat_type") + nat_check = s:option (Button, "nat_check", translate("Check NAT Status"), translate("") .. "

" .. natter_nat_type_tcp .. "

" .. natter_nat_type_udp) +else + nat_check = s:option (Button, "nat_check", translate("Check NAT Status")) +end + +nat_check.inputtitle = translate("Exec") +nat_check.write = function() + luci.sys.call ("sh /usr/share/luci-app-natter/natcheck.sh > /tmp/natter_nat_type") + luci.http.redirect(luci.dispatcher.build_url("admin", "network", "natter", "base")) +end + +local_ip = s:option(Value, "local_ip", translate("Local IP Address"), translate("Natter Listening Address")) +local_ip.default = "0.0.0.0" +local_ip.placeholder = "0.0.0.0" +local_ip.datatype = "host" +local_ip.rmempty = false + +log_path = s:option(Value, "log_path", translate("Log Path"), translate("Directory to save natter logs")) +log_path.default = "/tmp/natter" +log_path.placeholder = "/tmp/natter" +log_path.rmempty = false + +keep_alive_server = s:option(Value, "keep_alive_server", translate("Keep Alive Server"), translate("Please ensure that the address can be connected by Natter")) +keep_alive_server.rmempty = false + +tcp_stun_server = s:option(DynamicList, "tcp_stun_server", translate("TCP STUN Server"), translate("Please DO NOT handle the IP address/domain name/port of the TCP/UDP STUN server (3478) while running proxy")) +udp_stun_server = s:option(DynamicList, "udp_stun_server", translate("UDP STUN Server")) +udp_stun_server.rmempty = false + +s = m:section(TypedSection, "ports", translate("Port Settings")) +s.anonymous = true +s.addremove = true +s.template = "cbi/tblsection" +s.extedit = luci.dispatcher.build_url("admin", "network", "natter", "ports", "%s") +function s.create(...) + local sid = TypedSection.create(...) + if sid then + luci.http.redirect(s.extedit % sid) + return + end +end + +enable_port = s:option(Flag, "enable_port", translate("Enable")) +enable_port.default = 1 +enable_port.width = "5%" + +id = s:option(DummyValue, "id", translate("ID")) +id.width = "8%" + +remarks = s:option(DummyValue, "remarks", translate("Remarks")) +remarks.width = "10%" + +forward_mode = s:option(DummyValue, "forward_mode", translate("Forward Mode")) +forward_mode.width = "8%" + +external_port = s:option(DummyValue, "external_port", translate("External Port")) +external_port.width = "12%" + +enable_forward = s:option(Flag, "enable_forward", translate("Forward")) +enable_forward.default = 0 + +internal_ip = s:option(DummyValue, "internal_ip", translate("Internal IP Address")) +internal_ip.width = "12%" + +internal_port = s:option(DummyValue, "internal_port", translate("Internal Port")) +internal_port.width = "12%" + +return m diff --git a/luci-app-natter/luasrc/model/cbi/natter/log.lua b/luci-app-natter/luasrc/model/cbi/natter/log.lua new file mode 100755 index 000000000..fec1ba0ec --- /dev/null +++ b/luci-app-natter/luasrc/model/cbi/natter/log.lua @@ -0,0 +1,6 @@ +log = SimpleForm("natter") +log.reset = false +log.submit = false +log:append(Template("natter/natter_log")) + +return log diff --git a/luci-app-natter/luasrc/model/cbi/natter/ports.lua b/luci-app-natter/luasrc/model/cbi/natter/ports.lua new file mode 100755 index 000000000..fcd2030ef --- /dev/null +++ b/luci-app-natter/luasrc/model/cbi/natter/ports.lua @@ -0,0 +1,65 @@ +m = Map("natter", translate("Port Settings")) +m.redirect = luci.dispatcher.build_url("admin", "network", "natter") + +s = m:section(NamedSection, arg[1], "ports", "") +s.addremove = false +s.dynamic = false + +enable_port = s:option(Flag, "enable_port", translate("Enable")) + +local rand_id = luci.sys.exec("cut -d '-' -f1 /proc/sys/kernel/random/uuid 2> /dev/null") +id = s:option(Value, "id", translate("ID"), translate("Just keep default, or ensure uniqueness")) +id.default = rand_id + +remarks = s:option(Value, "remarks", translate("Remarks")) +remarks.rmempty = false + +forward_mode = s:option(ListValue, "forward_mode", translate("Forward Mode")) +forward_mode:value('1', translate("1 - Natter")) +forward_mode:value('2', translate("2 - Firewall")) +forward_mode.default = 2 + +external_port = s:option(Value, "external_port", translate("External Port"), translate("Specify the port opened by Natter")) +external_port.datatype = "port" +external_port:depends({forward_mode = "2"}) + +port_type = s:option(ListValue, "port_type", translate("Port Type")) +port_type:value("udp", translate("UDP")) +port_type:value("tcp", translate("TCP")) +port_type:value("both", translate("TCP + UDP")) +port_type.default = both +port_type.rempty = false + +enable_forward = s:option(Flag, "enable_forward", translate("Enable Port Forward"), translate("Forward opened port to internal host")) +enable_forward.default = 1 +enable_forward.rempty = false + +internal_ip = s:option(Value, "internal_ip", translate("Internal IP address"), translate("Internal Host IP address")) +internal_ip.datatype = "ipmask4" +internal_ip:depends({enable_forward = "1"}) +luci.sys.net.ipv4_hints( +function(ip, name) + internal_ip:value(ip, "%s (%s)" %{ ip, name }) +end) + +internal_port = s:option(Value, "internal_port", translate("Internal Port"), translate("Internal Host Port")) +internal_port.datatype = "port" +internal_port:depends({enable_forward = "1"}) + +delay = s:option(Value, "delay", translate("Start delay (Seconds)")) +delay.default = 0 +delay.datatype = "uinteger" +delay.rmempty = false + +log_level = s:option(ListValue, "log_level", translate("Log Level")) +log_level:value('debug', translate("Debug")) +log_level:value('info', translate("Info")) +log_level:value('warning', translate("Warning")) +log_level:value('error', translate("Error")) + +--[[ +hook = s:option(Value, "hook", translate("Hook")) +hook.rmempty = true +--]] + +return m diff --git a/luci-app-natter/luasrc/view/natter/natter_log.htm b/luci-app-natter/luasrc/view/natter/natter_log.htm new file mode 100755 index 000000000..deeff8b6b --- /dev/null +++ b/luci-app-natter/luasrc/view/natter/natter_log.htm @@ -0,0 +1,29 @@ + + +
+ + +
diff --git a/luci-app-natter/po/zh-cn/natter.po b/luci-app-natter/po/zh-cn/natter.po new file mode 100755 index 000000000..40cb67589 --- /dev/null +++ b/luci-app-natter/po/zh-cn/natter.po @@ -0,0 +1,114 @@ +msgid "Natter" +msgstr "Natter" + +msgid "Open Port under FullCone NAT (NAT 1)" +msgstr "帮助 Full cone NAT (NAT 1) 用户打开公网端口" + +msgid "Log Path" +msgstr "日志路径" + +msgid "Log Level" +msgstr "日志等级" + +msgid "Base Settings" +msgstr "基础设置" + +msgid "Log" +msgstr "日志" + +msgid "IP Address" +msgstr "IP 地址" + +msgid "Start delay (Seconds)" +msgstr "启动延迟 (秒)" + +msgid "Start delay" +msgstr "启动延迟" + +msgid "Port Settings" +msgstr "端口设置" + +msgid "TCP STUN Server" +msgstr "TCP STUN 服务器" + +msgid "UDP STUN Server" +msgstr "UDP STUN 服务器" + +msgid "Keep Alive Server" +msgstr "Keep Alive 服务器" + +msgid "Directory to save natter logs" +msgstr "Natter 运行日志保存路径 (文件夹)" + +msgid "ID" +msgstr "标识" + +msgid "Just keep default, or ensure uniqueness" +msgstr "保持默认即可, 修改时请确保标识的唯一性" + +msgid "Remarks" +msgstr "备注" + +msgid "Internal Port" +msgstr "内部端口" + +msgid "Internal Host IP address" +msgstr "内部主机的 IP 地址" + +msgid "Internal Host Port" +msgstr "内部主机的端口" + +msgid "External Port" +msgstr "外部端口" + +msgid "Specify the port opened by Natter" +msgstr "指定 Natter 打开的端口" + +msgid "Enable Port Forward" +msgstr "启用端口转发" + +msgid "Forward opened port to internal host" +msgstr "将打开的端口转发至内部主机" + +msgid "Port Type" +msgstr "端口类型" + +msgid "FullCone NAT" +msgstr "FullCone NAT" + +msgid "Please DO NOT handle the IP address/domain name/port of the TCP/UDP STUN server (3478) while running proxy" +msgstr "请不要使用任何代理软件代理 TCP/UDP STUN 服务器的IP 地址/域名/端口 (3478)" + +msgid "Local IP Address" +msgstr "本地 IP 地址" + +msgid "Natter Listening Address" +msgstr "Natter 监听地址" + +msgid "Please ensure that the address can be connected by Natter" +msgstr "请确保 Keep Alive 服务器地址能被 Natter 连接" + +msgid "Internal IP Address" +msgstr "内部 IP 地址" + +msgid "Forward Mode" +msgstr "转发策略" + +msgid "1 - Natter" +msgstr "1 - Natter 内置" + +msgid "2 - Firewall" +msgstr "2 - 防火墙" + +msgid "Delete Logs" +msgstr "清除日志" + +msgid "<%:Delete Logs%>" +msgstr "清除日志" + +msgid "Check NAT Status" +msgstr "NAT 类型检测" + +msgid "Exec" +msgstr "执行" + diff --git a/luci-app-natter/po/zh_Hans b/luci-app-natter/po/zh_Hans new file mode 120000 index 000000000..41451e4a1 --- /dev/null +++ b/luci-app-natter/po/zh_Hans @@ -0,0 +1 @@ +zh-cn \ No newline at end of file diff --git a/luci-app-natter/root/etc/config/natter b/luci-app-natter/root/etc/config/natter new file mode 100755 index 000000000..a7fd285b7 --- /dev/null +++ b/luci-app-natter/root/etc/config/natter @@ -0,0 +1,15 @@ +config base + option enable '0' + option keep_alive_server "www.baidu.com" + list tcp_stun_server 'stun.nextcloud.com' + list tcp_stun_server 'fwa.lifesizecloud.com' + list tcp_stun_server 'stun.isp.net.au' + list tcp_stun_server 'stun.freeswitch.org' + list tcp_stun_server 'stun.voip.blackberry.com' + list tcp_stun_server 'stun.stunprotocol.org' + list tcp_stun_server 'stun.sipnet.com' + list tcp_stun_server 'stun.radiojar.com' + list tcp_stun_server 'stun.sonetel.com' + list tcp_stun_server 'stun.voipgate.com' + list udp_stun_server 'stun.miwifi.com' + list udp_stun_server 'stun.qq.com' diff --git a/luci-app-natter/root/etc/init.d/natter b/luci-app-natter/root/etc/init.d/natter new file mode 100755 index 000000000..ba4eb72bc --- /dev/null +++ b/luci-app-natter/root/etc/init.d/natter @@ -0,0 +1,235 @@ +#!/bin/sh /etc/rc.common + +START=98 +USE_PROCD=0 + +start_service() { + local basic_list="enable enable_fullcone_nat log_path tcp_stun_server udp_stun_server keep_alive_url local_ip" + local port_list="enable_port id remarks port enable_forward \ + forward_mode external_port port_type delay log_level \ + internal_ip internal_port hook" + for i in $basic_list + do + local eval $i="$(uci_get_by_type base 0 $i)" + done ; unset i + if [ "$enable_fullcone_nat" == 1 ] + then + echo "Starting Natter ..." + if [ "$(uci get firewall.@defaults[0].fullcone > /dev/null ; echo $?)" == 0 ] + then + if [ "$(uci get firewall.@defaults[0].fullcone)" == 0 ] + then + echo "Starting FullCone NAT ..." + uci set firewall.@defaults[0].fullcone="1" + uci commit firewall + else + echo "FullCone NAT was already started ..." + fi + else + echo "Failed to start FullCone NAT ..." + uci set natter.@base[0].enable_fullcone_nat="0" + uci commit natter + fi + fi + if [ "$enable" == 1 ] + then + include_file=/var/etc/natter.include + echo " +#!/bin/sh +iptables -N natter 2> /dev/null +iptables -I INPUT -j natter 2> /dev/null +" \ + > $include_file + mkdir -p ${log_path} + iptables_remove_rule + mkdir -p /var/etc/natter + for u in $(seq 0 $(($(uci show natter 2> /dev/null | egrep '@ports\[[0-9]\]+=ports' | wc -l) - 1))) + do + for i in $port_list + do + local eval $i="$(uci_get_by_type ports $u $i)" + echo "$i : $(uci_get_by_type ports $u $i)" + done ; unset i + + [ "$enable_port" != 1 ] && continue + + case $port_type in + tcp | udp) + eval external_${port_type}="$local_ip:$external_port" + eval internal_${port_type}="$internal_ip:$internal_port" + iptables_type=$port_type + ;; + both) + external_tcp="$local_ip:$external_port" + external_udp="$local_ip:$external_port" + internal_tcp="$internal_ip:$internal_port" + internal_udp="$internal_ip:$internal_port" + iptables_type="tcp udp" + ;; + esac + + log_file=${log_path}/natter-${id}-${remarks}.log + json_file=/var/etc/natter/natter-${id}-${remarks}.json + status_file=${log_path}/natter-${id}-${remarks}.json + + echo "{ + \"logging\": { + \"level\": \"$log_level\", + \"log_file\": \"${log_file}\" + }, + \"status_report\": { + \"hook\": \"$hook\", + \"status_file\": \"${status_file}\" + }, + $( + case ${forward_mode} in + 1) + echo " + \"open_port\": { + \"tcp\": [ + + ], + \"udp\": [ + + ] + }," + echo " + \"forward_port\": { + \"tcp\": [ + $([ "$internal_tcp" ] && echo \"${internal_tcp}\") + ], + \"udp\": [ + $([ "$internal_udp" ] && echo \"${internal_udp}\") + ] + }," + ;; + 2) + echo " + \"open_port\": { + \"tcp\": [ + $([ "$external_tcp" ] && echo \"${external_tcp}\") + ], + \"udp\": [ + $([ "$external_udp" ] && echo \"${external_udp}\") + ] + }," + echo " + \"forward_port\": { + \"tcp\": [ + + ], + \"udp\": [ + + ] + }," + ;; + esac + ) + \"stun_server\": { + \"tcp\": $( + printf "[" + j=1 ; for i in $tcp_stun_server + do + [[ "$j" == 1 ]] && unset j || printf ", " + printf '"%s"' $i + done ; unset i j + printf "],") + \"udp\": $( + printf "[" + j=1 ; for i in $udp_stun_server + do + [[ "$j" == 1 ]] && unset j || printf ", " + printf '"%s"' $i + done ; unset i j + printf "]") + }, + \"keep_alive\": \"$keep_alive_url\" +}" \ + > $json_file + echo "json File: $json_file" + echo "log File: $log_file" + echo "status File: $status_file" + sleep $delay + for i in $(ps -efww | egrep 'natter.py' | grep -v grep | grep -v $$ | grep "$id" | awk '{print $1}') + do + kill -9 "$i" 2> /dev/null + done + $(command -v python) /usr/share/natter/natter.py -c $json_file & + if [ "$enable_forward" == 1 ] + then + case $forward_mode in + 1) + : + ;; + 2) + iptables -N natter 2> /dev/null + iptables -I INPUT -j natter 2> /dev/null + for i in $iptables_type + do + # iptables -A natter \ + -p $i -m $i --dport $external_port \ + -m comment --comment "nt-op-$id-$remarks" \ + -j ACCEPT + # echo "iptables -A natter -p $i -m $i --dport $external_port -m comment --comment \"nt-op-$id-$remarks\" -j ACCEPT" >> ${include_file} + iptables -t nat -A PREROUTING \ + -p $i -m $i --dport $external_port \ + -m comment --comment "nt-dnat-$id-$remarks" \ + -j DNAT \ + --to-destination $internal_ip:$internal_port + echo "iptables -t nat -A PREROUTING -p $i -m $i --dport $external_port -m comment --comment \"nt-dnat-$id-$remarks\" -j DNAT --to-destination $internal_ip:$internal_port" >> ${include_file} + done ; unset i + ;; + esac + fi + for i in $port_list + do + unset $(echo $i) + done ; unset i + unset iptables_type internal_tcp internal_udp external_tcp external_udp + done ; unset u + else + echo "Natter is disabled ..." + stop_service + fi +} + +stop_service() { + echo "Stopping Natter ..." + for i in $(ps -efww | egrep 'natter.py' | grep -v grep | grep -v $$ | awk '{print $1}') + do + kill -9 "$i" 2> /dev/null + done + iptables_remove_rule + rm /var/etc/natter.include 2> /dev/null + rm -r /var/etc/natter 2> /dev/null + rm -r /tmp/natter 2> /dev/null +} + +iptables_remove_rule() { + echo "Removing iptable rules ..." + iptables -D INPUT -j natter 2> /dev/null + iptables -F natter 2> /dev/null + iptables -X natter 2> /dev/null + iptables-save | grep -v 'nt-dnat' | iptables-restore +} + +stop() { + stop_service +} + +start() { + start_service +} + +restart() { + stop + start +} +service_triggers() { + procd_add_reload_trigger "natter" +} + +uci_get_by_type() { + local ret=$(uci get natter.@$1[$2].$3 2>/dev/null) + echo ${ret:=$4} +} diff --git a/luci-app-natter/root/etc/uci-defaults/luci-natter b/luci-app-natter/root/etc/uci-defaults/luci-natter new file mode 100755 index 000000000..eb13c32e9 --- /dev/null +++ b/luci-app-natter/root/etc/uci-defaults/luci-natter @@ -0,0 +1,17 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@natter[-1] + add ucitrack natter + set ucitrack.@natter[-1].init=natter + commit ucitrack + + delete firewall.natter + set firewall.natter=include + set firewall.natter.type=script + set firewall.natter.path=/var/etc/natter.include + set firewall.natter.reload=1 + commit firewall +EOF + +exit 0 \ No newline at end of file diff --git a/luci-app-natter/root/usr/share/luci-app-natter/log.sh b/luci-app-natter/root/usr/share/luci-app-natter/log.sh new file mode 100755 index 000000000..4b37db7de --- /dev/null +++ b/luci-app-natter/root/usr/share/luci-app-natter/log.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +log_path=$(uci get natter.@base[0].log_path 2> /dev/null) + +for i in $(ls -1 ${log_path} | grep natter | grep .log) +do + case $1 in + print) + echo -e "\n======> $i <======" + tail -n 30 ${log_path}/$i 2> /dev/null + echo -e "======> END of $i <======" + ;; + del) + echo > ${log_path}/$i + ;; + esac +done + +exit 0 diff --git a/luci-app-natter/root/usr/share/luci-app-natter/natcheck.sh b/luci-app-natter/root/usr/share/luci-app-natter/natcheck.sh new file mode 100755 index 000000000..01d31a20d --- /dev/null +++ b/luci-app-natter/root/usr/share/luci-app-natter/natcheck.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# Check=$(python3 /usr/share/natter/natter.py --check-nat 2>&1 | grep -v "Checking" | grep 'NAT Type for') + +script_file='/usr/share/natter/natter.py' +tmp_path=$(uci get natter.@base[0].log_path) +[ ! "$tmp_path" ] && tmp_path=/tmp/natter + +mkdir -p $tmp_path +python3 $script_file --check-nat 2>&1 | grep -v "Checking" | grep 'NAT Type for' > $tmp_path/natter_nat_type.tmp +TCP=$(awk -F '[:]+' '/TCP/{print $2}' $tmp_path/natter_nat_type.tmp | sed 's/\[//g;s/\]//g') +UDP=$(awk -F '[:]+' '/UDP/{print $2}' $tmp_path/natter_nat_type.tmp | sed 's/\[//g;s/\]//g') +rm -f $tmp_path/natter_nat_type.tmp +[ ! "$TCP" ] && TCP="未知" +[ ! "$UDP" ] && UDP="未知" + +echo "TCP:$TCP" +echo "UDP:$UDP" diff --git a/luci-app-natter/root/usr/share/rpcd/acl.d/luci-app-natter.json b/luci-app-natter/root/usr/share/rpcd/acl.d/luci-app-natter.json new file mode 100644 index 000000000..fbe0d8a20 --- /dev/null +++ b/luci-app-natter/root/usr/share/rpcd/acl.d/luci-app-natter.json @@ -0,0 +1,11 @@ +{ + "luci-app-natter": { + "description": "Grant UCI access for luci-app-natter", + "read": { + "uci": [ "natter" ] + }, + "write": { + "uci": [ "natter" ] + } + } +} diff --git a/luci-app-npc/Makefile b/luci-app-npc/Makefile new file mode 100755 index 000000000..9dfa4f6cb --- /dev/null +++ b/luci-app-npc/Makefile @@ -0,0 +1,14 @@ +# Copyright (C) 2008-2014 The LuCI Team +# Copyright (C) 2020-2021 Hyy2001X + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI support for NPS Client(NPC) +LUCI_DEPENDS:=+npc +LUCI_PKGARCH:=all +PKG_VERSION:=1.3 +PKG_RELEASE:=2 + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-npc/README.md b/luci-app-npc/README.md new file mode 100755 index 000000000..ac6e6d0c9 --- /dev/null +++ b/luci-app-npc/README.md @@ -0,0 +1,11 @@ +# luci-app-npc + +## 修改内容 + + - 解除原有服务端仅 IPv4 地址的限制 + + - 添加[速度限制] [流量限制] [最大连接数] 等多个选项 + +## Based on + + - [lede](https://github.com/coolsnowwolf/lede/tree/master/package/lean/luci-app-nps) diff --git a/luci-app-npc/luasrc/controller/npc.lua b/luci-app-npc/luasrc/controller/npc.lua new file mode 100755 index 000000000..54f1cf79a --- /dev/null +++ b/luci-app-npc/luasrc/controller/npc.lua @@ -0,0 +1,17 @@ +module("luci.controller.npc",package.seeall) + +function index() + if not nixio.fs.access("/etc/config/npc") then + return + end + + entry({"admin", "services", "npc"}, cbi("npc"), _("NPS Client"), 99).dependent = true + entry({"admin", "services", "npc", "status"}, call("act_status")).leaf = true +end + +function act_status() + local e = {} + e.running = luci.sys.call("pgrep npc > /dev/null") == 0 + luci.http.prepare_content("application/json") + luci.http.write_json(e) +end diff --git a/luci-app-npc/luasrc/model/cbi/npc.lua b/luci-app-npc/luasrc/model/cbi/npc.lua new file mode 100755 index 000000000..5e8c45de5 --- /dev/null +++ b/luci-app-npc/luasrc/model/cbi/npc.lua @@ -0,0 +1,50 @@ +m = Map("npc", translate("NPS Client"), translate("Nps is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.")) + +m:section(SimpleSection).template = "npc/npc_status" + +s = m:section(TypedSection,"npc") +s.addremove = false +s.anonymous = true + +enable = s:option(Flag, "enable", translate("Enable")) +enable.rmempty = false +enable.default = "0" + +server = s:option(Value, "server_addr", translate("Server Address"), translate("IPv4 address or Domain Name")) +server.rmempty = false + +port = s:option(Value, "server_port", translate("Port")) +port.datatype = "port" +port.default = "8024" +port.rmempty = false + +vkey = s:option(Value, "vkey", translate("vkey")) +vkey.password = true +vkey.rmempty = false + +protocol = s:option(ListValue, "protocol", translate("Protocol Type")) +protocol.default = "tcp" +protocol:value("tcp", translate("TCP Protocol")) +protocol:value("kcp", translate("KCP Protocol")) + +max_conn = s:option(Value, "max_conn", translate("Max Connection Limit"), translate("Maximum number of connections (Not necessary)")) +max_conn.optional = true +max_conn.rmempty = true + +rate_limit = s:option(Value, "rate_limit", translate("Rate Limit"), translate("Client rate limit (Not necessary)")) +rate_limit.optional = true +rate_limit.rmempty = true + +flow_limit = s:option(Value, "flow_limit", translate("Flow Limit"), translate("Client flow limit (Not necessary)")) +flow_limit.optional = true +flow_limit.rmempty = true + +compress = s:option(Flag, "compress", translate("Enable Compression"), translate("The contents will be compressed to speed up the traffic forwarding speed, but this will consume some additional cpu resources.")) +compress.default = "0" +compress.rmempty = false + +crypt = s:option(Flag, "crypt", translate("Enable Encryption"), translate("Encrypted the communication between Npc and Nps, will effectively prevent the traffic intercepted.")) +crypt.default = "0" +crypt.rmempty = false + +return m diff --git a/luci-app-npc/luasrc/view/npc/npc_status.htm b/luci-app-npc/luasrc/view/npc/npc_status.htm new file mode 100755 index 000000000..55897428e --- /dev/null +++ b/luci-app-npc/luasrc/view/npc/npc_status.htm @@ -0,0 +1,22 @@ + + +
+

+ <%:Collecting data...%> +

+
diff --git a/luci-app-npc/po/zh-cn/npc.po b/luci-app-npc/po/zh-cn/npc.po new file mode 100755 index 000000000..c039622dd --- /dev/null +++ b/luci-app-npc/po/zh-cn/npc.po @@ -0,0 +1,56 @@ +msgid "NPS Client" +msgstr "NPS 内网穿透客户端" + +msgid "Nps is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet." +msgstr "NPS 是一种快速反向代理,可帮助您将 NAT 或防火墙后的本地服务器公开到 Internet" + +msgid "IPv4 address or Domain Name" +msgstr "服务器域名或 IPv4 地址" + +msgid "vkey" +msgstr "唯一验证密钥(vkey)" + +msgid "Enable Compression" +msgstr "压缩传输" + +msgid "Enable Encryption" +msgstr "加密传输" + +msgid "The contents will be compressed to speed up the traffic forwarding speed, but this will consume some additional cpu resources." +msgstr "启用压缩传输内容会加快流量转发速度,但是会额外消耗 CPU 资源" + +msgid "Encrypted the communication between Npc and Nps, will effectively prevent the traffic intercepted." +msgstr "启用加密传输客户端与服务端之间的通信内容,会有效防止流量被拦截" + +msgid "Basic Setting" +msgstr "基本设置" + +msgid "Protocol Type" +msgstr "协议类型" + +msgid "Server Address" +msgstr "服务端地址" + +msgid "TCP Protocol" +msgstr "TCP" + +msgid "KCP Protocol" +msgstr "KCP" + +msgid "Max Connection Limit" +msgstr "连接数限制" + +msgid "Maximum number of connections (Not necessary)" +msgstr "最大连接数限制 (可选,非必须)" + +msgid "Rate Limit" +msgstr "速度限制" + +msgid "Client rate limit (Not necessary)" +msgstr "客户端速度限制 (可选,非必须)" + +msgid "Flow Limit" +msgstr "流量限制" + +msgid "Client flow limit (Not necessary)" +msgstr "客户端流量限制 (可选,非必须)" diff --git a/luci-app-npc/po/zh_Hans/npc.po b/luci-app-npc/po/zh_Hans/npc.po new file mode 100755 index 000000000..c039622dd --- /dev/null +++ b/luci-app-npc/po/zh_Hans/npc.po @@ -0,0 +1,56 @@ +msgid "NPS Client" +msgstr "NPS 内网穿透客户端" + +msgid "Nps is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet." +msgstr "NPS 是一种快速反向代理,可帮助您将 NAT 或防火墙后的本地服务器公开到 Internet" + +msgid "IPv4 address or Domain Name" +msgstr "服务器域名或 IPv4 地址" + +msgid "vkey" +msgstr "唯一验证密钥(vkey)" + +msgid "Enable Compression" +msgstr "压缩传输" + +msgid "Enable Encryption" +msgstr "加密传输" + +msgid "The contents will be compressed to speed up the traffic forwarding speed, but this will consume some additional cpu resources." +msgstr "启用压缩传输内容会加快流量转发速度,但是会额外消耗 CPU 资源" + +msgid "Encrypted the communication between Npc and Nps, will effectively prevent the traffic intercepted." +msgstr "启用加密传输客户端与服务端之间的通信内容,会有效防止流量被拦截" + +msgid "Basic Setting" +msgstr "基本设置" + +msgid "Protocol Type" +msgstr "协议类型" + +msgid "Server Address" +msgstr "服务端地址" + +msgid "TCP Protocol" +msgstr "TCP" + +msgid "KCP Protocol" +msgstr "KCP" + +msgid "Max Connection Limit" +msgstr "连接数限制" + +msgid "Maximum number of connections (Not necessary)" +msgstr "最大连接数限制 (可选,非必须)" + +msgid "Rate Limit" +msgstr "速度限制" + +msgid "Client rate limit (Not necessary)" +msgstr "客户端速度限制 (可选,非必须)" + +msgid "Flow Limit" +msgstr "流量限制" + +msgid "Client flow limit (Not necessary)" +msgstr "客户端流量限制 (可选,非必须)" diff --git a/luci-app-npc/root/etc/config/npc b/luci-app-npc/root/etc/config/npc new file mode 100755 index 000000000..149367260 --- /dev/null +++ b/luci-app-npc/root/etc/config/npc @@ -0,0 +1,6 @@ + +config npc + option enable '0' + option server_addr '1.2.3.4' + option vkey 'abcdefg' + diff --git a/luci-app-npc/root/etc/init.d/npc b/luci-app-npc/root/etc/init.d/npc new file mode 100755 index 000000000..783340531 --- /dev/null +++ b/luci-app-npc/root/etc/init.d/npc @@ -0,0 +1,67 @@ +#!/bin/sh /etc/rc.common + +START=95 +USE_PROCD=1 +LOGGER="logger -t [NPC]" + +npc_Path="$(command -v npc)" +conf_Path="/tmp/etc/npc.conf" + +start_service() { + local basic_list="enable server_addr server_port protocol vkey max_conn rate_limit flow_limit compress crypt" + for i in $(echo $basic_list);do + local eval $i="$(uci_get_by_type npc 0 $i)" + done;unset i + + [ -s "$conf_Path" ] && rm -f $conf_Path + echo "[common]" > $conf_Path || { + ${LOGGER} "Failed to create config,exit ..." + exit 1 + } + echo "server_addr=${server_addr}:${server_port}" >> $conf_Path + echo "conn_type=${protocol}" >> $conf_Path + echo "vkey=${vkey}" >> $conf_Path + echo "auto_reconnection=true" >> $conf_Path + [ -n "$max_conn" ] && echo "max_conn=${max_conn}" >> $conf_Path + [ -n "$rate_limit" ] && echo "rate_limit=${rate_limit}" >> $conf_Path + [ -n "$flow_limit" ] && echo "flow_limit=${flow_limit}" >> $conf_Path + conf_write_bool compress $compress + conf_write_bool crypt $crypt + + if [ "$enable" = 1 ] + then + ${LOGGER} "Starting NPS Client(NPC) ..." + procd_open_instance + procd_set_param command $npc_Path -config=$conf_Path + procd_set_param respawn + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_close_instance + else + ${LOGGER} "NPS Client(NPC) Service is now disabled ..." + fi +} + +stop_service() { + $LOGGER "Stopping NPS Client(NPC) ..." + rm -f $conf_Path +} + +service_triggers() { + procd_add_reload_trigger "npc" +} + +conf_write_bool() { + if [ "$2" == 0 ] + then + echo "$1=false" >> $conf_Path + else + echo "$1=true" >> $conf_Path + fi + return +} + +uci_get_by_type() { + local ret=$(uci get npc.@$1[$2].$3 2>/dev/null) + echo ${ret:=$4} +} diff --git a/luci-app-npc/root/etc/uci-defaults/luci-npc b/luci-app-npc/root/etc/uci-defaults/luci-npc new file mode 100755 index 000000000..8f6dc3789 --- /dev/null +++ b/luci-app-npc/root/etc/uci-defaults/luci-npc @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@npc[-1] + add ucitrack npc + set ucitrack.@npc[-1].init=npc + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 diff --git a/luci-app-npc/root/usr/share/rpcd/acl.d/luci-app-npc.json b/luci-app-npc/root/usr/share/rpcd/acl.d/luci-app-npc.json new file mode 100644 index 000000000..a2412b294 --- /dev/null +++ b/luci-app-npc/root/usr/share/rpcd/acl.d/luci-app-npc.json @@ -0,0 +1,11 @@ +{ + "luci-app-npc": { + "description": "Grant UCI access for luci-app-npc", + "read": { + "uci": [ "npc" ] + }, + "write": { + "uci": [ "npc" ] + } + } +} diff --git a/luci-app-shutdown/Makefile b/luci-app-shutdown/Makefile new file mode 100755 index 000000000..2e6116e84 --- /dev/null +++ b/luci-app-shutdown/Makefile @@ -0,0 +1,13 @@ +# Copyright (C) 2020-2021 Hyy2001X + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI Support for Shutdown Target +PKG_NAME:=luci-app-shutdown +PKG_VERSION:=1.0 +PKG_RELEASE:=1 +LUCI_PKGARCH:=all + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-shutdown/README.md b/luci-app-shutdown/README.md new file mode 100755 index 000000000..4a77844c2 --- /dev/null +++ b/luci-app-shutdown/README.md @@ -0,0 +1,3 @@ +## luci-app-shutdown + +一键关闭/重启设备 diff --git a/luci-app-shutdown/luasrc/controller/shutdown.lua b/luci-app-shutdown/luasrc/controller/shutdown.lua new file mode 100755 index 000000000..09792f1a8 --- /dev/null +++ b/luci-app-shutdown/luasrc/controller/shutdown.lua @@ -0,0 +1,5 @@ +module("luci.controller.shutdown",package.seeall) + +function index() + entry({"admin", "system", "shutdown"}, cbi("shutdown"), _("Shutdown"),99) +end diff --git a/luci-app-shutdown/luasrc/model/cbi/shutdown.lua b/luci-app-shutdown/luasrc/model/cbi/shutdown.lua new file mode 100755 index 000000000..6a006ce24 --- /dev/null +++ b/luci-app-shutdown/luasrc/model/cbi/shutdown.lua @@ -0,0 +1,23 @@ +require("luci.sys") + +m = SimpleForm("shutdown", translate("Shutdown/Reboot"), + translate("Shut down / restart the system on your device")) + +s = m:section(SimpleSection) + +button_shutdown = s:option (Button, "button_shutdown", translate("Shutdown"), translatef("Please wait for the device to shut down")) +button_shutdown.inputtitle = translate ("Do shutdown") +button_shutdown.write = function() + luci.sys.call("sync && poweroff > /dev/null") +end + +button_reboot = s:option (Button, "button_reboot", translate("Reboot"), translatef("Please wait a minutes until the device restart")) +button_reboot.inputtitle = translate ("Do reboot") +button_reboot.write = function() + luci.sys.call("sync && reboot > /dev/null") +end + +m.reset = false +m.submit = false + +return m diff --git a/luci-app-shutdown/po/zh-cn/shutdown.po b/luci-app-shutdown/po/zh-cn/shutdown.po new file mode 100755 index 000000000..bb258f790 --- /dev/null +++ b/luci-app-shutdown/po/zh-cn/shutdown.po @@ -0,0 +1,23 @@ +msgid "Shutdown" +msgstr "关机" + +msgid "Do shutdown" +msgstr "执行关机" + +msgid "Do reboot" +msgstr "执行重启" + +msgid "Reboot" +msgstr "重启" + +msgid "Shutdown/Reboot" +msgstr "关机/重启" + +msgid "Shut down / restart the system on your device" +msgstr "一键关闭/重启您设备上的系统" + +msgid "Please wait a minutes until the device restart" +msgstr "点击后请耐心等待 1-2 分钟直至设备重启成功" + +msgid "Please wait for the device to shut down" +msgstr "点击后请耐心等待设备关闭" diff --git a/luci-app-shutdown/po/zh_Hans/shutdown.po b/luci-app-shutdown/po/zh_Hans/shutdown.po new file mode 100755 index 000000000..bb258f790 --- /dev/null +++ b/luci-app-shutdown/po/zh_Hans/shutdown.po @@ -0,0 +1,23 @@ +msgid "Shutdown" +msgstr "关机" + +msgid "Do shutdown" +msgstr "执行关机" + +msgid "Do reboot" +msgstr "执行重启" + +msgid "Reboot" +msgstr "重启" + +msgid "Shutdown/Reboot" +msgstr "关机/重启" + +msgid "Shut down / restart the system on your device" +msgstr "一键关闭/重启您设备上的系统" + +msgid "Please wait a minutes until the device restart" +msgstr "点击后请耐心等待 1-2 分钟直至设备重启成功" + +msgid "Please wait for the device to shut down" +msgstr "点击后请耐心等待设备关闭" diff --git a/luci-app-webd/Makefile b/luci-app-webd/Makefile new file mode 100755 index 000000000..7ebeb2321 --- /dev/null +++ b/luci-app-webd/Makefile @@ -0,0 +1,25 @@ +# Copyright (C) 2020-2021 Hyy2001X + +include $(TOPDIR)/rules.mk + +PKG_NAME:=luci-app-webd +PKG_VERSION:=1.3 +PKG_RELEASE:=3 + +LUCI_TITLE:=LuCI support for Webd Netdisk +LUCI_PKGARCH:=all + +LUCI_DEPENDS:= \ + +PACKAGE_$(PKG_NAME)_INCLUDE_WEBD_BINARY:webd + +define Package/$(PKG_NAME)/config + +config PACKAGE_$(PKG_NAME)_INCLUDE_WEBD_BINARY + bool "Include webd Binary" + default y + +endef + +include $(TOPDIR)/feeds/luci/luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-webd/README.md b/luci-app-webd/README.md new file mode 100644 index 000000000..eda3ec5cd --- /dev/null +++ b/luci-app-webd/README.md @@ -0,0 +1,3 @@ +# luci-app-webd + +项目地址: https://webd.cf/ diff --git a/luci-app-webd/luasrc/controller/webd.lua b/luci-app-webd/luasrc/controller/webd.lua new file mode 100755 index 000000000..65bf78d04 --- /dev/null +++ b/luci-app-webd/luasrc/controller/webd.lua @@ -0,0 +1,17 @@ +module("luci.controller.webd",package.seeall) + +function index() + if not nixio.fs.access("/etc/config/webd") then + return + end + + entry({"admin", "nas", "webd"}, cbi("webd"), _("Webd Netdisk"),99) + entry({"admin", "nas", "webd", "status"}, call("act_status")).leaf = true +end + +function act_status() + local e = {} + e.running = luci.sys.call("pgrep webd > /dev/null") == 0 + luci.http.prepare_content("application/json") + luci.http.write_json(e) +end diff --git a/luci-app-webd/luasrc/model/cbi/webd.lua b/luci-app-webd/luasrc/model/cbi/webd.lua new file mode 100755 index 000000000..386d48b58 --- /dev/null +++ b/luci-app-webd/luasrc/model/cbi/webd.lua @@ -0,0 +1,82 @@ +m = Map("webd", translate("Webd Netdisk"), +translate("Webd - A lightweight self hosted netdisk") +.. [[ ]] +.. translate("Official Website") +.. [[]] +) + +m:section(SimpleSection).template = "webd/webd_status" + +s = m:section(TypedSection, "webd", translate("Basic Settings"), translate("Set the basic settings of Webd Netdisk")) +s.anonymous = true + +enable = s:option(Flag, "enable", translate("Enable")) +enable.default = 0 + +port = s:option(Value, "webd_port", translate("Listening Port")) +port.datatype = "port" +port.default = "9212" +port.rmempty = false + +enable_ipv6 = s:option(Flag, "enable_ipv6", translate("Listen IPv6"), translatef("Listen both IPv4 and IPv6 Address")) +enable_ipv6.default = 0 + +root = s:option(Value, "webd_root", translate("Local Directory"), translatef("Directory of Webd Netdisk")) +root.default = "/mnt" +root.rmempty = false + +enable_recyclebin = s:option(Flag, "enable_recyclebin", translate("Recycle Bin"), translatef("Automatically create recycle bin directory")) +enable_recyclebin.default = 1 + +enable_anonymous = s:option(Flag, "enable_anonymous", translate("Enable Anonymous Access"), translatef("Anonymous access is allowed when enabled (Not Safe)")) +enable_anonymous.default = 0 + +anonymous_perm = s:option(MultiValue, "anonymous_perm", translate("Anonymous Permission")) +anonymous_perm:value("r", translate("Read files")) +anonymous_perm:value("l", translate("Obtain file list")) +anonymous_perm:value("u", translate("Upload files")) +anonymous_perm:value("m", translate("Remove files")) +anonymous_perm:value("S", translate("Show hidden files")) +anonymous_perm:value("T", translate("Play media")) +anonymous_perm:depends("enable_anonymous", "1") +anonymous_perm.description = translate("At least one permission must be choosed to allow anonymous access") + +webd_bin = s:option(Value, "webd_bin", translate("Binary Path"), translatef("Webd Netdisk binary Path")) +webd_bin.default = "/usr/bin/webd" +webd_bin.rmempty = false + +webd_conf = s:option(Value, "webd_conf", translate("Config Path"), translatef("Webd Netdisk config Path")) +webd_conf.default = "/etc/webd.conf" +webd_conf.rmempty = false + +s = m:section(TypedSection, "users", translate("User Settings"), translate("Set the username, password and permissions. Maximum for 2 accounts")) +s.anonymous = true +s.addremove = true +s.template = "cbi/tblsection" + +username = s:option(Value, "username", translate("Username")) +username.rmempty = false + +password = s:option(Value, "password", translate("Password")) +password.rmempty = false +password.password=false + +enable_read = s:option(Flag, "enable_read", translate("Read files")) +enable_read.default = 1 + +enable_read_list = s:option(Flag, "enable_read_list", translate("Obtain file list")) +enable_read_list.default = 1 + +enable_upload = s:option(Flag, "enable_upload", translate("Upload files")) +enable_upload.default = 1 + +enable_move = s:option(Flag, "enable_move", translate("Remove files")) +enable_move.default = 1 + +enable_showhide = s:option(Flag, "enable_showhide", translate("Show hidden files")) +enable_showhide.default = 0 + +enable_play = s:option(Flag, "enable_play", translate("Play media")) +enable_play.default = 1 + +return m diff --git a/luci-app-webd/luasrc/view/webd/webd_status.htm b/luci-app-webd/luasrc/view/webd/webd_status.htm new file mode 100755 index 000000000..2df3e910d --- /dev/null +++ b/luci-app-webd/luasrc/view/webd/webd_status.htm @@ -0,0 +1,27 @@ + + +
+

+ <%:Collecting data...%> +

+
\ No newline at end of file diff --git a/luci-app-webd/po/zh-cn/webd.po b/luci-app-webd/po/zh-cn/webd.po new file mode 100755 index 000000000..b5ded6714 --- /dev/null +++ b/luci-app-webd/po/zh-cn/webd.po @@ -0,0 +1,80 @@ +msgid "Webd Netdisk" +msgstr "Webd 网盘" + +msgid "Official Website" +msgstr "官网" + +msgid "Basic Settings" +msgstr "基础设置" + +msgid "Set the basic settings of Webd Netdisk" +msgstr "配置 Webd 网盘的基础设置" + +msgid "Listening Port" +msgstr "监听端口" + +msgid "Webd - A lightweight self hosted netdisk" +msgstr "Webd 是一款轻量级的 (self-hosted) 自建网盘软件, 界面简洁易用, 速度快资源占用低" + +msgid "Listen IPv6" +msgstr "监听 IPv6" + +msgid "Listen both IPv4 and IPv6 Address" +msgstr "同时监听 IPv4 和 IPv6 地址" + +msgid "Enable Anonymous Access" +msgstr "允许匿名访问" + +msgid "Anonymous Permission" +msgstr "匿名访问权限" + +msgid "Anonymous access is allowed when enabled (Not Safe)" +msgstr "启用后将允许匿名用户访问 (不安全)" + +msgid "At least one permission must be choosed to allow anonymous access" +msgstr "若要允许匿名访问则勾选至少一个权限" + +msgid "Binary Path" +msgstr "程序路径" + +msgid "Webd Netdisk binary Path" +msgstr "Webd 网盘二进制程序路径" + +msgid "Config Path" +msgstr "配置文件路径" + +msgid "Webd Netdisk config Path" +msgstr "Webd 网盘配置文件路径" + +msgid "Local Directory" +msgstr "本地路径" + +msgid "Directory of Webd Netdisk" +msgstr "Webd 网盘监听路径" + +msgid "Recycle Bin" +msgstr "回收站" + +msgid "Automatically create recycle bin directory" +msgstr "允许自动创建回收站目录" + +msgid "Set the username, password and permissions. Maximum for 2 accounts" +msgstr "设置用户名和密码, 以及单个用户的权限, 最多支持设置两个账号" + +msgid "Read files" +msgstr "读取文件" + +msgid "Obtain file list" +msgstr "获取文件列表" + +msgid "Upload files" +msgstr "上传文件" + +msgid "Remove files" +msgstr "删除或移动文件" + +msgid "Show hidden files" +msgstr "显示隐藏文件" + +msgid "Play media" +msgstr "播放媒体" diff --git a/luci-app-webd/po/zh_Hans/webd.po b/luci-app-webd/po/zh_Hans/webd.po new file mode 100755 index 000000000..b5ded6714 --- /dev/null +++ b/luci-app-webd/po/zh_Hans/webd.po @@ -0,0 +1,80 @@ +msgid "Webd Netdisk" +msgstr "Webd 网盘" + +msgid "Official Website" +msgstr "官网" + +msgid "Basic Settings" +msgstr "基础设置" + +msgid "Set the basic settings of Webd Netdisk" +msgstr "配置 Webd 网盘的基础设置" + +msgid "Listening Port" +msgstr "监听端口" + +msgid "Webd - A lightweight self hosted netdisk" +msgstr "Webd 是一款轻量级的 (self-hosted) 自建网盘软件, 界面简洁易用, 速度快资源占用低" + +msgid "Listen IPv6" +msgstr "监听 IPv6" + +msgid "Listen both IPv4 and IPv6 Address" +msgstr "同时监听 IPv4 和 IPv6 地址" + +msgid "Enable Anonymous Access" +msgstr "允许匿名访问" + +msgid "Anonymous Permission" +msgstr "匿名访问权限" + +msgid "Anonymous access is allowed when enabled (Not Safe)" +msgstr "启用后将允许匿名用户访问 (不安全)" + +msgid "At least one permission must be choosed to allow anonymous access" +msgstr "若要允许匿名访问则勾选至少一个权限" + +msgid "Binary Path" +msgstr "程序路径" + +msgid "Webd Netdisk binary Path" +msgstr "Webd 网盘二进制程序路径" + +msgid "Config Path" +msgstr "配置文件路径" + +msgid "Webd Netdisk config Path" +msgstr "Webd 网盘配置文件路径" + +msgid "Local Directory" +msgstr "本地路径" + +msgid "Directory of Webd Netdisk" +msgstr "Webd 网盘监听路径" + +msgid "Recycle Bin" +msgstr "回收站" + +msgid "Automatically create recycle bin directory" +msgstr "允许自动创建回收站目录" + +msgid "Set the username, password and permissions. Maximum for 2 accounts" +msgstr "设置用户名和密码, 以及单个用户的权限, 最多支持设置两个账号" + +msgid "Read files" +msgstr "读取文件" + +msgid "Obtain file list" +msgstr "获取文件列表" + +msgid "Upload files" +msgstr "上传文件" + +msgid "Remove files" +msgstr "删除或移动文件" + +msgid "Show hidden files" +msgstr "显示隐藏文件" + +msgid "Play media" +msgstr "播放媒体" diff --git a/luci-app-webd/root/etc/config/webd b/luci-app-webd/root/etc/config/webd new file mode 100755 index 000000000..acd693997 --- /dev/null +++ b/luci-app-webd/root/etc/config/webd @@ -0,0 +1,13 @@ + +config webd + option enable '0' + option webd_port '9212' + +config users + option enable_read '1' + option enable_read_list '1' + option enable_upload '1' + option enable_move '1' + option enable_showhide '0' + option username 'root' + option password 'password' diff --git a/luci-app-webd/root/etc/init.d/webd b/luci-app-webd/root/etc/init.d/webd new file mode 100755 index 000000000..65355c365 --- /dev/null +++ b/luci-app-webd/root/etc/init.d/webd @@ -0,0 +1,120 @@ +#!/bin/sh /etc/rc.common + +START=99 +USE_PROCD=1 +LOGGER="logger -t [Webd]" + +start_service() { + local basic_list="enable webd_conf webd_bin webd_port webd_root enable_recyclebin enable_anonymous anonymous_perm enable_ipv6" + local users_list="enable_read enable_read_list enable_upload enable_move enable_showhide" + for i in $(echo $basic_list);do + local eval $i="$(uci_get_by_type webd 0 $i)" + done;unset i + if [ "$enable" == 1 ] + then + [ ! -r "$webd_root" -o ! -d "$webd_root" ] && EXIT "Unable to access $webd_root,exit ..." + [ ! -x "$webd_bin" ] && EXIT "Unable to access $webd_bin,exit ..." + if [ "$enable_recyclebin" == 1 -a ! -d "$webd_root/.Trash" ] + then + ${LOGGER} "Creating Recycle Bin directory ..." + mkdir -p $webd_root/.Trash || EXIT "Failed to create Recycle Bin directory,exit ..." + fi + ${LOGGER} "Removing old config file ..." + rm -f $webd_conf + touch -a $webd_conf || EXIT "Failed to create config,exit ..." + [ "$enable_ipv6" == 1 ] && webd_port="[::]:${webd_port}" + if [ "$enable_anonymous" != 0 ] + then + if [ -n "$anonymous_perm" ] + then + + unset enable_anonymous + for i in $(echo $anonymous_perm);do + enable_anonymous="$enable_anonymous$i" + done + unset i + else + enable_anonymous=0 + uci set webd.@webd[0].enable_anonymous=0 + uci commit webd + fi + fi + echo "Webd.Listen $webd_port" >> $webd_conf + echo "Webd.Root $webd_root" >> $webd_conf + echo "Webd.Guest $enable_anonymous" >> $webd_conf + + for u in 0 1;do + for i in $(echo $users_list);do + eval ${i}=$(uci_get_by_type users $u $i 0) + echo "$users_list" | grep -q $i + [ "$?" == 0 ] && eval perm_bin=$(eval echo '$'perm_bin)$(uci_get_by_type users $u $i) + done + unset i + username=$(uci_get_by_type users $u username) + password=$(uci_get_by_type users $u password) + if [ -n "$username" ] + then + eval perm=$(perm_converter $(eval echo '$'perm_bin) | tail -n 1) + if [ -n "$(eval echo '$'perm)" ] + then + ${LOGGER} "Creating account for User $username ..." + echo "Webd.User $(eval echo '$'perm) $username $password" >> $webd_conf + else + ${LOGGER} "Removing excessive user config ..." + uci delete webd.@users[$u] + uci commit webd + fi + unset perm_bin + fi + done + unset u + ${LOGGER} "Killing old processes ..." + ps -efww | grep "$webd_bin" | awk '{print $1}' | xargs kill -9 2> /dev/null + ${LOGGER} "Starting Webd Netdisk Service ..." + procd_open_instance + procd_set_param command $webd_bin -c $webd_conf + procd_set_param respawn + procd_close_instance + else + stop_service + ${LOGGER} "Webd Netdisk Service is now disabled ..." + fi +} + +stop_service() { + ${LOGGER} "Stopping Webd Netdisk Service ..." +} + +service_triggers() { + procd_add_reload_trigger "webd" +} + +uci_get_by_type() { + local ret=$(uci get webd.@$1[$2].$3 2>/dev/null) + echo ${ret:=$4} +} + +EXIT() { + ${LOGGER} $* + exit +} + +perm_converter() { + local u i=1 + echo $1 | egrep -o [0-1] | while read X + do + if [ "$X" == 1 ] + then + case $i in + 1)u=r;; + 2)u=l;; + 3)u=u;; + 4)u=m;; + 5)u=S;; + esac + [ -n "$u" ] && a="$a$u" + echo "$a" + fi + i=$(($i + 1)) + done +} diff --git a/luci-app-webd/root/etc/uci-defaults/luci-webd b/luci-app-webd/root/etc/uci-defaults/luci-webd new file mode 100755 index 000000000..41934849f --- /dev/null +++ b/luci-app-webd/root/etc/uci-defaults/luci-webd @@ -0,0 +1,11 @@ +#!/bin/sh + +uci -q batch <<-EOF >/dev/null + delete ucitrack.@webd[-1] + add ucitrack webd + set ucitrack.@webd[-1].init=webd + commit ucitrack +EOF + +rm -f /tmp/luci-indexcache +exit 0 diff --git a/luci-app-webd/root/usr/share/rpcd/acl.d/luci-app-webd.json b/luci-app-webd/root/usr/share/rpcd/acl.d/luci-app-webd.json new file mode 100644 index 000000000..8247638a0 --- /dev/null +++ b/luci-app-webd/root/usr/share/rpcd/acl.d/luci-app-webd.json @@ -0,0 +1,11 @@ +{ + "luci-app-webd": { + "description": "Grant UCI access for luci-app-webd", + "read": { + "uci": [ "webd" ] + }, + "write": { + "uci": [ "webd" ] + } + } +} diff --git a/natter/Makefile b/natter/Makefile new file mode 100755 index 000000000..4d2ab4e3a --- /dev/null +++ b/natter/Makefile @@ -0,0 +1,40 @@ +# Copyright (C) 2020-2022 Hyy2001X + +include $(TOPDIR)/rules.mk + +PKG_NAME:=natter +PKG_VERSION=0.9 +PKG_RELEASE:=$(AUTORELEASE) +PKG_SOURCE_VERSION:=42005887f95dcfdfd5ed995bf237003f2f80ccfd + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_SOURCE_VERSION) +PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/MikeWang000000/Natter/tar.gz/$(PKG_SOURCE_VERSION)? +PKG_HASH:=skip + +include $(INCLUDE_DIR)/package.mk + +define Package/$(PKG_NAME) + SECTION:=net + CATEGORY:=Network + TITLE:=Open Port under FullCone NAT (NAT 1) + URL:=https://github.com/MikeWang000000/Natter + DEPENDS:=+python3-light +iptables-mod-fullconenat +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + tar -zxvf $(DL_DIR)/$(PKG_SOURCE) -C $(PKG_BUILD_DIR) +endef + +define Build/Compile +endef + +define Package/$(PKG_NAME)/install + $(INSTALL_DIR) $(1)/usr/share/$(PKG_NAME) + $(INSTALL_BIN) $(PKG_BUILD_DIR)/Natter-$(PKG_SOURCE_VERSION)/natter.py $(1)/usr/share/$(PKG_NAME)/natter.py + $(INSTALL_BIN) $(PKG_BUILD_DIR)/Natter-$(PKG_SOURCE_VERSION)/natter-config.template.json $(1)/usr/share/$(PKG_NAME)/natter-config.template.json + $(INSTALL_BIN) $(PKG_BUILD_DIR)/Natter-$(PKG_SOURCE_VERSION)/natter-hook.sh $(1)/usr/share/$(PKG_NAME)/natter-hook.sh +endef + +$(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/upx-static/Makefile b/upx-static/Makefile index 43fe26f93..80334d156 100755 --- a/upx-static/Makefile +++ b/upx-static/Makefile @@ -3,8 +3,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=upx-static -PKG_VERSION:=4.0.2 -PKG_RELEASE:=1 +PKG_VERSION:=3.96 +PKG_RELEASE:=20220422 ifeq ($(ARCH),x86_64) PKG_ARCH:=amd64 @@ -37,7 +37,7 @@ endif PKG_FILE:=upx-$(PKG_VERSION).tar.xz PKG_URL:=https://github.com/upx/upx/releases/download/v$(PKG_VERSION)/upx-$(PKG_VERSION)-$(PKG_ARCH)_linux.tar.xz PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) -PKG_HASH:=540c512bae2f32995729f74921282b11da2f72e3c0cec2dbd63c91fe9b00b011 +PKG_HASH:=skip include $(INCLUDE_DIR)/package.mk diff --git a/webd/Makefile b/webd/Makefile new file mode 100755 index 000000000..ebd92acb7 --- /dev/null +++ b/webd/Makefile @@ -0,0 +1,93 @@ +# Copyright (C) 2020-2022 Hyy2001X +# See more information at https://webd.cf/ + +include $(TOPDIR)/rules.mk + +PKG_NAME:=webd +PKG_VERSION:=20220512 +PKG_RELEASE:=$(AUTORELESE) + +include $(INCLUDE_DIR)/package.mk + +define Package/$(PKG_NAME) + SECTION:=net + CATEGORY:=Network + TITLE:=A Lightweight self-hosted netdisk application + DEPENDS:=@(arm||x86_64||mipsel||mips||aarch64) + URL:=https://webd.cf +endef + +ifeq ($(ARCH),aarch64) + ifeq ($(BOARD),cortex-a53) + TARGET_ARCH:=aarch64_cortex-a53.brcm2708-bcm2710 + endif + ifeq ($(BOARD),rockchip) + TARGET_ARCH:=aarch64_generic.rockchip-armv8 + endif + ifeq ($(BOARD),mvebu) + TARGET_ARCH:=arm_cortex-a9.mvebu-cortexa9 + endif +endif + +ifeq ($(ARCH),arm) + ifeq ($(BOARD),ipq806x) + TARGET_ARCH:=arm_cortex-a15.ipq806x + endif + ifeq ($(BOARD),ipq40xx) + TARGET_ARCH:=arm_cortex-a7.ipq40xx + endif + ifeq ($(BOARD),bcm53xx) + TARGET_ARCH:=arm_cortex-a9.bcm53xx + endif + ifeq ($(BOARD),oxnas) + TARGET_ARCH:=arm_mpcore.oxnas + endif + ifeq ($(BOARD),kirkwood) + TARGET_ARCH:=arm_xscale.kirkwood + endif +endif + +ifeq ($(ARCH),mipsel) + ifeq ($(BOARD),bcm47xx) + TARGET_ARCH:=mipsel_74kc.brcm47xx-mips74k + endif + ifeq ($(BOARD),ramips) + TARGET_ARCH:=mipsel_24kc.ramips-mt7620 + endif +endif + +ifeq ($(ARCH),mips) + ifeq ($(BOARD),ath79) + TARGET_ARCH:=mips_24kc.ath79 + endif + ifeq ($(BOARD),bcm63xx) + TARGET_ARCH:=mips_mips32.brcm63xx-uClibc + endif +endif + +ifeq ($(ARCH),x86_64) + TARGET_ARCH:=x86-64 +endif + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-openwrt-$(TARGET_ARCH).tar.gz +PKG_SOURCE_URL:=https://gwgw.ga/webd/$(PKG_VERSION)/ +PKG_HASH:=skip + +UNTAR_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) + +define Build/Prepare + mkdir -p $(UNTAR_DIR) + tar -zxvf $(DL_DIR)/$(PKG_SOURCE) -C $(UNTAR_DIR) +endef + +define Build/Compile +endef + +define Package/$(PKG_NAME)/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(UNTAR_DIR)/webd/webd $(1)/usr/bin + $(INSTALL_DIR) $(1)/usr/share/$(PKG_NAME) + $(INSTALL_BIN) $(UNTAR_DIR)/webd/web/.player.htm $(1)/usr/share/$(PKG_NAME) +endef + +$(eval $(call BuildPackage,$(PKG_NAME)))