Exemplo n.º 1
0
function callExecuting($peerid)
{
    global $ourcallid;
    global $partycallid;
    Yate::Debug("callExecuting: '{$peerid}'");
    $partycallid = $peerid;
    // Install handlers for the wave end and dtmf notify messages
    Yate::Install("chan.dtmf", 90, "peerid", $ourcallid);
    Yate::Install("call.answered", 90, "peerid", $ourcallid);
    Yate::Install("chan.notify", 90, "id", $ourcallid);
}
Exemplo n.º 2
0
 /**
  * This static function initializes globals in the PHP Yate Channel Module.
  * It should be called before any other method.
  * It will call Yate::Init internally.
  * @param $prefix (optional) Prefix used for the unique channel identifier
  * @param $async (optional) True if asynchronous, polled mode is desired
  * @param $addr Hostname to connect to or UNIX socket path
  * @param $port TCP port to connect to, zero to use UNIX sockets
  */
 static function Init($prefix = "extchan", $async = false, $addr = "", $port = 0)
 {
     global $chan_instance;
     Yate::Init($async, $addr, $port, "channel");
     $chan_instance = new YateChan($prefix);
     YateChan::RunEvents();
     if ($chan_instance->exiting) {
         return;
     }
     Yate::Install("chan.dtmf");
     Yate::Install("chan.notify");
 }
Exemplo n.º 3
0
 */
