application/luci-asterisk:
[project/luci.git] / applications / luci-asterisk / luasrc / model / cbi / asterisk / trunks.lua
index b9dd1df..02576b5 100644 (file)
@@ -15,7 +15,8 @@ $Id$
 
 local ast = require("luci.asterisk")
 
 
 local ast = require("luci.asterisk")
 
-cbimap = Map("asterisk", "asterisk", "")
+cbimap = Map("asterisk", "Registered Trunks")
+cbimap.pageaction = false
 
 local sip_peers = { }
 cbimap.uci:foreach("asterisk", "sip",
 
 local sip_peers = { }
 cbimap.uci:foreach("asterisk", "sip",
@@ -28,16 +29,47 @@ cbimap.uci:foreach("asterisk", "sip",
        end)
 
 
        end)
 
 
-sip_table = cbimap:section(Table, sip_peers, "SIP Trunks")
-sip_table.template = "cbi/tblsection"
-sip_table.extedit  = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
+sip_table = cbimap:section(TypedSection, "sip", "SIP Trunks")
+sip_table.template  = "cbi/tblsection"
+sip_table.extedit   = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
+sip_table.addremove = true
+
+sip_table.hidden = {
+       type    = "peer",
+       qualify = "yes"
+}
+
+function sip_table.filter(self, s)
+       return s and (
+               cbimap.uci:get("asterisk", s, "type") == "peer" or
+               cbimap.uci:get("asterisk", s, "type") == nil
+       )
+end
+
+function sip_table.create(self, section)
+       if TypedSection.create(self, section) then
+               created = section
+       else
+               self.invalid_cts = true
+       end
+end
+
+function sip_table.parse(self, ...)
+       TypedSection.parse(self, ...)
+       if created then
+               cbimap.uci:save("asterisk")
+               luci.http.redirect(luci.dispatcher.build_url(
+                       "admin", "asterisk", "trunks", "sip", created
+               ))
+       end
+end
+
 
 
-name = sip_table:option(DummyValue, "name")
 user = sip_table:option(DummyValue, "username")
 
 host = sip_table:option(DummyValue, "host")
 function host.cfgvalue(self, s)
 user = sip_table:option(DummyValue, "username")
 
 host = sip_table:option(DummyValue, "host")
 function host.cfgvalue(self, s)
-       if sip_peers[s].info.address then
+       if sip_peers[s] and sip_peers[s].info.address then
                return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
        else
                return "n/a"
                return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
        else
                return "n/a"
@@ -46,28 +78,41 @@ end
 
 context = sip_table:option(DummyValue, "context")
 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
 
 context = sip_table:option(DummyValue, "context")
 context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
+function context.cfgvalue(...)
+       return AbstractValue.cfgvalue(...) or "(default)"
+end
 
 nat = sip_table:option(DummyValue, "nat")
 function nat.cfgvalue(self, s)
 
 nat = sip_table:option(DummyValue, "nat")
 function nat.cfgvalue(self, s)
-       return sip_peers[s].info.Nat or "none"
+       return sip_peers[s] and sip_peers[s].info.Nat or "none"
 end
 
 online = sip_table:option(DummyValue, "online")
 function online.cfgvalue(self, s)
 end
 
 online = sip_table:option(DummyValue, "online")
 function online.cfgvalue(self, s)
-       if sip_peers[s].info.online == nil then
+       if sip_peers[s] and sip_peers[s].info.online == nil then
                return "n/a"
        else
                return "n/a"
        else
-               return sip_peers[s].info.online and "yes" or "no"
+               return sip_peers[s] and sip_peers[s].info.online
+                       and "yes" or "no (%s)" %{
+                               sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown"
+                       }
        end
 end
 
 delay = sip_table:option(DummyValue, "delay")
 function delay.cfgvalue(self, s)
        end
 end
 
 delay = sip_table:option(DummyValue, "delay")
 function delay.cfgvalue(self, s)
-       if sip_peers[s].info.online then
+       if sip_peers[s] and sip_peers[s].info.online then
                return "%i ms" % sip_peers[s].info.delay
        else
                return "n/a"
        end
 end
 
                return "%i ms" % sip_peers[s].info.delay
        else
                return "n/a"
        end
 end
 
+info = sip_table:option(Button, "_info", "Info")
+function info.write(self, s)
+       luci.http.redirect(luci.dispatcher.build_url(
+               "admin", "asterisk", "trunks", "sip", s, "info"
+       ))
+end
+
 return cbimap
 return cbimap