applications: add luci-ltqtapi, provides port status monitoring and VoIP control...
[project/luci.git] / applications / luci-ltqtapi / luasrc / controller / ltqtapi.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2019 John Crispin <blogic@openwrt.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 ]]--
13
14 module("luci.controller.ltqtapi", package.seeall)
15
16 function index()
17 if not nixio.fs.access("/etc/config/telephony") then
18 return
19 end
20
21 page = node("admin", "telephony")
22 page.target = firstchild()
23 page.title = _("VoIP")
24 page.order = 90
25 page.i18n = "telephony"
26
27 entry({"admin", "telephony", "account"}, cbi("luci_ltqtapi/account") , _("Account"), 10)
28 entry({"admin", "telephony", "contact"}, cbi("luci_ltqtapi/contact") , _("Contacts"), 20)
29
30 entry({"admin", "telephony", "status"}, call("tapi_status")).leaf = true
31 end
32
33 function tapi_status()
34 local st = { }
35 local state = require "luci.model.uci".cursor_state()
36 state:load("telephony")
37
38 st.status = "Offline";
39 if state:get("telephony", "state", "port1", "0") == "0" then
40 st.line1 = "Idle";
41 else
42 st.line1 = "Calling";
43 end
44 if state:get("telephony", "state", "port2", "0") == "0" then
45 st.line2 = "Idle";
46 else
47 st.line2 = "Calling";
48 end
49 luci.http.prepare_content("application/json")
50 luci.http.write_json(st)
51 end