mirror of
https://github.com/roacn/openwrt-packages.git
synced 2025-01-07 03:16:45 +08:00
🎉 Sync 2024-12-09 00:30
This commit is contained in:
parent
a95e7f674c
commit
0459d63a77
@ -7,7 +7,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=floatip
|
||||
PKG_VERSION:=1.0.1
|
||||
PKG_VERSION:=1.0.4
|
||||
PKG_RELEASE:=1
|
||||
PKG_MAINTAINER:=jjm2473 <jjm2473@gmail.com>
|
||||
|
||||
@ -18,6 +18,7 @@ define Package/$(PKG_NAME)
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=IP Addresses and Names
|
||||
TITLE:=Float IP
|
||||
DEPENDS:=+iputils-arping
|
||||
PKGARCH:=all
|
||||
endef
|
||||
|
||||
|
@ -6,7 +6,9 @@ config floatip 'main'
|
||||
# option role 'main'
|
||||
# 对于 fallback 节点,检查到 check_ip 都不在线超过一定时间(例如30秒),就设置自身的 set_ip,然后检查 check_ip 中任一 IP 在线就清除自身的 set_ip,重复上述流程。
|
||||
# 对于 main 节点,启动后不断检查 set_ip ,直到 set_ip 不在线,就设置自身的 set_ip,然后退出进程。
|
||||
# set_ip 可以不提供前缀长度,将会按 lan 口配置的网段的长度
|
||||
option set_ip '192.168.100.3/24'
|
||||
# option set_ip '192.168.100.3'
|
||||
# check_ip 仅 fallback 有效,并且检查时只检查跟 set_ip 同一网段的
|
||||
list check_ip '192.168.100.2'
|
||||
# list check_ip '192.168.100.4'
|
||||
|
@ -12,34 +12,36 @@ start_service() {
|
||||
local set_ip set_prefix
|
||||
config_get set_ip "main" set_ip
|
||||
[[ -n "$set_ip" ]] || return 0
|
||||
eval "$(ipcalc.sh "$set_ip" )";set_prefix=$PREFIX;set_ip=$IP
|
||||
[[ "$set_ip" = 0.0.0.0 ]] && set_ip=192.168.100.3
|
||||
[[ "$set_prefix" = 0 ]] && set_prefix=24
|
||||
if [[ "$set_ip" = "*/*" ]]; then
|
||||
eval "$(ipcalc.sh "$set_ip" )";set_prefix=$PREFIX;set_ip=$IP
|
||||
else
|
||||
set_prefix=32
|
||||
fi
|
||||
local lan_ip="`uci -q get network.lan.ipaddr`"
|
||||
[[ -n "$lan_ip" ]] || return 0
|
||||
local lan_net lan_prefix set_net ip
|
||||
local in_range=0
|
||||
if echo "$lan_ip" | grep -Fq '/'; then
|
||||
for ip in $lan_ip; do
|
||||
eval "$(ipcalc.sh ${ip/\// } )";lan_net=$NETWORK;lan_prefix=$PREFIX
|
||||
[[ "$set_prefix" -ge "$lan_prefix" ]] || continue
|
||||
eval "$(ipcalc.sh $set_ip $lan_prefix } )";set_net=$NETWORK
|
||||
[[ "$set_net" = "$lan_net" ]] && {
|
||||
in_range=1
|
||||
break
|
||||
}
|
||||
done
|
||||
else
|
||||
local netmask="`uci -q get network.lan.netmask`"
|
||||
eval "$(ipcalc.sh "$lan_ip" "$netmask" )";lan_net=$NETWORK;lan_prefix=$PREFIX
|
||||
if [[ "$set_prefix" -ge "$lan_prefix" ]]; then
|
||||
eval "$(ipcalc.sh $set_ip $lan_prefix } )";set_net=$NETWORK
|
||||
[[ "$set_net" = "$lan_net" ]] && in_range=1
|
||||
local lan_netmask="`uci -q get network.lan.netmask`"
|
||||
for ip in $lan_ip; do
|
||||
if [[ "$ip" = "*/*" ]]; then
|
||||
eval "$(ipcalc.sh $ip )";lan_net=$NETWORK;lan_prefix=$PREFIX
|
||||
else
|
||||
# prefix=32 if not present
|
||||
[[ -n "$lan_netmask" ]] || continue
|
||||
eval "$(ipcalc.sh $ip $lan_netmask )";lan_net=$NETWORK;lan_prefix=$PREFIX
|
||||
fi
|
||||
fi
|
||||
[[ "$set_prefix" -ge "$lan_prefix" ]] || continue
|
||||
eval "$(ipcalc.sh $set_ip/$lan_prefix )";set_net=$NETWORK
|
||||
[[ "$set_net" = "$lan_net" ]] && {
|
||||
[[ "$set_prefix" = 32 ]] && set_prefix=$lan_prefix
|
||||
in_range=1
|
||||
break
|
||||
}
|
||||
done
|
||||
|
||||
[[ $in_range = 1 ]] || return 0
|
||||
procd_open_instance
|
||||
procd_set_param command /usr/libexec/floatip.sh
|
||||
procd_set_param command /usr/libexec/floatip.sh "$set_prefix"
|
||||
procd_set_param stderr 1
|
||||
procd_set_param file /etc/config/floatip
|
||||
procd_close_instance
|
||||
|
@ -1,5 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
DEFAULT_PREFIX=24
|
||||
|
||||
# random number 0-255
|
||||
random() {
|
||||
local num=$(dd if=/dev/urandom bs=1 count=1 2>/dev/null | hexdump -ve '1/1 "%u"')
|
||||
@ -9,8 +11,10 @@ random() {
|
||||
echo ${num:-1}
|
||||
}
|
||||
|
||||
# check host alive, timeout in 2 seconds
|
||||
host_alive() {
|
||||
ping -4 -c 2 -A -t 1 -W 1 -q "$1" >/dev/null
|
||||
# ping -4 -c 2 -A -t 1 -W 1 -q "$1" >/dev/null
|
||||
arping -f -q -b -c 2 -w 2 -i 1 -I br-lan "$1"
|
||||
}
|
||||
|
||||
set_up() {
|
||||
@ -42,14 +46,15 @@ fallback_loop() {
|
||||
local set_ip check_ip set_net set_prefix
|
||||
config_get set_ip "main" set_ip
|
||||
config_get check_ip "main" check_ip
|
||||
[[ "$set_ip" = "*/*" ]] || set_ip="$set_ip/32"
|
||||
eval "$(ipcalc.sh "$set_ip" )";set_net=$NETWORK;set_prefix=$PREFIX;set_ip=$IP
|
||||
[[ "$set_net" = 0.0.0.0 ]] && set_net=192.168.100.0
|
||||
[[ "$set_prefix" = 0 ]] && set_prefix=24
|
||||
[[ "$set_prefix" = 32 ]] && set_prefix=$DEFAULT_PREFIX
|
||||
[[ "$set_ip" = 0.0.0.0 ]] && set_ip=192.168.100.3
|
||||
local ipaddr="$set_ip/$set_prefix"
|
||||
local valid_check_ip cip
|
||||
for cip in $check_ip; do
|
||||
eval "$(ipcalc.sh $cip $set_prefix )"
|
||||
eval "$(ipcalc.sh $cip/$set_prefix )"
|
||||
[[ "$NETWORK" = "$set_net" ]] && valid_check_ip="$valid_check_ip $cip"
|
||||
done
|
||||
valid_check_ip="$valid_check_ip "
|
||||
@ -101,9 +106,10 @@ fallback_loop() {
|
||||
main_loop() {
|
||||
local set_ip set_net set_prefix
|
||||
config_get set_ip "main" set_ip
|
||||
[[ "$set_ip" = "*/*" ]] || set_ip="$set_ip/32"
|
||||
eval "$(ipcalc.sh "$set_ip" )";set_net=$NETWORK;set_prefix=$PREFIX;set_ip=$IP
|
||||
[[ "$set_net" = 0.0.0.0 ]] && set_net=192.168.100.0
|
||||
[[ "$set_prefix" = 0 ]] && set_prefix=24
|
||||
[[ "$set_prefix" = 32 ]] && set_prefix=$DEFAULT_PREFIX
|
||||
[[ "$set_ip" = 0.0.0.0 ]] && set_ip=192.168.100.3
|
||||
local ipaddr="$set_ip/$set_prefix"
|
||||
while :; do
|
||||
@ -131,4 +137,8 @@ main() {
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ -n "$1" ]]; then
|
||||
[[ "$1" -ge 0 && "$1" -lt 32 ]] && DEFAULT_PREFIX=$1
|
||||
fi
|
||||
|
||||
main
|
||||
|
18
linkease/nas/luci-app-floatip/Makefile
Normal file
18
linkease/nas/luci-app-floatip/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2016 Openwrt.org
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for floatip
|
||||
LUCI_DEPENDS:=+floatip
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=0.1.1-1
|
||||
# PKG_RELEASE MUST be empty for luci.mk
|
||||
PKG_RELEASE:=
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
|
24
linkease/nas/luci-app-floatip/luasrc/controller/floatip.lua
Normal file
24
linkease/nas/luci-app-floatip/luasrc/controller/floatip.lua
Normal file
@ -0,0 +1,24 @@
|
||||
module("luci.controller.floatip", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/floatip") then
|
||||
return
|
||||
end
|
||||
|
||||
entry({"admin", "services", "floatip"}, cbi("floatip"), _("FloatingGateway"), 20).dependent = true
|
||||
|
||||
entry({"admin", "services", "floatip_status"}, call("floatip_status"))
|
||||
end
|
||||
|
||||
function floatip_status()
|
||||
local sys = require "luci.sys"
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
|
||||
local status = {
|
||||
running = (sys.call("pidof floatip.sh >/dev/null") == 0),
|
||||
}
|
||||
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(status)
|
||||
end
|
||||
|
50
linkease/nas/luci-app-floatip/luasrc/model/cbi/floatip.lua
Normal file
50
linkease/nas/luci-app-floatip/luasrc/model/cbi/floatip.lua
Normal file
@ -0,0 +1,50 @@
|
||||
local m, s, o
|
||||
|
||||
m = Map("floatip", translate("FloatingGateway"), translate("FloatingGateway allows two gateway within one lan which can switch between each other in case of a failure."))
|
||||
|
||||
m:section(SimpleSection).template = "floatip_status"
|
||||
|
||||
s=m:section(NamedSection, "main", translate("Global settings"))
|
||||
s.addremove=false
|
||||
s.anonymous=true
|
||||
|
||||
o = s:option(Flag, "enabled", translate("Enable"))
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "role", translate("Role"))
|
||||
o.rmempty = false
|
||||
o:value("main", translate("Preemptor"))
|
||||
o:value("fallback", translate("Fallback"))
|
||||
|
||||
o = s:option(Value, "set_ip", translate("Floating Gateway IP"))
|
||||
o.rmempty = false
|
||||
function o.validate(self, value)
|
||||
local ip, mask = value:match("(%d+%.%d+%.%d+%.%d+)/?(%d*)")
|
||||
if not ip then
|
||||
return nil, "Invalid format."
|
||||
end
|
||||
|
||||
-- 验证 IP 地址格式
|
||||
for octet in ip:gmatch("%d+") do
|
||||
if tonumber(octet) < 0 or tonumber(octet) > 255 then
|
||||
return nil, "IP address octets must be between 0 and 255"
|
||||
end
|
||||
end
|
||||
|
||||
-- 验证子网掩码(如果存在)
|
||||
if mask ~= nil and mask ~= "" then
|
||||
local netmask = tonumber(mask)
|
||||
if netmask < 0 or netmask > 32 then
|
||||
return nil, "Netmask must be between 0 and 32"
|
||||
end
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:option(Value, "check_ip", translate("Check IP"))
|
||||
o.rmempty = false
|
||||
o.datatype = "ipaddr"
|
||||
o:depends("role", "fallback")
|
||||
|
||||
return m
|
26
linkease/nas/luci-app-floatip/luasrc/view/floatip_status.htm
Normal file
26
linkease/nas/luci-app-floatip/luasrc/view/floatip_status.htm
Normal file
@ -0,0 +1,26 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(5, '<%=url("admin/services/floatip_status")%>', null,
|
||||
function(x, st)
|
||||
{
|
||||
var tb = document.getElementById('floatip_status');
|
||||
if (st && tb)
|
||||
{
|
||||
if (st.running)
|
||||
{
|
||||
tb.innerHTML = '<br/><em style=\"color:green\"><%:The floatip service is running.%></em>';
|
||||
}
|
||||
else
|
||||
{
|
||||
tb.innerHTML = '<br/><em style=\"color:red\"><%:The floatip service is not running.%></em>';
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
//]]></script>
|
||||
|
||||
<fieldset class="cbi-section">
|
||||
<legend><%:FloatIP Status%></legend>
|
||||
<p id="floatip_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
32
linkease/nas/luci-app-floatip/po/zh-cn/floatip.po
Normal file
32
linkease/nas/luci-app-floatip/po/zh-cn/floatip.po
Normal file
@ -0,0 +1,32 @@
|
||||
msgid "FloatingGateway"
|
||||
msgstr "浮动网关"
|
||||
|
||||
msgid "Running state"
|
||||
msgstr "运行状态"
|
||||
|
||||
msgid "FloatingGateway allows two gateway within one lan which can switch between each other in case of a failure."
|
||||
msgstr "浮动网关可以让你在内网有两个相互备份的网关,出现问题会相互切换。"
|
||||
|
||||
msgid "The FloatingGateway service is running."
|
||||
msgstr "服务已启动"
|
||||
|
||||
msgid "The FloatingGateway service is not running."
|
||||
msgstr "服务未启动"
|
||||
|
||||
msgid "FloatingGateway Status"
|
||||
msgstr "服务状态"
|
||||
|
||||
msgid "Collecting data..."
|
||||
msgstr "收集数据..."
|
||||
|
||||
msgid "Preemptor"
|
||||
msgstr "旁路由"
|
||||
|
||||
msgid "Fallback"
|
||||
msgstr "主路由"
|
||||
|
||||
msgid "Floating Gateway IP"
|
||||
msgstr "浮动网关IP"
|
||||
|
||||
msgid "Check IP"
|
||||
msgstr "旁路由 IP"
|
1
linkease/nas/luci-app-floatip/po/zh_Hans
Symbolic link
1
linkease/nas/luci-app-floatip/po/zh_Hans
Symbolic link
@ -0,0 +1 @@
|
||||
zh-cn
|
Loading…
Reference in New Issue
Block a user