luci-app-shadowsocks-libev: auto update instance running state
[project/luci.git] / applications / luci-app-shadowsocks-libev / luasrc / controller / shadowsocks-libev.lua
1 -- Copyright 2017 Yousong Zhou <yszhou4tech@gmail.com>
2 -- Licensed to the public under the Apache License 2.0.
3 --
4 module("luci.controller.shadowsocks-libev", package.seeall)
5
6 function index()
7         entry({"admin", "services", "shadowsocks-libev"},
8                 alias("admin", "services", "shadowsocks-libev", "instances"),
9                 _("Shadowsocks-libev"), 59)
10
11         entry({"admin", "services", "shadowsocks-libev", "instances"},
12                 arcombine(cbi("shadowsocks-libev/instances"), cbi("shadowsocks-libev/instance-details")),
13                 _("Local Instances"), 10).leaf = true
14
15         entry({"admin", "services", "shadowsocks-libev", "servers"},
16                 cbi("shadowsocks-libev/servers"),
17                 _("Remote Servers"), 20).leaf = true
18
19         entry({"admin", "services", "shadowsocks-libev", "rules"},
20                 cbi("shadowsocks-libev/rules"),
21                 _("Redir Rules"), 30).leaf = true
22
23         entry({"admin", "services", "shadowsocks-libev", "status"}, call("ss_status"), nil).leaf = true
24
25 end
26
27 function ss_status()
28         local ut = require "luci.util"
29         local rv = ut.ubus("service", "list", {name = "shadowsocks-libev"})["shadowsocks-libev"] or {_=0}
30
31         luci.http.prepare_content("application/json")
32         luci.http.write_json(rv)
33 end