update-12.23

This commit is contained in:
github-actions[bot] 2021-12-23 20:33:16 +08:00
parent c32d161a4c
commit 62a7a9671d
17 changed files with 453 additions and 282 deletions

View File

@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=UnblockNeteaseMusic
PKG_BASE_VERSION:=0.27.0-rc.4
PKG_RELEASE:=53
PKG_RELEASE:=54
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/UnblockNeteaseMusic/server.git
PKG_SOURCE_DATE:=2021-12-21
PKG_SOURCE_VERSION:=6ed9f70c78a083f91c38e2a507d2977ea429d742
PKG_SOURCE_VERSION:=513c1c6313f3c287a9363ecbb0c1530af62b2e4d
PKG_MIRROR_HASH:=skip
PKG_VERSION:=$(PKG_BASE_VERSION)-$(PKG_SOURCE_DATE)-$(call version_abbrev,$(PKG_SOURCE_VERSION))

View File

@ -57,10 +57,8 @@ end
function getver()
local e={}
local c=luci.model.uci.cursor()
local l=Split(c:get("easyupdate", "main", "github"), "/")
e.newver=luci.sys.exec("uclient-fetch -qO- 'https://api.github.com/repos/" .. l[4] .. "/" .. l[5] .. "/releases/latest' | jsonfilter -e '@.tag_name'")
e.newver=e.newver:sub(e.newver:find('_')+1,-2)
e.newver=luci.sys.exec("/usr/bin/easyupdate.sh -c")
e.newver=e.newver:sub(0,-2)
e.newverint=os.time({day=e.newver:sub(7,8), month=e.newver:sub(5,6), year=e.newver:sub(1,4), hour=e.newver:sub(10,11), min=e.newver:sub(12,13), sec=e.newver:sub(14,15)})
luci.http.prepare_content("application/json")
luci.http.write_json(e)
@ -68,26 +66,8 @@ end
function download()
local e={}
local c=luci.model.uci.cursor()
local l=Split(c:get("easyupdate", "main", "github"), "/")
local sedd
if nixio.fs.access("/sys/firmware/efi") then
sedd="combined-efi.img.gz"
else
sedd="combined.img.gz"
end
local url=luci.sys.exec("uclient-fetch -qO- 'https://api.github.com/repos/" .. l[4] .. "/" .. l[5] .. "/releases/latest' | jsonfilter -e '@.assets[*].browser_download_url' | sed -n '/" .. sedd .. "/p'")
url=url:gsub("\n","")
local u=c:get("easyupdate", "main", "proxy")
if u then
u="https://ghproxy.com/"
else
u=""
end
local l=Split(url, "/")
luci.sys.exec("uclient-fetch -O '/tmp/" .. l[9] .. "' '" .. u .. url .. "' > /tmp/easyupdate.log 2>&1 &")
luci.sys.exec("/usr/bin/easyupdate.sh -d")
e.code=1
e.data=l[9]
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
@ -102,14 +82,7 @@ end
function flash()
local e={}
local f = luci.http.formvalue('file')
local c=luci.model.uci.cursor()
local k=c:get("easyupdate", "main", "keepconfig")
if k then
k=""
else
k="-n"
end
luci.sys.exec("sysupgrade " .. k .. " '/tmp/" .. f .. "' > /tmp/easyupdate.log 2>&1 &")
luci.sys.exec("/usr/bin/easyupdate.sh -f " .. f)
e.code=1
luci.http.prepare_content("application/json")
luci.http.write_json(e)

View File

