diff --git a/third-party/luci-app-udp2raw/Makefile b/third-party/luci-app-udp2raw/Makefile index 8ce589e..66541e1 100644 --- a/third-party/luci-app-udp2raw/Makefile +++ b/third-party/luci-app-udp2raw/Makefile @@ -9,17 +9,15 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-udp2raw PKG_VERSION:=1.0.0 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_LICENSE:=GPLv3 PKG_LICENSE_FILES:=LICENSE PKG_MAINTAINER:=Jian Chang -PKG_BUILD_PARALLEL:=1 - include $(INCLUDE_DIR)/package.mk -define Package/luci-app-udp2raw +define Package/$(PKG_NAME) SECTION:=luci CATEGORY:=LuCI SUBMENU:=3. Applications @@ -28,7 +26,7 @@ define Package/luci-app-udp2raw DEPENDS:=+udp2raw-tunnel endef -define Package/luci-app-udp2raw/description +define Package/$(PKG_NAME)/description LuCI Support for udp2raw-tunnel. endef @@ -43,28 +41,27 @@ endef define Build/Compile endef -define Package/luci-app-udp2raw/postinst +define Package/$(PKG_NAME)/postinst #!/bin/sh if [ -z "$${IPKG_INSTROOT}" ]; then ( . /etc/uci-defaults/luci-udp2raw ) && rm -f /etc/uci-defaults/luci-udp2raw - rm -rf /tmp/luci-indexcache /tmp/luci-modulecache fi exit 0 endef -define Package/luci-app-udp2raw/conffiles -/etc/config/udp2raw +define Package/$(PKG_NAME)/conffiles + /etc/config/udp2raw endef -define Package/luci-app-udp2raw/install +define Package/$(PKG_NAME)/install $(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n $(INSTALL_DATA) $(PKG_BUILD_DIR)/udp2raw.*.lmo $(1)/usr/lib/lua/luci/i18n/ $(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller $(INSTALL_DATA) ./files/luci/controller/*.lua $(1)/usr/lib/lua/luci/controller/ $(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/udp2raw $(INSTALL_DATA) ./files/luci/model/cbi/udp2raw/*.lua $(1)/usr/lib/lua/luci/model/cbi/udp2raw/ - $(INSTALL_DIR) $(1)/usr/lib/lua/luci/view - $(INSTALL_DATA) ./files/luci/view/*.htm $(1)/usr/lib/lua/luci/view/ + $(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/udp2raw + $(INSTALL_DATA) ./files/luci/view/udp2raw/*.htm $(1)/usr/lib/lua/luci/view/udp2raw/ $(INSTALL_DIR) $(1)/etc/config $(INSTALL_CONF) ./files/root/etc/config/udp2raw $(1)/etc/config/udp2raw $(INSTALL_DIR) $(1)/etc/init.d @@ -73,4 +70,4 @@ define Package/luci-app-udp2raw/install $(INSTALL_BIN) ./files/root/etc/uci-defaults/luci-udp2raw $(1)/etc/uci-defaults/luci-udp2raw endef -$(eval $(call BuildPackage,luci-app-udp2raw)) +$(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/third-party/luci-app-udp2raw/files/luci/i18n/udp2raw.zh-cn.lmo b/third-party/luci-app-udp2raw/files/luci/i18n/udp2raw.zh-cn.lmo index e25325d..a73a6cf 100644 Binary files a/third-party/luci-app-udp2raw/files/luci/i18n/udp2raw.zh-cn.lmo and b/third-party/luci-app-udp2raw/files/luci/i18n/udp2raw.zh-cn.lmo differ diff --git a/third-party/luci-app-udp2raw/files/luci/i18n/udp2raw.zh-cn.po b/third-party/luci-app-udp2raw/files/luci/i18n/udp2raw.zh-cn.po index fb20472..92c892b 100644 --- a/third-party/luci-app-udp2raw/files/luci/i18n/udp2raw.zh-cn.po +++ b/third-party/luci-app-udp2raw/files/luci/i18n/udp2raw.zh-cn.po @@ -77,7 +77,7 @@ msgid "Cipher Mode" msgstr "加密方式" msgid "Auth Mode" -msgstr "认证方式" +msgstr "验证方式" msgid "Auto Rule" msgstr "自动规则" @@ -89,7 +89,7 @@ msgid "Keep Rule" msgstr "保持规则" msgid "Monitor iptables and auto re-add if necessary." -msgstr "监视 iptables 并在必要时重新添加规则。" +msgstr "定期检查 iptables 并在必要时重新添加规则。" msgid "seq Mode" msgstr "seq 模式" diff --git a/third-party/luci-app-udp2raw/files/luci/model/cbi/udp2raw/general.lua b/third-party/luci-app-udp2raw/files/luci/model/cbi/udp2raw/general.lua index a4d3430..dbd22e9 100644 --- a/third-party/luci-app-udp2raw/files/luci/model/cbi/udp2raw/general.lua +++ b/third-party/luci-app-udp2raw/files/luci/model/cbi/udp2raw/general.lua @@ -18,13 +18,14 @@ uci:foreach("udp2raw", "servers", function(s) end) m = Map("udp2raw", "%s - %s" %{translate("udp2raw-tunnel"), translate("Settings")}) -m:append(Template("udp2raw_status")) +m:append(Template("udp2raw/status")) s = m:section(NamedSection, "general", "general", translate("General Settings")) s.anonymous = true s.addremove = false -o = s:option(ListValue, "server", translate("Server")) +o = s:option(DynamicList, "server", translate("Server")) +o.template = "udp2raw/dynamiclist" o:value("nil", translate("Disable")) for _, s in ipairs(servers) do o:value(s.name, s.alias) end o.default = "nil" diff --git a/third-party/luci-app-udp2raw/files/luci/view/udp2raw/dynamiclist.htm b/third-party/luci-app-udp2raw/files/luci/view/udp2raw/dynamiclist.htm new file mode 100644 index 0000000..7ee3dc9 --- /dev/null +++ b/third-party/luci-app-udp2raw/files/luci/view/udp2raw/dynamiclist.htm @@ -0,0 +1,98 @@ +<%# + Copyright (C) 2017 Jian Chang + Licensed to the public under the GNU General Public License v3. +-%> + +<%+cbi/valueheader%> + +<%- + local values = self:formvalue(section) + if not values then + values = self:cfgvalue(section) or {self.default} + end + + local function serialize_json(x, cb) + local rv, push = nil, cb + if not push then + rv = { } + push = function(tok) rv[#rv+1] = tok end + end + + if x == nil then + push("null") + elseif type(x) == "table" then + push("[") + for k = 1, #x do + if k > 1 then + push(",") + end + serialize_json(x[k], push) + end + push("]") + else + push('"%s"' % tostring(x):gsub('["%z\1-\31\\]', + function(c) return '\\u%04x' % c:byte(1) end)) + end + + if not cb then + return table.concat(rv, "") + end + end +-%> + +> + + +<%+cbi/valuefooter%> diff --git a/third-party/luci-app-udp2raw/files/luci/view/udp2raw/status.htm b/third-party/luci-app-udp2raw/files/luci/view/udp2raw/status.htm new file mode 100644 index 0000000..964b117 --- /dev/null +++ b/third-party/luci-app-udp2raw/files/luci/view/udp2raw/status.htm @@ -0,0 +1,39 @@ +<% +local function get_udp2raw_version(name) + local info = luci.util.split(luci.sys.exec("%s -h 2>/dev/null" %{name}), "\n") + local version = string.match(info[2], "git version:(%w+)") + local build = string.match(info[2], "build date:(.+)") + return info[1] == "udp2raw-tunnel" and version or "", info[1] == "udp2raw-tunnel" and build or "" +end + +local udp2raw_version, udp2raw_build = get_udp2raw_version("udp2raw") +-%> + +
+ <%:Running Status%> + + + + + + <% if udp2raw_build ~= "" then -%> + + <% end -%> + +
<%:Binary Version%> + <% if udp2raw_version == "" then -%> + <%:Invalid Binary File.%> + <% else -%> + <%=pcdata(udp2raw_version)%> + <%- end %> +
<%:Build Time%><%=pcdata(udp2raw_build)%>
<%:Running Status%><%:Collecting data...%>
+
+ + diff --git a/third-party/luci-app-udp2raw/files/root/etc/config/udp2raw b/third-party/luci-app-udp2raw/files/root/etc/config/udp2raw index 8a27625..eaa58ee 100644 --- a/third-party/luci-app-udp2raw/files/root/etc/config/udp2raw +++ b/third-party/luci-app-udp2raw/files/root/etc/config/udp2raw @@ -1,6 +1,6 @@ config general 'general' - option server 'nil' + list server 'nil' option daemon_user 'root' config servers 'default' diff --git a/third-party/luci-app-udp2raw/files/root/etc/init.d/udp2raw b/third-party/luci-app-udp2raw/files/root/etc/init.d/udp2raw index 3733b66..3c960cc 100644 --- a/third-party/luci-app-udp2raw/files/root/etc/init.d/udp2raw +++ b/third-party/luci-app-udp2raw/files/root/etc/init.d/udp2raw @@ -1,51 +1,56 @@ #!/bin/sh /etc/rc.common START=88 +STOP=15 USE_PROCD=1 -UDP2RAW=udp2raw +NAME=udp2raw _log() { - local level="$1" - local msg="$2" - - logger -p "daemon.${level}" -t "$UDP2RAW" "$msg" + logger -p "daemon.$1" -t "$NAME" "$2" } -gen_client_config_file() { +has_valid_server() { + local server + for server in $@; do + [ "$(uci_get $NAME $server)" = "servers" ] && return 0 + done + return 1 +} + +create_config() { local config_file="$1" echo "# auto-generated config file from /etc/config/udp2raw" > $config_file echo "-c" >> $config_file - echo "-l ${listen_addr}:${listen_port}" >> $config_file && _log "info" "listening on: ${listen_addr}:${listen_port}" - echo "-r ${server_addr}:${server_port}" >> $config_file && _log "info" "remote address: ${server_addr}:${server_port}" + echo "-l ${listen_addr:=127.0.0.1}:${listen_port:=2080}" >> $config_file && _log "info" "listening on: ${listen_addr}:${listen_port}" + echo "-r ${server_addr}:${server_port:=8080}" >> $config_file [ -n "$raw_mode" ] && echo "--raw-mode ${raw_mode}" >> $config_file && _log "info" "raw-mode: ${raw_mode}" [ -n "$key" ] && echo "--key ${key}" >> $config_file - [ -n "$cipher_mode" ] && echo "--cipher-mode ${cipher_mode}" >> $config_file && _log "info" "cipher-mode: ${cipher_mode}" - [ -n "$auth_mode" ] && echo "--auth-mode ${auth_mode}" >> $config_file && _log "info" "auth-mode: ${auth_mode}" + [ -n "$cipher_mode" ] && echo "--cipher-mode ${cipher_mode}" >> $config_file + [ -n "$auth_mode" ] && echo "--auth-mode ${auth_mode}" >> $config_file - [ "$auto_rule" -ne 0 ] && echo "--auto-rule" >> $config_file && _log "info" "auto-rule: true" - [ "$auto_rule" -ne 0 -a "$keep_rule" -ne 0 ] && echo "--keep-rule" >> $config_file && _log "info" "keep-rule: true" + [ $auto_rule -eq 1 ] && echo "--auto-rule" >> $config_file + [ $auto_rule -eq 1 -a $keep_rule -eq 1 ] && echo "--keep-rule" >> $config_file - [ -n "$seq_mode" ] && echo "--seq-mode ${seq_mode}" >> $config_file && _log "info" "seq-mode: ${seq_mode}" - [ -n "$lower_level" ] && echo "--lower-level ${lower_level}" >> $config_file && _log "info" "lower-level: ${lower_level}" + [ -n "$seq_mode" ] && echo "--seq-mode ${seq_mode}" >> $config_file + [ -n "$lower_level" ] && echo "--lower-level ${lower_level}" >> $config_file [ -n "$source_ip" ] && echo "--source-ip ${source_ip}" >> $config_file [ -n "$source_port" ] && echo "--source-port ${source_port}" >> $config_file [ -n "$log_level" ] && echo "--log-level ${log_level}" >> $config_file echo "--disable-color" >> $config_file - _log "info" "running from ${daemon_user} user" } validate_config_section() { - uci_validate_section "$UDP2RAW" general "$1" \ + uci_validate_section "$NAME" general "$1" \ 'server:uciname' \ 'daemon_user:string:root' } validate_server_section() { - uci_validate_section "$UDP2RAW" servers "$1" \ + uci_validate_section "$NAME" servers "$1" \ 'server_addr:host' \ 'server_port:port:8080' \ 'listen_addr:ipaddr:127.0.0.1' \ @@ -63,59 +68,49 @@ validate_server_section() { 'log_level:range(0,6)' } -start_udp2raw_instance() { - local section="$1" +start_instance() { + local server="$1" - if ! validate_config_section "$section" ; then - _log "err" "Config validate failed." - return 1 - fi - - if [ -z "$server" ] || [ "$server" = "nil" ]; then + if [ -z "$server" -o "$server" == "nil" ]; then return 0 elif ! validate_server_section "$server"; then _log "err" "Server config validation failed." return 1 - elif [ -z "$server_addr" ]; then + fi + + /sbin/validate_data "ipaddr" "$server_addr" >/dev/null 2>&1 + [ $? -ne 0 ] && server_addr=$(nslookup "$server_addr" | \ + sed -n 's/^Address[[:space:]]*[0-9]*:[[:space:]]*\(\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\)$/\1/p') + if [ -z "$server_addr" ]; then _log "err" "Server address validation failed." return 1 fi - is_ipv6_address() { - echo "$1" | grep -q ":" - } - - is_ipv6_address "$server_addr" && server_addr="[${server_addr}]" - is_ipv6_address "$listen_addr" && listen_addr="[${listen_addr}]" - - _log "notice" "udp2raw-tunnel start." [ -d /var/etc ] || mkdir -p /var/etc - local config_file=/var/etc/${UDP2RAW}.${server}.conf - - if ! ( gen_client_config_file "$config_file" ); then - _log "err" "Can't create config file". - return 1 - fi + local config_file="/var/etc/${NAME}.${server}.conf" + create_config "$config_file" || return 1 procd_open_instance procd_set_param command /usr/bin/udp2raw procd_append_param command --conf-file "$config_file" procd_set_param respawn procd_set_param file "$config_file" - procd_set_param user "$daemon_user" - procd_set_param pidfile /var/run/${UDP2RAW}.${server}.pid + [ -n "$daemon_user" ] && procd_set_param user "$daemon_user" && _log "info" "running from ${daemon_user} user" + procd_set_param pidfile "/var/run/${NAME}.${server}.pid" procd_close_instance } service_triggers() { - procd_add_reload_trigger "$UDP2RAW" + procd_add_reload_trigger "$NAME" } start_service() { - config_load "$UDP2RAW" - config_foreach start_udp2raw_instance "general" -} - -stop_service() { - _log "notice" "udp2raw-tunnel stop." + if ! validate_config_section "general" ; then + _log "err" "Config validate failed." + return 1 + fi + has_valid_server $server || return 1 + for srv in $server; do + start_instance $srv + done } diff --git a/third-party/luci-app-udp2raw/files/root/etc/init.d/udp2raw.init b/third-party/luci-app-udp2raw/files/root/etc/init.d/udp2raw.init new file mode 100644 index 0000000..7232d5f --- /dev/null +++ b/third-party/luci-app-udp2raw/files/root/etc/init.d/udp2raw.init @@ -0,0 +1,130 @@ +#!/bin/sh /etc/rc.common + +START=88 +STOP=15 + +NAME=udp2raw + +_log() { + logger -p "daemon.$1" -t "$NAME" "$2" +} + +has_valid_server() { + local server + for server in $@; do + [ "$(uci_get $NAME $server)" = "servers" ] && return 0 + done + return 1 +} + +create_config() { + local config_file="$1" + echo "# auto-generated config file from /etc/config/udp2raw" > $config_file + + echo "-c" >> $config_file + echo "-l ${listen_addr:=127.0.0.1}:${listen_port:=2080}" >> $config_file + echo "-r ${server_addr}:${server_port:=8080}" >> $config_file + + [ -n "$raw_mode" ] && echo "--raw-mode ${raw_mode}" >> $config_file + [ -n "$key" ] && echo "--key ${key}" >> $config_file + [ -n "$cipher_mode" ] && echo "--cipher-mode ${cipher_mode}" >> $config_file + [ -n "$auth_mode" ] && echo "--auth-mode ${auth_mode}" >> $config_file + + [ $auto_rule -eq 1 ] && echo "--auto-rule" >> $config_file + [ $auto_rule -eq 1 -a $keep_rule -eq 1 ] && echo "--keep-rule" >> $config_file + + [ -n "$seq_mode" ] && echo "--seq-mode ${seq_mode}" >> $config_file + [ -n "$lower_level" ] && echo "--lower-level ${lower_level}" >> $config_file + [ -n "$source_ip" ] && echo "--source-ip ${source_ip}" >> $config_file + [ -n "$source_port" ] && echo "--source-port ${source_port}" >> $config_file + + [ -n "$log_level" ] && echo "--log-level ${log_level}" >> $config_file + echo "--disable-color" >> $config_file +} + +validate_config_section() { + local ret=$(/sbin/validate_data "$NAME" general "$1" \ + 'server:uciname' \ + 'daemon_user:string:root' \ + 2> /dev/null) + [ $? -ne 0 ] && return 1 + eval "$ret" +} + +validate_server_section() { + local ret=$(/sbin/validate_data "$NAME" servers "$1" \ + 'server_addr:host' \ + 'server_port:port:8080' \ + 'listen_addr:ipaddr:127.0.0.1' \ + 'listen_port:port:2080' \ + 'raw_mode:or("faketcp", "udp", "icmp"):faketcp' \ + 'key:string' \ + 'cipher_mode:or("aes128cbc", "xor", "none"):aes128cbc' \ + 'auth_mode:or("md5", "crc32", "simple", "none"):md5' \ + 'auto_rule:bool:1' \ + 'keep_rule:bool:0' \ + 'seq_mode:range(0,4)' \ + 'lower_level:string' \ + 'source_ip:ipaddr' \ + 'source_port:port' \ + 'log_level:range(0,6)' \ + 2> /dev/null) + [ $? -ne 0 ] && return 1 + eval "$ret" +} + +start_instance() { + local server="$1" + + if [ -z "$server" -o "$server" == "nil" ]; then + return 0 + elif ! validate_server_section "$server"; then + _log "err" "Server config validation failed." + return 1 + fi + + /sbin/validate_data "ipaddr" "$server_addr" >/dev/null 2>&1 + [ $? -ne 0 ] && server_addr=$(nslookup "$server_addr" | \ + sed -n 's/^Address[[:space:]]*[0-9]*:[[:space:]]*\(\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\)$/\1/p') + if [ -z "$server_addr" ]; then + _log "err" "Server address validation failed." + return 1 + fi + + [ -d /var/etc ] || mkdir -p /var/etc + local config_file="/var/etc/${NAME}.${server}.conf" + create_config "$config_file" || return 1 + [ -d "/var/log/${NAME}" ] || mkdir -p "/var/log/${NAME}" + + /usr/bin/udp2raw --conf-file "$config_file" >> "/var/log/${NAME}/${NAME}.${server}.log" & + echo $! > "/var/run/${NAME}.${server}.pid" + return 0 +} + +start() { + pgrep "/usr/bin/${NAME}" >/dev/null 2>&1 && return + + if ! validate_config_section "general" ; then + _log "err" "Config validate failed." + return 1 + fi + has_valid_server $server || return 1 + for srv in $server; do + start_instance $srv + done +} + +stop() { + local pids=$(pgrep "/usr/bin/${NAME}" 2> /dev/null) + [ $? -ne 0 ] && return + for pid in $pids; do + kill $pid >/dev/null 2>&1 + done + return 0 +} + +restart() { + stop + sleep 1 + start +} diff --git a/third-party/luci-app-udp2raw/files/root/etc/uci-defaults/luci-udp2raw b/third-party/luci-app-udp2raw/files/root/etc/uci-defaults/luci-udp2raw index c04688e..d8d7b7e 100644 --- a/third-party/luci-app-udp2raw/files/root/etc/uci-defaults/luci-udp2raw +++ b/third-party/luci-app-udp2raw/files/root/etc/uci-defaults/luci-udp2raw @@ -8,11 +8,9 @@ uci -q batch <<-EOF >/dev/null EOF general=$(uci -q get udp2raw.@general[-1]) - if [ -z "$general" ]; then uci -q add udp2raw general fi - if [ ."$general" != ."general" ]; then uci -q batch <<-EOF >/dev/null rename udp2raw.@general[-1]="general" diff --git a/third-party/luci-app-udp2raw/luci-app-udp2raw1.jpg b/third-party/luci-app-udp2raw/luci-app-udp2raw1.jpg index b44fbd5..8369c26 100644 Binary files a/third-party/luci-app-udp2raw/luci-app-udp2raw1.jpg and b/third-party/luci-app-udp2raw/luci-app-udp2raw1.jpg differ diff --git a/third-party/luci-app-udp2raw/luci-app-udp2raw2.jpg b/third-party/luci-app-udp2raw/luci-app-udp2raw2.jpg index e29de68..3228940 100644 Binary files a/third-party/luci-app-udp2raw/luci-app-udp2raw2.jpg and b/third-party/luci-app-udp2raw/luci-app-udp2raw2.jpg differ diff --git a/third-party/luci-app-udp2raw/luci-app-udp2raw3.jpg b/third-party/luci-app-udp2raw/luci-app-udp2raw3.jpg index b8b4e30..214c2cb 100644 Binary files a/third-party/luci-app-udp2raw/luci-app-udp2raw3.jpg and b/third-party/luci-app-udp2raw/luci-app-udp2raw3.jpg differ diff --git a/third-party/udp2raw-openwrt-makefile/Makefile b/third-party/udp2raw-openwrt-makefile/Makefile index 22f7673..44dcae4 100644 --- a/third-party/udp2raw-openwrt-makefile/Makefile +++ b/third-party/udp2raw-openwrt-makefile/Makefile @@ -9,13 +9,13 @@ include $(TOPDIR)/rules.mk PKG_NAME:=udp2raw-tunnel PKG_VERSION:=20171125.0 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://github.com/wangyu-/udp2raw-tunnel.git -PKG_SOURCE_VERSION:=b35edf74865275cdc970384681a1a076d3a8d0e1 +PKG_SOURCE_VERSION:=19b4d456365ea5d44e2fa6e7447e59061f14ef51 PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.xz PKG_LICENSE:=MIT PKG_LICENSE_FILES:=LICENSE @@ -40,12 +40,11 @@ endef MAKE_FLAGS += cross2 -define Build/Prepare - $(PKG_UNPACK) - sed -i 's/cc_cross=.*/cc_cross=$(TARGET_CXX)/g' $(PKG_BUILD_DIR)/makefile - sed -i '/\*gitversion/d' $(PKG_BUILD_DIR)/makefile - echo 'const char *gitversion = "$(PKG_SOURCE_VERSION)";' > $(PKG_BUILD_DIR)/git_version.h - $(Build/Patch) +define Build/Configure + $(call Build/Configure/Default) + $(SED) 's/cc_cross[[:space:]]*=.*/cc_cross=$(TARGET_CXX)/' \ + -e 's/\\".*shell git rev-parse HEAD.*\\"/\\"$(PKG_SOURCE_VERSION)\\"/' \ + $(PKG_BUILD_DIR)/makefile endef define Package/udp2raw-tunnel/install