Auerswald PBX templates for D.Series running 1.4

templates.xml
<?xml version="1.0" encoding="utf-8"?>
<templates version="1.3.5">
  <template prio="30" name="@string/speed_dial_title">
    <keyConfiguration>
      <function>
        <invocations>
          <invocation>
            <invite>
              <uri/>
              <line>
                <id/>
              </line>
            </invite>
          </invocation>
        </invocations>
        <reactions>
          <reaction>
            <presence>
              <subscribe type="dialog">
                <uri/>
                <line>
                  <id/>
                </line>
              </subscribe>
            </presence>
          </reaction>
        </reactions>
      </function>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/uri">
        <path>//subscribe/uri</path>
        <path>//invite/uri</path>
        <mode>append</mode>
      </parameter>
      <parameter optional="true" name="@string/identity">
        <path>//subscribe/line/id</path>
        <path>//invite/line/id</path>
      </parameter>
    </parameters>
  </template>
  <template prio="10" name="@string/call_waiting_title" icon="@drawable/call_waiting">
    <keyConfiguration>
      <function>
        <invocations>
          <invocation>
            <setting path="/telephony/callWaiting/active">
              <values>
                <value>true</value>
                <led ledColor="green"/>
              </values>
              <values>
                <value>false</value>
                <led ledColor="off"/>
              </values>
            </setting>
          </invocation>
        </invocations>
      </function>
    </keyConfiguration>
  </template>
  <template name="@string/do_not_disturb_title" prio="10" icon="@drawable/dnd">
    <keyConfiguration>
      <lua>
        <code>local valid = false
			local active = false
			local on = "##8*211"
			local off = "##8*210"
			local userpath = "/identities/identity["..identity.."]/"
			local host = config.get(userpath .. "host")
			local user = config.get(userpath .. "username")
 
			local function updateLed()
			if valid then
				if active then
					key:setLed( "red" )
				else
					key:setLed( "off" )
					end
				else
					key:setLed( "red", true )
				end
			end
 
			local unescape = function(url)
				return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
				end
 
			local function check_sub(data, uri, handle)
			local x = xml.eval(data)
			local test_uri_on = "sip:"..on.."#"..user.."@"..host
			if unescape(uri) == test_uri_on and x ~= nil then
				for _,dlg in ipairs(x) do
					state = dlg:find("state") 
					if state and state[1] == "trying" then 
						active = true
					elseif state and state[1] == "terminated" then
						active = false
						end
					end
				end
				updateLed()
			end
 
			local function check_valid()
			if identity == "" then
				valid = false
			else
				valid = true
				end
			end
 
			local function sub()
				sip.subscribe(on.."#"..user,"0",identity,check_sub)
				end
 
			function onKeyUp()
			if active and valid then
				sip.invite(off.."#"..user,false,identity,true)
			elseif valid then
				sip.invite(on.."#"..user,false,identity,true)
				end
			end
			check_valid()
			updateLed()
		    sub()</code>
        <params>
          <param name="identity"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
    </parameters>
  </template>
  <template prio="10" name="@string/clir_title" icon="@drawable/clir">
    <keyConfiguration>
      <function>
        <invocations>
          <invocation>
            <setting path="/telephony/clir/active">
              <values>
                <value>true</value>
                <led ledColor="green"/>
              </values>
              <values>
                <value>false</value>
                <led ledColor="off"/>
              </values>
            </setting>
          </invocation>
        </invocations>
      </function>
    </keyConfiguration>
  </template>
  <template name="@string/call_forwarding_unconditional_title" prio="10" icon="@drawable/call_forwarding">
    <keyConfiguration>
      <lua>
        <code>local valid = false
			local active = false
			local on = "*21*"
			local off = "#21#"
			local userpath = "/identities/identity["..identity.."]/"
			local host = config.get(userpath .. "host")
			local user = config.get(userpath .. "username")
 
			local function updateLed()
			if valid then
				if active then
					key:setLed( "green" )
				else
					key:setLed( "off" )
					end
			else
				key:setLed( "red", true )
				end
			end
 
			local unescape = function(url)
				return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
				end
 
				local function check_sub(data, uri, handle)
				local x = xml.eval(data)
				local test_uri_on = "sip:"..on..target.."#"..user.."@"..host			
				if unescape(uri) == test_uri_on and x ~= nil then
					for _,dlg in ipairs(x) do
						state = dlg:find("state") 
						if state and state[1] == "trying" then 
							active = true
						elseif state and state[1] == "terminated" then
							active = false
						end
					end
				end
				updateLed()
		    	end
 
				local function check_valid()
				if identity == "" or target== "" then
					valid = false
				else
					valid = true
					end
				end
 
				local function sub()
				sip.subscribe(on..target.."#"..user,"0",identity,check_sub)
				end
 
				function onKeyUp()
				if active and valid then
					sip.invite(off.."#"..user,false,identity,true)
				elseif valid then
					sip.invite(on..target.."#"..user,false,identity,true)
					end
			    end
				check_valid()
				updateLed()
				sub()</code>
        <params>
          <param name="identity"/>
          <param name="target"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
      <parameter name="@string/target">
        <path>//param[@name="target"]/value</path>
      </parameter>
    </parameters>
  </template>
  <template name="@string/call_forwarding_busy_title" prio="10" icon="@drawable/call_forwarding">
    <keyConfiguration>
      <lua>
        <code>local valid = false
			local active = false
			local on = "*67*"
			local off = "#67#"
			local userpath = "/identities/identity["..identity.."]/"
			local host = config.get(userpath .. "host")
			local user = config.get(userpath .. "username")
 
			local function updateLed()
			if valid then
				if active then
					key:setLed( "green" )
				else
					key:setLed( "off" )
					end
			else
				key:setLed( "red", true )
				end
			end
 
			local unescape = function(url)
			return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
			end
 
			local function check_sub(data, uri, handle)
			local x = xml.eval(data)
			local test_uri_on = "sip:"..on..target.."#"..user.."@"..host
			if unescape(uri) == test_uri_on and x ~= nil then
				for _,dlg in ipairs(x) do
					state = dlg:find("state") 
					if state and state[1] == "trying" then 
						active = true
					elseif state and state[1] == "terminated" then
						active = false
						end
					end
				end
		    	updateLed()
			end
 
			local function check_valid()
			if identity =="" or target=="" then
				valid = false
			else
				valid = true
			end
			end
 
			local function sub()
			sip.subscribe(on..target.."#"..user,"0",identity,check_sub)
				end
 
			function onKeyUp()
			if active and valid then
				sip.invite(off.."#"..user,false,identity,true)
			elseif valid then
				sip.invite(on..target.."#"..user,false,identity,true)
				end
		    end
			check_valid()
			updateLed()
			sub()</code>
        <params>
          <param name="identity"/>
          <param name="target"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
      <parameter name="@string/target">
        <path>//param[@name="target"]/value</path>
      </parameter>
    </parameters>
  </template>
  <template name="@string/call_forwarding_no_response_title" prio="10" icon="@drawable/call_forwarding">
    <keyConfiguration>
      <lua>
        <code>local valid = false
			local active = false
			local on = "*61*"
			local off = "#61#"
		    local userpath = "/identities/identity["..identity.."]/"
			local host = config.get(userpath .. "host")
			local user = config.get(userpath .. "username")
 
			local function updateLed()
			if valid then
				if active then
					key:setLed( "green" )
				else
					key:setLed( "off" )
					end
			else
				key:setLed( "red", true )
				end
			end
 
			local unescape = function(url)
			return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
			end
 
			local function check_sub(data, uri, handle)
			local x = xml.eval(data)
			local test_uri_on = "sip:"..on..target.."#"..user.."@"..host
			if unescape(uri) == test_uri_on and x ~= nil then
				for _,dlg in ipairs(x) do
				state = dlg:find("state") 
				if state and state[1] == "trying" then 
					active = true
				elseif state and state[1] == "terminated" then
					active = false
					end
				end
			end
			updateLed()
			end
 
			local function check_valid()
			if identity =="" or target=="" then
				valid = false
			else
				valid = true
				end
			end
 
			local function sub()
			sip.subscribe(on..target.."#"..user,"0",identity,check_sub)
			end
 
			function onKeyUp()
			if active and valid then
				sip.invite(off.."#"..user,false,identity,true)
			elseif valid then
				sip.invite(on..target.."#"..user,false,identity,true)
				end
			end
			check_valid()
			updateLed()
			sub()</code>
        <params>
          <param name="identity"/>
          <param name="target"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
      <parameter name="@string/target">
        <path>//param[@name="target"]/value</path>
      </parameter>
    </parameters>
  </template>
  <template prio="20" name="@string/line_title">
    <keyConfiguration>
      <line>
        <id/>
      </line>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//line/id</path>
      </parameter>
    </parameters>
  </template>
  <template prio="10" name="@string/http_request_title">
    <keyConfiguration>
      <function>
        <invocations>
          <invocation>
            <http>
              <request httpMethod="get">
                <uri/>
              </request>
              <httpReactions>
                <responseCode ledColor="off">
                  <responseCode>200</responseCode>
                </responseCode>
              </httpReactions>
            </http>
          </invocation>
        </invocations>
      </function>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/uri">
        <path>//uri</path>
      </parameter>
    </parameters>
  </template>
  <template prio="10" name="@string/vpn">
    <keyConfiguration>
      <function>
        <invocations>
          <invocation>
            <setting path="network/vpn/active">
              <values>
                <value>true</value>
                <led ledColor="green"/>
              </values>
              <values>
                <value>false</value>
                <led ledColor="off"/>
              </values>
            </setting>
          </invocation>
        </invocations>
      </function>
    </keyConfiguration>
  </template>
  <template name="@string/group_title" prio="10" icon="@drawable/group">
    <keyConfiguration>
      <lua>
        <code>local valid = false
			local active = false
			local on = "##8*401"
			local off = "##8*400"
			local userpath = "/identities/identity["..identity.."]/"
			local host = config.get(userpath .. "host")
			local user = config.get(userpath .. "username")
 
			local function updateLed()
			if valid then
				if active then
					key:setLed( "green" )
				else
					key:setLed( "off" )
				end
			else
				key:setLed( "red", true )
				end
			end
 
			local unescape = function(url)
			return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
			end
 
			local function check_sub(data, uri, handle)
			local x = xml.eval(data)
			local test_uri_on = "sip:"..on..group.."#"..user.."@"..host
			if unescape(uri) == test_uri_on and x ~= nil then
				for _,dlg in ipairs(x) do
					state = dlg:find("state") 
					if state and state[1] == "trying" then 
						active = true
					elseif state and state[1] == "terminated" then
						active = false
						end
					end
				end
				updateLed()
			end
 
			local function check_valid()
			if identity == "" or group == "" then
				valid = false
			else
				valid = true
				end
			end
 
			local function sub()
			sip.subscribe(on..group.."#"..user,"0",identity,check_sub)
			end
 
			function onKeyUp()
			if active and valid then
				sip.invite(off..group.."#"..user,false,identity,true)
			elseif valid then
				sip.invite(on..group.."#"..user,false,identity,true)
				end
			end
			check_valid()
			updateLed()
			sub()</code>
        <params>
          <param name="identity"/>
          <param name="group"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
      <parameter name="@string/group">
        <path>//param[@name="group"]/value</path>
      </parameter>
    </parameters>
  </template>
  <template name="@string/call_forwarding_extern_no_response_title" prio="10" icon="@drawable/call_forwarding">
    <keyConfiguration>
      <lua>
        <code>local valid = false
			local active = false
			local prefix ="##96"
			local on = "*61*"
			local off = "##61#"
			local userpath = "/identities/identity["..identity.."]/"
			local host = config.get(userpath .. "host")
			local user = config.get(userpath .. "username")
 
			local function updateLed()
			if valid then
				if active then
					key:setLed( "green" )
				else
					key:setLed( "off" )
					end
			else
				key:setLed( "red", true )
				end
			end
 
			local unescape = function(url)
			return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
			end
 
			local function check_sub(data, uri, handle)
			local x = xml.eval(data)
			local test_uri_on = "sip:"..prefix..msn.."#"..on..target.."#"..user.."@"..host
			if unescape(uri) == test_uri_on and x ~= nil then
				for _,dlg in ipairs(x) do
					state = dlg:find("state") 
				    if state and state[1] == "trying" then 
						active = true
					elseif state and state[1] == "terminated" then
						active = false
						end
					end
				end
				updateLed()
			end
 
			local function check_valid()
			if identity =="" or target=="" then
				valid = false
			else
				valid = true
				end
			end
 
			local function sub()
			sip.subscribe(prefix..msn.."#"..on..target.."#"..user,"0",identity,check_sub)
			end
 
			function onKeyUp()
			if active and valid then
				sip.invite(prefix..msn..off.."#"..user,false,identity,true)
			elseif valid then
				sip.invite(prefix..msn.."#"..on..target.."#"..user,false,identity,true)
				end
			end
			check_valid()
			updateLed()
			sub()</code>
        <params>
          <param name="identity"/>
          <param name="target"/>
          <param name="msn"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
      <parameter name="@string/msn">
        <path>//param[@name="msn"]/value</path>
      </parameter>
      <parameter name="@string/target">
        <path>//param[@name="target"]/value</path>
      </parameter>
    </parameters>
  </template>
  <template name="@string/call_forwarding_extern_busy_title" prio="10" icon="@drawable/call_forwarding">
    <keyConfiguration>
      <lua>
        <code>local valid = false
			local active = false
			local prefix ="##96"
			local on = "*67*"
			local off = "##67#"
			local userpath = "/identities/identity["..identity.."]/"
			local host = config.get(userpath .. "host")
			local user = config.get(userpath .. "username")
 
			local function updateLed()
			if valid then
				if active then
					key:setLed( "green" )
				else
					key:setLed( "off" )
					end
				else
					key:setLed( "red", true )
					end
				end
 
				local unescape = function(url)
				return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
				end
 
				local function check_sub(data, uri, handle)
				local x = xml.eval(data)
				local test_uri_on = "sip:"..prefix..msn.."#"..on..target.."#"..user.."@"..host
				if unescape(uri) == test_uri_on and x ~= nil then
					for _,dlg in ipairs(x) do
						state = dlg:find("state") 
						if state and state[1] == "trying" then 
							active = true
						elseif state and state[1] == "terminated" then
							active = false
						end
					end
				end
				updateLed()
				end
 
				local function check_valid()
				if identity =="" or target=="" then
					valid = false
				else
					valid = true
					end
				end
 
				local function sub()
				sip.subscribe(prefix..msn.."#"..on..target.."#"..user,"0",identity,check_sub)
				end
 
				function onKeyUp()
				if active and valid then
					sip.invite(prefix..msn..off.."#"..user,false,identity,true)
				elseif valid then
					sip.invite(prefix..msn.."#"..on..target.."#"..user,false,identity,true)
					end
				end
			    check_valid()
				updateLed()
				sub()</code>
        <params>
          <param name="identity"/>
          <param name="target"/>
          <param name="msn"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
      <parameter name="@string/msn">
        <path>//param[@name="msn"]/value</path>
      </parameter>
      <parameter name="@string/target">
        <path>//param[@name="target"]/value</path>
      </parameter>
    </parameters>
  </template>
  <template name="@string/call_forwarding_extern_unconditional_title" prio="10" icon="@drawable/call_forwarding">
    <keyConfiguration>
      <lua>
        <code>local valid = false
			local active = false
			local prefix ="##96"
			local on = "*21*"
			local off = "##21#"
			local userpath = "/identities/identity["..identity.."]/"
			local host = config.get(userpath .. "host")
			local user = config.get(userpath .. "username")
 
			local function updateLed()
			if valid then
				if active then
					key:setLed( "green" )
				else
					key:setLed( "off" )
				end
			else
				key:setLed( "red", true )
				end
			end
 
			local unescape = function(url)
				return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
			end
 
			local function check_sub(data, uri, handle)
				local x = xml.eval(data)
				local test_uri_on = "sip:"..prefix..msn.."#"..on..target.."#"..user.."@"..host
				if (unescape(uri) == test_uri_on) and x ~= nil then
				for _,dlg in ipairs(x) do
					state = dlg:find("state") 
					if state and state[1] == "trying" then 
						active = true
					elseif state and state[1] == "terminated" then
						active = false
						end
					end
				end
				updateLed()
			    end
 
				local function check_valid()
					if identity =="" or target=="" then
						valid = false
					else
						valid = true
					end
				end
 
				local function sub()
					sip.subscribe(prefix..msn.."#"..on..target.."#"..user,"0",identity,check_sub)
				end
 
				function onKeyUp()
					if active and valid then
						sip.invite(prefix..msn..off.."#"..user,false,identity,true)
					elseif valid then
						sip.invite(prefix..msn.."#"..on..target.."#"..user,false,identity,true)
					end
				end
				check_valid()
				updateLed()
				sub()</code>
        <params>
          <param name="identity"/>
          <param name="target"/>
          <param name="msn"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
      <parameter name="@string/msn">
        <path>//param[@name="msn"]/value</path>
      </parameter>
      <parameter name="@string/target">
        <path>//param[@name="target"]/value</path>
      </parameter>
    </parameters>
  </template>
  <template name="@string/config_activation_title" prio="10" icon="@drawable/day_or_night">
    <keyConfiguration>
      <lua>
        <code>local valid = false
			local active = false
			local on = "##8*81"
			local userpath = "/identities/identity["..identity.."]/"
			local host = config.get(userpath .. "host")
			local user = config.get(userpath .. "username")
 
			local function updateLed()
			if valid then
				if active then
					key:setLed( "green" )
				else
					key:setLed( "off" )
				    end
			else
				key:setLed( "red", true )
				end
		    end
 
			local unescape = function(url)
			return url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end )
			end
 
			local function check_sub(data, uri, handle)
			local x = xml.eval(data)
			local test_uri_on = "sip:"..on..konfid.."#"..user.."@"..host
			if unescape(uri) == test_uri_on then
				for _,dlg in ipairs(x) do
					state = dlg:find("state") 
					if state and state[1] == "trying" then 
						active = true
					elseif state and state[1] == "terminated" then
						active = false
						end
					end
				end
				updateLed()
				end
 
				local function check_valid()
					if identity == "" or konfid == "" then
						valid = false
					else
						valid = true
					end
				end
 
				local function sub()
					sip.subscribe(on..konfid.."#"..user,"0",identity,check_sub)
				end
 
				function onKeyUp()
					if not active and valid then
						sip.invite(on..konfid.."#"..user,false,identity,true)
					end
				end
				check_valid()
				updateLed()
				sub()</code>
        <params>
          <param name="identity"/>
          <param name="konfid"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
      <parameter name="@string/configuration_id">
        <path>//param[@name="konfid"]/value</path>
      </parameter>
    </parameters>
  </template>
  <template prio="10" name="@string/relay_title" icon="@drawable/relay">
    <keyConfiguration>
      <lua>
        <code>
local valid = false
local active = false
local on = "##8*26"
 
local function updateLed()
  if valid then
    if active then
        key:setLed( "green", true )
        time.sleep("2")
        key:setLed( "off")
    end
  else
    key:setLed( "red", true )
  end
end
 
local function check_valid()
  if identity == "" or relid == "" then
    valid = false
  else
    valid = true
  end
end
 
function onKeyUp()
  if valid then
    sip.invite(on..relid.."#",false,identity,true)
    active = true
    updateLed()
  end
end
 
check_valid()
updateLed()
        </code>
        <params>
          <param name="identity"/>
          <param name="relid"/>
        </params>
      </lua>
    </keyConfiguration>
    <parameters>
      <parameter name="@string/identity">
        <path>//param[@name="identity"]/value</path>
      </parameter>
      <parameter name="@string/relay_id">
        <path>//param[@name="relid"]/value</path>
      </parameter>
    </parameters>
  </template>  
</templates>