@ -1,7 +1,8 @@
local pcall, dofile, _G = pcall, dofile, _G
pcall(dofile, "/etc/openwrt_release")
local fs = require "nixio.fs"
m=Map("easyupdate",translate("EasyUpdate"),translate("EasyUpdate LUCI supports scheduled upgrade & one-click firmware upgrade") .. [[<br /><br /><a href="https://github.com/sundaqiang/openwrt-packages" target="_blank">Powered by sundaqiang</a>]])
m=Map("easyupdate",translate("EasyUpdate"),translate("EasyUpdate LUCI supports scheduled upgrade & one-click firmware upgrade.") .. [[<br />]] .. translate("Update may cause the restart failure, Exercise caution when selecting automatic update.") .. [[<br /><br /><a href="https://github.com/sundaqiang/openwrt-packages" target="_blank">Powered by sundaqiang</a>]])
s=m:section(TypedSection,"easyupdate")
s.anonymous=true
@ -23,35 +24,67 @@ f.default=0
f.optional=false
w=s:option(ListValue,"week",translate("Update Time"),translate("Advised to set the automatic update time to idle time."))
w:value(7,translate("Everyday"))
w:value(0,translate("Everyday"))
w:value(1,translate("Monday"))
w:value(2,translate("Tuesday"))
w:value(3,translate("Wednesday"))
w:value(4,translate("Thursday"))
w:value(5,translate("Friday"))
w:value(6,translate("Saturday"))
w:value(0,translate("Sunday"))
w.default=0
w:value(7,translate("Sunday"))
w.default=1
w:depends("enable", "1")
h=s:option(Value,"hour",translate("Hour"))
h=s:option(Value,"hour",translate("Hour"),translate("Only 0 to 23 can be entered."))
h.datatype="range(0,23)"
h.rmempty=true
h.default=0
h:depends("enable", "1")
n=s:option(Value,"minute",translate("Minute"))
n=s:option(Value,"minute",translate("Minute"),translate("Only 0 to 59 can be entered."))
n.datatype="range(0,59)"
n.rmempty=true
n.default=30
n:depends("enable", "1")
g=s:option(Value,"github",translate("Github Url"),translate("Your Github project address "))
g=s:option(Value,"github",translate("Github Url"),translate("Your Github project address."))
g.default=''
g.rmempty=false
l=s:option(TextValue,"",translate("Log"))
l.rmempty = true
l.rows = 15
function l.cfgvalue()
return fs.readfile("/tmp/easyupdatemain.log") or ""
end
l.readonly="readonly"
b=s:option(Button,"",translate("Firmware Upgrade"))
b.template="easyupdate/button"
b.versions=_G.DISTRIB_VERSIONS
local apply = luci.http.formvalue("cbi.apply")
if apply then
local enable = luci.http.formvalue("cbid.easyupdate.main.enable")
crontabs=fs.readfile("/etc/crontabs/root")
if enable then
crontabs=crontabs:gsub('[%d%* ]+/usr/bin/easyupdate%.sh %-u # EasyUpdate\n', '')
if crontabs:sub(-1) == '\n' then
n=''
else
n='\n'
end
local week = luci.http.formvalue("cbid.easyupdate.main.week")
if week == '0' then
week='*'
end
local hour = luci.http.formvalue("cbid.easyupdate.main.hour")
local minute = luci.http.formvalue("cbid.easyupdate.main.minute")
crontabs=crontabs .. n .. minute .. ' ' .. hour .. ' ' .. '* * ' .. week .. ' /usr/bin/easyupdate.sh -u # EasyUpdate\n'
else
crontabs=crontabs:gsub('[%d%* ]+/usr/bin/easyupdate%.sh %-u # EasyUpdate\n', '')
end
fs.writefile ("/etc/crontabs/root", crontabs)
end
return m

View File

