<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/2033/1/7/_/styles/combined.css?spaceKey=AST&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://wiki.asterisk.org/wiki/display/AST/Phone+Provisioning+Templates">Phone Provisioning Templates</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://wiki.asterisk.org/wiki/display/~mdavenport">Malcolm Davenport</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >  &lt;APPLICATION  <br>    APP_FILE_PATH=&quot;sip.ld&quot;  <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">CONFIG_FILES=&quot;${IF($[${STAT(e<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">|</span><span class="diff-added-chars"style="background-color: #dfd;">,</span>${CUSTOM_CONFIG})}]</span> ? &quot;custom.cfg, &quot;)}config/${TOLOWER(${MAC})}, sip.cfg&quot; <br></td></tr>
            <tr><td class="diff-unchanged" >    MISC_FILES=&quot;&quot; LOG_FILE_DIRECTORY=&quot;&quot; <br> /&gt; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>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:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: xml; gutter: false"><![CDATA[
&lt;?xml version="1.0" standalone="yes"?&gt;
  &lt;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=""
 /&gt;
]]></script>
</div></div>

<p>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:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: xml; gutter: false"><![CDATA[
&lt;?xml version="1.0" standalone="yes"?&gt;
  &lt;APPLICATION
    APP_FILE_PATH="sip.ld"
    CONFIG_FILES="config/deadbeef4dad, sip.cfg"
    MISC_FILES=""
    LOG_FILE_DIRECTORY=""
/&gt;
]]></script>
</div></div>

<p>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). </p>

<p>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:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: xml; gutter: false"><![CDATA[
&lt;?xml version="1.0" standalone="yes"?&gt;
&lt;directory&gt;
  &lt;item_list&gt;
    ${PP_EACH_USER(&lt;item&gt;&lt;fn&gt;%{DISPLAY_NAME}&lt;/fn&gt;&lt;ct&gt;%{CALLERID}&lt;/ct&gt;&lt;bw&gt;1&lt;/bw&gt;&lt;/item&gt;|${MAC})}
  &lt;/item_list&gt;
&lt;/directory&gt;
]]></script>
</div></div>

<p>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).</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://wiki.asterisk.org/wiki/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://wiki.asterisk.org/wiki/display/AST/Phone+Provisioning+Templates">View Online</a>
        |
        <a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=5243059&revisedVersion=3&originalVersion=2">View Changes</a>
                |
        <a href="https://wiki.asterisk.org/wiki/display/AST/Phone+Provisioning+Templates?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>