subscribe.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. #!/usr/bin/lua
  2. ------------------------------------------------
  3. -- This file is part of the luci-app-ssr-plus subscribe.lua
  4. -- @author William Chan <[email protected]>
  5. ------------------------------------------------
  6. require "luci.model.uci"
  7. require "nixio"
  8. require "luci.util"
  9. require "luci.sys"
  10. require "luci.jsonc"
  11. -- these global functions are accessed all the time by the event handler
  12. -- so caching them is worth the effort
  13. local tinsert = table.insert
  14. local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub
  15. local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify
  16. local b64decode = nixio.bin.b64decode
  17. local cache = {}
  18. local nodeResult = setmetatable({}, {__index = cache}) -- update result
  19. local name = 'shadowsocksr'
  20. local uciType = 'servers'
  21. local ucic = luci.model.uci.cursor()
  22. local proxy = ucic:get_first(name, 'server_subscribe', 'proxy', '0')
  23. local switch = ucic:get_first(name, 'server_subscribe', 'switch', '1')
  24. local subscribe_url = ucic:get_first(name, 'server_subscribe', 'subscribe_url', {})
  25. local filter_words = ucic:get_first(name, 'server_subscribe', 'filter_words', '过期时间/剩余流量')
  26. local save_words = ucic:get_first(name, 'server_subscribe', 'save_words', '')
  27. local v2_ss = luci.sys.exec('type -t -p ss-redir sslocal') ~= "" and "ss" or "v2ray"
  28. local v2_tj = luci.sys.exec('type -t -p trojan') ~= "" and "trojan" or "v2ray"
  29. local log = function(...)
  30. print(os.date("%Y-%m-%d %H:%M:%S ") .. table.concat({...}, " "))
  31. end
  32. local encrypt_methods_ss = {
  33. -- aead
  34. "aes-128-gcm",
  35. "aes-192-gcm",
  36. "aes-256-gcm",
  37. "chacha20-ietf-poly1305",
  38. "xchacha20-ietf-poly1305"
  39. --[[ stream
  40. "table",
  41. "rc4",
  42. "rc4-md5",
  43. "aes-128-cfb",
  44. "aes-192-cfb",
  45. "aes-256-cfb",
  46. "aes-128-ctr",
  47. "aes-192-ctr",
  48. "aes-256-ctr",
  49. "bf-cfb",
  50. "camellia-128-cfb",
  51. "camellia-192-cfb",
  52. "camellia-256-cfb",
  53. "salsa20",
  54. "chacha20",
  55. "chacha20-ietf" ]]
  56. }
  57. -- 分割字符串
  58. local function split(full, sep)
  59. full = full:gsub("%z", "") -- 这里不是很清楚 有时候结尾带个\0
  60. local off, result = 1, {}
  61. while true do
  62. local nStart, nEnd = full:find(sep, off)
  63. if not nEnd then
  64. local res = ssub(full, off, slen(full))
  65. if #res > 0 then -- 过滤掉 \0
  66. tinsert(result, res)
  67. end
  68. break
  69. else
  70. tinsert(result, ssub(full, off, nStart - 1))
  71. off = nEnd + 1
  72. end
  73. end
  74. return result
  75. end
  76. -- urlencode
  77. local function get_urlencode(c)
  78. return sformat("%%%02X", sbyte(c))
  79. end
  80. local function urlEncode(szText)
  81. local str = szText:gsub("([^0-9a-zA-Z ])", get_urlencode)
  82. str = str:gsub(" ", "+")
  83. return str
  84. end
  85. local function get_urldecode(h)
  86. return schar(tonumber(h, 16))
  87. end
  88. local function UrlDecode(szText)
  89. return szText:gsub("+", " "):gsub("%%(%x%x)", get_urldecode)
  90. end
  91. -- trim
  92. local function trim(text)
  93. if not text or text == "" then
  94. return ""
  95. end
  96. return (sgsub(text, "^%s*(.-)%s*$", "%1"))
  97. end
  98. -- md5
  99. local function md5(content)
  100. local stdout = luci.sys.exec('echo \"' .. urlEncode(content) .. '\" | md5sum | cut -d \" \" -f1')
  101. -- assert(nixio.errno() == 0)
  102. return trim(stdout)
  103. end
  104. -- base64
  105. local function base64Decode(text)
  106. local raw = text
  107. if not text then
  108. return ''
  109. end
  110. text = text:gsub("%z", "")
  111. text = text:gsub("_", "/")
  112. text = text:gsub("-", "+")
  113. local mod4 = #text % 4
  114. text = text .. string.sub('====', mod4 + 1)
  115. local result = b64decode(text)
  116. if result then
  117. return result:gsub("%z", "")
  118. else
  119. return raw
  120. end
  121. end
  122. -- 检查数组(table)中是否存在某个字符值
  123. -- https://www.04007.cn/article/135.html
  124. local function checkTabValue(tab)
  125. local revtab = {}
  126. for k,v in pairs(tab) do
  127. revtab[v] = true
  128. end
  129. return revtab
  130. end
  131. -- 处理数据
  132. local function processData(szType, content)
  133. local result = {type = szType, local_port = 1234, kcp_param = '--nocomp'}
  134. if szType == 'ssr' then
  135. local dat = split(content, "/%?")
  136. local hostInfo = split(dat[1], ':')
  137. result.server = hostInfo[1]
  138. result.server_port = hostInfo[2]
  139. result.protocol = hostInfo[3]
  140. result.encrypt_method = hostInfo[4]
  141. result.obfs = hostInfo[5]
  142. result.password = base64Decode(hostInfo[6])
  143. local params = {}
  144. for _, v in pairs(split(dat[2], '&')) do
  145. local t = split(v, '=')
  146. params[t[1]] = t[2]
  147. end
  148. result.obfs_param = base64Decode(params.obfsparam)
  149. result.protocol_param = base64Decode(params.protoparam)
  150. local group = base64Decode(params.group)
  151. if group then
  152. result.alias = "[" .. group .. "] "
  153. end
  154. result.alias = result.alias .. base64Decode(params.remarks)
  155. elseif szType == 'vmess' then
  156. local info = jsonParse(content)
  157. result.type = 'v2ray'
  158. result.v2ray_protocol = 'vmess'
  159. result.server = info.add
  160. result.server_port = info.port
  161. result.transport = info.net
  162. result.vmess_id = info.id
  163. result.alias = info.ps
  164. -- result.mux = 1
  165. -- result.concurrency = 8
  166. if info.net == 'ws' then
  167. result.ws_host = info.host
  168. result.ws_path = info.path
  169. end
  170. if info.net == 'h2' then
  171. result.h2_host = info.host
  172. result.h2_path = info.path
  173. end
  174. if info.net == 'tcp' then
  175. if info.type and info.type ~= "http" then
  176. info.type = "none"
  177. end
  178. result.tcp_guise = info.type
  179. result.http_host = info.host
  180. result.http_path = info.path
  181. end
  182. if info.net == 'kcp' then
  183. result.kcp_guise = info.type
  184. result.mtu = 1350
  185. result.tti = 50
  186. result.uplink_capacity = 5
  187. result.downlink_capacity = 20
  188. result.read_buffer_size = 2
  189. result.write_buffer_size = 2
  190. end
  191. if info.net == 'quic' then
  192. result.quic_guise = info.type
  193. result.quic_key = info.key
  194. result.quic_security = info.securty
  195. end
  196. if info.security then
  197. result.security = info.security
  198. end
  199. if info.tls == "tls" or info.tls == "1" then
  200. result.tls = "1"
  201. result.tls_host = info.host
  202. result.insecure = 1
  203. else
  204. result.tls = "0"
  205. end
  206. -- https://www.v2fly.org/config/protocols/vmess.html#vmess-md5-认证信息-淘汰机制
  207. if info.aid and (tonumber(info.aid) > 0) then
  208. result.server = nil
  209. end
  210. elseif szType == "ss" then
  211. local idx_sp = 0
  212. local alias = ""
  213. if content:find("#") then
  214. idx_sp = content:find("#")
  215. alias = content:sub(idx_sp + 1, -1)
  216. end
  217. local info = content:sub(1, idx_sp - 1)
  218. local hostInfo = split(base64Decode(info), "@")
  219. local host = split(hostInfo[2], ":")
  220. local userinfo = base64Decode(hostInfo[1])
  221. local method = userinfo:sub(1, userinfo:find(":") - 1)
  222. local password = userinfo:sub(userinfo:find(":") + 1, #userinfo)
  223. result.alias = UrlDecode(alias)
  224. result.type = v2_ss
  225. result.password = password
  226. result.server = host[1]
  227. if host[2]:find("/%?") then
  228. local query = split(host[2], "/%?")
  229. result.server_port = query[1]
  230. local params = {}
  231. for _, v in pairs(split(query[2], '&')) do
  232. local t = split(v, '=')
  233. params[t[1]] = t[2]
  234. end
  235. if params.plugin then
  236. local plugin_info = UrlDecode(params.plugin)
  237. local idx_pn = plugin_info:find(";")
  238. if idx_pn then
  239. result.plugin = plugin_info:sub(1, idx_pn - 1)
  240. result.plugin_opts = plugin_info:sub(idx_pn + 1, #plugin_info)
  241. else
  242. result.plugin = plugin_info
  243. end
  244. -- 部分机场下发的插件名为 simple-obfs,这里应该改为 obfs-local
  245. if result.plugin == "simple-obfs" then
  246. result.plugin = "obfs-local"
  247. end
  248. end
  249. else
  250. result.server_port = host[2]:gsub("/","")
  251. end
  252. if not checkTabValue(encrypt_methods_ss)[method] then
  253. -- 1202 年了还不支持 SS AEAD 的屑机场
  254. result.server = nil
  255. elseif v2_ss == "v2ray" then
  256. result.v2ray_protocol = "shadowsocks"
  257. result.encrypt_method_v2ray_ss = method
  258. else
  259. result.encrypt_method_ss = method
  260. end
  261. elseif szType == "sip008" then
  262. result.type = v2_ss
  263. result.server = content.server
  264. result.server_port = content.server_port
  265. result.password = content.password
  266. result.plugin = content.plugin
  267. result.plugin_opts = content.plugin_opts
  268. result.alias = content.remarks
  269. if not checkTabValue(encrypt_methods_ss)[content.method] then
  270. result.server = nil
  271. elseif v2_ss == "v2ray" then
  272. result.v2ray_protocol = "shadowsocks"
  273. result.encrypt_method_v2ray_ss = content.method
  274. else
  275. result.encrypt_method_ss = content.method
  276. end
  277. elseif szType == "ssd" then
  278. result.type = v2_ss
  279. result.server = content.server
  280. result.server_port = content.port
  281. result.password = content.password
  282. result.plugin_opts = content.plugin_options
  283. result.alias = "[" .. content.airport .. "] " .. content.remarks
  284. if content.plugin == "simple-obfs" then
  285. result.plugin = "obfs-local"
  286. else
  287. result.plugin = content.plugin
  288. end
  289. if not checkTabValue(encrypt_methods_ss)[content.encryption] then
  290. result.server = nil
  291. elseif v2_ss == "v2ray" then
  292. result.v2ray_protocol = "shadowsocks"
  293. result.encrypt_method_v2ray_ss = content.method
  294. else
  295. result.encrypt_method_ss = content.method
  296. end
  297. elseif szType == "trojan" then
  298. local idx_sp = 0
  299. local alias = ""
  300. if content:find("#") then
  301. idx_sp = content:find("#")
  302. alias = content:sub(idx_sp + 1, -1)
  303. end
  304. local info = content:sub(1, idx_sp - 1)
  305. local hostInfo = split(info, "@")
  306. local host = split(hostInfo[2], ":")
  307. local userinfo = hostInfo[1]
  308. local password = userinfo
  309. result.alias = UrlDecode(alias)
  310. result.type = v2_tj
  311. result.v2ray_protocol = "trojan"
  312. result.server = host[1]
  313. -- 按照官方的建议 默认验证ssl证书
  314. result.insecure = "0"
  315. result.tls = "1"
  316. if host[2]:find("?") then
  317. local query = split(host[2], "?")
  318. result.server_port = query[1]
  319. local params = {}
  320. for _, v in pairs(split(query[2], '&')) do
  321. local t = split(v, '=')
  322. params[t[1]] = t[2]
  323. end
  324. if params.sni then
  325. -- 未指定peer(sni)默认使用remote addr
  326. result.tls_host = params.sni
  327. end
  328. else
  329. result.server_port = host[2]
  330. end
  331. result.password = password
  332. elseif szType == "vless" then
  333. local idx_sp = 0
  334. local alias = ""
  335. if content:find("#") then
  336. idx_sp = content:find("#")
  337. alias = content:sub(idx_sp + 1, -1)
  338. end
  339. local info = content:sub(1, idx_sp - 1)
  340. local hostInfo = split(info, "@")
  341. local host = split(hostInfo[2], ":")
  342. local uuid = hostInfo[1]
  343. if host[2]:find("?") then
  344. local query = split(host[2], "?")
  345. local params = {}
  346. for _, v in pairs(split(UrlDecode(query[2]), '&')) do
  347. local t = split(v, '=')
  348. params[t[1]] = t[2]
  349. end
  350. result.alias = UrlDecode(alias)
  351. result.type = 'v2ray'
  352. result.v2ray_protocol = 'vless'
  353. result.server = host[1]
  354. result.server_port = query[1]
  355. result.vmess_id = uuid
  356. result.vless_encryption = params.encryption or "none"
  357. result.transport = params.type and (params.type == 'http' and 'h2' or params.type) or "tcp"
  358. if not params.type or params.type == "tcp" then
  359. if params.security == "xtls" then
  360. result.xtls = "1"
  361. result.tls_host = params.sni
  362. result.vless_flow = params.flow
  363. else
  364. result.xtls = "0"
  365. end
  366. end
  367. if params.type == 'ws' then
  368. result.ws_host = params.host
  369. result.ws_path = params.path or "/"
  370. end
  371. if params.type == 'http' then
  372. result.h2_host = params.host
  373. result.h2_path = params.path or "/"
  374. end
  375. if params.type == 'kcp' then
  376. result.kcp_guise = params.headerType or "none"
  377. result.mtu = 1350
  378. result.tti = 50
  379. result.uplink_capacity = 5
  380. result.downlink_capacity = 20
  381. result.read_buffer_size = 2
  382. result.write_buffer_size = 2
  383. result.seed = params.seed
  384. end
  385. if params.type == 'quic' then
  386. result.quic_guise = params.headerType or "none"
  387. result.quic_key = params.key
  388. result.quic_security = params.quicSecurity or "none"
  389. end
  390. if params.type == 'grpc' then
  391. result.serviceName = params.serviceName
  392. end
  393. if params.security == "tls" then
  394. result.tls = "1"
  395. result.tls_host = params.sni
  396. else
  397. result.tls = "0"
  398. end
  399. else
  400. result.server_port = host[2]
  401. end
  402. end
  403. if not result.alias then
  404. if result.server and result.server_port then
  405. result.alias = result.server .. ':' .. result.server_port
  406. else
  407. result.alias = "NULL"
  408. end
  409. end
  410. -- alias 不参与 hashkey 计算
  411. local alias = result.alias
  412. result.alias = nil
  413. local switch_enable = result.switch_enable
  414. result.switch_enable = nil
  415. result.hashkey = md5(jsonStringify(result))
  416. result.alias = alias
  417. result.switch_enable = switch_enable
  418. return result
  419. end
  420. -- wget
  421. local function wget(url)
  422. local stdout = luci.sys.exec('uclient-fetch -q --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" --no-check-certificate -O- "' .. url .. '"')
  423. return trim(stdout)
  424. end
  425. local function check_filer(result)
  426. do
  427. -- 过滤的关键词列表
  428. local filter_word = split(filter_words, "/")
  429. -- 保留的关键词列表
  430. local check_save = false
  431. if save_words ~= nil and save_words ~= "" and save_words ~= "NULL" then
  432. check_save = true
  433. end
  434. local save_word = split(save_words, "/")
  435. -- 检查结果
  436. local filter_result = false
  437. local save_result = true
  438. -- 检查是否存在过滤关键词
  439. for i, v in pairs(filter_word) do
  440. if tostring(result.alias):find(v, nil, true) then
  441. filter_result = true
  442. end
  443. end
  444. -- 检查是否打开了保留关键词检查,并且进行过滤
  445. if check_save == true then
  446. for i, v in pairs(save_word) do
  447. if tostring(result.alias):find(v, nil, true) then
  448. save_result = false
  449. end
  450. end
  451. else
  452. save_result = false
  453. end
  454. -- 不等时返回
  455. if filter_result == true or save_result == true then
  456. return true
  457. else
  458. return false
  459. end
  460. end
  461. end
  462. local execute = function()
  463. -- exec
  464. do
  465. if proxy == '0' then -- 不使用代理更新的话先暂停
  466. log('服务正在暂停')
  467. luci.sys.init.stop(name)
  468. end
  469. for k, url in ipairs(subscribe_url) do
  470. local raw = wget(url)
  471. if #raw > 0 then
  472. local nodes, szType
  473. local groupHash = md5(url)
  474. cache[groupHash] = {}
  475. tinsert(nodeResult, {})
  476. local index = #nodeResult
  477. -- SSD 似乎是这种格式 ssd:// 开头的
  478. if raw:find('ssd://') then
  479. szType = 'ssd'
  480. local nEnd = select(2, raw:find('ssd://'))
  481. nodes = base64Decode(raw:sub(nEnd + 1, #raw))
  482. nodes = jsonParse(nodes)
  483. local extra = {airport = nodes.airport, port = nodes.port, encryption = nodes.encryption, password = nodes.password}
  484. local servers = {}
  485. -- SS里面包着 干脆直接这样
  486. for _, server in ipairs(nodes.servers) do
  487. tinsert(servers, setmetatable(server, {__index = extra}))
  488. end
  489. nodes = servers
  490. -- SS SIP008 直接使用 Json 格式
  491. elseif jsonParse(raw) then
  492. nodes = jsonParse(raw).servers or jsonParse(raw)
  493. if nodes[1].server and nodes[1].method then
  494. szType = 'sip008'
  495. end
  496. else
  497. -- ssd 外的格式
  498. nodes = split(base64Decode(raw):gsub(" ", "_"), "\n")
  499. end
  500. for _, v in ipairs(nodes) do
  501. if v then
  502. local result
  503. if szType then
  504. result = processData(szType, v)
  505. elseif not szType then
  506. local node = trim(v)
  507. local dat = split(node, "://")
  508. if dat and dat[1] and dat[2] then
  509. local dat3 = ""
  510. if dat[3] then
  511. dat3 = "://" .. dat[3]
  512. end
  513. if dat[1] == 'ss' or dat[1] == 'trojan' then
  514. result = processData(dat[1], dat[2] .. dat3)
  515. else
  516. result = processData(dat[1], base64Decode(dat[2]))
  517. end
  518. end
  519. else
  520. log('跳过未知类型: ' .. szType)
  521. end
  522. -- log(result)
  523. if result then
  524. -- 中文做地址的 也没有人拿中文域名搞,就算中文域也有Puny Code SB 机场
  525. if not result.server or not result.server_port or result.alias == "NULL" or check_filer(result) or result.server:match("[^0-9a-zA-Z%-%.%s]") or cache[groupHash][result.hashkey] then
  526. log('丢弃无效节点: ' .. result.type .. ' 节点, ' .. result.alias)
  527. else
  528. -- log('成功解析: ' .. result.type ..' 节点, ' .. result.alias)
  529. result.grouphashkey = groupHash
  530. tinsert(nodeResult[index], result)
  531. cache[groupHash][result.hashkey] = nodeResult[index][#nodeResult[index]]
  532. end
  533. end
  534. end
  535. end
  536. log('成功解析节点数量: ' .. #nodes)
  537. else
  538. log(url .. ': 获取内容为空')
  539. end
  540. end
  541. end
  542. -- diff
  543. do
  544. if next(nodeResult) == nil then
  545. log("更新失败,没有可用的节点信息")
  546. if proxy == '0' then
  547. luci.sys.init.start(name)
  548. log('订阅失败, 恢复服务')
  549. end
  550. return
  551. end
  552. local add, del = 0, 0
  553. ucic:foreach(name, uciType, function(old)
  554. if old.grouphashkey or old.hashkey then -- 没有 hash 的不参与删除
  555. if not nodeResult[old.grouphashkey] or not nodeResult[old.grouphashkey][old.hashkey] then
  556. ucic:delete(name, old['.name'])
  557. del = del + 1
  558. else
  559. local dat = nodeResult[old.grouphashkey][old.hashkey]
  560. ucic:tset(name, old['.name'], dat)
  561. -- 标记一下
  562. setmetatable(nodeResult[old.grouphashkey][old.hashkey], {__index = {_ignore = true}})
  563. end
  564. else
  565. if not old.alias then
  566. if old.server or old.server_port then
  567. old.alias = old.server .. ':' .. old.server_port
  568. log('忽略手动添加的节点: ' .. old.alias)
  569. else
  570. ucic:delete(name, old['.name'])
  571. end
  572. else
  573. log('忽略手动添加的节点: ' .. old.alias)
  574. end
  575. end
  576. end)
  577. for k, v in ipairs(nodeResult) do
  578. for kk, vv in ipairs(v) do
  579. if not vv._ignore then
  580. local section = ucic:add(name, uciType)
  581. ucic:tset(name, section, vv)
  582. ucic:set(name, section, "switch_enable", switch)
  583. add = add + 1
  584. end
  585. end
  586. end
  587. ucic:commit(name)
  588. -- 如果原有服务器节点已经不见了就尝试换为第一个节点
  589. local globalServer = ucic:get_first(name, 'global', 'global_server', '')
  590. if globalServer ~= "nil" then
  591. local firstServer = ucic:get_first(name, uciType)
  592. if firstServer then
  593. if not ucic:get(name, globalServer) then
  594. luci.sys.call("/etc/init.d/" .. name .. " stop > /dev/null 2>&1 &")
  595. ucic:commit(name)
  596. ucic:set(name, ucic:get_first(name, 'global'), 'global_server', ucic:get_first(name, uciType))
  597. ucic:commit(name)
  598. log('当前主服务器节点已被删除,正在自动更换为第一个节点。')
  599. luci.sys.call("/etc/init.d/" .. name .. " start > /dev/null 2>&1 &")
  600. else
  601. log('维持当前主服务器节点。')
  602. luci.sys.call("/etc/init.d/" .. name .. " restart > /dev/null 2>&1 &")
  603. end
  604. else
  605. log('没有服务器节点了,停止服务')
  606. luci.sys.call("/etc/init.d/" .. name .. " stop > /dev/null 2>&1 &")
  607. end
  608. end
  609. log('新增节点数量: ' .. add, '删除节点数量: ' .. del)
  610. log('订阅更新成功')
  611. end
  612. end
  613. if subscribe_url and #subscribe_url > 0 then
  614. xpcall(execute, function(e)
  615. log(e)
  616. log(debug.traceback())
  617. log('发生错误, 正在恢复服务')
  618. local firstServer = ucic:get_first(name, uciType)
  619. if firstServer then
  620. luci.sys.call("/etc/init.d/" .. name .. " restart > /dev/null 2>&1 &") -- 不加&的话日志会出现的更早
  621. log('重启服务成功')
  622. else
  623. luci.sys.call("/etc/init.d/" .. name .. " stop > /dev/null 2>&1 &") -- 不加&的话日志会出现的更早
  624. log('停止服务成功')
  625. end
  626. end)
  627. end