@ -58,6 +58,10 @@
body.apply-overlay-active #update_apply_overlay {
display: block;
}
.cbi-input-textarea {
width: 45VW!important;
}
</style>
<script type="text/javascript">
function update_status_message(type, content) {
@ -134,7 +138,6 @@ function check_version() {
tb.disabled = true;
XHR.get('<%=url([[admin]], [[services]], [[easyupdate]], [[download]])%>', null, (x, r) => {
if (r.code == 1) {
tb.setAttribute('file', r.data);
XHR.poll(1, '<%=url([[admin]], [[services]], [[easyupdate]], [[getlog]])%>', null,(x, r) => {
if (r.data.indexOf(" error") > -1 || r.data.indexOf("Connection reset") > -1){
XHR.halt()
@ -149,6 +152,8 @@ function check_version() {
update_status_message();
tb.value = '<%:Firmware Upgrade%>'
tb.setAttribute('flash', 1);
const file = r.data.match(/Writing to '([^\s]+img.gz)'/);
tb.setAttribute('file', file[1]);
},3000);
}else{
update_status_message('notice', r.data);

View File

@ -1,9 +1,12 @@
msgid "EasyUpdate"
msgstr "简易更新"
msgid "EasyUpdate LUCI supports scheduled upgrade & one-click firmware upgrade"
msgid "EasyUpdate LUCI supports scheduled upgrade & one-click firmware upgrade."
msgstr "EasyUpdate 支持LUCI定时升级和一键式固件升级"
msgid "Update may cause the restart failure, Exercise caution when selecting automatic update."
msgstr "升级可能导致重启失败,请谨慎选择自动升级"
msgid "When selected, firmware upgrade will be automatically at the specified time."
msgstr "选中后,系统将在指定的时间自动升级固件。"
@ -34,13 +37,19 @@ msgstr "每天"
msgid "Hour"
msgstr "小时"
msgid "Only 0 to 23 can be entered."
msgstr "只能输入0 ~ 23"
msgid "Minute"
msgstr "分钟"
msgid "Only 0 to 59 can be entered."
msgstr "只能输入0 ~ 59"
msgid "Github Url"
msgstr "Github网址"
msgid "Your Github project address"
msgid "Your Github project address."
msgstr "你的Github项目地址"
msgid "Firmware Upgrade"

View File

@ -0,0 +1,108 @@
#!/bin/bash
# https://github.com/sundaqiang/openwrt-packages
# EasyUpdate for Openwrt
function checkEnv() {
if !type sysupgrade >/dev/null 2>&1; then
echo 'Your firmware does not contain sysupgrade and does not support automatic updates(您的固件未包含sysupgrade,暂不支持自动更新)'
exit
fi
}
function shellHelp() {
checkEnv
cat <<EOF
Openwrt-EasyUpdate Script by sundaqiang
Your firmware already includes Sysupgrade and supports automatic updates(您的固件已包含sysupgrade,支持自动更新)
参数:
-c Get the cloud firmware version(获取云端固件版本)
-d Download cloud Firmware(下载云端固件)
-f filename Flash firmware(刷写固件)
-u One-click firmware update(一键更新固件)
EOF
}
function getCloudVer() {
checkEnv
github=$(uci get easyupdate.main.github)
github=(${github//// })
uclient-fetch -qO- "https://api.github.com/repos/${github[2]}/${github[3]}/releases/latest" | jsonfilter -e '@.tag_name'
}
function downCloudVer() {
checkEnv
echo 'Get github project address(读取github项目地址)'
github=$(uci get easyupdate.main.github)
echo "Github project address(github项目地址):$github"
github=(${github//// })
echo 'Check whether EFI firmware is available(判断是否EFI固件)'
if [ -d "/sys/firmware/efi/" ]; then
suffix="combined-efi.img.gz"
else
suffix="combined.img.gz"
fi
echo "Whether EFI firmware is available(是否EFI固件):$suffix"
echo 'Get the cloud firmware link(获取云端固件链接)'
url=$(uclient-fetch -qO- "https://api.github.com/repos/${github[2]}/${github[3]}/releases/latest" | jsonfilter -e '@.assets[*].browser_download_url' | sed -n "/$suffix/p")
echo "Cloud firmware link(云端固件链接):$url"
echo 'Get whether to use Chinese mirror(读取是否使用中国镜像)'
proxy=$(uci get easyupdate.main.proxy)
if [ $proxy -eq 1 ]; then
proxy='https://ghproxy.com/'
res='yes'
else
proxy=''
res='no'
fi
echo "Whether to use Chinese mirror(是否使用中国镜像):$res"
echo 'Start downloading firmware, log output in /tmp/easyupdate.log(开始下载固件,日志输出在/tmp/easyupdate.log)'
fileName=(${url//// })
uclient-fetch -O "/tmp/${fileName[7]}" "$proxy$url" >/tmp/easyupdate.log 2>&1 &
}
function flashFirmware() {
checkEnv
if [[ -z "$file" ]]; then
echo 'Please specify the file name(请指定文件名)'
else
echo 'Get whether to save the configuration(读取是否保存配置)'
keepconfig=$(uci get easyupdate.main.keepconfig)
if [ $keepconfig -eq 1 ]; then
keepconfig=''
res='yes'
else
keepconfig='-n '
res='no'
fi
echo "Whether to save the configuration(读取是否保存配置):$res"
echo 'Start flash firmware, log output in /tmp/easyupdate.log(开始刷写固件,日志输出在/tmp/easyupdate.log)'
sysupgrade $keepconfig"/tmp/$file" >/tmp/easyupdate.log 2>&1 &
fi
}
function updateCloud() {
checkEnv
}
if [[ -z "$1" ]]; then
shellHelp
else
case $1 in
-c)
getCloudVer
;;
-d)
downCloudVer
;;
-f)
file=$2
flashFirmware
;;
-u)
updateCloud
;;
*)
shellHelp
;;
esac
fi

View File

@ -1,4 +1,4 @@
# Copyright (C) 2018-2020 Lienol <lawlienol@gmail.com>
# Copyright (C) 2018-2021 Lienol <lawlienol@gmail.com>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
@ -8,8 +8,8 @@ include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI support for PPPoE Server
LUCI_DEPENDS:=+rp-pppoe-common +rp-pppoe-server
LUCI_PKGARCH:=all
PKG_VERSION:=1
PKG_RELEASE:=8-20200326
PKG_VERSION:=20211223
PKG_RELEASE:=1
define Package/luci-app-pppoe-server/preinst
#!/bin/sh
@ -20,4 +20,4 @@ endef
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature
# call BuildPackage - OpenWrt buildroot signature

View File

@ -1,20 +1,14 @@
-- Copyright 2018-2019 Lienol <lawlienol@gmail.com>
-- Copyright 2018-2021 Lienol <lawlienol@gmail.com>
module("luci.controller.pppoe-server", package.seeall)
function index()
if not nixio.fs.access("/etc/config/pppoe-server") then return end
entry({"admin", "services", "pppoe-server"},
alias("admin", "services", "pppoe-server", "settings"),
_("PPPoE Server"), 3)
entry({"admin", "services", "pppoe-server", "settings"},
cbi("pppoe-server/settings"), _("General Settings"), 10).leaf = true
entry({"admin", "services", "pppoe-server", "users"},
cbi("pppoe-server/users"), _("Users Manager"), 20).leaf = true
entry({"admin", "services", "pppoe-server", "online"},
cbi("pppoe-server/online"), _("Online Users"), 30).leaf = true
entry({"admin", "services", "pppoe-server", "status"}, call("status")).leaf =
true
entry({"admin", "services", "pppoe-server"}, alias("admin", "services", "pppoe-server", "settings"), _("PPPoE Server"), 3)
entry({"admin", "services", "pppoe-server", "settings"}, cbi("pppoe-server/settings"), _("General Settings"), 10).leaf = true
entry({"admin", "services", "pppoe-server", "users"}, cbi("pppoe-server/users"), _("Users Manager"), 20).leaf = true
entry({"admin", "services", "pppoe-server", "online"}, cbi("pppoe-server/online"), _("Online Users"), 30).leaf = true
entry({"admin", "services", "pppoe-server", "status"}, call("status")).leaf = true
end
function status()

View File

@ -1,36 +1,39 @@
local e = {}
local o = require "luci.dispatcher"
local a = luci.util.execi(
"/bin/busybox top -bn1 | grep 'pppd plugin rp-pppoe.so' | grep -v 'grep'")
for t in a do
local a, n, h, s, o = t:match(
"^ *(%d+) +(%d+) +.+rp_pppoe_sess 1:+([A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+[A-Fa-f0-9]) +.+options +(%S.-%S)%:(%S.-%S) ")
local t = tonumber(a)
if t then
e["%02i.%s" % {t, "online"}] = {
['PID'] = a,
['PPID'] = n,
['MAC'] = h,
['GATEWAY'] = s,
['CIP'] = o,
['BLACKLIST'] = 0
}
local fs = require "nixio.fs"
local jsonc = require "luci.jsonc"
local sessions = {}
local session_path = "/var/etc/pppoe-server/session"
if fs.access(session_path) then
for filename in fs.dir(session_path) do
local session_file = session_path .. "/" .. filename
local file = io.open(session_file, "r")
local t = jsonc.parse(file:read("*a"))
if t then
t.session_file = session_file
sessions[#sessions + 1] = t
end
file:close()
end
end
f = SimpleForm("processes", translate("PPPoE Server"))
f = SimpleForm("processes", translate("PPPoE Server"), translate("The PPPoE server is a broadband access authentication server that prevents ARP spoofing."))
f.reset = false
f.submit = false
f.description = translate(
"The PPPoE server is a broadband access authentication server that prevents ARP spoofing.")
t = f:section(Table, e, translate("Online Users"))
t:option(DummyValue, "GATEWAY", translate("Server IP"))
t:option(DummyValue, "CIP", translate("IP address"))
t:option(DummyValue, "MAC", translate("MAC"))
kill = t:option(Button, "_kill", translate("Forced offline"))
kill.inputstyle = "reset"
function kill.write(e, t)
null, e.tag_error[t] = luci.sys.process.signal(e.map:get(t, "PID"), 9)
t = f:section(Table, sessions, translate("Online Users"))
t:option(DummyValue, "username", translate("Username"))
t:option(DummyValue, "interface", translate("Interface"))
t:option(DummyValue, "ip", translate("Client IP"))
t:option(DummyValue, "mac", translate("MAC address"))
t:option(DummyValue, "login_time", translate("Login Time"))
_kill = t:option(Button, "_kill", translate("Forced offline"))
_kill.inputstyle = "reset"
function _kill.write(t, s)
luci.util.execi("rm -f " .. t.map:get(s, "session_file"))
null, t.tag_error[t] = luci.sys.process.signal(t.map:get(s, "pid"), 9)
luci.http.redirect(o.build_url("admin/services/pppoe-server/online"))
end
return f

View File

@ -1,70 +1,22 @@
local s = require "luci.sys"
local net = require"luci.model.network".init()
local ifaces = s.net:devices()
local m, s, o
local sys = require "luci.sys"
local ifaces = sys.net:devices()
local net = require "luci.model.network".init()
m = Map("pppoe-server", translate("PPPoE Server"))
m.description = translate(
"The PPPoE server is a broadband access authentication server that prevents ARP spoofing.")
m.description = translate("The PPPoE server is a broadband access authentication server that prevents ARP spoofing.")
m.template = "pppoe-server/index"
s = m:section(TypedSection, "service")
s.anonymous = true
o = s:option(DummyValue, "rp_pppoe_server_status",
translate("Current Condition"))
o = s:option(DummyValue, "_status", translate("Current Condition"))
o.template = "pppoe-server/status"
o.value = translate("Collecting data...")
o = s:option(Flag, "enabled", translate("Enable"),
translate("Enable or disable the PPPoE server"))
o.rmempty = false
o = s:option(ListValue, "client_interface", translate("Client Interface"),
translate("Listen in this interface"))
for _, iface in ipairs(ifaces) do
if (iface:match("^br") or iface:match("^eth*") or iface:match("^pppoe*") or iface:match("wlan*")) then
local nets = net:get_interface(iface)
nets = nets and nets:get_networks() or {}
for k, v in pairs(nets) do nets[k] = nets[k].sid end
nets = table.concat(nets, ",")
o:value(iface, ((#nets > 0) and "%s (%s)" % {iface, nets} or iface))
end
end
o.rmempty = true
o = s:option(Value, "localip", translate("Server IP"),
translate("PPPoE Server IP address.default: 10.0.1.1"))
o.datatype = "ipaddr"
o.placeholder = translate("10.0.1.1")
o.rmempty = true
o.default = "10.0.1.1"
o = s:option(Value, "remoteip", translate("Client IP"),
translate("PPPoE Client IP address.default: 10.0.1.100-254"))
o.placeholder = translate("10.0.1.100-254")
o.rmempty = true
o.default = "10.0.1.100-254"
o = s:option(Value, "count", translate("Client upper limit"), translate(
"Specify how many clients can connect to the server simultaneously."))
o.placeholder = translate("50")
o.rmempty = true
o.default = "50"
o = s:option(Value, "dns1", translate("DNS IP address1"), translate(
"Set the PPPoE server to default DNS server, which is not required."))
o.placeholder = translate("10.0.1.1")
o.datatype = "ipaddr"
o.default = "10.0.1.1"
o = s:option(Value, "dns2", translate("DNS IP address2"), translate(
"Set the PPPoE server to default DNS server, which is not required."))
o.placeholder = translate("119.29.29.29")
o.datatype = "ipaddr"
o.default = "119.29.29.29"
o = s:option(Value, "mru", translate("mru"), translate(
"You may not be able to access the Internet if you don't set it up properly.default: 1492"))
o.default = "1492"
o = s:option(Value, "mtu", translate("mtu"), translate(
"You may not be able to access the Internet if you don't set it up properly.default: 1492"))
o.default = "1492"
o = s:option(Flag, "is_nat", translate("is_nat"))
o = s:option(Flag, "enabled", translate("Enable"))
o.rmempty = false
o = s:option(ListValue, "export_interface", translate("Interface"),
translate("Specify interface forwarding traffic."))
o:value("default", translate("default"))
o = s:option(ListValue, "client_interface", translate("Client Interface"), translate("Listen in this interface"))
for _, iface in ipairs(ifaces) do
if (iface:match("^br") or iface:match("^eth*") or iface:match("^pppoe*") or iface:match("wlan*")) then
local nets = net:get_interface(iface)
@ -74,9 +26,26 @@ for _, iface in ipairs(ifaces) do
o:value(iface, ((#nets > 0) and "%s (%s)" % {iface, nets} or iface))
end
end
o:depends("is_nat", "1")
o = s:option(Value, "log", translate("Log"),
translate("Log save path, default: /var/log/pppoe-server.log"))
o.default = "/var/log/pppoe-server.log"
o.rmempty = false
o = s:option(Value, "localip", translate("Server IP"), translate("PPPoE Server IP address.default: 10.0.1.1"))
o.datatype = "ipaddr"
o.placeholder = "10.0.1.1"
o.default = o.placeholder
o = s:option(Value, "remoteip", translate("Client IP"), translate("PPPoE Client IP address.default: 10.0.1.100-254"))
o.placeholder = "10.0.1.100-254"
o.default = o.placeholder
o = s:option(Value, "count", translate("Client upper limit"), translate("Specify how many clients can connect to the server simultaneously."))
o.placeholder = "50"
o.default = o.placeholder
o = s:option(Value, "dns1", translate("Preferred DNS server"))
o.placeholder = "10.0.1.1"
o.datatype = "ipaddr"
o = s:option(Value, "dns2", translate("Alternate DNS server"))
o.datatype = "ipaddr"
o.placeholder = "119.29.29.29"
return m

View File

@ -4,18 +4,12 @@ msgstr "PPPoE 服务器"
msgid "The PPPoE server is a broadband access authentication server that prevents ARP spoofing."
msgstr "PPPoE服务器是一个宽带接入认证服务器可以防止ARP欺骗."
msgid "PPPoE Server status"
msgstr "PPPoE 服务器运行状态"
msgid "Current Condition"
msgstr "当前状态"
msgid "General settings"
msgstr "基本设置"
msgid "Enable or disable the PPPoE server"
msgstr "启用或禁用PPPoE服务器"
msgid "Client Interface"
msgstr "客户端接口"
@ -34,17 +28,11 @@ msgstr "客户端 IP 地址"
msgid "PPPoE Client IP address.default: 10.0.1.100-254"
msgstr "分配给客户端的 IP 地址范围。默认10.0.1.100-254"
msgid "DNS IP address1"
msgstr "DNS 1"
msgid "Preferred DNS server"
msgstr "首选 DNS 服务器"
msgid "DNS IP address2"
msgstr "DNS 2"
msgid "Set the PPPoE server to default DNS server, which is not required."
msgstr "设置 PPPoE 服务器第一个 DNS 服务器,该设置非必须。"
msgid "Set the PPPoE server to default DNS server, which is not required."
msgstr "设置 PPPoE 服务器第二个 DNS 服务器,该设置非必须。"
msgid "Alternate DNS server"
msgstr "备用 DNS 服务器"
msgid "Client upper limit"
msgstr "客户端上限数"
@ -52,24 +40,6 @@ msgstr "客户端上限数"
msgid "Specify how many clients can connect to the server simultaneously."
msgstr "指定有多少客户端可以同时连接到服务器"
msgid "You may not be able to access the Internet if you don't set it up properly.default: 1492"
msgstr "如果设置不当你可能无法访问互联网。默认1492"
msgid "is_nat"
msgstr "NAT转发"
msgid "Interface"
msgstr "接口"
msgid "Specify interface forwarding traffic."
msgstr "指定接口转发流量。"
msgid "Log"
msgstr "日志"
msgid "Log save path, default: /var/log/pppoe-server.log"
msgstr "日志保存路径,默认:/var/log/pppoe-server.log"
msgid "Users Manager"
msgstr "用户管理"
@ -88,9 +58,12 @@ msgstr "IP 地址"
msgid "Automatically"
msgstr "自动分配"
msgid "Online Users""
msgid "Online Users"
msgstr "在线用户"
msgid "Login Time"
msgstr "登录时间"
msgid "Forced offline"
msgstr "强制下线"

View File

@ -1,21 +1,9 @@
config service
option client_interface 'br-lan'
option localip '10.0.1.1'
option log '/var/log/pppoe-server.log'
option count '50'
option mru '1492'
option mtu '1492'
option remoteip '10.0.1.100-254'
option is_nat '1'
option export_interface 'default'
option client_interface 'eth0'
option count '50'
option dns1 '223.5.5.5'
option dns2 '119.29.29.29'
option enabled '0'
option dns1 '10.0.1.1'
option dns2 '192.168.0.2'
config user
option enabled '1'
option ipaddress '*'
option username 'guest'
option password '123456'

View File

@ -1,101 +1,118 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2018-2020 Lienol <lawlienol@gmail.com>
# Copyright (C) 2018-2021 Lienol <lawlienol@gmail.com>
START=99
CONFIG="pppoe-server"
CONFIG_FILE=/etc/ppp/$CONFIG-options
CHAP_SECRETS=/var/etc/chap-secrets
TEMP=/tmp/$CONFIG.tmp
CONFIG_PATH=/var/etc/${CONFIG}
OPTIONS_FILE=${CONFIG_PATH}/options
CHAP_SECRETS=/etc/ppp/chap-secrets
ipt_flag="PPPoE Server"
config_t_get() {
local index=0
[ -n "$4" ] && index=$4
local ret=$(uci -q get $CONFIG.@$1[$index].$2 2>/dev/null)
local ret=$(uci -q get ${CONFIG}.@$1[$index].$2 2>/dev/null)
echo ${ret:=$3}
}
setup_users() {
config_get enabled $1 enabled
[ "$enabled" -eq 0 ] && return 0
config_get username $1 username
config_get password $1 password
config_get ipaddress $1 ipaddress
[ -n "$username" -a -n "$password" ] && echo "$username $CONFIG $password $ipaddress" >> $CHAP_SECRETS
localip=$(config_t_get service localip 10.0.1.1)
ipt_rule() {
if [ "$1" = "add" ]; then
iptables -t nat -I POSTROUTING -s ${localip%.*}.0/24 -m comment --comment "${ipt_flag}" -j MASQUERADE 2>/dev/null
iptables -I forwarding_rule -s ${localip%.*}.0/24 -m comment --comment "${ipt_flag}" -j ACCEPT 2>/dev/null
else
ipt_del() {
for i in $(seq 1 $($1 -nL $2 | grep -c "${ipt_flag}")); do
local index=$($1 --line-number -nL $2 | grep "${ipt_flag}" | head -1 | awk '{print $1}')
$1 -w -D $2 $index 2>/dev/null
done
}
ipt_del "iptables" "forwarding_rule"
ipt_del "iptables -t nat" "POSTROUTING"
fi
}
del_user()
{
cat $CHAP_SECRETS | grep -v $CONFIG > $TEMP
cat $TEMP > $CHAP_SECRETS
rm $TEMP
gen_include() {
echo '#!/bin/sh' > /var/etc/${CONFIG}.include
extract_rules() {
echo "*$1"
iptables-save -t $1 | grep "${ipt_flag}" | \
sed -e "s/^-A \(INPUT\)/-I \1 1/"
echo 'COMMIT'
}
cat <<-EOF >> /var/etc/${CONFIG}.include
iptables-save -c | grep -v "${ipt_flag}" | iptables-restore -c
iptables-restore -n <<-EOT
$(extract_rules filter)
$(extract_rules nat)
EOT
EOF
return 0
}
start() {
config_load pppoe-server
enabled=$(config_t_get service enabled)
[ "$enabled" -eq 0 ] && exit 0
cat <<-EOF >$CONFIG_FILE
# PPP options for the PPPoE server
# LIC: GPL
name $CONFIG
login
require-mschap-v2
refuse-chap
require-pap
lcp-echo-interval 10
lcp-echo-failure 2
mru $(config_t_get service mru 1492)
mtu $(config_t_get service mtu 1492)
ms-dns $(config_t_get service dns1 223.5.5.5)
ms-dns $(config_t_get service dns2 119.29.29.29)
logfile $(config_t_get service log /var/log/pppoe-server.log)
EOF
del_user
config_foreach setup_users user
ln -sfn $CHAP_SECRETS /etc/ppp/chap-secrets
local is_nat=$(config_t_get service is_nat)
local localip=$(config_t_get service localip)
if [ "$is_nat" -eq 1 ];then
local export_interface=$(config_t_get service export_interface)
if [ "$export_interface" != "default" ];then
iptables -t nat -A POSTROUTING -s ${localip%.*}.0/24 -o ${export_interface} -m comment --comment "PPPoE Server" -j MASQUERADE
else
iptables -t nat -A POSTROUTING -s ${localip%.*}.0/24 -m comment --comment "PPPoE Server" -j MASQUERADE
fi
iptables -A forwarding_rule -s ${localip%.*}.0/24 -m comment --comment "PPPoE Server" -j ACCEPT
fi
/usr/sbin/pppoe-server -k -I $(config_t_get service client_interface) -L $(config_t_get service localip) -R $(config_t_get service remoteip) -N $(config_t_get service count)
local enabled=$(config_t_get service enabled)
[ "$enabled" -eq 1 ] || return 1
touch ${CHAP_SECRETS}
mkdir -p ${CONFIG_PATH}
local ms_dns1=""
local dns1=$(config_t_get service dns1)
[ -n "${dns1}" ] && ms_dns1="ms-dns ${dns1}"
local ms_dns2=""
local dns2=$(config_t_get service dns2)
[ -n "${dns2}" ] && ms_dns2="ms-dns ${dns2}"
cat <<-EOF >> ${OPTIONS_FILE}
# PPP options for the PPPoE server
# LIC: GPL
name $CONFIG
login
require-mschap-v2
refuse-chap
require-pap
lcp-echo-interval 10
lcp-echo-failure 2
mru 1492
mtu 1492
${ms_dns1}
${ms_dns2}
logfile ${CONFIG_PATH}/log.log
ip-up-script /usr/share/pppoe-server/ip-up
ip-down-script /usr/share/pppoe-server/ip-down
EOF
local _users=$(uci show ${CONFIG} | grep "=user" | cut -d '.' -sf 2 | cut -d '=' -sf 1)
[ -n "${_users}" ] && {
for _user in ${_users}; do
local u_enabled=$(uci -q get ${CONFIG}.${_user}.enabled)
[ "${u_enabled}" -eq 1 ] || continue
local u_username=$(uci -q get ${CONFIG}.${_user}.username)
[ -n "${u_username}" ] || continue
local u_password=$(uci -q get ${CONFIG}.${_user}.password)
[ -n "${u_password}" ] || continue
local u_ipaddress=$(uci -q get ${CONFIG}.${_user}.ipaddress)
[ -n "${u_ipaddress}" ] || u_ipaddress="*"
echo "${u_username} ${CONFIG} ${u_password} ${u_ipaddress}" >> ${CHAP_SECRETS}
done
}
/usr/sbin/pppoe-server -O ${OPTIONS_FILE} -k -I $(config_t_get service client_interface) -L ${localip} -R $(config_t_get service remoteip) -N $(config_t_get service count)
ipt_rule add
gen_include
}
stop() {
del_user
nums=$(iptables -t nat -n -L POSTROUTING 2>/dev/null | grep -c "PPPoE Server")
if [ -n "$nums" ]; then
until [ "$nums" = 0 ]
do
rules=$(iptables -t nat -n -L POSTROUTING --line-num 2>/dev/null | grep "PPPoE Server" | awk '{print $1}')
for rule in $rules
do
iptables -t nat -D POSTROUTING $rule 2> /dev/null
break
done
nums=$(expr $nums - 1)
done
fi
nums2=$(iptables -L forwarding_rule 2>/dev/null | grep -c "PPPoE Server")
if [ -n "$nums2" ]; then
until [ "$nums2" = 0 ]
do
rules=$(iptables -L forwarding_rule --line-num 2>/dev/null | grep "PPPoE Server" | awk '{print $1}')
for rule in $rules
do
iptables -D forwarding_rule $rule 2> /dev/null
break
done
nums2=$(expr $nums2 - 1)
done
fi
ps | grep "pppd plugin rp-pppoe.so" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1 &
killall -q -9 pppoe-server
sed -i "/${CONFIG}/d" ${CHAP_SECRETS}
top -bn1 | grep "${CONFIG_PATH}" | grep -v "grep" | awk '{print $1}' | xargs kill -9 >/dev/null 2>&1
ipt_rule del
rm -rf /var/etc/${CONFIG}.include
rm -rf ${CONFIG_PATH}
}

View File

@ -1,5 +1,13 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete firewall.pppoe_server
set firewall.pppoe_server=include
set firewall.pppoe_server.type=script
set firewall.pppoe_server.path=/var/etc/pppoe-server.include
set firewall.pppoe_server.reload=1
EOF
uci -q batch <<-EOF >/dev/null
delete ucitrack.@pppoe-server[-1]
add ucitrack pppoe-server
@ -7,5 +15,5 @@ uci -q batch <<-EOF >/dev/null
commit ucitrack
EOF
rm -f /tmp/luci-indexcache
rm -rf /tmp/luci-*cache
exit 0

View File

@ -0,0 +1,27 @@
#!/bin/sh
_LOGOUT_TIME="$(date "+%Y-%m-%d %H:%M:%S")"
CONFIG="pppoe-server"
CONFIG_PATH=/var/etc/${CONFIG}
SESSION_PATH=${CONFIG_PATH}/session
_USERNAME=${PEERNAME}
_IFACE=${1}
_TTY=${2}
_SPEED=${3}
_LOCALIP=${4}
_PEERIP=${5}
_REMOTEIP=${6}
_BYTES_SENT=${BYTES_SENT}
_BYTES_RCVD=${BYTES_RCVD}
_CONNECT_TIME=${CONNECT_TIME}
rm -f ${SESSION_PATH}/${_USERNAME}.${_IFACE}
rm -f /var/run/${_IFACE}.pid
#可根据退出的账号自定义脚本,如静态路由表,组网等。
SCRIPT="/usr/share/${CONFIG}/ip-down.d/${_USERNAME}"
[ -s "$SCRIPT" ] && {
[ ! -x "$SCRIPT" ] && chmod 0755 "$SCRIPT"
"$SCRIPT" "$@"
}

View File

@ -0,0 +1,59 @@
#!/bin/sh
_LOGIN_TIME="$(date "+%Y-%m-%d %H:%M:%S")"
CONFIG="pppoe-server"
CONFIG_PATH=/var/etc/${CONFIG}
SESSION_PATH=${CONFIG_PATH}/session
_USERNAME=${PEERNAME}
_IFACE=${1}
_TTY=${2}
_SPEED=${3}
_LOCALIP=${4}
_PEERIP=${5}
_REMOTEIP=${6}
_PID="$(cat /var/run/${_IFACE}.pid 2>/dev/null)"
_MAC=$(top -bn1 | grep -v grep | grep "${CONFIG}" | grep "${_PID}" | grep -E -o "[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}")
mkdir -p ${SESSION_PATH}
cat <<-EOF > ${SESSION_PATH}/${_USERNAME}.${_IFACE}
{
"username": "${_USERNAME}",
"interface": "${_IFACE}",
"tty": "${_TTY}",
"speed": "${_SPEED}",
"ip": "${_PEERIP}",
"mac": "${_MAC}",
"pid": "${_PID}",
"login_time": "${_LOGIN_TIME}"
}
EOF
#只能单用户使用
cfgid=$(uci show ${CONFIG} | grep "@user" | grep "\.username='${_USERNAME}'" | cut -d '.' -sf 2)
[ -n "$cfgid" ] && {
HAS_LOGIN=$(ls ${SESSION_PATH} | grep "^${_USERNAME}\.ppp" | grep -v "${_IFACE}")
[ -n "$HAS_LOGIN" ] && {
#踢出之前的用户
KO_IFACE=$(echo $HAS_LOGIN | awk -F '.' '{print $2}')
KO_PID=$(cat /var/run/${KO_IFACE}.pid 2>/dev/null)
[ -n "$KO_PID" ] && kill -9 ${KO_PID} >/dev/null 2>&1
rm -f ${SESSION_PATH}/${HAS_LOGIN}
rm -f /var/run/${KO_IFACE}.pid
}
routes=$(uci -q get ${CONFIG}.${cfgid}.routes)
[ -n "$routes" ] && {
for router in ${routes}; do
route add -net ${router} dev ${_IFACE} >/dev/null 2>&1
done
}
}
#可根据登录的账号自定义脚本,如组网、日志、限速、权限等特殊待遇。
SCRIPT="/usr/share/${CONFIG}/ip-up.d/${_USERNAME}"
[ -s "$SCRIPT" ] && {
[ ! -x "$SCRIPT" ] && chmod 0755 "$SCRIPT"
"$SCRIPT" "$@"
}

View File

@ -89,6 +89,11 @@ function update()
e.error=nixio.fs.mover("/tmp/" .. filename:gsub(".tar.gz", "") .. "/supervisord", d)
if e.error then
e.error=0
sysupgrade=nixio.fs.readfile("/etc/sysupgrade.conf")
if not sysupgrade:find(d) then
sysupgrade=sysupgrade .. '\n' .. d
nixio.fs.writefile ("/etc/sysupgrade.conf", sysupgrade)
end
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end