<commit_before>--[[
LuCI - Lua Configuration Interface

Copyright 2008 <NAME> <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

$Id$

]]--

local ast = require("luci.asterisk")

--
-- Specific SIP trunk
--
if arg[1] then
	cbimap = Map("asterisk", "Edit SIP Trunk")

	peer = cbimap:section(NamedSection, arg[1], "Foo")

	name = peer:option(DummyValue, "username")

	outproxy = peer:option(Value, "outboundproxy")
	

	return cbimap

--
-- Trunk overview
--
else
	cbimap = Map("asterisk", "asterisk", "")

	local sip_peers = { }
	cbimap.uci:foreach("asterisk", "sip",
		function(s)
			if s.type == "peer" then
				s.name = s['.name']
				s.info = ast.sip.peer(s.name)
				sip_peers[s.name] = s
			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")

	name = sip_table:option(DummyValue, "name")
	user = sip_table:option(DummyValue, "username")

	host = sip_table:option(DummyValue, "host")
	function host.cfgvalue(self, s)
		if sip_peers[s].info.address then
			return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
		else
			return "n/a"
		end
	end

	context = sip_table:option(DummyValue, "context")
	context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")

	nat = sip_table:option(DummyValue, "nat")
	function nat.cfgvalue(self, s)
		return sip_peers[s].info.Nat or "none"
	end

	online = sip_table:option(DummyValue, "online")
	function online.cfgvalue(self, s)
		if sip_peers[s].info.online == nil then
			return "n/a"
		else
			return sip_peers[s].info.online and "yes" or "no"
		end
	end

	delay = sip_table:option(DummyValue, "delay")
	function delay.cfgvalue(self, s)
		if sip_peers[s].info.online then
			return "%i ms" % sip_peers[s].info.delay
		else
			return "n/a"
		end
	end

	return cbimap
end
<commit_msg>applications/luci-asterisk: add some options to sip trunk configuration<commit_after>--[[
LuCI - Lua Configuration Interface

Copyright 2008 <NAME> <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

$Id$

]]--

local ast = require("luci.asterisk")

--
-- Specific SIP trunk
--
if arg[1] then
	cbimap = Map("asterisk", "Edit SIP Trunk")

	peer = cbimap:section(NamedSection, arg[1])
	peer.hidden = {
		type = "peer"
	}

	back = peer:option(DummyValue, "_overview", "Back to trunk overview")
	back.value = ""
	back.titleref = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip")

	sipdomain = peer:option(Value, "host", "SIP Domain")
	sipport   = peer:option(Value, "port", "SIP Port")
	sipport.default = 5060

	username  = peer:option(Value, "username", "Authorization ID")
	password  = peer:option(Value, "secret", "Authorization Password")
	password.password = <PASSWORD>

	register = peer:option(ListValue, "register", "Register with peer")
	register:value("yes", "on")
	register:value("no", "off")

	regext = peer:option(Value, "registerextension", "Extension to register (optional)")
	regext:depends({register="yes"})

	didval = peer:option(ListValue, "_did", "Number of assigned DID numbers")
	for i=1,24 do didval:value(i) end

	return cbimap

--
-- Trunk overview
--
else
	cbimap = Map("asterisk", "asterisk", "")

	local sip_peers = { }
	cbimap.uci:foreach("asterisk", "sip",
		function(s)
			if s.type == "peer" then
				s.name = s['.name']
				s.info = ast.sip.peer(s.name)
				sip_peers[s.name] = s
			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")

	name = sip_table:option(DummyValue, "name")
	user = sip_table:option(DummyValue, "username")

	host = sip_table:option(DummyValue, "host")
	function host.cfgvalue(self, s)
		if sip_peers[s].info.address then
			return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
		else
			return "n/a"
		end
	end

	context = sip_table:option(DummyValue, "context")
	context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")

	nat = sip_table:option(DummyValue, "nat")
	function nat.cfgvalue(self, s)
		return sip_peers[s].info.Nat or "none"
	end

	online = sip_table:option(DummyValue, "online")
	function online.cfgvalue(self, s)
		if sip_peers[s].info.online == nil then
			return "n/a"
		else
			return sip_peers[s].info.online and "yes" or "no"
		end
	end

	delay = sip_table:option(DummyValue, "delay")
	function delay.cfgvalue(self, s)
		if sip_peers[s].info.online then
			return "%i ms" % sip_peers[s].info.delay
		else
			return "n/a"
		end
	end

	return cbimap
end

{'fraction_non_alphanumeric': 0.15203856196023297, 'fraction_numerical': 0.0054227756577626025, 'mean_word_length': 4.343347639484978, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1890247', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1861, 'n_words': 445}