mirror of
https://github.com/kenzok8/small-package
synced 2025-01-05 11:36:47 +08:00
update 2023-08-14 16:22:09
This commit is contained in:
parent
a98ef6cd03
commit
c95c87a0c1
@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
|
||||
LUCI_TITLE:=LuCI support for linkease
|
||||
LUCI_DEPENDS:=+linkease
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=2.1.12-1
|
||||
PKG_VERSION:=2.1.12-2
|
||||
# PKG_RELEASE MUST be empty for luci.mk
|
||||
PKG_RELEASE:=
|
||||
LUCI_MINIFY_CSS:=0
|
||||
|
@ -43,9 +43,18 @@ local function session_retrieve(sid, allowed_users)
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
local function get_session(sid)
|
||||
if sid then
|
||||
return session_retrieve(sid, nil)
|
||||
local function get_session()
|
||||
local sid
|
||||
local key
|
||||
local sdat
|
||||
for _, key in ipairs({"sysauth_https", "sysauth_http", "sysauth"}) do
|
||||
sid = http.getcookie(key)
|
||||
if sid then
|
||||
sid, sdat = session_retrieve(sid, nil)
|
||||
if sid and sdat then
|
||||
return sid, sdat
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
@ -105,7 +114,7 @@ function linkease_backend()
|
||||
local start = "HTTP_"
|
||||
local start_len = string.len(start)
|
||||
local ctype = http.getenv("CONTENT_TYPE")
|
||||
if ctype then
|
||||
if ctype then
|
||||
input[#input+1] = "Content-Type: " .. ctype
|
||||
end
|
||||
for k, v in pairs(req.message.env) do
|
||||
@ -113,10 +122,7 @@ function linkease_backend()
|
||||
input[#input+1] = string.sub(k, start_len+1, string.len(k)) .. ": " .. v
|
||||
end
|
||||
end
|
||||
local sid, sdat = get_session(http.getcookie("sysauth"))
|
||||
if sdat == nil then
|
||||
sid, sdat = get_session(http.getcookie('sysauth_%s' % { http.getenv("HTTPS") == "on" and "https" or "http" }))
|
||||
end
|
||||
local sid, sdat = get_session()
|
||||
if sdat ~= nil then
|
||||
input[#input+1] = "X-Forwarded-Sid: " .. sid
|
||||
input[#input+1] = "X-Forwarded-Token: " .. sdat.token
|
||||
@ -150,6 +156,8 @@ function linkease_backend()
|
||||
num = tonumber(status) or 0
|
||||
http.status(num, msg)
|
||||
|
||||
local allow_ranges = http.getenv("SERVER_SOFTWARE") ~= "uhttpd"
|
||||
|
||||
local chunked = 0
|
||||
line = linesrc()
|
||||
while line and line ~= "" do
|
||||
@ -158,7 +166,7 @@ function linkease_backend()
|
||||
if key == "Transfer-Encoding" and val == "chunked" then
|
||||
chunked = 1
|
||||
end
|
||||
if key ~= "Connection" and key ~= "Transfer-Encoding" and key ~= "Content-Length" then
|
||||
if key ~= "Connection" and key ~= "Transfer-Encoding" and ( allow_ranges or (key ~= "Content-Length" and key ~= "Accept-Ranges") ) then
|
||||
http.header(key, val)
|
||||
end
|
||||
end
|
||||
|
20
luci-app-multiaccountdial/Makefile
Normal file
20
luci-app-multiaccountdial/Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
#
|
||||
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=multi account Virtual WAN config generator
|
||||
LUCI_PKGARCH:=all
|
||||
LUCI_DEPENDS:=+kmod-macvlan +luci-app-mwan3
|
||||
|
||||
PKG_NAME:=luci-app-multiaccountdial
|
||||
PKG_VERSION:=2.2
|
||||
PKG_RELEASE:=1
|
||||
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
@ -0,0 +1,39 @@
|
||||
module("luci.controller.multiaccountdial", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/multiaccountdial") then
|
||||
return
|
||||
end
|
||||
entry({"admin", "network", "multiaccountdial"}, cbi("multiaccountdial"), _("多账号多拨"), 103).dependent = true
|
||||
entry({"admin", "network", "multiaccountdial_redial"}, call("redial"), nil).leaf = true
|
||||
entry({"admin", "network", "add_vwan"}, call("add_vwan"), nil).leaf = true
|
||||
entry({"admin", "network", "del_vwan"}, call("del_vwan"), nil).leaf = true
|
||||
entry({"admin", "network", "syncdial_status"}, call("act_status")).leaf = true
|
||||
end
|
||||
|
||||
function redial()
|
||||
os.execute("killall -9 pppd")
|
||||
os.execute("logger -t multiaccountdial redial")
|
||||
end
|
||||
|
||||
|
||||
function add_vwan()
|
||||
os.execute("multi_account_dial add")
|
||||
os.execute("logger -t multiaccountdial add_vwan")
|
||||
end
|
||||
|
||||
function del_vwan()
|
||||
os.execute("multi_account_dial del")
|
||||
os.execute("logger -t multiaccountdial del_vwan")
|
||||
end
|
||||
|
||||
function act_status()
|
||||
local e = {}
|
||||
local mwan3_status = luci.util.exec("mwan3 status")
|
||||
e.num_online = 0
|
||||
for _ in mwan3_status:gmatch("tracking is active") do
|
||||
e.num_online = e.num_online + 1
|
||||
end
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
@ -0,0 +1,69 @@
|
||||
m = Map("multiaccountdial")
|
||||
local fs = require "nixio.fs"
|
||||
|
||||
if not fs.access("/etc/multiaccountdial/") then
|
||||
fs.mkdir("/etc/multiaccountdial/")
|
||||
end
|
||||
|
||||
if not fs.access("/etc/multiaccountdial/config") then
|
||||
fs.writefile("/etc/multiaccountdial/config","")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
syncdial_status = m:section(SimpleSection, "dial_status", translate("dial_status"))
|
||||
syncdial_status.template = "multiaccountdial/dial_status"
|
||||
|
||||
|
||||
base_setting_section = m:section(TypedSection, "base_setting", translate("base setting"))
|
||||
base_setting_section.anonymous = false
|
||||
base_setting_section.addremove = false
|
||||
|
||||
dial_num = base_setting_section:option(Value, "dial_num", translate("多播数量"))
|
||||
dial_num.default = 2
|
||||
dial_num.datatype = "range(1,249)"
|
||||
|
||||
o = base_setting_section:option(DummyValue, "_redial", translate("重新并发拨号"))
|
||||
o.template = "multiaccountdial/redial_button"
|
||||
o.width = "10%"
|
||||
|
||||
add_vwan = base_setting_section:option(DummyValue, "_add_vwan", translate("添加虚拟wan口"))
|
||||
add_vwan.template = "multiaccountdial/add_vwan_button"
|
||||
add_vwan.width = "10%"
|
||||
|
||||
del_vwan = base_setting_section:option(DummyValue, "_del_vwan", translate("删除虚拟wan口"))
|
||||
del_vwan.template = "multiaccountdial/del_vwan_button"
|
||||
del_vwan.width = "10%"
|
||||
|
||||
|
||||
|
||||
o = base_setting_section:option(Flag, "add_mwan", translate("自动配置mwan3"))
|
||||
o.rmempty = false
|
||||
|
||||
|
||||
config = base_setting_section:option(TextValue, "config")
|
||||
config.description = "写成如下形式:\npppoe账号,pppoe密码,接口名称,vlan_tag"
|
||||
config.template = "cbi/tvalue"
|
||||
config.title = "配置文件"
|
||||
config.rows = 25
|
||||
config.wrap = "off"
|
||||
|
||||
|
||||
function config.cfgvalue(self, section)
|
||||
return fs.readfile("/etc/multiaccountdial/config")
|
||||
end
|
||||
|
||||
function config.write(self,section,value)
|
||||
value = value:gsub("\r\n?", "\n")
|
||||
fs.writefile("/etc/multiaccountdial/config", value)
|
||||
end
|
||||
|
||||
return m
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
<%+cbi/valueheader%>
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-17.110.13538-6360059"></script>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
|
||||
function do_add_vwan()
|
||||
{
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "add_vwan")%>', null,
|
||||
function(x, st)
|
||||
{
|
||||
window.location.href='<%=luci.dispatcher.build_url("admin", "network", "network")%>';
|
||||
}
|
||||
);
|
||||
}
|
||||
//]]></script>
|
||||
|
||||
<input class="btn cbi-button cbi-button-save" id="cbi-add_vwan-<%=section%>-action" type="button" value="添加vwan" onclick="do_add_vwan()" />
|
||||
<%+cbi/valuefooter%>
|
@ -0,0 +1,17 @@
|
||||
<%+cbi/valueheader%>
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-17.110.13538-6360059"></script>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
|
||||
function do_del_vwan()
|
||||
{
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "del_vwan")%>', null,
|
||||
function(x, st)
|
||||
{
|
||||
window.location.href='<%=luci.dispatcher.build_url("admin", "network", "network")%>';
|
||||
}
|
||||
);
|
||||
}
|
||||
//]]></script>
|
||||
|
||||
<input class="btn cbi-button cbi-button-save" id="cbi-del_vwan-<%=section%>-action" type="button" value="删除vwan" onclick="do_del_vwan()" />
|
||||
<%+cbi/valuefooter%>
|
@ -0,0 +1,18 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(3, '<%=luci.dispatcher.build_url("admin", "network", "syncdial_status", "status")%>', null,
|
||||
function(x, data) {
|
||||
var tb = document.getElementById('syncdial_status');
|
||||
if (data && tb) {
|
||||
tb.innerHTML = '<b><%:当前在线接口数量:%> ' + data.num_online + '</b>';
|
||||
}
|
||||
}
|
||||
);
|
||||
//]]>
|
||||
</script>
|
||||
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||
<fieldset class="cbi-section">
|
||||
<p id="syncdial_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
@ -0,0 +1,17 @@
|
||||
<%+cbi/valueheader%>
|
||||
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-17.110.13538-6360059"></script>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
|
||||
function do_macvlan_redial()
|
||||
{
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "multiaccountdial_redial")%>', null,
|
||||
function(x, st)
|
||||
{
|
||||
window.location.href='<%=luci.dispatcher.build_url("admin", "network", "network")%>';
|
||||
}
|
||||
);
|
||||
}
|
||||
//]]></script>
|
||||
|
||||
<input class="btn cbi-button cbi-button-save" id="cbi-macvlan_rediag-<%=section%>-action" type="button" value="重新拨号" onclick="do_macvlan_redial()" />
|
||||
<%+cbi/valuefooter%>
|
172
luci-app-multiaccountdial/root/bin/multi_account_dial
Normal file
172
luci-app-multiaccountdial/root/bin/multi_account_dial
Normal file
@ -0,0 +1,172 @@
|
||||
#!/bin/sh
|
||||
. /lib/functions.sh
|
||||
|
||||
|
||||
config_file='/etc/multiaccountdial/config'
|
||||
syncdial_num=2
|
||||
macvlan_index=0
|
||||
command=$1
|
||||
track_ip='119.29.29.29 www.baidu.com 114.114.114.114'
|
||||
add_mwan=$(uci get multiaccountdial.@base_setting[0].add_mwan)
|
||||
dial_num=$(uci get multiaccountdial.@base_setting[0].dial_num)
|
||||
if [ "$dial_num" != "" ]; then
|
||||
syncdial_num=$dial_num
|
||||
fi
|
||||
|
||||
mwan_cfg_add() {
|
||||
#gen mwan3_interface
|
||||
uci set mwan3.${1}=interface
|
||||
uci set mwan3.${1}.enabled=1
|
||||
uci set mwan3.${1}.count=2
|
||||
uci set mwan3.${1}.timeout=2
|
||||
uci set mwan3.${1}.interval=5
|
||||
uci set mwan3.${1}.down=4
|
||||
uci set mwan3.${1}.up=1
|
||||
for i in $chk_ip_list
|
||||
do
|
||||
uci add_list mwan3.${1}.track_ip="$track_ip"
|
||||
done
|
||||
uci set mwan3.${1}.reliability=1
|
||||
uci set mwan3.${1}.initial_state=online
|
||||
uci set mwan3.${1}.family=ipv4
|
||||
uci set mwan3.${1}.track_method=ping
|
||||
uci set mwan3.${1}.size=56
|
||||
uci set mwan3.${1}.failure_interval=5
|
||||
uci set mwan3.${1}.recovery_interval=5
|
||||
uci set mwan3.${1}.flush_conntrack=never
|
||||
#gen mwan3_member
|
||||
uci set mwan3.${1}_m1_w1=member
|
||||
uci set mwan3.${1}_m1_w1.interface=${1}
|
||||
uci set mwan3.${1}_m1_w1.metric=1
|
||||
uci set mwan3.${1}_m1_w1.weight=1
|
||||
#gen mwan3_policy
|
||||
uci add_list mwan3.balanced.use_member=${1}_m1_w1
|
||||
}
|
||||
|
||||
#删除MWAN负载均衡相关配置
|
||||
#$1:接口名称
|
||||
mwan_cfg_del() {
|
||||
uci del mwan3.${1}
|
||||
uci del mwan3.${1}_m1_w1
|
||||
uci del_list mwan3.balanced.use_member=${1}_m1_w1
|
||||
}
|
||||
|
||||
|
||||
|
||||
#$1 parent interface , $2 macvlan_index , $3 vlan_tag
|
||||
#会创建一个macvlan接口,ifname为mac_${parent_ifname}
|
||||
create_macvlan_if(){
|
||||
local ifname=$1
|
||||
local macvlan_index=$2
|
||||
local vlan_tag=$3
|
||||
local macvlan_name=${ifname}.${vlan_tag}mac${macvlan_index}
|
||||
local config_name=mac_${macvlan_name}
|
||||
echo "create macvlan $macvlan_name with ifname $ifname"
|
||||
uci batch <<EOF
|
||||
add network device
|
||||
set network.@device[-1].name=$macvlan_name
|
||||
set network.@device[-1].ifname=${ifname}.${vlan_tag}
|
||||
set network.@device[-1].type=macvlan
|
||||
set network.@device[-1].mode=bridge
|
||||
set network.@device[-1].scriptmark=1
|
||||
EOF
|
||||
uci commit
|
||||
}
|
||||
|
||||
#$ifname,$index,$account,$password
|
||||
add_pppoe_if(){
|
||||
local ifname=$1
|
||||
local index=$2
|
||||
local account=$3
|
||||
local password=$4
|
||||
local metric=$((40+$index))
|
||||
echo add pppoe $ifname with account $account and password $password
|
||||
uci batch <<EOF
|
||||
set network.vwan$index=interface
|
||||
set network.vwan$index.proto=pppoe
|
||||
set network.vwan$index.ifname=$ifname
|
||||
set network.vwan$index.username=$account
|
||||
set network.vwan$index.password=$password
|
||||
set network.vwan$index.metric=$metric
|
||||
set network.vwan$index.defaultroute=0
|
||||
set network.vwan$index.ipv6=0
|
||||
add_list firewall.@zone[1].network=vwan$index
|
||||
set dhcp.vwan$index=dhcp
|
||||
set dhcp.vwan$index.interface=vwan$index
|
||||
set dhcp.vwan$index.ignore=1
|
||||
commit network
|
||||
commit firewall
|
||||
commit dhcp
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
remove_device(){
|
||||
local device_cfg=$1
|
||||
uci -q get network.${device_cfg}.scriptmark && {
|
||||
echo remove device ${device_cfg}
|
||||
uci del network.${device_cfg}
|
||||
}
|
||||
}
|
||||
|
||||
remove_if(){
|
||||
local ifcfg=$1
|
||||
[ ${ifcfg::4} == "vwan" ] && {
|
||||
uci del network.${ifcfg}
|
||||
uci del_list firewall.@zone[1].network=${ifcfg}
|
||||
}
|
||||
mwan_cfg_del ${ifcfg}
|
||||
}
|
||||
|
||||
remove_vwan(){
|
||||
config_load network
|
||||
config_foreach remove_device device
|
||||
config_foreach remove_if interface
|
||||
}
|
||||
|
||||
|
||||
add_vwan(){
|
||||
for line in `cat $config_file`
|
||||
do
|
||||
#remove comment
|
||||
line=`echo $line | sed 's/#.*$//'`
|
||||
if [ -z "$line" ]; then
|
||||
continue
|
||||
fi
|
||||
#get params split by comma
|
||||
account=`echo $line | awk -F ',' '{print $1}'`
|
||||
password=`echo $line | awk -F ',' '{print $2}'`
|
||||
ifname=`echo $line | awk -F ',' '{print $3}'`
|
||||
vlan_tag=`echo $line | awk -F ',' '{print $4}'`
|
||||
for i in $(seq 1 $syncdial_num)
|
||||
do
|
||||
|
||||
create_macvlan_if ${ifname} $macvlan_index $vlan_tag
|
||||
#add devicename to list
|
||||
add_pppoe_if ${ifname}.${vlan_tag}mac${macvlan_index} $macvlan_index $account $password
|
||||
if [ "$add_mwan" == "1" ]; then
|
||||
mwan_cfg_add vwan${macvlan_index}
|
||||
fi
|
||||
uci commit
|
||||
macvlan_index=$((macvlan_index+1))
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
case $command in
|
||||
"add")
|
||||
add_vwan
|
||||
uci commit network
|
||||
uci commit firewall
|
||||
uci commit mwan3
|
||||
;;
|
||||
"del")
|
||||
remove_vwan
|
||||
uci commit network
|
||||
uci commit firewall
|
||||
uci commit mwan3
|
||||
;;
|
||||
*)
|
||||
echo "unknown command $command"
|
||||
;;
|
||||
esac
|
@ -0,0 +1,2 @@
|
||||
config base_setting
|
||||
option add_mwan "0"
|
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-multiaccountdial": {
|
||||
"description": "Grant UCI access for luci-app-multiaccountdial",
|
||||
"read": {
|
||||
"uci": [ "multiaccountdial" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "multiaccountdial" ]
|
||||
}
|
||||
}
|
||||
}
|
16
luci-app-multiaccountdial/simple-install.sh
Executable file
16
luci-app-multiaccountdial/simple-install.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
# run in router
|
||||
APPNAME=$1
|
||||
|
||||
if [ -z "${APPNAME}" ]; then
|
||||
APPNAME=plex
|
||||
fi
|
||||
|
||||
mkdir -p /usr/lib/lua/luci/view/${APPNAME}
|
||||
cp ./luasrc/controller/${APPNAME}.lua /usr/lib/lua/luci/controller/
|
||||
cp ./luasrc/view/${APPNAME}/* /usr/lib/lua/luci/view/${APPNAME}/
|
||||
cp -rf ./luasrc/model/* /usr/lib/lua/luci/model/
|
||||
cp -rf ./root/* /
|
||||
rm -rf /tmp/luci-*
|
||||
|
Loading…
Reference in New Issue
Block a user