1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Add haproxy and add pot for glorytun

This commit is contained in:
Ycarus 2018-02-20 13:49:33 +01:00
parent 5dc4952622
commit 1de17a4886
14 changed files with 716 additions and 1 deletions

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 chenhw2
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,80 @@
#
# Copyright (C) 2016 chenhw2 <chenhw2@github.com>
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
#
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-haproxy-tcp
PKG_VERSION:=0.1.4
PKG_RELEASE:=1
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=LICENSE
PKG_MAINTAINER:=chenhw2 <chenhw2@github.com>
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include ../luci/luci.mk
define Package/luci-app-haproxy-tcp
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=3. Applications
TITLE:=LuCI Support for HAProxy-TCP
PKGARCH:=all
DEPENDS:=+haproxy-nossl
endef
define Package/luci-app-haproxy-tcp/description
LuCI Support for HAProxy-TCP.
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/luci-app-haproxy-tcp/postinst
#!/bin/sh
if [ -z "$${IPKG_INSTROOT}" ]; then
if [ -f /etc/uci-defaults/luci-haproxy-tcp ]; then
( . /etc/uci-defaults/luci-haproxy-tcp ) && \
rm -f /etc/uci-defaults/luci-haproxy-tcp
fi
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache
fi
exit 0
endef
define Package/luci-app-haproxy-tcp/prerm
#!/bin/sh
/etc/init.d/haproxy-tcp disable
/etc/init.d/haproxy-tcp stop
rm -f /usr/sbin/haproxy-tcp
exit 0
endef
define Package/luci-app-haproxy-tcp/conffiles
/etc/config/haproxy-tcp
endef
define Package/luci-app-haproxy-tcp/install
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_DATA) ./luasrc/controller/*.lua $(1)/usr/lib/lua/luci/controller/
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi
$(INSTALL_DATA) ./luasrc/model/cbi/*.lua $(1)/usr/lib/lua/luci/model/cbi/
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DATA) ./root/etc/config/haproxy-tcp $(1)/etc/config/haproxy-tcp
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./root/etc/init.d/haproxy-tcp $(1)/etc/init.d/haproxy-tcp
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./root/etc/uci-defaults/luci-haproxy-tcp $(1)/etc/uci-defaults/luci-haproxy-tcp
$(INSTALL_DIR) $(1)/usr/sbin
$(LN) haproxy $(1)/usr/sbin/haproxy-tcp
endef
$(eval $(call BuildPackage,luci-app-haproxy-tcp))

View file

@ -0,0 +1,69 @@
OpenWrt/LEDE LuCI for HAProxy-TCP
===
简介
---
本软件包是 HAProxy-TCP 的 LuCI 控制界面,
软件包文件结构:
```
/
├── etc/
│   ├── config/
│   │   └── haproxy-tcp // UCI 配置文件
│   │── init.d/
│   │   └── haproxy-tcp // init 脚本
│   └── uci-defaults/
│      └── luci-haproxy-tcp // uci-defaults 脚本
└── usr/
└── lib/
└── lua/
└── luci/ // LuCI 部分
├── controller/
│   └── haproxy-tcp.lua // LuCI 菜单配置
├── i18n/ // LuCI 语言文件目录
│   └── haproxy-tcp.zh-cn.lmo
└── model/
└── cbi/
└── haproxy-tcp.lua // LuCI 基本设置
```
依赖
---
软件包的正常使用需要依赖 `haproxy` .
预览
---
![preview](https://github.com/chenhw2/luci-app-haproxy-tcp/blob/master/preview.png)
配置
---
软件包的配置文件路径: `/etc/config/haproxy-tcp`
此文件为 UCI 配置文件, 配置方式可参考 [Wiki -> Use-UCI-system][Use-UCI-system] 和 [OpenWrt Wiki][uci]
编译
---
从 OpenWrt 的 [SDK][openwrt-sdk] 编译
```bash
# 解压下载好的 SDK
tar xjf OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
cd OpenWrt-SDK-ar71xx-*
# Clone 项目
git clone https://github.com/chenhw2/luci-app-haproxy-tcp.git package/feeds/luci-app-haproxy-tcp
# 编译 po2lmo (如果有po2lmo可跳过)
pushd package/feeds/luci-app-haproxy-tcp/tools/po2lmo
make && sudo make install
popd
# 选择要编译的包 LuCI -> 3. Applications
make menuconfig
# 开始编译
make package/feeds/luci-app-haproxy-tcp/compile V=s
```
[openwrt-sdk]: https://wiki.openwrt.org/doc/howto/obtain.firmware.sdk
[Use-UCI-system]: https://github.com/shadowsocks/luci-app-shadowsocks/wiki/Use-UCI-system
[uci]: https://wiki.openwrt.org/doc/uci

View file

@ -0,0 +1,7 @@
module("luci.controller.haproxy-tcp", package.seeall)
function index()
entry(
{"admin", "services", "haproxy-tcp"},
cbi("haproxy-tcp"), _("HAProxy-TCP"), 55)
end

View file

@ -0,0 +1,57 @@
local m, s, o
if luci.sys.call("pgrep haproxy-tcp >/dev/null") == 0 then
m = Map("haproxy-tcp", translate("HAProxy-TCP"), "%s - %s" %{translate("HAProxy-TCP"), translate("RUNNING")})
else
m = Map("haproxy-tcp", translate("HAProxy-TCP"), "%s - %s" %{translate("HAProxy-TCP"), translate("NOT RUNNING")})
end
s = m:section(TypedSection, "general", translate("General Setting"),
"<a target=\"_blank\" href=\"http://%s:%s\">%s</a>" %{
luci.sys.exec("uci get network.lan.ipaddr | tr -d '\r\n'"),
luci.sys.exec("uci get haproxy-tcp.general.admin_stats | tr -d '\r\n'"),
translate("Status Admin")
})
s.anonymous = true
o = s:option(Flag, "enable", translate("Enable"))
o.rmempty = false
o = s:option(Value, "startup_delay", translate("Startup Delay"))
o:value(0, translate("Not enabled"))
for _, v in ipairs({5, 10, 15, 25, 40}) do
o:value(v, translate("%u seconds") %{v})
end
o.datatype = "uinteger"
o.default = 0
o.rmempty = false
o = s:option(Value, "admin_stats", "%s%s" %{translate("Status Admin"), translate("Port")})
o.placeholder = "7777"
o.default = "7777"
o.datatype = "port"
o.rmempty = false
o = s:option(Value, "listen", translate("Listen Address:Port"))
o.placeholder = "0.0.0.0:6666"
o.default = "0.0.0.0:6666"
o.rmempty = false
o = s:option(Value, "timeout", translate("Timeout Connect (ms)"))
o.placeholder = "666"
o.default = "666"
o.datatype = "range(33, 10000)"
o.rmempty = false
o = s:option(Value, "retries", translate("Retries"))
o.placeholder = "1"
o.default = "1"
o.datatype = "range(1, 10)"
o.rmempty = false
o = s:option(DynamicList, "upstreams", translate("UpStream Server"), translate("e.g. [123.123.123.123:65101 check]"))
o.placeholder = "123.123.123.123:65101"
o.rmempty = false
return m

View file

@ -0,0 +1,47 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
msgid "%u seconds"
msgstr ""
msgid "Enable"
msgstr ""
msgid "General Setting"
msgstr ""
msgid "HAProxy-TCP"
msgstr ""
msgid "Listen Address:Port"
msgstr ""
msgid "NOT RUNNING"
msgstr ""
msgid "Not enabled"
msgstr ""
msgid "Port"
msgstr ""
msgid "RUNNING"
msgstr ""
msgid "Retries"
msgstr ""
msgid "Startup Delay"
msgstr ""
msgid "Status Admin"
msgstr ""
msgid "Timeout Connect (ms)"
msgstr ""
msgid "UpStream Server"
msgstr ""
msgid "e.g. [123.123.123.123:65101 check]"
msgstr ""

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View file

@ -0,0 +1,9 @@
config general 'general'
option enable '0'
option retries '1'
option timeout '1000'
option listen '0.0.0.0:65101'
option admin_stats '7777'
option startup_delay '5'
list upstreams '1.2.3.4:65101'

View file

@ -0,0 +1,110 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2016 chenhw2 <chenhw2@github.com>
# Copyright (C) 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
START=85
USE_PROCD=1
PROG_NAME=haproxy-tcp
PROG=/usr/sbin/${PROG_NAME}
PIDCOUNT=0
_log() {
logger -p daemon.info -t ${PROG_NAME} "$@"
}
_err() {
logger -p daemon.err -t ${PROG_NAME} "$@"
}
validate_section() {
uci_validate_section haproxy-tcp general "${1}" \
'enable:bool:0' \
'retries:uinteger:1' \
'timeout:uinteger:1000' \
'startup_delay:uinteger:5' \
'admin_stats:port:7777' \
'listen:string' \
'upstreams:list(string)'
}
genline_srv(){
line="$1"
hash="$(echo -n $line | md5sum | cut -c1-6)"
hash="$(echo -n $line | tr -d '\t ' | cut -c1-8)__$hash"
echo " server $hash $line" | tr -d "\'"
}
boot() {
local delay=$(uci -q get $NAME.general.startup_delay)
(sleep ${delay:-0} && start >/dev/null 2>&1) &
return 0
}
start_instance() {
local enable retries timeout admin_stats startup_delay listen upstreams
validate_section "${1}" || {
_err "validation failed"
return 1
}
[ "$enable" = 1 ] || return 1
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
mkdir -p /var/etc
cat <<-EOF > /var/etc/$PROG_NAME.cfg
global
nbproc $(grep -c '^processor' /proc/cpuinfo | tr -d "\n")
defaults
mode tcp
retries ${retries:-2}
timeout connect ${timeout:-1000}
listen admin_stats
bind 0.0.0.0:${admin_stats:-7777}
mode http
stats uri /
stats refresh 10s
frontend tcp-in
bind ${listen:-0.0.0.0:6666}
default_backend tcp-out
backend tcp-out
$( if [ 0 -lt $(grep -c weight /etc/config/$PROG_NAME) ]; then
echo " balance static-rr"
sed -n 's/.*upstreams[\t ]*//p' /etc/config/$PROG_NAME |
while read upstream; do
genline_srv "$upstream"
done
else
config_list_foreach "${1}" "upstreams" genline_srv
fi
)
EOF
procd_open_instance
procd_set_param command ${PROG} \
-q -D -f /var/etc/$PROG_NAME.cfg \
-p /var/run/${PROG}.${PIDCOUNT}.pid
procd_set_param respawn 0 30 0
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
start_service() {
config_load haproxy-tcp
config_foreach start_instance general
}
service_triggers() {
procd_add_reload_trigger haproxy-tcp general
}

View file

@ -0,0 +1,15 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@haproxy-tcp[-1]
add ucitrack haproxy-tcp
set ucitrack.@haproxy-tcp[-1].init=haproxy-tcp
commit ucitrack
EOF
/etc/init.d/haproxy stop
/etc/init.d/haproxy disable
/etc/init.d/haproxy-tcp enable
exit 0