From 37ae420e2346fb0b9ef83366841389b7cdd7a812 Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Thu, 12 Sep 2024 22:57:33 +0300 Subject: [PATCH 1/8] Add luci package --- luci-app-youtubeUnblock/Makefile | 8 + .../luasrc/controller/youtubeUnblock.lua | 5 + .../luasrc/model/cbi/youtubeUnblock.lua | 160 ++++++++++++++++++ youtubeUnblock/Makefile | 4 +- .../files/etc/init.d/youtubeUnblock | 98 +++++++++++ .../files/etc/uci-defaults/99-youtubeUnblock | 23 +++ .../share/nftables.d}/537-youtubeUnblock.nft | 0 youtubeUnblock/files/youtubeUnblock.owrt | 21 --- 8 files changed, 297 insertions(+), 22 deletions(-) create mode 100644 luci-app-youtubeUnblock/Makefile create mode 100644 luci-app-youtubeUnblock/luasrc/controller/youtubeUnblock.lua create mode 100644 luci-app-youtubeUnblock/luasrc/model/cbi/youtubeUnblock.lua create mode 100755 youtubeUnblock/files/etc/init.d/youtubeUnblock create mode 100644 youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock rename youtubeUnblock/files/{ => usr/share/nftables.d}/537-youtubeUnblock.nft (100%) delete mode 100755 youtubeUnblock/files/youtubeUnblock.owrt diff --git a/luci-app-youtubeUnblock/Makefile b/luci-app-youtubeUnblock/Makefile new file mode 100644 index 0000000..f96b96f --- /dev/null +++ b/luci-app-youtubeUnblock/Makefile @@ -0,0 +1,8 @@ +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI Support for youtubeUnblock +LUCI_DEPENDS:=+luci-base +luci-compat + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-youtubeUnblock/luasrc/controller/youtubeUnblock.lua b/luci-app-youtubeUnblock/luasrc/controller/youtubeUnblock.lua new file mode 100644 index 0000000..cab80c5 --- /dev/null +++ b/luci-app-youtubeUnblock/luasrc/controller/youtubeUnblock.lua @@ -0,0 +1,5 @@ +module("luci.controller.youtubeUnblock", package.seeall) + +function index() + entry( {"admin", "services", "youtubeUnblock"}, cbi("youtubeUnblock"), _("youtubeUnblock")) +end diff --git a/luci-app-youtubeUnblock/luasrc/model/cbi/youtubeUnblock.lua b/luci-app-youtubeUnblock/luasrc/model/cbi/youtubeUnblock.lua new file mode 100644 index 0000000..4d0621b --- /dev/null +++ b/luci-app-youtubeUnblock/luasrc/model/cbi/youtubeUnblock.lua @@ -0,0 +1,160 @@ +local sys = require "luci.sys" +-- local uci = require "luci.model.uci".cursor() +local m = Map("youtubeUnblock", "youtubeUnblock", "Bypasses Deep Packet Inspection (DPI) systems that rely on SNI") +local s = m:section(NamedSection, "youtubeUnblock", "youtubeUnblock", "youtubeUnblock", "Config. Check the README for more details https://github.com/Waujito/youtubeUnblock") + +local o +s:option(Value, "queue_num", "queue num", "The number of netfilter queue youtubeUnblock will be linked to.") +s:option(Flag, "fake_sni", "fake sni", "This flag enables fake-sni which forces youtubeUnblock to send at least three packets instead of one with TLS ClientHello: Fake ClientHello, 1st part of original ClientHello, 2nd part of original ClientHello. This flag may be related to some Operation not permitted error messages, so before open an issue refer to Troubleshooting for EPERMS.") + +o = s:option(ListValue, "faking_strategy", "faking strategy", + [[ + This flag determines the strategy of fake packets invalidation. + + ]]) +o:value("pastseq", "pastseq") +o:value("randseq", "randseq") +o:value("ttl", "ttl") +o:value("tcp_check", "tcp_check") +o.widget="radio" +o:depends("fake_sni", 1) + +o = s:option(Value, "faking_ttl", "faking ttl", "Tunes the time to live (TTL) of fake SNI messages. TTL is specified like that the packet will go through the DPI system and captured by it, but will not reach the destination server.") +o:depends("faking_strategy", "ttl") + +o = s:option(Value, "fake_seq_offset", "fake seq offset", "Tunes the offset from original sequence number for fake packets. Used by randseq faking strategy. If 0, random sequence number will be set.") +o:depends("faking_strategy", "randseq") + +o = s:option(Value, "fake_sni_seq_len", "fake sni seq len", "This flag specifies youtubeUnblock to build a complicated construction of fake client hello packets. length determines how much fakes will be sent.") +o:depends("fake_sni", 1) + +o = s:option(ListValue, "frag", "fragmentation strategy", "Specifies the fragmentation strategy for the packet. Tcp is used by default. Ip fragmentation may be blocked by DPI system. None specifies no fragmentation. Probably this won't work, but may be will work for some fake sni strategies.") +o:value("tcp", "tcp") +o:value("ip", "ip") +o:value("none", "none") +o.widget="radio" + +o = s:option(Flag, "frag_sni_reverse", "frag sni reverse", "Specifies youtubeUnblock to send ClientHello fragments in the reverse order.") +o:depends("frag", "tcp") +o:depends("frag", "ip") + +o = s:option(Flag, "frag_sni_faked", "frag sni faked", "Specifies youtubeUnblock to send fake packets near ClientHello (fills payload with zeroes).") +o:depends("frag", "tcp") +o:depends("frag", "ip") + +o = s:option(Flag, "frag_middle_sni", "frag middle sni", "With this options youtubeUnblock will split the packet in the middle of SNI data.") +o:depends("frag", "tcp") +o:depends("frag", "ip") + +o = s:option(Value, "frag_sni_pos", "frag sni pos", "With this option youtubeUnblock will split the packet at the position pos.") +o:depends("frag", "tcp") +o:depends("frag", "ip") + +o = s:option(Flag, "quic_drop", "drop quic", "Drop all QUIC packets which goes to youtubeUnblock. Won't affect any other UDP packets. Suitable for some TVs. Note, that for this option to work you should also add proxy udp to youtubeUnblock in firewall. connbytes may also be used with udp.") + +o = s:option(Value, "fk_winsize", "frag winsize", "Specifies window size for the fragmented TCP packet. Applicable if you want for response to be fragmented. May slowdown connection initialization. Pass 0 if you don't want this.") +o:depends("frag", "tcp") +o:depends("frag", "ip") + +o = s:option(Flag, "synfake", "synfake", "If 1, syn payload will be sent before each request. The idea is taken from syndata from zapret project. Syn payload will normally be discarded by endpoint but may be handled by TSPU. This option sends normal fake in that payload. Please note, that the option works for all the sites, so --sni-domains won't change anything.") + +o = s:option(Value, "synfake_len", "synfake len", "The fake packet sent in synfake may be too large. If you experience issues, lower up synfake-len. where len stands for how much bytes should be sent as syndata. Pass 0 if you want to send an entire fake packet.") +o:depends("synfake", 1) + +o = s:option(Value, "seg2delay", "seg2delay", "This flag forces youtubeUnblock to wait a little bit before send the 2nd part of the split packet.") + +o = s:option(Flag, "silent", "silent", "Disables verbose mode") +o:depends("trace", 0) + +o = s:option(Flag, "trace", "trace", "Maximum verbosity for debug purposes") +o:depends("silent", 0) + +o = s:option(Flag, "no_gso", "no gso", "Disables support for Google Chrome fat packets which uses GSO. This feature is well tested now, so this flag probably won't fix anything.") + +o = s:option(Flag, "no_ipv6", "disable ipv6", "Disables support for ipv6. May be useful if you don't want for ipv6 socket to be opened.") + +o = s:option(Value, "packet_mark", "packet mark", "Use this option if youtubeUnblock conflicts with other systems rely on packet mark. Note that you may want to change accept rule for iptables to follow the mark.") + +o = s:option(Flag, "all_domains", "Target all domains", "Use this option if you want for every ClientHello to be handled") +o = s:option(DynamicList, "sni_domains", "sni domains", "List of domains you want to be handled by SNI.") +o:depends("all_domains", 0) + +o = s:option(DynamicList, "exclude_domains", "excluded domains", "List of domains to be excluded from targetting.") + +local bs = m:section(NamedSection, "youtubeUnblock", "youtubeUnblock", "Service status") + +local asts = sys.call("/etc/init.d/youtubeUnblock enabled &>/dev/null") + +if asts == 0 then + local asto = bs:option(Button, "_autostart_disable", "Autostart") + asto.inputstyle = "negative" + asto.inputtitle = "Disable" + + asto.write = function(self, section) + sys.call("/etc/init.d/youtubeUnblock disable &>/dev/null") + end +else + local asto = bs:option(Button, "_autostart_enable", "Autostart") + asto.inputstyle = "positive" + asto.inputtitle = "Enable" + + asto.write = function(self, section) + sys.call("/etc/init.d/youtubeUnblock enable &>/dev/null") + end +end + + +local sts = sys.call("/etc/init.d/youtubeUnblock running &>/dev/null") + +if sts == 0 then + local sto = bs:option(Button, "_status_stop", "Status") + sto.inputstyle = "negative" + sto.inputtitle = "Stop" + sto.description = "youtubeUnblock is currently active" + + sto.write = function(self, section) + sys.call("/etc/init.d/youtubeUnblock stop &>/dev/null") + end +else + local sto = bs:option(Button, "_status_start", "Status") + sto.inputstyle = "positive" + sto.inputtitle = "Start" + sto.description = "youtubeUnblock is currently down" + + sto.write = function(self, section) + sys.call("/etc/init.d/youtubeUnblock start &>/dev/null") + end +end + +local rso = bs:option(Button, "_restart", "Restart") +rso.inputstyle = "action" +function rso.write(self, section) + sys.call("/etc/init.d/youtubeUnblock restart &>/dev/null") +end + +local fwo = bs:option(Button, "_firewall", "Firewall") +fwo.inputtitle = "Reload" +fwo.inputstyle = "action" +function fwo.write(self, section) + sys.call("/etc/init.d/firewall reload") +end + +local logs = sys.exec("logread -l 800 -p youtubeUnblock | sed '1!G;h;$!d'") +local o = bs:option(DummyValue, "_logs", "Logs") +o.rawhtml = true +o.value = logs +o.wrap = "off" +o.rows = 33 +o.readonly = true +o.template = "cbi/tvalue" +o.width = "100%" + +m.on_after_commit = function(self, map) + sys.call('/etc/init.d/youtubeUnblock restart &>/dev/null') +end + +return m diff --git a/youtubeUnblock/Makefile b/youtubeUnblock/Makefile index 9470b87..1829ab8 100644 --- a/youtubeUnblock/Makefile +++ b/youtubeUnblock/Makefile @@ -45,7 +45,9 @@ define Package/youtubeUnblock/install $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/build/youtubeUnblock $(1)/usr/bin $(INSTALL_DIR) $(1)/etc/init.d - $(INSTALL_BIN) ./files/youtubeUnblock.owrt $(1)/etc/init.d/youtubeUnblock + $(INSTALL_BIN) ./files/etc/init.d/youtubeUnblock $(1)/etc/init.d/youtubeUnblock + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_BIN) ./files/etc/uci-defaults/99-youtubeUnblock $(1)/etc/uci-defaults/99-youtubeUnblock $(INSTALL_DIR) $(1)/usr/share/nftables.d/ruleset-post/ $(CP) ./files/537-youtubeUnblock.nft $(1)/usr/share/nftables.d/ruleset-post/537-youtubeUnblock.nft endef diff --git a/youtubeUnblock/files/etc/init.d/youtubeUnblock b/youtubeUnblock/files/etc/init.d/youtubeUnblock new file mode 100755 index 0000000..0609f01 --- /dev/null +++ b/youtubeUnblock/files/etc/init.d/youtubeUnblock @@ -0,0 +1,98 @@ +#!/bin/sh /etc/rc.common + +# Thanks @spvkgn https://github.com/spvkgn/ByeDPI-OpenWrt/blob/main/byedpi/files/byedpi.init +# For reference + + +START=91 +USE_PROCD=1 +PROCD_DEBUG=1 +PROG=/usr/bin/youtubeUnblock + +# You should use uci for configuration +OPTS="" + +xappend() { + local name="$1" value="$2" + OPTS="$OPTS --${name//_/-}=$value" +} + +xappend_toggler() { + local name="$1" + OPTS="$OPTS --${name//_/-}" +} + +append_opts() { + local name value cfg="$1"; shift + for name in $*; do + config_get value "$cfg" "$name" + [ -n "$value" ] && xappend "$name" "$value" + done +} + +append_commasep_list() { + local name cfg="$1"; shift + for name in $*; do + local res="" + _handle_list() { + res="$res$1," + } + config_list_foreach "$cfg" "$name" _handle_list + [ -n "$res" ] && xappend "$name" "$res" + done +} + +append_opts_boolean() { + local name value cfg="$1"; shift + for name in $*; do + config_get_bool value "$cfg" "$name" + [ -n "$value" ] && xappend "$name" "$value" + done +} + +append_opts_btoggler() { + local name value cfg="$1"; shift + for name in $*; do + config_get_bool value "$cfg" "$name" 0 + [ $value -gt 0 ] && xappend_toggler "$name" + done +} + +parse_options() { + local config="$1" + local value + config_get_bool value "$config" all_domains 0 + + if [ $value -gt 0 ]; then + xappend "sni_domains" "all" + else + append_commasep_list "$config" sni_domains + fi + + append_opts "$config" queue_num fake_sni_seq_len faking_strategy faking_ttl fake_seq_offset frag frag_sni_pos fk_winsize synfake_len seg2delay packet_mark + append_commasep_list "$config" exclude_domains + append_opts_boolean "$config" fake_sni frag_sni_reverse frag_sni_faked frag_middle_sni synfake + append_opts_btoggler "$config" quic_drop silent trace no_gso no_ipv6 +} + +# Openwrt procd script: https://openwrt.org/docs/guide-developer/procd-init-script-example +# The program should be put into /usr/bin/ +# This file should be put into /etc/init.d/ + +start_service() { + config_load youtubeUnblock + config_foreach parse_options youtubeUnblock + + echo "$OPTS" + + procd_open_instance 'youtubeUnblock' + procd_set_param command $PROG $OPTS + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_close_instance +} + +reload_service() { + stop + start +} diff --git a/youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock b/youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock new file mode 100644 index 0000000..2d71789 --- /dev/null +++ b/youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock @@ -0,0 +1,23 @@ +uci -q batch << EOI +add youtubeUnblock youtubeUnblock +set youtubeUnblock.youtubeUnblock.frag='tcp' +set youtubeUnblock.youtubeUnblock.frag_sni_reverse='1' +set youtubeUnblock.youtubeUnblock.frag_middle_sni='1' +set youtubeUnblock.youtubeUnblock.frag_sni_pos='1' +set youtubeUnblock.youtubeUnblock.fk_winsize='0' +set youtubeUnblock.youtubeUnblock.seg2delay='0' +set youtubeUnblock.youtubeUnblock.packet_mark='32768' +set youtubeUnblock.youtubeUnblock.fake_sni='1' +set youtubeUnblock.youtubeUnblock.faking_strategy='pastseq' +set youtubeUnblock.youtubeUnblock.fake_sni_seq_len='1' +add_list youtubeUnblock.youtubeUnblock.sni_domains='googlevideo.com' +add_list youtubeUnblock.youtubeUnblock.sni_domains='ggpht.com' +add_list youtubeUnblock.youtubeUnblock.sni_domains='ytimg.com' +add_list youtubeUnblock.youtubeUnblock.sni_domains='youtube.com' +add_list youtubeUnblock.youtubeUnblock.sni_domains='play.google.com' +add_list youtubeUnblock.youtubeUnblock.sni_domains='youtu.be' +add_list youtubeUnblock.youtubeUnblock.sni_domains='googleapis.com' +add_list youtubeUnblock.youtubeUnblock.sni_domains='googleusercontent.com' +add_list youtubeUnblock.youtubeUnblock.sni_domains='gstatic.com' +add_list youtubeUnblock.youtubeUnblock.sni_domains='l.google.com' +EOI diff --git a/youtubeUnblock/files/537-youtubeUnblock.nft b/youtubeUnblock/files/usr/share/nftables.d/537-youtubeUnblock.nft similarity index 100% rename from youtubeUnblock/files/537-youtubeUnblock.nft rename to youtubeUnblock/files/usr/share/nftables.d/537-youtubeUnblock.nft diff --git a/youtubeUnblock/files/youtubeUnblock.owrt b/youtubeUnblock/files/youtubeUnblock.owrt deleted file mode 100755 index 9ed7ac5..0000000 --- a/youtubeUnblock/files/youtubeUnblock.owrt +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh /etc/rc.common -USE_PROCD=1 - -START=50 -STOP=50 - -# Openwrt procd script: https://openwrt.org/docs/guide-developer/procd-init-script-example -# The program should be put into /usr/bin/ -# This file should be put into /etc/init.d/ - -start_service() { - procd_open_instance - procd_set_param command /usr/bin/youtubeUnblock - - procd_set_param nice -20 - - procd_set_param stdout 1 - procd_set_param stderr 1 - - procd_close_instance -} From 484d8555de76015b7deba9882c5470cf1cd19ef3 Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Thu, 12 Sep 2024 23:19:08 +0300 Subject: [PATCH 2/8] Add luci.mk --- luci-app-youtubeUnblock/Makefile | 2 +- luci-app-youtubeUnblock/luci.mk | 349 +++++++++++++++++++++++++++++++ 2 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 luci-app-youtubeUnblock/luci.mk diff --git a/luci-app-youtubeUnblock/Makefile b/luci-app-youtubeUnblock/Makefile index f96b96f..d8a6c01 100644 --- a/luci-app-youtubeUnblock/Makefile +++ b/luci-app-youtubeUnblock/Makefile @@ -3,6 +3,6 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI Support for youtubeUnblock LUCI_DEPENDS:=+luci-base +luci-compat -include ../../luci.mk +include $(CURDIR)/luci.mk # call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-youtubeUnblock/luci.mk b/luci-app-youtubeUnblock/luci.mk new file mode 100644 index 0000000..b5bd6fc --- /dev/null +++ b/luci-app-youtubeUnblock/luci.mk @@ -0,0 +1,349 @@ +# +# Copyright (C) 2008-2015 The LuCI Team +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +LUCI_NAME?=$(notdir ${CURDIR}) +LUCI_TYPE?=$(word 2,$(subst -, ,$(LUCI_NAME))) +LUCI_BASENAME?=$(patsubst luci-$(LUCI_TYPE)-%,%,$(LUCI_NAME)) +LUCI_LANGUAGES:=$(sort $(filter-out templates,$(notdir $(wildcard ${CURDIR}/po/*)))) +LUCI_DEFAULTS:=$(notdir $(wildcard ${CURDIR}/root/etc/uci-defaults/*)) +LUCI_PKGARCH?=$(if $(realpath src/Makefile),,all) +LUCI_SECTION?=luci +LUCI_CATEGORY?=LuCI +LUCI_URL?=https://github.com/openwrt/luci +LUCI_MAINTAINER?=OpenWrt LuCI community +LUCI_MINIFY_LUA?=1 +LUCI_MINIFY_CSS?=1 +LUCI_MINIFY_JS?=1 + +#LUCI_LANG_START +LUCI_LANG.ar=العربية (Arabic) +LUCI_LANG.bg=български (Bulgarian) +LUCI_LANG.bn_BD=বাংলা (Bengali) +LUCI_LANG.ca=Català (Catalan) +LUCI_LANG.cs=Čeština (Czech) +LUCI_LANG.da=Dansk (Danish) +LUCI_LANG.de=Deutsch (German) +LUCI_LANG.el=Ελληνικά (Greek) +LUCI_LANG.es=Español (Spanish) +LUCI_LANG.fi=Suomi (Finnish) +LUCI_LANG.fr=Français (French) +LUCI_LANG.he=עִבְרִית (Hebrew) +LUCI_LANG.hi=हिंदी (Hindi) +LUCI_LANG.hu=Magyar (Hungarian) +LUCI_LANG.it=Italiano (Italian) +LUCI_LANG.ja=日本語 (Japanese) +LUCI_LANG.ko=한국어 (Korean) +LUCI_LANG.lt=Lietuvių (Lithuanian) +LUCI_LANG.mr=Marāṭhī (Marathi) +LUCI_LANG.ms=Bahasa Melayu (Malay) +LUCI_LANG.nb_NO=Norsk (Norwegian) +LUCI_LANG.nl=Nederlands (Dutch) +LUCI_LANG.pl=Polski (Polish) +LUCI_LANG.pt=Português (Portuguese) +LUCI_LANG.pt_BR=Português do Brasil (Brazilian Portuguese) +LUCI_LANG.ro=Română (Romanian) +LUCI_LANG.ru=Русский (Russian) +LUCI_LANG.sk=Slovenčina (Slovak) +LUCI_LANG.sv=Svenska (Swedish) +LUCI_LANG.tr=Türkçe (Turkish) +LUCI_LANG.uk=Українська (Ukrainian) +LUCI_LANG.vi=Tiếng Việt (Vietnamese) +LUCI_LANG.zh_Hans=简体中文 (Chinese Simplified) +LUCI_LANG.zh_Hant=繁體中文 (Chinese Traditional) +#LUCI_LANG_END + +# Submenu titles +LUCI_MENU.col=1. Collections +LUCI_MENU.mod=2. Modules +LUCI_MENU.app=3. Applications +LUCI_MENU.theme=4. Themes +LUCI_MENU.proto=5. Protocols +LUCI_MENU.lib=6. Libraries + +# Language aliases +LUCI_LC_ALIAS.bn_BD=bn +LUCI_LC_ALIAS.nb_NO=no +LUCI_LC_ALIAS.pt_BR=pt-br +LUCI_LC_ALIAS.zh_Hans=zh-cn +LUCI_LC_ALIAS.zh_Hant=zh-tw + +# Default locations +HTDOCS = /www +LUA_LIBRARYDIR = /usr/lib/lua +LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci +UCODE_LIBRARYDIR = /usr/share/ucode/luci + + +# 1: everything expect po subdir or only po subdir +define findrev + $(shell \ + if git log -1 >/dev/null 2>/dev/null; then \ + set -- $$(git log -1 --format="%ct %h" --abbrev=7 -- $(if $(1),. ':(exclude)po',po)); \ + if [ -n "$$1" ]; then + secs="$$(($$1 % 86400))"; \ + yday="$$(date --utc --date="@$$1" "+%y.%j")"; \ + printf '%s.%05d~%s' "$$yday" "$$secs" "$$2"; \ + else \ + echo "0"; \ + fi; \ + else \ + ts=$$(find . -type f $(if $(1),-not) -path './po/*' -printf '%T@\n' 2>/dev/null | sort -rn | head -n1 | cut -d. -f1); \ + if [ -n "$$ts" ]; then \ + secs="$$(($$ts % 86400))"; \ + date="$$(date --utc --date="@$$ts" "+%y%m%d")"; \ + printf '0.%s.%05d' "$$date" "$$secs"; \ + else \ + echo "0"; \ + fi; \ + fi \ + ) +endef + +PKG_NAME?=$(LUCI_NAME) +PKG_RELEASE?=1 +PKG_INSTALL:=$(if $(realpath src/Makefile),1) +PKG_BUILD_DEPENDS += lua/host luci-base/host LUCI_CSSTIDY:csstidy/host LUCI_SRCDIET:luasrcdiet/host $(LUCI_BUILD_DEPENDS) +PKG_CONFIG_DEPENDS += CONFIG_LUCI_SRCDIET CONFIG_LUCI_JSMIN CONFIG_LUCI_CSSTIDY + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) + +PKG_PO_VERSION?=$(if $(DUMP),x,$(strip $(call findrev))) +PKG_SRC_VERSION?=$(if $(DUMP),x,$(strip $(call findrev,1))) + +PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \ + variant="LuCI"; \ + if git log -1 >/dev/null 2>/dev/null; then \ + branch=$$(git branch --format='%(refname:strip=3)' --remote --no-abbrev --contains 2>/dev/null | tail -n1); \ + branch=$${branch:-$$(git branch --format='%(refname:strip=2)' --no-abbrev --contains 2>/dev/null | tail -n1)}; \ + if [ "$$branch" != "master" ]; then \ + variant="LuCI $${branch:-unknown} branch"; \ + else \ + variant="LuCI Master"; \ + fi; \ + fi; \ + echo "$$variant" \ +))) + +include $(INCLUDE_DIR)/package.mk + +# LUCI_SUBMENU: the submenu-item below the LuCI top-level menu inside OpenWrt menuconfig +# usually one of the LUCI_MENU.* definitions +# LUCI_SUBMENU_DEFAULT: the regular SUBMENU defined by LUCI_TYPE or derived from the packagename +# LUCI_SUBMENU_FORCED: manually forced value SUBMENU to set to by explicit definition +# can be any string, "none" disables the creation of a submenu +# most useful in combination with LUCI_CATEGORY, to make the package appear +# anywhere in the menu structure +LUCI_SUBMENU_DEFAULT=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app)) +LUCI_SUBMENU=$(if $(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_DEFAULT)) + +ifneq ($(wildcard ${CURDIR}/luasrc/*),) + ifneq ($(filter-out luci-lib-base luci-lua-runtime,$(PKG_NAME)),) + LUCI_DEPENDS += +luci-lua-runtime + endif +endif + +define Package/$(PKG_NAME) + SECTION:=$(LUCI_SECTION) + CATEGORY:=$(LUCI_CATEGORY) +ifneq ($(LUCI_SUBMENU),none) + SUBMENU:=$(LUCI_SUBMENU) +endif + TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE)) + DEPENDS:=$(LUCI_DEPENDS) + VERSION:=$(if $(PKG_VERSION),$(if $(PKG_RELEASE),$(PKG_VERSION)-$(PKG_RELEASE),$(PKG_VERSION)),$(PKG_SRC_VERSION)) + $(if $(LUCI_EXTRA_DEPENDS),EXTRA_DEPENDS:=$(LUCI_EXTRA_DEPENDS)) + $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH)) + $(if $(PKG_PROVIDES),PROVIDES:=$(PKG_PROVIDES)) + URL:=$(LUCI_URL) + MAINTAINER:=$(LUCI_MAINTAINER) +endef + +ifneq ($(LUCI_DESCRIPTION),) + define Package/$(PKG_NAME)/description + $(strip $(LUCI_DESCRIPTION)) + endef +endif + +define Build/Prepare + for d in luasrc ucode htdocs root src; do \ + if [ -d ./$$$$d ]; then \ + mkdir -p $(PKG_BUILD_DIR)/$$$$d; \ + $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \ + fi; \ + done + $(call Build/Prepare/Default) +endef + +define Build/Configure +endef + +ifneq ($(wildcard ${CURDIR}/src/Makefile),) + MAKE_PATH := src/ + MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_SRC_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)" + + define Build/Compile + $(call Build/Compile/Default,clean compile) + endef +else + define Build/Compile + endef +endif + +define Package/$(PKG_NAME)/install + + ifneq ($(wildcard ${CURDIR}/luasrc),) + $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR) + cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/ + $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm + $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true) + $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/) + endif + ifneq ($(wildcard ${CURDIR}/ucode),) + $(INSTALL_DIR) $(1)$(UCODE_LIBRARYDIR) + cp -pR $(PKG_BUILD_DIR)/ucode/* $(1)$(UCODE_LIBRARYDIR)/ + $(call SubstituteVersion,$(1)$(UCODE_LIBRARYDIR)/) + endif + ifneq ($(wildcard ${CURDIR}/htdocs),) + $(INSTALL_DIR) $(1)$(HTDOCS) + cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/ + $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true) + $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true) + endif + ifneq ($(wildcard ${CURDIR}/root),) + $(INSTALL_DIR) $(1)/ + cp -pR $(PKG_BUILD_DIR)/root/* $(1)/ + endif + ifneq ($(wildcard ${CURDIR}/src),) + $(call Build/Install/Default) + $(CP) $(PKG_INSTALL_DIR)/* $(1)/ + endif +endef + +ifndef Package/$(PKG_NAME)/postinst +define Package/$(PKG_NAME)/postinst +[ -n "$${IPKG_INSTROOT}" ] || { \ + rm -f /tmp/luci-indexcache.* + rm -rf /tmp/luci-modulecache/ + killall -HUP rpcd 2>/dev/null + exit 0 +} +endef +endif + +# some generic macros that can be used by all packages +ifeq ($(LUCI_MINIFY_LUA),1) + define SrcDiet + $(FIND) $(1) -type f -name '*.lua' | while read src; do \ + if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \ + then mv "$$$$src.o" "$$$$src"; fi; \ + done + endef +else + define SrcDiet + $$(call MESSAGE,$$(LUCI_NAME) does not support Lua source minification) + endef +endif + +ifeq ($(LUCI_MINIFY_JS),1) + define JsMin + $(FIND) $(1) -type f -name '*.js' | while read src; do \ + if jsmin < "$$$$src" > "$$$$src.o"; \ + then mv "$$$$src.o" "$$$$src"; fi; \ + done + endef +else + define JsMin + $$(call MESSAGE,$$(LUCI_NAME) does not support JavaScript source minification) + endef +endif + +ifeq ($(LUCI_MINIFY_CSS),1) + define CssTidy + $(FIND) $(1) -type f -name '*.css' | while read src; do \ + if csstidy "$$$$src" --template=highest --remove_last_semicolon=true "$$$$src.o"; \ + then mv "$$$$src.o" "$$$$src"; fi; \ + done + endef +else + define CssTidy + $$(call MESSAGE,$$(LUCI_NAME) does not support CSS source minification) + endef +endif + +define SubstituteVersion + $(FIND) $(1) -type f -name '*.htm' | while read src; do \ + $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \ + -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \ + "$$$$src"; \ + done; \ + $(FIND) $(1) -type f -name '*.ut' | while read src; do \ + $(SED) 's/{# *\([^ ]*\)PKG_VERSION *#}/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \ + -e 's/"\({{ *\(media\|resource\) *}}[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \ + "$$$$src"; \ + done +endef + +# additional setting luci-base package +ifeq ($(PKG_NAME),luci-base) + define Package/luci-base/config + config LUCI_SRCDIET + bool "Minify Lua sources" + default n + + config LUCI_JSMIN + bool "Minify JavaScript sources" + default y + + config LUCI_CSSTIDY + bool "Minify CSS files" + default y + + menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)), + + config LUCI_LANG_$(lang) + tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))")) + + endmenu + endef +endif + + +LUCI_BUILD_PACKAGES := $(PKG_NAME) + +# 1: LuCI language code +# 2: BCP 47 language tag +define LuciTranslation + define Package/luci-i18n-$(LUCI_BASENAME)-$(1) + SECTION:=luci + CATEGORY:=LuCI + TITLE:=$(PKG_NAME) - $(1) translation + HIDDEN:=1 + DEFAULT:=LUCI_LANG_$(2)||(ALL&&m) + DEPENDS:=$(PKG_NAME) + VERSION:=$(PKG_PO_VERSION) + PKGARCH:=all + endef + + define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description + Translation for $(PKG_NAME) - $(LUCI_LANG.$(2)) + endef + + define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install + $$(INSTALL_DIR) $$(1)/etc/uci-defaults + echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(2))'; uci commit luci" \ + > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1) + $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n + $(foreach po,$(wildcard ${CURDIR}/po/$(2)/*.po), \ + po2lmo $(po) \ + $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;) + endef + + LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1) + +endef + +$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang))))) +$(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg)))) From 6b6f53c942dd6c17d8c14bd148937d2fdd55936f Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Thu, 12 Sep 2024 23:49:06 +0300 Subject: [PATCH 3/8] All in one package --- luci-app-youtubeUnblock/Makefile | 8 - luci-app-youtubeUnblock/luci.mk | 349 ------------------ youtubeUnblock/Makefile | 11 +- .../luasrc/controller/youtubeUnblock.lua | 0 .../luasrc/model/cbi/youtubeUnblock.lua | 0 5 files changed, 9 insertions(+), 359 deletions(-) delete mode 100644 luci-app-youtubeUnblock/Makefile delete mode 100644 luci-app-youtubeUnblock/luci.mk rename {luci-app-youtubeUnblock => youtubeUnblock/files}/luasrc/controller/youtubeUnblock.lua (100%) rename {luci-app-youtubeUnblock => youtubeUnblock/files}/luasrc/model/cbi/youtubeUnblock.lua (100%) diff --git a/luci-app-youtubeUnblock/Makefile b/luci-app-youtubeUnblock/Makefile deleted file mode 100644 index d8a6c01..0000000 --- a/luci-app-youtubeUnblock/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -include $(TOPDIR)/rules.mk - -LUCI_TITLE:=LuCI Support for youtubeUnblock -LUCI_DEPENDS:=+luci-base +luci-compat - -include $(CURDIR)/luci.mk - -# call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-youtubeUnblock/luci.mk b/luci-app-youtubeUnblock/luci.mk deleted file mode 100644 index b5bd6fc..0000000 --- a/luci-app-youtubeUnblock/luci.mk +++ /dev/null @@ -1,349 +0,0 @@ -# -# Copyright (C) 2008-2015 The LuCI Team -# -# This is free software, licensed under the Apache License, Version 2.0 . -# - -LUCI_NAME?=$(notdir ${CURDIR}) -LUCI_TYPE?=$(word 2,$(subst -, ,$(LUCI_NAME))) -LUCI_BASENAME?=$(patsubst luci-$(LUCI_TYPE)-%,%,$(LUCI_NAME)) -LUCI_LANGUAGES:=$(sort $(filter-out templates,$(notdir $(wildcard ${CURDIR}/po/*)))) -LUCI_DEFAULTS:=$(notdir $(wildcard ${CURDIR}/root/etc/uci-defaults/*)) -LUCI_PKGARCH?=$(if $(realpath src/Makefile),,all) -LUCI_SECTION?=luci -LUCI_CATEGORY?=LuCI -LUCI_URL?=https://github.com/openwrt/luci -LUCI_MAINTAINER?=OpenWrt LuCI community -LUCI_MINIFY_LUA?=1 -LUCI_MINIFY_CSS?=1 -LUCI_MINIFY_JS?=1 - -#LUCI_LANG_START -LUCI_LANG.ar=العربية (Arabic) -LUCI_LANG.bg=български (Bulgarian) -LUCI_LANG.bn_BD=বাংলা (Bengali) -LUCI_LANG.ca=Català (Catalan) -LUCI_LANG.cs=Čeština (Czech) -LUCI_LANG.da=Dansk (Danish) -LUCI_LANG.de=Deutsch (German) -LUCI_LANG.el=Ελληνικά (Greek) -LUCI_LANG.es=Español (Spanish) -LUCI_LANG.fi=Suomi (Finnish) -LUCI_LANG.fr=Français (French) -LUCI_LANG.he=עִבְרִית (Hebrew) -LUCI_LANG.hi=हिंदी (Hindi) -LUCI_LANG.hu=Magyar (Hungarian) -LUCI_LANG.it=Italiano (Italian) -LUCI_LANG.ja=日本語 (Japanese) -LUCI_LANG.ko=한국어 (Korean) -LUCI_LANG.lt=Lietuvių (Lithuanian) -LUCI_LANG.mr=Marāṭhī (Marathi) -LUCI_LANG.ms=Bahasa Melayu (Malay) -LUCI_LANG.nb_NO=Norsk (Norwegian) -LUCI_LANG.nl=Nederlands (Dutch) -LUCI_LANG.pl=Polski (Polish) -LUCI_LANG.pt=Português (Portuguese) -LUCI_LANG.pt_BR=Português do Brasil (Brazilian Portuguese) -LUCI_LANG.ro=Română (Romanian) -LUCI_LANG.ru=Русский (Russian) -LUCI_LANG.sk=Slovenčina (Slovak) -LUCI_LANG.sv=Svenska (Swedish) -LUCI_LANG.tr=Türkçe (Turkish) -LUCI_LANG.uk=Українська (Ukrainian) -LUCI_LANG.vi=Tiếng Việt (Vietnamese) -LUCI_LANG.zh_Hans=简体中文 (Chinese Simplified) -LUCI_LANG.zh_Hant=繁體中文 (Chinese Traditional) -#LUCI_LANG_END - -# Submenu titles -LUCI_MENU.col=1. Collections -LUCI_MENU.mod=2. Modules -LUCI_MENU.app=3. Applications -LUCI_MENU.theme=4. Themes -LUCI_MENU.proto=5. Protocols -LUCI_MENU.lib=6. Libraries - -# Language aliases -LUCI_LC_ALIAS.bn_BD=bn -LUCI_LC_ALIAS.nb_NO=no -LUCI_LC_ALIAS.pt_BR=pt-br -LUCI_LC_ALIAS.zh_Hans=zh-cn -LUCI_LC_ALIAS.zh_Hant=zh-tw - -# Default locations -HTDOCS = /www -LUA_LIBRARYDIR = /usr/lib/lua -LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci -UCODE_LIBRARYDIR = /usr/share/ucode/luci - - -# 1: everything expect po subdir or only po subdir -define findrev - $(shell \ - if git log -1 >/dev/null 2>/dev/null; then \ - set -- $$(git log -1 --format="%ct %h" --abbrev=7 -- $(if $(1),. ':(exclude)po',po)); \ - if [ -n "$$1" ]; then - secs="$$(($$1 % 86400))"; \ - yday="$$(date --utc --date="@$$1" "+%y.%j")"; \ - printf '%s.%05d~%s' "$$yday" "$$secs" "$$2"; \ - else \ - echo "0"; \ - fi; \ - else \ - ts=$$(find . -type f $(if $(1),-not) -path './po/*' -printf '%T@\n' 2>/dev/null | sort -rn | head -n1 | cut -d. -f1); \ - if [ -n "$$ts" ]; then \ - secs="$$(($$ts % 86400))"; \ - date="$$(date --utc --date="@$$ts" "+%y%m%d")"; \ - printf '0.%s.%05d' "$$date" "$$secs"; \ - else \ - echo "0"; \ - fi; \ - fi \ - ) -endef - -PKG_NAME?=$(LUCI_NAME) -PKG_RELEASE?=1 -PKG_INSTALL:=$(if $(realpath src/Makefile),1) -PKG_BUILD_DEPENDS += lua/host luci-base/host LUCI_CSSTIDY:csstidy/host LUCI_SRCDIET:luasrcdiet/host $(LUCI_BUILD_DEPENDS) -PKG_CONFIG_DEPENDS += CONFIG_LUCI_SRCDIET CONFIG_LUCI_JSMIN CONFIG_LUCI_CSSTIDY - -PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) - -PKG_PO_VERSION?=$(if $(DUMP),x,$(strip $(call findrev))) -PKG_SRC_VERSION?=$(if $(DUMP),x,$(strip $(call findrev,1))) - -PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \ - variant="LuCI"; \ - if git log -1 >/dev/null 2>/dev/null; then \ - branch=$$(git branch --format='%(refname:strip=3)' --remote --no-abbrev --contains 2>/dev/null | tail -n1); \ - branch=$${branch:-$$(git branch --format='%(refname:strip=2)' --no-abbrev --contains 2>/dev/null | tail -n1)}; \ - if [ "$$branch" != "master" ]; then \ - variant="LuCI $${branch:-unknown} branch"; \ - else \ - variant="LuCI Master"; \ - fi; \ - fi; \ - echo "$$variant" \ -))) - -include $(INCLUDE_DIR)/package.mk - -# LUCI_SUBMENU: the submenu-item below the LuCI top-level menu inside OpenWrt menuconfig -# usually one of the LUCI_MENU.* definitions -# LUCI_SUBMENU_DEFAULT: the regular SUBMENU defined by LUCI_TYPE or derived from the packagename -# LUCI_SUBMENU_FORCED: manually forced value SUBMENU to set to by explicit definition -# can be any string, "none" disables the creation of a submenu -# most useful in combination with LUCI_CATEGORY, to make the package appear -# anywhere in the menu structure -LUCI_SUBMENU_DEFAULT=$(if $(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.$(LUCI_TYPE)),$(LUCI_MENU.app)) -LUCI_SUBMENU=$(if $(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_FORCED),$(LUCI_SUBMENU_DEFAULT)) - -ifneq ($(wildcard ${CURDIR}/luasrc/*),) - ifneq ($(filter-out luci-lib-base luci-lua-runtime,$(PKG_NAME)),) - LUCI_DEPENDS += +luci-lua-runtime - endif -endif - -define Package/$(PKG_NAME) - SECTION:=$(LUCI_SECTION) - CATEGORY:=$(LUCI_CATEGORY) -ifneq ($(LUCI_SUBMENU),none) - SUBMENU:=$(LUCI_SUBMENU) -endif - TITLE:=$(if $(LUCI_TITLE),$(LUCI_TITLE),LuCI $(LUCI_NAME) $(LUCI_TYPE)) - DEPENDS:=$(LUCI_DEPENDS) - VERSION:=$(if $(PKG_VERSION),$(if $(PKG_RELEASE),$(PKG_VERSION)-$(PKG_RELEASE),$(PKG_VERSION)),$(PKG_SRC_VERSION)) - $(if $(LUCI_EXTRA_DEPENDS),EXTRA_DEPENDS:=$(LUCI_EXTRA_DEPENDS)) - $(if $(LUCI_PKGARCH),PKGARCH:=$(LUCI_PKGARCH)) - $(if $(PKG_PROVIDES),PROVIDES:=$(PKG_PROVIDES)) - URL:=$(LUCI_URL) - MAINTAINER:=$(LUCI_MAINTAINER) -endef - -ifneq ($(LUCI_DESCRIPTION),) - define Package/$(PKG_NAME)/description - $(strip $(LUCI_DESCRIPTION)) - endef -endif - -define Build/Prepare - for d in luasrc ucode htdocs root src; do \ - if [ -d ./$$$$d ]; then \ - mkdir -p $(PKG_BUILD_DIR)/$$$$d; \ - $(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \ - fi; \ - done - $(call Build/Prepare/Default) -endef - -define Build/Configure -endef - -ifneq ($(wildcard ${CURDIR}/src/Makefile),) - MAKE_PATH := src/ - MAKE_VARS += FPIC="$(FPIC)" LUCI_VERSION="$(PKG_SRC_VERSION)" LUCI_GITBRANCH="$(PKG_GITBRANCH)" - - define Build/Compile - $(call Build/Compile/Default,clean compile) - endef -else - define Build/Compile - endef -endif - -define Package/$(PKG_NAME)/install - - ifneq ($(wildcard ${CURDIR}/luasrc),) - $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR) - cp -pR $(PKG_BUILD_DIR)/luasrc/* $(1)$(LUCI_LIBRARYDIR)/ - $(FIND) $(1)$(LUCI_LIBRARYDIR)/ -type f -name '*.luadoc' | $(XARGS) rm - $(if $(CONFIG_LUCI_SRCDIET),$(call SrcDiet,$(1)$(LUCI_LIBRARYDIR)/),true) - $(call SubstituteVersion,$(1)$(LUCI_LIBRARYDIR)/) - endif - ifneq ($(wildcard ${CURDIR}/ucode),) - $(INSTALL_DIR) $(1)$(UCODE_LIBRARYDIR) - cp -pR $(PKG_BUILD_DIR)/ucode/* $(1)$(UCODE_LIBRARYDIR)/ - $(call SubstituteVersion,$(1)$(UCODE_LIBRARYDIR)/) - endif - ifneq ($(wildcard ${CURDIR}/htdocs),) - $(INSTALL_DIR) $(1)$(HTDOCS) - cp -pR $(PKG_BUILD_DIR)/htdocs/* $(1)$(HTDOCS)/ - $(if $(CONFIG_LUCI_JSMIN),$(call JsMin,$(1)$(HTDOCS)/),true) - $(if $(CONFIG_LUCI_CSSTIDY),$(call CssTidy,$(1)$(HTDOCS)/),true) - endif - ifneq ($(wildcard ${CURDIR}/root),) - $(INSTALL_DIR) $(1)/ - cp -pR $(PKG_BUILD_DIR)/root/* $(1)/ - endif - ifneq ($(wildcard ${CURDIR}/src),) - $(call Build/Install/Default) - $(CP) $(PKG_INSTALL_DIR)/* $(1)/ - endif -endef - -ifndef Package/$(PKG_NAME)/postinst -define Package/$(PKG_NAME)/postinst -[ -n "$${IPKG_INSTROOT}" ] || { \ - rm -f /tmp/luci-indexcache.* - rm -rf /tmp/luci-modulecache/ - killall -HUP rpcd 2>/dev/null - exit 0 -} -endef -endif - -# some generic macros that can be used by all packages -ifeq ($(LUCI_MINIFY_LUA),1) - define SrcDiet - $(FIND) $(1) -type f -name '*.lua' | while read src; do \ - if LUA_PATH="$(STAGING_DIR_HOSTPKG)/lib/lua/5.1/?.lua" luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; \ - then mv "$$$$src.o" "$$$$src"; fi; \ - done - endef -else - define SrcDiet - $$(call MESSAGE,$$(LUCI_NAME) does not support Lua source minification) - endef -endif - -ifeq ($(LUCI_MINIFY_JS),1) - define JsMin - $(FIND) $(1) -type f -name '*.js' | while read src; do \ - if jsmin < "$$$$src" > "$$$$src.o"; \ - then mv "$$$$src.o" "$$$$src"; fi; \ - done - endef -else - define JsMin - $$(call MESSAGE,$$(LUCI_NAME) does not support JavaScript source minification) - endef -endif - -ifeq ($(LUCI_MINIFY_CSS),1) - define CssTidy - $(FIND) $(1) -type f -name '*.css' | while read src; do \ - if csstidy "$$$$src" --template=highest --remove_last_semicolon=true "$$$$src.o"; \ - then mv "$$$$src.o" "$$$$src"; fi; \ - done - endef -else - define CssTidy - $$(call MESSAGE,$$(LUCI_NAME) does not support CSS source minification) - endef -endif - -define SubstituteVersion - $(FIND) $(1) -type f -name '*.htm' | while read src; do \ - $(SED) 's/<%# *\([^ ]*\)PKG_VERSION *%>/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \ - -e 's/"\(<%= *\(media\|resource\) *%>[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \ - "$$$$src"; \ - done; \ - $(FIND) $(1) -type f -name '*.ut' | while read src; do \ - $(SED) 's/{# *\([^ ]*\)PKG_VERSION *#}/\1$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))/g' \ - -e 's/"\({{ *\(media\|resource\) *}}[^"]*\.\(js\|css\)\)"/"\1?v=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))"/g' \ - "$$$$src"; \ - done -endef - -# additional setting luci-base package -ifeq ($(PKG_NAME),luci-base) - define Package/luci-base/config - config LUCI_SRCDIET - bool "Minify Lua sources" - default n - - config LUCI_JSMIN - bool "Minify JavaScript sources" - default y - - config LUCI_CSSTIDY - bool "Minify CSS files" - default y - - menu "Translations"$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)), - - config LUCI_LANG_$(lang) - tristate "$(shell echo '$(LUCI_LANG.$(lang))' | sed -e 's/^.* (\(.*\))$$/\1/') ($(lang))")) - - endmenu - endef -endif - - -LUCI_BUILD_PACKAGES := $(PKG_NAME) - -# 1: LuCI language code -# 2: BCP 47 language tag -define LuciTranslation - define Package/luci-i18n-$(LUCI_BASENAME)-$(1) - SECTION:=luci - CATEGORY:=LuCI - TITLE:=$(PKG_NAME) - $(1) translation - HIDDEN:=1 - DEFAULT:=LUCI_LANG_$(2)||(ALL&&m) - DEPENDS:=$(PKG_NAME) - VERSION:=$(PKG_PO_VERSION) - PKGARCH:=all - endef - - define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/description - Translation for $(PKG_NAME) - $(LUCI_LANG.$(2)) - endef - - define Package/luci-i18n-$(LUCI_BASENAME)-$(1)/install - $$(INSTALL_DIR) $$(1)/etc/uci-defaults - echo "uci set luci.languages.$(subst -,_,$(1))='$(LUCI_LANG.$(2))'; uci commit luci" \ - > $$(1)/etc/uci-defaults/luci-i18n-$(LUCI_BASENAME)-$(1) - $$(INSTALL_DIR) $$(1)$(LUCI_LIBRARYDIR)/i18n - $(foreach po,$(wildcard ${CURDIR}/po/$(2)/*.po), \ - po2lmo $(po) \ - $$(1)$(LUCI_LIBRARYDIR)/i18n/$(basename $(notdir $(po))).$(1).lmo;) - endef - - LUCI_BUILD_PACKAGES += luci-i18n-$(LUCI_BASENAME)-$(1) - -endef - -$(foreach lang,$(LUCI_LANGUAGES),$(if $(LUCI_LANG.$(lang)),$(eval $(call LuciTranslation,$(firstword $(LUCI_LC_ALIAS.$(lang)) $(lang)),$(lang))))) -$(foreach pkg,$(LUCI_BUILD_PACKAGES),$(eval $(call BuildPackage,$(pkg)))) diff --git a/youtubeUnblock/Makefile b/youtubeUnblock/Makefile index 1829ab8..a54b38f 100644 --- a/youtubeUnblock/Makefile +++ b/youtubeUnblock/Makefile @@ -11,13 +11,16 @@ PKG_SOURCE_URL:=https://github.com/Waujito/youtubeUnblock.git PKG_SOURCE_PROTO:=git PKG_SOURCE_VERSION:=$(PKG_REV) +LUA_LIBRARYDIR = /usr/lib/lua +LUCI_LIBRARYDIR = $(LUA_LIBRARYDIR)/luci + include $(INCLUDE_DIR)/package.mk define Package/youtubeUnblock - SECTION:=net + SECTION:=services CATEGORY:=Networking TITLE:=youtubeUnblock - DEPENDS:=+libpthread + DEPENDS:=+libpthread +luci-base +luci-compat URL:=https://github.com/Waujito/youtubeUnblock MAINTAINER:=Vadim Vetrov VERSION:=$(PKG_VERSION)-$(BOARD)-$(PKG_RELEASE) @@ -50,6 +53,10 @@ define Package/youtubeUnblock/install $(INSTALL_BIN) ./files/etc/uci-defaults/99-youtubeUnblock $(1)/etc/uci-defaults/99-youtubeUnblock $(INSTALL_DIR) $(1)/usr/share/nftables.d/ruleset-post/ $(CP) ./files/537-youtubeUnblock.nft $(1)/usr/share/nftables.d/ruleset-post/537-youtubeUnblock.nft + $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)/controller + $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)/model/cbi + $(INSTALL_BIN) ./files/luasrc/controller/* $(1)$(LUCI_LIBRARYDIR)/controller + $(INSTALL_BIN) ./files/luasrc/model/cbi/* $(1)$(LUCI_LIBRARYDIR)/model/cbi endef $(eval $(call BuildPackage,youtubeUnblock)) diff --git a/luci-app-youtubeUnblock/luasrc/controller/youtubeUnblock.lua b/youtubeUnblock/files/luasrc/controller/youtubeUnblock.lua similarity index 100% rename from luci-app-youtubeUnblock/luasrc/controller/youtubeUnblock.lua rename to youtubeUnblock/files/luasrc/controller/youtubeUnblock.lua diff --git a/luci-app-youtubeUnblock/luasrc/model/cbi/youtubeUnblock.lua b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua similarity index 100% rename from luci-app-youtubeUnblock/luasrc/model/cbi/youtubeUnblock.lua rename to youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua From 6725e22de79f76e848c83a298e943aef4425c0fd Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Fri, 13 Sep 2024 21:12:41 +0300 Subject: [PATCH 4/8] Add new option --- youtubeUnblock/Makefile | 2 +- youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua | 1 + .../files/{usr/share => }/nftables.d/537-youtubeUnblock.nft | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename youtubeUnblock/files/{usr/share => }/nftables.d/537-youtubeUnblock.nft (100%) diff --git a/youtubeUnblock/Makefile b/youtubeUnblock/Makefile index a54b38f..3083ab2 100644 --- a/youtubeUnblock/Makefile +++ b/youtubeUnblock/Makefile @@ -52,7 +52,7 @@ define Package/youtubeUnblock/install $(INSTALL_DIR) $(1)/etc/uci-defaults $(INSTALL_BIN) ./files/etc/uci-defaults/99-youtubeUnblock $(1)/etc/uci-defaults/99-youtubeUnblock $(INSTALL_DIR) $(1)/usr/share/nftables.d/ruleset-post/ - $(CP) ./files/537-youtubeUnblock.nft $(1)/usr/share/nftables.d/ruleset-post/537-youtubeUnblock.nft + $(CP) ./files/nftables.d/537-youtubeUnblock.nft $(1)/usr/share/nftables.d/ruleset-post/537-youtubeUnblock.nft $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)/controller $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)/model/cbi $(INSTALL_BIN) ./files/luasrc/controller/* $(1)$(LUCI_LIBRARYDIR)/controller diff --git a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua index 4d0621b..beb746d 100644 --- a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua +++ b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua @@ -20,6 +20,7 @@ o:value("pastseq", "pastseq") o:value("randseq", "randseq") o:value("ttl", "ttl") o:value("tcp_check", "tcp_check") +o:value("md5sum", "md5sum") o.widget="radio" o:depends("fake_sni", 1) diff --git a/youtubeUnblock/files/usr/share/nftables.d/537-youtubeUnblock.nft b/youtubeUnblock/files/nftables.d/537-youtubeUnblock.nft similarity index 100% rename from youtubeUnblock/files/usr/share/nftables.d/537-youtubeUnblock.nft rename to youtubeUnblock/files/nftables.d/537-youtubeUnblock.nft From 9dacead2ee772de003869deb81eb5d9cfed6310d Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Fri, 13 Sep 2024 21:55:18 +0300 Subject: [PATCH 5/8] Fix uci-defaults --- youtubeUnblock/Makefile | 8 ++++---- youtubeUnblock/files/etc/init.d/youtubeUnblock | 7 +++++-- .../{99-youtubeUnblock => 99-youtubeUnblock.sh} | 9 +++++++-- youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua | 1 - 4 files changed, 16 insertions(+), 9 deletions(-) rename youtubeUnblock/files/etc/uci-defaults/{99-youtubeUnblock => 99-youtubeUnblock.sh} (81%) diff --git a/youtubeUnblock/Makefile b/youtubeUnblock/Makefile index 3083ab2..6e9cde0 100644 --- a/youtubeUnblock/Makefile +++ b/youtubeUnblock/Makefile @@ -50,13 +50,13 @@ define Package/youtubeUnblock/install $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/etc/init.d/youtubeUnblock $(1)/etc/init.d/youtubeUnblock $(INSTALL_DIR) $(1)/etc/uci-defaults - $(INSTALL_BIN) ./files/etc/uci-defaults/99-youtubeUnblock $(1)/etc/uci-defaults/99-youtubeUnblock + $(INSTALL_BIN) ./files/etc/uci-defaults/99-youtubeUnblock.sh $(1)/etc/uci-defaults/99-youtubeUnblock.sh $(INSTALL_DIR) $(1)/usr/share/nftables.d/ruleset-post/ - $(CP) ./files/nftables.d/537-youtubeUnblock.nft $(1)/usr/share/nftables.d/ruleset-post/537-youtubeUnblock.nft + $(INSTALL_DATA) ./files/nftables.d/537-youtubeUnblock.nft $(1)/usr/share/nftables.d/ruleset-post/537-youtubeUnblock.nft $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)/controller $(INSTALL_DIR) $(1)$(LUCI_LIBRARYDIR)/model/cbi - $(INSTALL_BIN) ./files/luasrc/controller/* $(1)$(LUCI_LIBRARYDIR)/controller - $(INSTALL_BIN) ./files/luasrc/model/cbi/* $(1)$(LUCI_LIBRARYDIR)/model/cbi + $(INSTALL_DATA) ./files/luasrc/controller/* $(1)$(LUCI_LIBRARYDIR)/controller + $(INSTALL_DATA) ./files/luasrc/model/cbi/* $(1)$(LUCI_LIBRARYDIR)/model/cbi endef $(eval $(call BuildPackage,youtubeUnblock)) diff --git a/youtubeUnblock/files/etc/init.d/youtubeUnblock b/youtubeUnblock/files/etc/init.d/youtubeUnblock index 0609f01..e33bf8b 100755 --- a/youtubeUnblock/files/etc/init.d/youtubeUnblock +++ b/youtubeUnblock/files/etc/init.d/youtubeUnblock @@ -6,7 +6,7 @@ START=91 USE_PROCD=1 -PROCD_DEBUG=1 +# PROCD_DEBUG=1 PROG=/usr/bin/youtubeUnblock # You should use uci for configuration @@ -83,7 +83,10 @@ start_service() { config_load youtubeUnblock config_foreach parse_options youtubeUnblock - echo "$OPTS" + + if [[ "$PROCD_DEBUG" == "1" ]]; then + echo "$OPTS" + fi procd_open_instance 'youtubeUnblock' procd_set_param command $PROG $OPTS diff --git a/youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock b/youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock.sh similarity index 81% rename from youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock rename to youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock.sh index 2d71789..ab8f3c0 100644 --- a/youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock +++ b/youtubeUnblock/files/etc/uci-defaults/99-youtubeUnblock.sh @@ -1,5 +1,7 @@ -uci -q batch << EOI -add youtubeUnblock youtubeUnblock +#!/bin/sh +[[ ! "$(uci -q get youtubeUnblock.youtubeUnblock)" == "" ]] && exit 0 +uci batch << EOI +set youtubeUnblock.youtubeUnblock='youtubeUnblock' set youtubeUnblock.youtubeUnblock.frag='tcp' set youtubeUnblock.youtubeUnblock.frag_sni_reverse='1' set youtubeUnblock.youtubeUnblock.frag_middle_sni='1' @@ -21,3 +23,6 @@ add_list youtubeUnblock.youtubeUnblock.sni_domains='googleusercontent.com' add_list youtubeUnblock.youtubeUnblock.sni_domains='gstatic.com' add_list youtubeUnblock.youtubeUnblock.sni_domains='l.google.com' EOI +uci commit +/etc/init.d/firewall restart &>/dev/null +exit 0 # IMPORTANT, IF WE NO PUT THIS, WILL EXECUTED ENDLESSLY diff --git a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua index beb746d..8d5808a 100644 --- a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua +++ b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua @@ -4,7 +4,6 @@ local m = Map("youtubeUnblock", "youtubeUnblock", "Bypasses Deep Packet Inspecti local s = m:section(NamedSection, "youtubeUnblock", "youtubeUnblock", "youtubeUnblock", "Config. Check the README for more details https://github.com/Waujito/youtubeUnblock") local o -s:option(Value, "queue_num", "queue num", "The number of netfilter queue youtubeUnblock will be linked to.") s:option(Flag, "fake_sni", "fake sni", "This flag enables fake-sni which forces youtubeUnblock to send at least three packets instead of one with TLS ClientHello: Fake ClientHello, 1st part of original ClientHello, 2nd part of original ClientHello. This flag may be related to some Operation not permitted error messages, so before open an issue refer to Troubleshooting for EPERMS.") o = s:option(ListValue, "faking_strategy", "faking strategy", From dba6078f2cd7f41ef5127b5d1c0e06744d7f1c62 Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Sat, 14 Sep 2024 10:58:22 +0300 Subject: [PATCH 6/8] Update nftables to allow quic drop --- youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua | 4 +++- youtubeUnblock/files/nftables.d/537-youtubeUnblock.nft | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua index 8d5808a..916f224 100644 --- a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua +++ b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua @@ -13,7 +13,9 @@ o = s:option(ListValue, "faking_strategy", "faking strategy",
  • randseq specifies that random sequence/acknowledgemend random will be set. This option may be handled by provider which uses conntrack with drop on invalid conntrack state firewall rule enabled.
  • ttl specifies that packet will be invalidated after --faking-ttl=n hops. ttl is better but may cause issues if unconfigured.
  • pastseq is like randseq but sequence number is not random but references the packet sent in the past (before current).
  • -
  • tcp_check will invalidate faking packet with invalid checksum. May be handled and dropped by some providers/TSPUs.
  • +
  • tcp_check will invalidate faking packet with invalid checksum. May be handled and dropped by some providers/TSPUs.
  • +
  • md5sum will invalidate faking packet with invalid TCP md5sum. md5sum is a TCP option which is handled by the destination server but may be skipped by TSPU.
  • + ]]) o:value("pastseq", "pastseq") o:value("randseq", "randseq") diff --git a/youtubeUnblock/files/nftables.d/537-youtubeUnblock.nft b/youtubeUnblock/files/nftables.d/537-youtubeUnblock.nft index 6a49c14..a3a4687 100644 --- a/youtubeUnblock/files/nftables.d/537-youtubeUnblock.nft +++ b/youtubeUnblock/files/nftables.d/537-youtubeUnblock.nft @@ -1,5 +1,6 @@ #!/usr/sbin/nft -f -# This file +# This file will be applied automatically for nftables -add rule inet fw4 mangle_forward tcp dport 443 ct original packets < 20 counter queue num 537 bypass +add chain inet fw4 youtubeUnblock { type filter hook postrouting priority mangle - 1; policy accept; } +add rule inet fw4 youtubeUnblock meta l4proto { tcp, udp } th dport 443 ct original packets < 20 counter queue num 537 bypass insert rule inet fw4 output mark and 0x8000 == 0x8000 counter accept From d7df9cbc6d4a38ddae0b83e5c6825036272743d8 Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Sat, 14 Sep 2024 11:32:32 +0300 Subject: [PATCH 7/8] More detailed logs --- youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua index 916f224..217d3ed 100644 --- a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua +++ b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua @@ -145,7 +145,7 @@ function fwo.write(self, section) sys.call("/etc/init.d/firewall reload") end -local logs = sys.exec("logread -l 800 -p youtubeUnblock | sed '1!G;h;$!d'") +local logs = sys.exec("logread -l 800 -p youtubeUnblock | grep youtubeUnblock | sed '1!G;h;$!d'") local o = bs:option(DummyValue, "_logs", "Logs") o.rawhtml = true o.value = logs From 0becd2fb18994cb6e41ffeb396b7ba027ac7597f Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Sat, 14 Sep 2024 12:19:41 +0300 Subject: [PATCH 8/8] Reload after apply --- youtubeUnblock/files/etc/init.d/youtubeUnblock | 4 ++++ youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/youtubeUnblock/files/etc/init.d/youtubeUnblock b/youtubeUnblock/files/etc/init.d/youtubeUnblock index e33bf8b..f491ecf 100755 --- a/youtubeUnblock/files/etc/init.d/youtubeUnblock +++ b/youtubeUnblock/files/etc/init.d/youtubeUnblock @@ -95,6 +95,10 @@ start_service() { procd_close_instance } +service_triggers() { + procd_add_reload_trigger "youtubeUnblock" +} + reload_service() { stop start diff --git a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua index 217d3ed..014b6cf 100644 --- a/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua +++ b/youtubeUnblock/files/luasrc/model/cbi/youtubeUnblock.lua @@ -155,8 +155,4 @@ o.readonly = true o.template = "cbi/tvalue" o.width = "100%" -m.on_after_commit = function(self, map) - sys.call('/etc/init.d/youtubeUnblock restart &>/dev/null') -end - return m