#!/usr/bin/php -q type) { case "incoming": $userPart = ''; // Reset variables each time around $domainPart = ''; $ev->handled = false; preg_match('/sip:(.*)@([^;]+)/', $ev->params['sip_uri'], $parts); // parse a SIP URI $userPart = preg_replace('/[^[:alnum:]]/', '', $parts[1]); // remove non-alpha/num $domainPart = $parts[2]; Yate::Output($ev->params['id'] . ": Invite from " . $ev->params['sip_from']); if (!in_array(strtolower($domainPart), $localDomains)) { // check whether the domain requested is our domain/IP Yate::Output($ev->params['id'] . ": Looking up TXT for $userPart@$domainPart"); $lookup = dns_get_record("sip-$userPart.$domainPart", DNS_TXT); // sip-user.dom.ain IN TXT? if (isset($lookup[0]['txt'])) { // only acts on the first TXT record found for the name $dest = $lookup[0]['txt']; Yate::Output($ev->params['id'] . ": Rerouting to sip:" . $dest); $ev->retval = 'sip/sip:' . $dest; $ev->setParam('redirect', 'true'); } else { Yate::Output($ev->params['id'] . ": Not found"); $ev->retval = '-'; $ev->setparam('error', '404'); $ev->setparam('reason', 'TXT Not Found'); } unset($lookup); // reset for next time around this loop } else { // reject requests to our domain/IP Yate::Output($ev->params['id'] . ": Ignoring local request."); $ev->retval = '-'; $ev->setparam('error', '403'); $ev->setparam('reason', 'Forbidden'); } /* This is extremely important. We MUST let messages return, handled or not */ $ev->handled = TRUE; // this is the only routing in all cases. Either redirect or 404. $ev->Acknowledge(); break; case "answer": Yate::Output("PHP Answered: " . $ev->name . " id: " . $ev->id); break; case "installed": Yate::Output("PHP Installed: " . $ev->name); break; case "uninstalled": Yate::Output("PHP Uninstalled: " . $ev->name); break; default: Yate::Output("PHP Event: " . $ev->type); } } Yate::Output("PHP: bye!"); /* vi: set ts=8 sw=4 sts=4 noet: */ ?>