ltqtapi.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. -- Copyright 2019 John Crispin <blogic@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. module("luci.controller.ltqtapi", package.seeall)
  4. function index()
  5. if not nixio.fs.access("/etc/config/telephony") then
  6. return
  7. end
  8. page = node("admin", "telephony")
  9. page.target = firstchild()
  10. page.title = _("VoIP")
  11. page.order = 90
  12. page.acl_depends = { "luci-app-ltqtapi" }
  13. entry({"admin", "telephony", "account"}, cbi("luci_ltqtapi/account") , _("Account"), 10)
  14. entry({"admin", "telephony", "contact"}, cbi("luci_ltqtapi/contact") , _("Contacts"), 20)
  15. entry({"admin", "telephony", "status"}, call("tapi_status")).leaf = true
  16. end
  17. function tapi_status()
  18. local st = { }
  19. local state = require "luci.model.uci".cursor_state()
  20. state:load("telephony")
  21. st.status = "Offline";
  22. if state:get("telephony", "state", "port1", "0") == "0" then
  23. st.line1 = "Idle";
  24. else
  25. st.line1 = "Calling";
  26. end
  27. if state:get("telephony", "state", "port2", "0") == "0" then
  28. st.line2 = "Idle";
  29. else
  30. st.line2 = "Calling";
  31. end
  32. luci.http.prepare_content("application/json")
  33. luci.http.write_json(st)
  34. end