mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-18 17:33:31 +00:00
add new luci-app-haproxy-tcp package
This commit is contained in:
parent
b690341dcb
commit
09581e13be
@ -21,8 +21,6 @@ include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/he-6in4
|
||||
SECTION:=ipv6
|
||||
CATEGORY:=Gmod
|
||||
SUBMENU:=Network
|
||||
TITLE:=Dynamic Update he.net of ip
|
||||
PKGARCH:=all
|
||||
DEPENDS:=+luci-proto-ipv6 +6in4 +curl
|
||||
|
51
package/lean/luci-app-haproxy-tcp/Makefile
Normal file
51
package/lean/luci-app-haproxy-tcp/Makefile
Normal file
@ -0,0 +1,51 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-haproxy-tcp
|
||||
PKG_VERSION=1.4
|
||||
PKG_RELEASE:=1
|
||||
PKG_MAINTAINER:=Alex Zhuo <1886090@gmail.com>
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/$(PKG_NAME)
|
||||
CATEGORY:=Utilities
|
||||
SUBMENU:=Luci
|
||||
TITLE:=luci for haproxy and shadowsocks
|
||||
PKGARCH:=all
|
||||
DEPENDS:=+haproxy
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
A luci app for haproxy with shadowsocks
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/postinst
|
||||
#!/bin/sh
|
||||
rm -rf /tmp/luci*
|
||||
echo stopping haproxy
|
||||
/etc/init.d/haproxy stop
|
||||
/etc/init.d/haproxy disable
|
||||
echo haproxy disabled
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(foreach po,$(wildcard ${CURDIR}/i18n/zh-cn/*.po), \
|
||||
po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));)
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
|
||||
$(INSTALL_DATA) $(PKG_BUILD_DIR)/*.*.lmo $(1)/usr/lib/lua/luci/i18n/
|
||||
$(CP) ./files/* $(1)/
|
||||
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
54
package/lean/luci-app-haproxy-tcp/README.md
Normal file
54
package/lean/luci-app-haproxy-tcp/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
# luci-app-haproxy-tcp
|
||||
OpenWrt HAProxy的Luci配置页面,已在[该固件][A]中使用
|
||||
|
||||
简介
|
||||
---
|
||||
|
||||
本软件包为OpenWRT HAPrxoy的 LuCI 控制界面,用于Shadowsocks在多服务器条件下实现负载均衡和高可用
|
||||
|
||||
可以设置多个主服务器或多个备用服务器. 默认监听端口127.0.0.1:2222 后台监控页面端口0.0.0.0:1111,后台监控页面地址192.168.1.1:1111/haproxy
|
||||
|
||||
多主服务器是将所有TCP流量分流,并可以设置每个服务器的分流比例;多备用服务器是在检测到主服务器A宕机之后切换至备用服务器B,B宕机之后切换到服务器C...依次类推,可以防止因为单个服务器或者线路故障导致的断网问题。
|
||||
使用效果和更多使用方法请[点击这里][A]
|
||||
|
||||
|
||||
依赖
|
||||
---
|
||||
|
||||
显式依赖 `haproxy`, 安装完毕该luci包后会stop并disable当前op的haproxy,点击“保存&应用”后会修改HAProxy默认配置文件/etc/haproxy.cfg并自动重启,支持开机自启.
|
||||
|
||||
|
||||
配置
|
||||
---
|
||||
|
||||
如果有需要,可以修改/etc/haproxy_init.sh ,不要直接修改/etc/haproxy.cfg,否则会被覆盖
|
||||
|
||||
编译
|
||||
---
|
||||
|
||||
从 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/AlexZhuo/luci-app-haproxy-tcp package/luci-app-haproxy-tcp
|
||||
# 编译 po2lmo (如果有po2lmo可跳过)
|
||||
pushd package/luci-app-haproxy-tcp/tools/po2lmo
|
||||
make && sudo make install
|
||||
popd
|
||||
# 选择要编译的包 Utilities -> LuCI -> luci-app-haproxy-tcp
|
||||
make menuconfig
|
||||
# 开始编译
|
||||
make package/luci-app-haproxy-tcp/compile V=99
|
||||
```
|
||||
|
||||
|
||||
截图
|
||||
---
|
||||

|
||||
|
||||
[A]: http://www.right.com.cn/forum/thread-198649-1-1.html
|
||||
[openwrt-sdk]: http://wiki.openwrt.org/doc/howto/obtain.firmware.sdk
|
||||
|
||||
|
29
package/lean/luci-app-haproxy-tcp/files/etc/config/haproxy
Normal file
29
package/lean/luci-app-haproxy-tcp/files/etc/config/haproxy
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
config arguments
|
||||
option enabled '0'
|
||||
|
||||
config main_server
|
||||
option server_weight '10'
|
||||
option server_ip '1.2.3.4'
|
||||
option server_port '443'
|
||||
option server_name 'JP1'
|
||||
option validate '1'
|
||||
|
||||
config backup_server
|
||||
option server_name 'JP2'
|
||||
option server_ip '2.2.2.2'
|
||||
option server_port '8038'
|
||||
option validate '1'
|
||||
|
||||
config backup_server
|
||||
option server_name 'JP3'
|
||||
option server_ip '3.3.3.3'
|
||||
option server_port '443'
|
||||
option validate '1'
|
||||
|
||||
config backup_server
|
||||
option server_name 'JP4'
|
||||
option server_ip '4.4.4.4'
|
||||
option server_port '443'
|
||||
option validate '1'
|
||||
|
129
package/lean/luci-app-haproxy-tcp/files/etc/haproxy_init.sh
Executable file
129
package/lean/luci-app-haproxy-tcp/files/etc/haproxy_init.sh
Executable file
@ -0,0 +1,129 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
CFG_FILE=/etc/haproxy.cfg
|
||||
stop(){
|
||||
logger -t alex stopping haproxy
|
||||
echo "stopping haproxy"
|
||||
/etc/init.d/haproxy disable
|
||||
/etc/init.d/haproxy stop
|
||||
[ -f /etc/haproxy_backup ] && {
|
||||
cp /etc/haproxy_backup /etc/init.d/haproxy
|
||||
}
|
||||
iptables -t nat -D OUTPUT -j HAPROXY &> /dev/null
|
||||
iptables -t nat -F HAPROXY &> /dev/null
|
||||
sleep 1
|
||||
iptables -t nat -X HAPROXY &> /dev/null
|
||||
}
|
||||
start(){
|
||||
echo "starting haproxy"
|
||||
logger -t alex restarting haproxy
|
||||
echo global > $CFG_FILE
|
||||
cat >> $CFG_FILE <<EOF
|
||||
log 127.0.0.1 local0 #[日志输出配置,所有日志都记录在本机,通过local0输出]
|
||||
log 127.0.0.1 local1 notice #定义haproxy 日志级别[error warringinfo debug]
|
||||
daemon #以后台形式运行harpoxy
|
||||
nbproc 1 #设置进程数量
|
||||
pidfile /var/run/haproxy.pid
|
||||
ulimit-n 1024 #ulimit 的数量限制
|
||||
maxconn 1024 #默认最大连接数,需考虑ulimit-n限制
|
||||
#chroot /usr/local/haproxy
|
||||
defaults
|
||||
log global
|
||||
mode tcp #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK
|
||||
retries 3 #两次连接失败就认为是服务器不可用,也可以通过后面设置
|
||||
option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接
|
||||
option redispatch
|
||||
maxconn 1024 #默认的最大连接数
|
||||
timeout connect 5000ms #连接超时
|
||||
timeout client 30000ms #客户端超时
|
||||
timeout server 30000ms #服务器超时
|
||||
balance roundrobin #设置默认负载均衡方式,轮询方式
|
||||
#balance source #设置默认负载均衡方式,类似于nginx的ip_hash
|
||||
#balnace leastconn #设置默认负载均衡方式,最小连接数
|
||||
listen admin_stats
|
||||
bind 0.0.0.0:1111 #节点统计页面的访问端口
|
||||
mode http #http的7层模式
|
||||
option httplog #采用http日志格式
|
||||
maxconn 10 #节点统计页面默认的最大连接数
|
||||
stats refresh 30s #节点统计页面自动刷新时间
|
||||
stats uri /haproxy #节点统计页面url
|
||||
stats realm Haproxy #统计页面密码框上提示文本
|
||||
stats auth admin:root #设置监控页面的用户和密码:admin,可以设置多个用户名
|
||||
stats admin if TRUE #设置手工启动/禁用,后端服务器(haproxy-1.4.9以后版本)
|
||||
frontend ss-in
|
||||
bind 127.0.0.1:2222
|
||||
default_backend ss-out
|
||||
backend ss-out
|
||||
mode tcp
|
||||
balance roundrobin
|
||||
option tcplog
|
||||
EOF
|
||||
local COUNTER=0
|
||||
#添加主服务器
|
||||
iptables -t nat -X HAPROXY
|
||||
iptables -t nat -N HAPROXY
|
||||
iptables -t nat -F HAPROXY
|
||||
|
||||
while true
|
||||
do
|
||||
local server_ip=`uci get haproxy.@main_server[$COUNTER].server_ip 2>/dev/null`
|
||||
local server_name=`uci get haproxy.@main_server[$COUNTER].server_name 2>/dev/null`
|
||||
local server_port=`uci get haproxy.@main_server[$COUNTER].server_port 2>/dev/null`
|
||||
local server_weight=`uci get haproxy.@main_server[$COUNTER].server_weight 2>/dev/null`
|
||||
local validate=`uci get haproxy.@main_server[$COUNTER].validate 2>/dev/null`
|
||||
if [ -z "$server_ip" ] || [ -z "$server_name" ] || [ -z "$server_port" ] || [ -z "$server_weight" ]; then
|
||||
echo break
|
||||
break
|
||||
fi
|
||||
echo the main server $COUNTER $server_ip $server_name $server_port $server_weight
|
||||
[ "$validate" = 1 ] && {
|
||||
echo server $server_name $server_ip:$server_port weight $server_weight maxconn 1024 check inter 1500 rise 3 fall 3 >> $CFG_FILE
|
||||
}
|
||||
iptables -t nat -A HAPROXY -p tcp -d $server_ip -j ACCEPT
|
||||
COUNTER=$(($COUNTER+1))
|
||||
done
|
||||
COUNTER=0
|
||||
#添加备用服务器
|
||||
while true
|
||||
do
|
||||
local server_ip=`uci get haproxy.@backup_server[$COUNTER].server_ip 2>/dev/null`
|
||||
local server_name=`uci get haproxy.@backup_server[$COUNTER].server_name 2>/dev/null`
|
||||
local server_port=`uci get haproxy.@backup_server[$COUNTER].server_port 2>/dev/null`
|
||||
local validate=`uci get haproxy.@backup_server[$COUNTER].validate 2>/dev/null`
|
||||
if [ -z "$server_ip" ] || [ -z "$server_name" ] || [ -z "$server_port" ]; then
|
||||
echo break
|
||||
break
|
||||
fi
|
||||
echo the backup server $COUNTER $server_ip $server_name $server_port
|
||||
[ "$validate" = 1 ] && {
|
||||
echo server $server_name $server_ip:$server_port weight 10 check backup inter 1500 rise 3 fall 3 >> $CFG_FILE
|
||||
}
|
||||
iptables -t nat -A HAPROXY -p tcp -d $server_ip -j ACCEPT
|
||||
COUNTER=$(($COUNTER+1))
|
||||
done
|
||||
iptables -t nat -I OUTPUT -j HAPROXY
|
||||
/etc/init.d/haproxy enable
|
||||
/etc/init.d/haproxy restart
|
||||
cp /etc/init.d/haproxy /etc/haproxy_backup
|
||||
cp /etc/haproxy_start /etc/init.d/haproxy
|
||||
}
|
||||
|
||||
restart(){
|
||||
echo luci for haproxy
|
||||
sleep 1s
|
||||
local vt_enabled=`uci get haproxy.@arguments[0].enabled 2>/dev/null`
|
||||
logger -t alex !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!haproxy is initializing enabled is $vt_enabled
|
||||
echo $vt_enabled
|
||||
if [ "$vt_enabled" = 1 ]; then
|
||||
[ -f /etc/haproxy_backup ] && {
|
||||
cp /etc/haproxy_backup /etc/init.d/haproxy
|
||||
}
|
||||
iptables -t nat -D OUTPUT -j HAPROXY &> /dev/null
|
||||
iptables -t nat -F HAPROXY &> /dev/null
|
||||
sleep 1
|
||||
iptables -t nat -X HAPROXY &> /dev/null
|
||||
start;
|
||||
else
|
||||
stop;
|
||||
fi
|
||||
}
|
73
package/lean/luci-app-haproxy-tcp/files/etc/haproxy_start
Executable file
73
package/lean/luci-app-haproxy-tcp/files/etc/haproxy_start
Executable file
@ -0,0 +1,73 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2009-2010 OpenWrt.org
|
||||
|
||||
START=99
|
||||
STOP=80
|
||||
|
||||
SERVICE_USE_PID=1
|
||||
|
||||
HAPROXY_BIN="/usr/sbin/haproxy"
|
||||
HAPROXY_CONFIG="/etc/haproxy.cfg"
|
||||
HAPROXY_PID="/var/run/haproxy.pid"
|
||||
|
||||
start() {
|
||||
service_start $HAPROXY_BIN -q -D -f "$HAPROXY_CONFIG" -p "$HAPROXY_PID"
|
||||
local COUNTER=0
|
||||
#添加主服务器
|
||||
iptables -t nat -D OUTPUT -j HAPROXY &> /dev/null
|
||||
iptables -t nat -X HAPROXY
|
||||
iptables -t nat -N HAPROXY
|
||||
iptables -t nat -F HAPROXY
|
||||
|
||||
while true
|
||||
do
|
||||
local server_ip=`uci get haproxy.@main_server[$COUNTER].server_ip 2>/dev/null`
|
||||
local server_name=`uci get haproxy.@main_server[$COUNTER].server_name 2>/dev/null`
|
||||
local server_port=`uci get haproxy.@main_server[$COUNTER].server_port 2>/dev/null`
|
||||
local server_weight=`uci get haproxy.@main_server[$COUNTER].server_weight 2>/dev/null`
|
||||
local validate=`uci get haproxy.@main_server[$COUNTER].validate 2>/dev/null`
|
||||
if [ -z "$server_ip" ] || [ -z "$server_name" ] || [ -z "$server_port" ] || [ -z "$server_weight" ]; then
|
||||
echo break
|
||||
break
|
||||
fi
|
||||
echo the main2 server $COUNTER $server_ip $server_name $server_port $server_weight
|
||||
[ "$validate" = 1 ] && {
|
||||
iptables -t nat -A HAPROXY -p tcp -d $server_ip -j ACCEPT
|
||||
}
|
||||
COUNTER=$(($COUNTER+1))
|
||||
done
|
||||
COUNTER=0
|
||||
#添加备用服务器
|
||||
while true
|
||||
do
|
||||
local server_ip=`uci get haproxy.@backup_server[$COUNTER].server_ip 2>/dev/null`
|
||||
local server_name=`uci get haproxy.@backup_server[$COUNTER].server_name 2>/dev/null`
|
||||
local server_port=`uci get haproxy.@backup_server[$COUNTER].server_port 2>/dev/null`
|
||||
local validate=`uci get haproxy.@backup_server[$COUNTER].validate 2>/dev/null`
|
||||
if [ -z "$server_ip" ] || [ -z "$server_name" ] || [ -z "$server_port" ]; then
|
||||
echo break
|
||||
break
|
||||
fi
|
||||
echo the backup2 server $COUNTER $server_ip $server_name $server_port
|
||||
[ "$validate" = 1 ] && {
|
||||
iptables -t nat -A HAPROXY -p tcp -d $server_ip -j ACCEPT
|
||||
}
|
||||
COUNTER=$(($COUNTER+1))
|
||||
done
|
||||
|
||||
iptables -t nat -I OUTPUT -j HAPROXY
|
||||
}
|
||||
|
||||
stop() {
|
||||
kill -9 $(cat $HAPROXY_PID | tr "\n" " ")
|
||||
service_stop $HAPROXY_BIN
|
||||
iptables -t nat -D OUTPUT -j HAPROXY &> /dev/null
|
||||
iptables -t nat -F HAPROXY &> /dev/null
|
||||
sleep 1
|
||||
iptables -t nat -X HAPROXY &> /dev/null
|
||||
}
|
||||
|
||||
reload() {
|
||||
$HAPROXY_BIN -D -q -f $HAPROXY_CONFIG -p $HAPROXY_PID -sf $(cat $HAPROXY_PID | tr "\n" " ")
|
||||
#$HAPROXY_BIN -D -q -f $HAPROXY_CONFIG -p $HAPROXY_PID -sf $(cat $HAPROXY_PID)
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
module("luci.controller.haproxy", package.seeall)
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/haproxy") then
|
||||
return
|
||||
end
|
||||
entry({"admin", "services", "haproxy"}, cbi("haproxy"), _("HAProxy")).dependent = true
|
||||
end
|
@ -0,0 +1,67 @@
|
||||
--Alex<1886090@gmail.com>
|
||||
local fs = require "nixio.fs"
|
||||
|
||||
function sync_value_to_file(value, file) --用来写入文件的函数,目前这种方式已经弃用
|
||||
value = value:gsub("\r\n?", "\n")
|
||||
local old_value = nixio.fs.readfile(file)
|
||||
if value ~= old_value then
|
||||
nixio.fs.writefile(file, value)
|
||||
end
|
||||
end
|
||||
local state_msg = ""
|
||||
local haproxy_on = (luci.sys.call("pidof haproxy > /dev/null") == 0)
|
||||
local router_ip = luci.sys.exec("uci get network.lan.ipaddr")
|
||||
if haproxy_on then
|
||||
state_msg = "<b><font color=\"green\">" .. translate("Running") .. "</font></b>"
|
||||
else
|
||||
state_msg = "<b><font color=\"red\">" .. translate("Not running") .. "</font></b>"
|
||||
end
|
||||
m=Map("haproxy",translate("HAProxy"),translate("HAProxy能够检测Shadowsocks服务器的连通情况,从而实现负载均衡和高可用的功能,支持主备用服务器宕机自动切换,并且可以设置多个主服务器用于分流,规定每个分流节点的流量比例等。前提条件是你的所有Shadowsocks服务器的【加密方式】和【密码】一致。<br><br>使用方法:配置好你的Shadowsocks服务器ip地址和端口,然后开启Shadowsocks服务,将服务器地址填写为【127.0.0.1】,端口【2222】,其他参数和之前一样即可,你可以通过访问【路由器的IP:1111/haproxy】输入用户名admin,密码root来观察各节点健康状况,红色为宕机,绿色正常,使用说明请<a href='http://www.right.com.cn/forum/thread-198649-1-1.html'>点击这里</a>") .. "<br><br>后台监控页面:<a href='http://" .. router_ip .. ":1111/haproxy'>" .. router_ip .. ":1111/haproxy</a> 用户名admin,密码root" .. "<br><br>状态 - " .. state_msg)
|
||||
s=m:section(TypedSection,"arguments","")
|
||||
s.addremove=false
|
||||
s.anonymous=true
|
||||
view_enable = s:option(Flag,"enabled",translate("Enable"))
|
||||
--通过读写配置文件控制HAProxy这种方式已经弃用
|
||||
--view_cfg = s:option(TextValue, "1", nil)
|
||||
--view_cfg.rmempty = false
|
||||
--view_cfg.rows = 43
|
||||
|
||||
--function view_cfg.cfgvalue()
|
||||
-- return nixio.fs.readfile("/etc/haproxy.cfg") or ""
|
||||
--end
|
||||
--function view_cfg.write(self, section, value)
|
||||
-- sync_value_to_file(value, "/etc/haproxy.cfg")
|
||||
--end
|
||||
s=m:section(TypedSection,"main_server","<b>" .. translate("Main Server List") .. "<b>")
|
||||
s.anonymous=true
|
||||
s.addremove=true
|
||||
o=s:option(Value,"server_name",translate("Display Name"),translate("Only English Characters,No spaces"))
|
||||
o.rmempty = false
|
||||
|
||||
o=s:option(Flag,"validate",translate("validate"))
|
||||
|
||||
o=s:option(Value,"server_ip",translate("Proxy Server IP"))
|
||||
o.datatype="ip4addr"
|
||||
o=s:option(Value,"server_port",translate("Proxy Server Port"))
|
||||
o.datatype="uinteger"
|
||||
o=s:option(Value,"server_weight",translate("Weight"))
|
||||
o.datatype="uinteger"
|
||||
|
||||
s=m:section(TypedSection,"backup_server","<b>" .. translate("Backup Server List") .. "<b>")
|
||||
s.anonymous=true
|
||||
s.addremove=true
|
||||
o=s:option(Value,"server_name",translate("Display Name"),translate("Only English Characters,No spaces"))
|
||||
o.rmempty = false
|
||||
|
||||
o=s:option(Flag,"validate",translate("validate"))
|
||||
|
||||
o=s:option(Value,"server_ip",translate("Proxy Server IP"))
|
||||
o.datatype="ip4addr"
|
||||
o=s:option(Value,"server_port",translate("Proxy Server Port"))
|
||||
o.datatype="uinteger"
|
||||
-- ---------------------------------------------------
|
||||
local apply = luci.http.formvalue("cbi.apply")
|
||||
if apply then
|
||||
os.execute("/etc/haproxy_init.sh restart >/dev/null 2>&1 &")
|
||||
end
|
||||
return m
|
34
package/lean/luci-app-haproxy-tcp/i18n/zh-cn/haproxy.zh-cn.po
Executable file
34
package/lean/luci-app-haproxy-tcp/i18n/zh-cn/haproxy.zh-cn.po
Executable file
@ -0,0 +1,34 @@
|
||||
msgid "Running"
|
||||
msgstr "运行中"
|
||||
|
||||
msgid "Not running"
|
||||
msgstr "未运行"
|
||||
|
||||
msgid "Main Server List"
|
||||
msgstr "主服务器列表"
|
||||
|
||||
msgid "Display Name"
|
||||
msgstr "服务器名称"
|
||||
|
||||
msgid "Only English Characters,No spaces"
|
||||
msgstr "仅限英文字母,不要有空格"
|
||||
|
||||
msgid "Proxy Server IP"
|
||||
msgstr "代理服务器IP"
|
||||
|
||||
msgid "Proxy Server Port"
|
||||
msgstr "代理服务器端口"
|
||||
|
||||
msgid "Weight"
|
||||
msgstr "分流权重"
|
||||
|
||||
msgid "Backup Server List"
|
||||
msgstr "备用服务器列表"
|
||||
|
||||
msgid "validate"
|
||||
msgstr "生效"
|
||||
|
||||
|
||||
|
||||
|
||||
|
BIN
package/lean/luci-app-haproxy-tcp/tools/po2lmo/src/po2lmo
Executable file
BIN
package/lean/luci-app-haproxy-tcp/tools/po2lmo/src/po2lmo
Executable file
Binary file not shown.
@ -1,21 +0,0 @@
|
||||
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.
|
@ -1,86 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2016 chenhw2 <chenhw2@github.com>
|
||||
#
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-haproxy-tcp
|
||||
PKG_VERSION:=0.1.4
|
||||
PKG_RELEASE:=2
|
||||
|
||||
PKG_LICENSE:=MIT
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
PKG_MAINTAINER:=chenhw2 <chenhw2@github.com>
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
include $(INCLUDE_DIR)/package.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/Prepare
|
||||
$(foreach po,$(wildcard ${CURDIR}/files/luci/i18n/*.po), \
|
||||
po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));)
|
||||
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/i18n
|
||||
$(INSTALL_DATA) $(PKG_BUILD_DIR)/haproxy-tcp.*.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
|
||||
$(INSTALL_DATA) ./files/luci/model/cbi/*.lua $(1)/usr/lib/lua/luci/model/cbi/
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_DATA) ./files/root/etc/config/haproxy-tcp $(1)/etc/config/haproxy-tcp
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/root/etc/init.d/haproxy-tcp $(1)/etc/init.d/haproxy-tcp
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/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))
|
@ -1,7 +0,0 @@
|
||||
module("luci.controller.haproxy-tcp", package.seeall)
|
||||
|
||||
function index()
|
||||
entry(
|
||||
{"admin", "services", "haproxy-tcp"},
|
||||
cbi("haproxy-tcp"), _("HAProxy-TCP"), 55)
|
||||
end
|
@ -1,35 +0,0 @@
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
||||
msgid "%u seconds"
|
||||
msgstr "%u 秒"
|
||||
|
||||
msgid "Enable"
|
||||
msgstr "启用"
|
||||
|
||||
msgid "General Setting"
|
||||
msgstr "基本设置"
|
||||
|
||||
msgid "HAProxy-TCP"
|
||||
msgstr "负载均衡-TCP"
|
||||
|
||||
msgid "Listen Address:Port"
|
||||
msgstr "服务地址"
|
||||
|
||||
msgid "Retries"
|
||||
msgstr "重试次数"
|
||||
|
||||
msgid "Status Admin"
|
||||
msgstr "状态管理"
|
||||
|
||||
msgid "Startup Delay"
|
||||
msgstr "自启动延时"
|
||||
|
||||
msgid "Port"
|
||||
msgstr "端口"
|
||||
|
||||
msgid "Timeout Connect (ms)"
|
||||
msgstr "连接超时 (毫秒)"
|
||||
|
||||
msgid "UpStream Server"
|
||||
msgstr "上游服务器"
|
@ -1,57 +0,0 @@
|
||||
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. [8.8.8.8:53 weight 100]"))
|
||||
o.placeholder = "8.8.8.8:53"
|
||||
o.rmempty = false
|
||||
|
||||
return m
|
@ -1,9 +0,0 @@
|
||||
|
||||
config general 'general'
|
||||
option enable '0'
|
||||
option retries '1'
|
||||
option timeout '1000'
|
||||
option listen '0.0.0.0:6666'
|
||||
option admin_stats '7777'
|
||||
option startup_delay '5'
|
||||
list upstreams '1.2.3.4:8388'
|
@ -1,74 +0,0 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=85
|
||||
NAME=haproxy-tcp
|
||||
|
||||
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() {
|
||||
enable=$(uci -q get $NAME.general.enable)
|
||||
[ "$enable" = 1 ] || return 0
|
||||
listen=$(uci -q get $NAME.general.listen)
|
||||
admin_stats=$(uci -q get $NAME.general.admin_stats)
|
||||
retries=$(uci -q get $NAME.general.retries)
|
||||
timeout=$(uci -q get $NAME.general.timeout)
|
||||
upstreams=$(uci -q get $NAME.general.upstreams)
|
||||
|
||||
mkdir -p /var/etc
|
||||
cat <<-EOF > /var/etc/$NAME.cfg
|
||||
global
|
||||
nbproc 2
|
||||
|
||||
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/$NAME) ]; then
|
||||
echo " balance static-rr"
|
||||
sed -n 's/.*upstreams[\t ]*//p' /etc/config/$NAME |
|
||||
while read upstream; do
|
||||
genline_srv "$upstream"
|
||||
done
|
||||
else
|
||||
for upstream in $upstreams; do
|
||||
genline_srv "$upstream"
|
||||
done
|
||||
fi
|
||||
)
|
||||
|
||||
EOF
|
||||
|
||||
/usr/sbin/$NAME -q -D -f /var/etc/$NAME.cfg -p /var/run/$NAME.pid
|
||||
}
|
||||
|
||||
kill_all() {
|
||||
kill -9 $(pgrep -f $@) >/dev/null 2>&1
|
||||
}
|
||||
|
||||
stop() {
|
||||
kill_all "$NAME.pid"
|
||||
rm -rf /var/etc/$NAME.cfg
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#!/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
|
Loading…
Reference in New Issue
Block a user