I implented a hack, that I thought might benefit others.
- I added an item to template_data.xml:
<item>
<!-- Image Name -->
<variable>$external_ip</variable>
<default_value></default_value>
<description>External IP Address</description>
<type>input</type>
</item>
-
I created two clones, one for local phones and one for remote phones. In the clone for the remote phone, I put the external IP address for the PBX, in the clone for the local phones, I left it blank.
-
I created a function in base.php called “parse_if” (which is just a slightly modified variant of “parse_loops”):
/**
* Parse data between {if_*}{/if_*}
* @param string $line_total Total Number of Lines on the specific Phone
* @param string $file_contents Full Contents of the configuration file
* @param boolean $keep_unknown Keep Unknown variables as {$variable} instead of erasing them (blanking the space), can be used to parse these variables later
* @param integer $specific_line The specific line number to manipulate. If no line number set then assume All Lines
* @return string Full Contents of the configuration file (After Parsing)
* @example {if_external_ip}{/if_external_ip}
* @author Andrew Nagy
*/
function parse_if($line_total, $file_contents, $keep_unknown=FALSE, $specific_line='ALL') {
//Find line looping data betwen {line_loop}{/line_loop}
$pattern = "/{if_(.*?)}(.*?){\/if_(.*?)}/si";
while (preg_match($pattern, $file_contents, $matches)) {
if(isset($this->options[$matches[3]]) and $this->options[$matches[3]] != "") {
$parsed = "";
$parsed .= $this->parse_config_values($matches[2], FALSE, "GLOBAL");
$file_contents = preg_replace($pattern, $parsed, $file_contents, 1);
} else {
$file_contents = preg_replace($pattern, "", $file_contents, 1);
}
}
return($file_contents);
}
- Added call to “parse_if” under the call for “parse_loops”:
$file_contents = $this->parse_if($line_total,$file_contents, $keep_unknown = FALSE, $specific_line);
- Now, in my template I can have logic like this:
{if_external_ip}
#
# NAT
#
nat_enable: "1"
nat_address: "{$external_ip}"
nat_received_processing: 1
proxy1_address: "{$external_ip}"
proxy2_address: "{$external_ip}"
{/if_external_ip}