public static function set($base) { if (empty($base['plugins']['simpleroute'])) { return; } $simpleroute = $base['plugins']['simpleroute']; foreach ($simpleroute['patterns'] as $index => $options) { foreach ($simpleroute['contexts'] as $context_id => $enabled) { $xml = FreeSwitch::createExtension('trunk_' . $base['trunk_id'] . '_pattern_' . $index, 'main', 'context_' . $context_id); if (empty($enabled)) { $xml->deleteNode(); continue; } if (empty($options['enabled'])) { $xml->deleteNode(); continue; } if (!($pattern = simplerouter::getOutboundPattern($index, 'freeswitch'))) { $xml->deleteNode(); continue; } $condition = '/condition[@field="destination_number"][@expression="' . $pattern . '"][@bluebox="pattern_' . $index . '"]'; if (!empty($options['prepend'])) { $xml->update($condition . '/action[@application="set"][@bluebox="prepend"]{@data="prepend=' . $options['prepend'] . '"}'); } else { $xml->update($condition . '/action[@application="set"][@bluebox="prepend"]{@data="prepend="}'); } if (!empty($simpleroute['caller_id_name'])) { $xml->update($condition . '/action[@application="set"][@bluebox="cid_name"]{@data="effective_caller_id_name=' . $simpleroute['caller_id_name'] . '"}'); } if (!empty($simpleroute['caller_id_number'])) { $xml->update($condition . '/action[@application="set"][@bluebox="cid_number"]{@data="effective_caller_id_number=' . $simpleroute['caller_id_number'] . '"}'); } // If a Caller ID module is installed and caller ID is set, use it // TODO: Integrate this into the plugin $caller_id = '/condition[@field="${outbound_caller_id_number}"][@expression="^.+$"][@break="never"][@bluebox="caller_id"]'; $xml->update($caller_id . '/action[@application="set"][@data="effective_caller_id_name=${outbound_caller_id_name}"]'); $xml->update($caller_id . '/action[@application="set"][@data="effective_caller_id_number=${outbound_caller_id_number}"]'); $dummy = '/condition[@field="destination_number"][@expression="' . $pattern . '"][@bluebox="pattern_' . $index . '_out"]'; $xml->update($dummy . '/action[@application="bridge"]{@data="sofia\\/gateway\\/trunk_' . $base['trunk_id'] . '\\/${prepend}$1"}'); } } }
public static function set($base) { if (empty($base['plugins']['simpleroute']['patterns'])) { return; } $simpleroute = $base['plugins']['simpleroute']; $sip = $base['plugins']['sip']; foreach ($simpleroute['patterns'] as $simple_route_id => $options) { foreach ($simpleroute['contexts'] as $context_id => $enabled) { $xml = FreeSwitch::createExtension('trunk_' . $base['trunk_id'] . '_pattern_' . $simple_route_id, 'main', 'context_' . $context_id); if (empty($enabled)) { $xml->deleteNode(); continue; } if (empty($options['enabled'])) { $xml->deleteNode(); continue; } if (!($pattern = simplerouter::getOutboundPattern($simple_route_id, 'freeswitch'))) { $xml->deleteNode(); continue; } $xml->deleteChildren(); $pattern_string = ''; foreach (array_keys($pattern) as $pattern_index) { $pattern_string .= '|' . $pattern[$pattern_index]; } $pattern_string = substr($pattern_string, 1); $condition = '/condition[@field="destination_number"][@expression="' . $pattern_string . '"][@bluebox="pattern_' . $simple_route_id . '_parts"]'; if (isset($options['prepend'])) { $xml->update($condition . '/action[@application="set"][@bluebox="prepend"]{@data="prepend=' . $options['prepend'] . '"}'); } else { $xml->update($condition . '/action[@application="set"][@bluebox="prepend"]{@data="prepend="}'); } if (!empty($simpleroute['caller_id_name'])) { $xml->update($condition . '/action[@application="set"][@bluebox="cid_name"]{@data="effective_caller_id_name=' . $simpleroute['caller_id_name'] . '"}'); } if (!empty($simpleroute['caller_id_number'])) { $xml->update($condition . '/action[@application="set"][@bluebox="cid_number"]{@data="effective_caller_id_number=' . $simpleroute['caller_id_number'] . '"}'); } // If a Caller ID module is installed and caller ID is set, use it // TODO: Integrate this into the plugin $caller_id = '/condition[@field="${outbound_caller_id_number}"][@expression="^.+$"][@break="never"][@bluebox="caller_id"]'; $xml->update($caller_id . '/action[@application="set"][@data="effective_caller_id_name=${outbound_caller_id_name}"]'); $xml->update($caller_id . '/action[@application="set"][@data="effective_caller_id_number=${outbound_caller_id_number}"]'); // Put Caller ID into the right place if (isset($sip['caller_id_field'])) { if ($sip['caller_id_field'] == 'rpid' or $sip['caller_id_field'] == 'pid') { $xml->update($caller_id . '/action[@application="export"][@bluebox="caller_id_field"]{@data="sip_cid_type=' . $sip['caller_id_field'] . '"}'); } else { // Assume Caller ID is default or elsewhere $xml->deleteNode($caller_id . '/action[@application="export"][@bluebox="caller_id_field"]'); } } foreach (array_keys($pattern) as $pattern_index) { $dummy = '/condition[@field="destination_number"][@break="never"][@expression="' . $pattern[$pattern_index] . '"][@bluebox="pattern_' . $simple_route_id . '_part_' . ($pattern_index + 1) . '_out"]'; $xml->update($dummy . '/action[@application="set"]{@data="hangup_after_bridge=true"}'); if (!empty($simpleroute['continue_on_fail'])) { //$xml->update($dummy .'/action[@application="set"][@bluebox="setting_continue_on_fail"]{@data="failure_causes=NORMAL_CLEARING,ORIGINATOR_CANCEL,CRASH"}'); $xml->update($dummy . '/action[@application="set"][@bluebox="setting_continue_on_fail"]{@data="continue_on_fail=true"}'); } else { $xml->deleteNode($dummy . '/action[@application="set"][@bluebox="setting_continue_on_fail"]'); } $boolAllowMediaProxy = $base['registry']['allow_media_proxy'] == 0 ? 'false' : 'true'; $xml->update($dummy . '/action[@application="set"][@data="proxy_media=' . $boolAllowMediaProxy . '"]'); $xml->update($dummy . '/action[@application="bridge"][@bluebox="out_trunk_' . $base['trunk_id'] . '"]{@data="sofia\\/gateway\\/trunk_' . $base['trunk_id'] . '\\/${prepend}$1"}'); } } } }
public static function set($xmppData) { $xml = Telephony::getDriver()->xml; // Build the Dinagling profile... $root = '//document/section[@name="configuration"]/configuration[@name="dingaling.conf"]' . '/profile[@name="dingaling_' . $xmppData['xmpp_id'] . '"]'; $xml->setXmlRoot($root); $xml->update('/param[@name="name"]{@value="dingaling_' . $xmppData['xmpp_id'] . '"}'); $login = preg_replace('/\//', '\/', $xmppData['login']); $xml->update('/param[@name="login"]{@value="' . $login . '"}'); $xml->update('/param[@name="password"]{@value="' . $xmppData['registry']['password'] . '"}'); $xml->update('/param[@name="server"]{@value="' . $xmppData['registry']['loginserver'] . '"}'); $xml->update('/param[@name="dialplan"]{@value="' . $xmppData['registry']['dialplan'] . '"}'); $message = $xmppData['registry']['message']; if($message == "") { $message = "Bluebox"; } $xml->update('/param[@name="message"]{@value="' . $message . '"}'); $xml->update('/param[@name="rtp-ip"]{@value="' . $xmppData['registry']['rtpip'] . '"}'); $xml->update('/param[@name="auto-login"]{@value="' . ($xmppData['registry']['autologin'] == 1 ? 'true' : 'false') . '"}'); $autoreply = $xmppData['registry']['autoreply']; if($autoreply == "") { $autoreply = "This is an auto-reply"; } $xml->update('/param[@name="auto-reply"]{@value="' . $autoreply . '"}'); $xml->update('/param[@name="sasl"]{@value="' . $xmppData['registry']['sasl'] . '"}'); $xml->update('/param[@name="tls"]{@value="' . ($xmppData['registry']['tls'] == 1 ? 'true' : 'false') . '"}'); $xml->update('/param[@name="use-rtp-timer"]{@value="' . ($xmppData['registry']['usertptimer'] == 1 ? 'true' : 'false') . '"}'); $xml->update('/param[@name="vad"]{@value="' . $xmppData['registry']['vad'] . '"}'); $xml->update('/param[@name="candidate-acl"]{@value="' . $xmppData['registry']['candidateacl'] . '"}'); $xml->update('/param[@name="local-network-acl"]{@value="' . $xmppData['registry']['localnetacl'] . '"}'); $xml->update('/param[@name="context"]{@value="context_' . $xmppData['registry']['inbound_context'] . '"}'); // Now to locate the 'real' extension, our exten variable is holding the number's index $realExten = Doctrine::getTable('Number')->find($xmppData['registry']['exten']); $xml->update('/param[@name="exten"]{@value="' . $realExten['number'] . '"}'); // Build the dialplan from the ... foreach ($xmppData['registry']['patterns'] as $simple_route_id => $options) { foreach ($xmppData['registry']['contexts'] as $context_id => $enabled) { //dingaling_1_pattern_1 $xml = FreeSwitch::createExtension($xmppData['xmpp_id'] .'_pattern_' .$simple_route_id, 'main', 'context_' .$context_id); if (empty($enabled)) { $xml->deleteNode(); continue; } if (empty($options['enabled'])) { $xml->deleteNode(); continue; } if (!$pattern = simplerouter::getOutboundPattern($simple_route_id, 'freeswitch')) { $xml->deleteNode(); continue; } $xml->deleteChildren(); foreach(array_keys($pattern) as $pattern_index) { $condition = '/condition[@field="destination_number"][@break="never"][@expression="' . $pattern[$pattern_index] . '"][@bluebox="pattern_' .$simple_route_id .'_part_' . $pattern_index . '"]'; if (!empty($options['prepend'])) { $xml->update($condition .'/action[@application="set"][@bluebox="prepend"]{@data="prepend=' .$options['prepend'] . '"}'); } else { $xml->update($condition .'/action[@application="set"][@bluebox="prepend"]{@data="prepend="}'); } $xml->update($condition . '/action[@application="set"][@data="hangup_after_bridge=true"]'); $xml->update($condition . '/action[@application="bridge"]{@data="dingaling\/' . $xmppData['name'] . '\/+${prepend}$1@' . $xmppData['registry']['outboundserver'] . '"}'); } } } }
public static function delete($obj) { $doc = Telephony::getDriver()->doc; $base = Bluebox_Record::getBaseTransactionObject(); if (empty($base->trunk_id)) { return FALSE; } $patterns = simplerouter::getOutboundPattern('emergency', 'asterisk'); foreach ($patterns as $pattern => $exten) { $doc->deleteDialplanExtension($obj->context_id, $pattern); } $patterns = simplerouter::getOutboundPattern('international', 'asterisk'); foreach ($patterns as $pattern => $exten) { $doc->deleteDialplanExtension($obj->context_id, $pattern); } $patterns = simplerouter::getOutboundPattern('local', 'asterisk'); foreach ($patterns as $pattern => $exten) { $doc->deleteDialplanExtension($obj->context_id, $pattern); } $patterns = simplerouter::getOutboundPattern('short', 'asterisk'); foreach ($patterns as $pattern => $exten) { $doc->deleteDialplanExtension($obj->context_id, $pattern); } }
public static function set($base) { if ($base instanceof Device) { if (isset($base['plugins']['simpleroute']['tags'])) { $tags = preg_split('/[\\s\\,]+/', $base['plugins']['simpleroute']['tags']); sort($tags); $tags = implode(" ", $tags); } else { $tags = ""; } $domain = '$${location_' . $base['User']['location_id'] . '}'; $xml = FreeSwitch::setSection('user', $domain, $base['device_id']); $xml->update('/variables/variable[@name="bluebox-tags"]{@value="' . $tags . '"}'); } elseif ($base instanceof Simpleroute) { foreach (Doctrine::getTable('Context')->findAll() as $thiscontext) { $routenumber = 0; if (array_key_exists("simpleroute", $thiscontext->plugins)) { foreach ($thiscontext->plugins["simpleroute"] as $route) { $trunk = Doctrine::getTable('Trunk')->find($route["trunk"]); $destination = Doctrine::getTable('SimpleRoute')->find($route["destination"]); $pattern_number = 0; foreach (simplerouter::getOutboundPattern($route["destination"], 'freeswitch') as $pattern) { $routenumber++; $pattern_number++; $xml = FreeSwitch::createExtension("route_{$routenumber}", 'main', 'context_' . $thiscontext->context_id); if (!isset($route["taglist"])) { $route["taglist"] = ""; } # Remove all the children, and put in a comment so we can see where we are! $xml->replaceWithXML('<!-- CONTEXT: ' . $thiscontext->context_id . ' - ' . $thiscontext->name . '; DESTINATION: ' . $route["destination"] . ' - ' . $destination->name . '; TRUNK: ' . $route["trunk"] . ' - ' . $trunk->name . '; PATTERN: ' . $pattern_number . ' - ' . $pattern . " TAGS: {$route['taglist']} -->"); if ($route["taglist"] != "") { $taglist = preg_split('/[\\s\\,]+/', $route["taglist"]); sort($taglist); $taglist = '^(.* |)' . implode('( .* | )', $taglist) . '( .*|)$'; $xml->update('/condition[@field="${bluebox-tags}"][@break="on-false"][@expression="' . $taglist . '"]'); } $xml->update('/condition[@field="destination_number"][@break="on-false"][@expression="' . $pattern . '"][@bluebox="extension-in"]'); // If a Caller ID module is installed and caller ID is set, use it // TODO: Integrate this into the plugin $caller_id = '/condition[@field="${outbound_caller_id_number}"][@expression="^.+$"][@break="never"][@bluebox="caller_id"]'; $xml->update($caller_id . '/action[@application="set"][@data="effective_caller_id_name=${outbound_caller_id_name}"]'); $xml->update($caller_id . '/action[@application="set"][@data="effective_caller_id_number=${outbound_caller_id_number}"]'); // Put Caller ID into the right place if (isset($sip['caller_id_field'])) { if ($sip['caller_id_field'] == 'rpid' or $sip['caller_id_field'] == 'pid') { $xml->update($caller_id . '/action[@application="export"][@bluebox="caller_id_field"]{@data="sip_cid_type=' . $sip['caller_id_field'] . '"}'); } else { // Assume Caller ID is default or elsewhere $xml->deleteNode($caller_id . '/action[@application="export"][@bluebox="caller_id_field"]'); } } $dummy = '/condition[@field="destination_number"][@break="never"][@expression="' . $pattern . '"]'; if (!empty($route['continue_on_fail'])) { $xml->update($dummy . '/action[@application="set"][@bluebox="setting_continue_on_fail"]{@data="failure_causes=NORMAL_CLEARING,ORIGINATOR_CANCEL,CRASH"}'); } else { $xml->deleteNode($dummy . '/action[@application="set"][@bluebox="setting_continue_on_fail"]'); } $xml->update($dummy . '/action[@application="bridge"][@bluebox="extension_out"]{@data="sofia\\/gateway\\/trunk_' . $route['trunk'] . '\\/' . $route["dialstring"] . '"}'); } } } // If there are any routes > routenumber, then they are old and need to be deleted. $routenumber++; $xml = FreeSwitch::createExtension("route_{$routenumber}", 'main', 'context_' . $thiscontext->context_id, array("existing")); while ($xml !== FALSE) { $xml->deleteNode(); $routenumber++; $xml = FreeSwitch::createExtension("route_{$routenumber}", 'main', 'context_' . $thiscontext->context_id, array("existing")); } } } }