Exemplo n.º 1
0
function callInitiate($target, $ev)
{
    Yate::Debug("Initiating dialout call to '{$target}'");
    $m = new Yate("call.execute");
    $m->id = "";
    $m->SetParam("callto", "external/nodata/dialout-dialer.php");
    $m->SetParam("direct", $target);
    $m->SetParam("caller", $ev->GetValue("caller"));
    $m->SetParam("callername", $ev->GetValue("callername"));
    $m->SetParam("called", $ev->GetValue("called"));
    $m->Dispatch();
}
Exemplo n.º 2
0
function callInitiate($target, $ev)
{
    Yate::Debug("Initiating dialout call to '{$target}'");
    $m = new Yate("call.execute");
    $m->params = $ev->params;
    $m->id = "";
    $m->SetParam("callto", "external/nodata/ctc-dialer.php");
    $m->SetParam("direct", $target);
    $m->SetParam("caller", $ev->GetValue("real_called"));
    $m->SetParam("call_from", $ev->GetValue("call_from"));
    $m->SetParam("called", $ev->GetValue("real_caller"));
    $m->SetParam("cdrtrack", "true");
    $m->Dispatch();
}
Exemplo n.º 3
0
function vmGetMessageFiles($mailbox, &$files)
{
    $dir = vmGetVoicemailDir($mailbox);
    if (is_dir($dir) && ($d = @opendir($dir))) {
        $nf = array();
        $of = array();
        while (($f = readdir($d)) !== false) {
            if (substr($f, 0, 4) == "nvm-") {
                Yate::Debug("found new file '{$f}'");
                $nf[] = $f;
            } else {
                if (substr($f, 0, 3) == "vm-") {
                    Yate::Debug("found old file '{$f}'");
                    $of[] = $f;
                }
            }
        }
        closedir($d);
        $files = array_merge($nf, $of);
        return true;
    }
    return false;
}
Exemplo n.º 4
0
function doRoute(&$ev)
{
    global $prefix, $calls;
    $called = $ev->GetValue("called");
    // Check if called number starts with prefix
    $len = strlen($prefix);
    if (substr($called, 0, $len) != $prefix) {
        return;
    }
    // Get rid of prefix and search the active calls
    $called = substr($called, $len);
    if ($called == "") {
        return;
    }
    // Have to search, cannot use number as array key because it's not unique
    $chan = array_search($called, $calls);
    Yate::Debug("For picking up '{$called}' found channel '{$chan}'");
    if ($chan == "") {
        return;
    }
    // Found! Route to it and signal success
    $ev->retval = "pickup/{$chan}";
    $ev->handled = true;
}
Exemplo n.º 5
0
function callAnswered($ev, $text, $idParam)
{
    global $param;
    global $defDelay;
    $evId = $ev->GetValue($idParam);
    $evPeerId = $ev->GetValue("peerid");
    $outbound = getBoolValue($ev->getValue($param . "_outbound"), false);
    $tmp = $ev->getValue($param . "_delay");
    $delay = $defDelay;
    if (!empty($tmp)) {
        $val = (int) $tmp;
        if ($val >= 0) {
            $delay = $val;
        }
    }
    Yate::Debug($param . ": Handling " . $ev->name . " text=" . $text . " id=" . $evId . " peerid=" . $evPeerId . " outbound=" . $outbound . " delay=" . $delay);
    if ($outbound) {
        if (empty($evPeerId)) {
            return;
        }
        $evId = $evPeerId;
    } else {
        if (empty($evId)) {
            return;
        }
    }
    if ($delay > 0) {
        setupCall($evId, true, $delay, $text);
    } else {
        sendTones($evId, $text);
    }
}
Exemplo n.º 6
0
function debug($msg)
{
    Yate::Debug('send_voicem.php: ' . $msg);
}
Exemplo n.º 7
0
function onAnswer($ev, $id, $when)
{
    global $calls;
    global $codes;
    if (substr($id, 0, 4) != "sip/") {
        return;
    }
    if (!isset($calls[$id])) {
        return;
    }
    $keys = $codes[rand(0, count($codes) - 1)];
    $when += rand(2, 10);
    $calls[$id] = "{$when}:{$keys}";
    Yate::Debug("ANSWER: {$id} '{$keys}'");
}
Exemplo n.º 8
0
 function Update($ev, $id)
 {
     $body = $ev->GetValue("xsip_body");
     if ($body != "") {
         Yate::Debug("Presence: for " . $this->match);
         $this->body = $body;
         $this->pending = true;
         $this->Flush();
     }
 }