/* Simple player/recorder for the Yate PHP interface
   To test add in regexroute.conf

   ^NNN$=external/nodata/playrec.php

   where NNN is the number you want to assign
*/
require_once "libyate.php";
/* Always the first action to do */
Yate::Init();
/* Set tracking name for all installed handlers */
Yate::SetLocal("trackparam", "playrec.php");
/* Install handlers for the DTMF and wave EOF messages */
Yate::Install("chan.dtmf");
Yate::Install("chan.notify");
$ourcallid = "playrec/" . uniqid(rand(), 1);
$partycallid = "";
$state = "call";
$dir = "/tmp";
function setState($newstate)
{
    global $ourcallid;
    global $partycallid;
    global $state;
    global $dir;
    // are we exiting?
    if ($state == "") {
        return;
    }
    Yate::Output("setState('" . $newstate . "') state: " . $state);
Exemplo n.º 4
0
#!/usr/bin/php -q

<?php 
/* Test script for the Yate PHP interface
   To test add in extmodule.conf

   [scripts]
   test.php=
*/
require_once "libyate.php";
/* Always the first action to do */
Yate::Init();
/* Install a handler for the call routing message */
Yate::Install("call.route", 80);
/* The main loop. We pick events and handle them */
for (;;) {
    $ev = Yate::GetEvent();
    /* If Yate disconnected us then exit cleanly */
    if ($ev === false) {
        break;
    }
    /* Empty events are normal in non-blocking operation.
       This is an opportunity to do idle tasks and check timers */
    if ($ev === true) {
        //        Yate::Output("PHP event: empty");
        continue;
    }
    /* If we reached here we should have a valid object */
    switch ($ev->type) {
        case "incoming":
            //    Yate::Output("PHP Message: " . $ev->name . " id: " . $ev->id . " called: " . $ev->params["called"] . " caller: " . $ev->params["caller"]);
Exemplo n.º 5
0
    global $tones;
    foreach ($calls as $key => $call) {
        $calls[$key]--;
        if ($calls[$key] <= 0) {
            sendTones($key, $tones[$key]);
            // sendTones() might change the counter
            if ($calls[$key] <= 0) {
                setupCall($key, false);
            }
        }
    }
}
Yate::Watch("call.answered");
Yate::Watch("chan.replaced");
Yate::Install("chan.hangup");
Yate::Install("engine.timer");
// Restart if terminated
Yate::SetLocal("restart", true);
Yate::Debug($param . ": Starting");
/* The main loop. We pick events and handle them */
for (;;) {
    $ev = Yate::GetEvent();
    /* If Yate disconnected us then exit cleanly */
    if ($ev === false) {
        break;
    }
    /* Empty events are normal in non-blocking operation.
       This is an opportunity to do idle tasks and check timers */
    if ($ev === true) {
        Yate::Debug($param . ": empty event");
        continue;
Exemplo n.º 6
0
    $m = new Yate("chan.masquerade");
    $m->params = $ev->params;
    $m->SetParam("message", "call.execute");
    $m->SetParam("callto", $route);
    //$m->SetParam("caller", $real_caller);
    $m->SetParam("called", $real_called);
    $m->SetParam("id", $partycallid);
    $m->SetParam("billid", $billid);
    $m->SetParam("call_from", $callFrom);
    $m->Dispatch();
}
/* Always the first action to do */
Yate::Init();
Yate::SetLocal("id", $ourcallid);
Yate::SetLocal("disconnected", "true");
Yate::Install("call.answered", 50, "targetid", $ourcallid);
$exit = false;
/* The main loop. We pick events and handle them */
for (;;) {
    if ($exit) {
        break;
    }
    $ev = Yate::GetEvent();
    /* If Yate disconnected us then exit cleanly */
    if ($ev === false) {
        break;
    }
    /* No need to handle empty events in this application */
    if ($ev === true) {
        continue;
    }
Exemplo n.º 7
0
     }
     $newsource = $ev->GetValue("source");
     if ($ev->GetValue("greeting")) {
         $m->params["source"] = $ev->GetValue("greeting");
     } else {
         if ($newsource) {
             if (substr($newsource, 0, 4) == "moh/") {
                 $m->params["mohlist"] = $ev->GetValue("mohlist");
             }
             $m->params["source"] = $newsource;
             $newsource = "";
         }
     }
     if ($newsource) {
         $m->params["notify"] = $ourcallid;
         Yate::Install("chan.notify", 100, "targetid", $ourcallid);
     } else {
         if ($answermode == "late") {
             $answermode = "early";
         }
     }
     $m->Dispatch();
 }
 switch ($answermode) {
     case "early":
         SendMsg("call.answered");
         break;
     case "late":
     case "never":
         SendMsg("call.ringing");
         break;
Exemplo n.º 8
0
 }
 /* No need to handle empty events in this application */
 if ($ev === true) {
     continue;
 }
 /* If we reached here we should have a valid object */
 switch ($ev->type) {
     case "incoming":
         switch ($ev->name) {
             case "call.execute":
                 $partycallid = $ev->GetValue("notify");
                 $caller = $ev->GetValue("caller");
                 $prompt = $ev->GetValue("prompt");
                 $queue = $ev->GetValue("queue");
                 $ev->handled = true;
                 Yate::Install("chan.hangup", 80, "id", $partycallid);
                 // create call leg to operator
                 $m = new Yate("call.execute");
                 $m->params["id"] = $ourcallid;
                 $m->params["caller"] = $caller;
                 $m->params["called"] = $ev->GetValue("called");
                 $m->params["callto"] = $ev->GetValue("direct");
                 $m->params["billid"] = $ev->GetValue("billid");
                 $m->params["maxcall"] = $ev->GetValue("maxcall");
                 $m->params["cdrtrack"] = "false";
                 $m->Dispatch();
                 // check if queued call still exists
                 $m = new Yate("chan.locate");
                 $m->params["id"] = $partycallid;
                 $m->Dispatch();
                 break;
Exemplo n.º 9
0
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
/* Test script for the Yate PHP interface
   To test add in extmodule.conf

   [scripts]
   test.php=
*/
require_once "libyate.php";
/* Always the first action to do */
Yate::Init();
/* Install a handler for the engine generated timer message */
Yate::Install("engine.timer", 10);
/* Create and dispatch an initial test message */
$m = new Yate("test");
$m->params["param1"] = "val1";
$m->retval = "ret_value";
$m->Dispatch();
Yate::GetLocal("engine.version");
Yate::GetLocal("engine.nodename");
Yate::GetLocal("engine.nosuch");
Yate::SetLocal("engine.nodename", "error because is readonly");
Yate::GetLocal("config.nosuch");
Yate::GetLocal("config.localsym");
Yate::GetLocal("config.localsym.h323chan.yate");
Yate::SetLocal("config.localsym.h323chan.yate", "r/o error too");
/* The main loop. We pick events and handle them */
for (;;) {
Exemplo n.º 10
0
}
Yate::Init();
// Comment the next line to get output only in logs, not in rmanager
Yate::Output(true);
// Uncomment the next line to get debugging details by default
//Yate::Debug(true);
$n = round(1 * Yate::Arg());
if ($n >= 2) {
    $ban_failures = $n;
}
Yate::SetLocal("trackparam", "banbrutes");
Yate::Watch("user.auth");
Yate::Watch("user.authfail");
Yate::Watch("engine.timer");
Yate::Install("engine.command", 120);
Yate::Install("engine.help", 150);
Yate::SetLocal("restart", true);
for (;;) {
    $ev = Yate::GetEvent();
    if ($ev === false) {
        break;
    }
    if ($ev === true) {
        continue;
    }
    if ($ev->type == "incoming") {
        switch ($ev->name) {
            case "engine.command":
                if ($ev->GetValue("line")) {
                    $ev->handled = onCommand($ev->GetValue("line"), $ev->retval);
                } else {
Exemplo n.º 11
0
 if ($ev === true) {
     continue;
 }
 /* If we reached here we should have a valid object */
 switch ($ev->type) {
     case "incoming":
         // Yate::Debug("PHP Message: " . $ev->name . " id: " . $ev->id);
         switch ($ev->name) {
             case "call.execute":
                 $ourcallid = $ev->GetValue("id");
                 $callto = $ev->GetValue("real_callto");
                 if ($ourcallid && $callto) {
                     // Put back the real callto and let the message flow
                     $ev->params["callto"] = $callto;
                     Yate::Install("chan.hangup", 75, "id", $ourcallid);
                     Yate::Install("chan.disconnected", 75, "id", $ourcallid);
                     onStartup($ev);
                 } else {
                     Yate::Output("Invalid assist: '{$ourcallid}' -> '{$callto}'");
                     $ourcallid = false;
                 }
                 break;
             case "chan.hangup":
                 // We were hung up. Do any cleanup and exit.
                 onHangup($ev);
                 $ourcallid = false;
                 break;
             case "chan.disconnected":
                 // Our party disconnected and we're ready to hang up.
                 // We should reconnect before this message is acknowledged
                 if (onDisconnect($ev, $ev->GetValue("reason"))) {
Exemplo n.º 12
0
 /**
  * Run the IVR system
  * @param $ivrname Name of the initial IVR to start
  */
 static function Run($ivrname)
 {
     global $yate_ivr_target;
     global $yate_ivr_current;
     if (IVR::Jump($ivrname)) {
         $init_id = true;
         while ($yate_ivr_current !== null) {
             $ev = Yate::GetEvent();
             if ($ev === true) {
                 continue;
             }
             if ($ev === false) {
                 break;
             }
             if ($ev->type == "incoming" && $ev->name == "call.execute") {
                 $yate_ivr_target = $ev->GetValue("id");
                 IVR::SetChannelID($ev->GetValue("ivrchanid"));
             }
             IVR::EventIVR($ev);
             if ($init_id && $yate_ivr_current !== null) {
                 $init_id = false;
                 Yate::SetLocal("id", IVR::ChannelID());
                 Yate::Install("chan.dtmf", 100, "targetid", IVR::ChannelID());
                 Yate::Install("chan.notify", 100, "targetid", IVR::ChannelID());
             }
             if ($ev && $ev->type == "incoming") {
                 if ($ev->handled && $ev->name == "call.execute") {
                     $ev->SetParam("targetid", IVR::ChannelID());
                 }
                 $ev->Acknowledge();
             }
         }
         IVR::CleanupIVR();
     }
 }
Exemplo n.º 13
0
   ringback.php=RINGBACK

   where RINGBACK is a wave or autorepeat temporary tone resource like:
      tone/*ring  (this is the default)
      wave/play/path/to/custom.au
*/
require_once "libyate.php";
// A fixed format is needed as we can't know what the called will offer
$mediafmt = "mulaw";
Yate::Init();
//Yate::Debug(true);
$ringback = Yate::Arg();
if ($ringback == "") {
    $ringback = "tone/*ring";
}
Yate::Install("call.ringing", 50);
Yate::Watch("call.ringing");
Yate::SetLocal("restart", true);
for (;;) {
    $ev = Yate::GetEvent();
    if ($ev === false) {
        break;
    }
    if ($ev === true) {
        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);
Exemplo n.º 14
0
require_once 'lib_smtp.inc.php';
require_once 'lib_queries.php';
set_time_limit(600);
function debug($msg)
{
    Yate::Debug('send_mail.php: ' . $msg);
}
if (!isset($incoming_trunks)) {
    $incoming_trunks = array();
}
$sql_time = "SELECT value FROM ntn_settings WHERE param = 'time_zone_hour'";
$res_time = query_to_array($sql_time);
$time_zone_hour = $res_time[0]['value'] ? $res_time[0]['value'] : 3;
// Always the first action to do
Yate::Init();
Yate::Install('call.cdr', 120);
// Ask Yate to restart this script if it dies unexpectedly
Yate::SetLocal('restart', true);
Yate::Debug(true);
// The main loop. We pick events and handle them
for (;;) {
    $ev = Yate::GetEvent();
    if ($ev === false) {
        break;
    }
    if ($ev === true) {
        continue;
    }
    // We are sure it's the timer message
    if ($ev->type == 'incoming') {
        switch ($ev->name) {
Exemplo n.º 15
0
                $changed = true;
            }
        }
        if (count($entries) == 0) {
            Yate::Debug("Invalidating entire host {$host}");
            unset($cache[$host]);
        } else {
            if ($changed) {
                $cache[$host] = array_values($cache[$host]);
            }
        }
    }
}
Yate::SetLocal("trackparam", "resolver.php");
Yate::Install("call.execute", 80);
Yate::Install("chan.hangup", 120, "cause_sip", "408");
Yate::SetLocal("restart", true);
function _disable_warnings_handler($errno, $errstr, $errfile, $errline)
{
    switch ($errno) {
        case E_USER_ERROR:
        case E_WARNING:
        case E_USER_WARNING:
            _yate_error_handler($errno, $errstr, $errfile, $errline);
        default:
            if (!strpos($errfile, 'Net/DNS')) {
                _yate_error_handler($errno, $errstr, $errfile, $errline);
            }
    }
}
// Net_DNS has static call issues so disable its many warnings...
Exemplo n.º 16
0
    $m = new Yate("chan.masquerade");
    $m->id = "";
    // don't notify about message result
    $m->params["message"] = "call.execute";
    $m->params["id"] = $id;
    // FIXME: generate an unique name for each call
    $m->params["callto"] = "fax/receive/spool/fax-rx.tif";
    $m->params["reason"] = "fax";
    $m->Dispatch();
}
/* Always the first action to do */
Yate::Init();
Yate::Install("engine.command", 85);
Yate::Install("engine.help", 125);
Yate::Install("call.execute", 25);
Yate::Install("call.fax", 25);
/* Create and dispatch an initial test message */
/* The main loop. We pick events and handle them */
for (;;) {
    $ev = Yate::GetEvent();
    /* If Yate disconnected us then exit cleanly */
    if ($ev === false) {
        break;
    }
    /* Empty events are normal in non-blocking operation.
       This is an opportunity to do idle tasks and check timers */
    if ($ev === true) {
        continue;
    }
    /* If we reached here we should have a valid object */
    switch ($ev->type) {
Exemplo n.º 17
0
    exit;
}
// Install handler for the wave end notify messages
Yate::Watch("engine.timer");
Yate::Install("user.register");
Yate::Install("user.unregister");
Yate::Install("user.auth");
Yate::Install("call.route");
Yate::Install("call.cdr");
Yate::Install("call.answered", 50);
Yate::Install("chan.disconnected", 50);
Yate::Install("chan.hangup");
Yate::Install("user.notify");
Yate::Install("engine.status");
Yate::Install("engine.command");
Yate::Install("engine.debug");
// Ask to be restarted if dying unexpectedly
Yate::SetLocal("restart", "true");
$query = "SELECT enabled, protocol, username, description, 'interval', formats, authname, password, server, domain, outbound , localaddress, modified, gateway as account, gateway_id, status, 1 AS gw, ip_transport FROM gateways WHERE enabled = 1 AND gateway IS NOT NULL AND username IS NOT NULL ORDER BY gateway";
$res = query_to_array($query);
for ($i = 0; $i < count($res); $i++) {
    $m = new Yate("user.login");
    $m->params = $res[$i];
    $m->Dispatch();
}
set_caller_id();
set_moh();
set_prefixes();
// The main loop. We pick events and handle them
for (;;) {
    $ev = Yate::GetEvent();
Exemplo n.º 18
0
        $retval .= "Subscriptions:\r\n";
        dumpAll($users, $retval);
        dumpAll($chans, $retval);
        return true;
    }
    return false;
}
/* Always the first action to do */
Yate::Init();
Yate::Debug(true);
Yate::Install("sip.subscribe");
Yate::Install("user.update");
Yate::Install("chan.update");
Yate::Install("call.cdr");
Yate::Install("engine.timer");
Yate::Install("engine.command");
/* Create and dispatch an initial test message */
/* The main loop. We pick events and handle them */
for (;;) {
    $ev = Yate::GetEvent();
    /* If Yate disconnected us then exit cleanly */
    if ($ev === false) {
        break;
    }
    /* Empty events are normal in non-blocking operation.
       This is an opportunity to do idle tasks and check timers */
    if ($ev === true) {
        continue;
    }
    /* If we reached here we should have a valid object */
    switch ($ev->type) {
Exemplo n.º 19
0
        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}'");
}
Yate::Init();
Yate::Debug(true);
Yate::Install("engine.timer");
Yate::Install("chan.startup", 50);
Yate::Install("chan.hangup", 50);
Yate::Install("call.answered", 50);
/* The main loop. We pick events and handle them */
for (;;) {
    $ev = Yate::GetEvent();
    /* If Yate disconnected us then exit cleanly */
    if ($ev === false) {
        break;
    }
    /* No need to handle empty events in this application */
    if ($ev === true) {
        continue;
    }
    /* If we reached here we should have a valid object */
    switch ($ev->type) {
        case "incoming":
            switch ($ev->name) {
Exemplo n.º 20
0
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
/* Test script for the Yate PHP interface
   To test add in extmodule.conf

   [scripts]
   test.php=
*/
require_once "libyate.php";
/* Always the first action to do */
Yate::Init();
/* Install a handler for the engine generated timer message */
//Yate::Install("engine.timer",10);
Yate::Install("user.auth", 10);
/* Create and dispatch an initial test message */
/* The main loop. We pick events and handle them */
for (;;) {
    $ev = Yate::GetEvent();
    /* If Yate disconnected us then exit cleanly */
    if ($ev === false) {
        break;
    }
    /* Empty events are normal in non-blocking operation.
       This is an opportunity to do idle tasks and check timers */
    if ($ev === true) {
        //        Yate::Output("PHP event: empty");
        continue;
    }
    /* If we reached here we should have a valid object */
Exemplo n.º 21
0
        case "finalize":
            // Forget about the call leg that got hung up
            unset($calls[$chan]);
            break;
    }
}
$calls = array();
$prefix = Yate::Arg();
if ($prefix == "") {
    // Hope this is a sensible default - else set a prefix from extmodule.conf
    $prefix = "#8";
    Yate::Output("Pickup prefix not set, using default '{$prefix}'");
}
Yate::SetLocal("trackparam", "pickup.php");
Yate::Install("call.route", 35);
Yate::Install("call.cdr", 110, "direction", "outgoing");
Yate::SetLocal("restart", true);
for (;;) {
    $ev = Yate::GetEvent();
    if ($ev === false) {
        break;
    }
    if ($ev === true) {
        continue;
    }
    if ($ev->type == "incoming") {
        switch ($ev->name) {
            case "call.route":
                doRoute($ev);
                break;
            case "call.cdr":