diff --git a/luci-app-linkease/Makefile b/luci-app-linkease/Makefile index c641f1c53..483e80542 100644 --- a/luci-app-linkease/Makefile +++ b/luci-app-linkease/Makefile @@ -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 diff --git a/luci-app-linkease/luasrc/controller/linkease_backend.lua b/luci-app-linkease/luasrc/controller/linkease_backend.lua index a6e6b3021..576ba42ea 100644 --- a/luci-app-linkease/luasrc/controller/linkease_backend.lua +++ b/luci-app-linkease/luasrc/controller/linkease_backend.lua @@ -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 diff --git a/luci-app-multiaccountdial/Makefile b/luci-app-multiaccountdial/Makefile new file mode 100644 index 000000000..1ed8c7fd1 --- /dev/null +++ b/luci-app-multiaccountdial/Makefile @@ -0,0 +1,20 @@ +# +# Copyright (C) 2008-2014 The LuCI Team +# +# 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 diff --git a/luci-app-multiaccountdial/luasrc/controller/multiaccountdial.lua b/luci-app-multiaccountdial/luasrc/controller/multiaccountdial.lua new file mode 100644 index 000000000..07377aa6f --- /dev/null +++ b/luci-app-multiaccountdial/luasrc/controller/multiaccountdial.lua @@ -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 diff --git a/luci-app-multiaccountdial/luasrc/model/cbi/multiaccountdial.lua b/luci-app-multiaccountdial/luasrc/model/cbi/multiaccountdial.lua new file mode 100644 index 000000000..654352ec2 --- /dev/null +++ b/luci-app-multiaccountdial/luasrc/model/cbi/multiaccountdial.lua @@ -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 + + + + + + + diff --git a/luci-app-multiaccountdial/luasrc/view/multiaccountdial/add_vwan_button.htm b/luci-app-multiaccountdial/luasrc/view/multiaccountdial/add_vwan_button.htm new file mode 100644 index 000000000..0b8cf0a80 --- /dev/null +++ b/luci-app-multiaccountdial/luasrc/view/multiaccountdial/add_vwan_button.htm @@ -0,0 +1,17 @@ +<%+cbi/valueheader%> + + + + +<%+cbi/valuefooter%> diff --git a/luci-app-multiaccountdial/luasrc/view/multiaccountdial/del_vwan_button.htm b/luci-app-multiaccountdial/luasrc/view/multiaccountdial/del_vwan_button.htm new file mode 100644 index 000000000..e4f2dea90 --- /dev/null +++ b/luci-app-multiaccountdial/luasrc/view/multiaccountdial/del_vwan_button.htm @@ -0,0 +1,17 @@ +<%+cbi/valueheader%> + + + + +<%+cbi/valuefooter%> diff --git a/luci-app-multiaccountdial/luasrc/view/multiaccountdial/dial_status.htm b/luci-app-multiaccountdial/luasrc/view/multiaccountdial/dial_status.htm new file mode 100644 index 000000000..a6d95b308 --- /dev/null +++ b/luci-app-multiaccountdial/luasrc/view/multiaccountdial/dial_status.htm @@ -0,0 +1,18 @@ + + +
+

+ <%:Collecting data...%> +

+
+ diff --git a/luci-app-multiaccountdial/luasrc/view/multiaccountdial/redial_button.htm b/luci-app-multiaccountdial/luasrc/view/multiaccountdial/redial_button.htm new file mode 100644 index 000000000..437553b25 --- /dev/null +++ b/luci-app-multiaccountdial/luasrc/view/multiaccountdial/redial_button.htm @@ -0,0 +1,17 @@ +<%+cbi/valueheader%> + + + + +<%+cbi/valuefooter%> diff --git a/luci-app-multiaccountdial/root/bin/multi_account_dial b/luci-app-multiaccountdial/root/bin/multi_account_dial new file mode 100644 index 000000000..318818689 --- /dev/null +++ b/luci-app-multiaccountdial/root/bin/multi_account_dial @@ -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 <