Exemplo n.º 9
0
 /**
  * Initialize the IVR system if not already initialized, used internally
  */
 private static function InitIVR()
 {
     global $yate_ivr_target;
     global $yate_ivr_register;
     global $yate_ivr_current;
     global $yate_ivr_stack;
     global $yate_ivr_files;
     if (isset($yate_ivr_register)) {
         return;
     }
     Yate::Debug("IVR::InitIVR()");
     $yate_ivr_target = null;
     $yate_ivr_register = array();
     $yate_ivr_current = null;
     $yate_ivr_stack = array();
     $yate_ivr_files = "";
 }
Exemplo n.º 10
0
function debug($mess)
{
    Yate::Debug("register.php : " . $mess);
}
Exemplo n.º 11
0
function gotDTMF($text)
{
    global $state;
    global $mailbox;
    global $collect_user;
    global $collect_pass;
    Yate::Debug("gotDTMF('{$text}') state: {$state}");
    switch ($state) {
        case "user":
            if ($text == "*") {
                promptUser();
                return;
            }
            if ($text == "#") {
                checkUser();
            } else {
                $collect_user .= $text;
            }
            return;
        case "pass":
            if ($text == "*") {
                promptPass();
                return;
            }
            if ($text == "#") {
                checkPass();
            } else {
                $collect_pass .= $text;
            }
            return;
    }
    if ($mailbox == "") {
        return;
    }
    navigate($text);
}
Exemplo n.º 12
0
                    }
                    break;
                case "engine.help":
                    $ev->handled = onHelp($ev->GetValue("line"), $ev->retval);
                    break;
                case "call.execute":
                    if ($detect && $ev->GetValue("callto")) {
                        onExecute($ev->GetValue("id"), $ev);
                    }
                    break;
                case "call.fax":
                    onFax($ev->GetValue("id"));
                    break;
            }
            $ev->Acknowledge();
            break;
        case "answer":
            Yate::Debug("PHP Answered: " . $ev->name . " id: " . $ev->id);
            break;
        case "installed":
            Yate::Debug("PHP Installed: " . $ev->name);
            break;
        case "uninstalled":
            Yate::Debug("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: */
Exemplo n.º 13
0
function onCommand($l, &$retval)
{
    global $hosts;
    global $ban_failures;
    global $cmd_unban;
    if ($l == "banbrutes") {
        $gray = 0;
        $banned = 0;
        foreach ($hosts as &$host) {
            if ($host->banned()) {
                $banned++;
            } else {
                $gray++;
            }
        }
        $retval = "failures={$ban_failures},banned={$banned},gray={$gray}\r\n";
        return true;
    } else {
        if ($l == "banbrutes list") {
            $retval = "";
            $now = time();
            foreach ($hosts as $addr => &$host) {
                if ($retval != "") {
                    $retval .= ",";
                }
                if ($host->banned()) {
                    $t = $host->when - $now;
                    $retval .= "{$addr}=banned:{$t}s";
                } else {
                    $retval .= "{$addr}=gray:" . $host->fail;
                }
            }
            $retval .= "\r\n";
            return true;
        } else {
            if (strpos($l, "banbrutes unban ") === 0) {
                $addr = substr($l, 16);
                if (isset($hosts[$addr])) {
                    if ($hosts[$addr]->banned()) {
                        $cmd = eval('return "' . $cmd_unban . '";');
                        Yate::Output("banbrutes: {$cmd}");
                        shell_exec($cmd);
                        unset($hosts[$addr]);
                        $retval = "Unbanned: {$addr}\r\n";
                    } else {
                        unset($hosts[$addr]);
                        $retval = "Removed from gray list: {$addr}\r\n";
                    }
                } else {
                    $retval = "Not banned: {$addr}\r\n";
                }
                return true;
            } else {
                if (strpos($l, "banbrutes failures ") === 0) {
                    $fail = 1 * substr($l, 19);
                    if ($fail > 1 && $fail <= 1000) {
                        $ban_failures = $fail;
                        return true;
                    }
                } else {
                    if (strpos($l, "banbrutes debug ") === 0) {
                        $dbg = substr($l, 16);
                        switch ($dbg) {
                            case "true":
                            case "yes":
                            case "on":
                                Yate::Debug(true);
                                return true;
                            case "false":
                            case "no":
                            case "off":
                                Yate::Debug(false);
                                return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Exemplo n.º 14
0
            case "*":
                // hang up the IVR channel and possibly the incoming call
                IVR::Hangup();
                break;
            case "#":
                // return to calling IVR with value 'Got #'
                IVR::Leave("Got {$tone}");
                break;
            case "0":
            case "1":
            case "2":
                $this->Output("Got {$tone}");
                break;
            default:
                return false;
        }
        return true;
    }
}
// initialize the Yate PHP library with default values, enable output to rmanager and debugging
Yate::Init();
Yate::Output(true);
Yate::Debug(true);
// register the two IVR classes with some names
IVR::Register("ivr1", "IVR1");
IVR::Register("ivr2", "TheIVR_2");
// and start running by entering the 1st IVR
IVR::Run("ivr1");
// if we reach here the IVR is terminated
Yate::Output("PHP: bye!");
/* vi: set ts=8 sw=4 sts=4 noet: */
Exemplo n.º 15
0
function endRoute($callto, $ok, $err, $params)
{
    global $partycallid;
    global $collect;
    global $final;
    global $queue;
    global $routeOnly;
    global $state;
    if ($ok && $callto != "-" && $callto != "error") {
        Yate::Output("Overlapped got route: '{$callto}' for '{$collect}'");
        $m = new Yate("chan.masquerade");
        $m->params = $params;
        $m->params["message"] = "call.execute";
        $m->params["complete_minimal"] = true;
        $m->params["id"] = $partycallid;
        $m->params["callto"] = $callto;
        $m->Dispatch();
        if (strlen($queue)) {
            // Masquerade the remaining digits
            // TODO: wait for call.execute to be processed to do that?
            $d = new Yate("chan.masquerade");
            $d->params["message"] = "chan.dtmf";
            $d->params["id"] = $partycallid;
            $d->params["tone"] = $queue;
            $d->Dispatch();
        }
        return;
    }
    if ($final) {
        Yate::Output("Overlapped got final error '{$err}' for '{$collect}'");
        Yate::SetLocal("reason", $err);
        setState("");
    } else {
        if ($err != "incomplete") {
            Yate::Output("Overlapped got error '{$err}' for '{$collect}'");
            Yate::SetLocal("reason", $err);
            setState("");
            $final = true;
        } else {
            Yate::Debug("Overlapped still incomplete: '{$collect}'");
            if ($routeOnly) {
                setState("noroute");
            } else {
                // Don't use setState: we don't want to change the prompt
                $state = "prompt";
            }
            // Check if got some other digits
            if ($queue != "") {
                gotDTMF("");
            }
        }
    }
}
Exemplo n.º 16
0
function callAnswered()
{
    global $ourcallid;
    global $prompt;
    global $done;
    Yate::Debug("callAnswered");
    if ($prompt != "") {
        $m = new Yate("chan.attach");
        $m->id = "";
        $m->SetParam("id", $ourcallid);
        $m->SetParam("source", $prompt);
        $m->SetParam("single", true);
        $m->SetParam("notify", $ourcallid);
        $m->Dispatch();
    } else {
        $done = true;
    }
}
Exemplo n.º 17
0
function debug($mess)
{
    Yate::Debug("auto_attendant.php: " . $mess);
}
Exemplo n.º 18
0
function debug($msg)
{
    Yate::Debug('send_mail.php: ' . $msg);
}
Exemplo n.º 19
0
        continue;
    }
    $id = $ev->GetValue("peerid");
    if ($ev->type == "incoming") {
        if ($ev->GetValue("earlymedia") == "false" && $ev->GetValue("rtp_forward") != "yes") {
            Yate::Debug("Preparing fake {$mediafmt} ringback to {$id}");
            $ev->SetParam("earlymedia", true);
            $ev->SetParam("formats", $mediafmt);
            $ev->SetParam("ringback", $ringback);
        }
        $ev->Acknowledge();
    } else {
        if ($ev->type == "answer") {
            if ($ev->handled) {
                $ring = $ev->GetValue("ringback");
                if ($id != "" && $ring != "") {
                    Yate::Debug("Faking ringback {$ring} to {$id}");
                    $m = new Yate("chan.masquerade");
                    $m->id = "";
                    $m->SetParam("message", "chan.attach");
                    $m->SetParam("id", $id);
                    $m->SetParam("replace", $ring);
                    $m->SetParam("autorepeat", true);
                    $m->SetParam("single", true);
                    $m->Dispatch();
                }
            }
        }
    }
}
/* vi: set ts=8 sw=4 sts=4 noet: */
Exemplo n.º 20
0
function debug($mess)
{
    Yate::Debug("leavemaildb.php: " . $mess);
}
Exemplo n.º 21
0
function invalidate($address)
{
    global $cache;
    foreach ($cache as $host => &$entries) {
        $changed = false;
        foreach ($entries as $idx => $cached) {
            if ($cached->address == $address) {
                Yate::Output("Invalidating {$address} of host {$host}");
                unset($entries[$idx]);
                $changed = true;
            }
        }
        if (count($entries) == 0) {
            Yate::Debug("Invalidating entire host {$host}");
            unset($cache[$host]);
        } else {
            if ($changed) {
                $cache[$host] = array_values($cache[$host]);
            }
        }
    }
}
Exemplo n.º 22
0
 function Update($ev, $id)
 {
     $st = "";
     $dir = "";
     switch ($ev->GetValue("operation")) {
         case "initialize":
             $st = "trying";
             break;
         case "finalize":
             $st = "terminated";
             break;
         default:
             switch ($ev->GetValue("status")) {
                 case "connected":
                 case "answered":
                     $st = "confirmed";
                     break;
                 case "incoming":
                 case "outgoing":
                 case "calling":
                 case "ringing":
                 case "progressing":
                     $st = "early";
                     break;
                 case "redirected":
                     $st = "rejected";
                     break;
                 case "destroyed":
                     $st = "terminated";
                     break;
             }
     }
     if ($st != "") {
         // directions are reversed because we are talking about the remote end
         switch ($ev->GetValue("direction")) {
             case "incoming":
                 $dir = "initiator";
                 break;
             case "outgoing":
                 $dir = "recipient";
                 break;
         }
         if ($dir != "") {
             $dir = " direction=\"{$dir}\"";
         }
     } else {
         $id = false;
     }
     Yate::Debug("Dialog updated, st: '{$st}' id: '{$id}'");
     $this->body = "<?xml version=\"1.0\"?>\r\n";
     $this->body .= "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"" . $this->version . "\" entity=\"" . $this->uri . "\" notify-state=\"full\">\r\n";
     if ($id) {
         $uri = ereg_replace("^.*<([^<>]+)>.*\$", "\\1", $this->uri);
         $tag = $this->match;
         $tag = " call-id=\"{$id}\" local-tag=\"{$tag}\" remote-tag=\"{$tag}\"";
         $this->body .= "  <dialog id=\"{$id}\"{$tag}{$dir}>\r\n";
         $this->body .= "    <state>{$st}</state>\r\n";
         $this->body .= "    <remote><target uri=\"{$uri}\"/></remote>\r\n";
         $this->body .= "  </dialog>\r\n";
     }
     $this->body .= "</dialog-info>\r\n";
     $this->version++;
     $this->pending = true;
     if ($id) {
         $this->Flush();
     }
 }
Exemplo n.º 23
0
function debug($mess)
{
    Yate::Debug("voicemaildb.php: " . $mess);
}
Exemplo n.º 24
0
                        case "never":
                            SendMsg("call.ringing");
                            break;
                    }
                    /* Prevent a warning if trying to ACK this message again */
                    $ev = false;
                    break;
                case "chan.notify":
                    Yate::Uninstall("chan.notify");
                    $m = new Yate("chan.attach");
                    $m->params["id"] = $ourcallid;
                    $m->params["source"] = $newsource;
                    $m->Dispatch();
                    $newsource = "";
                    if ($answermode == "late") {
                        SendMsg("call.answered");
                    }
                    break;
            }
            /* This is extremely important.
               We MUST let messages return, handled or not */
            if ($ev) {
                $ev->Acknowledge();
            }
            break;
        default:
            Yate::Debug("PHP Event: " . $ev->type);
    }
}
Yate::Debug("PHP: bye!");
/* vi: set ts=8 sw=4 sts=4 noet: */
Exemplo n.º 25
0
function gotNotify($reason)
{
    global $state;
    Yate::Debug("gotNotify('{$reason}') state: {$state}");
    if ($reason == "replaced") {
        return;
    }
    switch ($state) {
        case "goodbye":
            setState("");
            break;
        case "greeting":
            setState("beep");
            break;
        case "beep":
            setState("record");
            break;
        default:
            setState("goodbye");
            break;
    }
}