Пример #1
0
 /**
  * Retorna um usuário em sua classe nativa.
  *
  * ex: PBX_Asterisk_Ramal e no futuro Snep_Agent
  *
  * @param int $userid
  * @return Snep_Usuario usuario
  */
 public static function get($userid)
 {
     $db = Snep_Db::getInstance();
     $userid = str_replace("'", "\\'", $userid);
     $select = $db->select()->from('peers')->where("name = '{$userid}' AND peer_type='R'");
     $stmt = $db->query($select);
     $usuario = $stmt->fetchObject();
     if (!$usuario) {
         throw new PBX_Exception_NotFound("Usuario {$userid} nao encontrado");
     }
     $tech = substr($usuario->canal, 0, strpos($usuario->canal, '/'));
     if ($tech == "SIP") {
         require_once "PBX/Asterisk/Interface/SIP.php";
         $interface = new PBX_Asterisk_Interface_SIP(array("username" => $usuario->name, "secret" => $usuario->secret));
     } else {
         if ($tech == "IAX2") {
             require_once "PBX/Asterisk/Interface/IAX2.php";
             $interface = new PBX_Asterisk_Interface_IAX2(array("username" => $usuario->name, "secret" => $usuario->secret));
         } else {
             if ($tech == "MANUAL") {
                 require_once "PBX/Asterisk/Interface/VIRTUAL.php";
                 $interface = new PBX_Asterisk_Interface_VIRTUAL(array("channel" => substr($usuario->canal, strpos($usuario->canal, '/') + 1)));
             } else {
                 if ($tech == "VIRTUAL") {
                     require_once "PBX/Asterisk/Interface/VIRTUAL.php";
                     $trunk = PBX_Trunks::get(substr($usuario->canal, strpos($usuario->canal, '/') + 1));
                     $interface = new PBX_Asterisk_Interface_VIRTUAL(array("channel" => $trunk->getInterface()->getCanal() . "/" . $userid));
                 } else {
                     if ($tech == "KHOMP") {
                         require_once "PBX/Asterisk/Interface/KHOMP.php";
                         $khomp_id = substr($usuario->canal, strpos($usuario->canal, '/') + 1);
                         $khomp_board = substr($khomp_id, 1, strpos($khomp_id, 'c') - 1);
                         $khomp_channel = substr($khomp_id, strpos($khomp_id, 'c') + 1);
                         $interface = new PBX_Asterisk_Interface_KHOMP(array("board" => $khomp_board, "channel" => $khomp_channel));
                     } else {
                         throw new Exception("Tecnologia {$tech} desconhecida ou invalida.");
                     }
                 }
             }
         }
     }
     $user = new Snep_Exten($usuario->name, $usuario->password, $usuario->callerid, $interface);
     $user->setGroup($usuario->group);
     if ($usuario->authenticate) {
         $user->lock();
     }
     if ($usuario->dnd) {
         $user->DNDEnable();
     }
     if ($usuario->sigame != "") {
         $user->setFollowMe($usuario->sigame);
     }
     if (is_numeric($usuario->pickupgroup)) {
         $user->setPickupGroup($usuario->pickupgroup);
     }
     if ($usuario->usa_vc) {
         $user->setMailBox($usuario->mailbox);
         $user->setEmail($usuario->email);
     }
     return $user;
 }
Пример #2
0
 /**
  * Processa dados crus da tabela no banco para instanciação de objetos de
  * ramais.
  *
  * @param Object $data Resultado de um select com todas as colunas no banco
  * de dados dos ramais.
  * @return Snep_Exten ramal criado a partir dos dados.
  */
 private function processExten($data)
 {
     $tech = substr($data->canal, 0, strpos($data->canal, '/'));
     if ($tech == "SIP" || $tech == "IAX2") {
         $config = array("username" => $data->name, "secret" => $data->secret, "allow" => $data->allow, "type" => $data->type, "qualify" => $data->qualify, "dtmfmode" => $data->dtmfmode, "nat" => $data->nat, "call-limit" => $data->{'call-limit'});
         if ($tech == "SIP") {
             $interface = new PBX_Asterisk_Interface_SIP($config);
         } else {
             $interface = new PBX_Asterisk_Interface_IAX2($config);
         }
     } else {
         if ($tech == "VIRTUAL") {
             $trunk = PBX_Trunks::get(substr($data->canal, strpos($data->canal, '/') + 1));
             $interface = new PBX_Asterisk_Interface_VIRTUAL(array("channel" => $trunk->getInterface()->getCanal() . "/" . $exten_id));
         } else {
             if ($tech == "MANUAL") {
                 $interface = new PBX_Asterisk_Interface_VIRTUAL(array("channel" => substr($data->canal, strpos($data->canal, '/') + 1)));
             } else {
                 if ($tech == "KHOMP") {
                     $khomp_id = substr($data->canal, strpos($data->canal, '/') + 1);
                     $khomp_board = substr($khomp_id, 1, strpos($khomp_id, 'c') - 1);
                     $khomp_channel = substr($khomp_id, strpos($khomp_id, 'c') + 1);
                     $interface = new PBX_Asterisk_Interface_KHOMP(array("board" => $khomp_board, "channel" => $khomp_channel));
                 } else {
                     throw new Exception("Tecnologia {$tech} desconhecida ou invalida.");
                 }
             }
         }
     }
     $exten = new Snep_Exten($data->name, $data->password, $data->callerid, $interface);
     $exten->setChannel($data->canal);
     $exten->setGroup($data->group);
     if ($data->authenticate) {
         $exten->lock();
     }
     if ($data->dnd) {
         $exten->DNDEnable();
     }
     if ($data->sigame != "") {
         $exten->setFollowMe($data->sigame);
     }
     if (is_numeric($data->pickupgroup)) {
         $exten->setPickupGroup($data->pickupgroup);
     }
     if ($data->usa_vc == 'yes') {
         $exten->setMailBox($data->mailbox);
         $exten->setEmail($data->email);
     }
     if ($data->time_total != NULL) {
         $exten->setTimeTotal($data->time_total);
         $exten->setCtrlType($data->time_chargeby);
     }
     return $exten;
 }