# Asterisk Project : Phone Provisioning Templates

Added by mdavenport , edited by mdavenport on Dec 20, 2010

Configuration templates are a generic way to configure phones with text-based configuration files. Templates can use any loaded dialplan function and all of the variables created by phoneprov.conf and users.conf. A short example is the included 000000000000.cfg Polycom template:

    <?xml version="1.0" standalone="yes"?>
      <APPLICATION
        APP_FILE_PATH="sip.ld"
        CONFIG_FILES="${IF($[${STAT(e,${CUSTOM_CONFIG})}] ? "custom.cfg, ")}config/${TOLOWER(${MAC})}, sip.cfg"
        MISC_FILES="" LOG_FILE_DIRECTORY=""
     />

This template uses dialplan functions, expressions, and a couple of variables to generate a config file to instruct the Polycom where to pull other needed config files. If a phone with MAC address 0xDEADBEEF4DAD requests this config file, and the filename that is stored in variable CUSTOM_CONFIG does not exist, then the generated output would be:

    <?xml version="1.0" standalone="yes"?>
      <APPLICATION
        APP_FILE_PATH="sip.ld"
        CONFIG_FILES="config/deadbeef4dad, sip.cfg"
        MISC_FILES=""
        LOG_FILE_DIRECTORY=""
    />

The Polycom phone would then download both sip.cfg (which would be registered in phoneprov.conf as a static file) and config/deadbeef4dad (which would be registered as a dynamic file pointing to another template, polycom.xml).

res_phoneprov also registers its own dialplan function: PP_EACH_USER. This function was designed to be able to print out a particular string for each user that res_phoneprov knows about. An example use of this function is the template for a Polycom contact directory:

    <?xml version="1.0" standalone="yes"?>
    <directory>
      <item_list>
        ${PP_EACH_USER(<item><fn>%{DISPLAY_NAME}</fn><ct>%{CALLERID}</ct><bw>1</bw></item>|${MAC})}
      </item_list>
    </directory>

PP_EACH_USER takes two arguments. The first is the string to be printed for each user. Any variables that are to be substituted need to be in the format %{VARNAME} so that Asterisk doesn't try to substitute the variable immediately before it is passed to PP_EACH_USER. The second, optional, argument is a MAC address to exclude from the list iterated over (so, in this case, a phone won't be listed in its own contact directory).

## Comments:

Note separator error in
    CONFIG_FILES="${IF($[${STAT(e|${CUSTOM_CONFIG})}] ? "custom.cfg, ")}config/${TOLOWER(${MAC})}, sip.cfg"
where the pipe is no longer used. This should be:
    CONFIG_FILES="${IF($[${STAT(e,${CUSTOM_CONFIG})}] ? "custom.cfg, ")}config/${TOLOWER(${MAC})}, sip.cfg"
Posted by lathama at Dec 20, 2010 13:50
Good catch. Addressed. Posted by mdavenport at Dec 20, 2010 16:27
Examples for some advanced usage. Advanced Usage
    %{SIPPEER(%{CALLERID},pickupgroup)}
    %{SIPPEER(%{CALLERID},callgroup)}
    %{SIPPEER(%{CALLERID},context)}
    %{SIPPEER(%{CALLERID},useragent)}
    %{SIPPEER(%{CALLERID},ip)}
Posted by lathama at Sep 06, 2011 14:57